changeset 29062:036b4d49c4a0 v8.2.5053

patch 8.2.5053: cannot have a comment halfway an expression in a block Commit: https://github.com/vim/vim/commit/75ebd2aab0f009049561f60424d521ba5f80063a Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 3 17:39:46 2022 +0100 patch 8.2.5053: cannot have a comment halfway an expression in a block 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 03 Jun 2022 18:45:05 +0200
parents 420b1439214e
children c079d173c33d
files src/eval.c src/testdir/test_autocmd.vim src/version.c
diffstat 3 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
 	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 *e
     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) == '#')
--- 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
 
--- 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,