comparison src/eval.c @ 6947:1efa7c2b9368 v7.4.792

patch 7.4.792 Problem: Can only conceal text by defining syntax items. Solution: Use matchadd() to define concealing. (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Tue, 21 Jul 2015 15:48:27 +0200
parents 4db70c94226b
children 814f1f569e4a
comparison
equal deleted inserted replaced
6946:c56ef0540cd5 6947:1efa7c2b9368
8222 #endif 8222 #endif
8223 {"map", 2, 2, f_map}, 8223 {"map", 2, 2, f_map},
8224 {"maparg", 1, 4, f_maparg}, 8224 {"maparg", 1, 4, f_maparg},
8225 {"mapcheck", 1, 3, f_mapcheck}, 8225 {"mapcheck", 1, 3, f_mapcheck},
8226 {"match", 2, 4, f_match}, 8226 {"match", 2, 4, f_match},
8227 {"matchadd", 2, 4, f_matchadd}, 8227 {"matchadd", 2, 5, f_matchadd},
8228 {"matchaddpos", 2, 4, f_matchaddpos}, 8228 {"matchaddpos", 2, 5, f_matchaddpos},
8229 {"matcharg", 1, 1, f_matcharg}, 8229 {"matcharg", 1, 1, f_matcharg},
8230 {"matchdelete", 1, 1, f_matchdelete}, 8230 {"matchdelete", 1, 1, f_matchdelete},
8231 {"matchend", 2, 4, f_matchend}, 8231 {"matchend", 2, 4, f_matchend},
8232 {"matchlist", 2, 4, f_matchlist}, 8232 {"matchlist", 2, 4, f_matchlist},
8233 {"matchstr", 2, 4, f_matchstr}, 8233 {"matchstr", 2, 4, f_matchstr},
12029 dict_add_nr_str(dict, "pattern", 0L, cur->pattern); 12029 dict_add_nr_str(dict, "pattern", 0L, cur->pattern);
12030 } 12030 }
12031 dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id)); 12031 dict_add_nr_str(dict, "group", 0L, syn_id2name(cur->hlg_id));
12032 dict_add_nr_str(dict, "priority", (long)cur->priority, NULL); 12032 dict_add_nr_str(dict, "priority", (long)cur->priority, NULL);
12033 dict_add_nr_str(dict, "id", (long)cur->id, NULL); 12033 dict_add_nr_str(dict, "id", (long)cur->id, NULL);
12034 # ifdef FEAT_CONCEAL
12035 if (cur->conceal_char)
12036 {
12037 char_u buf[MB_MAXBYTES + 1];
12038
12039 buf[(*mb_char2bytes)((int)cur->conceal_char, buf)] = NUL;
12040 dict_add_nr_str(dict, "conceal", 0L, (char_u *)&buf);
12041 }
12042 # endif
12034 list_append_dict(rettv->vval.v_list, dict); 12043 list_append_dict(rettv->vval.v_list, dict);
12035 cur = cur->next; 12044 cur = cur->next;
12036 } 12045 }
12037 } 12046 }
12038 #endif 12047 #endif
14587 char_u *grp = get_tv_string_buf_chk(&argvars[0], buf); /* group */ 14596 char_u *grp = get_tv_string_buf_chk(&argvars[0], buf); /* group */
14588 char_u *pat = get_tv_string_buf_chk(&argvars[1], buf); /* pattern */ 14597 char_u *pat = get_tv_string_buf_chk(&argvars[1], buf); /* pattern */
14589 int prio = 10; /* default priority */ 14598 int prio = 10; /* default priority */
14590 int id = -1; 14599 int id = -1;
14591 int error = FALSE; 14600 int error = FALSE;
14601 char_u *conceal_char = NULL;
14592 14602
14593 rettv->vval.v_number = -1; 14603 rettv->vval.v_number = -1;
14594 14604
14595 if (grp == NULL || pat == NULL) 14605 if (grp == NULL || pat == NULL)
14596 return; 14606 return;
14597 if (argvars[2].v_type != VAR_UNKNOWN) 14607 if (argvars[2].v_type != VAR_UNKNOWN)
14598 { 14608 {
14599 prio = get_tv_number_chk(&argvars[2], &error); 14609 prio = get_tv_number_chk(&argvars[2], &error);
14600 if (argvars[3].v_type != VAR_UNKNOWN) 14610 if (argvars[3].v_type != VAR_UNKNOWN)
14611 {
14601 id = get_tv_number_chk(&argvars[3], &error); 14612 id = get_tv_number_chk(&argvars[3], &error);
14613 if (argvars[4].v_type != VAR_UNKNOWN)
14614 {
14615 if (argvars[4].v_type != VAR_DICT)
14616 {
14617 EMSG(_(e_dictreq));
14618 return;
14619 }
14620 if (dict_find(argvars[4].vval.v_dict,
14621 (char_u *)"conceal", -1) != NULL)
14622 conceal_char = get_dict_string(argvars[4].vval.v_dict,
14623 (char_u *)"conceal", FALSE);
14624 }
14625 }
14602 } 14626 }
14603 if (error == TRUE) 14627 if (error == TRUE)
14604 return; 14628 return;
14605 if (id >= 1 && id <= 3) 14629 if (id >= 1 && id <= 3)
14606 { 14630 {
14607 EMSGN("E798: ID is reserved for \":match\": %ld", id); 14631 EMSGN("E798: ID is reserved for \":match\": %ld", id);
14608 return; 14632 return;
14609 } 14633 }
14610 14634
14611 rettv->vval.v_number = match_add(curwin, grp, pat, prio, id, NULL); 14635 rettv->vval.v_number = match_add(curwin, grp, pat, prio, id, NULL,
14636 conceal_char);
14612 #endif 14637 #endif
14613 } 14638 }
14614 14639
14615 /* 14640 /*
14616 * "matchaddpos()" function 14641 * "matchaddpos()" function
14625 char_u *group; 14650 char_u *group;
14626 int prio = 10; 14651 int prio = 10;
14627 int id = -1; 14652 int id = -1;
14628 int error = FALSE; 14653 int error = FALSE;
14629 list_T *l; 14654 list_T *l;
14655 char_u *conceal_char = NULL;
14630 14656
14631 rettv->vval.v_number = -1; 14657 rettv->vval.v_number = -1;
14632 14658
14633 group = get_tv_string_buf_chk(&argvars[0], buf); 14659 group = get_tv_string_buf_chk(&argvars[0], buf);
14634 if (group == NULL) 14660 if (group == NULL)
14645 14671
14646 if (argvars[2].v_type != VAR_UNKNOWN) 14672 if (argvars[2].v_type != VAR_UNKNOWN)
14647 { 14673 {
14648 prio = get_tv_number_chk(&argvars[2], &error); 14674 prio = get_tv_number_chk(&argvars[2], &error);
14649 if (argvars[3].v_type != VAR_UNKNOWN) 14675 if (argvars[3].v_type != VAR_UNKNOWN)
14676 {
14650 id = get_tv_number_chk(&argvars[3], &error); 14677 id = get_tv_number_chk(&argvars[3], &error);
14678 if (argvars[4].v_type != VAR_UNKNOWN)
14679 {
14680 if (argvars[4].v_type != VAR_DICT)
14681 {
14682 EMSG(_(e_dictreq));
14683 return;
14684 }
14685 if (dict_find(argvars[4].vval.v_dict,
14686 (char_u *)"conceal", -1) != NULL)
14687 conceal_char = get_dict_string(argvars[4].vval.v_dict,
14688 (char_u *)"conceal", FALSE);
14689 }
14690 }
14651 } 14691 }
14652 if (error == TRUE) 14692 if (error == TRUE)
14653 return; 14693 return;
14654 14694
14655 /* id == 3 is ok because matchaddpos() is supposed to substitute :3match */ 14695 /* id == 3 is ok because matchaddpos() is supposed to substitute :3match */
14657 { 14697 {
14658 EMSGN("E798: ID is reserved for \":match\": %ld", id); 14698 EMSGN("E798: ID is reserved for \":match\": %ld", id);
14659 return; 14699 return;
14660 } 14700 }
14661 14701
14662 rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l); 14702 rettv->vval.v_number = match_add(curwin, group, NULL, prio, id, l,
14703 conceal_char);
14663 #endif 14704 #endif
14664 } 14705 }
14665 14706
14666 /* 14707 /*
14667 * "matcharg()" function 14708 * "matcharg()" function
17163 while (li != NULL) 17204 while (li != NULL)
17164 { 17205 {
17165 int i = 0; 17206 int i = 0;
17166 char_u buf[5]; 17207 char_u buf[5];
17167 dictitem_T *di; 17208 dictitem_T *di;
17209 char_u *group;
17210 int priority;
17211 int id;
17212 char_u *conceal;
17168 17213
17169 d = li->li_tv.vval.v_dict; 17214 d = li->li_tv.vval.v_dict;
17170
17171 if (dict_find(d, (char_u *)"pattern", -1) == NULL) 17215 if (dict_find(d, (char_u *)"pattern", -1) == NULL)
17172 { 17216 {
17173 if (s == NULL) 17217 if (s == NULL)
17174 { 17218 {
17175 s = list_alloc(); 17219 s = list_alloc();
17191 } 17235 }
17192 else 17236 else
17193 break; 17237 break;
17194 } 17238 }
17195 } 17239 }
17240
17241 group = get_dict_string(d, (char_u *)"group", FALSE);
17242 priority = (int)get_dict_number(d, (char_u *)"priority");
17243 id = (int)get_dict_number(d, (char_u *)"id");
17244 conceal = dict_find(d, (char_u *)"conceal", -1) != NULL
17245 ? get_dict_string(d, (char_u *)"conceal", FALSE)
17246 : NULL;
17196 if (i == 0) 17247 if (i == 0)
17197 { 17248 {
17198 match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE), 17249 match_add(curwin, group,
17199 get_dict_string(d, (char_u *)"pattern", FALSE), 17250 get_dict_string(d, (char_u *)"pattern", FALSE),
17200 (int)get_dict_number(d, (char_u *)"priority"), 17251 priority, id, NULL, conceal);
17201 (int)get_dict_number(d, (char_u *)"id"), NULL);
17202 } 17252 }
17203 else 17253 else
17204 { 17254 {
17205 match_add(curwin, get_dict_string(d, (char_u *)"group", FALSE), 17255 match_add(curwin, group, NULL, priority, id, s, conceal);
17206 NULL, (int)get_dict_number(d, (char_u *)"priority"),
17207 (int)get_dict_number(d, (char_u *)"id"), s);
17208 list_unref(s); 17256 list_unref(s);
17209 s = NULL; 17257 s = NULL;
17210 } 17258 }
17211 17259
17212 li = li->li_next; 17260 li = li->li_next;