aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-25 19:52:42 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-25 20:20:13 +1200
commitb4d6ec1a8c0986ea59589c493ad4e88f94dcc318 (patch)
tree2558f2fa69f1c54eb90b165502198f5c7da606d8
parentInline conditional (diff)
downloadvim-insert-cancel-b4d6ec1a8c0986ea59589c493ad4e88f94dcc318.tar.gz
vim-insert-cancel-b4d6ec1a8c0986ea59589c493ad4e88f94dcc318.zip
Rearrange some code for clarity
-rw-r--r--autoload/insert_cancel.vim14
-rw-r--r--plugin/insert_cancel.vim11
2 files changed, 11 insertions, 14 deletions
diff --git a/autoload/insert_cancel.vim b/autoload/insert_cancel.vim
index 41e6c60..afc8c8b 100644
--- a/autoload/insert_cancel.vim
+++ b/autoload/insert_cancel.vim
@@ -1,3 +1,10 @@
+" On entering insert mode, reset the changed flag and check for a new round of
+" changes since insert mode was opened
+function! insert_cancel#Enter()
+ let b:insert_cancel_changed = 0
+ call insert_cancel#Check()
+endfunction
+
" On leaving insert mode, whether normally or via <Plug>(InsertCancel), check
" if changenr() exceeds the last time we cached it, and flag that a change has
" taken place if it did
@@ -7,13 +14,6 @@ function! insert_cancel#Check()
endif
endfunction
-" On entering insert mode, reset the changed flag and check for a new round of
-" changes since insert mode was opened
-function! insert_cancel#Enter()
- let b:insert_cancel_changed = 0
- call insert_cancel#Check()
-endfunction
-
" On cancelling insert mode, if we think we made a change, undo it
function! insert_cancel#Cancel()
if get(b:, 'insert_cancel_changed', 0)
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim
index 1c80def..b9dd4ca 100644
--- a/plugin/insert_cancel.vim
+++ b/plugin/insert_cancel.vim
@@ -17,15 +17,12 @@ let loaded_insert_cancel = 1
" support all the hooks required
augroup insert_cancel
autocmd!
-
- " On buffer edit and cursor move, cache the current change number
+ autocmd InsertEnter *
+ \ call insert_cancel#Enter()
+ autocmd InsertLeave *
+ \ call insert_cancel#Check()
autocmd BufEnter,CursorMoved *
\ let b:insert_cancel_changenr = changenr()
-
- " Function wrappers for entering and leaving insert mode
- autocmd InsertEnter * call insert_cancel#Enter()
- autocmd InsertLeave * call insert_cancel#Check()
-
augroup END
" Mapping that exits insert mode normally and checks for a change to undo