aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-14 13:32:47 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-04-14 16:10:09 +0800
commite99f28e57d69cfa1bd38ab531a0954f4f875ca47 (patch)
treebd6961d931f0cd3d2fafcb50e59271a838e70547 /src/nvim/eval.c
parent64a91f5ea2424674b0f2550e33f3f8512af75231 (diff)
downloadrneovim-e99f28e57d69cfa1bd38ab531a0954f4f875ca47.tar.gz
rneovim-e99f28e57d69cfa1bd38ab531a0954f4f875ca47.tar.bz2
rneovim-e99f28e57d69cfa1bd38ab531a0954f4f875ca47.zip
vim-patch:8.2.1076: Vim9: no line break allowed in :if expression
Problem: Vim9: no line break allowed in :if expression. Solution: Skip linebreak. https://github.com/vim/vim/commit/faf8626b79e380fe81e7ae2439a535ed7619d27b Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 16db4e791b..a79a464860 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -703,10 +703,15 @@ int eval_to_bool(char *arg, bool *error, exarg_T *eap, int skip)
typval_T tv;
bool retval = false;
+ evalarg_T evalarg = {
+ .eval_flags = skip ? 0 : EVAL_EVALUATE,
+ .eval_cookie = eap != NULL && eap->getline == getsourceline ? eap->cookie : NULL,
+ };
+
if (skip) {
emsg_skip++;
}
- if (eval0(arg, &tv, eap, skip ? NULL : &EVALARG_EVALUATE) == FAIL) {
+ if (eval0(arg, &tv, eap, &evalarg) == FAIL) {
*error = true;
} else {
*error = false;
@@ -718,6 +723,7 @@ int eval_to_bool(char *arg, bool *error, exarg_T *eap, int skip)
if (skip) {
emsg_skip--;
}
+ clear_evalarg(&evalarg, eap);
return retval;
}
@@ -2228,6 +2234,20 @@ static int eval_func(char **const arg, char *const name, const int name_len, typ
return ret;
}
+/// After using "evalarg" filled from "eap" free the memory.
+void clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
+{
+ if (evalarg != NULL && eap != NULL && evalarg->eval_tofree != NULL) {
+ // We may need to keep the original command line, e.g. for
+ // ":let" it has the variable names. But we may also need the
+ // new one, "nextcmd" points into it. Keep both.
+ xfree(eap->cmdline_tofree);
+ eap->cmdline_tofree = *eap->cmdlinep;
+ *eap->cmdlinep = evalarg->eval_tofree;
+ evalarg->eval_tofree = NULL;
+ }
+}
+
/// The "evaluate" argument: When false, the argument is only parsed but not
/// executed. The function may return OK, but the rettv will be of type
/// VAR_UNKNOWN. The function still returns FAIL for a syntax error.
@@ -2278,15 +2298,7 @@ int eval0(char *arg, typval_T *rettv, exarg_T *eap, evalarg_T *const evalarg)
eap->nextcmd = check_nextcmd(p);
}
- if (evalarg != NULL && eap != NULL && evalarg->eval_tofree != NULL) {
- // We may need to keep the original command line, e.g. for
- // ":let" it has the variable names. But we may also need the
- // new one, "nextcmd" points into it. Keep both.
- xfree(eap->cmdline_tofree);
- eap->cmdline_tofree = *eap->cmdlinep;
- *eap->cmdlinep = evalarg->eval_tofree;
- evalarg->eval_tofree = NULL;
- }
+ clear_evalarg(evalarg, eap);
return ret;
}
@@ -7502,6 +7514,7 @@ void ex_echo(exarg_T *eap)
arg = skipwhite(arg);
}
eap->nextcmd = check_nextcmd(arg);
+ clear_evalarg(&evalarg, eap);
if (eap->skip) {
emsg_skip--;