From 75a51d354b2fbd9f0818e330a37b1644a1cd0d46 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 28 May 2019 22:43:39 +1200 Subject: Completely overhaul, losing autoload Vim 7.0 and expression mappings sure make this easier. --- README.md | 8 ++++---- autoload/insert_cancel.vim | 22 ---------------------- doc/insert_cancel.txt | 16 +++++++--------- plugin/insert_cancel.vim | 22 ++++++++-------------- 4 files changed, 19 insertions(+), 49 deletions(-) delete mode 100644 autoload/insert_cancel.vim diff --git a/README.md b/README.md index 4efa5dd..b0e07eb 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ insert\_cancel.vim ================== -This plugin provides a mapping target to cancel an insert operation. It leaves -insert mode normally, firing `InsertLeave`, and then runs `:undo` if the buffer -was changed by the insert. This is intended as a remap of Ctrl-C in insert -mode. +This small plugin provides a mapping in insert mode to cancel the current +insert operation by undoing the last change upon insert exit, if a change to +the buffer was made during insert mode, without firing `InsertLeave`. This is +intended for remapping Ctrl-C in insert mode to do something more useful. License ------- diff --git a/autoload/insert_cancel.vim b/autoload/insert_cancel.vim deleted file mode 100644 index 74af060..0000000 --- a/autoload/insert_cancel.vim +++ /dev/null @@ -1,22 +0,0 @@ -" 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 (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 9e0deda..5c628be 100644 --- a/doc/insert_cancel.txt +++ b/doc/insert_cancel.txt @@ -1,11 +1,11 @@ -*insert_cancel.txt* For Vim version 7.0 Last change: 2019 May 25 +*insert_cancel.txt* For Vim version 7.0 Last change: 2019 May 28 DESCRIPTION *insert_cancel* -This plugin provides a mapping target to cancel an insert operation. It -leaves insert mode normally, firing |InsertLeave|, and then runs |:undo| if -the buffer was changed by the insert. This is intended as a remap of -|i_CTRL-C|. +This small plugin provides a mapping in insert mode to cancel the current +insert operation by undoing the last change upon insert exit, if a change to +the buffer was made during insert mode, without firing InsertLeave. This is +intended for remapping |i_CTRL-C| to do something more useful. REQUIREMENTS *insert_cancel-requirements* @@ -20,11 +20,9 @@ example: > imap (InsertCancel) < -ISSUES *insert_cancel-issues* +LIMITATIONS *insert_cancel-limitations* -It doesn't work at all in paste mode, in the same way as any other mapping, so -you can't cancel an insert operation while pasting. You might consider this a -feature. +It doesn't work in paste mode, much the same as any other mapping. AUTHOR *insert_cancel-author* diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim index f722ac8..f0d8443 100644 --- a/plugin/insert_cancel.vim +++ b/plugin/insert_cancel.vim @@ -1,9 +1,8 @@ " -" insert_cancel.vim: Cancel the current insert operation by undoing the last -" change upon insert exit, if we made a change; intended for remapping -" insert-mode Ctrl-C to do something useful. -" -" This was *way* harder to figure out than it looks. +" insert_cancel.vim: Insert mode mapping to cancel the current insert +" operation by undoing the last change upon insert exit, if we made a change, +" without firing InsertLeave. This is intended for remapping Ctrl-C in insert +" mode to do something more useful. " " Author: Tom Ryder " License: Same as Vim itself @@ -13,18 +12,13 @@ if exists('loaded_insert_cancel') || &compatible || v:version < 700 endif let loaded_insert_cancel = 1 -" Set up the hooks described for the functions above, if Vim is new enough to -" support all the hooks required +" Each time the cursor moves in normal mode, cache the current change number 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 (InsertCancel) - \ :call insert_cancel#Cancel() +" Undo any changes if they exceed the cached number on insert map key press +inoremap (InsertCancel) + \ changenr() > b:insert_cancel_changenr ? "\u" : "\" -- cgit v1.2.3 From b2198af6196071660966ceb9e662342b5ad0c637 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 28 May 2019 22:44:53 +1200 Subject: Bump VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fcdb2e1..0062ac9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.0 +5.0.0 -- cgit v1.2.3