diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-16 11:07:48 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-16 15:04:41 +0800 |
commit | 0167649ce4071e60d985b65f3f9408ffb21cb58c (patch) | |
tree | 0a6e9e3e31fc47d02de3561a7c063417ea3b45d2 /src/nvim/eval/userfunc.c | |
parent | b75634e55ee4cdfee7917b29f39e3ca1307cb059 (diff) | |
download | rneovim-0167649ce4071e60d985b65f3f9408ffb21cb58c.tar.gz rneovim-0167649ce4071e60d985b65f3f9408ffb21cb58c.tar.bz2 rneovim-0167649ce4071e60d985b65f3f9408ffb21cb58c.zip |
vim-patch:9.0.0379: cleaning up after writefile() is a hassle
Problem: Cleaning up after writefile() is a hassle.
Solution: Add the 'D' flag to defer deleting the written file. Very useful
in tests.
https://github.com/vim/vim/commit/806a273f3c84ecd475913d901890bb1929be9a0a
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/eval/userfunc.c')
-rw-r--r-- | src/nvim/eval/userfunc.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 9853622ee0..4b9bc1fdec 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -478,6 +478,7 @@ void emsg_funcname(const char *errmsg, const char *name) /// Get function arguments at "*arg" and advance it. /// Return them in "*argvars[MAX_FUNC_ARGS + 1]" and the count in "argcount". +/// On failure FAIL is returned but the "argvars[argcount]" are still set. static int get_func_arguments(char **arg, evalarg_T *const evalarg, int partial_argc, typval_T *argvars, int *argcount) { @@ -3119,16 +3120,28 @@ static int ex_defer_inner(char *name, char **arg, evalarg_T *const evalarg) { typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments int argcount = 0; // number of arguments found - int ret = FAIL; if (current_funccal == NULL) { semsg(_(e_str_not_inside_function), "defer"); return FAIL; } if (get_func_arguments(arg, evalarg, false, argvars, &argcount) == FAIL) { - goto theend; + while (--argcount >= 0) { + tv_clear(&argvars[argcount]); + } + return FAIL; } + add_defer(name, argcount, argvars); + return OK; +} + +/// Add a deferred call for "name" with arguments "argvars[argcount]". +/// Consumes "argvars[]". +/// Caller must check that current_funccal is not NULL. +void add_defer(char *name, int argcount_arg, typval_T *argvars) +{ char *saved_name = xstrdup(name); + int argcount = argcount_arg; if (current_funccal->fc_defer.ga_itemsize == 0) { ga_init(¤t_funccal->fc_defer, sizeof(defer_T), 10); @@ -3140,13 +3153,6 @@ static int ex_defer_inner(char *name, char **arg, evalarg_T *const evalarg) argcount--; dr->dr_argvars[argcount] = argvars[argcount]; } - ret = OK; - -theend: - while (--argcount >= 0) { - tv_clear(&argvars[argcount]); - } - return ret; } /// Invoked after a function has finished: invoke ":defer" functions. |