Commit: patch 9.1.1770: Vim9: wrong behaviour with trailing comments in command blocks

3 views
Skip to first unread message

Christian Brabandt

unread,
Sep 18, 2025, 3:45:18 PMSep 18
to vim...@googlegroups.com
patch 9.1.1770: Vim9: wrong behaviour with trailing comments in command blocks

Commit: https://github.com/vim/vim/commit/6bea1241378a1cbdd50ce2a91c96469fea470510
Author: Yegappan Lakshmanan <yega...@yahoo.com>
Date: Thu Sep 18 19:40:22 2025 +0000

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 <yega...@yahoo.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 9d7e58ed9..ea524486f 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -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;
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 8726ee483..823a6cf25 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -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']
diff --git a/src/version.c b/src/version.c
index 7f307167c..bd78cbf1d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -724,6 +724,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1770,
/**/
1769,
/**/
Reply all
Reply to author
Forward
0 new messages