0
0
mirror of https://github.com/vim/vim.git synced 2025-09-30 04:44:14 -04:00

patch 8.2.3430: no generic way to trigger an autocommand on mode change

Problem:    No generic way to trigger an autocommand on mode change.
Solution:   Add the ModeChanged autocommand event. (Magnus Gross, closes #8856)
This commit is contained in:
=?UTF-8?q?Magnus=20Gro=C3=9F?=
2021-09-12 13:39:55 +02:00
committed by Bram Moolenaar
parent 464393a696
commit f1e8876fa2
13 changed files with 135 additions and 4 deletions

View File

@@ -150,6 +150,7 @@ static struct event_name
{"InsertLeavePre", EVENT_INSERTLEAVEPRE},
{"InsertCharPre", EVENT_INSERTCHARPRE},
{"MenuPopup", EVENT_MENUPOPUP},
{"ModeChanged", EVENT_MODECHANGED},
{"OptionSet", EVENT_OPTIONSET},
{"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
{"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
@@ -1817,6 +1818,17 @@ has_completechanged(void)
}
#endif
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* Return TRUE when there is a ModeChanged autocommand defined.
*/
int
has_modechanged(void)
{
return (first_autopat[(int)EVENT_MODECHANGED] != NULL);
}
#endif
/*
* Execute autocommands for "event" and file name "fname".
* Return TRUE if some commands were executed.
@@ -1938,7 +1950,8 @@ apply_autocmds_group(
if (fname_io == NULL)
{
if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
|| event == EVENT_OPTIONSET)
|| event == EVENT_OPTIONSET
|| event == EVENT_MODECHANGED)
autocmd_fname = NULL;
else if (fname != NULL && !ends_excmd(*fname))
autocmd_fname = fname;
@@ -2011,7 +2024,8 @@ apply_autocmds_group(
|| event == EVENT_COLORSCHEMEPRE
|| event == EVENT_OPTIONSET
|| event == EVENT_QUICKFIXCMDPOST
|| event == EVENT_DIRCHANGED)
|| event == EVENT_DIRCHANGED
|| event == EVENT_MODECHANGED)
{
fname = vim_strsave(fname);
autocmd_fname_full = TRUE; // don't expand it later