patch 8.2.2785: Vim9: cannot redirect to local variable
Problem: Vim9: cannot redirect to local variable.
Solution: Compile :redir when redirecting to a variable.
diff --git a/src/evalvars.c b/src/evalvars.c
index 9952ffc..1b0b7d0 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3778,6 +3778,27 @@
static char_u *redir_endp = NULL;
static char_u *redir_varname = NULL;
+ int
+alloc_redir_lval(void)
+{
+ redir_lval = ALLOC_CLEAR_ONE(lval_T);
+ if (redir_lval == NULL)
+ return FAIL;
+ return OK;
+}
+
+ void
+clear_redir_lval(void)
+{
+ VIM_CLEAR(redir_lval);
+}
+
+ void
+init_redir_ga(void)
+{
+ ga_init2(&redir_ga, (int)sizeof(char), 500);
+}
+
/*
* Start recording command output to a variable
* When "append" is TRUE append to an existing variable.
@@ -3801,15 +3822,14 @@
if (redir_varname == NULL)
return FAIL;
- redir_lval = ALLOC_CLEAR_ONE(lval_T);
- if (redir_lval == NULL)
+ if (alloc_redir_lval() == FAIL)
{
var_redir_stop();
return FAIL;
}
// The output is stored in growarray "redir_ga" until redirection ends.
- ga_init2(&redir_ga, (int)sizeof(char), 500);
+ init_redir_ga();
// Parse the variable name (can be a dict or list entry).
redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, 0,
@@ -3922,6 +3942,20 @@
}
/*
+ * Get the collected redirected text and clear redir_ga.
+ */
+ char_u *
+get_clear_redir_ga(void)
+{
+ char_u *res;
+
+ ga_append(&redir_ga, NUL); // Append the trailing NUL.
+ res = redir_ga.ga_data;
+ redir_ga.ga_data = NULL;
+ return res;
+}
+
+/*
* "gettabvar()" function
*/
void