mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(misc1): move out autocmd related functions
This commit is contained in:
parent
2ec0e0a868
commit
51822f0655
@ -1116,12 +1116,6 @@ typedef struct {
|
|||||||
pos_T w_cursor_corr; // corrected cursor position
|
pos_T w_cursor_corr; // corrected cursor position
|
||||||
} pos_save_T;
|
} pos_save_T;
|
||||||
|
|
||||||
// Struct passed to get_v_event() and restore_v_event().
|
|
||||||
typedef struct {
|
|
||||||
bool sve_did_save;
|
|
||||||
hashtab_T sve_hashtab;
|
|
||||||
} save_v_event_T;
|
|
||||||
|
|
||||||
/// Indices into vimmenu_T->strings[] and vimmenu_T->noremap[] for each mode
|
/// Indices into vimmenu_T->strings[] and vimmenu_T->noremap[] for each mode
|
||||||
/// \addtogroup MENU_INDEX
|
/// \addtogroup MENU_INDEX
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -303,6 +303,31 @@ const list_T *eval_msgpack_type_lists[] = {
|
|||||||
[kMPExt] = NULL,
|
[kMPExt] = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dict_T *get_v_event(save_v_event_T *sve)
|
||||||
|
{
|
||||||
|
dict_T *v_event = get_vim_var_dict(VV_EVENT);
|
||||||
|
|
||||||
|
if (v_event->dv_hashtab.ht_used > 0) {
|
||||||
|
// recursive use of v:event, save, make empty and restore later
|
||||||
|
sve->sve_did_save = true;
|
||||||
|
sve->sve_hashtab = v_event->dv_hashtab;
|
||||||
|
hash_init(&v_event->dv_hashtab);
|
||||||
|
} else {
|
||||||
|
sve->sve_did_save = false;
|
||||||
|
}
|
||||||
|
return v_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
void restore_v_event(dict_T *v_event, save_v_event_T *sve)
|
||||||
|
{
|
||||||
|
tv_dict_free_contents(v_event);
|
||||||
|
if (sve->sve_did_save) {
|
||||||
|
v_event->dv_hashtab = sve->sve_hashtab;
|
||||||
|
} else {
|
||||||
|
hash_init(&v_event->dv_hashtab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return "n1" divided by "n2", taking care of dividing by zero.
|
// Return "n1" divided by "n2", taking care of dividing by zero.
|
||||||
varnumber_T num_divide(varnumber_T n1, varnumber_T n2)
|
varnumber_T num_divide(varnumber_T n1, varnumber_T n2)
|
||||||
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_CONST FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
|
@ -193,6 +193,13 @@ extern const list_T *eval_msgpack_type_lists[LAST_MSGPACK_TYPE + 1];
|
|||||||
|
|
||||||
#undef LAST_MSGPACK_TYPE
|
#undef LAST_MSGPACK_TYPE
|
||||||
|
|
||||||
|
// Struct passed to get_v_event() and restore_v_event().
|
||||||
|
typedef struct {
|
||||||
|
bool sve_did_save;
|
||||||
|
hashtab_T sve_hashtab;
|
||||||
|
} save_v_event_T;
|
||||||
|
|
||||||
|
|
||||||
/// trans_function_name() flags
|
/// trans_function_name() flags
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TFN_INT = 1, ///< May use internal function name
|
TFN_INT = 1, ///< May use internal function name
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
#include "nvim/spell.h"
|
#include "nvim/spell.h"
|
||||||
#include "nvim/spellfile.h"
|
#include "nvim/spellfile.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
|
#include "nvim/state.h"
|
||||||
#include "nvim/syntax.h"
|
#include "nvim/syntax.h"
|
||||||
#include "nvim/tag.h"
|
#include "nvim/tag.h"
|
||||||
#include "nvim/terminal.h"
|
#include "nvim/terminal.h"
|
||||||
|
@ -1018,58 +1018,3 @@ void add_time(char_u *buf, size_t buflen, time_t tt)
|
|||||||
seconds);
|
seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dict_T *get_v_event(save_v_event_T *sve)
|
|
||||||
{
|
|
||||||
dict_T *v_event = get_vim_var_dict(VV_EVENT);
|
|
||||||
|
|
||||||
if (v_event->dv_hashtab.ht_used > 0) {
|
|
||||||
// recursive use of v:event, save, make empty and restore later
|
|
||||||
sve->sve_did_save = true;
|
|
||||||
sve->sve_hashtab = v_event->dv_hashtab;
|
|
||||||
hash_init(&v_event->dv_hashtab);
|
|
||||||
} else {
|
|
||||||
sve->sve_did_save = false;
|
|
||||||
}
|
|
||||||
return v_event;
|
|
||||||
}
|
|
||||||
|
|
||||||
void restore_v_event(dict_T *v_event, save_v_event_T *sve)
|
|
||||||
{
|
|
||||||
tv_dict_free_contents(v_event);
|
|
||||||
if (sve->sve_did_save) {
|
|
||||||
v_event->dv_hashtab = sve->sve_hashtab;
|
|
||||||
} else {
|
|
||||||
hash_init(&v_event->dv_hashtab);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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);
|
|
||||||
}
|
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/autocmd.h"
|
||||||
#include "nvim/edit.h"
|
#include "nvim/edit.h"
|
||||||
|
#include "nvim/eval.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
@ -202,3 +204,33 @@ char *get_mode(void)
|
|||||||
|
|
||||||
return buf;
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user