aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-25 20:23:56 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-25 20:23:56 +1200
commit6ebbce7d994111fcbe5b1fd5617f9da6b773f733 (patch)
tree2159c324a1ddd1635678ba82f79f3fd7f8e366c7
parentMerge branch 'release/v3.3.0' (diff)
parentBump VERSION (diff)
downloadvim-insert-cancel-6ebbce7d994111fcbe5b1fd5617f9da6b773f733.tar.gz
vim-insert-cancel-6ebbce7d994111fcbe5b1fd5617f9da6b773f733.zip
Merge branch 'release/v4.0.0'v4.0.0
* release/v4.0.0: Add abort attribute to autoload functions Remove unneeded BufEnter event Rearrange some code for clarity Inline conditional Move functions into autoload Drop support for Vim 6.x
-rw-r--r--VERSION2
-rw-r--r--autoload/insert_cancel.vim22
-rw-r--r--doc/insert_cancel.txt10
-rw-r--r--plugin/insert_cancel.vim67
4 files changed, 36 insertions, 65 deletions
diff --git a/VERSION b/VERSION
index 15a2799..fcdb2e1 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.3.0
+4.0.0
diff --git a/autoload/insert_cancel.vim b/autoload/insert_cancel.vim
new file mode 100644
index 0000000..74af060
--- /dev/null
+++ b/autoload/insert_cancel.vim
@@ -0,0 +1,22 @@
+" 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() abort
+ 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
+function! insert_cancel#Check() abort
+ if changenr() > b:insert_cancel_changenr
+ let b:insert_cancel_changed = 1
+ endif
+endfunction
+
+" On cancelling insert mode, if we think we made a change, undo it
+function! insert_cancel#Cancel() abort
+ if get(b:, 'insert_cancel_changed', 0)
+ silent undo
+ endif
+endfunction
diff --git a/doc/insert_cancel.txt b/doc/insert_cancel.txt
index 233e627..9e0deda 100644
--- a/doc/insert_cancel.txt
+++ b/doc/insert_cancel.txt
@@ -1,4 +1,4 @@
-*insert_cancel.txt* For Vim version 6.0 Last change: 2018 July 12
+*insert_cancel.txt* For Vim version 7.0 Last change: 2019 May 25
DESCRIPTION *insert_cancel*
@@ -9,13 +9,7 @@ the buffer was changed by the insert. This is intended as a remap of
REQUIREMENTS *insert_cancel-requirements*
-This plugin only loads if 'compatible' is not set. It works best if you have
-at least |vim7| with |autocmd|, because it leans on the |CursorMoved| event.
-
-If you don't have |CursorMoved|, the |'[| and |']| marks are used to detect
-changes instead. This still works for undoing insert additions, but it won't
-restore text that was erased when insert mode was entered with |c| or |s| or
-their variants, and it doesn't undo new unindented blank lines.
+This plugin only loads if 'compatible' is not set.
MAPPINGS *insert_cancel-mappings*
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim
index 8ad47e5..f722ac8 100644
--- a/plugin/insert_cancel.vim
+++ b/plugin/insert_cancel.vim
@@ -8,68 +8,23 @@
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
-if exists('loaded_insert_cancel') || &compatible
- finish
-endif
-if v:version < 600
+if exists('loaded_insert_cancel') || &compatible || v:version < 700
finish
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()
-
- " The flag exists, if it's on, undo
- if exists('b:insert_cancel_changed')
- if b:insert_cancel_changed
- silent undo
- endif
-
- " The flag didn't exist, fall back to marks; if the line number or column
- " number of the marks for the last changed text aren't exactly equal, that
- " suggests we changed something; undo it
- elseif line("'[") != line("']") || col("'[") != col("']")
- silent undo
- endif
-
- " Redraw the screen to avoid bug with vestigial 'showmode' display
- redraw!
-
-endfunction
-
" Set up the hooks described for the functions above, if Vim is new enough to
" support all the hooks required
-if has('autocmd') && v:version >= 700
- augroup insert_cancel
- autocmd!
-
- " On buffer edit and cursor move, cache the current change number
- autocmd BufEnter,CursorMoved *
- \ let b:insert_cancel_changenr = changenr()
-
- " Function wrappers for entering and leaving insert mode
- autocmd InsertEnter * call s:Enter()
- autocmd InsertLeave * call s:Check()
-
- augroup END
-endif
+augroup insert_cancel
+ autocmd!
+ autocmd InsertEnter *
+ \ call insert_cancel#Enter()
+ autocmd InsertLeave *
+ \ call insert_cancel#Check()
+ autocmd CursorMoved *
+ \ let b:insert_cancel_changenr = changenr()
+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>