various auto-indenting improvements; fixes #10
This commit is contained in:
parent
3d9f5fac08
commit
bebdd7bb99
2 changed files with 30 additions and 17 deletions
|
|
@ -48,7 +48,7 @@ endf
|
||||||
augroup NimrodVim
|
augroup NimrodVim
|
||||||
au!
|
au!
|
||||||
au BufEnter log://nimrod call s:UpdateNimLog()
|
au BufEnter log://nimrod call s:UpdateNimLog()
|
||||||
au QuitPre * :py nimTerminateAll()
|
" au QuitPre * :py nimTerminateAll()
|
||||||
au VimLeavePre * :py nimTerminateAll()
|
au VimLeavePre * :py nimTerminateAll()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,18 @@ if exists("*GetNimrodIndent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! s:FindStartLine(fromln, pattern)
|
||||||
|
let lnum = a:fromln
|
||||||
|
let safechoice = indent(lnum)
|
||||||
|
while getline(lnum) !~ a:pattern
|
||||||
|
if indent(lnum) == 0 || lnum == 1
|
||||||
|
return safechoice
|
||||||
|
endif
|
||||||
|
let lnum = lnum - 1
|
||||||
|
endwhile
|
||||||
|
return indent(lnum)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! GetNimrodIndent(lnum)
|
function! GetNimrodIndent(lnum)
|
||||||
" Search backwards for the previous non-empty line.
|
" Search backwards for the previous non-empty line.
|
||||||
let plnum = prevnonblank(a:lnum - 1)
|
let plnum = prevnonblank(a:lnum - 1)
|
||||||
|
|
@ -66,9 +78,21 @@ function! GetNimrodIndent(lnum)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if pline =~ ':\s*$'
|
if pline =~ ':\s*$'
|
||||||
\ || pline =~ '=\s*$'
|
"return s:FindStartLine(plnum, '(^\s*\(if\|when\|else\|elif\|case\|of\|try\|except\|finally\)\>)\|\<do\>') + &sw
|
||||||
\ || pline =~ '\(type\|import\|const\|var\)\s*$'
|
return s:FindStartLine(plnum, '^\s*\(if\|when\|else\|elif\|for\|while\|case\|of\|try\|except\|finally\)\>') + &sw
|
||||||
\ || pline =~ '=\s*\(object\|enum\)'
|
endif
|
||||||
|
|
||||||
|
if pline =~ '=\s*$'
|
||||||
|
return s:FindStartLine(plnum, '^\s*\(proc\|template\|macro\|iterator\)\>') + &sw
|
||||||
|
endif
|
||||||
|
|
||||||
|
" if we got here, this should be the begging of a multi-line if expression for example
|
||||||
|
if pline =~ '^\s*\(if\|when\|proc\|iterator\|macro\|template\|for\|while\)[^:]*$'
|
||||||
|
return plindent + &sw
|
||||||
|
endif
|
||||||
|
|
||||||
|
if pline =~ '\(type\|import\|const\|var\)\s*$'
|
||||||
|
\ || pline =~ '=\s*\(object\|enum\|tuple\|generic\)'
|
||||||
return plindent + &sw
|
return plindent + &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
@ -101,18 +125,7 @@ function! GetNimrodIndent(lnum)
|
||||||
|
|
||||||
" If the current line begins with a header keyword, dedent
|
" If the current line begins with a header keyword, dedent
|
||||||
if getline(a:lnum) =~ '^\s*\(elif\|else\)\>'
|
if getline(a:lnum) =~ '^\s*\(elif\|else\)\>'
|
||||||
|
return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)')
|
||||||
" Unless the previous line was a one-liner
|
|
||||||
"if getline(plnumstart) =~ '^\s*\(for\|if\|try\)\>'
|
|
||||||
"return plindent
|
|
||||||
"endif
|
|
||||||
|
|
||||||
" Or the user has already dedented
|
|
||||||
if clindent <= plindent - &sw
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
|
|
||||||
return plindent - &sw
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return -1
|
return -1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue