add s:remove_from_buffer_list()

This functions checks if a given key actually exists in our
s:active_buffers dictionary, because there might be buffers that weren't
added to it in the first place.

At the moment this is the case for Vim's help pages and buffers that
aren't associated with any filename.

Thanks for reporting, Jeremy Mack.

Closes #1.
This commit is contained in:
Marco Hinz 2013-03-07 00:45:22 +01:00
parent 9187b70098
commit e7338cd155

View File

@ -63,7 +63,7 @@ aug signify
au ColorScheme * call s:set_colors() au ColorScheme * call s:set_colors()
au BufWritePost * call s:start() au BufWritePost * call s:start()
au BufEnter * let s:colors_set_b = 0 | call s:start() au BufEnter * let s:colors_set_b = 0 | call s:start()
au BufDelete * call s:stop() | call remove(s:active_buffers, expand('%:p')) au BufDelete * call s:stop() | call s:remove_from_buffer_list(expand('%:p'))
aug END aug END
com! -nargs=0 -bar SignifyToggle call s:toggle_signify() com! -nargs=0 -bar SignifyToggle call s:toggle_signify()
@ -111,7 +111,6 @@ function! s:stop() abort
aug signify aug signify
au! * <buffer> au! * <buffer>
aug END aug END
let s:active_buffers[expand('%:p')] = 0
endfunction endfunction
" Functions -> s:toggle_signify() {{{2 " Functions -> s:toggle_signify() {{{2
@ -247,7 +246,14 @@ function! s:jump_to_prev_hunk()
let s:last_jump_was_next = 0 let s:last_jump_was_next = 0
endfunction endfunction
" Functions -> SignifyListActiveBuffers() {{{2 " Functions -> s:remove_from_buffer_list() {{{2
function! s:remove_from_buffer_list(path) abort
if has_key(s:active_buffers, a:path)
call remove(s:active_buffers, a:path)
endif
endfunction
" Functions -> SignifyListActiveBuffers() {{{2
function! SignifyListActiveBuffers() abort function! SignifyListActiveBuffers() abort
if len(s:active_buffers) == 0 if len(s:active_buffers) == 0
echo 'No active buffers!' echo 'No active buffers!'