aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-25 19:49:44 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-25 19:49:44 +1200
commit92a70f73b5cbbf86cb3d239684a97711ac1302fe (patch)
tree2bf6c65921964b139a09ab144b375de3169524d6
parentDrop support for Vim 6.x (diff)
downloadvim-insert-cancel-92a70f73b5cbbf86cb3d239684a97711ac1302fe.tar.gz
vim-insert-cancel-92a70f73b5cbbf86cb3d239684a97711ac1302fe.zip
Move functions into autoload
-rw-r--r--autoload/insert_cancel.vim22
-rw-r--r--plugin/insert_cancel.vim29
2 files changed, 25 insertions, 26 deletions
diff --git a/autoload/insert_cancel.vim b/autoload/insert_cancel.vim
new file mode 100644
index 0000000..41e6c60
--- /dev/null
+++ b/autoload/insert_cancel.vim
@@ -0,0 +1,22 @@
+" 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
+function! insert_cancel#Check()
+ if changenr() > b:insert_cancel_changenr
+ let b:insert_cancel_changed = 1
+ 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)
+ silent undo
+ endif
+endfunction
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim
index a4595f9..4221ba4 100644
--- a/plugin/insert_cancel.vim
+++ b/plugin/insert_cancel.vim
@@ -16,29 +16,6 @@ if v:version < 700
endif
let loaded_insert_cancel = 1
-" 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
-function! s:Check()
- if changenr() > b:insert_cancel_changenr
- let b:insert_cancel_changed = 1
- endif
-endfunction
-
-" On entering insert mode, reset the changed flag and check for a new round of
-" changes since insert mode was opened
-function! s:Enter()
- let b:insert_cancel_changed = 0
- call s:Check()
-endfunction
-
-" On cancelling insert mode, if we think we made a change, undo it
-function! s:Cancel()
- if get(b:, 'insert_cancel_changed', 0)
- silent undo
- endif
-endfunction
-
" Set up the hooks described for the functions above, if Vim is new enough to
" support all the hooks required
augroup insert_cancel
@@ -49,11 +26,11 @@ augroup insert_cancel
\ let b:insert_cancel_changenr = changenr()
" Function wrappers for entering and leaving insert mode
- autocmd InsertEnter * call s:Enter()
- autocmd InsertLeave * call s:Check()
+ 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
inoremap <silent> <Plug>(InsertCancel)
- \ <Esc>:<C-U>call <SID>Cancel()<CR>
+ \ <Esc>:<C-U>call insert_cancel#Cancel()<CR>