Skip to content

Commit 5fbd36a

Browse files
brammooldouglaskayama
authored andcommitted
patch 7.4.745 Problem: The entries added by matchaddpos() are returned by getmatches() but can't be set with setmatches(). (Lcd) Solution: Fix setmatches(). (Christian Brabandt)
1 parent 2d68b5c commit 5fbd36a

4 files changed

Lines changed: 54 additions & 2 deletions

File tree

src/eval.c

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17146,6 +17146,7 @@ f_setmatches(argvars, rettv)
1714617146
list_T *l;
1714717147
listitem_T *li;
1714817148
dict_T *d;
17149+
list_T *s = NULL;
1714917150

1715017151
rettv->vval.v_number = -1;
1715117152
if (argvars[0].v_type != VAR_LIST)
@@ -17168,7 +17169,8 @@ f_setmatches(argvars, rettv)
1716817169
return;
1716917170
}
1717017171
if (!(dict_find(d, (char_u *)"group", -1) != NULL
17171-
&& dict_find(d, (char_u *)"pattern", -1) != NULL
17172+
&& (dict_find(d, (char_u *)"pattern", -1) != NULL
17173+
|| dict_find(d, (char_u *)"pos1", -1) != NULL)
1717217174
&& dict_find(d, (char_u *)"priority", -1) != NULL
1717317175
&& dict_find(d, (char_u *)"id", -1) != NULL))
1717417176
{
@@ -17182,11 +17184,53 @@ f_setmatches(argvars, rettv)
1718217184
li = l->lv_first;
1718317185
while (li != NULL)
1718417186
{
17187+
int i = 0;
17188+
char_u buf[4];
17189+
dictitem_T *di;
17190+
1718517191
d = li->li_tv.vval.v_dict;
17186-
match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
17192+
17193+
if (dict_find(d, (char_u *)"pattern", -1) == NULL)
17194+
{
17195+
if (s == NULL)
17196+
{
17197+
s = list_alloc();
17198+
if (s == NULL)
17199+
return;
17200+
}
17201+
17202+
/* match from matchaddpos() */
17203+
for (i = 1; i < 9; i++)
17204+
{
17205+
sprintf((char *)buf, (char *)"pos%d", i);
17206+
if ((di = dict_find(d, (char_u *)buf, -1)) != NULL)
17207+
{
17208+
if (di->di_tv.v_type != VAR_LIST)
17209+
return;
17210+
17211+
list_append_tv(s, &di->di_tv);
17212+
s->lv_refcount++;
17213+
}
17214+
else
17215+
break;
17216+
}
17217+
}
17218+
if (i == 0)
17219+
{
17220+
match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
1718717221
get_dict_string(d, (char_u *)"pattern", FALSE),
1718817222
(int)get_dict_number(d, (char_u *)"priority"),
1718917223
(int)get_dict_number(d, (char_u *)"id"), NULL);
17224+
}
17225+
else
17226+
{
17227+
match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
17228+
NULL, (int)get_dict_number(d, (char_u *)"priority"),
17229+
(int)get_dict_number(d, (char_u *)"id"), s);
17230+
list_unref(s);
17231+
s = NULL;
17232+
}
17233+
1719017234
li = li->li_next;
1719117235
}
1719217236
rettv->vval.v_number = 0;

src/testdir/test63.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ STARTTEST
187187
:else
188188
: let @r .= "FAILED: " . v4 . "/" . v5 . "/" . v6 . "/" . v7 . "/" . v8 . "/" . v9 . "/" . v10 . "\n"
189189
:endif
190+
:" Check, that setmatches() can correctly restore the matches from matchaddpos()
191+
:call matchadd('MyGroup1', '\%2lmatchadd')
192+
:let m=getmatches()
190193
:call clearmatches()
194+
:call setmatches(m)
195+
:let @r .= string(getmatches())."\n"
191196
G"rp
192197
:/^Results/,$wq! test.out
193198
ENDTEST

src/testdir/test63.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Results of test63:
1414
OK
1515
[{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}]
1616
OK
17+
[{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 12}]

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ static char *(features[]) =
756756

757757
static int included_patches[] =
758758
{ /* Add new patch number below this line */
759+
/**/
760+
745,
759761
/**/
760762
744,
761763
/**/

0 commit comments

Comments
 (0)