Last active
January 14, 2022 20:33
-
-
Save Syncrossus/88524b0318555b380e8de65133ff972d to your computer and use it in GitHub Desktop.
My attempt at making a Monokai python syntax coloring for nano based on scopatz/nanorc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Python syntax highlighting rules for Nano | |
## The colors chosen here may seem strange. | |
## In my terminal, "yellow" = orange, "magenta" = purple, "brightyellow" = yellow, "cyan" = teal. | |
## Since there is no actual magenta, I used "brightred" which is the closest I could get. | |
## Since there is no grey, black is difficult to read in a terminal and setting the background to | |
## white is harsh on the eyes, I decided to use teal for comments. | |
syntax "python" "\.py$" | |
header "^#!.*/(env +)?python[-0-9._]*( |$)" | |
magic "Python script" | |
## definitions | |
color yellow start="^[[:space:]]*def " end="):" | |
color green "^[[:space:]]*def [a-zA-Z_0-9]+" | |
## built-in objects | |
color magenta "\<(None|self|True|False)\>" | |
## built-in attributes | |
color brightblue "\<(__builtin__|__dict__|__methods__|__members__|__class__|__bases__|__import__|__name__|__doc__|__self__|__debug__)\>" | |
## built-in functions | |
color brightblue "\<(abs|append|apply|buffer|callable|chr|clear|close|closed|cmp|coerce|compile|complex|conjugate|copy|count|delattr|dir|divmod|eval|execfile|exec|extend|fileno|filter|float|flush|get|getattr|globals|has_key|hasattr|hash|hex|id|index|input|insert|int|intern|isatty|isinstance|issubclass|items|keys|len|list|locals|long|map|max|min|mode|name|oct|open|ord|pop|pow|print|range|raw_input|read|readline|readlines|reduce|reload|remove|repr|reverse|round|seek|setattr|slice|softspace|sort|str|tell|truncate|tuple|type|unichr|unicode|update|values|vars|write|writelines|xrange|zip|bool)\>" | |
## built-in functions that were previously keywords | |
color brightblue "\<(print|exec)\>([[:space:]]|$)" | |
## special method names | |
color brightblue "\<(__abs__|__add__|__and__|__call__|__cmp__|__coerce__|__complex__|__concat__|__contains__|__del__|__delattr__|__delitem__|__delslice__|__div__|__divmod__|__float__|__getattr__|__getitem__|__getslice__|__hash__|__hex__|__init__|__int__|__inv__|__invert__|__len__|__long__|__lshift__|__mod__|__mul__|__neg__|__nonzero__|__oct__|__or__|__pos__|__pow__|__radd__|__rand__|__rcmp__|__rdiv__|__rdivmod__|__repeat__|__repr__|__rlshift__|__rmod__|__rmul__|__ror__|__rpow__|__rrshift__|__rshift__|__rsub__|__rxor__|__setattr__|__setitem__|__setslice__|__str__|__sub__|__xor__|__bool__)\>" | |
## exception classes | |
color brightblue "[a-zA-Z_0-9]*(Exception|Error)" | |
## types | |
color magenta "[a-zA-Z_0-9]*Type" | |
## keywords | |
color brightblue "\<(async|class|def|del|lambda|map)\>" | |
color brightred "\<(and|as|assert|await|break|continue|elif|else|except|finally|for|from|global|if|import|in|is|not|or|pass|raise|return|try|with|while|yield)\>" | |
## decorators | |
color blue "@.*[(]?" | |
color brightred "@" | |
## operators | |
color white "[.:;,]" | |
color brightred "[+*|=!%@]" "<" ">" "/" "-" "&" | |
## parentheses | |
color white "[(){}]" "\[" "\]" | |
## numbers | |
icolor magenta "\b(([1-9][0-9]+)|0+)\.[0-9]+j?\b" "\b([1-9][0-9]*[Lj]?)\b" "\b0o?[0-7]*L?\b" "\b0x[1-9a-f][0-9a-f]*L?\b" "\b0b[01]+\b" | |
## strings | |
color brightyellow "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}" "''" | |
color brightyellow "[\"][^\"]*[^\\][\"]" "[\"]{3}.*[^\\][\"]{3}" "\"\"" | |
## comments | |
color cyan "^#.*|[[:space:]]#.*$" | |
## block comments. | |
## Because beginning and end delimiters can't be the same, block comments should start with quadruple double quotes ( """" ) for highlighting to take effect | |
color cyan start="^[[:space:]][\"]{4}" end="[\"]{3}$" start="^[[:space:]][']{4}" end="[']{3}$" | |
## trailing spaces | |
color ,green "[[:space:]]+$" | |
## reminders | |
color brightwhite,yellow "(FIXME|TODO|XXX)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on scopatz/nanorc, subject to GNU GPL v3.