diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-16 11:37:41 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-16 15:04:41 +0800 |
commit | 7b05ddbb72717f995fedc81583d73f82c78c881d (patch) | |
tree | 0e09fc8651f9fabd194751f2b9fcd56c3c1118d8 /src/nvim/eval/userfunc.c | |
parent | 335bef0c211dc962499814d248670ff17758a642 (diff) | |
download | rneovim-7b05ddbb72717f995fedc81583d73f82c78c881d.tar.gz rneovim-7b05ddbb72717f995fedc81583d73f82c78c881d.tar.bz2 rneovim-7b05ddbb72717f995fedc81583d73f82c78c881d.zip |
vim-patch:9.0.0397: :defer not tested with exceptions and ":qa!"
Problem: :defer not tested with exceptions and ":qa!".
Solution: Test :defer works when exceptions are thrown and when ":qa!" is
used. Invoke the deferred calls on exit.
https://github.com/vim/vim/commit/58779858fb5a82a3233af5d4237a3cece88c10d4
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/eval/userfunc.c')
-rw-r--r-- | src/nvim/eval/userfunc.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index e9e780747a..0a8e5c349a 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1176,7 +1176,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett } // Invoke functions added with ":defer". - handle_defer(); + handle_defer_one(current_funccal); RedrawingDisabled--; @@ -3174,10 +3174,10 @@ void add_defer(char *name, int argcount_arg, typval_T *argvars) } /// Invoked after a function has finished: invoke ":defer" functions. -static void handle_defer(void) +static void handle_defer_one(funccall_T *funccal) { - for (int idx = current_funccal->fc_defer.ga_len - 1; idx >= 0; idx--) { - defer_T *dr = ((defer_T *)current_funccal->fc_defer.ga_data) + idx; + for (int idx = funccal->fc_defer.ga_len - 1; idx >= 0; idx--) { + defer_T *dr = ((defer_T *)funccal->fc_defer.ga_data) + idx; funcexe_T funcexe = { .fe_evaluate = true }; typval_T rettv; rettv.v_type = VAR_UNKNOWN; // tv_clear() uses this @@ -3188,7 +3188,15 @@ static void handle_defer(void) tv_clear(&dr->dr_argvars[i]); } } - ga_clear(¤t_funccal->fc_defer); + ga_clear(&funccal->fc_defer); +} + +/// Called when exiting: call all defer functions. +void invoke_all_defer(void) +{ + for (funccall_T *funccal = current_funccal; funccal != NULL; funccal = funccal->caller) { + handle_defer_one(funccal); + } } /// ":1,25call func(arg1, arg2)" function call. |