]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1877: cindent: wrong indentation after an array declaration v9.1.1877
authorAnttoni Erkkilä <anttoni.erkkila@protonmail.com>
Sun, 26 Oct 2025 19:46:38 +0000 (19:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 26 Oct 2025 19:46:38 +0000 (19:46 +0000)
Problem:  cindent: wrong indentation after an array declaration
Solution: check if the filetype if javascript before matching the syntax
          (Anttoni Erkkilä)

cindent matches a javascript syntax for C files causing wrong
indentation in the following case:
```
void foo() {
float a[5],
b;
}
```

closes: #18631

Signed-off-by: Anttoni Erkkilä <anttoni.erkkila@protonmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/cindent.c
src/testdir/test_cindent.vim
src/version.c

index f2f2ac0c10fac2bf667cf69ed3413170ab21bb65..e23f96d453cf2956b18ac42d1e40888f9b506a35 100644 (file)
@@ -3476,7 +3476,7 @@ get_c_indent(void)
                            amount = cur_amount;
 
                            n = (int)STRLEN(l);
-                           if (terminated == ',' && (*skipwhite(l) == ']'
+                           if (curbuf->b_ind_js && terminated == ',' && (*skipwhite(l) == ']'
                                        || (n >=2 && l[n - 2] == ']')))
                                break;
 
index d27adbc4b51dc4e7da1ed5c347e3ae02c697ba13..589fcdd61f640d4dadefa9640a566d497ecd85f3 100644 (file)
@@ -1106,6 +1106,11 @@ def Test_cindent_1()
   }
   }
 
+  void foo() {
+  float a[5],
+  b;
+  }
+
   /* end of AUTO */
   [CODE]
 
@@ -2083,6 +2088,11 @@ def Test_cindent_1()
        }
   }
 
+  void foo() {
+       float a[5],
+                 b;
+  }
+
   /* end of AUTO */
 
   [CODE]
index 0ce44e9d46bbb353a6cee11b232a3db8509c5689..13aa6ec436a73106007cf791230a6d2ebda8492b 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1877,
 /**/
     1876,
 /**/