diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-06-03 17:39:46 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-06-03 17:39:46 +0100 |
commit | 75ebd2aab0f009049561f60424d521ba5f80063a (patch) | |
tree | 08dcb10638a10e06467a8372d0916f02c84d41ad | |
parent | bfaa24f95343af9c058696644375d04e660f1b00 (diff) | |
download | vim-git-75ebd2aab0f009049561f60424d521ba5f80063a.tar.gz |
patch 8.2.5053: cannot have a comment halfway an expression in a blockv8.2.5053
Problem: Cannot have a comment halfway an expression in an autocmd command
block.
Solution: When skipping over the NL also skip over comments. (closes #10519)
-rw-r--r-- | src/eval.c | 33 | ||||
-rw-r--r-- | src/testdir/test_autocmd.vim | 16 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 49 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c index 5f9c3423d..dce78f7f0 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2136,6 +2136,35 @@ eval_func( } /* + * After a NL, skip over empty lines and comment-only lines. + */ + static char_u * +newline_skip_comments(char_u *arg) +{ + char_u *p = arg + 1; + + for (;;) + { + p = skipwhite(p); + + if (*p == NUL) + break; + if (vim9_comment_start(p)) + { + char_u *nl = vim_strchr(p, NL); + + if (nl == NULL) + break; + p = nl; + } + if (*p != NL) + break; + ++p; // skip another NL + } + return p; +} + +/* * Get the next line source line without advancing. But do skip over comment * lines. * Only called for Vim9 script. @@ -2184,7 +2213,7 @@ eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext) char_u *next; if (*p == NL) - next = p + 1; + next = newline_skip_comments(p); else if (evalarg->eval_cookie != NULL) next = getline_peek_skip_comments(evalarg); else @@ -2212,7 +2241,7 @@ eval_next_line(char_u *arg, evalarg_T *evalarg) if (arg != NULL) { if (*arg == NL) - return skipwhite(arg + 1); + return newline_skip_comments(arg); // Truncate before a trailing comment, so that concatenating the lines // won't turn the rest into a comment. if (*skipwhite(arg) == '#') diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index 1a4ed1a62..24e2ed984 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -3102,6 +3102,22 @@ func Test_autocmd_with_block() augroup block_testing au! + autocmd CursorHold * { + if true + # comment + && true + + && true + g:done = 'yes' + endif + } + augroup END + doautocmd CursorHold + call assert_equal('yes', g:done) + + unlet g:done + augroup block_testing + au! augroup END endfunc diff --git a/src/version.c b/src/version.c index 36a69d922..0f33fb2f2 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 5053, +/**/ 5052, /**/ 5051, |