Use timer instead of autocmd to defer startup processing

If the user has removed the "gitgutter CursorHold" autocommand, which
is the documented way to turn off automatic refreshing, calling the
autocommand at start up will fail.  Use a timer instead.

This implementation also changes the processing delay to 1ms instead of
'updatetime'.

See #840.
This commit is contained in:
Andy Stewart
2022-08-22 09:30:47 +01:00
parent ded11946c0
commit 7808c48c7b

View File

@@ -245,8 +245,8 @@ function! s:on_bufenter()
" 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')
if exists('*timer_start') && has('lambda')
call s:next_tick("call gitgutter#process_buffer(+".bufnr('').", 0)")
endif
return
endif
@@ -259,10 +259,6 @@ function! s:on_bufenter()
endif
endfunction
function! GitGutterCursorHold(timer)
execute 'doautocmd' s:nomodeline 'gitgutter CursorHold'
endfunction
function! s:next_tick(cmd)
call timer_start(1, {-> execute(a:cmd)})
endfunction