From 53ab5d55eb2ba2abf9a7959e8fd8283d3ec7e562 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 12 Jul 2018 11:30:54 +1200 Subject: Remove autoload, trim down --- plugin/insert_timeout.vim | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/plugin/insert_timeout.vim b/plugin/insert_timeout.vim index 2b127e9..36f63b6 100644 --- a/plugin/insert_timeout.vim +++ b/plugin/insert_timeout.vim @@ -9,20 +9,29 @@ if exists('g:loaded_insert_timeout') || &compatible finish endif -if v:version < 700 +if !has('autocmd') || v:version < 700 finish endif let g:loaded_insert_timeout = 1 +" Initialise 'updatetime' caching variable +let s:updatetime_save = &updatetime + +" Set update time to configured variable or default 20 seconds +function! s:SetUpdatetime() abort + let s:updatetime_save = &updatetime + let &updatetime = get(g:, 'insert_timeout_duration', 20000) +endfunction + +" Restore update time to globally configured variable +function! s:RestoreUpdatetime() abort + let &updatetime = s:updatetime_save +endfunction + " Set up actions in a group augroup insert_timeout autocmd! - - " Set and restore update time - autocmd InsertEnter * call insert_timeout#SetUpdatetime() - autocmd InsertLeave * call insert_timeout#RestoreUpdatetime() - - " Cancel insert mode if timeout reached + autocmd InsertEnter * call s:SetUpdatetime() + autocmd InsertLeave * call s:RestoreUpdatetime() autocmd CursorHoldI * stopinsert - augroup END -- cgit v1.2.3