0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2022-09-04 15:40:36 +01:00
parent c1eb131c9e
commit 806a273f3c
11 changed files with 254 additions and 85 deletions

View File

@@ -1684,6 +1684,27 @@ compile_eval(char_u *arg, cctx_T *cctx)
return skipwhite(p);
}
/*
* 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)".
*/
@@ -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);