annotate src/match.c @ 30015:adb0de8be4ce v9.0.0345

patch 9.0.0345: error message for list argument could be clearer Commit: https://github.com/vim/vim/commit/d83392a43a48c566c0f3b76382a3648584dae32b Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 1 12:22:46 2022 +0100 patch 9.0.0345: error message for list argument could be clearer Problem: Error message for list argument could be clearer. Solution: Include the argument number. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/11027)
author Bram Moolenaar <Bram@vim.org>
date Thu, 01 Sep 2022 13:30:05 +0200
parents 89e1d67814a9
children 86683eee58ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * match.c: functions for highlighting matches
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 # define SEARCH_HL_PRIORITY 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 * Add match to the match list of window 'wp'. The pattern 'pat' will be
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * highlighted with the group 'grp' with priority 'prio'.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * If no particular ID is desired, -1 must be specified for 'id'.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 * Return ID of added match, -1 on failure.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 match_add(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 win_T *wp,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 char_u *grp,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 char_u *pat,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 int prio,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 int id,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 list_T *pos_list,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 char_u *conceal_char UNUSED) // pointer to conceal replacement char
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 matchitem_T *cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 matchitem_T *prev;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 matchitem_T *m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 int hlg_id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 regprog_T *regprog = NULL;
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29442
diff changeset
42 int rtype = UPD_SOME_VALID;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 if (*grp == NUL || (pat != NULL && *pat == NUL))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 if (id < -1 || id == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 {
26964
5de60e0d65fa patch 8.2.4011: test fails because of changed error number
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
48 semsg(_(e_invalid_id_nr_must_be_greater_than_or_equal_to_one_1), id);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 if (id != -1)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if (cur->id == id)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 {
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
58 semsg(_(e_id_already_taken_nr), id);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 {
25306
078edc1821bf patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
66 semsg(_(e_no_such_highlight_group_name_str), grp);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26823
diff changeset
71 semsg(_(e_invalid_argument_str), pat);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 // Find available match ID.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 while (id == -1)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 while (cur != NULL && cur->id != wp->w_next_match_id)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 if (cur == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 id = wp->w_next_match_id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 wp->w_next_match_id++;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 // Build new match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 m = ALLOC_CLEAR_ONE(matchitem_T);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 m->id = id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 m->priority = prio;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 m->pattern = pat == NULL ? NULL : vim_strsave(pat);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 m->hlg_id = hlg_id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 m->match.regprog = regprog;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 m->match.rmm_ic = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 m->match.rmm_maxcol = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 # if defined(FEAT_CONCEAL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 m->conceal_char = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 if (conceal_char != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 m->conceal_char = (*mb_ptr2char)(conceal_char);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 // Set up position matches
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 if (pos_list != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 linenr_T toplnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 linenr_T botlnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 listitem_T *li;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 int i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 CHECK_LIST_MATERIALIZE(pos_list);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 for (i = 0, li = pos_list->lv_first; li != NULL && i < MAXPOSMATCH;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 i++, li = li->li_next)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 linenr_T lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 colnr_T col = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 int len = 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 list_T *subl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 listitem_T *subli;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 int error = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 if (li->li_tv.v_type == VAR_LIST)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 subl = li->li_tv.vval.v_list;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 if (subl == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 subli = subl->lv_first;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 if (subli == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 lnum = tv_get_number_chk(&subli->li_tv, &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 if (lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 --i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 m->pos.pos[i].lnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 subli = subli->li_next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 if (subli != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 col = tv_get_number_chk(&subli->li_tv, &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 subli = subli->li_next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 if (subli != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 len = tv_get_number_chk(&subli->li_tv, &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 m->pos.pos[i].col = col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 m->pos.pos[i].len = len;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 else if (li->li_tv.v_type == VAR_NUMBER)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 if (li->li_tv.vval.v_number == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 --i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 m->pos.pos[i].lnum = li->li_tv.vval.v_number;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 m->pos.pos[i].col = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 m->pos.pos[i].len = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 {
26897
d02d40f0261c patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26887
diff changeset
167 emsg(_(e_list_or_number_required));
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 if (toplnum == 0 || lnum < toplnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 toplnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 if (botlnum == 0 || lnum >= botlnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 botlnum = lnum + 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 // Calculate top and bottom lines for redrawing area
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 if (toplnum != 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 if (wp->w_buffer->b_mod_set)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 if (wp->w_buffer->b_mod_top > toplnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 wp->w_buffer->b_mod_top = toplnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 if (wp->w_buffer->b_mod_bot < botlnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 wp->w_buffer->b_mod_bot = botlnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 wp->w_buffer->b_mod_set = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 wp->w_buffer->b_mod_top = toplnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 wp->w_buffer->b_mod_bot = botlnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 wp->w_buffer->b_mod_xlines = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 m->pos.toplnum = toplnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 m->pos.botlnum = botlnum;
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29442
diff changeset
195 rtype = UPD_VALID;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 // Insert new match. The match list is in ascending order with regard to
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 // the match priorities.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 while (cur != NULL && prio >= cur->priority)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 if (cur == prev)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 wp->w_match_head = m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 prev->next = m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 m->next = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 redraw_win_later(wp, rtype);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 return id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 fail:
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 vim_free(m);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 * Delete match with ID 'id' in the match list of window 'wp'.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 * Print error messages if 'perr' is TRUE.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 match_delete(win_T *wp, int id, int perr)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 matchitem_T *cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 matchitem_T *prev = cur;
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29442
diff changeset
231 int rtype = UPD_SOME_VALID;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 if (id < 1)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 if (perr == TRUE)
26964
5de60e0d65fa patch 8.2.4011: test fails because of changed error number
Bram Moolenaar <Bram@vim.org>
parents: 26962
diff changeset
236 semsg(_(e_invalid_id_nr_must_be_greater_than_or_equal_to_one_2), id);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 while (cur != NULL && cur->id != id)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 if (cur == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 if (perr == TRUE)
26962
85866e069c24 patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
247 semsg(_(e_id_not_found_nr), id);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 if (cur == prev)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 wp->w_match_head = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 prev->next = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 vim_regfree(cur->match.regprog);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 vim_free(cur->pattern);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 if (cur->pos.toplnum != 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 if (wp->w_buffer->b_mod_set)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 if (wp->w_buffer->b_mod_top > cur->pos.toplnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 wp->w_buffer->b_mod_top = cur->pos.toplnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 if (wp->w_buffer->b_mod_bot < cur->pos.botlnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 wp->w_buffer->b_mod_bot = cur->pos.botlnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 wp->w_buffer->b_mod_set = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 wp->w_buffer->b_mod_top = cur->pos.toplnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 wp->w_buffer->b_mod_bot = cur->pos.botlnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 wp->w_buffer->b_mod_xlines = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 }
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29442
diff changeset
272 rtype = UPD_VALID;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 vim_free(cur);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 redraw_win_later(wp, rtype);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 return 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 * Delete all matches in the match list of window 'wp'.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 clear_matches(win_T *wp)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 matchitem_T *m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 while (wp->w_match_head != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 m = wp->w_match_head->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 vim_regfree(wp->w_match_head->match.regprog);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 vim_free(wp->w_match_head->pattern);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 vim_free(wp->w_match_head);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 wp->w_match_head = m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 }
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29442
diff changeset
295 redraw_win_later(wp, UPD_SOME_VALID);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 * Get match from ID 'id' in window 'wp'.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 * Return NULL if match not found.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 static matchitem_T *
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 get_match(win_T *wp, int id)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 matchitem_T *cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 while (cur != NULL && cur->id != id)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 return cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 * Init for calling prepare_search_hl().
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 init_search_hl(win_T *wp, match_T *search_hl)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 matchitem_T *cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 // Setup for match and 'hlsearch' highlighting. Disable any previous
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 // match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 cur->hl.rm = cur->match;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 if (cur->hlg_id == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 cur->hl.attr = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 cur->hl.attr = syn_id2attr(cur->hlg_id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 cur->hl.buf = wp->w_buffer;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 cur->hl.lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 cur->hl.first_lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 search_hl->buf = wp->w_buffer;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 search_hl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 search_hl->first_lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 // time limit is set at the toplevel, for all windows
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 * If there is a match fill "shl" and return one.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 * Return zero otherwise.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 next_search_hl_pos(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 match_T *shl, // points to a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 posmatch_T *posmatch, // match positions
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 colnr_T mincol) // minimal column for a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 int i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 int found = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 for (i = posmatch->cur; i < MAXPOSMATCH; i++)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 llpos_T *pos = &posmatch->pos[i];
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 if (pos->lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 if (pos->len == 0 && pos->col < mincol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 if (pos->lnum == lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 if (found >= 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 // if this match comes before the one at "found" then swap
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 // them
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 if (pos->col < posmatch->pos[found].col)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 llpos_T tmp = *pos;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 *pos = posmatch->pos[found];
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 posmatch->pos[found] = tmp;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 found = i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 posmatch->cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 if (found >= 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 colnr_T start = posmatch->pos[found].col == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 ? 0 : posmatch->pos[found].col - 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 colnr_T end = posmatch->pos[found].col == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 ? MAXCOL : start + posmatch->pos[found].len;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 shl->lnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 shl->rm.startpos[0].lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 shl->rm.startpos[0].col = start;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 shl->rm.endpos[0].lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 shl->rm.endpos[0].col = end;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 shl->is_addpos = TRUE;
28469
9ff0e5a29037 patch 8.2.4759: CurSearch highlight does not work for multi-line match
Bram Moolenaar <Bram@vim.org>
parents: 28399
diff changeset
395 shl->has_cursor = FALSE;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 posmatch->cur = found + 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 return 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 return 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 * Search for a next 'hlsearch' or match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 * Uses shl->buf.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 * Sets shl->lnum and shl->rm contents.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 * Note: Assumes a previous match is always before "lnum", unless
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 * shl->lnum is zero.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 * Careful: Any pointers for buffer lines will become invalid.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 static void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 next_search_hl(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 win_T *win,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 match_T *search_hl,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 match_T *shl, // points to search_hl or a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 colnr_T mincol, // minimal column for a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 matchitem_T *cur) // to retrieve match positions if any
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 linenr_T l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 colnr_T matchcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 long nmatched;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 int called_emsg_before = called_emsg;
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29050
diff changeset
423 int timed_out = FALSE;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 // for :{range}s/pat only highlight inside the range
26823
f1618f8705e4 patch 8.2.3940: match highlight disappears when doing incsearch for ":s/pat"
Bram Moolenaar <Bram@vim.org>
parents: 26334
diff changeset
426 if ((lnum < search_first_line || lnum > search_last_line) && cur == NULL)
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 if (shl->lnum != 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 // Check for three situations:
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 // 1. If the "lnum" is below a previous match, start a new search.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 // 2. If the previous match includes "mincol", use it.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 // 3. Continue after the previous match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 if (lnum > l)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 else if (lnum < l || shl->rm.endpos[0].col > mincol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 // Repeat searching for a match until one is found that includes "mincol"
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 // or none is found in this line.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 for (;;)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 // Three situations:
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 // 1. No useful previous match: search from start of line.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 // 2. Not Vi compatible or empty match: continue at next character.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 // Break the loop if this is beyond the end of the line.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 // 3. Vi compatible searching: continue at end of previous match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 if (shl->lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 matchcol = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 || (shl->rm.endpos[0].lnum == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 char_u *ml;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 matchcol = shl->rm.startpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 if (*ml == NUL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 ++matchcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 if (has_mbyte)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 matchcol += mb_ptr2len(ml);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 ++matchcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 matchcol = shl->rm.endpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 shl->lnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 if (shl->rm.regprog != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 // Remember whether shl->rm is using a copy of the regprog in
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 // cur->match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 int regprog_is_copy = (shl != search_hl && cur != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 && shl == &cur->hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 && cur->match.regprog == cur->hl.rm.regprog);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum,
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 29050
diff changeset
488 matchcol, &timed_out);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 // Copy the regprog, in case it got freed and recompiled.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 if (regprog_is_copy)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 cur->match.regprog = cur->hl.rm.regprog;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 if (called_emsg > called_emsg_before || got_int || timed_out)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 // Error while handling regexp: stop using this regexp.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 if (shl == search_hl)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 // don't free regprog in the match list, it's a copy
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 vim_regfree(shl->rm.regprog);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 set_no_hlsearch(TRUE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 shl->rm.regprog = NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 got_int = FALSE; // avoid the "Type :quit to exit Vim" message
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 else if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 nmatched = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 if (nmatched == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 shl->lnum = 0; // no match found
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 if (shl->rm.startpos[0].lnum > 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 || shl->rm.startpos[0].col >= mincol
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 || nmatched > 1
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 || shl->rm.endpos[0].col > mincol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 shl->lnum += shl->rm.startpos[0].lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 break; // useful match found
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 * Advance to the match in window "wp" line "lnum" or past it.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 matchitem_T *cur; // points to the match list
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 match_T *shl; // points to search_hl or a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 int shl_flag; // flag to indicate whether search_hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 // has been processed or not
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 int pos_inprogress; // marks that position match search is
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 // in progress
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 int n;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 // When using a multi-line pattern, start searching at the top
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 // of the window or just after a closed fold.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 // Do this both for search_hl and the match list.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 shl_flag = WIN_IS_POPUP(wp); // skip search_hl in a popup window
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 while (cur != NULL || shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 if (shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 if (shl->rm.regprog != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 && shl->lnum == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 && re_multiline(shl->rm.regprog))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 if (shl->first_lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 # ifdef FEAT_FOLDING
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 for (shl->first_lnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 shl->first_lnum > wp->w_topline; --shl->first_lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 if (hasFoldingWin(wp, shl->first_lnum - 1,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 NULL, NULL, TRUE, NULL))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 # else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 shl->first_lnum = wp->w_topline;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 cur->pos.cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 pos_inprogress = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 n = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 while (shl->first_lnum < lnum && (shl->rm.regprog != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 || (cur != NULL && pos_inprogress)))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 next_search_hl(wp, search_hl, shl, shl->first_lnum, (colnr_T)n,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 shl == search_hl ? NULL : cur);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 pos_inprogress = cur == NULL || cur->pos.cur == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 ? FALSE : TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 if (shl->lnum != 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 shl->first_lnum = shl->lnum
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 + shl->rm.endpos[0].lnum
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 - shl->rm.startpos[0].lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 n = shl->rm.endpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 ++shl->first_lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 n = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 if (shl != search_hl && cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 /*
28562
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
603 * Update "shl->has_cursor" based on the match in "shl" and the cursor
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
604 * position.
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
605 */
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
606 static void
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
607 check_cur_search_hl(win_T *wp, match_T *shl)
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
608 {
28576
3a16a350614f patch 8.2.4812: unused struct item
Bram Moolenaar <Bram@vim.org>
parents: 28562
diff changeset
609 linenr_T linecount = shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
28562
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
610
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
611 if (wp->w_cursor.lnum >= shl->lnum
28576
3a16a350614f patch 8.2.4812: unused struct item
Bram Moolenaar <Bram@vim.org>
parents: 28562
diff changeset
612 && wp->w_cursor.lnum <= shl->lnum + linecount
28562
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
613 && (wp->w_cursor.lnum > shl->lnum
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
614 || wp->w_cursor.col >= shl->rm.startpos[0].col)
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
615 && (wp->w_cursor.lnum < shl->lnum + linecount
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
616 || wp->w_cursor.col < shl->rm.endpos[0].col))
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
617 shl->has_cursor = TRUE;
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
618 else
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
619 shl->has_cursor = FALSE;
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
620 }
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
621
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
622 /*
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 * Prepare for 'hlsearch' and match highlighting in one window line.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 * Return TRUE if there is such highlighting and set "search_attr" to the
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 * current highlight attribute.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 prepare_search_hl_line(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 win_T *wp,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 colnr_T mincol,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 char_u **line,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 match_T *search_hl,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 int *search_attr)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 matchitem_T *cur; // points to the match list
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 match_T *shl; // points to search_hl or a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 int shl_flag; // flag to indicate whether search_hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 // has been processed or not
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 int area_highlighting = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 // Handle highlighting the last used search pattern and matches.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 // Do this for both search_hl and the match list.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 // Do not use search_hl in a popup window.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 shl_flag = WIN_IS_POPUP(wp);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 while (cur != NULL || shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 if (shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 shl->startcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 shl->endcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 shl->attr_cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 shl->is_addpos = FALSE;
28469
9ff0e5a29037 patch 8.2.4759: CurSearch highlight does not work for multi-line match
Bram Moolenaar <Bram@vim.org>
parents: 28399
diff changeset
660 shl->has_cursor = FALSE;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 cur->pos.cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 next_search_hl(wp, search_hl, shl, lnum, mincol,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 shl == search_hl ? NULL : cur);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 // Need to get the line again, a multi-line regexp may have made it
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 // invalid.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 *line = ml_get_buf(wp->w_buffer, lnum, FALSE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 if (shl->lnum != 0 && shl->lnum <= lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 if (shl->lnum == lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 shl->startcol = shl->rm.startpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 shl->startcol = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 if (lnum == shl->lnum + shl->rm.endpos[0].lnum
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 - shl->rm.startpos[0].lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 shl->endcol = shl->rm.endpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 shl->endcol = MAXCOL;
28469
9ff0e5a29037 patch 8.2.4759: CurSearch highlight does not work for multi-line match
Bram Moolenaar <Bram@vim.org>
parents: 28399
diff changeset
681
9ff0e5a29037 patch 8.2.4759: CurSearch highlight does not work for multi-line match
Bram Moolenaar <Bram@vim.org>
parents: 28399
diff changeset
682 // check if the cursor is in the match before changing the columns
28562
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
683 if (shl == search_hl)
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
684 check_cur_search_hl(wp, shl);
28469
9ff0e5a29037 patch 8.2.4759: CurSearch highlight does not work for multi-line match
Bram Moolenaar <Bram@vim.org>
parents: 28399
diff changeset
685
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 // Highlight one character for an empty match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 if (shl->startcol == shl->endcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 if (has_mbyte && (*line)[shl->endcol] != NUL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 shl->endcol += (*mb_ptr2len)((*line) + shl->endcol);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 ++shl->endcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 if ((long)shl->startcol < mincol) // match at leftcol
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 shl->attr_cur = shl->attr;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 *search_attr = shl->attr;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 area_highlighting = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 if (shl != search_hl && cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 return area_highlighting;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 * For a position in a line: Check for start/end of 'hlsearch' and other
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 * matches.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 * After end, check for start/end of next match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * When another match, have to check for start again.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 * Watch out for matching an empty string!
26334
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
713 * "on_last_col" is set to TRUE with non-zero search_attr and the next column
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
714 * is endcol.
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 * Return the updated search_attr.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 update_search_hl(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 win_T *wp,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 colnr_T col,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 char_u **line,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 match_T *search_hl,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 int *has_match_conc UNUSED,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 int *match_conc UNUSED,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 int did_line_attr,
26334
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
727 int lcs_eol_one,
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
728 int *on_last_col)
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 matchitem_T *cur; // points to the match list
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 match_T *shl; // points to search_hl or a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 int shl_flag; // flag to indicate whether search_hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 // has been processed or not
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 int pos_inprogress; // marks that position match search is in
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 // progress
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 int search_attr = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 // Do this for 'search_hl' and the match list (ordered by priority).
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 shl_flag = WIN_IS_POPUP(wp);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 while (cur != NULL || shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 if (shl_flag == FALSE
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 && (cur == NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 || cur->priority > SEARCH_HL_PRIORITY))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 cur->pos.cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 pos_inprogress = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 while (shl->rm.regprog != NULL || (cur != NULL && pos_inprogress))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 if (shl->startcol != MAXCOL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 && col >= shl->startcol
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 && col < shl->endcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 int next_col = col + mb_ptr2len(*line + col);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 if (shl->endcol < next_col)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 shl->endcol = next_col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 shl->attr_cur = shl->attr;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 # ifdef FEAT_CONCEAL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 // Match with the "Conceal" group results in hiding
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 // the match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 if (cur != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 && shl != search_hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 && syn_name2id((char_u *)"Conceal") == cur->hlg_id)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 *has_match_conc = col == shl->startcol ? 2 : 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 *match_conc = cur->conceal_char;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 *has_match_conc = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 # endif
28399
d395fadbaf67 patch 8.2.4724: current instance of last search pattern not easily spotted
Bram Moolenaar <Bram@vim.org>
parents: 28315
diff changeset
780 // Highlight the match were the cursor is using the CurSearch
d395fadbaf67 patch 8.2.4724: current instance of last search pattern not easily spotted
Bram Moolenaar <Bram@vim.org>
parents: 28315
diff changeset
781 // group.
28469
9ff0e5a29037 patch 8.2.4759: CurSearch highlight does not work for multi-line match
Bram Moolenaar <Bram@vim.org>
parents: 28399
diff changeset
782 if (shl == search_hl && shl->has_cursor)
29050
a2710736125a patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents: 28576
diff changeset
783 {
28399
d395fadbaf67 patch 8.2.4724: current instance of last search pattern not easily spotted
Bram Moolenaar <Bram@vim.org>
parents: 28315
diff changeset
784 shl->attr_cur = HL_ATTR(HLF_LC);
29050
a2710736125a patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents: 28576
diff changeset
785 if (shl->attr_cur != shl->attr)
a2710736125a patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents: 28576
diff changeset
786 search_hl_has_cursor_lnum = lnum;
a2710736125a patch 8.2.5047: CurSearch highlight is often wrong
Bram Moolenaar <Bram@vim.org>
parents: 28576
diff changeset
787 }
28399
d395fadbaf67 patch 8.2.4724: current instance of last search pattern not easily spotted
Bram Moolenaar <Bram@vim.org>
parents: 28315
diff changeset
788
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 else if (col == shl->endcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 shl->attr_cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 next_search_hl(wp, search_hl, shl, lnum, col,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 shl == search_hl ? NULL : cur);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 pos_inprogress = !(cur == NULL || cur->pos.cur == 0);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 // Need to get the line again, a multi-line regexp may have
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 // made it invalid.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 *line = ml_get_buf(wp->w_buffer, lnum, FALSE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 if (shl->lnum == lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 shl->startcol = shl->rm.startpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 if (shl->rm.endpos[0].lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 shl->endcol = shl->rm.endpos[0].col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 shl->endcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808
28562
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
809 // check if the cursor is in the match
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
810 if (shl == search_hl)
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
811 check_cur_search_hl(wp, shl);
e96111a91a21 patch 8.2.4805: CurSearch used for all matches in current line
Bram Moolenaar <Bram@vim.org>
parents: 28469
diff changeset
812
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 if (shl->startcol == shl->endcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 // highlight empty match, try again after
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 // it
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 if (has_mbyte)
24000
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
818 {
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
819 char_u *p = *line + shl->endcol;
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
820
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
821 if (*p == NUL)
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
822 // consistent with non-mbyte
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
823 ++shl->endcol;
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
824 else
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
825 shl->endcol += (*mb_ptr2len)(p);
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
826 }
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 ++shl->endcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 // Loop to check if the match starts at the
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 // current position
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 if (shl != search_hl && cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 // Use attributes from match with highest priority among 'search_hl' and
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 // the match list.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 shl_flag = WIN_IS_POPUP(wp);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 while (cur != NULL || shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 if (shl_flag == FALSE
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 && (cur == NULL ||
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 cur->priority > SEARCH_HL_PRIORITY))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 if (shl->attr_cur != 0)
26334
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
858 {
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 search_attr = shl->attr_cur;
26334
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
860 *on_last_col = col + 1 >= shl->endcol;
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
861 }
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 if (shl != search_hl && cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 // Only highlight one character after the last column.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 if (*(*line + col) == NUL && (did_line_attr >= 1
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 || (wp->w_p_list && lcs_eol_one == -1)))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 search_attr = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 return search_attr;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 long prevcol = curcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 int prevcol_hl_flag = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 matchitem_T *cur; // points to the match list
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878
24000
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
879 #if defined(FEAT_PROP_POPUP)
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
880 // don't do this in a popup window
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
881 if (popup_is_popup(wp))
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
882 return FALSE;
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
883 #endif
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
884
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 // we're not really at that column when skipping some text
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 ++prevcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888
24000
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
889 // Highlight a character after the end of the line if the match started
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
890 // at the end of the line or when the match continues in the next line
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
891 // (match includes the line break).
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
892 if (!search_hl->is_addpos && (prevcol == (long)search_hl->startcol
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
893 || (prevcol > (long)search_hl->startcol
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
894 && search_hl->endcol == MAXCOL)))
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 prevcol_hl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 {
24000
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
901 if (!cur->hl.is_addpos && (prevcol == (long)cur->hl.startcol
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
902 || (prevcol > (long)cur->hl.startcol
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
903 && cur->hl.endcol == MAXCOL)))
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 prevcol_hl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 return prevcol_hl_flag;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 * Get highlighting for the char after the text in "char_attr" from 'hlsearch'
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 * or match highlighting.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 get_search_match_hl(win_T *wp, match_T *search_hl, long col, int *char_attr)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 matchitem_T *cur; // points to the match list
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 match_T *shl; // points to search_hl or a match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 int shl_flag; // flag to indicate whether search_hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 // has been processed or not
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 cur = wp->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 shl_flag = WIN_IS_POPUP(wp);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 while (cur != NULL || shl_flag == FALSE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 if (shl_flag == FALSE
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 && ((cur != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 && cur->priority > SEARCH_HL_PRIORITY)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 || cur == NULL))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 if (col - 1 == (long)shl->startcol
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 && (shl == search_hl || !shl->is_addpos))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 *char_attr = shl->attr;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 if (shl != search_hl && cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 #endif // FEAT_SEARCH_EXTRA
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 #if defined(FEAT_EVAL) || defined(PROTO)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 # ifdef FEAT_SEARCH_EXTRA
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 matchadd_dict_arg(typval_T *tv, char_u **conceal_char, win_T **win)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 dictitem_T *di;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 if (tv->v_type != VAR_DICT)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
959 emsg(_(e_dictionary_required));
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 return FAIL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962
28315
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
963 if (dict_has_key(tv->vval.v_dict, "conceal"))
29442
827d9f2b7a71 patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents: 29081
diff changeset
964 *conceal_char = dict_get_string(tv->vval.v_dict, "conceal", FALSE);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 if ((di = dict_find(tv->vval.v_dict, (char_u *)"window", -1)) != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 *win = find_win_by_nr_or_id(&di->di_tv);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 if (*win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 {
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
971 emsg(_(e_invalid_window_number));
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 return FAIL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 return OK;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 * "clearmatches()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 f_clearmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 #ifdef FEAT_SEARCH_EXTRA
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
987 win_T *win;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
989 if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
990 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
991
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
992 win = get_optional_window(argvars, 0);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 if (win != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 clear_matches(win);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 * "getmatches()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 f_getmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 # ifdef FEAT_SEARCH_EXTRA
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 dict_T *dict;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 matchitem_T *cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 int i;
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1008 win_T *win;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1010 if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1011 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1012
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1013 win = get_optional_window(argvars, 0);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 if (rettv_list_alloc(rettv) == FAIL || win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 cur = win->w_match_head;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 dict = dict_alloc();
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 if (dict == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 if (cur->match.regprog == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 // match added with matchaddpos()
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 for (i = 0; i < MAXPOSMATCH; ++i)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 llpos_T *llpos;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 char buf[30]; // use 30 to avoid compiler warning
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 list_T *l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 llpos = &cur->pos.pos[i];
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 if (llpos->lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 l = list_alloc();
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 if (l == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 list_append_number(l, (varnumber_T)llpos->lnum);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 if (llpos->col > 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 list_append_number(l, (varnumber_T)llpos->col);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 list_append_number(l, (varnumber_T)llpos->len);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 sprintf(buf, "pos%d", i + 1);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 dict_add_list(dict, buf, l);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 dict_add_string(dict, "pattern", cur->pattern);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 dict_add_string(dict, "group", syn_id2name(cur->hlg_id));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 dict_add_number(dict, "priority", (long)cur->priority);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 dict_add_number(dict, "id", (long)cur->id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 # if defined(FEAT_CONCEAL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 if (cur->conceal_char)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 char_u buf[MB_MAXBYTES + 1];
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 26964
diff changeset
1060 buf[(*mb_char2bytes)(cur->conceal_char, buf)] = NUL;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 dict_add_string(dict, "conceal", (char_u *)&buf);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 list_append_dict(rettv->vval.v_list, dict);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 * "setmatches()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 #ifdef FEAT_SEARCH_EXTRA
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 list_T *l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 listitem_T *li;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 dict_T *d;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 list_T *s = NULL;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1081 win_T *win;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 rettv->vval.v_number = -1;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1084
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1085 if (in_vim9script()
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1086 && (check_for_list_arg(argvars, 0) == FAIL
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1087 || check_for_opt_number_arg(argvars, 1) == FAIL))
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1088 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1089
30015
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29732
diff changeset
1090 if (check_for_list_arg(argvars, 0) == FAIL)
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 return;
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1092 win = get_optional_window(argvars, 1);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 if (win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 if ((l = argvars[0].vval.v_list) != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 // To some extent make sure that we are dealing with a list from
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 // "getmatches()".
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 li = l->lv_first;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 while (li != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 if (li->li_tv.v_type != VAR_DICT
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 || (d = li->li_tv.vval.v_dict) == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26823
diff changeset
1106 emsg(_(e_invalid_argument));
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 }
28315
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1109 if (!(dict_has_key(d, "group")
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1110 && (dict_has_key(d, "pattern")
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1111 || dict_has_key(d, "pos1"))
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1112 && dict_has_key(d, "priority")
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1113 && dict_has_key(d, "id")))
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26823
diff changeset
1115 emsg(_(e_invalid_argument));
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 li = li->li_next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 clear_matches(win);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 li = l->lv_first;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 while (li != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 int i = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 char buf[30]; // use 30 to avoid compiler warning
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 dictitem_T *di;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 char_u *group;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 int priority;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 int id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 char_u *conceal;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 d = li->li_tv.vval.v_dict;
28315
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1134 if (!dict_has_key(d, "pattern"))
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 if (s == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 s = list_alloc();
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 if (s == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 // match from matchaddpos()
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 for (i = 1; i < 9; i++)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 sprintf((char *)buf, (char *)"pos%d", i);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 if ((di = dict_find(d, (char_u *)buf, -1)) != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 if (di->di_tv.v_type != VAR_LIST)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 list_append_tv(s, &di->di_tv);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 s->lv_refcount++;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159
29442
827d9f2b7a71 patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents: 29081
diff changeset
1160 group = dict_get_string(d, "group", TRUE);
827d9f2b7a71 patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents: 29081
diff changeset
1161 priority = (int)dict_get_number(d, "priority");
827d9f2b7a71 patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents: 29081
diff changeset
1162 id = (int)dict_get_number(d, "id");
28315
62cc3b60493b patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1163 conceal = dict_has_key(d, "conceal")
29442
827d9f2b7a71 patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents: 29081
diff changeset
1164 ? dict_get_string(d, "conceal", TRUE)
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 : NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 if (i == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 match_add(win, group,
29442
827d9f2b7a71 patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents: 29081
diff changeset
1169 dict_get_string(d, "pattern", FALSE),
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 priority, id, NULL, conceal);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 match_add(win, group, NULL, priority, id, s, conceal);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 list_unref(s);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 s = NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 vim_free(group);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 vim_free(conceal);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 li = li->li_next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 rettv->vval.v_number = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 * "matchadd()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 f_matchadd(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 # ifdef FEAT_SEARCH_EXTRA
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 char_u buf[NUMBUFLEN];
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1196 char_u *grp; // group
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1197 char_u *pat; // pattern
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 int prio = 10; // default priority
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 int id = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 int error = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 char_u *conceal_char = NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 win_T *win = curwin;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 rettv->vval.v_number = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1206 if (in_vim9script()
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1207 && (check_for_string_arg(argvars, 0) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1208 || check_for_string_arg(argvars, 1) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1209 || check_for_opt_number_arg(argvars, 2) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1210 || (argvars[2].v_type != VAR_UNKNOWN
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1211 && (check_for_opt_number_arg(argvars, 3) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1212 || (argvars[3].v_type != VAR_UNKNOWN
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1213 && check_for_opt_dict_arg(argvars, 4) == FAIL)))))
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1214 return;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1215
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1216 grp = tv_get_string_buf_chk(&argvars[0], buf); // group
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1217 pat = tv_get_string_buf_chk(&argvars[1], buf); // pattern
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 if (grp == NULL || pat == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 if (argvars[2].v_type != VAR_UNKNOWN)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 prio = (int)tv_get_number_chk(&argvars[2], &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 if (argvars[3].v_type != VAR_UNKNOWN)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 id = (int)tv_get_number_chk(&argvars[3], &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 if (argvars[4].v_type != VAR_UNKNOWN
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 if (id >= 1 && id <= 3)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 {
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
1235 semsg(_(e_id_is_reserved_for_match_nr), id);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 rettv->vval.v_number = match_add(win, grp, pat, prio, id, NULL,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 conceal_char);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 * "matchaddpos()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 # ifdef FEAT_SEARCH_EXTRA
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 char_u buf[NUMBUFLEN];
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 char_u *group;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 int prio = 10;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 int id = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 int error = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 list_T *l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 char_u *conceal_char = NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 win_T *win = curwin;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 rettv->vval.v_number = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1262 if (in_vim9script()
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1263 && (check_for_string_arg(argvars, 0) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1264 || check_for_list_arg(argvars, 1) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1265 || check_for_opt_number_arg(argvars, 2) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1266 || (argvars[2].v_type != VAR_UNKNOWN
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1267 && (check_for_opt_number_arg(argvars, 3) == FAIL
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1268 || (argvars[3].v_type != VAR_UNKNOWN
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1269 && check_for_opt_dict_arg(argvars, 4) == FAIL)))))
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1270 return;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1271
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 group = tv_get_string_buf_chk(&argvars[0], buf);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 if (group == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 if (argvars[1].v_type != VAR_LIST)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 {
26887
612339679616 patch 8.2.3972: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26883
diff changeset
1278 semsg(_(e_argument_of_str_must_be_list), "matchaddpos()");
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 l = argvars[1].vval.v_list;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 if (l == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 if (argvars[2].v_type != VAR_UNKNOWN)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 prio = (int)tv_get_number_chk(&argvars[2], &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 if (argvars[3].v_type != VAR_UNKNOWN)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 id = (int)tv_get_number_chk(&argvars[3], &error);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 if (argvars[4].v_type != VAR_UNKNOWN
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 && matchadd_dict_arg(&argvars[4], &conceal_char, &win) == FAIL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 // id == 3 is ok because matchaddpos() is supposed to substitute :3match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 if (id == 1 || id == 2)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 {
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26897
diff changeset
1303 semsg(_(e_id_is_reserved_for_match_nr), id);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 rettv->vval.v_number = match_add(win, group, NULL, prio, id, l,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 conceal_char);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 * "matcharg()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 f_matcharg(typval_T *argvars UNUSED, typval_T *rettv)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 if (rettv_list_alloc(rettv) == OK)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 # ifdef FEAT_SEARCH_EXTRA
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1321 int id;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 matchitem_T *m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1324 if (in_vim9script() && check_for_number_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1325 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1326
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1327 id = (int)tv_get_number(&argvars[0]);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 if (id >= 1 && id <= 3)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 {
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 26964
diff changeset
1330 if ((m = get_match(curwin, id)) != NULL)
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 list_append_string(rettv->vval.v_list,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 syn_id2name(m->hlg_id), -1);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 list_append_string(rettv->vval.v_list, m->pattern, -1);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 list_append_string(rettv->vval.v_list, NULL, -1);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 list_append_string(rettv->vval.v_list, NULL, -1);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 * "matchdelete()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 f_matchdelete(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 # ifdef FEAT_SEARCH_EXTRA
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1353 win_T *win;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1355 if (in_vim9script()
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1356 && (check_for_number_arg(argvars, 0) == FAIL
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1357 || check_for_opt_number_arg(argvars, 1) == FAIL))
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1358 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1359
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25338
diff changeset
1360 win = get_optional_window(argvars, 1);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 if (win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 rettv->vval.v_number = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 rettv->vval.v_number = match_delete(win,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 (int)tv_get_number(&argvars[0]), TRUE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 * ":[N]match {group} {pattern}"
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 * Sets nextcmd to the start of the next command, if any. Also called when
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 * skipping commands to find the next command.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 ex_match(exarg_T *eap)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 char_u *p;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 char_u *g = NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 char_u *end;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 int c;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 int id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 if (eap->line2 <= 3)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 id = eap->line2;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21459
diff changeset
1389 emsg(_(e_invalid_command));
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 // First clear any old pattern.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 if (!eap->skip)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 match_delete(curwin, id, FALSE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 if (ends_excmd2(eap->cmd, eap->arg))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 end = eap->arg;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 else if ((STRNICMP(eap->arg, "none", 4) == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 && (VIM_ISWHITE(eap->arg[4])
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 || ends_excmd2(eap->arg, eap->arg + 4))))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 end = eap->arg + 4;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 p = skiptowhite(eap->arg);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 if (!eap->skip)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 g = vim_strnsave(eap->arg, p - eap->arg);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 p = skipwhite(p);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 if (*p == NUL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 // There must be two arguments.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 vim_free(g);
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26823
diff changeset
1413 semsg(_(e_invalid_argument_str), eap->arg);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 end = skip_regexp(p + 1, *p, TRUE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 if (!eap->skip)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 if (*end != NUL && !ends_excmd2(end, skipwhite(end + 1)))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 vim_free(g);
26883
7f150a4936f2 patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1422 eap->errmsg = ex_errmsg(e_trailing_characters_str, end);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 if (*end != *p)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 vim_free(g);
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26823
diff changeset
1428 semsg(_(e_invalid_argument_str), p);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 c = *end;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 *end = NUL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 match_add(curwin, g, p + 1, 10, id, NULL, NULL);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 vim_free(g);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 *end = c;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 eap->nextcmd = find_nextcmd(end);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 #endif