]> Cypherpunks repositories - gostls13.git/commitdiff
misc/vim: use shiftwidth() instead of &sw if available.
authorShenghou Ma <minux.ma@gmail.com>
Tue, 17 Dec 2013 01:05:48 +0000 (20:05 -0500)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 17 Dec 2013 01:05:48 +0000 (20:05 -0500)
Fixes #6841.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/43010044

misc/vim/indent/go.vim

index faf4d79e25aef66f570522692f734dad4209c58e..e3d6e841690cb9a96e74cd721e50a15a3dddb7c2 100644 (file)
@@ -24,6 +24,18 @@ if exists("*GoIndent")
   finish
 endif
 
+" The shiftwidth() function is relatively new.
+" Don't require it to exist.
+if exists('*shiftwidth')
+  func s:sw()
+    return shiftwidth()
+  endfunc
+else
+  func s:sw()
+    return &shiftwidth
+  endfunc
+endif
+
 function! GoIndent(lnum)
   let prevlnum = prevnonblank(a:lnum-1)
   if prevlnum == 0
@@ -40,17 +52,17 @@ function! GoIndent(lnum)
 
   if prevl =~ '[({]\s*$'
     " previous line opened a block
-    let ind += &sw
+    let ind += s:sw()
   endif
   if prevl =~# '^\s*\(case .*\|default\):$'
     " previous line is part of a switch statement
-    let ind += &sw
+    let ind += s:sw()
   endif
   " TODO: handle if the previous line is a label.
 
   if thisl =~ '^\s*[)}]'
     " this line closed a block
-    let ind -= &sw
+    let ind -= s:sw()
   endif
 
   " Colons are tricky.
@@ -58,7 +70,7 @@ function! GoIndent(lnum)
   " We ignore trying to deal with jump labels because (a) they're rare, and
   " (b) they're hard to disambiguate from a composite literal key.
   if thisl =~# '^\s*\(case .*\|default\):$'
-    let ind -= &sw
+    let ind -= s:sw()
   endif
 
   return ind