The indent/tcl.vim file needs an improvement. I already contacted Nikolai
Weibull and he told me he's the previous maintainer and not the current
maintainer. How do I find out who is maintaining the runtime/indent files?
Lines 59-60:
elseif line =~ '^\s*}'
return indent(v:lnum) - shiftwidth()
...if a line starts with a closing brace, then it should be de-indented one
shiftwidth relative to the previous line. This code does the de-indentation
relative to the current line without regard to the previous line.
This works okay as you're interactively typing in Tcl code, but it won't
correct existing code that is not indented enough.
Here's a patch that fixes the problem. I also added a condition for line
continuation slash markers.
diff --git a/runtime/indent/tcl.vim b/runtime/indent/tcl.vim
index e9d61e436..e43663fee 100644
--- a/runtime/indent/tcl.vim
+++ b/runtime/indent/tcl.vim
@@ -1,7 +1,8 @@
" Vim indent file
" Language: Tcl
-" Maintainer: Nikolai Weibull <[email protected]>
-" Latest Revision: 2006-12-20
+" Previous Maintainer: Nikolai Weibull <[email protected]>
+" Latest Update: Chris Heithoff <[email protected]>
+" 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
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.