Patch 8.2.1914
Problem: Vim9: cannot put line break in expression for '=' register.
Solution: Pass fgetline to set_expr_line(). (closes #7209)
Files: src/register.c, src/proto/register.pro, src/ex_docmd.c,
src/eval.c, src/proto/eval.pro, src/misc2.c,
src/testdir/test_vim9_script.vim
*** ../vim-8.2.1913/src/register.c 2020-10-24 20:49:37.502683026 +0200
--- src/register.c 2020-10-28 13:31:46.105008553 +0100
***************
*** 79,84 ****
--- 79,85 ----
* Keep the last expression line here, for repeating.
*/
static char_u *expr_line = NULL;
+ static exarg_T *expr_eap = NULL;
/*
* Get an expression for the "\"=expr1" or "CTRL-R =expr1"
***************
*** 95,113 ****
if (*new_line == NUL) // use previous line
vim_free(new_line);
else
! set_expr_line(new_line);
return '=';
}
/*
* Set the expression for the '=' register.
* Argument must be an allocated string.
*/
void
! set_expr_line(char_u *new_line)
{
vim_free(expr_line);
expr_line = new_line;
}
/*
--- 96,117 ----
if (*new_line == NUL) // use previous line
vim_free(new_line);
else
! set_expr_line(new_line, NULL);
return '=';
}
/*
* Set the expression for the '=' register.
* Argument must be an allocated string.
+ * "eap" may be used if the next line needs to be checked when evaluating the
+ * expression.
*/
void
! set_expr_line(char_u *new_line, exarg_T *eap)
{
vim_free(expr_line);
expr_line = new_line;
+ expr_eap = eap;
}
/*
***************
*** 136,142 ****
return expr_copy;
++nested;
! rv = eval_to_string(expr_copy, TRUE);
--nested;
vim_free(expr_copy);
return rv;
--- 140,146 ----
return expr_copy;
++nested;
! rv = eval_to_string_eap(expr_copy, TRUE, expr_eap);
--nested;
vim_free(expr_copy);
return rv;
***************
*** 2774,2780 ****
vim_free(p);
p = s;
}
! set_expr_line(p);
return;
}
--- 2778,2784 ----
vim_free(p);
p = s;
}
! set_expr_line(p, NULL);
return;
}
*** ../vim-8.2.1913/src/proto/register.pro 2020-09-08 22:45:31.113504961
+0200
--- src/proto/register.pro 2020-10-28 12:57:07.239038076 +0100
***************
*** 6,12 ****
void set_y_current(yankreg_T *yreg);
void set_y_previous(yankreg_T *yreg);
int get_expr_register(void);
! void set_expr_line(char_u *new_line);
char_u *get_expr_line(void);
int valid_yank_reg(int regname, int writing);
int get_yank_register(int regname, int writing);
--- 6,12 ----
void set_y_current(yankreg_T *yreg);
void set_y_previous(yankreg_T *yreg);
int get_expr_register(void);
! void set_expr_line(char_u *new_line, exarg_T *eap);
char_u *get_expr_line(void);
int valid_yank_reg(int regname, int writing);
int get_yank_register(int regname, int writing);
*** ../vim-8.2.1913/src/ex_docmd.c 2020-10-26 21:39:09.119677673 +0100
--- src/ex_docmd.c 2020-10-28 12:48:25.580384525 +0100
***************
*** 1719,1724 ****
--- 1719,1725 ----
#ifdef FEAT_EVAL
int may_have_range;
int vim9script = in_vim9script();
+ int did_set_expr_line = FALSE;
#endif
CLEAR_FIELD(ea);
***************
*** 2315,2322 ****
// for '=' register: accept the rest of the line as an expression
if (ea.arg[-1] == '=' && ea.arg[0] != NUL)
{
! set_expr_line(vim_strsave(ea.arg));
ea.arg += STRLEN(ea.arg);
}
#endif
ea.arg = skipwhite(ea.arg);
--- 2316,2324 ----
// for '=' register: accept the rest of the line as an expression
if (ea.arg[-1] == '=' && ea.arg[0] != NUL)
{
! set_expr_line(vim_strsave(ea.arg), &ea);
ea.arg += STRLEN(ea.arg);
+ did_set_expr_line = TRUE;
}
#endif
ea.arg = skipwhite(ea.arg);
***************
*** 2595,2600 ****
--- 2597,2605 ----
do_errthrow(cstack,
(ea.cmdidx != CMD_SIZE && !IS_USER_CMDIDX(ea.cmdidx))
? cmdnames[(int)ea.cmdidx].cmd_name : (char_u *)NULL);
+
+ if (did_set_expr_line)
+ set_expr_line(NULL, NULL);
#endif
undo_cmdmod(&cmdmod);
*** ../vim-8.2.1913/src/eval.c 2020-10-22 21:22:54.740905315 +0200
--- src/eval.c 2020-10-28 12:56:09.067190312 +0100
***************
*** 474,482 ****
* Return pointer to allocated memory, or NULL for failure.
*/
char_u *
! eval_to_string(
char_u *arg,
! int convert)
{
typval_T tv;
char_u *retval;
--- 474,483 ----
* Return pointer to allocated memory, or NULL for failure.
*/
char_u *
! eval_to_string_eap(
char_u *arg,
! int convert,
! exarg_T *eap)
{
typval_T tv;
char_u *retval;
***************
*** 484,491 ****
#ifdef FEAT_FLOAT
char_u numbuf[NUMBUFLEN];
#endif
! if (eval0(arg, &tv, NULL, &EVALARG_EVALUATE) == FAIL)
retval = NULL;
else
{
--- 485,494 ----
#ifdef FEAT_FLOAT
char_u numbuf[NUMBUFLEN];
#endif
+ evalarg_T evalarg;
! fill_evalarg_from_eap(&evalarg, eap, eap != NULL && eap->skip);
! if (eval0(arg, &tv, NULL, &evalarg) == FAIL)
retval = NULL;
else
{
***************
*** 512,522 ****
retval = vim_strsave(tv_get_string(&tv));
clear_tv(&tv);
}
! clear_evalarg(&EVALARG_EVALUATE, NULL);
return retval;
}
/*
* Call eval_to_string() without using current local variables and using
* textwinlock. When "use_sandbox" is TRUE use the sandbox.
--- 515,533 ----
retval = vim_strsave(tv_get_string(&tv));
clear_tv(&tv);
}
! clear_evalarg(&evalarg, NULL);
return retval;
}
+ char_u *
+ eval_to_string(
+ char_u *arg,
+ int convert)
+ {
+ return eval_to_string_eap(arg, convert, NULL);
+ }
+
/*
* Call eval_to_string() without using current local variables and using
* textwinlock. When "use_sandbox" is TRUE use the sandbox.
*** ../vim-8.2.1913/src/proto/eval.pro 2020-10-22 21:22:54.740905315 +0200
--- src/proto/eval.pro 2020-10-28 12:56:39.743110086 +0100
***************
*** 11,16 ****
--- 11,17 ----
char_u *eval_to_string_skip(char_u *arg, exarg_T *eap, int skip);
int skip_expr(char_u **pp, evalarg_T *evalarg);
int skip_expr_concatenate(char_u **arg, char_u **start, char_u **end,
evalarg_T *evalarg);
+ char_u *eval_to_string_eap(char_u *arg, int convert, exarg_T *eap);
char_u *eval_to_string(char_u *arg, int convert);
char_u *eval_to_string_safe(char_u *arg, int use_sandbox);
varnumber_T eval_to_number(char_u *expr);
*** ../vim-8.2.1913/src/misc2.c 2020-10-07 17:28:47.473370302 +0200
--- src/misc2.c 2020-10-28 13:30:27.749258290 +0100
***************
*** 1131,1137 ****
free_signs();
# endif
# ifdef FEAT_EVAL
! set_expr_line(NULL);
# endif
# ifdef FEAT_DIFF
if (curtab != NULL)
--- 1131,1137 ----
free_signs();
# endif
# ifdef FEAT_EVAL
! set_expr_line(NULL, NULL);
# endif
# ifdef FEAT_DIFF
if (curtab != NULL)
*** ../vim-8.2.1913/src/testdir/test_vim9_script.vim 2020-10-20
14:25:03.930883006 +0200
--- src/testdir/test_vim9_script.vim 2020-10-28 13:52:12.261397120 +0100
***************
*** 2859,2864 ****
--- 2859,2876 ----
unlet g:caught
enddef
+ def Test_put_with_linebreak()
+ new
+ var lines =<< trim END
+ vim9script
+ pu=split('abc', '\zs')
+ ->join()
+ END
+ CheckScriptSuccess(lines)
+ getline(2)->assert_equal('a b c')
+ bwipe!
+ enddef
+
" Keep this last, it messes up highlighting.
def Test_substitute_cmd()
new
*** ../vim-8.2.1913/src/version.c 2020-10-27 20:43:22.931862991 +0100
--- src/version.c 2020-10-28 13:52:44.685304876 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1914,
/**/
--
hundred-and-one symptoms of being an internet addict:
141. You'd rather go to http://www.weather.com/ than look out your window.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202010281254.09SCsYF02140131%40masaka.moolenaar.net.