Fix incorrect setbufvar with invalid bufname expr.

When bufname contains |file-pattern|, setbufvar() might raise E16
Invalid Range error.

Use setbufvar("", ...) instead of setbufvar(bufname_string, ...).
This commit is contained in:
bootleq 2013-04-10 14:03:25 +08:00
parent 667a668e11
commit 1d773b0dfe

View File

@ -118,19 +118,17 @@
let s:var_reset = {} let s:var_reset = {}
endif endif
let buf = bufname("")
if a:0 == 0 && has_key(s:var_reset, a:var) if a:0 == 0 && has_key(s:var_reset, a:var)
" Reset var to original value " Reset var to original value
call setbufvar(buf, a:var, s:var_reset[a:var]) call setbufvar("", a:var, s:var_reset[a:var])
elseif a:0 == 1 elseif a:0 == 1
let new_value = a:0 == 1 ? a:1 : '' let new_value = a:0 == 1 ? a:1 : ''
" Store original value " Store original value
let s:var_reset[a:var] = getbufvar(buf, a:var) let s:var_reset[a:var] = getbufvar("", a:var)
" Set new var value " Set new var value
call setbufvar(buf, a:var, new_value) call setbufvar("", a:var, new_value)
endif endif
endfunction " }}} endfunction " }}}
function! s:SetLines(lines, key) " {{{ function! s:SetLines(lines, key) " {{{