Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Enable nano syntax highlighting
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
boniek
Guru
Guru


Joined: 26 Mar 2005
Posts: 373

PostPosted: Sat Nov 25, 2006 8:59 pm    Post subject: Reply with quote

Just wanted to drop by and say thanks. Good stuff :)
_________________
[HOWTO]New freetype subpixel font rendering for lcd monitors
Back to top
View user's profile Send private message
ryszardzonk
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 225
Location: Rzeszów, POLAND

PostPosted: Sat Dec 02, 2006 4:06 pm    Post subject: great stuff Reply with quote

Thanks for this great stuff of which I take advantage for long time now. My question is however is there someone to make the *.po and ChangeLog file syntax for the greater benefit of human kind :) One might use this Midnight Commander syntax to help us little people out ;)

mc changelog syntax
Code:
context default
    spellcheck

context linestart \t \n\n
    keyword wholeright +() brightmagenta
    keyword linestart \t\*\s*: brightcyan
    keyword (*): cyan
    keyword (*)\{\s\}[*]: cyan

context linestart \s\s\s\s\s\s\s\s \n\n
    keyword wholeright +() brightmagenta
    keyword \*\s*: brightcyan
    keyword (*): cyan
    keyword (*)\{\s\}[*]: cyan
    keyword whole \* brightcyan

context linestart 19+-+\s \n yellow
    keyword <+> brightred
context linestart 20+-+\s \n yellow
    keyword <+> brightred
context linestart Mon\s \n yellow
    keyword <+> brightred
context linestart Tue\s \n yellow
    keyword <+> brightred
context linestart Wed\s \n yellow
    keyword <+> brightred
context linestart Thu\s \n yellow
    keyword <+> brightred
context linestart Fri\s \n yellow
    keyword <+> brightred
context linestart Sat\s \n yellow
    keyword <+> brightred
context linestart Sun\s \n yellow
    keyword <+> brightred

*.po syntax
Code:
context default
    keyword linestart msgstr\s\"\"\n\n brightred
    keyword linestart msgid brightcyan
    keyword linestart msgstr brightcyan

context linestart #,\sfuzzy \n\n brightred

context linestart #: \n white

context linestart #, \n white
    keyword c-format yellow

context linestart #~ \n red

context linestart # \n brown
    spellcheck

