more auto-indenting improvements
This commit is contained in:
parent
bebdd7bb99
commit
f947b48cda
1 changed files with 27 additions and 21 deletions
|
|
@ -43,6 +43,7 @@ function! GetNimrodIndent(lnum)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let pline = getline(plnum)
|
let pline = getline(plnum)
|
||||||
|
let cline = getline(a:lnum)
|
||||||
let pline_len = strlen(pline)
|
let pline_len = strlen(pline)
|
||||||
let plindent = indent(plnum)
|
let plindent = indent(plnum)
|
||||||
let clindent = indent(a:lnum)
|
let clindent = indent(a:lnum)
|
||||||
|
|
@ -77,6 +78,32 @@ function! GetNimrodIndent(lnum)
|
||||||
endwhile
|
endwhile
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if cline =~ '^\s*\(if\|when\|for\|while\|case\|of\|try\)\>'
|
||||||
|
" This is a benign line, do nothing
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If the current line begins with a keyword that lines up with "try"
|
||||||
|
if cline =~ '^\s*\(except\|finally\)\>'
|
||||||
|
let lnum = a:lnum - 1
|
||||||
|
while lnum >= 1
|
||||||
|
if getline(lnum) =~ '^\s*\(try\|except\)\>'
|
||||||
|
let ind = indent(lnum)
|
||||||
|
if ind >= clindent
|
||||||
|
return -1 " indent is already less than this
|
||||||
|
endif
|
||||||
|
return ind " line up with previous try or except
|
||||||
|
endif
|
||||||
|
let lnum = lnum - 1
|
||||||
|
endwhile
|
||||||
|
return -1 " no matching "try"!
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If the current line begins with a header keyword, dedent
|
||||||
|
if cline =~ '^\s*\(elif\|else\)\>'
|
||||||
|
return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)')
|
||||||
|
endif
|
||||||
|
|
||||||
if pline =~ ':\s*$'
|
if pline =~ ':\s*$'
|
||||||
"return s:FindStartLine(plnum, '(^\s*\(if\|when\|else\|elif\|case\|of\|try\|except\|finally\)\>)\|\<do\>') + &sw
|
"return s:FindStartLine(plnum, '(^\s*\(if\|when\|else\|elif\|case\|of\|try\|except\|finally\)\>)\|\<do\>') + &sw
|
||||||
return s:FindStartLine(plnum, '^\s*\(if\|when\|else\|elif\|for\|while\|case\|of\|try\|except\|finally\)\>') + &sw
|
return s:FindStartLine(plnum, '^\s*\(if\|when\|else\|elif\|for\|while\|case\|of\|try\|except\|finally\)\>') + &sw
|
||||||
|
|
@ -107,27 +134,6 @@ function! GetNimrodIndent(lnum)
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If the current line begins with a keyword that lines up with "try"
|
|
||||||
if getline(a:lnum) =~ '^\s*\(except\|finally\)\>'
|
|
||||||
let lnum = a:lnum - 1
|
|
||||||
while lnum >= 1
|
|
||||||
if getline(lnum) =~ '^\s*\(try\|except\)\>'
|
|
||||||
let ind = indent(lnum)
|
|
||||||
if ind >= clindent
|
|
||||||
return -1 " indent is already less than this
|
|
||||||
endif
|
|
||||||
return ind " line up with previous try or except
|
|
||||||
endif
|
|
||||||
let lnum = lnum - 1
|
|
||||||
endwhile
|
|
||||||
return -1 " no matching "try"!
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If the current line begins with a header keyword, dedent
|
|
||||||
if getline(a:lnum) =~ '^\s*\(elif\|else\)\>'
|
|
||||||
return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)')
|
|
||||||
endif
|
|
||||||
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue