patch 9.1.1770: Vim9: wrong behaviour with trailing comments in command blocks
Problem: Vim9: wrong behaviour with trailing comments in command blocks (balki) Solution: Correctly skip over trailing comments (Yegappan Lakshmanan). fixes: #18268 closes: #18327 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
6fd9dac992
commit
6bea124137
@ -5353,6 +5353,7 @@ repl_cmdline(
|
||||
void
|
||||
separate_nextcmd(exarg_T *eap, int keep_backslash)
|
||||
{
|
||||
int vim9script = in_vim9script();
|
||||
char_u *p;
|
||||
|
||||
#ifdef FEAT_QUICKFIX
|
||||
@ -5389,14 +5390,14 @@ separate_nextcmd(exarg_T *eap, int keep_backslash)
|
||||
// :@" and :*" do not start a comment!
|
||||
// :redir @" doesn't either.
|
||||
else if ((*p == '"'
|
||||
&& !in_vim9script()
|
||||
&& !vim9script
|
||||
&& !(eap->argt & EX_NOTRLCOM)
|
||||
&& ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star)
|
||||
|| p != eap->arg)
|
||||
&& (eap->cmdidx != CMD_redir
|
||||
|| p != eap->arg + 1 || p[-1] != '@'))
|
||||
|| (*p == '#'
|
||||
&& in_vim9script()
|
||||
&& vim9script
|
||||
&& !(eap->argt & EX_NOTRLCOM)
|
||||
&& p > eap->cmd && VIM_ISWHITE(p[-1]))
|
||||
|| (*p == '|'
|
||||
@ -5420,7 +5421,7 @@ separate_nextcmd(exarg_T *eap, int keep_backslash)
|
||||
}
|
||||
else
|
||||
{
|
||||
eap->nextcmd = check_nextcmd(p);
|
||||
set_nextcmd(eap, p);
|
||||
*p = NUL;
|
||||
break;
|
||||
}
|
||||
@ -5932,7 +5933,16 @@ check_nextcmd(char_u *p)
|
||||
void
|
||||
set_nextcmd(exarg_T *eap, char_u *arg)
|
||||
{
|
||||
char_u *p = check_nextcmd(arg);
|
||||
char_u *p = skipwhite(arg);
|
||||
|
||||
if (in_vim9script() && *p == '#')
|
||||
{
|
||||
char_u *nl = vim_strchr(p, NL);
|
||||
if (nl != NULL)
|
||||
p = nl;
|
||||
}
|
||||
|
||||
p = check_nextcmd(p);
|
||||
|
||||
if (eap->nextcmd == NULL)
|
||||
eap->nextcmd = p;
|
||||
|
@ -613,6 +613,52 @@ def Test_block_in_a_string()
|
||||
v9.CheckSourceSuccess(lines)
|
||||
enddef
|
||||
|
||||
" Test for a block in a command with comments
|
||||
def Test_block_command_with_comment()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
|
||||
g:Str = ''
|
||||
command Cmd1 {
|
||||
g:Str = 'Hello' # comment1
|
||||
var x: string # comment2
|
||||
g:Str ..= ' World' # comment3
|
||||
}
|
||||
Cmd1
|
||||
assert_equal('Hello World', g:Str)
|
||||
|
||||
g:Str = ''
|
||||
command Cmd2 {
|
||||
# comment1
|
||||
g:Str = 'Hello'
|
||||
# comment2
|
||||
g:Str ..= ' World'
|
||||
# comment3
|
||||
}
|
||||
Cmd2
|
||||
assert_equal('Hello World', g:Str)
|
||||
|
||||
command Cmd3 {
|
||||
new # comment1
|
||||
setline(1, 'hello') # comment2
|
||||
}
|
||||
Cmd3
|
||||
assert_equal(['hello'], getline(1, '$'))
|
||||
:bw!
|
||||
|
||||
command Cmd4 {
|
||||
# comment1
|
||||
new
|
||||
# comment2
|
||||
setline(1, 'hello') # comment2
|
||||
}
|
||||
Cmd4
|
||||
assert_equal(['hello'], getline(1, '$'))
|
||||
:bw!
|
||||
END
|
||||
v9.CheckSourceSuccess(lines)
|
||||
enddef
|
||||
|
||||
" Test for using too many nested blocks
|
||||
def Test_too_many_nested_blocks()
|
||||
var lines = ['vim9script']
|
||||
|
@ -724,6 +724,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1770,
|
||||
/**/
|
||||
1769,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user