From 63b9173693015b135aad8e3657bef5e7f776787e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 5 Aug 2021 20:40:03 +0200 Subject: patch 8.2.3297: cannot use all commands inside a {} block Problem: Cannot use all commands inside a {} block after :command and :autocmd. Solution: Do consider \n to separate commands. (closes #8620) --- src/ex_docmd.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/ex_docmd.c') diff --git a/src/ex_docmd.c b/src/ex_docmd.c index fde68be72..a0e8370c2 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -2314,22 +2314,24 @@ do_one_cmd( ea.do_ecmd_cmd = getargcmd(&ea.arg); /* - * Check for '|' to separate commands and '"' or '#' to start comments. - * Don't do this for ":read !cmd" and ":write !cmd". - */ - if ((ea.argt & EX_TRLBAR) && !ea.usefilter) - separate_nextcmd(&ea); - - /* - * Check for to end a shell command. + * For commands that do not use '|' inside their argument: Check for '|' to + * separate commands and '"' or '#' to start comments. + * + * Otherwise: Check for to end a shell command. * Also do this for ":read !cmd", ":write !cmd" and ":global". + * Also do this inside a { - } block after :command and :autocmd. * Any others? */ + if ((ea.argt & EX_TRLBAR) && !ea.usefilter) + { + separate_nextcmd(&ea); + } else if (ea.cmdidx == CMD_bang || ea.cmdidx == CMD_terminal || ea.cmdidx == CMD_global || ea.cmdidx == CMD_vglobal - || ea.usefilter) + || ea.usefilter + || inside_block(&ea)) { for (p = ea.arg; *p; ++p) { @@ -5409,6 +5411,21 @@ check_nextcmd(char_u *p) return NULL; } +/* + * If "eap->nextcmd" is not set, check for a next command at "p". + */ + void +set_nextcmd(exarg_T *eap, char_u *arg) +{ + char_u *p = check_nextcmd(arg); + + if (eap->nextcmd == NULL) + eap->nextcmd = p; + else if (p != NULL) + // cannot use "| command" inside a {} block + semsg(_(e_cannot_use_bar_to_separate_commands_here_str), arg); +} + /* * - if there are more files to edit * - and this is the last window @@ -7546,7 +7563,7 @@ ex_wincmd(exarg_T *eap) else p = eap->arg + 1; - eap->nextcmd = check_nextcmd(p); + set_nextcmd(eap, p); p = skipwhite(p); if (*p != NUL && *p != ( #ifdef FEAT_EVAL @@ -8580,7 +8597,7 @@ ex_findpat(exarg_T *eap) if (!ends_excmd2(eap->arg, p)) eap->errmsg = ex_errmsg(e_trailing_arg, p); else - eap->nextcmd = check_nextcmd(p); + set_nextcmd(eap, p); } } if (!eap->skip) -- cgit v1.2.1