From f87dac04c351583241ea1c4ec4228516431e6f22 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 15 Dec 2021 17:53:40 +0000 Subject: patch 8.2.3817: Vim9: Not using NL as command end does not work for :autocmd Problem: Vim9: Not using NL as command end does not work for :autocmd. Solution: Only ignore NL for commands with an expression argument. --- src/ex_cmds.h | 41 ++++++++++++++++++++------------------- src/ex_docmd.c | 2 +- src/testdir/test_usercommands.vim | 17 +++++++++++++--- src/version.c | 2 ++ 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/ex_cmds.h b/src/ex_cmds.h index fcf15ba60..c2657b0ff 100644 --- a/src/ex_cmds.h +++ b/src/ex_cmds.h @@ -57,6 +57,7 @@ // buffer when curbuf_lock is set #define EX_NONWHITE_OK 0x2000000 // command can be followed by non-white #define EX_KEEPSCRIPT 0x4000000 // keep sctx of where command was invoked +#define EX_EXPR_ARG 0x8000000 // argument is an expression #define EX_FILES (EX_XFILE | EX_EXTRA) // multiple extra files allowed #define EX_FILE1 (EX_FILES | EX_NOSPC) // 1 file, defaults to current file @@ -265,7 +266,7 @@ EXCMD(CMD_caddbuffer, "caddbuffer", ex_cbuffer, EX_RANGE|EX_WORD1|EX_TRLBAR, ADDR_OTHER), EXCMD(CMD_caddexpr, "caddexpr", ex_cexpr, - EX_NEEDARG|EX_WORD1|EX_NOTRLCOM, + EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG, ADDR_NONE), EXCMD(CMD_caddfile, "caddfile", ex_cfile, EX_TRLBAR|EX_FILE1, @@ -274,7 +275,7 @@ EXCMD(CMD_cafter, "cafter", ex_cbelow, EX_RANGE|EX_COUNT|EX_TRLBAR, ADDR_UNSIGNED), EXCMD(CMD_call, "call", ex_call, - EX_RANGE|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_RANGE|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_LINES), EXCMD(CMD_catch, "catch", ex_catch, EX_EXTRA|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, @@ -307,7 +308,7 @@ EXCMD(CMD_center, "center", ex_align, EX_TRLBAR|EX_RANGE|EX_WHOLEFOLD|EX_EXTRA|EX_CMDWIN|EX_LOCK_OK|EX_MODIFY, ADDR_LINES), EXCMD(CMD_cexpr, "cexpr", ex_cexpr, - EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_BANG, + EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG|EX_BANG, ADDR_NONE), EXCMD(CMD_cfile, "cfile", ex_cfile, EX_TRLBAR|EX_FILE1|EX_BANG, @@ -325,7 +326,7 @@ EXCMD(CMD_cgetbuffer, "cgetbuffer", ex_cbuffer, EX_RANGE|EX_WORD1|EX_TRLBAR, ADDR_OTHER), EXCMD(CMD_cgetexpr, "cgetexpr", ex_cexpr, - EX_NEEDARG|EX_WORD1|EX_NOTRLCOM, + EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG, ADDR_NONE), EXCMD(CMD_chdir, "chdir", ex_cd, EX_BANG|EX_FILE1|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, @@ -409,7 +410,7 @@ EXCMD(CMD_confirm, "confirm", ex_wrongmodifier, EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_const, "const", ex_let, - EX_EXTRA|EX_BANG|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_BANG|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_copen, "copen", ex_copen, EX_RANGE|EX_COUNT|EX_TRLBAR, @@ -526,28 +527,28 @@ EXCMD(CMD_earlier, "earlier", ex_later, EX_TRLBAR|EX_EXTRA|EX_NOSPC|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_echo, "echo", ex_echo, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_echoerr, "echoerr", ex_execute, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_echohl, "echohl", ex_echohl, EX_EXTRA|EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_echomsg, "echomsg", ex_execute, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_echoconsole, "echoconsole", ex_execute, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_echon, "echon", ex_echo, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_else, "else", ex_else, EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_elseif, "elseif", ex_else, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_emenu, "emenu", ex_emenu, EX_NEEDARG|EX_EXTRA|EX_TRLBAR|EX_NOTRLCOM|EX_RANGE|EX_CMDWIN|EX_LOCK_OK, @@ -586,19 +587,19 @@ EXCMD(CMD_enum, "enum", ex_ni, EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_eval, "eval", ex_eval, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_ex, "ex", ex_edit, EX_BANG|EX_FILE1|EX_CMDARG|EX_ARGOPT|EX_TRLBAR, ADDR_NONE), EXCMD(CMD_execute, "execute", ex_execute, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_exit, "exit", ex_exit, EX_RANGE|EX_WHOLEFOLD|EX_BANG|EX_FILE1|EX_ARGOPT|EX_DFLALL|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_LINES), EXCMD(CMD_export, "export", ex_export, - EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_exusage, "exusage", ex_exusage, EX_TRLBAR, @@ -649,7 +650,7 @@ EXCMD(CMD_foldopen, "foldopen", ex_foldopen, EX_RANGE|EX_BANG|EX_WHOLEFOLD|EX_TRLBAR|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_LINES), EXCMD(CMD_for, "for", ex_while, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_function, "function", ex_function, EX_EXTRA|EX_BANG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, @@ -709,7 +710,7 @@ EXCMD(CMD_iabclear, "iabclear", ex_abclear, EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_if, "if", ex_if, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_ijump, "ijump", ex_findpat, EX_BANG|EX_RANGE|EX_DFLALL|EX_WHOLEFOLD|EX_EXTRA, @@ -799,7 +800,7 @@ EXCMD(CMD_language, "language", ex_language, EX_EXTRA|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_laddexpr, "laddexpr", ex_cexpr, - EX_NEEDARG|EX_WORD1|EX_NOTRLCOM, + EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG, ADDR_NONE), EXCMD(CMD_laddbuffer, "laddbuffer", ex_cbuffer, EX_RANGE|EX_WORD1|EX_TRLBAR, @@ -847,10 +848,10 @@ EXCMD(CMD_leftabove, "leftabove", ex_wrongmodifier, EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM, ADDR_NONE), EXCMD(CMD_let, "let", ex_let, - EX_EXTRA|EX_NOTRLCOM|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, + EX_EXTRA|EX_NOTRLCOM|EX_EXPR_ARG|EX_SBOXOK|EX_CMDWIN|EX_LOCK_OK, ADDR_NONE), EXCMD(CMD_lexpr, "lexpr", ex_cexpr, - EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_BANG, + EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG|EX_BANG, ADDR_NONE), EXCMD(CMD_legacy, "legacy", ex_wrongmodifier, EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_CMDWIN|EX_LOCK_OK, @@ -871,7 +872,7 @@ EXCMD(CMD_lgetbuffer, "lgetbuffer", ex_cbuffer, EX_RANGE|EX_WORD1|EX_TRLBAR, ADDR_OTHER), EXCMD(CMD_lgetexpr, "lgetexpr", ex_cexpr, - EX_NEEDARG|EX_WORD1|EX_NOTRLCOM, + EX_NEEDARG|EX_WORD1|EX_NOTRLCOM|EX_EXPR_ARG, ADDR_NONE), EXCMD(CMD_lgrep, "lgrep", ex_make, EX_RANGE|EX_BANG|EX_NEEDARG|EX_EXTRA|EX_NOTRLCOM|EX_TRLBAR|EX_XFILE, diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 5f5240119..ab0a146fb 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -2305,7 +2305,7 @@ do_one_cmd( // versions. if (*p == '\\' && p[1] == '\n') STRMOVE(p, p + 1); - else if (*p == '\n' && (ea.argt & EX_TRLBAR)) + else if (*p == '\n' && !(ea.argt & EX_EXPR_ARG)) { ea.nextcmd = p + 1; *p = NUL; diff --git a/src/testdir/test_usercommands.vim b/src/testdir/test_usercommands.vim index b57ed0aa3..808a2c7d8 100644 --- a/src/testdir/test_usercommands.vim +++ b/src/testdir/test_usercommands.vim @@ -648,12 +648,23 @@ func Test_usercmd_with_block() call CheckScriptFailure(lines, 'E1026:') let lines =<< trim END - command BarCommand { + command HelloThere { echo 'hello' | echo 'there' } - BarCommand + HelloThere END - call CheckScriptFailure(lines, 'E1231:') + call CheckScriptSuccess(lines) + delcommand HelloThere + + let lines =<< trim END + command BadCommand { + echo { + 'key': 'value', + } + } + BadCommand + END + call CheckScriptFailure(lines, 'E1128:') endfunc func Test_delcommand_buffer() diff --git a/src/version.c b/src/version.c index 1b8368534..e9836ef41 100644 --- a/src/version.c +++ b/src/version.c @@ -749,6 +749,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 3817, /**/ 3816, /**/ -- cgit v1.2.1