context exclusive linestart msgid \n cyan
    spellcheck
    keyword \"\n\"
    keyword \\" brightgreen
    keyword \\\n brightgreen
    keyword %% brightgreen
    keyword %\[#0\s-\+,\]\[0123456789\]\[.\]\[0123456789\]\[L\]\{eEfgG\} brightgreen
    keyword %\[0\s-\+,\]\[0123456789\]\[.\]\[0123456789\]\[hl\]\{diouxX\} brightgreen
    keyword %\[hl\]n brightgreen
    keyword %\[.\]\[0123456789\]s brightgreen
    keyword %[*] brightgreen
    keyword %c brightgreen
    keyword \\\{0123\}\{01234567\}\{01234567\} brightgreen
    keyword \\\\ brightgreen
    keyword \\' brightgreen
    keyword \\\{abtnvfr\} brightgreen

context exclusive linestart msgstr \n green
    spellcheck
    keyword \"\n\"
    keyword \\" brightgreen
    keyword \\\n brightgreen
    keyword %% brightgreen
    keyword %\[#0\s-\+,\]\[0123456789\]\[.\]\[0123456789\]\[L\]\{eEfgG\} brightgreen
    keyword %\[0\s-\+,\]\[0123456789\]\[.\]\[0123456789\]\[hl\]\{diouxX\} brightgreen
    keyword %\[hl\]n brightgreen
    keyword %\[.\]\[0123456789\]s brightgreen
    keyword %[*] brightgreen
    keyword %c brightgreen
    keyword \\\{0123\}\{01234567\}\{01234567\} brightgreen
    keyword \\\\ brightgreen
    keyword \\' brightgreen
    keyword \\\{abtnvfr\} brightgreen

_________________
Sky is not the limit...
Back to top
View user's profile Send private message
laserprinter
n00b
n00b


Joined: 03 Dec 2006
Posts: 2

PostPosted: Sun Dec 03, 2006 6:09 am    Post subject: Reply with quote

these are great things, thank you..
_________________
lazy
Back to top
View user's profile Send private message
ryszardzonk
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 225
Location: Rzeszów, POLAND

PostPosted: Tue Dec 05, 2006 12:11 pm    Post subject: solutions? Reply with quote

After some time I made this syntax for *.po files. It is in no way complete, but here it comes anyway
Code:
## *.po file syntax
##
syntax "po" "\.po$"
color brightblue "\<(msgid|msgstr)\>"
color brightred "\/"
color green "#.*$"
color red "\<fuzzy\>"
color yellow "\<c-format\>"
color yellow "\""
color red  "\"\""
color brightyellow  "\"\\n\""
color brightmagenta "\<(Project\-Id\-Version|Report\-Msgid\-Bugs\-To|Last\-Translator|Language\-Team|charset)\>"
color cyan "\<(POT\-Creation\-Date|PO\-Revision\-Date|MIME\-Version|Content\-Type|Content\-Transfer\-Encoding)\>"
color yellow "\<(Copyright|(C))\>"
color yellow "[0-9]"
color brightyellow "\<(UTF|ISO|Windows|Mac|IBM)\>\-[0-9]"
color red "#~.*$"

ChangeLog syntax. Not quite what you would call perfect but somewhat usable
Code:

## Changelog file syntax
##
syntax "changelogs" "ChangeLog*"

color green "\+"
color red "\-"
color brightwhite "[0-9]"
color brightblue "[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]"
color blue "[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]"
color blue "[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]"
color blue "\<(CEST|CET|CST||CDT|EDT)\>"
color yellow "[0-9]\..*$"
color cyan "\*.*$"
color brightblue "\<(pre.*$|beta.*$|rc.*$|release.*$)\>"
color green "#.*$"
icolor brightred "^[[:space:]]*[.0-9A-Z_]*:"
color green "[[:space:]]*[.0-9A-Z_]*[[:space:]]*[.0-9A-Z_]*[[:space:]]<"
color brightyellow "<.*>$"
color brightwhite "commit[[:space:]]*[.0-9A-Z_]*$"

There must be a better solution than this...
I also had to put include "/usr/share/nano/changelog.nanorc" in end of my /etc/nanorc for it to work...

Edit:I added some more stuff in there. *.po syntax needs highlighting of phrases to catch syntax errors...
_________________
Sky is not the limit...


Last edited by ryszardzonk on Fri Dec 08, 2006 12:36 pm; edited 9 times in total
Back to top
View user's profile Send private message
bigmauler
Apprentice
Apprentice


Joined: 25 Apr 2005
Posts: 177
Location: Seattle, WA

PostPosted: Tue Dec 05, 2006 5:40 pm    Post subject: Reply with quote

Cool I didn't know nano did this...Nice thread, now my screen is pretty!
_________________
Never take raisins from a rabbit
Back to top
View user's profile Send private message
ryszardzonk
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 225
Location: Rzeszów, POLAND

PostPosted: Fri Dec 08, 2006 12:43 pm    Post subject: nano syntax Reply with quote

For convenience I placed all the syntax highlighting stuff to be found here along with few more syntaxes in this package http://bigvo.dyndns.org/nanosyntax.tar.bz2
WARNING: Tested just with the black background
_________________
Sky is not the limit...
Back to top
View user's profile Send private message
bladdo
Guru
Guru


Joined: 19 Jul 2004
Posts: 334
Location: NJ

PostPosted: Sat May 03, 2008 2:05 pm    Post subject: Reply with quote

I know this thread is old but thanks guys, nano just got that much better.
_________________
Bladdo formerly >Milo<
bladdo.net - scripting and design
Creator of AIM Bot: Tiny Tiny Bot - the bot that learns
distro: gentoo | window manager: pekwm
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Fri May 09, 2008 7:02 pm    Post subject: Reply with quote

Seeing as bladdo already necro'd it... :P

I wrote a little bash wrapper script which uses the `file` command on a file and uses the value to determine what (if any) syntax highlighting to enable in nano via --syntax.

It has a couple of issues though, for one thing you can only use --syntax once on the command line, and all files will end up using the same syntax (so in the script if you pass more than file it'll just start nano normally and let nano decide which highlighting to enable).

Another issue is `file` isn't entirely accurate, most noticeably is that it identifies a lot of diff/patch as C source files if there is a significant comment at the top of the file.

Anyways, here's the script if anyone is interested (and a link);
Code:
#!/bin/bash

NANO="/usr/bin/nano"

for PARAM; do
        if [[ -f $PARAM ]]; then
                [[ ! $NANOFILE ]] && NANOFILE="${PARAM}" || exec $NANO "$@"
        fi
done

case `file -b "${NANOFILE}"` in
        *perl*"script text"* )
                SYNTAX="--syntax perl"
                ;;
        *python*"script text"* )
                SYNTAX="--syntax python"
                ;;
        *ruby*"script text"* )
                SYNTAX="--syntax ruby"
                ;;
        *PHP*"script text"* )
                SYNTAX="--syntax php"
                ;;
        *"script text"* )
                SYNTAX="--syntax sh"
                ;;
        *"diff output text"* )
                SYNTAX="--syntax patch"
                ;;
        *C*"program text"*)
                SYNTAX="--syntax c"
                ;;
        *"Java program text"* )
                SYNTAX="--syntax java"
                ;;
        *"HTML document text"* )
                SYNTAX="--syntax html"
                ;;
