]> granicus.if.org Git - vim/commitdiff
patch 7.4.891 v7.4.891
authorBram Moolenaar <Bram@vim.org>
Wed, 7 Oct 2015 09:41:49 +0000 (11:41 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 7 Oct 2015 09:41:49 +0000 (11:41 +0200)
Problem:    Indentation of array initializer is wrong.
Solution:   Avoid that calling find_start_rawstring() changes the position
            returned by find_start_comment(), add a test. (Hirohito Higashi)

src/misc1.c
src/testdir/test3.in
src/testdir/test3.ok
src/version.c

index 7eb3dce8b90f20a9e957c3ec0120169df220a657..60e814694f15e7c36cdac3fcc8df3ab43f7f6171 100644 (file)
@@ -5345,8 +5345,19 @@ find_start_comment(ind_maxcomment)           /* XXX */
     static pos_T *
 ind_find_start_CORS()      /* XXX */
 {
-    pos_T      *comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
-    pos_T      *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
+    static pos_T comment_pos_copy;
+    pos_T      *comment_pos;
+    pos_T      *rs_pos;
+
+    comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
+    if (comment_pos != NULL)
+    {
+       /* Need to make a copy of the static pos in findmatchlimit(),
+        * calling find_start_rawstring() may change it. */
+       comment_pos_copy = *comment_pos;
+       comment_pos = &comment_pos_copy;
+    }
+    rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
 
     /* If comment_pos is before rs_pos the raw string is inside the comment.
      * If rs_pos is before comment_pos the comment is inside the raw string. */
@@ -8334,7 +8345,8 @@ get_c_indent()
                if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
                                                        && terminated == ','))
                {
-                   if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')
+                   if (lookfor != LOOKFOR_ENUM_OR_INIT &&
+                           (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '['))
                        amount += ind_continuation;
                    /*
                     * if we're in the middle of a paren thing,
@@ -8576,7 +8588,10 @@ get_c_indent()
                             */
                            l = ml_get_curline();
                            amount = cur_amount;
-                           if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']')
+
+                           n = (int)STRLEN(l);
+                           if (terminated == ',' && (*skipwhite(l) == ']'
+                                       || (n >=2 && l[n - 2] == ']')))
                                break;
 
                            /*
index 4f5331e56c907f1e6bca744d60ea0994ecf10f59..4fc73a978a05ed98a8e4bdb384ef9f16114a8ead 100644 (file)
@@ -910,6 +910,28 @@ const char* s = R"foo(
     )foo";
      }
 
+{
+int a[4] = {
+[0] = 0,
+[1] = 1,
+[2] = 2,
+[3] = 3,
+};
+}
+
+{
+a = b[2]
++ 3;
+}
+
+{
+if (1)
+/* aaaaa
+* bbbbb
+*/
+a = 1;
+}
+
 /* end of AUTO */
 
 STARTTEST
index e87e7fdcab277b36a207fe005e306acf31cd25a3..8fa9caac2113256d911677cdac000b27c44f12b6 100644 (file)
@@ -898,6 +898,28 @@ void getstring() {
     )foo";
 }
 
+{
+       int a[4] = {
+               [0] = 0,
+               [1] = 1,
+               [2] = 2,
+               [3] = 3,
+       };
+}
+
+{
+       a = b[2]
+               + 3;
+}
+
+{
+       if (1)
+               /* aaaaa
+                * bbbbb
+                */
+               a = 1;
+}
+
 /* end of AUTO */
 
 
index c60bbe6b75e4fa51ef47bec8ee52acba6444209a..ce0579288b24a9065b315d97f2df6403af6ed781 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    891,
 /**/
     890,
 /**/