Handle quickfix autocmd changing buffer

To keep things fast we turn off gitgutter in the current buffer during
quickfix commands, e.g. :vimgrep, and turn it back on afterwards.

However the user may have a quickfix autocmd which makes a different
buffer the current one, e.g. :cwindow. Previously this caused an error
because gitgutter expected the current buffer to remain current; now we
explicitly enable the original current buffer.

Fixes #904.
This commit is contained in:
Andy Stewart
2025-05-05 15:15:44 +01:00
parent 6620e5fbbe
commit a5ae0a5a18

View File

@@ -341,8 +341,18 @@ augroup gitgutter
autocmd BufFilePre * call s:on_buffilepre(expand('<abuf>')) autocmd BufFilePre * call s:on_buffilepre(expand('<abuf>'))
autocmd BufFilePost * call s:on_buffilepost(expand('<abuf>')) autocmd BufFilePost * call s:on_buffilepost(expand('<abuf>'))
autocmd QuickFixCmdPre *vimgrep* let b:gitgutter_was_enabled = gitgutter#utility#getbufvar(expand('<abuf>'), 'enabled') | GitGutterBufferDisable autocmd QuickFixCmdPre *vimgrep*
autocmd QuickFixCmdPost *vimgrep* if b:gitgutter_was_enabled | GitGutterBufferEnable | endif | unlet b:gitgutter_was_enabled \ if gitgutter#utility#getbufvar(expand('<abuf>'), 'enabled') |
\ let s:gitgutter_was_enabled = expand('<abuf>') |
\ else |
\ let s:gitgutter_was_enabled = 0 |
\ endif |
\ GitGutterBufferDisable
autocmd QuickFixCmdPost *vimgrep*
\ if s:gitgutter_was_enabled |
\ call gitgutter#buffer_enable(s:gitgutter_was_enabled) |
\ endif |
\ unlet s:gitgutter_was_enabled
augroup END augroup END
" }}} " }}}