]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
updated for version 7.4.670 v7.4.670
authorBram Moolenaar <Bram@vim.org>
Fri, 20 Mar 2015 18:06:06 +0000 (19:06 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 20 Mar 2015 18:06:06 +0000 (19:06 +0100)
Problem:    Using 'cindent' for Javascript is less than perfect.
Solution:   Improve indenting of continuation lines. (Hirohito Higashi)

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

index ac87ef8fc488bbc07e64a4dff60bc49919880d6d..940a3e917e6d64686cd514da4c68ba5e770c435b 100644 (file)
@@ -6670,20 +6670,43 @@ find_match_char(c, ind_maxparen)            /* XXX */
     pos_T      cursor_save;
     pos_T      *trypos;
     static pos_T pos_copy;
+    int                ind_maxp_wk;
 
     cursor_save = curwin->w_cursor;
-    if ((trypos = findmatchlimit(NULL, c, 0, ind_maxparen)) != NULL)
+    ind_maxp_wk = ind_maxparen;
+retry:
+    if ((trypos = findmatchlimit(NULL, c, 0, ind_maxp_wk)) != NULL)
     {
        /* check if the ( is in a // comment */
        if ((colnr_T)cin_skip2pos(trypos) > trypos->col)
+       {
+           ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum - trypos->lnum);
+           if (ind_maxp_wk > 0)
+           {
+               curwin->w_cursor = *trypos;
+               curwin->w_cursor.col = 0;       /* XXX */
+               goto retry;
+           }
            trypos = NULL;
+       }
        else
        {
+           pos_T       *trypos_wk;
+
            pos_copy = *trypos;     /* copy trypos, findmatch will change it */
            trypos = &pos_copy;
            curwin->w_cursor = *trypos;
-           if (ind_find_start_comment() != NULL) /* XXX */
+           if ((trypos_wk = ind_find_start_comment()) != NULL) /* XXX */
+           {
+               ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum
+                       - trypos_wk->lnum);
+               if (ind_maxp_wk > 0)
+               {
+                   curwin->w_cursor = *trypos_wk;
+                   goto retry;
+               }
                trypos = NULL;
+           }
        }
     }
     curwin->w_cursor = cursor_save;
@@ -7024,7 +7047,7 @@ get_c_indent()
 #define LOOKFOR_CPP_BASECLASS  9
 #define LOOKFOR_ENUM_OR_INIT   10
 #define LOOKFOR_JS_KEY         11
-#define LOOKFOR_NO_COMMA       12
+#define LOOKFOR_COMMA  12
 
     int                whilelevel;
     linenr_T   lnum;
@@ -7842,7 +7865,8 @@ get_c_indent()
                    else
                    {
                        if (lookfor != LOOKFOR_TERM
-                                         && lookfor != LOOKFOR_CPP_BASECLASS)
+                                       && lookfor != LOOKFOR_CPP_BASECLASS
+                                       && lookfor != LOOKFOR_COMMA)
                        {
                            amount = scope_amount;
                            if (theline[0] == '{')
@@ -8134,23 +8158,31 @@ get_c_indent()
                    amount = get_indent();
                    break;
                }
-               if (lookfor == LOOKFOR_NO_COMMA)
+               if (lookfor == LOOKFOR_COMMA)
                {
-                   if (terminated != ',')
+                   if (tryposBrace != NULL && tryposBrace->lnum
+                                                   >= curwin->w_cursor.lnum)
+                       break;
+                   if (terminated == ',')
                        /* line below current line is the one that starts a
                         * (possibly broken) line ending in a comma. */
                        break;
-                   amount = get_indent();
-                   if (curwin->w_cursor.lnum - 1 == ourscope)
-                       /* line above is start of the scope, thus current line
-                        * is the one that stars a (possibly broken) line
-                        * ending in a comma. */
-                       break;
+                   else
+                   {
+                       amount = get_indent();
+                       if (curwin->w_cursor.lnum - 1 == ourscope)
+                           /* line above is start of the scope, thus current
+                            * line is the one that stars a (possibly broken)
+                            * line ending in a comma. */
+                           break;
+                   }
                }
 
                if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
                                                        && terminated == ','))
                {
+                   if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')
+                       amount += ind_continuation;
                    /*
                     * if we're in the middle of a paren thing,
                     * go back to the line that starts it so
@@ -8389,7 +8421,10 @@ get_c_indent()
                             *      100 +
                             * ->           here;
                             */
+                           l = ml_get_curline();
                            amount = cur_amount;
+                           if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']')
+                               break;
 
                            /*
                             * If previous line ends in ',', check whether we
@@ -8418,8 +8453,9 @@ get_c_indent()
                                     *        5,
                                     *     6,
                                     */
-                                   lookfor = LOOKFOR_NO_COMMA;
-                                   amount = get_indent();          /* XXX */
+                                   if (cin_iscomment(skipwhite(l)))
+                                       break;
+                                   lookfor = LOOKFOR_COMMA;
                                    trypos = find_match_char('[',
                                                      curbuf->b_ind_maxparen);
                                    if (trypos != NULL)
