Patch 8.2.1874
Problem: Can't do something just before leaving Insert mode.
Solution: Add the InsertLeavePre autocommand event. (closes #7177)
Files: runtime/doc/autocmd.txt, src/edit.c, src/vim.h,
src/autocmd.c, src/testdir/test_edit.vim
*** ../vim-8.2.1873/runtime/doc/autocmd.txt 2020-06-12 22:08:56.414965077
+0200
--- runtime/doc/autocmd.txt 2020-10-21 12:06:06.018654049 +0200
***************
*** 881,889 ****
The cursor is restored afterwards. If you do
not want that set |v:char| to a non-empty
string.
*InsertLeave*
! InsertLeave When leaving Insert mode. Also when using
! CTRL-O |i_CTRL-O|. But not for |i_CTRL-C|.
*MenuPopup*
MenuPopup Just before showing the popup menu (under the
right mouse button). Useful for adjusting the
--- 881,894 ----
The cursor is restored afterwards. If you do
not want that set |v:char| to a non-empty
string.
+ *InsertLeavePre*
+ InsertLeavePre Just before leaving Insert mode. Also
when
+ using CTRL-O |i_CTRL-O|. Be caseful not to
+ change mode or use `:normal`, it will likely
+ cause trouble.
*InsertLeave*
! InsertLeave Just after leaving Insert mode. Also when
! using CTRL-O |i_CTRL-O|. But not for
|i_CTRL-C|.
*MenuPopup*
MenuPopup Just before showing the popup menu (under the
right mouse button). Useful for adjusting the
*** ../vim-8.2.1873/src/edit.c 2020-09-27 20:12:49.417331796 +0200
--- src/edit.c 2020-10-21 12:00:20.965391532 +0200
***************
*** 3607,3612 ****
--- 3607,3615 ----
undisplay_dollar();
}
+ if (cmdchar != 'r' && cmdchar != 'v')
+ ins_apply_autocmds(EVENT_INSERTLEAVEPRE);
+
// When an autoindent was removed, curswant stays after the
// indent
if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col)
*** ../vim-8.2.1873/src/vim.h 2020-09-27 15:19:23.638118934 +0200
--- src/vim.h 2020-10-21 12:03:59.358030595 +0200
***************
*** 1298,1304 ****
EVENT_INSERTCHANGE, // when changing Insert/Replace mode
EVENT_INSERTCHARPRE, // before inserting a char
EVENT_INSERTENTER, // when entering Insert mode
! EVENT_INSERTLEAVE, // when leaving Insert mode
EVENT_MENUPOPUP, // just before popup menu is displayed
EVENT_OPTIONSET, // option was set
EVENT_QUICKFIXCMDPOST, // after :make, :grep etc.
--- 1298,1305 ----
EVENT_INSERTCHANGE, // when changing Insert/Replace mode
EVENT_INSERTCHARPRE, // before inserting a char
EVENT_INSERTENTER, // when entering Insert mode
! EVENT_INSERTLEAVEPRE, // just before leaving Insert mode
! EVENT_INSERTLEAVE, // just after leaving Insert mode
EVENT_MENUPOPUP, // just before popup menu is displayed
EVENT_OPTIONSET, // option was set
EVENT_QUICKFIXCMDPOST, // after :make, :grep etc.
***************
*** 1325,1331 ****
EVENT_TABNEW, // when entering a new tab page
EVENT_TERMCHANGED, // after changing 'term'
EVENT_TERMINALOPEN, // after a terminal buffer was created
! EVENT_TERMINALWINOPEN, // after a terminal buffer was created and
entering its window
EVENT_TERMRESPONSE, // after setting "v:termresponse"
EVENT_TEXTCHANGED, // text was modified not in Insert mode
EVENT_TEXTCHANGEDI, // text was modified in Insert mode
--- 1326,1333 ----
EVENT_TABNEW, // when entering a new tab page
EVENT_TERMCHANGED, // after changing 'term'
EVENT_TERMINALOPEN, // after a terminal buffer was created
! EVENT_TERMINALWINOPEN, // after a terminal buffer was created and
! // entering its window
EVENT_TERMRESPONSE, // after setting "v:termresponse"
EVENT_TEXTCHANGED, // text was modified not in Insert mode
EVENT_TEXTCHANGEDI, // text was modified in Insert mode
*** ../vim-8.2.1873/src/autocmd.c 2020-10-01 22:37:36.403376674 +0200
--- src/autocmd.c 2020-10-21 12:16:43.157448322 +0200
***************
*** 149,154 ****
--- 149,155 ----
{"InsertChange", EVENT_INSERTCHANGE},
{"InsertEnter", EVENT_INSERTENTER},
{"InsertLeave", EVENT_INSERTLEAVE},
+ {"InsertLeavePre", EVENT_INSERTLEAVEPRE},
{"InsertCharPre", EVENT_INSERTCHARPRE},
{"MenuPopup", EVENT_MENUPOPUP},
{"OptionSet", EVENT_OPTIONSET},
*** ../vim-8.2.1873/src/testdir/test_edit.vim 2020-10-13 19:08:20.267560498
+0200
--- src/testdir/test_edit.vim 2020-10-21 12:18:20.157074048 +0200
***************
*** 1446,1476 ****
func Test_edit_InsertLeave()
new
au InsertLeave * let g:did_au = 1
let g:did_au = 0
call feedkeys("afoo\<Esc>", 'tx')
call assert_equal(1, g:did_au)
call assert_equal('foo', getline(1))
let g:did_au = 0
call feedkeys("Sbar\<C-C>", 'tx')
call assert_equal(0, g:did_au)
call assert_equal('bar', getline(1))
inoremap x xx<Esc>
let g:did_au = 0
call feedkeys("Saax", 'tx')
call assert_equal(1, g:did_au)
call assert_equal('aaxx', getline(1))
inoremap x xx<C-C>
let g:did_au = 0
call feedkeys("Sbbx", 'tx')
call assert_equal(0, g:did_au)
call assert_equal('bbxx', getline(1))
bwipe!
! au! InsertLeave
iunmap x
endfunc
--- 1446,1485 ----
func Test_edit_InsertLeave()
new
+ au InsertLeavePre * let g:did_au_pre = 1
au InsertLeave * let g:did_au = 1
+ let g:did_au_pre = 0
let g:did_au = 0
call feedkeys("afoo\<Esc>", 'tx')
+ call assert_equal(1, g:did_au_pre)
call assert_equal(1, g:did_au)
call assert_equal('foo', getline(1))
+ let g:did_au_pre = 0
let g:did_au = 0
call feedkeys("Sbar\<C-C>", 'tx')
+ call assert_equal(1, g:did_au_pre)
call assert_equal(0, g:did_au)
call assert_equal('bar', getline(1))
inoremap x xx<Esc>
+ let g:did_au_pre = 0
let g:did_au = 0
call feedkeys("Saax", 'tx')
+ call assert_equal(1, g:did_au_pre)
call assert_equal(1, g:did_au)
call assert_equal('aaxx', getline(1))
inoremap x xx<C-C>
+ let g:did_au_pre = 0
let g:did_au = 0
call feedkeys("Sbbx", 'tx')
+ call assert_equal(1, g:did_au_pre)
call assert_equal(0, g:did_au)
call assert_equal('bbxx', getline(1))
bwipe!
! au! InsertLeave InsertLeavePre
iunmap x
endfunc
*** ../vim-8.2.1873/src/version.c 2020-10-20 23:11:30.172481858 +0200
--- src/version.c 2020-10-21 12:19:14.680927829 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1874,
/**/
--
# echo reboot >universe
# chmod +x universe
# ./universe
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202010211020.09LAKJUl014240%40masaka.moolenaar.net.