mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.1838: Vim9: cannot insert a comment line in an expression
Problem: Vim9: cannot insert a comment line in an expression. Solution: Skip comment lines at the script level. (closes #7111)
This commit is contained in:
25
src/eval.c
25
src/eval.c
@@ -1967,6 +1967,29 @@ eval_func(
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the next line source line without advancing. But do skip over comment
|
||||
* lines.
|
||||
*/
|
||||
static char_u *
|
||||
getline_peek_skip_comments(evalarg_T *evalarg)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
char_u *next = getline_peek(evalarg->eval_getline,
|
||||
evalarg->eval_cookie);
|
||||
char_u *p;
|
||||
|
||||
if (next == NULL)
|
||||
break;
|
||||
p = skipwhite(next);
|
||||
if (*p != NUL && !vim9_comment_start(p))
|
||||
return next;
|
||||
(void)eval_next_line(evalarg);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If inside Vim9 script, "arg" points to the end of a line (ignoring a #
|
||||
* comment) and there is a next line, return the next line (skipping blanks)
|
||||
@@ -1988,7 +2011,7 @@ eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
|
||||
char_u *next;
|
||||
|
||||
if (evalarg->eval_cookie != NULL)
|
||||
next = getline_peek(evalarg->eval_getline, evalarg->eval_cookie);
|
||||
next = getline_peek_skip_comments(evalarg);
|
||||
else
|
||||
next = peek_next_line_from_context(evalarg->eval_cctx);
|
||||
|
||||
|
@@ -90,6 +90,16 @@ def Test_expr1_trinary_vimscript()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = v:false ? # comment
|
||||
'yes' :
|
||||
# comment
|
||||
'no' # comment
|
||||
assert_equal('no', name)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
# check white space
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
@@ -279,6 +289,17 @@ def Test_expr2_vimscript()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = v:false || # comment
|
||||
# comment
|
||||
v:true ||
|
||||
# comment
|
||||
v:false # comment
|
||||
assert_equal(v:true, name)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
# check white space
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
@@ -405,6 +426,17 @@ def Test_expr3_vimscript()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = v:true && # comment
|
||||
# comment
|
||||
v:true &&
|
||||
# comment
|
||||
v:true
|
||||
assert_equal(v:true, name)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
# check white space
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
@@ -800,6 +832,7 @@ def Test_expr4_vim9script()
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = 123
|
||||
# comment
|
||||
!= 123
|
||||
assert_equal(false, name)
|
||||
END
|
||||
@@ -822,6 +855,16 @@ def Test_expr4_vim9script()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var list = [1, 2, 3]
|
||||
var name = list # comment
|
||||
# comment
|
||||
is list
|
||||
assert_equal(true, name)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var myblob = 0z1234
|
||||
@@ -1057,6 +1100,16 @@ def Test_expr5_vim9script()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = 11 + # comment
|
||||
77 -
|
||||
# comment
|
||||
22
|
||||
assert_equal(66, name)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = 'one'
|
||||
@@ -1303,6 +1356,17 @@ def Test_expr6_vim9script()
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = 25
|
||||
# comment
|
||||
|
||||
# comment
|
||||
% 10
|
||||
assert_equal(5, name)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
var name = 11 *
|
||||
@@ -1618,6 +1682,12 @@ def Test_expr7_list_vim9script()
|
||||
echo [1,
|
||||
2] [3,
|
||||
4]
|
||||
|
||||
echo [1, # comment
|
||||
# comment
|
||||
2] [3,
|
||||
# comment
|
||||
4]
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
@@ -1832,6 +1902,17 @@ def Test_expr7_dict_vim9script()
|
||||
'two': 2,
|
||||
}
|
||||
assert_equal({'one': 1, 'two': 2}, d)
|
||||
|
||||
d = { # comment
|
||||
'one':
|
||||
# comment
|
||||
|
||||
1,
|
||||
# comment
|
||||
# comment
|
||||
'two': 2,
|
||||
}
|
||||
assert_equal({'one': 1, 'two': 2}, d)
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1838,
|
||||
/**/
|
||||
1837,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user