Skip to content

Commit

Permalink
Adding nano syntax highlightint
Browse files Browse the repository at this point in the history
  • Loading branch information
ngash committed Mar 9, 2014
1 parent 2364eb0 commit 698db91
Show file tree
Hide file tree
Showing 154 changed files with 2,804 additions and 0 deletions.
68 changes: 68 additions & 0 deletions nano/.nanorc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,71 @@ set nowrap
set smooth
set softwrap

include /home/barbossa/nanorc/scopatz_nanorc/apacheconf.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/asciidoc.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/asm.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/awk.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/c.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/cmake.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/coffeescript.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/colortest.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/conf.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/csharp.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/css.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/cython.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/dot.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/email.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/fish.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/fortran.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/gentoo.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/git.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/gitcommit.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/glsl.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/go.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/groff.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/haml.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/html.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/ini.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/inputrc.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/java.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/javascript.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/js.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/json.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/keymap.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/kickstart.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/ledger.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/lisp.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/lua.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/makefile.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/man.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/markdown.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/mpdconf.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/mutt.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/nanorc.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/nginx.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/patch.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/peg.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/perl.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/php.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/pkg-config.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/pkgbuild.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/po.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/pov.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/privoxy.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/python.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/reST.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/rpmspec.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/ruby.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/sed.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/sh.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/sql.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/systemd.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/tex.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/vala.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/vi.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/xml.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/xresources.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/yaml.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/yum.nanorc
include /home/barbossa/nanorc/scopatz_nanorc/zshrc.nanorc

1 change: 1 addition & 0 deletions nano/nanorc/nanorc_nanorc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
41 changes: 41 additions & 0 deletions nano/nanorc/nanorc_nanorc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
THEME = theme.sed
FILTER = sed -f mixins.sed | sed -f $(THEME)

install: ~/.nano/syntax.nanorc

install-separate: $(addprefix ~/.nano/syntax/, $(wildcard *.nanorc))

~/.nano/syntax.nanorc: *.nanorc mixins/*.nanorc $(THEME) | ~/.nano/
@cat *.nanorc | $(FILTER) > $@
@grep '^include $@' ~/.nanorc >/dev/null 2>&1 || \
echo 'include $@' >> ~/.nanorc
@echo 'Installed: $@'

~/.nano/syntax/%.nanorc: %.nanorc mixins/*.nanorc $(THEME) | ~/.nano/syntax/
@cat $< | $(FILTER) > $@
@echo 'Installed: $@'

~/.nano/ ~/.nano/syntax/:
@mkdir -p $@


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: install install-separate ~/.nano/syntax.nanorc
145 changes: 145 additions & 0 deletions nano/nanorc/nanorc_nanorc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
Project Status
==============

I am no longer using nano as my editor and hence have little motivation
to continue working on this project. I will answer GitHub issues and fix
existing bugs, but beyond that, please consider this repository only an
archive.

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.

Screenshots:
------------

#### Editing HTML:

![HTML Screenshot](http://cra.igbarn.es/img/nanorc-html.png)

#### Editing C:

![C Screenshot](http://cra.igbarn.es/img/nanorc-c.png)

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

Using `make install` will concatenate and install the syntax definitions
to `~/.nano/syntax.nanorc` and append an `include` command to
`~/.nanorc`, if necessary.

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, use `nano examples/*` to test if everything is
working properly. If some or all of the files aren't highlighted properly,
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][issue #5] 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`
lines from `/etc/nanorc`.

### Why do I get wierd 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/craigbarnes/nanorc/tree/master/theme.sed
[mixins.sed]: https://github.com/craigbarnes/nanorc/tree/master/mixins.sed
[mixins]: https://github.com/craigbarnes/nanorc/tree/master/mixins
[issue #5]: https://github.com/craigbarnes/nanorc/issues/5
[issue #25]: https://github.com/craigbarnes/nanorc/issues/25
[ERE]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04
24 changes: 24 additions & 0 deletions nano/nanorc/nanorc_nanorc/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 nano/nanorc/nanorc_nanorc/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 nano/nanorc/nanorc_nanorc/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 nano/nanorc/nanorc_nanorc/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 nano/nanorc/nanorc_nanorc/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 nano/nanorc/nanorc_nanorc/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
Loading

0 comments on commit 698db91

Please sign in to comment.