diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-21 14:40:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 14:40:43 +0800 |
commit | 3b0515e674f279d6504a0fc055808cdf01eead99 (patch) | |
tree | 39f1120f66af1d5fb573241d06ce5d2d70d9a028 /src/nvim/eval/funcs.c | |
parent | 91d8f2ac534a51859c0e3c6562d07c94b27f4478 (diff) | |
parent | 6aa29d0f01e715fe51de4f66dee377e4c1726229 (diff) | |
download | rneovim-3b0515e674f279d6504a0fc055808cdf01eead99.tar.gz rneovim-3b0515e674f279d6504a0fc055808cdf01eead99.tar.bz2 rneovim-3b0515e674f279d6504a0fc055808cdf01eead99.zip |
Merge pull request #24816 from zeertzjq/vim-8.1.2044
vim-patch:8.1.{2044,2046,2047,2048,2053,2066,2067,2068,2069,2099},8.2.4299: SafeState, state()
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 250b5c5556..3c232a7163 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -4925,6 +4925,50 @@ static void f_mode(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->v_type = VAR_STRING; } +static void may_add_state_char(garray_T *gap, const char *include, uint8_t c) +{ + if (include == NULL || vim_strchr(include, c) != NULL) { + ga_append(gap, c); + } +} + +/// "state()" function +static void f_state(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + garray_T ga; + ga_init(&ga, 1, 20); + const char *include = NULL; + + if (argvars[0].v_type != VAR_UNKNOWN) { + include = tv_get_string(&argvars[0]); + } + + if (!(stuff_empty() && typebuf.tb_len == 0 && !using_script())) { + may_add_state_char(&ga, include, 'm'); + } + if (op_pending()) { + may_add_state_char(&ga, include, 'o'); + } + if (autocmd_busy) { + may_add_state_char(&ga, include, 'x'); + } + if (ins_compl_active()) { + may_add_state_char(&ga, include, 'a'); + } + if (!get_was_safe_state()) { + may_add_state_char(&ga, include, 'S'); + } + for (int i = 0; i < get_callback_depth() && i < 3; i++) { + may_add_state_char(&ga, include, 'c'); + } + if (msg_scrolled > 0) { + may_add_state_char(&ga, include, 's'); + } + + rettv->v_type = VAR_STRING; + rettv->vval.v_string = ga.ga_data; +} + /// "msgpackdump()" function static void f_msgpackdump(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) FUNC_ATTR_NONNULL_ALL |