diff options
author | Bram Moolenaar <Bram@vim.org> | 2015-06-19 16:32:57 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2015-06-19 16:32:57 +0200 |
commit | 0fce4257727f9d75e488963b73e407d31dd46546 (patch) | |
tree | fd2623ba375b9454c80b9eee155506e3213aef87 /src/eval.c | |
parent | cf0213ef7e88d38c34ef71459d413cf5813e2a95 (diff) |
patch 7.4.745v7.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)
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c index 6f8aa3c8e0..665536c737 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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; |