diff --git a/README.md b/README.md index 3f9ca8d..01dd852 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Attempt at writing an async outline/structure listing/navigator for files/module # TODO For advanced - [ ] Syntax with nim compiler highlight using matchaddpos ?? +- [ ] Highlight variable names semantically - [ ] Outline with unite - [ ] Outline with proper tagbar - [ ] Usages with unite diff --git a/autoload/highlighter.vim b/autoload/highlighter.vim index 62efe00..7f30ffa 100644 --- a/autoload/highlighter.vim +++ b/autoload/highlighter.vim @@ -90,7 +90,7 @@ endfunction function! highlighter#guard() - if line("$") + 0 < 500 - call highlighter#New() - endif + " if line("$") + 0 < 500 + " call highlighter#New() + " endif endfunction diff --git a/compiler/nim.vim b/compiler/nim.vim new file mode 100644 index 0000000..e69de29 diff --git a/ftplugin/nim.vim b/ftplugin/nim.vim index c2502f0..59102fb 100644 --- a/ftplugin/nim.vim +++ b/ftplugin/nim.vim @@ -1,3 +1,12 @@ +" if exists("b:loaded") +" finish +" endif +let b:loaded = 1 + +setlocal formatoptions-=t formatoptions+=l +setlocal comments=s1:#[,mb:#,ex:]#,:# +setlocal commentstring=#\ %s +setlocal expandtab command! NimDefinition :call features#definition#run() command! NimInfo :call features#info#run() diff --git a/syntax/nim.vim b/syntax/nim.vim index d921148..9d9c516 100644 --- a/syntax/nim.vim +++ b/syntax/nim.vim @@ -1,37 +1,127 @@ -if exists("b:current_syntax") - finish -endif - -syntax keyword nimKeyword let const var -syntax keyword nimKeyword addr and as asm atomic -syntax keyword nimKeyword bind block break -syntax keyword nimKeyword case cast concept const continue converter -syntax keyword nimKeyword defer discard distinct div do -syntax keyword nimKeyword elif else end enum except export -syntax keyword nimKeyword finally for from func -syntax keyword nimKeyword generic -syntax keyword nimKeyword if import in include interface is isnot iterator -syntax keyword nimKeyword let -syntax keyword nimKeyword macro method mixin mod -syntax keyword nimKeyword nil not notin -syntax keyword nimKeyword object of or out -syntax keyword nimKeyword proc ptr -syntax keyword nimKeyword raise ref return -syntax keyword nimKeyword shl shr static -syntax keyword nimKeyword template try tuple type -syntax keyword nimKeyword using -syntax keyword nimKeyword var -syntax keyword nimKeyword when while with without -syntax keyword nimKeyword xor -syntax keyword nimKeyword yield - -syntax keyword nimBuiltinFunction echo - -syntax keyword nimOperator and or not xor shl shr div mod in notin is isnot of. -" syntax keyword nimOperator =+-*/<>@$~&%|!?^.:\ - -highlight link nimOperator Operator -highlight link nimKeyword Keyword -highlight link nimBuiltinFunction Function +" if exists("b:current_syntax") +" finish +" endif +" if version < 600 +" syntax +" endif let b:current_syntax = "nim" + + +" Keywords +syntax keyword nimKeyword let const var static +syntax keyword nimKeyword addr asm atomic bind cast converter +syntax keyword nimKeyword defer discard distinct do end generic iterator +syntax keyword nimKeyword typedesc out ptr raise ref return using with without yield + +" syntax keyword nimOperator for while +syntax keyword nimBoolean true false +syntax keyword nimConditional if elif else case continue break +syntax keyword nimDefine from as +syntax keyword nimException try except finally +syntax keyword nimInclude import include export +syntax keyword nimLabel of +syntax keyword nimMacro macro +syntax keyword nimPreCondit when block +syntax keyword nimPreProc nil +syntax keyword nimRepeat for while +syntax keyword nimStorage tuple enum object interface concept mixin +syntax keyword nimStorageClass type +syntax keyword nimTypedef func proc method template + +syntax keyword nimTodo TODO FIXME + + +" Operators +syntax match nimOperatorAll "[&:?!@<>\|\~\.\^\=\/\+\-\*\$%]\+" +syntax keyword nimOperator and or not xor shl shr div mod in notin is isnot of. +syntax keyword nimOP9 div mod shl shr +syntax keyword nimOP5 in notin is isnot not of +syntax keyword nimOP4 and +syntax keyword nimOP3 or xor +syntax match nimOP10 "[\$\^]" +syntax match nimOP9 "[\*\%\\\/]" +syntax match nimOP6 "\." +syntax match nimOP5 "[=|<|>]" +syntax match nimOP5 "\v([!<>]\=)" +syntax match nimOP2 "[@:?]" +syntax match nimOP1 "[\*+\/%&]=" +syntax match nimOP0 "=>" +syntax match nimOP0 "\->" + + +" Comments +syntax match nimComment "\v#.*$" contains=nimTodo + + +" Builtin +syntax keyword nimBuiltinFunction echo debugEcho + +syntax keyword nimBuiltinType seq + + +" Numbers +syntax match nimNumber "\v[0-9_]+((i|I|u|U)(8|16|32|64))?>" +syntax match nimFloat "\v[0-9_]+(f|d|F|D)>" +syntax match nimFloat "\v[0-9_]+\.[0-9]+(f|d|F|D)>" +syntax match nimFloat "\v[0-9_]+((f|F)(32|64|128))>" +syntax match nimFloat "\v[0-9_]+\.[0-9]+((f|F)(32|64|128))?>" + + +" Tokens +syntax match nimToken "`" +syntax match nimToken "(" +syntax match nimToken ")" +syntax match nimToken "{" +syntax match nimToken "}" +syntax match nimToken "\[" +syntax match nimToken "\]" +syntax match nimToken "," +syntax match nimToken ";" +syntax match nimToken "\[\." +syntax match nimToken "\.\]" +syntax match nimToken "{\." +syntax match nimToken "\.}" +syntax match nimToken "(\." +syntax match nimToken "\.)" + + +" Linking +highlight link nimBuiltinFunction Function +highlight link nimBuiltinType Type +highlight link nimComment Comment +highlight link nimKeyword Keyword +highlight link nimTodo Todo +highlight link nimOperatorAll Operator +highlight link nimOP10 Operator10 +highlight link nimOP9 Operator9 +highlight link nimOP8 Operator8 +highlight link nimOP7 Operator7 +highlight link nimOP6 Operator6 +highlight link nimOP5 Operator5 +highlight link nimOP4 Operator4 +highlight link nimOP3 Operator3 +highlight link nimOP2 Operator2 +highlight link nimOP1 Operator1 +highlight link nimOP0 Operator0 +highlight link nimToken Delimiter +highlight link nimSuffix SpecialChar +highlight link nimBoolean Boolean +highlight link nimFloat Float +highlight link nimString String +highlight link nimChar Char +highlight link nimNumber Number + +highlight link nimConditional Conditional +highlight link nimConstant Constant +highlight link nimDefine Define +highlight link nimException Exception +highlight link nimInclude Include +highlight link nimLabel Label +highlight link nimMacro Macro +highlight link nimPreCondit PreCondit +highlight link nimPreProc PreProc +highlight link nimRepeat Repeat +highlight link nimStorage Structure +highlight link nimStorageClass StorageClass +highlight link nimTypedef Typedef