annotate src/match.c @ 26334:baec4e1cee43 v8.2.3698

patch 8.2.3698: match highlighting continues over breakindent Commit: https://github.com/vim/vim/commit/0c359af5c0fd106d3f57cc0bb7cef1c89b5e1e10 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 29 19:18:57 2021 +0000 patch 8.2.3698: match highlighting continues over breakindent Problem: Match highlighting continues over breakindent. Solution: Stop before the end column. (closes https://github.com/vim/vim/issues/9242)
author Bram Moolenaar <Bram@vim.org>
date Mon, 29 Nov 2021 20:30:04 +0100
parents e8e2c4d33b9b
children f1618f8705e4
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;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 int rtype = SOME_VALID;
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 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 semsg(_("E799: Invalid ID: %d (must be 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
49 id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 if (id != -1)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 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
55 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 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
58 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 semsg(_("E801: ID already taken: %d"), id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 cur = cur->next;
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 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 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
66 {
25306
078edc1821bf patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 25302
diff changeset
67 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
68 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 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
71 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 semsg(_(e_invarg2), pat);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 return -1;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 // 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
77 while (id == -1)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 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
80 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
81 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 if (cur == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 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
84 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
85 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 // Build new match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 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
89 m->id = id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 m->priority = prio;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 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
92 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
93 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
94 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
95 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
96 # 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
97 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
98 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
99 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
100 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 // 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
103 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
104 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 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
106 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
107 listitem_T *li;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 int i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 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
111 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
112 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
113 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 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
115 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
116 int len = 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 list_T *subl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 listitem_T *subli;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 int error = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 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
122 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 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
124 if (subl == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 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
127 if (subli == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 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
130 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 if (lnum == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 --i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 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
138 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
139 if (subli != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 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
142 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 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
145 if (subli != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 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
148 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 goto fail;
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 }
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].col = col;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 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
154 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 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
156 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 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
158 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 --i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 }
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].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
163 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
164 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
165 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 emsg(_("E290: List or number required"));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 goto fail;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 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
172 toplnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 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
174 botlnum = lnum + 1;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 // 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
178 if (toplnum != 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 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
181 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 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
183 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
184 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
185 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
186 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 {
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_set = TRUE;
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_top = toplnum;
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_bot = botlnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 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
193 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 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
195 m->pos.botlnum = botlnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 rtype = VALID;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 // 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
201 // the match priorities.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 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
203 prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 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
205 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (cur == prev)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 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
211 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 prev->next = m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 m->next = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 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
216 return id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 fail:
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 vim_free(m);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 return -1;
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 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 * 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
225 * 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
226 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 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
229 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 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
231 matchitem_T *prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 int rtype = SOME_VALID;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 if (id < 1)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 if (perr == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 semsg(_("E802: Invalid ID: %d (must be 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
238 id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 return -1;
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 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
242 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 prev = cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 cur = cur->next;
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 (cur == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 if (perr == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 semsg(_("E803: ID not found: %d"), id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 return -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 if (cur == prev)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 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
254 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 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
256 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
257 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
258 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
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_set)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 {
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_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
263 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
264 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
265 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
266 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 {
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_set = TRUE;
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_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
271 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
272 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
273 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 rtype = VALID;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 vim_free(cur);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 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
278 return 0;
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
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 * 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
283 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 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
286 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 matchitem_T *m;
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 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
290 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 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
292 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
293 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
294 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
295 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
296 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 redraw_win_later(wp, SOME_VALID);
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 * 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
302 * 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
303 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 static matchitem_T *
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 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
306 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 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
308
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 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
310 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 return cur;
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
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 * 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
316 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 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
319 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 matchitem_T *cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 // 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
323 // match
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 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
325 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 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
328 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
329 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
330 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 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
332 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
333 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
334 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
335 # ifdef FEAT_RELTIME
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 // Set the time limit to 'redrawtime'.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 profile_setlimit(p_rdt, &(cur->hl.tm));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 cur = cur->next;
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 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
342 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
343 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
344 // 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
345 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 * 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
349 * Return zero otherwise.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 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
353 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
354 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 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
356 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
357 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 int i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 int found = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 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
362 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 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
364
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 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
366 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 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
368 continue;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 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
370 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 if (found >= 0)
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 // 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
374 // them
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 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
376 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 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
378
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 *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
380 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
381 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 found = i;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 posmatch->cur = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 if (found >= 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 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
391 ? 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
392 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
393 ? 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
394
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 shl->lnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 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
397 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
398 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
399 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
400 shl->is_addpos = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 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
402 return 1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 return 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 * 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
409 * Uses shl->buf.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 * 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
411 * 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
412 * 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
413 * 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
414 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 static void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 next_search_hl(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 win_T *win,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 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
419 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
420 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 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
422 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
423 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 linenr_T l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 colnr_T matchcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 long nmatched;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 int called_emsg_before = called_emsg;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 // for :{range}s/pat only highlight inside the range
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 if (lnum < search_first_line || lnum > search_last_line)
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 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 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 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
437 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 // 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
439 // 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
440 // 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
441 // 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
442 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
443 if (lnum > l)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 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
446 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 }
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 // 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
450 // 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
451 for (;;)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 # ifdef FEAT_RELTIME
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 // Stop searching after passing the time limit.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 if (profile_passed_limit(&(shl->tm)))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 shl->lnum = 0; // no match found in time
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 break;
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 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 // Three situations:
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 // 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
463 // 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
464 // 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
465 // 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
466 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
467 matchcol = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 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
469 || (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
470 && 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
471 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 char_u *ml;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 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
475 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
476 if (*ml == NUL)
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 ++matchcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 if (has_mbyte)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 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
484 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 ++matchcol;
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 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 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
489
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 shl->lnum = lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 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
492 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 // 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
494 // cur->match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 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
496 && shl == &cur->hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 && 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
498 int timed_out = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 matchcol,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 #ifdef FEAT_RELTIME
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 &(shl->tm), &timed_out
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 #else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 NULL, NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 #endif
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 // 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
509 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
510 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
511
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 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
513 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 // 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
515 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
516 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 // 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
518 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
519 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
520 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 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
522 shl->lnum = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 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
524 break;
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 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
528 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
529 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 nmatched = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 if (nmatched == 0)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 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
534 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 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
537 || 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
538 || nmatched > 1
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 || 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
540 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 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
542 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
543 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 * 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
549 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 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
552 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 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
554 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
555 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
556 // 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
557 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
558 // in progress
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 int n;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 // 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
562 // 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
563 // 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
564 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
565 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
566 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
567 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 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
569 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 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
576 && shl->lnum == 0
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 && 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
578 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 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
580 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 # ifdef FEAT_FOLDING
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 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
583 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
584 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
585 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
586 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 # else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 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
589 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 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
593 pos_inprogress = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 n = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 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
596 || (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
597 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 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
599 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
600 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
601 ? FALSE : TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 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
603 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 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
605 + 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
606 - 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
607 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
608 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 ++shl->first_lnum;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 n = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 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
617 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 * 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
623 * 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
624 * current highlight attribute.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 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
628 win_T *wp,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 colnr_T mincol,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 char_u **line,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 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
633 int *search_attr)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 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
636 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
637 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
638 // 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
639 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
640
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 // 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
642 // 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
643 // 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
644 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
645 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
646 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
647 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 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
649 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 shl_flag = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 shl->startcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 shl->endcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 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
658 shl->is_addpos = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 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
661 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
662 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
663
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 // 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
665 // invalid.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 *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
667
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 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
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 == lnum)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 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
672 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 shl->startcol = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 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
675 - 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
676 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
677 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 shl->endcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 // 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
680 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
681 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 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
683 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
684 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 ++shl->endcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 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
688 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 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
690 *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
691 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 area_highlighting = TRUE;
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 (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
695 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 return area_highlighting;
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
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 * 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
702 * matches.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 * 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
704 * 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
705 * 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
706 * "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
707 * is endcol.
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 * 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
709 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 update_search_hl(
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 win_T *wp,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 linenr_T lnum,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 colnr_T col,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 char_u **line,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 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
717 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
718 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
719 int did_line_attr,
26334
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
720 int lcs_eol_one,
baec4e1cee43 patch 8.2.3698: match highlighting continues over breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
721 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
722 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 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
724 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
725 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
726 // 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
727 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
728 // progress
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 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
730
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 // 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
733 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
734 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
735 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
736 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 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
738 && (cur == NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 || 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
740 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 shl_flag = TRUE;
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 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 if (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 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
748 pos_inprogress = TRUE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 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
750 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 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
752 && col >= shl->startcol
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 && col < shl->endcol)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 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
756
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 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
758 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
759 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
760 # ifdef FEAT_CONCEAL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 // 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
762 // the match.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 if (cur != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 && shl != search_hl
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 && 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
766 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 *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
768 *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
769 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 *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
772 # endif
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 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
775 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 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
777 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
778 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
779 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
780
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 // 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
782 // made it invalid.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 *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
784
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 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
786 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 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
788 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
789 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
790 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 shl->endcol = MAXCOL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 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
794 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 // 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
796 // it
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 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
798 {
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
799 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
800
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
801 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
802 // 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
803 ++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
804 else
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
805 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
806 }
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 ++shl->endcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 // 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
812 // current position
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 continue;
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 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 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
819 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 // 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
823 // the match list.
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 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
825 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
826 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
827 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 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
829 && (cur == NULL ||
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 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
831 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 shl_flag = TRUE;
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 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 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
838 {
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 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
840 *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
841 }
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 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
843 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 // 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
846 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
847 || (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
848 search_attr = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 return search_attr;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 }
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 int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 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
854 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 long prevcol = curcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 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
857 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
858
24000
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
859 #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
860 // 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
861 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
862 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
863 #endif
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
864
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 // 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
866 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
867 ++prevcol;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868
24000
bb2e921d2601 patch 8.2.2542: highlight of char beyond line end is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21821
diff changeset
869 // 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
870 // 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
871 // (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
872 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
873 || (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
874 && 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
875 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
876 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 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
879 while (cur != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 {
24000
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 (!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
882 || (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
883 && 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
884 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 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
886 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 cur = cur->next;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 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
892 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 * 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
896 * or match highlighting.
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 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 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
900 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 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
902 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
903 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
904 // 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
905
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 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
907 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
908 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
909 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 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
911 && ((cur != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 && 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
913 || cur == NULL))
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 shl = search_hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 shl_flag = TRUE;
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 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 shl = &cur->hl;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 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
921 && (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
922 *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
923 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
924 cur = cur->next;
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 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 #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
929
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 #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
931 # 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
932 static int
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 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
934 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 dictitem_T *di;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 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
938 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 emsg(_(e_dictreq));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 return FAIL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 if (dict_find(tv->vval.v_dict, (char_u *)"conceal", -1) != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 *conceal_char = dict_get_string(tv->vval.v_dict,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 (char_u *)"conceal", FALSE);
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 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
948 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 *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
950 if (*win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 emsg(_(e_invalwindow));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 return FAIL;
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 }
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 return OK;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960
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 * "clearmatches()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 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
966 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 #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
968 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
969
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
970 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
971 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
972
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
973 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
974 if (win != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 clear_matches(win);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 #endif
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
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 * "getmatches()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 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
984 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 # 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
986 dict_T *dict;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 matchitem_T *cur;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 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
989 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
990
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
991 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
992 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
993
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
994 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
995 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
996 return;
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 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
999 while (cur != NULL)
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 dict = dict_alloc();
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 if (dict == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 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
1005 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 // 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
1007 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
1008 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 llpos_T *llpos;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 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
1011 list_T *l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 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
1014 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
1015 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 l = list_alloc();
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 if (l == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 break;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 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
1020 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
1021 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 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
1023 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
1024 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 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
1026 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
1027 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 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
1032 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 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
1034 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
1035 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
1036 # 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
1037 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
1038 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 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
1040
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 buf[(*mb_char2bytes)((int)cur->conceal_char, buf)] = NUL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 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
1043 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 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
1046 cur = cur->next;
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 # endif
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
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 * "setmatches()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 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
1056 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 #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
1058 list_T *l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 listitem_T *li;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 dict_T *d;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 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
1062 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
1063
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 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
1065
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1066 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
1067 && (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
1068 || 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
1069 return;
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1070
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 if (argvars[0].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
1072 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 emsg(_(e_listreq));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 }
25302
4d3c68196d05 patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 24000
diff changeset
1076 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
1077 if (win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 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
1081 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 // 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
1083 // "getmatches()".
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 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
1085 while (li != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 || (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
1089 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 emsg(_(e_invarg));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 if (!(dict_find(d, (char_u *)"group", -1) != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 && (dict_find(d, (char_u *)"pattern", -1) != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 || dict_find(d, (char_u *)"pos1", -1) != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 && dict_find(d, (char_u *)"priority", -1) != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 && dict_find(d, (char_u *)"id", -1) != NULL))
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 emsg(_(e_invarg));
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 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
1103 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 clear_matches(win);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 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
1107 while (li != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 int i = 0;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111 dictitem_T *di;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 char_u *group;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 int priority;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 int id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 char_u *conceal;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 d = li->li_tv.vval.v_dict;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 if (dict_find(d, (char_u *)"pattern", -1) == NULL)
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 if (s == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 s = list_alloc();
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 if (s == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 // match from matchaddpos()
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 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
1129 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 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
1131 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
1132 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 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
1134 return;
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 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
1137 s->lv_refcount++;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 break;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 group = dict_get_string(d, (char_u *)"group", TRUE);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 priority = (int)dict_get_number(d, (char_u *)"priority");
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 id = (int)dict_get_number(d, (char_u *)"id");
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 conceal = dict_find(d, (char_u *)"conceal", -1) != NULL
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 ? dict_get_string(d, (char_u *)"conceal", TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 : NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 if (i == 0)
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 match_add(win, group,
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 dict_get_string(d, (char_u *)"pattern", FALSE),
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 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
1155 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 else
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 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
1159 list_unref(s);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 s = NULL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 vim_free(group);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 vim_free(conceal);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 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
1166 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 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
1168 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 }
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 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 * "matchadd()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 # 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
1179 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
1180 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
1181 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
1182 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
1183 int id = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 int error = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 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
1186 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
1187
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 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
1189
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1190 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
1191 && (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
1192 || 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
1193 || 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
1194 || (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
1195 && (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
1196 || (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
1197 && 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
1198 return;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1199
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1200 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
1201 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
1202 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
1203 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 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
1205 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 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
1207 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
1208 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 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
1210 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
1211 && 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
1212 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 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
1218 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 semsg(_("E798: ID is reserved for \":match\": %d"), id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 return;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 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
1224 conceal_char);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 * "matchaddpos()" function
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 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 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
1233 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 # 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
1235 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
1236 char_u *group;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 int prio = 10;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 int id = -1;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 int error = FALSE;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 list_T *l;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 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
1242 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
1243
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 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
1245
25338
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1246 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
1247 && (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
1248 || 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
1249 || 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
1250 || (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
1251 && (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
1252 || (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
1253 && 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
1254 return;
e2be9f3c5907 patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 25306
diff changeset
1255
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 if (group == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 return;
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 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
1261 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 semsg(_(e_listarg), "matchaddpos()");
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 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
1266 if (l == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 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
1270 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 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
1272 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
1273 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 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
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[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
1277 && 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
1278 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 }
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 if (error == TRUE)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 // 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
1285 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
1286 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 semsg(_("E798: ID is reserved for \":match\": %d"), id);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 return;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 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
1292 conceal_char);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 }
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 * "matcharg()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 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
1301 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 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
1303 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 # 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
1305 int id;
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 matchitem_T *m;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307
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
1308 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
1309 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
1310
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
1311 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
1312 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
1313 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 if ((m = (matchitem_T *)get_match(curwin, id)) != NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 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
1317 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
1318 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
1319 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 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
1323 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
1324 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 # endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 * "matchdelete()" function
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 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
1335 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 # 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
1337 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
1338
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
1339 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
1340 && (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
1341 || 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
1342 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
1343
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
1344 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
1345 if (win == NULL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 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
1347 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 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
1349 (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
1350 # endif
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 #endif
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 #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
1355 /*
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 * ":[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
1357 * 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
1358 * 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
1359 */
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 void
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 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
1362 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 char_u *p;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 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
1365 char_u *end;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 int c;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 int id;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 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
1370 id = eap->line2;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21459
diff changeset
1373 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
1374 return;
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
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 // 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
1378 if (!eap->skip)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 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
1380
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 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
1382 end = eap->arg;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 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
1384 && (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
1385 || 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
1386 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
1387 else
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 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
1390 if (!eap->skip)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 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
1392 p = skipwhite(p);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 if (*p == NUL)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 // 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
1396 vim_free(g);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 semsg(_(e_invarg2), eap->arg);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 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
1401 if (!eap->skip)
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 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
1404 {
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 vim_free(g);
21459
a422bd80b434 patch 8.2.1280: Ex command error cannot contain an argument
Bram Moolenaar <Bram@vim.org>
parents: 21054
diff changeset
1406 eap->errmsg = ex_errmsg(e_trailing_arg, end);
21054
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 if (*end != *p)
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 vim_free(g);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 semsg(_(e_invarg2), p);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 return;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 }
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 c = *end;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 *end = NUL;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 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
1419 vim_free(g);
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 *end = c;
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 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
1424 }
b1fac55cf8a3 patch 8.2.1078: highlight and match functionality together in one file
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 #endif