]> granicus.if.org Git - vim/commitdiff
patch 7.4.745 v7.4.745
authorBram Moolenaar <Bram@vim.org>
Fri, 19 Jun 2015 14:32:57 +0000 (16:32 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 19 Jun 2015 14:32:57 +0000 (16:32 +0200)
Problem:    The entries added by matchaddpos() are returned by getmatches()
            but can't be set with setmatches(). (Lcd)
Solution:   Fix setmatches(). (Christian Brabandt)

src/eval.c
src/testdir/test63.in
src/testdir/test63.ok
src/version.c

index 6f8aa3c8e04ad7dc7b89a5d381de027439944875..665536c737d254522d869cf10799ffc44b5b52ed 100644 (file)
@@ -17118,6 +17118,7 @@ f_setmatches(argvars, rettv)
     list_T     *l;
     listitem_T *li;
     dict_T     *d;
+    list_T     *s = NULL;
 
     rettv->vval.v_number = -1;
     if (argvars[0].v_type != VAR_LIST)
@@ -17140,7 +17141,8 @@ f_setmatches(argvars, rettv)
                return;
            }
            if (!(dict_find(d, (char_u *)"group", -1) != NULL
-                       && dict_find(d, (char_u *)"pattern", -1) != NULL
+                       && (dict_find(d, (char_u *)"pattern", -1) != NULL
+                           || dict_find(d, (char_u *)"pos1", -1) != NULL)
                        && dict_find(d, (char_u *)"priority", -1) != NULL
                        && dict_find(d, (char_u *)"id", -1) != NULL))
            {
@@ -17154,11 +17156,53 @@ f_setmatches(argvars, rettv)
        li = l->lv_first;
        while (li != NULL)
        {
+           int         i = 0;
+           char_u      buf[4];
+           dictitem_T  *di;
+
            d = li->li_tv.vval.v_dict;
-           match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
+
+           if (dict_find(d, (char_u *)"pattern", -1) == NULL)
+           {
+               if (s == NULL)
+               {
+                   s = list_alloc();
+                   if (s == NULL)
+                       return;
+               }
+
+               /* match from matchaddpos() */
+               for (i = 1; i < 9; i++)
+               {
+                   sprintf((char *)buf, (char *)"pos%d", i);
+                   if ((di = dict_find(d, (char_u *)buf, -1)) != NULL)
+                   {
+                       if (di->di_tv.v_type != VAR_LIST)
+                           return;
+
+                       list_append_tv(s, &di->di_tv);
+                       s->lv_refcount++;
+                   }
+                   else
+                       break;
+               }
+           }
+           if (i == 0)
+           {
+               match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
                    get_dict_string(d, (char_u *)"pattern", FALSE),
                    (int)get_dict_number(d, (char_u *)"priority"),
                    (int)get_dict_number(d, (char_u *)"id"), NULL);
+           }
+           else
+           {
+               match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
+                   NULL, (int)get_dict_number(d, (char_u *)"priority"),
+                   (int)get_dict_number(d, (char_u *)"id"), s);
+               list_unref(s);
+               s = NULL;
+           }
+
            li = li->li_next;
        }
        rettv->vval.v_number = 0;
index 1f073a78a61865e4b9e75203aee39a964258b077..03b2197aaf22ea464faaed1d77d896cbaad108aa 100644 (file)
@@ -187,7 +187,12 @@ STARTTEST
 :else
 :  let @r .= "FAILED: " . v4 . "/" . v5 . "/" . v6 . "/" . v7 . "/" . v8 . "/" . v9 . "/" . v10 . "\n"
 :endif
+:" Check, that setmatches() can correctly restore the matches from matchaddpos()
+:call matchadd('MyGroup1', '\%2lmatchadd')
+:let m=getmatches()
 :call clearmatches()
+:call setmatches(m)
+:let @r .= string(getmatches())."\n"
 G"rp
 :/^Results/,$wq! test.out
 ENDTEST
index 5d619395b7852709cfbb98f37a516878ad057c88..7016daf6bdf2f8f49afbf9288d96acce962bb9fb 100644 (file)
@@ -14,3 +14,4 @@ Results of test63:
 OK
 [{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}]
 OK
+[{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 12}]
index 75a5810e4a482ac208ba9f7f99c51eebec66d0cd..b5e88554623ed5be3e7af7974b8c7d909c17dbc5 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    745,
 /**/
     744,
 /**/