From 9dd86dff9b48928bfca1b37a60eaa98da77bfde3 Mon Sep 17 00:00:00 2001 From: Hirohito Higashi Date: Tue, 9 Jun 2026 19:35:02 +0000 Subject: [PATCH] patch 9.2.0610: cindent: closing brace in a comment affects the next line's indent 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) Signed-off-by: Hirohito Higashi Signed-off-by: Christian Brabandt --- src/cindent.c | 2 ++ src/testdir/test_cindent.vim | 31 +++++++++++++++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 35 insertions(+) diff --git a/src/cindent.c b/src/cindent.c index 94c01db7e8..fa8059509e 100644 --- a/src/cindent.c +++ b/src/cindent.c @@ -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; diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim index f050d82f8c..90dff6049e 100644 --- a/src/testdir/test_cindent.vim +++ b/src/testdir/test_cindent.vim @@ -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 diff --git a/src/version.c b/src/version.c index 6f4499c39a..3b135e4b00 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 610, /**/ 609, /**/