From 1a25f9aa0125db1d506e7e92ab83e06754df75fa Mon Sep 17 00:00:00 2001 From: baabelfish Date: Fri, 5 Feb 2016 02:03:04 +0200 Subject: [PATCH] Added indendation --- README.md | 31 ++++++++++--------- autoload/features/repl.vim | 0 autoload/highlighter.vim | 2 +- compiler/nim.vim | 4 --- ftplugin/nim.vim | 9 +++++- indent/nim.vim | 63 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 autoload/features/repl.vim delete mode 100644 compiler/nim.vim create mode 100644 indent/nim.vim diff --git a/README.md b/README.md index 3ac7814..6804dce 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,8 @@ Nim support for Neovim # TODO - [x] Add global options for user -- [ ] Indendation -- [ ] Doc - - [ ] Bindings - - [ ] Options - - [ ] Commands - - [ ] Using with other plugins +- [x] Indendation - [ ] Syntax - [x] Keywords @@ -21,12 +16,8 @@ Nim support for Neovim - [x] Highlight variable names semantically - [ ] Multiline comments -- [ ] File based configuration - - [ ] Read project file - - [ ] Create project file - -- [ ] Compiler support - - [ ] Make with nim check +- [x] Compiler support + - [x] Make with nim check - [x] Nimsuggest - [x] Usages @@ -44,9 +35,6 @@ Nim support for Neovim - [x] NimRenameSymbol - [ ] NimRenameSymbolProject -- [ ] Misc - - [ ] Airline integration - - [ ] IDE features - [x] Neomake - [x] View online documentation @@ -119,6 +107,19 @@ Nim support for Neovim - [ ] NimRenameSymbol - [ ] NimRenameSymbolProject +- [ ] Doc + - [ ] Bindings + - [ ] Options + - [ ] Commands + - [ ] Using with other plugins + +- [ ] File based configuration + - [ ] Read project file + - [ ] Create project file + +- [ ] Misc + - [ ] Airline integration + # Roadmap ## v0.1 diff --git a/autoload/features/repl.vim b/autoload/features/repl.vim new file mode 100644 index 0000000..e69de29 diff --git a/autoload/highlighter.vim b/autoload/highlighter.vim index 2c8c902..aefa73d 100644 --- a/autoload/highlighter.vim +++ b/autoload/highlighter.vim @@ -86,7 +86,7 @@ function! s:NimHighlighter.on_exit() if has_key(s:highlights, ctype) if has_key(semantics_set, ctype) - call add(b:highlights, matchaddpos("Semantic" . util#djb(strpart(str, c - 1, s)) % 20, [[line, c, s]])) + call add(b:highlights, matchaddpos("Semantic" . abs(util#djb(strpart(str, c - 1, s))) % 20, [[line, c, s]])) else call add(b:highlights, matchaddpos(s:highlights[ctype], [[line, c, s]])) endif diff --git a/compiler/nim.vim b/compiler/nim.vim deleted file mode 100644 index 632501e..0000000 --- a/compiler/nim.vim +++ /dev/null @@ -1,4 +0,0 @@ -if exists("s:loaded") - finish -endif -let s:loaded = 1 diff --git a/ftplugin/nim.vim b/ftplugin/nim.vim index c8278db..83c136d 100644 --- a/ftplugin/nim.vim +++ b/ftplugin/nim.vim @@ -3,11 +3,18 @@ if exists("b:loaded") endif let b:loaded = 1 +setlocal iskeyword=a-z,A-Z,48-57,128-255,_ setlocal formatoptions-=t formatoptions+=l -setlocal comments=s1:#[,mb:#,ex:]#,:# +setlocal comments=s1:#[,mb:#,ex:]#,:#,:## setlocal commentstring=#\ %s setlocal expandtab setlocal omnifunc=omni#nim +setlocal makeprg=nim\ c\ --verbosity:0\ --colors:off\ % +setlocal errorformat= + \%-GHint:\ %m, + \%A%f(%l\\,\ %c)\ Hint:\ %m, + \%E%f(%l\\,\ %c)\ Error:\ %m, + \%W%f(%l\\,\ %c)\ Warning:\ %m command! NimDefinition :call features#definition#run() command! NimInfo :call features#info#run() diff --git a/indent/nim.vim b/indent/nim.vim new file mode 100644 index 0000000..5bde146 --- /dev/null +++ b/indent/nim.vim @@ -0,0 +1,63 @@ +" if exists("b:loaded") +" finish +" endif +" let b:loaded = 1 + +setlocal nolisp +setlocal autoindent +setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif +setlocal indentexpr=NimIndent() + +function! Down() + return indent(prevnonblank(v:lnum - 1)) - &tabstop +endfunction + +function! Up() + return (indent(prevnonblank(v:lnum - 1)) + &tabstop) +endfunction + +function! NimIndent() + let line = getline(v:lnum) + let prev = prevnonblank(v:lnum - 1) + let prevempty = getline(v:lnum - 1) =~ '^\s*$' + let prev2empty = getline(v:lnum - 2) =~ '^\s*$' + let prevl = getline(prev) + + if prev2empty && prevempty + return + endif + + if prevl =~ '\([:=\[({]\|and\|or\|not\|xor\|shl\|shr\|div\|mod\|in\|notin\|is\|isnot\|of\)\s*$' + return Up() + endif + + if prevl =~ '\s*\(import\|type\)' + return Up() + endif + + if prevl =~ '\s*\(const\|var\|let\)\s*$' + return Up() + endif + + if prevl =~ '\(object\|enum\|object\|concept\|tuple\)\s*$' + return Up() + endif + + if prevl =~ '^\(const\|var\|let\).*\s*if\s*.*$' + return Up() + endif + + if prevl =~ ',\s*$' + return -1 + endif + + if prevempty && prevl =~ '\s*\(result\|return\|break\|continue\|raise\)' + return Down() + endif + + if prevl =~ '[\])}]\s*$' + return Down() + endif + + return -1 +endfunction