Add the buffer number as an argument to sy#stop()

sy#stop() is called by the BufDelete autocmd so b: variables may not
correspond to the buffer actually being deleted.  Instead, we must use
<abuf> to determine which buffer is being deleted and pass that into
sy#stop().

There are some ripple effects, causing sy#sign#remove_all_signs to also
gain a buffer number argument.

Signed-off-by: James McCoy <vega.james@gmail.com>
This commit is contained in:
James McCoy 2014-11-25 11:25:40 -05:00
parent 52cb36801d
commit c61dded98a
3 changed files with 13 additions and 10 deletions

View File

@ -88,15 +88,16 @@ function! sy#start() abort
endfunction
" Function: #stop {{{1
function! sy#stop() abort
if !exists('b:sy')
function! sy#stop(bufnr) abort
let sy = getbufvar(a:bufnr, 'sy')
if empty(sy)
return
endif
call sy#sign#remove_all_signs()
call sy#sign#remove_all_signs(a:bufnr)
augroup signify
execute printf('autocmd! * <buffer=%d>', b:sy.buffer)
execute printf('autocmd! * <buffer=%d>', sy.buffer)
augroup END
endfunction
@ -108,7 +109,7 @@ function! sy#toggle() abort
endif
if b:sy.active
call sy#stop()
call sy#stop(b:sy.buffer)
let b:sy.active = 0
let b:sy.stats = [-1, -1, -1]
else

View File

@ -189,15 +189,17 @@ function! sy#sign#process_diff(diff) abort
endfunction
" Function: #remove_all_signs {{{1
function! sy#sign#remove_all_signs() abort
for hunk in b:sy.hunks
function! sy#sign#remove_all_signs(bufnr) abort
let sy = getbufvar(a:bufnr, 'sy')
for hunk in sy.hunks
for id in hunk.ids
execute 'sign unplace' id
endfor
endfor
let b:sy.hunks = []
let b:sy.stats = [0, 0, 0]
let sy.hunks = []
let sy.stats = [0, 0, 0]
endfunction
" Function: s:add_sign {{{1

View File

@ -17,7 +17,7 @@ augroup signify
autocmd!
autocmd BufRead,BufWritePost * call sy#start()
autocmd BufDelete * call sy#stop()
autocmd BufDelete * call sy#stop(expand('<abuf>'))
autocmd QuickFixCmdPre *vimgrep* let g:signify_locked = 1
autocmd QuickFixCmdPost *vimgrep* let g:signify_locked = 0