Skip to content

Commit

Permalink
nanorc
Browse files Browse the repository at this point in the history
  • Loading branch information
nanorc committed Sep 16, 2014
0 parents commit ebe557e
Show file tree
Hide file tree
Showing 86 changed files with 1,360 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
LANGS = awk c cmake coffeescript colortest csharp css cython default dot \
email git glsl go html ini inputrc java javascript json keymap \
kickstart ledger lisp lua makefile man markdown mpdconf nanorc \
nginx patch peg php pkgbuild pkg-config po privoxy properties \
python rpmspec ruby sed shell sql systemd tex vala vi xml \
xresources yaml yum

MIXINS = $(wildcard mixins/*.nanorc)
FILES = $(addsuffix .nanorc, $(LANGS))
ALL = $(addprefix build/, $(FILES)) build/ALL.nanorc
DIR = $(HOME)/.nano/syntax
THEME = theme.sed
FILTER = sed -f mixins.sed | sed -f $(THEME)

all: $(ALL)

build/ALL.nanorc: $(FILES) $(MIXINS) $(THEME) | build/
@cat $(FILES) | $(FILTER) > $@
@echo 'Generated: $@'

build/%.nanorc: %.nanorc $(MIXINS) $(THEME) | build/
@cat $< | $(FILTER) > $@
@echo 'Generated: $@'

build/:
@mkdir -p $@

install: all
@mkdir -p '$(DESTDIR)$(DIR)'
@install -p -m 0644 $(ALL) '$(DESTDIR)$(DIR)'
@echo 'Installed: $(DESTDIR)$(DIR)/*.nanorc'

install-global:
@$(MAKE) --no-print-directory install DIR=/usr/local/share/nano

clean:
rm -rf build


ifeq ($(shell test -f ~/.nanotheme && echo 1),1)
THEME = ~/.nanotheme
endif

# Remove "header" directives if not supported (introduced in nano 2.1.6)
NANOVER = $(shell nano -V | sed -n 's/^.* version \([0-9\.]*\).*/\1/p')
ifeq ($(shell printf "2.1.5\n$(NANOVER)" | sort -nr | head -1),2.1.5)
FILTER += | sed -e '/^header/d'
endif

ifdef TEXT
FILTER += | sed -e 's|^color \(bright\)\{0,1\}black|color \1$(TEXT)|'
endif

ifdef BSDREGEX
FILTER += | sed -e 's|\\<|[[:<:]]|g;s|\\>|[[:>:]]|g'
endif


.PHONY: all install install-global clean force
148 changes: 148 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
Unmaintained
============

I am no longer using nano as my editor and hence have little motivation
to continue working on this project. It remains available on GitHub for
archival purposes only.

Everything in the repository is in the Public Domain. Feel free to fork
it and/or use the files for any purpose.

P.S. I highly recommend [dex](https://github.com/tihirvon/dex) as a
simple but much more capable editor.


------


Description
-----------

The syntax highlighting definitions that come bundled with nano are of
pretty poor quality. This is an attempt at providing a good set of accurate
syntax definitions to replace and expand the defaults.

Installation
------------

Using `make install` will install the syntax definitions to the
`~/.nano/syntax/` directory.

To enable highlighting for *all* languages after installation, add the
following command to your `~/.nanorc` file:

include ~/.nano/syntax/ALL.nanorc

To enable only a subset of languages, `include` them individually:

include ~/.nano/syntax/c.nanorc
include ~/.nano/syntax/python.nanorc
include ~/.nano/syntax/sh.nanorc
# ...

If you prefer to install to a location that all users can access, using
`sudo make install-global` will install to `/usr/local/share/nano/`.
Syntax files installed under this directory can then be `include`d in
either `/etc/nanorc` or any user's personal `~/.nanorc`.

**Note**: If your terminal **text** color isn't black, you'll need to
specify it when installing, using `make install TEXT=color`, where
`color` must be one of: `red`, `green`, `yellow`, `blue`, `magenta`,
`cyan` or `white`.

After installation, the various source code samples in the `examples`
directory can be used to check that highlighting is working correctly.
If it doesn't work as expected, see the FAQ below.

Theme System
------------

All `*.nanorc` files are passed through [mixins.sed] and [theme.sed] before
installation. These scripts allow rules to be specified in terms of token
names or [mixins], instead of hard-coded colors.

For example, the following named rule:

TYPE: "int|bool|string"

becomes:

color green "int|bool|string"

and the following "mixin":

+BOOLEAN

becomes:

color brightcyan "\<(true|false)\>"

This system helps to keep colors uniform across different languages and
also to keep the definitions clear and maintainable, which is something that
becomes quite awkward using only plain [nanorc] files.

**Note:** if `~/.nanotheme` exists it will be used as a custom theme, in
place of [theme.sed]. A custom theme may also be specified by installing
with `make THEME=your-custom-theme.sed`. Themes must be valid sed scripts,
defining *all* color codes found in [theme.sed] in order to work correctly.

FAQ
----

### Why does syntax highlighting only work for a subset of supported files?

There appears to be a bug in older versions of nano that causes
highlighting to fail when `/etc/nanorc` and `~/.nanorc` both contain
`syntax` rules. The usual workaround is to remove all `syntax` and `include`
commands from one file or the other, or to use a newer version of nano.

### Why do I get weird errors when running nano < 2.1.5 on *BSD systems?

In order to reliably highlight keywords, this projects makes heavy use of
the GNU regex word boundary extensions (`\<` and `\>`). BSD implementations
also have these extensions but use a different, incompatible syntax
(`[[:<:]]` and `[[:>:]]`). Since version 2.1.5, nano can automatically
translate the GNU syntax to BSD syntax at run-time, but for the benefit of
people running a pre-2.1.5 version of nano on OS X or *BSD, the `.nanorc`
file itself can be translated by installing with `make BSDREGEX=1`.

### Why not use `\s` instead of the verbose `[[:space:]]` pattern?

Because nano compiles against the platform's native regex library and some
platforms don't support `\s` (as it's not required by POSIX [ERE]).

Unlicense
---------

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>


[GNU nano]: http://www.nano-editor.org/
[nanorc]: http://www.nano-editor.org/dist/v2.3/nanorc.5.html
[theme.sed]: https://github.com/nanorc/nanorc/tree/master/theme.sed
[mixins.sed]: https://github.com/nanorc/nanorc/tree/master/mixins.sed
[mixins]: https://github.com/nanorc/nanorc/tree/master/mixins
[ERE]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04
24 changes: 24 additions & 0 deletions awk.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax "awk" "\.awk$"
header "^#!.*bin/(env +)?awk( |$)"

VARIABLE: "\$[A-Za-z0-9_!@#$*?-]+"
VARIABLE: "\<(ARGC|ARGIND|ARGV|BINMODE|CONVFMT|ENVIRON|ERRNO|FIELDWIDTHS)\>"
VARIABLE: "\<(FILENAME|FNR|FS|IGNORECASE|LINT|NF|NR|OFMT|OFS|ORS)\>"
VARIABLE: "\<(PROCINFO|RS|RT|RSTART|RLENGTH|SUBSEP|TEXTDOMAIN)\>"
FUNCTION: "\<(function|extension|BEGIN|END)\>"
OPERATOR: "[-+*/%^|!=&<>?;:]|\\|\[|\]"
KEYWORD: "\<(for|if|while|do|else|in|delete|exit)\>"
KEYWORD: "\<(break|continue|return)\>"
FUNCTION: "\<(close|getline|next|nextfile|print|printf|system|fflush)\>"
FUNCTION: "\<(atan2|cos|exp|int|log|rand|sin|sqrt|srand)\>"
FUNCTION: "\<(asort|asorti|gensub|gsub|index|length|match)\>"
FUNCTION: "\<(split|sprintf|strtonum|sub|substr|tolower|toupper)\>"
FUNCTION: "\<(mktime|strftime|systime)\>"
FUNCTION: "\<(and|compl|lshift|or|rshift|xor)\>"
FUNCTION: "\<(bindtextdomain|dcgettext|dcngettext)\>"
REGEXP: "/.*[^\]/"
+STRING
ESCAPE: "\\."
+HASHCOMMENT
+TODO
+LINT
21 changes: 21 additions & 0 deletions c.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax "c" "\.(c(c|pp|xx)?|C)$" "\.(h(h|pp|xx)?|H)$" "\.ii?$"

+FUNCTION
MACRO: "\<[A-Z_][0-9A-Z_]+\>"
TYPE: "\<(float|double|bool|char|int|short|long|void|(un)?signed)\>"
TYPE: "\<[a-z0-9_]+_t\>"
KEYWORD: "\<(struct|enum|static|const|union|typedef|extern)\>"
KEYWORD: "\<(for|if|while|do|else|case|default|switch)\>"
KEYWORD: "\<(return|inline|sizeof|auto|register|volatile|restrict)\>"
KEYWORD: "\<(try|throw|catch|operator|new|delete)\>"
JUMP: "\<(goto|break|continue)\>"
+BOOLEAN
OPERATOR: "[-+/*=<>?:!~%&|^]"
NUMBER: "\<([0-9]+|0x[0-9a-fA-F]*)\>|'.'"
MACRO: "^[[:space:]]*#[[:space:]]*(define|include(_next)?|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)"
ATTRIBUTE: "__attribute__[[:space:]]*\(\([^)]*\)\)" "__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
STRING: ""(\\.|[^"])*"|<[A-Za-z_./-]+>"
ESCAPE: "\\([\"'abfnrtv\\]|[0-3]?[0-7]{1,2}|x[A-Fa-f0-9]{1,2}|$)"
+CCOMMENT
+TODO
+LINT
9 changes: 9 additions & 0 deletions cmake.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax "cmake" "CMakeLists\.txt$|\.cmake$"

+FUNCTION
BOOLEAN: "\<(ON|OFF|TRUE|FALSE|YES|NO)\>"
VARIABLE: "\$\{[A-Za-z0-9_!@#$*?-]+\}"
+STRING
ESCAPE: "\\([()#$^]|\\|\")"
+HASHCOMMENT
+LINT
15 changes: 15 additions & 0 deletions coffeescript.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax "coffeescript" "\.coffee$"
header "^#!.*/(env +)?coffee"

OPERATOR: "[!&|=/*+-<>]|\<(and|or|is|isnt|not)\>"
FUNCTION: "[A-Za-z_][A-Za-z0-9_]*:[[:space:]]*(->|\()" "->"
PLAIN: "[()]"
KEYWORD: "\<(for|of|continue|break|isnt|null|unless|this|else|if|return)\>"
KEYWORD: "\<(try|catch|finally|throw|new|delete|typeof|in|instanceof)\>"
KEYWORD: "\<(debugger|switch|while|do|class|extends|super)\>"
KEYWORD: "\<(undefined|then|unless|until|loop|of|by|when)\>"
BOOLEAN: "\<(true|false|yes|no|on|off)\>"
VARIABLE: "@[A-Za-z0-9_]*"
+STRING
+HASHCOMMENT
+LINT
17 changes: 17 additions & 0 deletions colortest.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax "colortest" "ColorTest$"

color black "\<PLAIN\>"

color red "\<red\>"
color green "\<green\>"
color yellow "\<yellow\>"
color blue "\<blue\>"
color magenta "\<magenta\>"
color cyan "\<cyan\>"

color brightred "\<brightred\>"
color brightgreen "\<brightgreen\>"
color brightyellow "\<brightyellow\>"
color brightblue "\<brightblue\>"
color brightmagenta "\<brightmagenta\>"
color brightcyan "\<brightcyan\>"
24 changes: 24 additions & 0 deletions csharp.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax "c#" "\.cs$"

# Class
SECTION: "class +[A-Za-z0-9]+ *((:) +[A-Za-z0-9.]+)?"

# Annotation
ESCAPE: "@[A-Za-z]+"

+FUNCTION
TYPE: "\<(bool|byte|sbyte|char|decimal|double|float|IntPtr|int|uint|long|ulong|object|short|ushort|string|base|this|var|void)\>"
KEYWORD: "\<(alias|as|case|catch|checked|default|do|dynamic|else|finally|fixed|for|foreach|goto|if|is|lock|new|null|return|switch|throw|try|unchecked|while)\>"
KEYWORD: "\<(abstract|async|class|const|delegate|enum|event|explicit|extern|get|implicit|in|internal|interface|namespace|operator|out|override|params|partial|private|protected|public|readonly|ref|sealed|set|sizeof|stackalloc|static|struct|typeof|unsafe|using|value|virtual|volatile|yield)\>"
# LINQ-only keywords (ones that cannot be used outside of a LINQ query - lots others can)
KEYWORD: "\<(from|where|select|group|info|orderby|join|let|in|on|equals|by|ascending|descending)\>"
JUMP: "\<(break|continue)\>"
+BOOLEAN
OPERATOR: "[-+/*=<>?:!~%&|]"
NUMBER: "\<([0-9._]+|0x[A-Fa-f0-9_]+|0b[0-1_]+)[FL]?\>"
+STRING
ESCAPE: "\\([btnfr]|'|\"|\\)"
ESCAPE: "\\u[A-Fa-f0-9]{4}"
+CCOMMENT
+TODO
+LINT
31 changes: 31 additions & 0 deletions css.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
syntax "css" "\.s?css$"

# Selectors
TYPE: "\<(a|abbr|address|area|article|aside|audio|b|base|bdo|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|command|datalist|dd|del|details|dfn|div|dl|dt|em|embed|eventsource|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|keygen|label|legend|li|link|mark|map|menu|meta|meter|nav|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|ruby|rp|rt|samp|script|section|select|small|source|span|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|ul|var|video|wbr)\>"
OPERATOR: "[>+~*]"
VARIABLE: "[.#][A-Za-z_][A-Za-z0-9_-]*"
OPERATOR: ":(active|focus|hover|link|visited|first-child|lang|valid|invalid|not|selection)\>"
OPERATOR: ":(after|before|first-line|first-letter|root|target)\>"
STRING: "\[[^\[]*\]"
PLAIN: start="\{" end="\}"

# Sass
SECTION: "(^|[[:space:]])@(include|mixin)\>"
VARIABLE: "\$[A-Za-z0-9_-]+"

SECTION: "(^|[[:space:]])@(charset|font-face|media|page|import)\>"
OPERATOR: "[*]"
BOOLEAN: "\<(above|absolute|always|armenian|auto|avoid|baseline|behind|below|bidi-override|blink|block|bolder|bold|bottom|capitalize|center-left|center-right|center|circle|cjk-ideographic|close-quote|collapse|compact|condensed|continuous|crop|crosshair|cross|cue-after|cue-before|cursive|dashed|decimal|decimal-leading-zero|default|digits|disc|dotted|double|embed|e-resize|expanded|extra-condensed|extra-expanded|fantasy|far-left|far-right|faster|fast|fixed|fixed|georgian|groove|hebrew|help|hide|higher|high|hiragana-iroha|hiragana|inherit|inline|inline-block|inline-table|inset|inside|invert|italic|justify|katakana-iroha|katakana|landscape|large|larger|left|left-side|leftwards|level|lighter|line-through|list-item|loud|lower-alpha|lowercase|lower-greek|lower-latin|lower-roman|lower|low|ltr|marker|medium|medium|middle|mix|monospace|move|narrower|ne-resize|no-close-quote|none|no-open-quote|no-repeat|normal|nowrap|n-resize|nw-resize|oblique|once|open-quote|outset|outside|overline|pointer|portait|relative|repeat-x|repeat-y|repeat|ridge|right-side|right|rightwards|rlt|run-in|sans-serif|scroll|scroll|semi-condensed|semi-expanded|separate|se-resize|serif|show|silent|slower|slow|small-caps|smaller|small|soft|solid|spell-out|square|s-resize|static|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|text-bottom|text|text-top|thick|thin|top|top|transparent|ultra-condensed|ultra-expanded|underline|upper-alpha|uppercase|upper-latin|upper-roman|visible|wait|wider|w-resize|x-fast|x-high|x-large|x-loud|x-low|x-slow|x-small|x-soft|xx-large|xx-small|pre-wrap|break-word)([[:space:];,]|$)"
VARIABLE: ":[[:space:]]*(code|hidden|table|pre)\>"
KEYWORD: "\<(background-attachment|background-clip|background-color|background-image|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-bottom|border-collapse|border-color|border-left-color|border-left-style|border-left-width|border-left|border-radius|border-right-color|border-right-style|border-right-width|border-right|border-spacing|border-style|border-top-color|border-top-style|border-top-width|border-top|border-width|border|bottom|box-shadow|box-sizing|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size-adjust|font-size|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|marker-offset|marks|max-height|max-width|min-height|min-width|opacity|orphans|outline-color|outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page|pause-after|pause-before|pause|pitch-range|pitch|play-during|position|quotes|richness|right|size|speak-header|speak-numerical|speak-punctuation|speak|speech-rate|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|transition|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|word-wrap|z-index)[[:space:]]*:"
WARNING: "-(ms|moz|apple|khtml|wap|webkit|o|xv)-[a-z][a-z-]+"
PLAIN: "[:;,]"
NUMBER: "\<(0|[\+-]?[1-9][0-9]*)"
NUMBER: "[\+-]?([0-9]+|[0-9]*\.[0-9]+)(%|e(m|x)|p(x|t|c)|in|ft|(m|c)m|k?Hz|deg|g?rad|m?s)"
NUMBER: "#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})\>"
OPERATOR: "\!important\>"
FUNCTION: "[a-z-]*(-[a-z]+)?\(" "\(|\)"
+STRING
+CCOMMENT
+TODO
+LINT
25 changes: 25 additions & 0 deletions cython.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax "cython" "\.(pyx|pxd|pyi)$"

+FUNCTION
KEYWORD: "\<(and|as|assert|break|class|continue|def|del|elif|else|except)\>"
KEYWORD: "\<(exec|finally|for|from|global|if|import|in|is|lambda|not|or)\>"
KEYWORD: "\<(pass|print|raise|return|try|while|with|yield|None)\>"
KEYWORD: "\<(DEF|ELIF|ELSE|IF)\>"

KEYWORD: "\<(cp?def( inline)?|cimport|cppclass|ctypedef|extern|include)\>"
KEYWORD: "\<(namespace|property|struct)\>"
TYPE: "\<(bint|char|double|int|public|void|unsigned)\>"

OPERATOR: "[.:;,+*|=!\%@<>/&-]"
MACRO: "@[A-Za-z0-9_]+"
SECTION: "__[A-Za-z0-9_]+__"
BOOLEAN: "\<(True|False)\>"
+STRING
STRING: "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
STRING: "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
STRING: start=""""[^"]" end="""""
STRING: start="'''[^']" end="'''"
ESCAPE: "\\.?"
+HASHCOMMENT
+TODO
+LINT
2 changes: 2 additions & 0 deletions default.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
syntax "default"
+LINT
7 changes: 7 additions & 0 deletions dot.nanorc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax "dot" "\.(dot|gv)$"

KEYWORD: "\<(digraph|edge|graph|node|subgraph)\>"
ATTRIBUTE: "\<(arrowhead|arrowsize|arrowtail|bgcolor|center|color|constraint|decorateP|dir|distortion|fillcolor|fontcolor|fontname|fontsize|headclip|headlabel|height|labelangle|labeldistance|labelfontcolor|labelfontname|labelfontsize|label|layers|layer|margin|mclimit|minlen|name|nodesep|nslimit|ordering|orientation|pagedir|page|peripheries|port_label_distance|rankdir|ranksep|rank|ratio|regular|rotate|samehead|sametail|shapefile|shape|sides|size|skew|style|tailclip|taillabel|URL|weight|width)\>"
OPERATOR: "=|->|--"
+STRING
+CCOMMENT
Loading

0 comments on commit ebe557e

Please sign in to comment.