Fix enabling buffer when plugin disabled

Fixes #803.
This commit is contained in:
Andy Stewart
2022-02-02 10:58:53 +00:00
parent 54b94f98de
commit 23a65f370b
2 changed files with 24 additions and 13 deletions

View File

@@ -21,6 +21,10 @@ endfunction
function! gitgutter#process_buffer(bufnr, force) abort
" NOTE a:bufnr is not necessarily the current buffer.
if gitgutter#utility#getbufvar(a:bufnr, 'enabled', -1) == -1
call gitgutter#utility#setbufvar(a:bufnr, 'enabled', g:gitgutter_enabled)
endif
if gitgutter#utility#is_active(a:bufnr)
if has('patch-7.4.1559')
@@ -55,12 +59,11 @@ endfunction
function! gitgutter#disable() abort
" get list of all buffers (across all tabs)
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
call s:clear(bufnr)
call gitgutter#buffer_disable(bufnr)
endif
endif
endfor
@@ -69,8 +72,16 @@ function! gitgutter#disable() abort
endfunction
function! gitgutter#enable() abort
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#buffer_enable(bufnr)
endif
endif
endfor
let g:gitgutter_enabled = 1
call gitgutter#all(1)
endfunction
function! gitgutter#toggle() abort
@@ -82,23 +93,24 @@ function! gitgutter#toggle() abort
endfunction
function! gitgutter#buffer_disable() abort
let bufnr = bufnr('')
function! gitgutter#buffer_disable(...) abort
let bufnr = a:0 ? a:1 : bufnr('')
call gitgutter#utility#setbufvar(bufnr, 'enabled', 0)
call s:clear(bufnr)
endfunction
function! gitgutter#buffer_enable() abort
let bufnr = bufnr('')
function! gitgutter#buffer_enable(...) abort
let bufnr = a:0 ? a:1 : bufnr('')
call gitgutter#utility#setbufvar(bufnr, 'enabled', 1)
call gitgutter#process_buffer(bufnr, 1)
endfunction
function! gitgutter#buffer_toggle() abort
if gitgutter#utility#getbufvar(bufnr(''), 'enabled', 1)
call gitgutter#buffer_disable()
function! gitgutter#buffer_toggle(...) abort
let bufnr = a:0 ? a:1 : bufnr('')
if gitgutter#utility#getbufvar(bufnr, 'enabled', 1)
call gitgutter#buffer_disable(bufnr)
else
call gitgutter#buffer_enable()
call gitgutter#buffer_enable(bufnr)
endif
endfunction

View File

@@ -48,8 +48,7 @@ endfunction
" Returns truthy when the buffer's file should be processed; and falsey when it shouldn't.
" This function does not and should not make any system calls.
function! gitgutter#utility#is_active(bufnr) abort
return g:gitgutter_enabled &&
\ gitgutter#utility#getbufvar(a:bufnr, 'enabled', 1) &&
return gitgutter#utility#getbufvar(a:bufnr, 'enabled') &&
\ !pumvisible() &&
\ s:is_file_buffer(a:bufnr) &&
\ s:exists_file(a:bufnr) &&