Use shiftwidth() instead of &shiftwidth

The `shiftwidth` option can be set to 0, in which case the tabstop value
is used instead. In order to always set the correct shiftwidth, the Vim
docs advise the use of the `shiftwidth()` function.
This commit is contained in:
Patrice Peterson 2014-04-21 10:59:51 +02:00
parent 825853f481
commit 986fcb1e1f

View file

@ -1,4 +1,5 @@
function! fish#Indent()
let l:shiftwidth = shiftwidth()
let l:prevlnum = prevnonblank(v:lnum - 1)
if l:prevlnum ==# 0
return 0
@ -6,15 +7,15 @@ function! fish#Indent()
let l:indent = 0
let l:prevline = getline(l:prevlnum)
if l:prevline =~# '\v^\s*switch>'
let l:indent = &shiftwidth * 2
let l:indent = l:shiftwidth * 2
elseif l:prevline =~# '\v^\s*%(begin|if|else|while|for|function|case)>'
let l:indent = &shiftwidth
let l:indent = l:shiftwidth
endif
let l:line = getline(v:lnum)
if l:line =~# '\v^\s*end>'
return indent(v:lnum) - (l:indent ==# 0 ? &shiftwidth : l:indent)
return indent(v:lnum) - (l:indent ==# 0 ? l:shiftwidth : l:indent)
elseif l:line =~# '\v^\s*%(case|else)>'
return indent(v:lnum) - &shiftwidth
return indent(v:lnum) - l:shiftwidth
endif
return indent(l:prevlnum) + l:indent
endfunction