diff options
Diffstat (limited to 'runtime/indent/tcl.vim')
-rw-r--r-- | runtime/indent/tcl.vim | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/runtime/indent/tcl.vim b/runtime/indent/tcl.vim index e9d61e4366..d77081841d 100644 --- a/runtime/indent/tcl.vim +++ b/runtime/indent/tcl.vim @@ -1,7 +1,8 @@ " Vim indent file -" Language: Tcl -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: Tcl +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Update: Chris Heithoff <chrisheithoff@gmail.com> +" Latest Revision: 2018-12-05 if exists("b:did_indent") finish @@ -28,6 +29,15 @@ function s:prevnonblanknoncomment(lnum) return lnum endfunction +function s:ends_with_backslash(lnum) + let line = getline(a:lnum) + if line =~ '\\\s*$' + return 1 + else + return 0 + endif +endfunction + function s:count_braces(lnum, count_open) let n_open = 0 let n_close = 0 @@ -53,23 +63,39 @@ endfunction function GetTclIndent() let line = getline(v:lnum) - if line =~ '^\s*\*' - return cindent(v:lnum) - elseif line =~ '^\s*}' - return indent(v:lnum) - shiftwidth() - endif + " Get the line number of the previous non-blank or non-comment line. let pnum = s:prevnonblanknoncomment(v:lnum - 1) if pnum == 0 return 0 endif - let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() + " ..and the previous line before the previous line. + let pnum2 = s:prevnonblanknoncomment(pnum-1) - let pline = getline(pnum) - if pline =~ '}\s*$' - let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth() + " Default indentation is to preserve the previous indentation. + let ind = indent(pnum) + + " ...but if previous line introduces an open brace, then increase current line's indentation + if s:count_braces(pnum, 1) > 0 + let ind += shiftwidth() + else + " Look for backslash line continuation on the previous two lines. + let slash1 = s:ends_with_backslash(pnum) + let slash2 = s:ends_with_backslash(pnum2) + if slash1 && !slash2 + " If the previous line begins a line continuation. + let ind += shiftwidth() + elseif !slash1 && slash2 + " If two lines ago was the end of a line continuation group of lines. + let ind -= shiftwidth() + endif endif + " If the current line begins with a closed brace, then decrease the indentation by one. + if line =~ '^\s*}' + let ind -= shiftwidth() + endif + return ind endfunction |