mirror of
https://github.com/neovim/neovim.git
synced 2025-09-26 21:18:34 +00:00
refactor(misc1): move out autocmd related functions
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user