Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Enable nano syntax highlighting

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
64 posts
  • Previous
  • 1
  • 2
  • 3
Author
Message
boniek
Guru
Guru
User avatar
Posts: 373
Joined: Sat Mar 26, 2005 6:02 pm

  • Quote

Post by boniek » Sat Nov 25, 2006 8:59 pm

Just wanted to drop by and say thanks. Good stuff :)
[HOWTO]New freetype subpixel font rendering for lcd monitors
Top
ryszardzonk
Apprentice
Apprentice
User avatar
Posts: 225
Joined: Thu Dec 18, 2003 5:25 pm
Location: Rzeszów, POLAND

great stuff

  • Quote

Post by ryszardzonk » Sat Dec 02, 2006 4:06 pm

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: Select all

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: Select all

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...
Top
laserprinter
n00b
n00b
Posts: 2
Joined: Sun Dec 03, 2006 5:56 am
Contact:
Contact laserprinter
Website

  • Quote

Post by laserprinter » Sun Dec 03, 2006 6:09 am

these are great things, thank you..
lazy
Top
ryszardzonk
Apprentice
Apprentice
User avatar
Posts: 225
Joined: Thu Dec 18, 2003 5:25 pm
Location: Rzeszów, POLAND

solutions?

  • Quote

Post by ryszardzonk » Tue Dec 05, 2006 12:11 pm

After some time I made this syntax for *.po files. It is in no way complete, but here it comes anyway

Code: Select all

## *.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: Select all

## 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...
Last edited by ryszardzonk on Fri Dec 08, 2006 12:36 pm, edited 9 times in total.
Sky is not the limit...
Top
bigmauler
Apprentice
Apprentice
User avatar
Posts: 177
Joined: Mon Apr 25, 2005 7:36 pm
Location: Seattle, WA

  • Quote

Post by bigmauler » Tue Dec 05, 2006 5:40 pm

Cool I didn't know nano did this...Nice thread, now my screen is pretty!
Never take raisins from a rabbit
Top
ryszardzonk
Apprentice
Apprentice
User avatar
Posts: 225
Joined: Thu Dec 18, 2003 5:25 pm
Location: Rzeszów, POLAND

nano syntax

  • Quote

Post by ryszardzonk » Fri Dec 08, 2006 12:43 pm

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...
Top
bladdo
Guru
Guru
User avatar
Posts: 334
Joined: Mon Jul 19, 2004 7:05 pm
Location: NJ
Contact:
Contact bladdo
Website

  • Quote

Post by bladdo » Sat May 03, 2008 2:05 pm

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
Top
Sadako
Advocate
Advocate
User avatar
Posts: 3792
Joined: Thu Aug 05, 2004 5:50 pm
Location: sleeping in the bathtub
Contact:
Contact Sadako
Website

  • Quote

Post by Sadako » Fri May 09, 2008 7:02 pm

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: Select all

#!/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"
Top
steveL
Watchman
Watchman
Posts: 5153
Joined: Wed Sep 13, 2006 1:18 pm
Location: The Peanut Gallery

  • Quote

Post by steveL » Mon May 12, 2008 4:42 am

Nice one Hopeless, I needed this recently as I was installing on a machine with no X, ended up just adding the filename ([topic=546828]update[/topic]) 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.
Top
VinzC
Watchman
Watchman
User avatar
Posts: 5100
Joined: Sat Apr 17, 2004 1:51 pm
Location: Dark side of the mood

  • Quote

Post by VinzC » Sun Sep 06, 2009 5:51 pm

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.

Code: Select all

## 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!
Top
eyoung100
Veteran
Veteran
User avatar
Posts: 1428
Joined: Fri Jan 23, 2004 10:45 pm

  • Quote

Post by eyoung100 » Sun Oct 18, 2009 6:00 pm

A small pointer for all of you:

You may want to consider reading and then uncommenting

Code: Select all

/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: Select all

## 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
Top
bob doe
Apprentice
Apprentice
Posts: 207
Joined: Mon Jun 11, 2007 5:35 pm

Bash highlighting

  • Quote

Post by bob doe » Sun May 23, 2010 2:35 am

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: Select all

## 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:]]+$"
Top
VinzC
Watchman
Watchman
User avatar
Posts: 5100
Joined: Sat Apr 17, 2004 1:51 pm
Location: Dark side of the mood

  • Quote

Post by VinzC » Sun May 23, 2010 11:43 am

eyoung100 wrote:A small pointer for all of you:

You may want to consider reading and then uncommenting

Code: Select all

/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

Code: Select all

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!
Top
ryszardzonk
Apprentice
Apprentice
User avatar
Posts: 225
Joined: Thu Dec 18, 2003 5:25 pm
Location: Rzeszów, POLAND

  • Quote

Post by ryszardzonk » Sat Feb 04, 2017 8:22 pm

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: Select all

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...
Top
Post Reply

64 posts
  • Previous
  • 1
  • 2
  • 3

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic