Mercurial > vim
comparison src/highlight.c @ 17488:bba80d61ea73 v8.1.1742
patch 8.1.1742: still some match functions in evalfunc.c
commit https://github.com/vim/vim/commit/7dfb016d25e3e3e1f4411026dda21d1536f21acc
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 24 16:00:39 2019 +0200
patch 8.1.1742: still some match functions in evalfunc.c
Problem: Still some match functions in evalfunc.c.
Solution: Move them to highlight.c.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 24 Jul 2019 16:15:05 +0200 |
parents | bdf277d2d14c |
children | 367ef00c6258 |
comparison
equal
deleted
inserted
replaced
17487:a9fd9cb70c4f | 17488:bba80d61ea73 |
---|---|
3662 * highlighted with the group 'grp' with priority 'prio'. | 3662 * highlighted with the group 'grp' with priority 'prio'. |
3663 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1). | 3663 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1). |
3664 * If no particular ID is desired, -1 must be specified for 'id'. | 3664 * If no particular ID is desired, -1 must be specified for 'id'. |
3665 * Return ID of added match, -1 on failure. | 3665 * Return ID of added match, -1 on failure. |
3666 */ | 3666 */ |
3667 int | 3667 static int |
3668 match_add( | 3668 match_add( |
3669 win_T *wp, | 3669 win_T *wp, |
3670 char_u *grp, | 3670 char_u *grp, |
3671 char_u *pat, | 3671 char_u *pat, |
3672 int prio, | 3672 int prio, |
3860 | 3860 |
3861 /* | 3861 /* |
3862 * Delete match with ID 'id' in the match list of window 'wp'. | 3862 * Delete match with ID 'id' in the match list of window 'wp'. |
3863 * Print error messages if 'perr' is TRUE. | 3863 * Print error messages if 'perr' is TRUE. |
3864 */ | 3864 */ |
3865 int | 3865 static int |
3866 match_delete(win_T *wp, int id, int perr) | 3866 match_delete(win_T *wp, int id, int perr) |
3867 { | 3867 { |
3868 matchitem_T *cur = wp->w_match_head; | 3868 matchitem_T *cur = wp->w_match_head; |
3869 matchitem_T *prev = cur; | 3869 matchitem_T *prev = cur; |
3870 int rtype = SOME_VALID; | 3870 int rtype = SOME_VALID; |
3937 | 3937 |
3938 /* | 3938 /* |
3939 * Get match from ID 'id' in window 'wp'. | 3939 * Get match from ID 'id' in window 'wp'. |
3940 * Return NULL if match not found. | 3940 * Return NULL if match not found. |
3941 */ | 3941 */ |
3942 matchitem_T * | 3942 static matchitem_T * |
3943 get_match(win_T *wp, int id) | 3943 get_match(win_T *wp, int id) |
3944 { | 3944 { |
3945 matchitem_T *cur = wp->w_match_head; | 3945 matchitem_T *cur = wp->w_match_head; |
3946 | 3946 |
3947 while (cur != NULL && cur->id != id) | 3947 while (cur != NULL && cur->id != id) |
3978 } | 3978 } |
3979 | 3979 |
3980 return OK; | 3980 return OK; |
3981 } | 3981 } |
3982 #endif | 3982 #endif |
3983 | |
3984 /* | |
3985 * "clearmatches()" function | |
3986 */ | |
3987 void | |
3988 f_clearmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | |
3989 { | |
3990 #ifdef FEAT_SEARCH_EXTRA | |
3991 win_T *win = get_optional_window(argvars, 0); | |
3992 | |
3993 if (win != NULL) | |
3994 clear_matches(win); | |
3995 #endif | |
3996 } | |
3983 | 3997 |
3984 /* | 3998 /* |
3985 * "getmatches()" function | 3999 * "getmatches()" function |
3986 */ | 4000 */ |
3987 void | 4001 void |
4048 } | 4062 } |
4049 # endif | 4063 # endif |
4050 } | 4064 } |
4051 | 4065 |
4052 /* | 4066 /* |
4067 * "setmatches()" function | |
4068 */ | |
4069 void | |
4070 f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | |
4071 { | |
4072 #ifdef FEAT_SEARCH_EXTRA | |
4073 list_T *l; | |
4074 listitem_T *li; | |
4075 dict_T *d; | |
4076 list_T *s = NULL; | |
4077 win_T *win = get_optional_window(argvars, 1); | |
4078 | |
4079 rettv->vval.v_number = -1; | |
4080 if (argvars[0].v_type != VAR_LIST) | |
4081 { | |
4082 emsg(_(e_listreq)); | |
4083 return; | |
4084 } | |
4085 if (win == NULL) | |
4086 return; | |
4087 | |
4088 if ((l = argvars[0].vval.v_list) != NULL) | |
4089 { | |
4090 /* To some extent make sure that we are dealing with a list from | |
4091 * "getmatches()". */ | |
4092 li = l->lv_first; | |
4093 while (li != NULL) | |
4094 { | |
4095 if (li->li_tv.v_type != VAR_DICT | |
4096 || (d = li->li_tv.vval.v_dict) == NULL) | |
4097 { | |
4098 emsg(_(e_invarg)); | |
4099 return; | |
4100 } | |
4101 if (!(dict_find(d, (char_u *)"group", -1) != NULL | |
4102 && (dict_find(d, (char_u *)"pattern", -1) != NULL | |
4103 || dict_find(d, (char_u *)"pos1", -1) != NULL) | |
4104 && dict_find(d, (char_u *)"priority", -1) != NULL | |
4105 && dict_find(d, (char_u *)"id", -1) != NULL)) | |
4106 { | |
4107 emsg(_(e_invarg)); | |
4108 return; | |
4109 } | |
4110 li = li->li_next; | |
4111 } | |
4112 | |
4113 clear_matches(win); | |
4114 li = l->lv_first; | |
4115 while (li != NULL) | |
4116 { | |
4117 int i = 0; | |
4118 char buf[30]; // use 30 to avoid compiler warning | |
4119 dictitem_T *di; | |
4120 char_u *group; | |
4121 int priority; | |
4122 int id; | |
4123 char_u *conceal; | |
4124 | |
4125 d = li->li_tv.vval.v_dict; | |
4126 if (dict_find(d, (char_u *)"pattern", -1) == NULL) | |
4127 { | |
4128 if (s == NULL) | |
4129 { | |
4130 s = list_alloc(); | |
4131 if (s == NULL) | |
4132 return; | |
4133 } | |
4134 | |
4135 /* match from matchaddpos() */ | |
4136 for (i = 1; i < 9; i++) | |
4137 { | |
4138 sprintf((char *)buf, (char *)"pos%d", i); | |
4139 if ((di = dict_find(d, (char_u *)buf, -1)) != NULL) | |
4140 { | |
4141 if (di->di_tv.v_type != VAR_LIST) | |
4142 return; | |
4143 | |
4144 list_append_tv(s, &di->di_tv); | |
4145 s->lv_refcount++; | |
4146 } | |
4147 else | |
4148 break; | |
4149 } | |
4150 } | |
4151 | |
4152 group = dict_get_string(d, (char_u *)"group", TRUE); | |
4153 priority = (int)dict_get_number(d, (char_u *)"priority"); | |
4154 id = (int)dict_get_number(d, (char_u *)"id"); | |
4155 conceal = dict_find(d, (char_u *)"conceal", -1) != NULL | |
4156 ? dict_get_string(d, (char_u *)"conceal", TRUE) | |
4157 : NULL; | |
4158 if (i == 0) | |
4159 { | |
4160 match_add(win, group, | |
4161 dict_get_string(d, (char_u *)"pattern", FALSE), | |
4162 priority, id, NULL, conceal); | |
4163 } | |
4164 else | |
4165 { | |
4166 match_add(win, group, NULL, priority, id, s, conceal); | |
4167 list_unref(s); | |
4168 s = NULL; | |
4169 } | |
4170 vim_free(group); | |
4171 vim_free(conceal); | |
4172 | |
4173 li = li->li_next; | |
4174 } | |
4175 rettv->vval.v_number = 0; | |
4176 } | |
4177 #endif | |
4178 } | |
4179 | |
4180 /* | |
4053 * "matchadd()" function | 4181 * "matchadd()" function |
4054 */ | 4182 */ |
4055 void | 4183 void |
4056 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | 4184 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
4057 { | 4185 { |
4196 rettv->vval.v_number = match_delete(win, | 4324 rettv->vval.v_number = match_delete(win, |
4197 (int)tv_get_number(&argvars[0]), TRUE); | 4325 (int)tv_get_number(&argvars[0]), TRUE); |
4198 # endif | 4326 # endif |
4199 } | 4327 } |
4200 #endif | 4328 #endif |
4329 | |
4330 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) | |
4331 /* | |
4332 * ":[N]match {group} {pattern}" | |
4333 * Sets nextcmd to the start of the next command, if any. Also called when | |
4334 * skipping commands to find the next command. | |
4335 */ | |
4336 void | |
4337 ex_match(exarg_T *eap) | |
4338 { | |
4339 char_u *p; | |
4340 char_u *g = NULL; | |
4341 char_u *end; | |
4342 int c; | |
4343 int id; | |
4344 | |
4345 if (eap->line2 <= 3) | |
4346 id = eap->line2; | |
4347 else | |
4348 { | |
4349 emsg(_(e_invcmd)); | |
4350 return; | |
4351 } | |
4352 | |
4353 /* First clear any old pattern. */ | |
4354 if (!eap->skip) | |
4355 match_delete(curwin, id, FALSE); | |
4356 | |
4357 if (ends_excmd(*eap->arg)) | |
4358 end = eap->arg; | |
4359 else if ((STRNICMP(eap->arg, "none", 4) == 0 | |
4360 && (VIM_ISWHITE(eap->arg[4]) || ends_excmd(eap->arg[4])))) | |
4361 end = eap->arg + 4; | |
4362 else | |
4363 { | |
4364 p = skiptowhite(eap->arg); | |
4365 if (!eap->skip) | |
4366 g = vim_strnsave(eap->arg, (int)(p - eap->arg)); | |
4367 p = skipwhite(p); | |
4368 if (*p == NUL) | |
4369 { | |
4370 /* There must be two arguments. */ | |
4371 vim_free(g); | |
4372 semsg(_(e_invarg2), eap->arg); | |
4373 return; | |
4374 } | |
4375 end = skip_regexp(p + 1, *p, TRUE, NULL); | |
4376 if (!eap->skip) | |
4377 { | |
4378 if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) | |
4379 { | |
4380 vim_free(g); | |
4381 eap->errmsg = e_trailing; | |
4382 return; | |
4383 } | |
4384 if (*end != *p) | |
4385 { | |
4386 vim_free(g); | |
4387 semsg(_(e_invarg2), p); | |
4388 return; | |
4389 } | |
4390 | |
4391 c = *end; | |
4392 *end = NUL; | |
4393 match_add(curwin, g, p + 1, 10, id, NULL, NULL); | |
4394 vim_free(g); | |
4395 *end = c; | |
4396 } | |
4397 } | |
4398 eap->nextcmd = find_nextcmd(end); | |
4399 } | |
4400 #endif |