]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0610: cindent: closing brace in a comment affects the next line's indent v9.2.0610
authorHirohito Higashi <h.east.727@gmail.com>
Tue, 9 Jun 2026 19:35:02 +0000 (19:35 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 9 Jun 2026 19:35:02 +0000 (19:35 +0000)
Problem:  A '}' inside a // line comment changes the indentation of the
          following line inside an enum or struct (rendcrx).
Solution: Stop scanning the line once a line comment is reached, so a brace
          inside the comment is no longer mistaken for an unmatched brace.

fixes:  #20455
closes: #20458

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/cindent.c
src/testdir/test_cindent.vim
src/version.c

index 94c01db7e80dbc30f505ba9beb88ec4bc30d2fbf..fa8059509ea2bc0d0a57ef7da7be9f2f1339f2d7 100644 (file)
@@ -1217,6 +1217,8 @@ find_last_paren(char_u *l, int start, int end)
     for (i = 0; l[i] != NUL; i++)
     {
        i = (int)(cin_skipcomment(l + i) - l); // ignore parens in comments
+       if (l[i] == NUL)
+           break;
        i = (int)(skip_string(l + i) - l);    // ignore parens in quotes
        if (l[i] == start)
            ++open_count;
index f050d82f8c8b94f24906c8870ec1a28947b6731b..90dff6049e38a13808a83dbb9ba9c3db53a310f5 100644 (file)
@@ -5604,6 +5604,37 @@ def Test_cindent_comment_brackets()
   assert_equal('    arg3);', getline(3))
   bwipe!
 
+  # stray } in a // line comment inside an aggregate (enum/struct) whose
+  # opening brace is at the end of the line must not affect the next member
+  new
+  setl cindent sw=4
+  var code6 =<< trim [CODE]
+  typedef enum {
+      ND_BLOCK,  // { ... }
+      ND_FUNCALL,
+  } NodeKind;
+  [CODE]
+  setline(1, code6)
+  cursor(3, 1)
+  normal ==
+  assert_equal('    ND_FUNCALL,', getline(3))
+  bwipe!
+
+  # same, a struct member with a trailing // } comment
+  new
+  setl cindent sw=4
+  var code7 =<< trim [CODE]
+  struct S {
+      int a;  // }
+      int b;
+  };
+  [CODE]
+  setline(1, code7)
+  cursor(3, 1)
+  normal ==
+  assert_equal('    int b;', getline(3))
+  bwipe!
+
 enddef
 
 
index 6f4499c39adf53c64ae1654241ca0ce0d748a4d7..3b135e4b00adbf2c06db12ba1cb934d808edb190 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    610,
 /**/
     609,
 /**/