summaryrefslogtreecommitdiff
path: root/misc/vim/indent/go.vim
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2014-06-19 09:23:02 +0200
committerMichael Stapelberg <stapelberg@debian.org>2014-06-19 09:23:02 +0200
commit8fcc691d6fa80c9ddf38bf0d34b803bab0e421d5 (patch)
treeba71646a10b518372d110532d86fcf0b98edc14f /misc/vim/indent/go.vim
parent3bb719bbf3cdb97b3901f3baaa2da9d02a5c3cdb (diff)
parent8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (diff)
downloadgolang-8fcc691d6fa80c9ddf38bf0d34b803bab0e421d5.tar.gz
Merge tag 'upstream/1.3' into debian-sid
Upstream version 1.3
Diffstat (limited to 'misc/vim/indent/go.vim')
-rw-r--r--misc/vim/indent/go.vim20
1 files changed, 16 insertions, 4 deletions
diff --git a/misc/vim/indent/go.vim b/misc/vim/indent/go.vim
index faf4d79e2..e3d6e8416 100644
--- a/misc/vim/indent/go.vim
+++ b/misc/vim/indent/go.vim
@@ -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