mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 15:28:17 +00:00
vim-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)
0fce425772
This commit is contained in:
@@ -15209,6 +15209,7 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv)
|
|||||||
list_T *l;
|
list_T *l;
|
||||||
listitem_T *li;
|
listitem_T *li;
|
||||||
dict_T *d;
|
dict_T *d;
|
||||||
|
list_T *s = NULL;
|
||||||
|
|
||||||
rettv->vval.v_number = -1;
|
rettv->vval.v_number = -1;
|
||||||
if (argvars[0].v_type != VAR_LIST) {
|
if (argvars[0].v_type != VAR_LIST) {
|
||||||
@@ -15227,7 +15228,8 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(dict_find(d, (char_u *)"group", -1) != NULL
|
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 *)"priority", -1) != NULL
|
||||||
&& dict_find(d, (char_u *)"id", -1) != NULL)) {
|
&& dict_find(d, (char_u *)"id", -1) != NULL)) {
|
||||||
EMSG(_(e_invarg));
|
EMSG(_(e_invarg));
|
||||||
@@ -15239,11 +15241,47 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv)
|
|||||||
clear_matches(curwin);
|
clear_matches(curwin);
|
||||||
li = l->lv_first;
|
li = l->lv_first;
|
||||||
while (li != NULL) {
|
while (li != NULL) {
|
||||||
|
int i = 0;
|
||||||
|
char_u buf[4];
|
||||||
|
dictitem_T *di;
|
||||||
d = li->li_tv.vval.v_dict;
|
d = li->li_tv.vval.v_dict;
|
||||||
match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE),
|
|
||||||
get_dict_string(d, (char_u *)"pattern", FALSE),
|
if (dict_find(d, (char_u *)"pattern", -1) == NULL) {
|
||||||
(int)get_dict_number(d, (char_u *)"priority"),
|
if (s == NULL) {
|
||||||
(int)get_dict_number(d, (char_u *)"id"), 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;
|
li = li->li_next;
|
||||||
}
|
}
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
|
@@ -389,7 +389,7 @@ static int included_patches[] = {
|
|||||||
// 748,
|
// 748,
|
||||||
// 747,
|
// 747,
|
||||||
// 746,
|
// 746,
|
||||||
// 745,
|
745,
|
||||||
// 744 NA
|
// 744 NA
|
||||||
// 743,
|
// 743,
|
||||||
// 742,
|
// 742,
|
||||||
|
@@ -89,7 +89,11 @@ describe('063: Test for ":match", "matchadd()" and related functions', function(
|
|||||||
execute("call clearmatches()")
|
execute("call clearmatches()")
|
||||||
execute("call setmatches(ml)")
|
execute("call setmatches(ml)")
|
||||||
eq(ml, eval('getmatches()'))
|
eq(ml, eval('getmatches()'))
|
||||||
|
|
||||||
|
-- Check that "setmatches()" can correctly restore the matches from matchaddpos()
|
||||||
execute("call clearmatches()")
|
execute("call clearmatches()")
|
||||||
|
execute("call setmatches(ml)")
|
||||||
|
eq(ml, eval('getmatches()'))
|
||||||
|
|
||||||
-- Check that "setmatches()" will not add two matches with the same ID. The
|
-- Check that "setmatches()" will not add two matches with the same ID. The
|
||||||
-- expected behaviour (for now) is to add the first match but not the
|
-- expected behaviour (for now) is to add the first match but not the
|
||||||
|
Reference in New Issue
Block a user