aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/state.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-12-10 10:56:17 +0100
committerGitHub <noreply@github.com>2021-12-10 10:56:17 +0100
commit26eb6051528186270b924c7c806a3f434c233530 (patch)
tree7229d143d9ce52354cd35d105054bf47d206a5bc /src/nvim/state.c
parentac2d140a33dfe88f882218e15a443b8300cca6b2 (diff)
parenta59589ca018425f672eb70bf7d2b54d24df49326 (diff)
downloadrneovim-26eb6051528186270b924c7c806a3f434c233530.tar.gz
rneovim-26eb6051528186270b924c7c806a3f434c233530.tar.bz2
rneovim-26eb6051528186270b924c7c806a3f434c233530.zip
Merge pull request #16597 from bfredl/nomisc1
refactor: move out some long-hanging fruit from misc1.c
Diffstat (limited to 'src/nvim/state.c')
-rw-r--r--src/nvim/state.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/nvim/state.c b/src/nvim/state.c
index 71db25664f..68bc76660d 100644
--- a/src/nvim/state.c
+++ b/src/nvim/state.c
@@ -4,7 +4,9 @@
#include <assert.h>
#include "nvim/ascii.h"
+#include "nvim/autocmd.h"
#include "nvim/edit.h"
+#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/getchar.h"
#include "nvim/lib/kvec.h"
@@ -202,3 +204,33 @@ char *get_mode(void)
return buf;
}
+
+/// Fires a ModeChanged autocmd.
+void trigger_modechanged(void)
+{
+ if (!has_event(EVENT_MODECHANGED)) {
+ return;
+ }
+
+ char *mode = get_mode();
+ if (STRCMP(mode, last_mode) == 0) {
+ xfree(mode);
+ return;
+ }
+
+ save_v_event_T save_v_event;
+ dict_T *v_event = get_v_event(&save_v_event);
+ tv_dict_add_str(v_event, S_LEN("new_mode"), mode);
+ tv_dict_add_str(v_event, S_LEN("old_mode"), last_mode);
+
+ char_u *pat_pre = concat_str((char_u *)last_mode, (char_u *)":");
+ char_u *pat = concat_str(pat_pre, (char_u *)mode);
+ xfree(pat_pre);
+
+ apply_autocmds(EVENT_MODECHANGED, pat, NULL, false, curbuf);
+ xfree(last_mode);
+ last_mode = mode;
+
+ xfree(pat);
+ restore_v_event(v_event, &save_v_event);
+}