diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-04-19 20:50:03 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-04-19 20:50:03 +0200 |
commit | 2d1c57ed3dd25c44b41b9ddd4cf63c01ae89007e (patch) | |
tree | 3ffc5635d92db32e5310f46c879ca0424223d21e /src/evalvars.c | |
parent | 4c13721482d7786f92f5a56e43b0f5c499264b7e (diff) |
patch 8.2.2785: Vim9: cannot redirect to local variablev8.2.2785
Problem: Vim9: cannot redirect to local variable.
Solution: Compile :redir when redirecting to a variable.
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 9952ffcadf..1b0b7d0c98 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -3778,6 +3778,27 @@ static garray_T redir_ga; // only valid when redir_lval is not NULL 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 @@ var_redir_start(char_u *name, int append) 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 @@ var_redir_stop(void) } /* + * 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 |