esac

exec $NANO ${SYNTAX} "$@"

exit

It's only really useful for scripts without file extensions (although that alone makes it invaluable to me), and could probably be improved quite a bit, but it does what I want.

It should be easily extendable, too.
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon May 12, 2008 4:42 am    Post subject: Reply with quote

Nice one Hopeless, I needed this recently as I was installing on a machine with no X, ended up just adding the filename (update) to this syntax highlighting file: http://dev.gentooexperimental.org/~igli/src/bash.nanorc
It works really nicely for BASH, in some places better than kate. Multi-line strings are the only place it falls over, but you still see the first line in orange.
Back to top
View user's profile Send private message
VinzC
Watchman
Watchman


Joined: 17 Apr 2004
Posts: 5098
Location: Dark side of the mood

PostPosted: Sun Sep 06, 2009 5:51 pm    Post subject: Reply with quote

Hi all.

I've just upgraded nano to version 2.1.9 and python syntax doesn't seem to work anymore. Nothing is highlighted anymore. Forcing syntax to bash gives some colours à la bash script but I just wonder why python syntax highlighting doesn't work.
/usr/share/nano/python.nanorc:
## Here is an example for Python.
##
syntax "python" "\.py$"
header "^#!.*/python[-0-9._]*"
icolor brightblue "def [0-9A-Z_]+"
color brightcyan "\<(and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\>"
color brightgreen "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
color brightgreen "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
color brightgreen start=""""[^"]" end=""""" start="'''[^']" end="'''"
color brightred "#.*$"
color ,green "[[:space:]]+$"

I have added the last colour syntax item so that I see trailing spaces. Any idea?
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739!
Back to top
View user's profile Send private message
eyoung100
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1428

PostPosted: Sun Oct 18, 2009 6:00 pm    Post subject: Reply with quote

A small pointer for all of you:

You may want to consider reading and then uncommenting
Code:
/etc/nanorc


Uncommenting this file will override your per user settings in ~/.nanorc and enable highlighting on a system-wide basis. Here is the snippet dealing with colors:
Code:

## Color setup
##
## Format:
##
## syntax "short description" ["filename regex" ...]
##
## The "none" syntax is reserved; specifying it on the command line is
## the same as not having a syntax at all.  The "default" syntax is
## special: it takes no filename regexes, and applies to files that
## don't match any other syntax's filename regexes.
##
## color foreground,background "regex" ["regex"...]
## or
## icolor foreground,background "regex" ["regex"...]
##
## "color" will do case sensitive matches, while "icolor" will do case
## insensitive matches.
##
## Valid colors: white, black, red, blue, green, yellow, magenta, cyan.
## For foreground colors, you may use the prefix "bright" to get a
## stronger highlight.
##
## To use multi-line regexes, use the start="regex" end="regex"
## [start="regex" end="regex"...] format.
##
## If your system supports transparency, not specifying a background
## color will use a transparent color.  If you don't want this, be sure
## to set the background color to black or white.
##
## If you wish, you may put your syntaxes in separate files.  You can
## make use of such files (which can only include "syntax", "color", and
## "icolor" commands) as follows:
##
## include "/path/to/syntax_file.nanorc"
##
## Unless otherwise noted, the name of the syntax file (without the
## ".nanorc" extension) should be the same as the "short description"
## name inside that file.  These names are kept fairly short to make
## them easier to remember and faster to type using nano's -Y option.
##
## All regexes should be extended regular expressions.

## Key bindings
## Please see nanorc(5) for more details on this
##
## Here are some samples to get you going
##
# bind M-W nowrap main
# bind M-A casesens search
# bind ^S research main

## Set this if your backspace key sends delete most of the time (2.1.3+)
# bind kdel backspace all


## Nanorc files
# include "/usr/share/nano/nanorc.nanorc"

## C/C++
# include "/usr/share/nano/c.nanorc"

## Cascading Style Sheets
# include "/usr/share/nano/css.nanorc"

## Debian files
# include "/usr/share/nano/debian.nanorc"

## Gentoo files
# include "/usr/share/nano/gentoo.nanorc"

## HTML
# include "/usr/share/nano/html.nanorc"

## PHP
# include "/usr/share/nano/php.nanorc"

## TCL
# include "/usr/share/nano/tcl.nanorc"

## TeX
# include "/usr/share/nano/tex.nanorc"

## Quoted emails (under e.g. mutt)
# include "/usr/share/nano/mutt.nanorc"

## Patch files
# include "/usr/share/nano/patch.nanorc"

## Manpages
# include "/usr/share/nano/man.nanorc"

## Groff
# include "/usr/share/nano/groff.nanorc"

## Perl
# include "/usr/share/nano/perl.nanorc"

