summaryrefslogtreecommitdiff
path: root/src/autocmd.c
diff options
context:
space:
mode:
author=?UTF-8?q?Magnus=20Gro=C3=9F?= <magnus.gross@rwth-aachen.de>2021-09-12 13:39:55 +0200
committerBram Moolenaar <Bram@vim.org>2021-09-12 13:39:55 +0200
commitf1e8876fa2359b572d262772747405d3616db670 (patch)
tree1b33a32bccaa4522f14f2aad8ee8044295635d0b /src/autocmd.c
parent464393a6961d9b9de2bfe9c05f8e2ae5bdec0293 (diff)
downloadvim-git-f1e8876fa2359b572d262772747405d3616db670.tar.gz
patch 8.2.3430: no generic way to trigger an autocommand on mode changev8.2.3430
Problem: No generic way to trigger an autocommand on mode change. Solution: Add the ModeChanged autocommand event. (Magnus Gross, closes #8856)
Diffstat (limited to 'src/autocmd.c')
-rw-r--r--src/autocmd.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/autocmd.c b/src/autocmd.c
index 07681bbe5..a721e708a 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -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