aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-11 10:30:24 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-11 10:30:24 +1200
commitf0263d668f9b5abbb9cbd82726c09204a9caa8e0 (patch)
tree7df7a0117e148f44d20ed2685ab714ec837455a2
parentMerge branch 'release/v0.3.0' (diff)
parentBump VERSION (diff)
downloadvim-insert-cancel-f0263d668f9b5abbb9cbd82726c09204a9caa8e0.tar.gz
vim-insert-cancel-f0263d668f9b5abbb9cbd82726c09204a9caa8e0.zip
Merge branch 'release/v1.0.0'v1.0.0
* release/v1.0.0: Bump VERSION Refactor completely with TextChanged/CursorMoved
-rw-r--r--README.md7
-rw-r--r--VERSION2
-rw-r--r--doc/insert_cancel.txt40
-rw-r--r--plugin/insert_cancel.vim20
4 files changed, 42 insertions, 27 deletions
diff --git a/README.md b/README.md
index 85e81ab..e767d80 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,10 @@
insert\_cancel.vim
==================
-This plugin provides a mapping target to cancel an insert operation, by
-triggering `i_CTRL-C` and undoing a change if one was made by that insert
-operation.
+This plugin provides a mapping target to cancel an insert operation, by leaving
+insert mode normally and undoing a change if one was made by that insert
+operation. It's intended as a target for `i_CTRL-C`, to make it do something
+useful, and to fire `InsertLeave` afterwards where available.
License
-------
diff --git a/VERSION b/VERSION
index 0d91a54..3eefcb9 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.3.0
+1.0.0
diff --git a/doc/insert_cancel.txt b/doc/insert_cancel.txt
index c62671e..5893a05 100644
--- a/doc/insert_cancel.txt
+++ b/doc/insert_cancel.txt
@@ -1,18 +1,34 @@
-*insert_cancel.txt* For Vim version 6.0 Last change: 2018 July 02
+*insert_cancel.txt* For Vim version 6.0 Last change: 2018 July 11
DESCRIPTION *insert_cancel*
This plugin provides a mapping target to cancel an insert operation, by
-triggering |i_CTRL-C| and undoing a change if one was made by that insert
-operation.
+leaving insert mode normally and undoing a change if one was made by that
+insert operation. It's intended as a target for |i_CTRL-C|, to make it do
+something useful, and to fire |InsertLeave| afterwards where available.
REQUIREMENTS *insert_cancel-requirements*
-This plugin is only available if 'compatible' is not set. It works best if
-|+autocmd| is available, with the |InsertLeave| event from |vim7|. It does a
-much better job of telling whether a change was made with these features
-available, which avoids undoing unrelated changes inappropriately.
+This plugin is only available if 'compatible' is not set. It works better on
+newer versions of Vim.
+If you have |autocmd| and at least |version-7.4| (or |version-7.3| with patch
+867) it works really well, because it has |TextChanged| to lean on for
+watching |b:changedtick|.
+
+If you have |autocmd| and |version-7.0| to |version-7.3|, it leans on
+|CursorMoved| instead. This still seems pretty good, but I imagine it's more
+likely there are subtle gaps, and it's also not ideal in terms of performance
+because the event fires a lot without doing anything useful.
+
+If you have just |version6|, all the plugin has to go on are the |'[| and |']|
+marks. It still kind of works, but there are some big gaps; it won't undo text
+that was erased when insert mode was entered with |c| or |s| or its variants.
+It also may not undo new blank lines. Even this is still slightly better than
+just the intuitive mapping:
+>
+ imap <C-C> <Esc>u
+<
MAPPINGS *insert_cancel-mappings*
*<Plug>InsertCancel*
@@ -21,16 +37,6 @@ mode. There is no default key mapping to the target; you should define this
yourself in your |vimrc|. For example:
>
imap <C-C> <Plug>InsertCancel
-<
-BUGS *insert_cancel-bugs*
-
-If you open a line with |o| or |O|, and then press |i_CTRL-C| without making
-any other changes, that change will not be reverted.
-
-This is because for |o| and |O|, |b:changedticks| is incremented before the
-|InsertLeave| event used to sample the counter for comparison with when CTRL-C
-is pressed, and I can't figure out how to catch it any earlier without using
-|CursorMoved| or or |vim8|'s |TextChanged|, which I'd rather avoid.
AUTHOR *insert_cancel-author*
diff --git a/plugin/insert_cancel.vim b/plugin/insert_cancel.vim
index 7566fee..61d0b49 100644
--- a/plugin/insert_cancel.vim
+++ b/plugin/insert_cancel.vim
@@ -1,7 +1,7 @@
"
" 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.
+" insert-mode Ctrl-C to do something useful.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -17,16 +17,24 @@ let g:loaded_insert_cancel = 1
" Initialise s:changedtick so vint understands
let s:changedtick = 0
-" InsertEnter is only available from Vim 7
-if has('autocmd') && v:version >= 700
+" Set up an appropriate hook to track b:changedtick before we hit InsertLeave
+if has('autocmd')
augroup insert_cancel
autocmd!
- autocmd InsertEnter *
- \ let s:changedtick = b:changedtick
+
+ " Ideal; only runs when the text actually changes
+ if v:version > 703 || v:version == 703 && has('patch867')
+ autocmd TextChanged * let s:changedtick = b:changedtick
+
+ " Workable but wasteful and not quite as correct; updates every move
+ elseif v:version >= 700
+ autocmd CursorMoved * let s:changedtick = b:changedtick
+ endif
+
augroup END
endif
-" Try to figure out whether we made a change to undo, undo it if so
+" Try hard to figure out whether we made a change to undo, and undo it if so
function! s:InsertCancel()
if !&modified
return