## Python
# include "/usr/share/nano/python.nanorc"

## Ruby
# include "/usr/share/nano/ruby.nanorc"

## Java
# include "/usr/share/nano/java.nanorc"

## AWK
# include "/usr/share/nano/awk.nanorc"

## Assembler
# include "/usr/share/nano/asm.nanorc"

## Bourne shell scripts
# include "/usr/share/nano/sh.nanorc"

## POV-Ray
# include "/usr/share/nano/pov.nanorc"

## XML-type files
# include "/usr/share/nano/xml.nanorc"


There is already a gentoo syntax file in /usr/share/nano named gentoo.nanorc that is in the long list of includes above.
_________________
The Birth and Growth of Science is the Death and Atrophy of Art -- Unknown
Registerd Linux User #363735
Adopt a Post | Strip Comments| Emerge Wrapper
Back to top
View user's profile Send private message
bob doe
Apprentice
Apprentice


Joined: 11 Jun 2007
Posts: 207

PostPosted: Sun May 23, 2010 2:35 am    Post subject: Bash highlighting Reply with quote

Hey guys, I took this from 2.2.4's sh.nanorc and changed a few things:

Variables within double quotes ("") have the correct colour, because they are expanded. Within single quote ('') though, variables have the quotes colour because they arent expanded. Any quotes within comments wont be coloured, they'll just have the comment colour.

Code:
## Here is an example for Bourne shell scripts.
##
syntax "bash" "\.sh$"
header "^#!.*/(ba|k|pdk)?sh[-0-9_]*"
icolor brightgreen "^[0-9A-Z_]+\(\)"
color green "\<(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\>"
color green "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
color green "-[Ldefgruwx]\>"
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
color brightblue "\<(cat|cd|chmod|chown|cp|echo|env|export|grep|install|let|ln|make|mkdir|mv|rm|sed|set|tar|touch|umask|unset)\>"
color brightyellow ""(\\.|[^"])*""
icolor brightred "\$\{?[0-9A-Z_!@#$*?-]+\}?"
color brightyellow "'(\\.|[^'])*'"
color cyan "(^|[[:space:]])#.*$"
color ,green "[[:space:]]+$"
Back to top
View user's profile Send private message
VinzC
Watchman
Watchman


Joined: 17 Apr 2004
Posts: 5098
Location: Dark side of the mood

PostPosted: Sun May 23, 2010 11:43 am    Post subject: Reply with quote

eyoung100 wrote:
A small pointer for all of you:

You may want to consider reading and then uncommenting
Code:
/etc/nanorc

I finally found. I had left gentoo syntax file twice in /etc/nanorc. Removing the second line enabled python syntax back 8O . The moral of the story: beware of having the same syntax file mentioned more than once in /etc/nanorc otherwise all syntax files that are referenced between both occurrences will be disabled. In my case I had
grep '^include' /etc/nanorc:
include "/usr/share/nano/nanorc.nanorc"
include "/usr/share/nano/c.nanorc"
include "/usr/share/nano/gentoo.nanorc"  ## <-- first
include "/usr/share/nano/html.nanorc"
include "/usr/share/nano/patch.nanorc"
include "/usr/share/nano/perl.nanorc"
include "/usr/share/nano/python.nanorc"
include "/usr/share/nano/java.nanorc"
include "/usr/share/nano/gentoo.nanorc"  ## <-- second
include "/usr/share/nano/sh.nanorc"
include "/usr/share/nano/xml.nanorc"

so syntax highlighting was disabled for html, patch, perl, python and java. I just didn't happen to check any other file type but python. Bug IMHO...
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739!
Back to top
View user's profile Send private message
ryszardzonk
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 225
Location: Rzeszów, POLAND

PostPosted: Sat Feb 04, 2017 8:22 pm    Post subject: Reply with quote

With few exceptions for some configs I didn't touch nano syntaxes for quite some time and now I see number of sites have spread around dealing with that stuff. As I went ahead to go though quite a few of them I collected them in the most comprehensive archive to date. Hence I see the thread mentions my old website which changed way back at the time dyndns changed their policy I fought I'll drop a line about new site and the archive.

You can download them all from http://bigvo.hopto.org/nanosyntax.tar.bz2 or independently from http://bigvo.hopto.org/nanosyntax/nano/
- Main directory has files available in nano-2.7.4
- subdirectory extra has stuff divided depending on their use with exception of "new" where are files which I was not sure whee to put them just yet
- alternative directory list files which IMHO are prepared better than those in nano itself. Some of them actually do not differ all that much as they might have only
Code:
color ,green "[[:space:]]+$"
at the end to show trailing spaces.
- legacy directory has old version of the files which have better alternatives at the moment and are there only for reference
- zz_own in filetypes does not mean much besides that if I wanted to look for them I'll find them easier ;)
_________________
Sky is not the limit...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum