From c39a5c240a4f34d00288d51674d54b6b6480694f Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 28 Feb 2018 15:09:36 +0000 Subject: [PATCH] Add g:gitgutter_terminal_reports_focus to enable FocusGained workaround. See #490. --- README.mkd | 4 ++-- doc/gitgutter.txt | 27 +++++++++++++++++++++++++-- plugin/gitgutter.vim | 5 +++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.mkd b/README.mkd index 5fea55c..520e1cc 100644 --- a/README.mkd +++ b/README.mkd @@ -24,7 +24,7 @@ Features: Constraints: * Supports git only. If you work with other version control systems, I recommend [vim-signify](https://github.com/mhinz/vim-signify). -* Relies on the `FocusGained` event. If your terminal doesn't report focus events, I suggest using something like [Terminus][]. +* Relies on the `FocusGained` event. If your terminal doesn't report focus events, either use something like [Terminus][] or set `let g:gitgutter_terminal_reports_focus=0`. ### Screenshot @@ -506,7 +506,7 @@ Here are some things you can check: #### When signs don't update after focusing Vim -* Your terminal probably isn't reporting focus events. Try installing [Terminus][]. +* Your terminal probably isn't reporting focus events. Either try installing [Terminus][] or set `let g:gitgutter_terminal_reports_focus=0`. ### Shameless Plug diff --git a/doc/gitgutter.txt b/doc/gitgutter.txt index d7aefb6..8cf62b9 100644 --- a/doc/gitgutter.txt +++ b/doc/gitgutter.txt @@ -252,6 +252,10 @@ Signs:~ |g:gitgutter_sign_column_always| |g:gitgutter_override_sign_column_highlight| +Terminal:~ + + |g:gitgutter_terminal_reports_focus| + General:~ |g:gitgutter_enabled| @@ -365,6 +369,22 @@ it in your |vimrc|: User-defined (terminal Vim) highlight SignColumn ctermbg={whatever} User-defined (graphical Vim) highlight SignColumn guibg={whatever} + + *g:gitgutter_terminal_reports_focus* +Default: 1 + +Normally the plugin uses |FocusGained| to force-update all buffers when Vim +receives focus. However some terminals do not report focus events and so the +|FocusGained| autocommand never fires. + +If this applies to you, either install something like Terminus +(https://github.com/wincent/terminus) to make |FocusGained| work or set this +option to 0. + +When this option is 0, the plugin force-updates the buffer on |BufEnter| +(instead of only updating if the buffer's contents has changed since the last +update). + *g:gitgutter_enabled* Default: 1 @@ -491,6 +511,9 @@ Try reducing 'updatetime': When signs don't update after focusing Vim:~ -Your terminal probably isn't reporting focus events. Try installing Terminus -(https://github.com/wincent/terminus). +Your terminal probably isn't reporting focus events. Either try installing +Terminus (https://github.com/wincent/terminus) or set: +> + let g:gitgutter_terminal_reports_focus = 0 +< diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index d3663d3..4d95986 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -48,6 +48,7 @@ call s:set('g:gitgutter_sign_modified_removed', '~_') call s:set('g:gitgutter_diff_args', '') call s:set('g:gitgutter_diff_base', '') call s:set('g:gitgutter_map_keys', 1) +call s:set('g:gitgutter_terminal_reports_focus', 1) call s:set('g:gitgutter_async', 1) call s:set('g:gitgutter_log', 0) @@ -209,10 +210,10 @@ augroup gitgutter autocmd BufEnter * \ if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter | \ let t:gitgutter_didtabenter = 0 | - \ call gitgutter#all(0) | + \ call gitgutter#all(!g:gitgutter_terminal_reports_focus) | \ else | \ call gitgutter#init_buffer(bufnr('')) | - \ call gitgutter#process_buffer(bufnr(''), 0) | + \ call gitgutter#process_buffer(bufnr(''), !g:gitgutter_terminal_reports_focus) | \ endif autocmd CursorHold,CursorHoldI * call gitgutter#process_buffer(bufnr(''), 0)