Ensure that buffer is processed soon after startup

Fixes #738.
This commit is contained in:
Andy Stewart
2020-10-30 12:27:48 +00:00
parent 4477570033
commit 696a6ed389

View File

@@ -12,6 +12,8 @@ if v:version < 703 || (v:version == 703 && !has("patch105"))
finish finish
endif endif
let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? '<nomodeline>' : ''
function! s:set(var, default) abort function! s:set(var, default) abort
if !exists(a:var) if !exists(a:var)
if type(a:default) if type(a:default)
@@ -226,7 +228,20 @@ nnoremap <silent> <Plug>GitGutterPreviewHunk :call gitgutter#utility#warn('ple
function! s:on_bufenter() function! s:on_bufenter()
call gitgutter#setup_maps() call gitgutter#setup_maps()
if has('vim_starting') && !$VIM_GITGUTTER_TEST | return | endif " To keep vim's start-up fast, do not process the buffer when vim is starting.
" Instead process it a short time later. Normally we would rely on our
" CursorHold autocommand to handle this but it turns out CursorHold is not
" guaranteed to fire if the user has not typed anything yet; so set up a
" timer instead. The disadvantage is that if CursorHold does fire, the
" plugin will do a round of unnecessary work; but since there will not have
" been any changes to the buffer since the first round, the second round
" will be cheap.
if has('vim_starting') && !$VIM_GITGUTTER_TEST
if exists('*timer_start')
call timer_start(&updatetime, 'GitGutterCursorHold')
endif
return
endif
if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter
let t:gitgutter_didtabenter = 0 let t:gitgutter_didtabenter = 0
@@ -236,6 +251,10 @@ function! s:on_bufenter()
endif endif
endfunction endfunction
function! GitGutterCursorHold(timer)
execute 'doautocmd' s:nomodeline 'gitgutter CursorHold'
endfunction
" Autocommands {{{ " Autocommands {{{
augroup gitgutter augroup gitgutter