Search code examples
julianano

Syntax highlighting support for Julia in Nano


I use the minimal Nano text editor quite frequently. Recently, I've began to experiment with the young Julia programming language, but found that the .ji extension does not trigger appropriate highlighting in the editor environment as it does for recognized languages like Python.

Does syntax highlighting support exist for Julia x Nano? If it does not, how could I go about adding syntax highlighting support for a new language to Nano? Is there a standard template for each language?


Solution

  • Quoting Matt B.'s comment, see Google's top result for nano julia syntax is this reddit thread.

    Just copy and paste this into your .nanorc (typically located in ~/.nanorc):

    syntax "julia" "\.jl$"
    
    color brightblack  "\<(begin|break|catch|continue|function|elseif|else|end)\>"
    color brightblack  "\<(finally|for|global|local|if|include|using|require|macro)\>"
    color brightblack  "\<(println|return|try|type|while|module)\>"
    color brightblue "[A-Za-z_][A-Za-z0-9_]*[[:space:]]*[(]"
    color white    "[(]"
    color red "[-+*/|=%<>&~^]|\<(and|not|or|is|in)\>"
    color brightyellow    "@[A-Za-z0-9_]+"
    color brightmagenta  "__[A-Za-z0-9_]+__"
    color brightcyan  "\<(true|false)\>"
    color yellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
    color yellow   "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
    color yellow   "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
    color yellow   start=""""[^"]" end="""""
    color yellow   start="'''[^']" end="'''"
    color magenta   "\\.?"
    color cyan "(^|[[:space:]])#([^{].*)?$"
    color brightwhite,cyan "TODO:?"
    

    See https://github.com/Naereen/nanorc/blob/master/julia.nanorc for an updated version.