patch 9.1.2016: cindent wrong indentation after do-while loop
Commit:
https://github.com/vim/vim/commit/9d661b057e9f8e4d900b258fa4ed6a265751b7b7
Author: Anttoni Erkkilä <
anttoni...@protonmail.com>
Date: Tue Dec 23 20:42:57 2025 +0000
patch 9.1.2016: cindent wrong indentation after do-while loop
Problem: At "if(0) do if(0); while(0); else", else should be aligned
with outer if, but is aligned with inner if.
Solution: In function find_match, ignore "if" and "else" inside a
do-while loop, when looking for "if". (Anttoni Erkkilä)
closes: #19004
Signed-off-by: Anttoni Erkkilä <
anttoni...@protonmail.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/src/cindent.c b/src/cindent.c
index e23f96d45..12d7e694d 100644
--- a/src/cindent.c
+++ b/src/cindent.c
@@ -2076,16 +2076,30 @@ find_match(int lookfor, linenr_T ourscope)
if (theirscope->lnum > ourscope)
continue;
- // if it was an "else" (that's not an "else if")
- // then we need to go back to another if, so
- // increment elselevel
look = cin_skipcomment(ml_get_curline());
- if (cin_iselse(look))
+ // When looking for if, we ignore "if" and "else" in a deeper do-while loop.
+ if (!(lookfor == LOOKFOR_IF && whilelevel))
{
- mightbeif = cin_skipcomment(look + 4);
- if (!cin_isif(mightbeif))
- ++elselevel;
- continue;
+ // if it was an "else" (that's not an "else if")
+ // then we need to go back to another if, so
+ // increment elselevel
+ if (cin_iselse(look))
+ {
+ mightbeif = cin_skipcomment(look + 4);
+ if (!cin_isif(mightbeif))
+ ++elselevel;
+ continue;
+ }
+
+ // If it's an "if" decrement elselevel
+ if (cin_isif(look))
+ {
+ elselevel--;
+ // When looking for an "if" ignore "while"s that
+ // get in the way.
+ if (elselevel == 0 && lookfor == LOOKFOR_IF)
+ whilelevel = 0;
+ }
}
// if it was a "while" then we need to go back to
@@ -2096,17 +2110,6 @@ find_match(int lookfor, linenr_T ourscope)
continue;
}
- // If it's an "if" decrement elselevel
- look = cin_skipcomment(ml_get_curline());
- if (cin_isif(look))
- {
- elselevel--;
- // When looking for an "if" ignore "while"s that
- // get in the way.
- if (elselevel == 0 && lookfor == LOOKFOR_IF)
- whilelevel = 0;
- }
-
// If it's a "do" decrement whilelevel
if (cin_isdo(look))
whilelevel--;
diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim
index 589fcdd61..4b6fcb870 100644
--- a/src/testdir/test_cindent.vim
+++ b/src/testdir/test_cindent.vim
@@ -1111,6 +1111,27 @@ def Test_cindent_1()
b;
}
+ void func() {
+ if (0)
+ do
+ if (0);
+ while (0);
+ else;
+ }
+
+ void func() {
+ if (0)
+ do
+ if (0)
+ do
+ if (0)
+ a();
+ while (0);
+ while (0);
+ else
+ a();
+ }
+
/* end of AUTO */
[CODE]
@@ -2093,6 +2114,27 @@ def Test_cindent_1()
b;
}
+ void func() {
+ if (0)
+ do
+ if (0);
+ while (0);
+ else;
+ }
+
+ void func() {
+ if (0)
+ do
+ if (0)
+ do
+ if (0)
+ a();
+ while (0);
+ while (0);
+ else
+ a();
+ }
+
/* end of AUTO */
[CODE]
diff --git a/src/version.c b/src/version.c
index 75714149c..fdc6ed8f5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2016,
/**/
2015,
/**/