Ensure BufWritePost,FileChangedShellPost always process buffer.

Before this change the TabEnter/BufEnter logic was intertwined with
the logic for BufWritePost,FileChangedShellPost.

Separating the concerns fixes a minor bug where a TabEnter-BufEnter
combination led to the plugin not updating the diff the first time the
buffer was written.
This commit is contained in:
Andy Stewart
2016-10-11 10:02:21 +01:00
parent fa25cbb7d7
commit 297678a08d

View File

@@ -196,18 +196,35 @@ augroup gitgutter
endif
if g:gitgutter_eager
autocmd BufEnter,BufWritePost,FileChangedShellPost *
autocmd BufWritePost,FileChangedShellPost * call gitgutter#process_buffer(bufnr(''), 0)
" When you enter a new tab, BufEnter is only fired if the buffer you enter
" is not the one you came from.
"
" For example:
"
" `:tab split` fires TabEnter but not BufEnter.
" `:tab new` fires TabEnter and BufEnter.
"
" As and when both TabEnter and BufEnter are fired, we do not want to
" process the entered buffer twice. We avoid this by setting and clearing
" a flag.
autocmd BufEnter *
\ if gettabvar(tabpagenr(), 'gitgutter_didtabenter') |
\ call settabvar(tabpagenr(), 'gitgutter_didtabenter', 0) |
\ else |
\ call gitgutter#process_buffer(bufnr(''), 0) |
\ endif
autocmd TabEnter *
\ call settabvar(tabpagenr(), 'gitgutter_didtabenter', 1) |
\ call gitgutter#all()
if !has('gui_win32')
autocmd FocusGained * call gitgutter#all()
endif
else
autocmd BufRead,BufWritePost,FileChangedShellPost * call gitgutter#process_buffer(bufnr(''), 0)
endif