@@ -8449,7 +8485,8 @@ get_c_indent()
                                    cont_amount = cin_get_equal_amount(
                                                       curwin->w_cursor.lnum);
                                if (lookfor != LOOKFOR_TERM
-                                                && lookfor != LOOKFOR_JS_KEY)
+                                               && lookfor != LOOKFOR_JS_KEY
+                                               && lookfor != LOOKFOR_COMMA)
                                    lookfor = LOOKFOR_UNTERM;
                            }
                        }
index 7757569e37247576b66d7c8f81a6149ca503aa4b..a321bb885eae13a669e4d120a29175ac3ffe4a5d 100644 (file)
@@ -2064,6 +2064,164 @@ return true;
 })(jQuery);
 JSEND
 
+STARTTEST
+:set cino=j1,J1,+2
+/^JSSTART
+=/^JSEND
+ENDTEST
+
+JSSTART
+// Results of JavaScript indent
+// 1
+(function(){
+var a = [
+'a',
+'b',
+'c',
+'d',
+'e',
+'f',
+'g',
+'h',
+'i'
+];
+}())
+
+// 2
+(function(){
+var a = [
+0 +
+5 *
+9 *
+'a',
+'b',
+0 +
+5 *
+9 *
+'c',
+'d',
+'e',
+'f',
+'g',
+'h',
+'i'
+];
+}())
+
+// 3
+(function(){
+var a = [
+0 +
+// comment 1
+5 *
+/* comment 2 */
+9 *
+'a',
+'b',
+0 +
+5 *
+9 *
+'c',
+'d',
+'e',
+'f',
+'g',
+'h',
+'i'
+];
+}())
+
+// 4
+{
+var a = [
+0,
+1
+];
+var b;
+var c;
+}
+
+// 5
+{
+var a = [
+[
+0
+],
+2,
+3
+];
+}
+
+// 6
+{
+var a = [
+[
+0,
+1
+],
+2,
+3
+];
+}
+
+// 7
+{
+var a = [
+// [
+0,
+// 1
+// ],
+2,
+3
+];
+}
+
+// 8
+var x = [
+(function(){
+var a,
+b,
+c,
+d,
+e,
+f,
+g,
+h,
+i;
+})
+];
+
+// 9
+var a = [
+0 +
+5 *
+9 *
+'a',
+'b',
+0 +
+5 *
+9 *
+'c',
+'d',
+'e',
+'f',
+'g',
+'h',
+'i'
+];
+
+// 10
+var a,
+b,
+c,
+d,
+e,
+f,
+g,
+h,
+i;
+JSEND
+
 STARTTEST
 :g/^STARTTEST/.,/^ENDTEST/d
 :1;/start of AUTO/,$wq! test.out
index e75de0ffa336eaa241e89d65662b54a25c50e226..b1c8b7088fc6edc0e353a42d5401f67c038af341 100644 (file)
@@ -1832,3 +1832,156 @@ JSSTART
 })(jQuery);
 JSEND
 
+
+JSSTART
+// Results of JavaScript indent
+// 1
+(function(){
+       var a = [
+         'a',
+         'b',
+         'c',
+         'd',
+         'e',
+         'f',
+         'g',
+         'h',
+         'i'
+       ];
+}())
+
+// 2
+(function(){
+       var a = [
+         0 +
+               5 *
+               9 *
+               'a',
+         'b',
+         0 +
+               5 *
+               9 *
+               'c',
+         'd',
+         'e',
+         'f',
+         'g',
+         'h',
+         'i'
+       ];
+}())
+
+// 3
+(function(){
+       var a = [
+         0 +
+               // comment 1
+               5 *
+               /* comment 2 */
+               9 *
+               'a',
+         'b',
+         0 +
+               5 *
+               9 *
+               'c',
+         'd',
+         'e',
+         'f',
+         'g',
+         'h',
+         'i'
+       ];
+}())
+
+// 4
+{
+       var a = [
+         0,
+         1
+       ];
+       var b;
+       var c;
+}
+
+// 5
+{
+       var a = [
+         [
+               0
+         ],
+         2,
+         3
+       ];
+}
+
+// 6
+{
+       var a = [
+         [
+               0,
+               1
+         ],
+         2,
+         3
+       ];
+}
+
+// 7
+{
+       var a = [
+         // [
+         0,
+         // 1
+         // ],
+         2,
+         3
+       ];
+}
+
+// 8
+var x = [
+  (function(){
+         var a,
+         b,
+         c,
+         d,
+         e,
+         f,
+         g,
+         h,
+         i;
+  })
+];
+
+// 9
+var a = [
+  0 +
+  5 *
+  9 *
+  'a',
+  'b',
+  0 +
+  5 *
+  9 *
+  'c',
+  'd',
+  'e',
+  'f',
+  'g',
+  'h',
+  'i'
+];
+
+// 10
+var a,
+       b,
+       c,
+       d,
+       e,
+       f,
+       g,
+       h,
+       i;
+JSEND
+
index f7eae8501a0d9890a6c6ba5b96da7975ead72aae..af86a17299131cc7fdfc66fdbd0155d00a85b01f 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    670,
 /**/
     669,
 /**/