diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-26 20:25:47 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-26 20:25:47 +1200 |
commit | fe3d0bb24d6df0a3a7e01aa495d44f3422ff736e (patch) | |
tree | bfc12676e7862b02a0861f7f93eb9f93db0a89b8 | |
parent | Merge branch 'release/v0.3.0' into develop (diff) | |
download | vim-insert-timeout-fe3d0bb24d6df0a3a7e01aa495d44f3422ff736e.tar.gz vim-insert-timeout-fe3d0bb24d6df0a3a7e01aa495d44f3422ff736e.zip |
Refactor with autoload
-rw-r--r-- | autoload/insert_timeout.vim | 14 | ||||
-rw-r--r-- | plugin/insert_timeout.vim | 28 |
2 files changed, 21 insertions, 21 deletions
diff --git a/autoload/insert_timeout.vim b/autoload/insert_timeout.vim new file mode 100644 index 0000000..5df8b3d --- /dev/null +++ b/autoload/insert_timeout.vim @@ -0,0 +1,14 @@ +" Set update time to configured variable or default 20 seconds +function! insert_timeout#Enter() abort + let s:updatetime = &updatetime + let &updatetime = get(g:, 'insert_timeout_duration', 20000) +endfunction + +" Restore update time to its previous value +function! insert_timeout#Leave() abort + if exists('s:updatetime') + return + endif + let &updatetime = s:updatetime + unlet s:updatetime +endfunction diff --git a/plugin/insert_timeout.vim b/plugin/insert_timeout.vim index 3705df0..80915d3 100644 --- a/plugin/insert_timeout.vim +++ b/plugin/insert_timeout.vim @@ -6,32 +6,18 @@ " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself " -if exists('loaded_insert_timeout') || &compatible - finish -endif -if !has('autocmd') || v:version < 700 +if exists('loaded_insert_timeout') || &compatible || v:version < 700 finish endif let 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! - autocmd InsertEnter * call s:SetUpdatetime() - autocmd InsertLeave * call s:RestoreUpdatetime() - autocmd CursorHoldI * stopinsert + autocmd InsertEnter * + \ call insert_timeout#Enter() + autocmd InsertLeave * + \ call insert_timeout#Leave() + autocmd CursorHoldI * + \ stopinsert augroup END |