Skip to content

Commit

Permalink
Use shiftwidth() instead of 'shiftwidth'
Browse files Browse the repository at this point in the history
I'm using vim-sleuth[1] from tpope to automatically detect indent
settings for files that I edit. The latest version sets 'shiftwidth' to
zero for files that are detected to be indented only with hard tabs, so
that the value of 'tabstop' is used instead of 'shiftwidth'. This
change[2] was done to allow people setting 'tabstop' to their preferred
value, and to have 'shiftwidth' automatically follow.

The vim documentation about 'shiftwidth' states:

   When zero the 'ts' value will be used.  Use the shiftwidth()
   function to get the effective shiftwidth value.

Therefore this commit changes using 'sw' directly and instead calls
shiftwidth().

[1] https://github.com/tpope/vim-sleuth
[2] tpope/vim-sleuth@b6b4c3b
  • Loading branch information
fd0 committed Feb 7, 2015
1 parent 5dc0a78 commit 229130c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions indent/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,29 @@ function! GoIndent(lnum)
let previ = indent(prevlnum)

let ind = previ
let s:shiftwidth = shiftwidth()

if prevl =~ '[({]\s*$'
" previous line opened a block
let ind += &sw
let ind += s:shiftwidth
endif
if prevl =~# '^\s*\(case .*\|default\):$'
" previous line is part of a switch statement
let ind += &sw
let ind += s:shiftwidth
endif
" TODO: handle if the previous line is a label.

if thisl =~ '^\s*[)}]'
" this line closed a block
let ind -= &sw
let ind -= s:shiftwidth
endif

" Colons are tricky.
" We want to outdent if it's part of a switch ("case foo:" or "default:").
" 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:shiftwidth
endif

return ind
Expand Down

0 comments on commit 229130c

Please sign in to comment.