diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-09-04 15:40:36 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-09-04 15:40:36 +0100 |
commit | 806a273f3c84ecd475913d901890bb1929be9a0a (patch) | |
tree | 7970b531379736fd2497f3a1acea0c400028db81 /src/vim9cmds.c | |
parent | c1eb131c9eb38e00e08109f50e3e5337c072b71e (diff) | |
download | vim-git-806a273f3c84ecd475913d901890bb1929be9a0a.tar.gz |
patch 9.0.0379: cleaning up after writefile() is a hasslev9.0.0379
Problem: Cleaning up after writefile() is a hassle.
Solution: Add the 'D' flag to defer deleting the written file. Very useful
in tests.
Diffstat (limited to 'src/vim9cmds.c')
-rw-r--r-- | src/vim9cmds.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/vim9cmds.c b/src/vim9cmds.c index 9651801ed..c294d70a8 100644 --- a/src/vim9cmds.c +++ b/src/vim9cmds.c @@ -1685,6 +1685,27 @@ compile_eval(char_u *arg, cctx_T *cctx) } /* + * Get the local variable index for deferred function calls. + * Reserve it when not done already. + * Returns zero for failure. + */ + int +get_defer_var_idx(cctx_T *cctx) +{ + dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + + cctx->ctx_ufunc->uf_dfunc_idx; + if (dfunc->df_defer_var_idx == 0) + { + lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, + TRUE, &t_list_any); + if (lvar == NULL) + return 0; + dfunc->df_defer_var_idx = lvar->lv_idx + 1; + } + return dfunc->df_defer_var_idx; +} + +/* * Compile "defer func(arg)". */ char_u * @@ -1693,7 +1714,7 @@ compile_defer(char_u *arg_start, cctx_T *cctx) char_u *p; char_u *arg = arg_start; int argcount = 0; - dfunc_T *dfunc; + int defer_var_idx; type_T *type; int func_idx; @@ -1730,16 +1751,10 @@ compile_defer(char_u *arg_start, cctx_T *cctx) // TODO: check argument count with "type" - dfunc = ((dfunc_T *)def_functions.ga_data) + cctx->ctx_ufunc->uf_dfunc_idx; - if (dfunc->df_defer_var_idx == 0) - { - lvar_T *lvar = reserve_local(cctx, (char_u *)"@defer@", 7, - TRUE, &t_list_any); - if (lvar == NULL) - return NULL; - dfunc->df_defer_var_idx = lvar->lv_idx + 1; - } - if (generate_DEFER(cctx, dfunc->df_defer_var_idx - 1, argcount) == FAIL) + defer_var_idx = get_defer_var_idx(cctx); + if (defer_var_idx == 0) + return NULL; + if (generate_DEFER(cctx, defer_var_idx - 1, argcount) == FAIL) return NULL; return skipwhite(arg); |