mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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)
This commit is contained in:
33
src/eval.c
33
src/eval.c
@@ -2135,6 +2135,35 @@ eval_func(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
* Get the next line source line without advancing. But do skip over comment
|
||||||
* lines.
|
* lines.
|
||||||
@@ -2184,7 +2213,7 @@ eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
|
|||||||
char_u *next;
|
char_u *next;
|
||||||
|
|
||||||
if (*p == NL)
|
if (*p == NL)
|
||||||
next = p + 1;
|
next = newline_skip_comments(p);
|
||||||
else if (evalarg->eval_cookie != NULL)
|
else if (evalarg->eval_cookie != NULL)
|
||||||
next = getline_peek_skip_comments(evalarg);
|
next = getline_peek_skip_comments(evalarg);
|
||||||
else
|
else
|
||||||
@@ -2212,7 +2241,7 @@ eval_next_line(char_u *arg, evalarg_T *evalarg)
|
|||||||
if (arg != NULL)
|
if (arg != NULL)
|
||||||
{
|
{
|
||||||
if (*arg == NL)
|
if (*arg == NL)
|
||||||
return skipwhite(arg + 1);
|
return newline_skip_comments(arg);
|
||||||
// Truncate before a trailing comment, so that concatenating the lines
|
// Truncate before a trailing comment, so that concatenating the lines
|
||||||
// won't turn the rest into a comment.
|
// won't turn the rest into a comment.
|
||||||
if (*skipwhite(arg) == '#')
|
if (*skipwhite(arg) == '#')
|
||||||
|
@@ -3100,6 +3100,22 @@ func Test_autocmd_with_block()
|
|||||||
call assert_equal(77, g:gotSafeState)
|
call assert_equal(77, g:gotSafeState)
|
||||||
unlet g:gotSafeState
|
unlet g:gotSafeState
|
||||||
|
|
||||||
|
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
|
augroup block_testing
|
||||||
au!
|
au!
|
||||||
augroup END
|
augroup END
|
||||||
|
@@ -734,6 +734,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
5053,
|
||||||
/**/
|
/**/
|
||||||
5052,
|
5052,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user