diff runtime/indent/tcl.vim @ 15131:bc1a8d21c811

Update runtime files. commit https://github.com/vim/vim/commit/d47d52232bf21036c5c89081458be7eaf2630d24 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 9 20:43:55 2018 +0100 Update runtime files.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Dec 2018 20:45:05 +0100
parents d0a20101ecb2
children 834b7854aa3c
line wrap: on
line diff
--- 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