Mercurial > vim
annotate src/syntax.c @ 25315:cf45fde10bdb
Added tag v8.2.3194 for changeset 7e620652bd13fd4313bc3cb7d4d34ccd48166ec4
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 21 Jul 2021 19:15:04 +0200 |
parents | 078edc1821bf |
children | 2063b858cad9 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * syntax.c: code for syntax highlighting | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
17 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
18 #define SYN_NAMELEN 50 // maximum length of a syntax name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
19 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
20 // different types of offsets that are possible |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
21 #define SPO_MS_OFF 0 // match start offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
22 #define SPO_ME_OFF 1 // match end offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
23 #define SPO_HS_OFF 2 // highl. start offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
24 #define SPO_HE_OFF 3 // highl. end offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
25 #define SPO_RS_OFF 4 // region start offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
26 #define SPO_RE_OFF 5 // region end offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
27 #define SPO_LC_OFF 6 // leading context offset |
7 | 28 #define SPO_COUNT 7 |
29 | |
30 static char *(spo_name_tab[SPO_COUNT]) = | |
31 {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; | |
32 | |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
33 static char e_illegal_arg[] = N_("E390: Illegal argument: %s"); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
34 |
7 | 35 /* |
36 * The patterns that are being searched for are stored in a syn_pattern. | |
37 * A match item consists of one pattern. | |
38 * A start/end item consists of n start patterns and m end patterns. | |
39 * A start/skip/end item consists of n start patterns, one skip pattern and m | |
40 * end patterns. | |
41 * For the latter two, the patterns are always consecutive: start-skip-end. | |
42 * | |
43 * A character offset can be given for the matched text (_m_start and _m_end) | |
44 * and for the actually highlighted text (_h_start and _h_end). | |
13333
b4e7082de11d
patch 8.0.1541: synpat_T is taking too much memory
Christian Brabandt <cb@256bit.org>
parents:
13314
diff
changeset
|
45 * |
b4e7082de11d
patch 8.0.1541: synpat_T is taking too much memory
Christian Brabandt <cb@256bit.org>
parents:
13314
diff
changeset
|
46 * Note that ordering of members is optimized to reduce padding. |
7 | 47 */ |
48 typedef struct syn_pattern | |
49 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
50 char sp_type; // see SPTYPE_ defines below |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
51 char sp_syncing; // this item used for syncing |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
52 short sp_syn_match_id; // highlight group ID of pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
53 short sp_off_flags; // see below |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
54 int sp_offsets[SPO_COUNT]; // offsets |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
55 int sp_flags; // see HL_ defines below |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
56 #ifdef FEAT_CONCEAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
57 int sp_cchar; // conceal substitute character |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
58 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
59 int sp_ic; // ignore-case flag for sp_prog |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
60 int sp_sync_idx; // sync item index (syncing only) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
61 int sp_line_id; // ID of last line where tried |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
62 int sp_startcol; // next match in sp_line_id line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
63 short *sp_cont_list; // cont. group IDs, if non-zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
64 short *sp_next_list; // next group IDs, if non-zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
65 struct sp_syn sp_syn; // struct passed to in_id_list() |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
66 char_u *sp_pattern; // regexp to match, pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
67 regprog_T *sp_prog; // regexp to match, program |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
68 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
69 syn_time_T sp_time; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
70 #endif |
7 | 71 } synpat_T; |
72 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
73 // The sp_off_flags are computed like this: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
74 // offset from the start of the matched text: (1 << SPO_XX_OFF) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
75 // offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
76 // When both are present, only one is used. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
77 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
78 #define SPTYPE_MATCH 1 // match keyword with this group ID |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
79 #define SPTYPE_START 2 // match a regexp, start of item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
80 #define SPTYPE_END 3 // match a regexp, end of item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
81 #define SPTYPE_SKIP 4 // match a regexp, skip within item |
7 | 82 |
83 | |
84 #define SYN_ITEMS(buf) ((synpat_T *)((buf)->b_syn_patterns.ga_data)) | |
85 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
86 #define NONE_IDX -2 // value of sp_sync_idx for "NONE" |
7 | 87 |
88 /* | |
89 * Flags for b_syn_sync_flags: | |
90 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
91 #define SF_CCOMMENT 0x01 // sync on a C-style comment |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
92 #define SF_MATCH 0x02 // sync by matching a pattern |
7 | 93 |
94 #define SYN_STATE_P(ssp) ((bufstate_T *)((ssp)->ga_data)) | |
95 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
96 #define MAXKEYWLEN 80 // maximum length of a keyword |
7 | 97 |
98 /* | |
99 * The attributes of the syntax item that has been recognized. | |
100 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
101 static int current_attr = 0; // attr of current syntax word |
7 | 102 #ifdef FEAT_EVAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
103 static int current_id = 0; // ID of current char for syn_get_id() |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
104 static int current_trans_id = 0; // idem, transparency removed |
7 | 105 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
106 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
107 static int current_flags = 0; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
108 static int current_seqnr = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
109 static int current_sub_char = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
110 #endif |
7 | 111 |
221 | 112 typedef struct syn_cluster_S |
7 | 113 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
114 char_u *scl_name; // syntax cluster name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
115 char_u *scl_name_u; // uppercase of scl_name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
116 short *scl_list; // IDs in this syntax cluster |
221 | 117 } syn_cluster_T; |
7 | 118 |
119 /* | |
120 * Methods of combining two clusters | |
121 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
122 #define CLUSTER_REPLACE 1 // replace first list with second |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
123 #define CLUSTER_ADD 2 // add second list to first |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
124 #define CLUSTER_SUBTRACT 3 // subtract second list from first |
7 | 125 |
221 | 126 #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data)) |
7 | 127 |
128 /* | |
129 * Syntax group IDs have different types: | |
2743 | 130 * 0 - 19999 normal syntax groups |
131 * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) | |
132 * 21000 - 21999 TOP indicator (current_syn_inc_tag added) | |
133 * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) | |
134 * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) | |
135 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
136 #define SYNID_ALLBUT MAX_HL_ID // syntax group ID for contains=ALLBUT |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
137 #define SYNID_TOP 21000 // syntax group ID for contains=TOP |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
138 #define SYNID_CONTAINED 22000 // syntax group ID for contains=CONTAINED |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
139 #define SYNID_CLUSTER 23000 // first syntax group ID for clusters |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
140 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
141 #define MAX_SYN_INC_TAG 999 // maximum before the above overflow |
2743 | 142 #define MAX_CLUSTER_ID (32767 - SYNID_CLUSTER) |
7 | 143 |
144 /* | |
145 * Annoying Hack(TM): ":syn include" needs this pointer to pass to | |
146 * expand_filename(). Most of the other syntax commands don't need it, so | |
147 * instead of passing it to them, we stow it here. | |
148 */ | |
149 static char_u **syn_cmdlinep; | |
150 | |
151 /* | |
152 * Another Annoying Hack(TM): To prevent rules from other ":syn include"'d | |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
153 * files from leaking into ALLBUT lists, we assign a unique ID to the |
7 | 154 * rules in each ":syn include"'d file. |
155 */ | |
156 static int current_syn_inc_tag = 0; | |
157 static int running_syn_inc_tag = 0; | |
158 | |
159 /* | |
134 | 160 * In a hashtable item "hi_key" points to "keyword" in a keyentry. |
161 * This avoids adding a pointer to the hashtable item. | |
162 * KE2HIKEY() converts a var pointer to a hashitem key pointer. | |
163 * HIKEY2KE() converts a hashitem key pointer to a var pointer. | |
164 * HI2KE() converts a hashitem pointer to a var pointer. | |
165 */ | |
166 static keyentry_T dumkey; | |
167 #define KE2HIKEY(kp) ((kp)->keyword) | |
168 #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey))) | |
169 #define HI2KE(hi) HIKEY2KE((hi)->hi_key) | |
170 | |
171 /* | |
7 | 172 * To reduce the time spent in keepend(), remember at which level in the state |
173 * stack the first item with "keepend" is present. When "-1", there is no | |
174 * "keepend" on the stack. | |
175 */ | |
176 static int keepend_level = -1; | |
177 | |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
178 static char msg_no_items[] = N_("No Syntax items defined for this buffer"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
179 |
7 | 180 /* |
181 * For the current state we need to remember more than just the idx. | |
182 * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. | |
183 * (The end positions have the column number of the next char) | |
184 */ | |
185 typedef struct state_item | |
186 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
187 int si_idx; // index of syntax pattern or |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
188 // KEYWORD_IDX |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
189 int si_id; // highlight group ID for keywords |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
190 int si_trans_id; // idem, transparency removed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
191 int si_m_lnum; // lnum of the match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
192 int si_m_startcol; // starting column of the match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
193 lpos_T si_m_endpos; // just after end posn of the match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
194 lpos_T si_h_startpos; // start position of the highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
195 lpos_T si_h_endpos; // end position of the highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
196 lpos_T si_eoe_pos; // end position of end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
197 int si_end_idx; // group ID for end pattern or zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
198 int si_ends; // if match ends before si_m_endpos |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
199 int si_attr; // attributes in this state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
200 long si_flags; // HL_HAS_EOL flag in this state, and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
201 // HL_SKIP* for si_next_list |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
202 #ifdef FEAT_CONCEAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
203 int si_seqnr; // sequence number |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
204 int si_cchar; // substitution character for conceal |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
205 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
206 short *si_cont_list; // list of contained groups |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
207 short *si_next_list; // nextgroup IDs after this item ends |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
208 reg_extmatch_T *si_extmatch; // \z(...\) matches from start |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
209 // pattern |
7 | 210 } stateitem_T; |
211 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
212 #define KEYWORD_IDX -1 // value of si_idx for keywords |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
213 #define ID_LIST_ALL (short *)-1 // valid of si_cont_list for containing all |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
214 // but contained groups |
7 | 215 |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
216 #ifdef FEAT_CONCEAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
217 static int next_seqnr = 1; // value to use for si_seqnr |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
218 #endif |
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
219 |
7 | 220 /* |
154 | 221 * Struct to reduce the number of arguments to get_syn_options(), it's used |
222 * very often. | |
223 */ | |
224 typedef struct | |
225 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
226 int flags; // flags for contained and transparent |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
227 int keyword; // TRUE for ":syn keyword" |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
228 int *sync_idx; // syntax item for "grouphere" argument, NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
229 // if not allowed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
230 char has_cont_list; // TRUE if "cont_list" can be used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
231 short *cont_list; // group IDs for "contains" argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
232 short *cont_in_list; // group IDs for "containedin" argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
233 short *next_list; // group IDs for "nextgroup" argument |
154 | 234 } syn_opt_arg_T; |
235 | |
236 /* | |
7 | 237 * The next possible match in the current line for any pattern is remembered, |
238 * to avoid having to try for a match in each column. | |
239 * If next_match_idx == -1, not tried (in this line) yet. | |
240 * If next_match_col == MAXCOL, no match found in this line. | |
241 * (All end positions have the column of the char after the end) | |
242 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
243 static int next_match_col; // column for start of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
244 static lpos_T next_match_m_endpos; // position for end of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
245 static lpos_T next_match_h_startpos; // pos. for highl. start of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
246 static lpos_T next_match_h_endpos; // pos. for highl. end of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
247 static int next_match_idx; // index of matched item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
248 static long next_match_flags; // flags for next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
249 static lpos_T next_match_eos_pos; // end of start pattn (start region) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
250 static lpos_T next_match_eoe_pos; // pos. for end of end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
251 static int next_match_end_idx; // ID of group for end pattn or zero |
7 | 252 static reg_extmatch_T *next_match_extmatch = NULL; |
253 | |
254 /* | |
255 * A state stack is an array of integers or stateitem_T, stored in a | |
14968
c5ec5ddbe814
patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
256 * garray_T. A state stack is invalid if its itemsize entry is zero. |
7 | 257 */ |
258 #define INVALID_STATE(ssp) ((ssp)->ga_itemsize == 0) | |
259 #define VALID_STATE(ssp) ((ssp)->ga_itemsize != 0) | |
260 | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
261 #define FOR_ALL_SYNSTATES(sb, sst) \ |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
262 for ((sst) = (sb)->b_sst_first; (sst) != NULL; (sst) = (sst)->sst_next) |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
263 |
7 | 264 /* |
265 * The current state (within the line) of the recognition engine. | |
266 * When current_state.ga_itemsize is 0 the current state is invalid. | |
267 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
268 static win_T *syn_win; // current window for highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
269 static buf_T *syn_buf; // current buffer for highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
270 static synblock_T *syn_block; // current buffer for highlighting |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
271 #ifdef FEAT_RELTIME |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
272 static proftime_T *syn_tm; // timeout limit |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
273 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
274 static linenr_T current_lnum = 0; // lnum of current state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
275 static colnr_T current_col = 0; // column of current state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
276 static int current_state_stored = 0; // TRUE if stored current state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
277 // after setting current_finished |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
278 static int current_finished = 0; // current line has been finished |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
279 static garray_T current_state // current stack of state_items |
7 | 280 = {0, 0, 0, 0, NULL}; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
281 static short *current_next_list = NULL; // when non-zero, nextgroup list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
282 static int current_next_flags = 0; // flags for current_next_list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
283 static int current_line_id = 0; // unique number for current line |
7 | 284 |
285 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] | |
286 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
287 static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
288 static int syn_match_linecont(linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
289 static void syn_start_line(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
290 static void syn_update_ends(int startofline); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
291 static void syn_stack_alloc(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
292 static int syn_stack_cleanup(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
293 static void syn_stack_free_entry(synblock_T *block, synstate_T *p); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
294 static synstate_T *syn_stack_find_entry(linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
295 static synstate_T *store_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
296 static void load_current_state(synstate_T *from); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
297 static void invalidate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
298 static int syn_stack_equal(synstate_T *sp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
299 static void validate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
300 static int syn_finish_line(int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
301 static int syn_current_attr(int syncing, int displaying, int *can_spell, int keep_state); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
302 static int did_match_already(int idx, garray_T *gap); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
303 static stateitem_T *push_next_match(stateitem_T *cur_si); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
304 static void check_state_ends(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
305 static void update_si_attr(int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
306 static void check_keepend(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
307 static void update_si_end(stateitem_T *sip, int startcol, int force); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
308 static short *copy_id_list(short *list); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
309 static int in_id_list(stateitem_T *item, short *cont_list, struct sp_syn *ssp, int contained); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
310 static int push_current_state(int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
311 static void pop_current_state(void); |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
312 #ifdef FEAT_PROFILE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
313 static void syn_clear_time(syn_time_T *tt); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
314 static void syntime_clear(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
315 static void syntime_report(void); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
316 static int syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
317 # define IF_SYN_TIME(p) (p) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
318 #else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
319 # define IF_SYN_TIME(p) NULL |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
320 typedef int syn_time_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
321 #endif |
7 | 322 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
323 static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
324 static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, long *flagsp, lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
325 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
326 static void limit_pos(lpos_T *pos, lpos_T *limit); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
327 static void limit_pos_zero(lpos_T *pos, lpos_T *limit); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
328 static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp, int idx, int extra); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
329 static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp, int idx, int extra); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
330 static char_u *syn_getcurline(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
331 static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T *st); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
332 static int check_keyword_id(char_u *line, int startcol, int *endcol, long *flags, short **next_list, stateitem_T *cur_si, int *ccharp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
333 static void syn_remove_pattern(synblock_T *block, int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
334 static void syn_clear_pattern(synblock_T *block, int i); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
335 static void syn_clear_cluster(synblock_T *block, int i); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
336 static void syn_clear_one(int id, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
337 static void syn_cmd_onoff(exarg_T *eap, char *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
338 static void syn_lines_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
339 static void syn_match_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
340 static void syn_list_one(int id, int syncing, int link_only); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
341 static void syn_list_cluster(int id); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
342 static void put_id_list(char_u *name, short *list, int attr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
343 static void put_pattern(char *s, int c, synpat_T *spp, int attr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
344 static int syn_list_keywords(int id, hashtab_T *ht, int did_header, int attr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
345 static void syn_clear_keyword(int id, hashtab_T *ht); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
346 static void clear_keywtab(hashtab_T *ht); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
347 static int syn_scl_namen2id(char_u *linep, int len); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
348 static int syn_check_cluster(char_u *pp, int len); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
349 static int syn_add_cluster(char_u *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
350 static void init_syn_patterns(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
351 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
352 static int get_id_list(char_u **arg, int keylen, short **list, int skip); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
353 static void syn_combine_list(short **clstr1, short **clstr2, int list_op); |
7 | 354 |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
355 #if defined(FEAT_RELTIME) || defined(PROTO) |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
356 /* |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
357 * Set the timeout used for syntax highlighting. |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
358 * Use NULL to reset, no timeout. |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
359 */ |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
360 void |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
361 syn_set_timeout(proftime_T *tm) |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
362 { |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
363 syn_tm = tm; |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
364 } |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
365 #endif |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
366 |
7 | 367 /* |
368 * Start the syntax recognition for a line. This function is normally called | |
369 * from the screen updating, once for each displayed line. | |
370 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get | |
371 * it. Careful: curbuf and curwin are likely to point to another buffer and | |
372 * window. | |
373 */ | |
374 void | |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
375 syntax_start(win_T *wp, linenr_T lnum) |
7 | 376 { |
377 synstate_T *p; | |
378 synstate_T *last_valid = NULL; | |
379 synstate_T *last_min_valid = NULL; | |
1512 | 380 synstate_T *sp, *prev = NULL; |
7 | 381 linenr_T parsed_lnum; |
382 linenr_T first_stored; | |
383 int dist; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
384 static varnumber_T changedtick = 0; // remember the last change ID |
7 | 385 |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
386 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
387 current_sub_char = NUL; |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
388 #endif |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
389 |
7 | 390 /* |
391 * After switching buffers, invalidate current_state. | |
26 | 392 * Also do this when a change was made, the current state may be invalid |
393 * then. | |
7 | 394 */ |
8806
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
395 if (syn_block != wp->w_s |
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
396 || syn_buf != wp->w_buffer |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
397 || changedtick != CHANGEDTICK(syn_buf)) |
7 | 398 { |
399 invalidate_current_state(); | |
400 syn_buf = wp->w_buffer; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
401 syn_block = wp->w_s; |
7 | 402 } |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
403 changedtick = CHANGEDTICK(syn_buf); |
7 | 404 syn_win = wp; |
405 | |
406 /* | |
407 * Allocate syntax stack when needed. | |
408 */ | |
409 syn_stack_alloc(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
410 if (syn_block->b_sst_array == NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
411 return; // out of memory |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
412 syn_block->b_sst_lasttick = display_tick; |
7 | 413 |
414 /* | |
415 * If the state of the end of the previous line is useful, store it. | |
416 */ | |
417 if (VALID_STATE(¤t_state) | |
418 && current_lnum < lnum | |
419 && current_lnum < syn_buf->b_ml.ml_line_count) | |
420 { | |
421 (void)syn_finish_line(FALSE); | |
422 if (!current_state_stored) | |
423 { | |
424 ++current_lnum; | |
1512 | 425 (void)store_current_state(); |
7 | 426 } |
427 | |
428 /* | |
429 * If the current_lnum is now the same as "lnum", keep the current | |
430 * state (this happens very often!). Otherwise invalidate | |
431 * current_state and figure it out below. | |
432 */ | |
433 if (current_lnum != lnum) | |
434 invalidate_current_state(); | |
435 } | |
436 else | |
437 invalidate_current_state(); | |
438 | |
439 /* | |
440 * Try to synchronize from a saved state in b_sst_array[]. | |
441 * Only do this if lnum is not before and not to far beyond a saved state. | |
442 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
443 if (INVALID_STATE(¤t_state) && syn_block->b_sst_array != NULL) |
7 | 444 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
445 // Find last valid saved state before start_lnum. |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
446 FOR_ALL_SYNSTATES(syn_block, p) |
7 | 447 { |
448 if (p->sst_lnum > lnum) | |
449 break; | |
450 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0) | |
451 { | |
452 last_valid = p; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
453 if (p->sst_lnum >= lnum - syn_block->b_syn_sync_minlines) |
7 | 454 last_min_valid = p; |
455 } | |
456 } | |
457 if (last_min_valid != NULL) | |
458 load_current_state(last_min_valid); | |
459 } | |
460 | |
461 /* | |
462 * If "lnum" is before or far beyond a line with a saved state, need to | |
463 * re-synchronize. | |
464 */ | |
465 if (INVALID_STATE(¤t_state)) | |
466 { | |
467 syn_sync(wp, lnum, last_valid); | |
2906 | 468 if (current_lnum == 1) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
469 // First line is always valid, no matter "minlines". |
2906 | 470 first_stored = 1; |
471 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
472 // Need to parse "minlines" lines before state can be considered |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
473 // valid to store. |
2906 | 474 first_stored = current_lnum + syn_block->b_syn_sync_minlines; |
7 | 475 } |
476 else | |
477 first_stored = current_lnum; | |
478 | |
479 /* | |
480 * Advance from the sync point or saved state until the current line. | |
481 * Save some entries for syncing with later on. | |
482 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
483 if (syn_block->b_sst_len <= Rows) |
819 | 484 dist = 999999; |
485 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
486 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 487 while (current_lnum < lnum) |
488 { | |
489 syn_start_line(); | |
490 (void)syn_finish_line(FALSE); | |
491 ++current_lnum; | |
492 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
493 // If we parsed at least "minlines" lines or started at a valid |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
494 // state, the current state is considered valid. |
7 | 495 if (current_lnum >= first_stored) |
496 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
497 // Check if the saved state entry is for the current line and is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
498 // equal to the current state. If so, then validate all saved |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
499 // states that depended on a change before the parsed line. |
7 | 500 if (prev == NULL) |
1512 | 501 prev = syn_stack_find_entry(current_lnum - 1); |
502 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
503 sp = syn_block->b_sst_first; |
7 | 504 else |
1512 | 505 sp = prev; |
506 while (sp != NULL && sp->sst_lnum < current_lnum) | |
507 sp = sp->sst_next; | |
7 | 508 if (sp != NULL |
509 && sp->sst_lnum == current_lnum | |
510 && syn_stack_equal(sp)) | |
511 { | |
512 parsed_lnum = current_lnum; | |
513 prev = sp; | |
514 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) | |
515 { | |
516 if (sp->sst_lnum <= lnum) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
517 // valid state before desired line, use this one |
7 | 518 prev = sp; |
519 else if (sp->sst_change_lnum == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
520 // past saved states depending on change, break here. |
7 | 521 break; |
522 sp->sst_change_lnum = 0; | |
523 sp = sp->sst_next; | |
524 } | |
525 load_current_state(prev); | |
526 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
527 // Store the state at this line when it's the first one, the line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
528 // where we start parsing, or some distance from the previously |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
529 // saved state. But only when parsed at least 'minlines'. |
7 | 530 else if (prev == NULL |
531 || current_lnum == lnum | |
532 || current_lnum >= prev->sst_lnum + dist) | |
1512 | 533 prev = store_current_state(); |
7 | 534 } |
535 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
536 // This can take a long time: break when CTRL-C pressed. The current |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
537 // state will be wrong then. |
7 | 538 line_breakcheck(); |
539 if (got_int) | |
540 { | |
541 current_lnum = lnum; | |
542 break; | |
543 } | |
544 } | |
545 | |
546 syn_start_line(); | |
547 } | |
548 | |
549 /* | |
550 * We cannot simply discard growarrays full of state_items or buf_states; we | |
551 * have to manually release their extmatch pointers first. | |
552 */ | |
553 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
554 clear_syn_state(synstate_T *p) |
7 | 555 { |
556 int i; | |
557 garray_T *gap; | |
558 | |
559 if (p->sst_stacksize > SST_FIX_STATES) | |
560 { | |
561 gap = &(p->sst_union.sst_ga); | |
562 for (i = 0; i < gap->ga_len; i++) | |
563 unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch); | |
564 ga_clear(gap); | |
565 } | |
566 else | |
567 { | |
568 for (i = 0; i < p->sst_stacksize; i++) | |
569 unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch); | |
570 } | |
571 } | |
572 | |
573 /* | |
574 * Cleanup the current_state stack. | |
575 */ | |
576 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
577 clear_current_state(void) |
7 | 578 { |
579 int i; | |
580 stateitem_T *sip; | |
581 | |
582 sip = (stateitem_T *)(current_state.ga_data); | |
583 for (i = 0; i < current_state.ga_len; i++) | |
584 unref_extmatch(sip[i].si_extmatch); | |
585 ga_clear(¤t_state); | |
586 } | |
587 | |
588 /* | |
589 * Try to find a synchronisation point for line "lnum". | |
590 * | |
591 * This sets current_lnum and the current state. One of three methods is | |
592 * used: | |
593 * 1. Search backwards for the end of a C-comment. | |
594 * 2. Search backwards for given sync patterns. | |
595 * 3. Simply start on a given number of lines above "lnum". | |
596 */ | |
597 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
598 syn_sync( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
599 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
600 linenr_T start_lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
601 synstate_T *last_valid) |
7 | 602 { |
603 buf_T *curbuf_save; | |
604 win_T *curwin_save; | |
605 pos_T cursor_save; | |
606 int idx; | |
607 linenr_T lnum; | |
608 linenr_T end_lnum; | |
609 linenr_T break_lnum; | |
610 int had_sync_point; | |
611 stateitem_T *cur_si; | |
612 synpat_T *spp; | |
613 char_u *line; | |
614 int found_flags = 0; | |
615 int found_match_idx = 0; | |
616 linenr_T found_current_lnum = 0; | |
617 int found_current_col= 0; | |
618 lpos_T found_m_endpos; | |
442 | 619 colnr_T prev_current_col; |
7 | 620 |
621 /* | |
622 * Clear any current state that might be hanging around. | |
623 */ | |
624 invalidate_current_state(); | |
625 | |
626 /* | |
627 * Start at least "minlines" back. Default starting point for parsing is | |
628 * there. | |
629 * Start further back, to avoid that scrolling backwards will result in | |
630 * resyncing for every line. Now it resyncs only one out of N lines, | |
631 * where N is minlines * 1.5, or minlines * 2 if minlines is small. | |
632 * Watch out for overflow when minlines is MAXLNUM. | |
633 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
634 if (syn_block->b_syn_sync_minlines > start_lnum) |
7 | 635 start_lnum = 1; |
636 else | |
637 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
638 if (syn_block->b_syn_sync_minlines == 1) |
7 | 639 lnum = 1; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
640 else if (syn_block->b_syn_sync_minlines < 10) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
641 lnum = syn_block->b_syn_sync_minlines * 2; |
7 | 642 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
643 lnum = syn_block->b_syn_sync_minlines * 3 / 2; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
644 if (syn_block->b_syn_sync_maxlines != 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
645 && lnum > syn_block->b_syn_sync_maxlines) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
646 lnum = syn_block->b_syn_sync_maxlines; |
7 | 647 if (lnum >= start_lnum) |
648 start_lnum = 1; | |
649 else | |
650 start_lnum -= lnum; | |
651 } | |
652 current_lnum = start_lnum; | |
653 | |
654 /* | |
655 * 1. Search backwards for the end of a C-style comment. | |
656 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
657 if (syn_block->b_syn_sync_flags & SF_CCOMMENT) |
7 | 658 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
659 // Need to make syn_buf the current buffer for a moment, to be able to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
660 // use find_start_comment(). |
7 | 661 curwin_save = curwin; |
662 curwin = wp; | |
663 curbuf_save = curbuf; | |
664 curbuf = syn_buf; | |
665 | |
666 /* | |
667 * Skip lines that end in a backslash. | |
668 */ | |
669 for ( ; start_lnum > 1; --start_lnum) | |
670 { | |
671 line = ml_get(start_lnum - 1); | |
672 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') | |
673 break; | |
674 } | |
675 current_lnum = start_lnum; | |
676 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
677 // set cursor to start of search |
7 | 678 cursor_save = wp->w_cursor; |
679 wp->w_cursor.lnum = start_lnum; | |
680 wp->w_cursor.col = 0; | |
681 | |
682 /* | |
683 * If the line is inside a comment, need to find the syntax item that | |
684 * defines the comment. | |
685 * Restrict the search for the end of a comment to b_syn_sync_maxlines. | |
686 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
687 if (find_start_comment((int)syn_block->b_syn_sync_maxlines) != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
688 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
689 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
690 if (SYN_ITEMS(syn_block)[idx].sp_syn.id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
691 == syn_block->b_syn_sync_id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
692 && SYN_ITEMS(syn_block)[idx].sp_type == SPTYPE_START) |
7 | 693 { |
694 validate_current_state(); | |
695 if (push_current_state(idx) == OK) | |
696 update_si_attr(current_state.ga_len - 1); | |
697 break; | |
698 } | |
699 } | |
700 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
701 // restore cursor and buffer |
7 | 702 wp->w_cursor = cursor_save; |
703 curwin = curwin_save; | |
704 curbuf = curbuf_save; | |
705 } | |
706 | |
707 /* | |
708 * 2. Search backwards for given sync patterns. | |
709 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
710 else if (syn_block->b_syn_sync_flags & SF_MATCH) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
711 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
712 if (syn_block->b_syn_sync_maxlines != 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
713 && start_lnum > syn_block->b_syn_sync_maxlines) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
714 break_lnum = start_lnum - syn_block->b_syn_sync_maxlines; |
7 | 715 else |
716 break_lnum = 0; | |
717 | |
699 | 718 found_m_endpos.lnum = 0; |
719 found_m_endpos.col = 0; | |
7 | 720 end_lnum = start_lnum; |
721 lnum = start_lnum; | |
722 while (--lnum > break_lnum) | |
723 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
724 // This can take a long time: break when CTRL-C pressed. |
7 | 725 line_breakcheck(); |
726 if (got_int) | |
727 { | |
728 invalidate_current_state(); | |
729 current_lnum = start_lnum; | |
730 break; | |
731 } | |
732 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
733 // Check if we have run into a valid saved state stack now. |
7 | 734 if (last_valid != NULL && lnum == last_valid->sst_lnum) |
735 { | |
736 load_current_state(last_valid); | |
737 break; | |
738 } | |
739 | |
740 /* | |
741 * Check if the previous line has the line-continuation pattern. | |
742 */ | |
743 if (lnum > 1 && syn_match_linecont(lnum - 1)) | |
744 continue; | |
745 | |
746 /* | |
747 * Start with nothing on the state stack | |
748 */ | |
749 validate_current_state(); | |
750 | |
751 for (current_lnum = lnum; current_lnum < end_lnum; ++current_lnum) | |
752 { | |
753 syn_start_line(); | |
754 for (;;) | |
755 { | |
756 had_sync_point = syn_finish_line(TRUE); | |
757 /* | |
758 * When a sync point has been found, remember where, and | |
759 * continue to look for another one, further on in the line. | |
760 */ | |
761 if (had_sync_point && current_state.ga_len) | |
762 { | |
763 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
764 if (cur_si->si_m_endpos.lnum > start_lnum) | |
765 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
766 // ignore match that goes to after where started |
7 | 767 current_lnum = end_lnum; |
768 break; | |
769 } | |
1371 | 770 if (cur_si->si_idx < 0) |
771 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
772 // Cannot happen? |
1371 | 773 found_flags = 0; |
774 found_match_idx = KEYWORD_IDX; | |
775 } | |
776 else | |
777 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
778 spp = &(SYN_ITEMS(syn_block)[cur_si->si_idx]); |
1371 | 779 found_flags = spp->sp_flags; |
780 found_match_idx = spp->sp_sync_idx; | |
781 } | |
7 | 782 found_current_lnum = current_lnum; |
783 found_current_col = current_col; | |
784 found_m_endpos = cur_si->si_m_endpos; | |
785 /* | |
786 * Continue after the match (be aware of a zero-length | |
787 * match). | |
788 */ | |
789 if (found_m_endpos.lnum > current_lnum) | |
790 { | |
791 current_lnum = found_m_endpos.lnum; | |
792 current_col = found_m_endpos.col; | |
793 if (current_lnum >= end_lnum) | |
794 break; | |
795 } | |
796 else if (found_m_endpos.col > current_col) | |
797 current_col = found_m_endpos.col; | |
798 else | |
799 ++current_col; | |
800 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
801 // syn_current_attr() will have skipped the check for |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
802 // an item that ends here, need to do that now. Be |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
803 // careful not to go past the NUL. |
442 | 804 prev_current_col = current_col; |
805 if (syn_getcurline()[current_col] != NUL) | |
806 ++current_col; | |
7 | 807 check_state_ends(); |
442 | 808 current_col = prev_current_col; |
7 | 809 } |
810 else | |
811 break; | |
812 } | |
813 } | |
814 | |
815 /* | |
816 * If a sync point was encountered, break here. | |
817 */ | |
818 if (found_flags) | |
819 { | |
820 /* | |
821 * Put the item that was specified by the sync point on the | |
822 * state stack. If there was no item specified, make the | |
823 * state stack empty. | |
824 */ | |
825 clear_current_state(); | |
826 if (found_match_idx >= 0 | |
827 && push_current_state(found_match_idx) == OK) | |
828 update_si_attr(current_state.ga_len - 1); | |
829 | |
830 /* | |
831 * When using "grouphere", continue from the sync point | |
832 * match, until the end of the line. Parsing starts at | |
833 * the next line. | |
834 * For "groupthere" the parsing starts at start_lnum. | |
835 */ | |
836 if (found_flags & HL_SYNC_HERE) | |
837 { | |
838 if (current_state.ga_len) | |
839 { | |
840 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
841 cur_si->si_h_startpos.lnum = found_current_lnum; | |
842 cur_si->si_h_startpos.col = found_current_col; | |
843 update_si_end(cur_si, (int)current_col, TRUE); | |
844 check_keepend(); | |
845 } | |
846 current_col = found_m_endpos.col; | |
847 current_lnum = found_m_endpos.lnum; | |
848 (void)syn_finish_line(FALSE); | |
849 ++current_lnum; | |
850 } | |
851 else | |
852 current_lnum = start_lnum; | |
853 | |
854 break; | |
855 } | |
856 | |
857 end_lnum = lnum; | |
858 invalidate_current_state(); | |
859 } | |
860 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
861 // Ran into start of the file or exceeded maximum number of lines |
7 | 862 if (lnum <= break_lnum) |
863 { | |
864 invalidate_current_state(); | |
865 current_lnum = break_lnum + 1; | |
866 } | |
867 } | |
868 | |
869 validate_current_state(); | |
870 } | |
871 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
872 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
873 save_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
874 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
875 if (syn_block->b_syn_isk != empty_option) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
876 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
877 mch_memmove(chartab, syn_buf->b_chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
878 mch_memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
879 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
880 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
881 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
882 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
883 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
884 restore_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
885 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
886 if (syn_win->w_s->b_syn_isk != empty_option) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
887 mch_memmove(syn_buf->b_chartab, chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
888 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
889 |
7 | 890 /* |
891 * Return TRUE if the line-continuation pattern matches in line "lnum". | |
892 */ | |
893 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
894 syn_match_linecont(linenr_T lnum) |
7 | 895 { |
896 regmmatch_T regmatch; | |
6375 | 897 int r; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
898 char_u buf_chartab[32]; // chartab array for syn iskyeyword |
7 | 899 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
900 if (syn_block->b_syn_linecont_prog != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
901 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
902 // use syntax iskeyword option |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
903 save_chartab(buf_chartab); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
904 regmatch.rmm_ic = syn_block->b_syn_linecont_ic; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
905 regmatch.regprog = syn_block->b_syn_linecont_prog; |
6375 | 906 r = syn_regexec(®match, lnum, (colnr_T)0, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
907 IF_SYN_TIME(&syn_block->b_syn_linecont_time)); |
6375 | 908 syn_block->b_syn_linecont_prog = regmatch.regprog; |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
909 restore_chartab(buf_chartab); |
6375 | 910 return r; |
7 | 911 } |
912 return FALSE; | |
913 } | |
914 | |
915 /* | |
916 * Prepare the current state for the start of a line. | |
917 */ | |
918 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
919 syn_start_line(void) |
7 | 920 { |
921 current_finished = FALSE; | |
922 current_col = 0; | |
923 | |
924 /* | |
925 * Need to update the end of a start/skip/end that continues from the | |
926 * previous line and regions that have "keepend". | |
927 */ | |
928 if (current_state.ga_len > 0) | |
2863 | 929 { |
7 | 930 syn_update_ends(TRUE); |
2863 | 931 check_state_ends(); |
932 } | |
7 | 933 |
934 next_match_idx = -1; | |
935 ++current_line_id; | |
11581
2298fda621d3
patch 8.0.0673: build failure without conceal feature
Christian Brabandt <cb@256bit.org>
parents:
11579
diff
changeset
|
936 #ifdef FEAT_CONCEAL |
11579
52e3a77c097b
patch 8.0.0672: third item of synconcealed() changes too often
Christian Brabandt <cb@256bit.org>
parents:
11541
diff
changeset
|
937 next_seqnr = 1; |
11581
2298fda621d3
patch 8.0.0673: build failure without conceal feature
Christian Brabandt <cb@256bit.org>
parents:
11579
diff
changeset
|
938 #endif |
7 | 939 } |
940 | |
941 /* | |
942 * Check for items in the stack that need their end updated. | |
943 * When "startofline" is TRUE the last item is always updated. | |
944 * When "startofline" is FALSE the item with "keepend" is forcefully updated. | |
945 */ | |
946 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
947 syn_update_ends(int startofline) |
7 | 948 { |
949 stateitem_T *cur_si; | |
950 int i; | |
991 | 951 int seen_keepend; |
7 | 952 |
953 if (startofline) | |
954 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
955 // Check for a match carried over from a previous line with a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
956 // contained region. The match ends as soon as the region ends. |
7 | 957 for (i = 0; i < current_state.ga_len; ++i) |
958 { | |
959 cur_si = &CUR_STATE(i); | |
960 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
961 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type |
7 | 962 == SPTYPE_MATCH |
963 && cur_si->si_m_endpos.lnum < current_lnum) | |
964 { | |
965 cur_si->si_flags |= HL_MATCHCONT; | |
966 cur_si->si_m_endpos.lnum = 0; | |
967 cur_si->si_m_endpos.col = 0; | |
968 cur_si->si_h_endpos = cur_si->si_m_endpos; | |
969 cur_si->si_ends = TRUE; | |
970 } | |
971 } | |
972 } | |
973 | |
974 /* | |
975 * Need to update the end of a start/skip/end that continues from the | |
976 * previous line. And regions that have "keepend", because they may | |
991 | 977 * influence contained items. If we've just removed "extend" |
978 * (startofline == 0) then we should update ends of normal regions | |
979 * contained inside "keepend" because "extend" could have extended | |
980 * these "keepend" regions as well as contained normal regions. | |
7 | 981 * Then check for items ending in column 0. |
982 */ | |
983 i = current_state.ga_len - 1; | |
984 if (keepend_level >= 0) | |
985 for ( ; i > keepend_level; --i) | |
986 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
987 break; | |
991 | 988 |
989 seen_keepend = FALSE; | |
7 | 990 for ( ; i < current_state.ga_len; ++i) |
991 { | |
992 cur_si = &CUR_STATE(i); | |
993 if ((cur_si->si_flags & HL_KEEPEND) | |
991 | 994 || (seen_keepend && !startofline) |
7 | 995 || (i == current_state.ga_len - 1 && startofline)) |
996 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
997 cur_si->si_h_startpos.col = 0; // start highl. in col 0 |
7 | 998 cur_si->si_h_startpos.lnum = current_lnum; |
999 | |
1000 if (!(cur_si->si_flags & HL_MATCHCONT)) | |
1001 update_si_end(cur_si, (int)current_col, !startofline); | |
991 | 1002 |
1003 if (!startofline && (cur_si->si_flags & HL_KEEPEND)) | |
1004 seen_keepend = TRUE; | |
7 | 1005 } |
1006 } | |
1007 check_keepend(); | |
1008 } | |
1009 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1010 ///////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1011 // Handling of the state stack cache. |
7 | 1012 |
1013 /* | |
1014 * EXPLANATION OF THE SYNTAX STATE STACK CACHE | |
1015 * | |
1016 * To speed up syntax highlighting, the state stack for the start of some | |
1017 * lines is cached. These entries can be used to start parsing at that point. | |
1018 * | |
1019 * The stack is kept in b_sst_array[] for each buffer. There is a list of | |
1020 * valid entries. b_sst_first points to the first one, then follow sst_next. | |
1021 * The entries are sorted on line number. The first entry is often for line 2 | |
1022 * (line 1 always starts with an empty stack). | |
1023 * There is also a list for free entries. This construction is used to avoid | |
1024 * having to allocate and free memory blocks too often. | |
1025 * | |
1026 * When making changes to the buffer, this is logged in b_mod_*. When calling | |
1027 * update_screen() to update the display, it will call | |
1028 * syn_stack_apply_changes() for each displayed buffer to adjust the cached | |
1029 * entries. The entries which are inside the changed area are removed, | |
1030 * because they must be recomputed. Entries below the changed have their line | |
1031 * number adjusted for deleted/inserted lines, and have their sst_change_lnum | |
1032 * set to indicate that a check must be made if the changed lines would change | |
1033 * the cached entry. | |
1034 * | |
1035 * When later displaying lines, an entry is stored for each line. Displayed | |
1036 * lines are likely to be displayed again, in which case the state at the | |
1037 * start of the line is needed. | |
1038 * For not displayed lines, an entry is stored for every so many lines. These | |
1039 * entries will be used e.g., when scrolling backwards. The distance between | |
1040 * entries depends on the number of lines in the buffer. For small buffers | |
1041 * the distance is fixed at SST_DIST, for large buffers there is a fixed | |
1042 * number of entries SST_MAX_ENTRIES, and the distance is computed. | |
1043 */ | |
1044 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1045 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1046 syn_stack_free_block(synblock_T *block) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1047 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1048 synstate_T *p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1049 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1050 if (block->b_sst_array != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1051 { |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
1052 FOR_ALL_SYNSTATES(block, p) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1053 clear_syn_state(p); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1054 VIM_CLEAR(block->b_sst_array); |
14850
85ef79b16181
patch 8.1.0437: may access freed memory when syntax HL times out
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
1055 block->b_sst_first = NULL; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1056 block->b_sst_len = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1057 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1058 } |
7 | 1059 /* |
1060 * Free b_sst_array[] for buffer "buf". | |
1061 * Used when syntax items changed to force resyncing everywhere. | |
1062 */ | |
1063 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1064 syn_stack_free_all(synblock_T *block) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1065 { |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1066 #ifdef FEAT_FOLDING |
7 | 1067 win_T *wp; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1068 #endif |
7 | 1069 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1070 syn_stack_free_block(block); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1071 |
7 | 1072 #ifdef FEAT_FOLDING |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1073 // When using "syntax" fold method, must update all folds. |
7 | 1074 FOR_ALL_WINDOWS(wp) |
1075 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1076 if (wp->w_s == block && foldmethodIsSyntax(wp)) |
7 | 1077 foldUpdateAll(wp); |
1078 } | |
1079 #endif | |
1080 } | |
1081 | |
1082 /* | |
1083 * Allocate the syntax state stack for syn_buf when needed. | |
1084 * If the number of entries in b_sst_array[] is much too big or a bit too | |
1085 * small, reallocate it. | |
1086 * Also used to allocate b_sst_array[] for the first time. | |
1087 */ | |
1088 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1089 syn_stack_alloc(void) |
7 | 1090 { |
1091 long len; | |
1092 synstate_T *to, *from; | |
1093 synstate_T *sstp; | |
1094 | |
1095 len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; | |
1096 if (len < SST_MIN_ENTRIES) | |
1097 len = SST_MIN_ENTRIES; | |
1098 else if (len > SST_MAX_ENTRIES) | |
1099 len = SST_MAX_ENTRIES; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1100 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) |
7 | 1101 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1102 // Allocate 50% too much, to avoid reallocating too often. |
7 | 1103 len = syn_buf->b_ml.ml_line_count; |
1104 len = (len + len / 2) / SST_DIST + Rows * 2; | |
1105 if (len < SST_MIN_ENTRIES) | |
1106 len = SST_MIN_ENTRIES; | |
1107 else if (len > SST_MAX_ENTRIES) | |
1108 len = SST_MAX_ENTRIES; | |
1109 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1110 if (syn_block->b_sst_array != NULL) |
7 | 1111 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1112 // When shrinking the array, cleanup the existing stack. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1113 // Make sure that all valid entries fit in the new array. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1114 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len |
7 | 1115 && syn_stack_cleanup()) |
1116 ; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1117 if (len < syn_block->b_sst_len - syn_block->b_sst_freecount + 2) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1118 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; |
7 | 1119 } |
1120 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
1121 sstp = ALLOC_CLEAR_MULT(synstate_T, len); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1122 if (sstp == NULL) // out of memory! |
7 | 1123 return; |
1124 | |
1125 to = sstp - 1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1126 if (syn_block->b_sst_array != NULL) |
7 | 1127 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1128 // Move the states from the old array to the new one. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1129 for (from = syn_block->b_sst_first; from != NULL; |
7 | 1130 from = from->sst_next) |
1131 { | |
1132 ++to; | |
1133 *to = *from; | |
1134 to->sst_next = to + 1; | |
1135 } | |
1136 } | |
1137 if (to != sstp - 1) | |
1138 { | |
1139 to->sst_next = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1140 syn_block->b_sst_first = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1141 syn_block->b_sst_freecount = len - (int)(to - sstp) - 1; |
7 | 1142 } |
1143 else | |
1144 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1145 syn_block->b_sst_first = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1146 syn_block->b_sst_freecount = len; |
7 | 1147 } |
1148 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1149 // Create the list of free entries. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1150 syn_block->b_sst_firstfree = to + 1; |
7 | 1151 while (++to < sstp + len) |
1152 to->sst_next = to + 1; | |
1153 (sstp + len - 1)->sst_next = NULL; | |
1154 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1155 vim_free(syn_block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1156 syn_block->b_sst_array = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1157 syn_block->b_sst_len = len; |
7 | 1158 } |
1159 } | |
1160 | |
1161 /* | |
1162 * Check for changes in a buffer to affect stored syntax states. Uses the | |
1163 * b_mod_* fields. | |
1164 * Called from update_screen(), before screen is being updated, once for each | |
1165 * displayed buffer. | |
1166 */ | |
1167 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1168 syn_stack_apply_changes(buf_T *buf) |
7 | 1169 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1170 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1171 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1172 syn_stack_apply_changes_block(&buf->b_s, buf); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1173 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1174 FOR_ALL_WINDOWS(wp) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1175 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1176 if ((wp->w_buffer == buf) && (wp->w_s != &buf->b_s)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1177 syn_stack_apply_changes_block(wp->w_s, buf); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1178 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1179 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1180 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1181 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1182 syn_stack_apply_changes_block(synblock_T *block, buf_T *buf) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1183 { |
7 | 1184 synstate_T *p, *prev, *np; |
1185 linenr_T n; | |
1186 | |
1187 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1188 for (p = block->b_sst_first; p != NULL; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1189 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1190 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) |
7 | 1191 { |
1192 n = p->sst_lnum + buf->b_mod_xlines; | |
1193 if (n <= buf->b_mod_bot) | |
1194 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1195 // this state is inside the changed area, remove it |
7 | 1196 np = p->sst_next; |
1197 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1198 block->b_sst_first = np; |
7 | 1199 else |
1200 prev->sst_next = np; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1201 syn_stack_free_entry(block, p); |
7 | 1202 p = np; |
1203 continue; | |
1204 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1205 // This state is below the changed area. Remember the line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1206 // that needs to be parsed before this entry can be made valid |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1207 // again. |
7 | 1208 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) |
1209 { | |
1210 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) | |
1211 p->sst_change_lnum += buf->b_mod_xlines; | |
1212 else | |
1213 p->sst_change_lnum = buf->b_mod_top; | |
1214 } | |
1215 if (p->sst_change_lnum == 0 | |
1216 || p->sst_change_lnum < buf->b_mod_bot) | |
1217 p->sst_change_lnum = buf->b_mod_bot; | |
1218 | |
1219 p->sst_lnum = n; | |
1220 } | |
1221 prev = p; | |
1222 p = p->sst_next; | |
1223 } | |
1224 } | |
1225 | |
1226 /* | |
1227 * Reduce the number of entries in the state stack for syn_buf. | |
1228 * Returns TRUE if at least one entry was freed. | |
1229 */ | |
1230 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1231 syn_stack_cleanup(void) |
7 | 1232 { |
1233 synstate_T *p, *prev; | |
1234 disptick_T tick; | |
1235 int above; | |
1236 int dist; | |
1237 int retval = FALSE; | |
1238 | |
14850
85ef79b16181
patch 8.1.0437: may access freed memory when syntax HL times out
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
1239 if (syn_block->b_sst_first == NULL) |
7 | 1240 return retval; |
1241 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1242 // Compute normal distance between non-displayed entries. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1243 if (syn_block->b_sst_len <= Rows) |
819 | 1244 dist = 999999; |
1245 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1246 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 1247 |
1248 /* | |
2020 | 1249 * Go through the list to find the "tick" for the oldest entry that can |
7 | 1250 * be removed. Set "above" when the "tick" for the oldest entry is above |
1251 * "b_sst_lasttick" (the display tick wraps around). | |
1252 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1253 tick = syn_block->b_sst_lasttick; |
7 | 1254 above = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1255 prev = syn_block->b_sst_first; |
7 | 1256 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1257 { | |
1258 if (prev->sst_lnum + dist > p->sst_lnum) | |
1259 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1260 if (p->sst_tick > syn_block->b_sst_lasttick) |
7 | 1261 { |
1262 if (!above || p->sst_tick < tick) | |
1263 tick = p->sst_tick; | |
1264 above = TRUE; | |
1265 } | |
1266 else if (!above && p->sst_tick < tick) | |
1267 tick = p->sst_tick; | |
1268 } | |
1269 } | |
1270 | |
1271 /* | |
1272 * Go through the list to make the entries for the oldest tick at an | |
1273 * interval of several lines. | |
1274 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1275 prev = syn_block->b_sst_first; |
7 | 1276 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1277 { | |
1278 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) | |
1279 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1280 // Move this entry from used list to free list |
7 | 1281 prev->sst_next = p->sst_next; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1282 syn_stack_free_entry(syn_block, p); |
7 | 1283 p = prev; |
1284 retval = TRUE; | |
1285 } | |
1286 } | |
1287 return retval; | |
1288 } | |
1289 | |
1290 /* | |
1291 * Free the allocated memory for a syn_state item. | |
1292 * Move the entry into the free list. | |
1293 */ | |
1294 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1295 syn_stack_free_entry(synblock_T *block, synstate_T *p) |
7 | 1296 { |
1297 clear_syn_state(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1298 p->sst_next = block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1299 block->b_sst_firstfree = p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1300 ++block->b_sst_freecount; |
7 | 1301 } |
1302 | |
1303 /* | |
1304 * Find an entry in the list of state stacks at or before "lnum". | |
1305 * Returns NULL when there is no entry or the first entry is after "lnum". | |
1306 */ | |
1307 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1308 syn_stack_find_entry(linenr_T lnum) |
7 | 1309 { |
1310 synstate_T *p, *prev; | |
1311 | |
1312 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1313 for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) |
7 | 1314 { |
1315 if (p->sst_lnum == lnum) | |
1316 return p; | |
1317 if (p->sst_lnum > lnum) | |
1318 break; | |
1319 } | |
1320 return prev; | |
1321 } | |
1322 | |
1323 /* | |
1324 * Try saving the current state in b_sst_array[]. | |
1325 * The current state must be valid for the start of the current_lnum line! | |
1326 */ | |
1327 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1328 store_current_state(void) |
7 | 1329 { |
1330 int i; | |
1331 synstate_T *p; | |
1332 bufstate_T *bp; | |
1333 stateitem_T *cur_si; | |
1512 | 1334 synstate_T *sp = syn_stack_find_entry(current_lnum); |
7 | 1335 |
1336 /* | |
1337 * If the current state contains a start or end pattern that continues | |
1338 * from the previous line, we can't use it. Don't store it then. | |
1339 */ | |
1340 for (i = current_state.ga_len - 1; i >= 0; --i) | |
1341 { | |
1342 cur_si = &CUR_STATE(i); | |
1343 if (cur_si->si_h_startpos.lnum >= current_lnum | |
1344 || cur_si->si_m_endpos.lnum >= current_lnum | |
1345 || cur_si->si_h_endpos.lnum >= current_lnum | |
1346 || (cur_si->si_end_idx | |
1347 && cur_si->si_eoe_pos.lnum >= current_lnum)) | |
1348 break; | |
1349 } | |
1350 if (i >= 0) | |
1351 { | |
1352 if (sp != NULL) | |
1353 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1354 // find "sp" in the list and remove it |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1355 if (syn_block->b_sst_first == sp) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1356 // it's the first entry |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1357 syn_block->b_sst_first = sp->sst_next; |
7 | 1358 else |
1359 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1360 // find the entry just before this one to adjust sst_next |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
1361 FOR_ALL_SYNSTATES(syn_block, p) |
7 | 1362 if (p->sst_next == sp) |
1363 break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1364 if (p != NULL) // just in case |
840 | 1365 p->sst_next = sp->sst_next; |
7 | 1366 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1367 syn_stack_free_entry(syn_block, sp); |
7 | 1368 sp = NULL; |
1369 } | |
1370 } | |
1371 else if (sp == NULL || sp->sst_lnum != current_lnum) | |
1372 { | |
1373 /* | |
1374 * Add a new entry | |
1375 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1376 // If no free items, cleanup the array first. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1377 if (syn_block->b_sst_freecount == 0) |
7 | 1378 { |
1379 (void)syn_stack_cleanup(); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1380 // "sp" may have been moved to the freelist now |
7 | 1381 sp = syn_stack_find_entry(current_lnum); |
1382 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1383 // Still no free items? Must be a strange problem... |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1384 if (syn_block->b_sst_freecount == 0) |
7 | 1385 sp = NULL; |
1386 else | |
1387 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1388 // Take the first item from the free list and put it in the used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1389 // list, after *sp |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1390 p = syn_block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1391 syn_block->b_sst_firstfree = p->sst_next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1392 --syn_block->b_sst_freecount; |
7 | 1393 if (sp == NULL) |
1394 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1395 // Insert in front of the list |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1396 p->sst_next = syn_block->b_sst_first; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1397 syn_block->b_sst_first = p; |
7 | 1398 } |
1399 else | |
1400 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1401 // insert in list after *sp |
7 | 1402 p->sst_next = sp->sst_next; |
1403 sp->sst_next = p; | |
1404 } | |
1405 sp = p; | |
1406 sp->sst_stacksize = 0; | |
1407 sp->sst_lnum = current_lnum; | |
1408 } | |
1409 } | |
1410 if (sp != NULL) | |
1411 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1412 // When overwriting an existing state stack, clear it first |
7 | 1413 clear_syn_state(sp); |
1414 sp->sst_stacksize = current_state.ga_len; | |
1415 if (current_state.ga_len > SST_FIX_STATES) | |
1416 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1417 // Need to clear it, might be something remaining from when the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1418 // length was less than SST_FIX_STATES. |
7 | 1419 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); |
1420 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) | |
1421 sp->sst_stacksize = 0; | |
1422 else | |
1423 sp->sst_union.sst_ga.ga_len = current_state.ga_len; | |
1424 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1425 } | |
1426 else | |
1427 bp = sp->sst_union.sst_stack; | |
1428 for (i = 0; i < sp->sst_stacksize; ++i) | |
1429 { | |
1430 bp[i].bs_idx = CUR_STATE(i).si_idx; | |
1431 bp[i].bs_flags = CUR_STATE(i).si_flags; | |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1432 #ifdef FEAT_CONCEAL |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1433 bp[i].bs_seqnr = CUR_STATE(i).si_seqnr; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1434 bp[i].bs_cchar = CUR_STATE(i).si_cchar; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1435 #endif |
7 | 1436 bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); |
1437 } | |
1438 sp->sst_next_flags = current_next_flags; | |
1439 sp->sst_next_list = current_next_list; | |
1440 sp->sst_tick = display_tick; | |
1441 sp->sst_change_lnum = 0; | |
1442 } | |
1443 current_state_stored = TRUE; | |
1444 return sp; | |
1445 } | |
1446 | |
1447 /* | |
1448 * Copy a state stack from "from" in b_sst_array[] to current_state; | |
1449 */ | |
1450 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1451 load_current_state(synstate_T *from) |
7 | 1452 { |
1453 int i; | |
1454 bufstate_T *bp; | |
1455 | |
1456 clear_current_state(); | |
1457 validate_current_state(); | |
1458 keepend_level = -1; | |
1459 if (from->sst_stacksize | |
1460 && ga_grow(¤t_state, from->sst_stacksize) != FAIL) | |
1461 { | |
1462 if (from->sst_stacksize > SST_FIX_STATES) | |
1463 bp = SYN_STATE_P(&(from->sst_union.sst_ga)); | |
1464 else | |
1465 bp = from->sst_union.sst_stack; | |
1466 for (i = 0; i < from->sst_stacksize; ++i) | |
1467 { | |
1468 CUR_STATE(i).si_idx = bp[i].bs_idx; | |
1469 CUR_STATE(i).si_flags = bp[i].bs_flags; | |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1470 #ifdef FEAT_CONCEAL |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1471 CUR_STATE(i).si_seqnr = bp[i].bs_seqnr; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1472 CUR_STATE(i).si_cchar = bp[i].bs_cchar; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1473 #endif |
7 | 1474 CUR_STATE(i).si_extmatch = ref_extmatch(bp[i].bs_extmatch); |
1475 if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) | |
1476 keepend_level = i; | |
1477 CUR_STATE(i).si_ends = FALSE; | |
1478 CUR_STATE(i).si_m_lnum = 0; | |
1479 if (CUR_STATE(i).si_idx >= 0) | |
1480 CUR_STATE(i).si_next_list = | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1481 (SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_next_list; |
7 | 1482 else |
1483 CUR_STATE(i).si_next_list = NULL; | |
1484 update_si_attr(i); | |
1485 } | |
1486 current_state.ga_len = from->sst_stacksize; | |
1487 } | |
1488 current_next_list = from->sst_next_list; | |
1489 current_next_flags = from->sst_next_flags; | |
1490 current_lnum = from->sst_lnum; | |
1491 } | |
1492 | |
1493 /* | |
1494 * Compare saved state stack "*sp" with the current state. | |
1495 * Return TRUE when they are equal. | |
1496 */ | |
1497 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1498 syn_stack_equal(synstate_T *sp) |
7 | 1499 { |
1500 int i, j; | |
1501 bufstate_T *bp; | |
1502 reg_extmatch_T *six, *bsx; | |
1503 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1504 // First a quick check if the stacks have the same size end nextlist. |
7 | 1505 if (sp->sst_stacksize == current_state.ga_len |
1506 && sp->sst_next_list == current_next_list) | |
1507 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1508 // Need to compare all states on both stacks. |
7 | 1509 if (sp->sst_stacksize > SST_FIX_STATES) |
1510 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1511 else | |
1512 bp = sp->sst_union.sst_stack; | |
1513 | |
1514 for (i = current_state.ga_len; --i >= 0; ) | |
1515 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1516 // If the item has another index the state is different. |
7 | 1517 if (bp[i].bs_idx != CUR_STATE(i).si_idx) |
1518 break; | |
1519 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) | |
1520 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1521 // When the extmatch pointers are different, the strings in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1522 // them can still be the same. Check if the extmatch |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1523 // references are equal. |
7 | 1524 bsx = bp[i].bs_extmatch; |
1525 six = CUR_STATE(i).si_extmatch; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1526 // If one of the extmatch pointers is NULL the states are |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1527 // different. |
7 | 1528 if (bsx == NULL || six == NULL) |
1529 break; | |
1530 for (j = 0; j < NSUBEXP; ++j) | |
1531 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1532 // Check each referenced match string. They must all be |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1533 // equal. |
7 | 1534 if (bsx->matches[j] != six->matches[j]) |
1535 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1536 // If the pointer is different it can still be the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1537 // same text. Compare the strings, ignore case when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1538 // the start item has the sp_ic flag set. |
7 | 1539 if (bsx->matches[j] == NULL |
1540 || six->matches[j] == NULL) | |
1541 break; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1542 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic |
7 | 1543 ? MB_STRICMP(bsx->matches[j], |
1544 six->matches[j]) != 0 | |
1545 : STRCMP(bsx->matches[j], six->matches[j]) != 0) | |
1546 break; | |
1547 } | |
1548 } | |
1549 if (j != NSUBEXP) | |
1550 break; | |
1551 } | |
1552 } | |
1553 if (i < 0) | |
1554 return TRUE; | |
1555 } | |
1556 return FALSE; | |
1557 } | |
1558 | |
1559 /* | |
1560 * We stop parsing syntax above line "lnum". If the stored state at or below | |
1561 * this line depended on a change before it, it now depends on the line below | |
1562 * the last parsed line. | |
1563 * The window looks like this: | |
1564 * line which changed | |
1565 * displayed line | |
1566 * displayed line | |
1567 * lnum -> line below window | |
1568 */ | |
1569 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1570 syntax_end_parsing(linenr_T lnum) |
7 | 1571 { |
1572 synstate_T *sp; | |
1573 | |
1574 sp = syn_stack_find_entry(lnum); | |
1575 if (sp != NULL && sp->sst_lnum < lnum) | |
1576 sp = sp->sst_next; | |
1577 | |
1578 if (sp != NULL && sp->sst_change_lnum != 0) | |
1579 sp->sst_change_lnum = lnum; | |
1580 } | |
1581 | |
1582 /* | |
1583 * End of handling of the state stack. | |
1584 ****************************************/ | |
1585 | |
1586 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1587 invalidate_current_state(void) |
7 | 1588 { |
1589 clear_current_state(); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1590 current_state.ga_itemsize = 0; // mark current_state invalid |
7 | 1591 current_next_list = NULL; |
1592 keepend_level = -1; | |
1593 } | |
1594 | |
1595 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1596 validate_current_state(void) |
7 | 1597 { |
1598 current_state.ga_itemsize = sizeof(stateitem_T); | |
1599 current_state.ga_growsize = 3; | |
1600 } | |
1601 | |
1602 /* | |
1603 * Return TRUE if the syntax at start of lnum changed since last time. | |
1604 * This will only be called just after get_syntax_attr() for the previous | |
1605 * line, to check if the next line needs to be redrawn too. | |
1606 */ | |
1607 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1608 syntax_check_changed(linenr_T lnum) |
7 | 1609 { |
1610 int retval = TRUE; | |
1611 synstate_T *sp; | |
1612 | |
1613 /* | |
1614 * Check the state stack when: | |
1615 * - lnum is just below the previously syntaxed line. | |
1616 * - lnum is not before the lines with saved states. | |
1617 * - lnum is not past the lines with saved states. | |
1618 * - lnum is at or before the last changed line. | |
1619 */ | |
1620 if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) | |
1621 { | |
1622 sp = syn_stack_find_entry(lnum); | |
1623 if (sp != NULL && sp->sst_lnum == lnum) | |
1624 { | |
1625 /* | |
1626 * finish the previous line (needed when not all of the line was | |
1627 * drawn) | |
1628 */ | |
1629 (void)syn_finish_line(FALSE); | |
1630 | |
1631 /* | |
1632 * Compare the current state with the previously saved state of | |
1633 * the line. | |
1634 */ | |
1635 if (syn_stack_equal(sp)) | |
1636 retval = FALSE; | |
1637 | |
1638 /* | |
1639 * Store the current state in b_sst_array[] for later use. | |
1640 */ | |
1641 ++current_lnum; | |
1512 | 1642 (void)store_current_state(); |
7 | 1643 } |
1644 } | |
1645 | |
1646 return retval; | |
1647 } | |
1648 | |
1649 /* | |
1650 * Finish the current line. | |
1651 * This doesn't return any attributes, it only gets the state at the end of | |
1652 * the line. It can start anywhere in the line, as long as the current state | |
1653 * is valid. | |
1654 */ | |
1655 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1656 syn_finish_line( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1657 int syncing) // called for syncing |
7 | 1658 { |
1659 stateitem_T *cur_si; | |
442 | 1660 colnr_T prev_current_col; |
7 | 1661 |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1662 while (!current_finished) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1663 { |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1664 (void)syn_current_attr(syncing, FALSE, NULL, FALSE); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1665 /* |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1666 * When syncing, and found some item, need to check the item. |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1667 */ |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1668 if (syncing && current_state.ga_len) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1669 { |
7 | 1670 /* |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1671 * Check for match with sync item. |
7 | 1672 */ |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1673 cur_si = &CUR_STATE(current_state.ga_len - 1); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1674 if (cur_si->si_idx >= 0 |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1675 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1676 & (HL_SYNC_HERE|HL_SYNC_THERE))) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1677 return TRUE; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1678 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1679 // syn_current_attr() will have skipped the check for an item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1680 // that ends here, need to do that now. Be careful not to go |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1681 // past the NUL. |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1682 prev_current_col = current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1683 if (syn_getcurline()[current_col] != NUL) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1684 ++current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1685 check_state_ends(); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1686 current_col = prev_current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1687 } |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1688 ++current_col; |
7 | 1689 } |
1690 return FALSE; | |
1691 } | |
1692 | |
1693 /* | |
1694 * Return highlight attributes for next character. | |
1695 * Must first call syntax_start() once for the line. | |
1696 * "col" is normally 0 for the first use in a line, and increments by one each | |
1697 * time. It's allowed to skip characters and to stop before the end of the | |
1698 * line. But only a "col" after a previously used column is allowed. | |
221 | 1699 * When "can_spell" is not NULL set it to TRUE when spell-checking should be |
1700 * done. | |
7 | 1701 */ |
1702 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1703 get_syntax_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1704 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1705 int *can_spell, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1706 int keep_state) // keep state of char at "col" |
7 | 1707 { |
1708 int attr = 0; | |
1709 | |
1363 | 1710 if (can_spell != NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1711 // Default: Only do spelling when there is no @Spell cluster or when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1712 // ":syn spell toplevel" was used. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1713 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1714 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1715 : (syn_block->b_syn_spell == SYNSPL_TOP); |
1363 | 1716 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1717 // check for out of memory situation |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1718 if (syn_block->b_sst_array == NULL) |
7 | 1719 return 0; |
1720 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1721 // After 'synmaxcol' the attribute is always zero. |
431 | 1722 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) |
419 | 1723 { |
1724 clear_current_state(); | |
1725 #ifdef FEAT_EVAL | |
1726 current_id = 0; | |
1727 current_trans_id = 0; | |
1728 #endif | |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1729 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1730 current_flags = 0; |
11579
52e3a77c097b
patch 8.0.0672: third item of synconcealed() changes too often
Christian Brabandt <cb@256bit.org>
parents:
11541
diff
changeset
|
1731 current_seqnr = 0; |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1732 #endif |
419 | 1733 return 0; |
1734 } | |
1735 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1736 // Make sure current_state is valid |
7 | 1737 if (INVALID_STATE(¤t_state)) |
1738 validate_current_state(); | |
1739 | |
1740 /* | |
1741 * Skip from the current column to "col", get the attributes for "col". | |
1742 */ | |
1743 while (current_col <= col) | |
1744 { | |
1504 | 1745 attr = syn_current_attr(FALSE, TRUE, can_spell, |
1746 current_col == col ? keep_state : FALSE); | |
7 | 1747 ++current_col; |
1748 } | |
1749 | |
1750 return attr; | |
1751 } | |
1752 | |
1753 /* | |
1754 * Get syntax attributes for current_lnum, current_col. | |
1755 */ | |
1756 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1757 syn_current_attr( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1758 int syncing, // When 1: called for syncing |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1759 int displaying, // result will be displayed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1760 int *can_spell, // return: do spell checking |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1761 int keep_state) // keep syntax stack afterwards |
7 | 1762 { |
1763 int syn_id; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1764 lpos_T endpos; // was: char_u *endp; |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1765 lpos_T hl_startpos; // was: int hl_startcol; |
7 | 1766 lpos_T hl_endpos; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1767 lpos_T eos_pos; // end-of-start match (start region) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1768 lpos_T eoe_pos; // end-of-end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1769 int end_idx; // group ID for end pattern |
7 | 1770 int idx; |
1771 synpat_T *spp; | |
221 | 1772 stateitem_T *cur_si, *sip = NULL; |
7 | 1773 int startcol; |
1774 int endcol; | |
1775 long flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1776 int cchar; |
7 | 1777 short *next_list; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1778 int found_match; // found usable match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1779 static int try_next_column = FALSE; // must try in next col |
7 | 1780 int do_keywords; |
1781 regmmatch_T regmatch; | |
1782 lpos_T pos; | |
1783 int lc_col; | |
1784 reg_extmatch_T *cur_extmatch = NULL; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1785 char_u buf_chartab[32]; // chartab array for syn iskyeyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1786 char_u *line; // current line. NOTE: becomes invalid after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1787 // looking for a pattern match! |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1788 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1789 // variables for zero-width matches that have a "nextgroup" argument |
7 | 1790 int keep_next_list; |
1791 int zero_width_next_list = FALSE; | |
1792 garray_T zero_width_next_ga; | |
1793 | |
1794 /* | |
1795 * No character, no attributes! Past end of line? | |
1796 * Do try matching with an empty line (could be the start of a region). | |
1797 */ | |
1798 line = syn_getcurline(); | |
1799 if (line[current_col] == NUL && current_col != 0) | |
1800 { | |
1801 /* | |
1802 * If we found a match after the last column, use it. | |
1803 */ | |
1804 if (next_match_idx >= 0 && next_match_col >= (int)current_col | |
1805 && next_match_col != MAXCOL) | |
1806 (void)push_next_match(NULL); | |
1807 | |
1808 current_finished = TRUE; | |
1809 current_state_stored = FALSE; | |
1810 return 0; | |
1811 } | |
1812 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1813 // if the current or next character is NUL, we will finish the line now |
7 | 1814 if (line[current_col] == NUL || line[current_col + 1] == NUL) |
1815 { | |
1816 current_finished = TRUE; | |
1817 current_state_stored = FALSE; | |
1818 } | |
1819 | |
1820 /* | |
1821 * When in the previous column there was a match but it could not be used | |
1822 * (empty match or already matched in this column) need to try again in | |
1823 * the next column. | |
1824 */ | |
1825 if (try_next_column) | |
1826 { | |
1827 next_match_idx = -1; | |
1828 try_next_column = FALSE; | |
1829 } | |
1830 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1831 // Only check for keywords when not syncing and there are some. |
7 | 1832 do_keywords = !syncing |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1833 && (syn_block->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1834 || syn_block->b_keywtab_ic.ht_used > 0); |
7 | 1835 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1836 // Init the list of zero-width matches with a nextlist. This is used to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1837 // avoid matching the same item in the same position twice. |
7 | 1838 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10); |
1839 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1840 // use syntax iskeyword option |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1841 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1842 |
7 | 1843 /* |
1844 * Repeat matching keywords and patterns, to find contained items at the | |
1845 * same column. This stops when there are no extra matches at the current | |
1846 * column. | |
1847 */ | |
1848 do | |
1849 { | |
1850 found_match = FALSE; | |
1851 keep_next_list = FALSE; | |
1852 syn_id = 0; | |
1853 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1854 |
7 | 1855 /* |
1856 * 1. Check for a current state. | |
1857 * Only when there is no current state, or if the current state may | |
1858 * contain other things, we need to check for keywords and patterns. | |
1859 * Always need to check for contained items if some item has the | |
1860 * "containedin" argument (takes extra time!). | |
1861 */ | |
1862 if (current_state.ga_len) | |
1863 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1864 else | |
1865 cur_si = NULL; | |
1866 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1867 if (syn_block->b_syn_containedin || cur_si == NULL |
7 | 1868 || cur_si->si_cont_list != NULL) |
1869 { | |
1870 /* | |
1871 * 2. Check for keywords, if on a keyword char after a non-keyword | |
1872 * char. Don't do this when syncing. | |
1873 */ | |
1874 if (do_keywords) | |
1875 { | |
1876 line = syn_getcurline(); | |
4043 | 1877 if (vim_iswordp_buf(line + current_col, syn_buf) |
7 | 1878 && (current_col == 0 |
4043 | 1879 || !vim_iswordp_buf(line + current_col - 1 |
7 | 1880 - (has_mbyte |
1881 ? (*mb_head_off)(line, line + current_col - 1) | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1882 : 0) , syn_buf))) |
7 | 1883 { |
1884 syn_id = check_keyword_id(line, (int)current_col, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1885 &endcol, &flags, &next_list, cur_si, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1886 &cchar); |
205 | 1887 if (syn_id != 0) |
7 | 1888 { |
1889 if (push_current_state(KEYWORD_IDX) == OK) | |
1890 { | |
1891 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1892 cur_si->si_m_startcol = current_col; | |
1893 cur_si->si_h_startpos.lnum = current_lnum; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1894 cur_si->si_h_startpos.col = 0; // starts right away |
7 | 1895 cur_si->si_m_endpos.lnum = current_lnum; |
1896 cur_si->si_m_endpos.col = endcol; | |
1897 cur_si->si_h_endpos.lnum = current_lnum; | |
1898 cur_si->si_h_endpos.col = endcol; | |
1899 cur_si->si_ends = TRUE; | |
1900 cur_si->si_end_idx = 0; | |
1901 cur_si->si_flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1902 #ifdef FEAT_CONCEAL |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
1903 cur_si->si_seqnr = next_seqnr++; |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1904 cur_si->si_cchar = cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1905 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1906 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1907 CUR_STATE(current_state.ga_len - 2).si_flags |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1908 & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1909 #endif |
7 | 1910 cur_si->si_id = syn_id; |
1911 cur_si->si_trans_id = syn_id; | |
1912 if (flags & HL_TRANSP) | |
1913 { | |
1914 if (current_state.ga_len < 2) | |
1915 { | |
1916 cur_si->si_attr = 0; | |
1917 cur_si->si_trans_id = 0; | |
1918 } | |
1919 else | |
1920 { | |
1921 cur_si->si_attr = CUR_STATE( | |
1922 current_state.ga_len - 2).si_attr; | |
1923 cur_si->si_trans_id = CUR_STATE( | |
1924 current_state.ga_len - 2).si_trans_id; | |
1925 } | |
1926 } | |
1927 else | |
1928 cur_si->si_attr = syn_id2attr(syn_id); | |
1929 cur_si->si_cont_list = NULL; | |
1930 cur_si->si_next_list = next_list; | |
1931 check_keepend(); | |
1932 } | |
1933 else | |
1934 vim_free(next_list); | |
1935 } | |
1936 } | |
1937 } | |
1938 | |
1939 /* | |
205 | 1940 * 3. Check for patterns (only if no keyword found). |
7 | 1941 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1942 if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) |
7 | 1943 { |
1944 /* | |
1945 * If we didn't check for a match yet, or we are past it, check | |
1946 * for any match with a pattern. | |
1947 */ | |
1948 if (next_match_idx < 0 || next_match_col < (int)current_col) | |
1949 { | |
1950 /* | |
1951 * Check all relevant patterns for a match at this | |
1952 * position. This is complicated, because matching with a | |
1953 * pattern takes quite a bit of time, thus we want to | |
1954 * avoid doing it when it's not needed. | |
1955 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1956 next_match_idx = 0; // no match in this line yet |
7 | 1957 next_match_col = MAXCOL; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1958 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
7 | 1959 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1960 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 1961 if ( spp->sp_syncing == syncing |
1962 && (displaying || !(spp->sp_flags & HL_DISPLAY)) | |
1963 && (spp->sp_type == SPTYPE_MATCH | |
1964 || spp->sp_type == SPTYPE_START) | |
1965 && (current_next_list != NULL | |
1966 ? in_id_list(NULL, current_next_list, | |
1967 &spp->sp_syn, 0) | |
1968 : (cur_si == NULL | |
1969 ? !(spp->sp_flags & HL_CONTAINED) | |
1970 : in_id_list(cur_si, | |
1971 cur_si->si_cont_list, &spp->sp_syn, | |
1972 spp->sp_flags & HL_CONTAINED)))) | |
1973 { | |
6375 | 1974 int r; |
1975 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1976 // If we already tried matching in this line, and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1977 // there isn't a match before next_match_col, skip |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1978 // this item. |
7 | 1979 if (spp->sp_line_id == current_line_id |
1980 && spp->sp_startcol >= next_match_col) | |
1981 continue; | |
1982 spp->sp_line_id = current_line_id; | |
1983 | |
1984 lc_col = current_col - spp->sp_offsets[SPO_LC_OFF]; | |
1985 if (lc_col < 0) | |
1986 lc_col = 0; | |
1987 | |
1988 regmatch.rmm_ic = spp->sp_ic; | |
1989 regmatch.regprog = spp->sp_prog; | |
6375 | 1990 r = syn_regexec(®match, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1991 current_lnum, |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1992 (colnr_T)lc_col, |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1993 IF_SYN_TIME(&spp->sp_time)); |
6375 | 1994 spp->sp_prog = regmatch.regprog; |
1995 if (!r) | |
7 | 1996 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1997 // no match in this line, try another one |
7 | 1998 spp->sp_startcol = MAXCOL; |
1999 continue; | |
2000 } | |
2001 | |
2002 /* | |
2003 * Compute the first column of the match. | |
2004 */ | |
2005 syn_add_start_off(&pos, ®match, | |
2006 spp, SPO_MS_OFF, -1); | |
2007 if (pos.lnum > current_lnum) | |
2008 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2009 // must have used end of match in a next line, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2010 // we can't handle that |
7 | 2011 spp->sp_startcol = MAXCOL; |
2012 continue; | |
2013 } | |
2014 startcol = pos.col; | |
2015 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2016 // remember the next column where this pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2017 // matches in the current line |
7 | 2018 spp->sp_startcol = startcol; |
2019 | |
2020 /* | |
2021 * If a previously found match starts at a lower | |
2022 * column number, don't use this one. | |
2023 */ | |
2024 if (startcol >= next_match_col) | |
2025 continue; | |
2026 | |
2027 /* | |
2028 * If we matched this pattern at this position | |
2029 * before, skip it. Must retry in the next | |
2030 * column, because it may match from there. | |
2031 */ | |
2032 if (did_match_already(idx, &zero_width_next_ga)) | |
2033 { | |
2034 try_next_column = TRUE; | |
2035 continue; | |
2036 } | |
2037 | |
2038 endpos.lnum = regmatch.endpos[0].lnum; | |
2039 endpos.col = regmatch.endpos[0].col; | |
2040 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2041 // Compute the highlight start. |
7 | 2042 syn_add_start_off(&hl_startpos, ®match, |
2043 spp, SPO_HS_OFF, -1); | |
2044 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2045 // Compute the region start. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2046 // Default is to use the end of the match. |
7 | 2047 syn_add_end_off(&eos_pos, ®match, |
2048 spp, SPO_RS_OFF, 0); | |
2049 | |
2050 /* | |
2051 * Grab the external submatches before they get | |
2052 * overwritten. Reference count doesn't change. | |
2053 */ | |
2054 unref_extmatch(cur_extmatch); | |
2055 cur_extmatch = re_extmatch_out; | |
2056 re_extmatch_out = NULL; | |
2057 | |
2058 flags = 0; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2059 eoe_pos.lnum = 0; // avoid warning |
7 | 2060 eoe_pos.col = 0; |
2061 end_idx = 0; | |
2062 hl_endpos.lnum = 0; | |
2063 | |
2064 /* | |
2065 * For a "oneline" the end must be found in the | |
2066 * same line too. Search for it after the end of | |
2067 * the match with the start pattern. Set the | |
2068 * resulting end positions at the same time. | |
2069 */ | |
2070 if (spp->sp_type == SPTYPE_START | |
2071 && (spp->sp_flags & HL_ONELINE)) | |
2072 { | |
2073 lpos_T startpos; | |
2074 | |
2075 startpos = endpos; | |
2076 find_endpos(idx, &startpos, &endpos, &hl_endpos, | |
2077 &flags, &eoe_pos, &end_idx, cur_extmatch); | |
2078 if (endpos.lnum == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2079 continue; // not found |
7 | 2080 } |
2081 | |
2082 /* | |
2083 * For a "match" the size must be > 0 after the | |
2084 * end offset needs has been added. Except when | |
2085 * syncing. | |
2086 */ | |
2087 else if (spp->sp_type == SPTYPE_MATCH) | |
2088 { | |
2089 syn_add_end_off(&hl_endpos, ®match, spp, | |
2090 SPO_HE_OFF, 0); | |
2091 syn_add_end_off(&endpos, ®match, spp, | |
2092 SPO_ME_OFF, 0); | |
2093 if (endpos.lnum == current_lnum | |
2094 && (int)endpos.col + syncing < startcol) | |
2095 { | |
2096 /* | |
2097 * If an empty string is matched, may need | |
2098 * to try matching again at next column. | |
2099 */ | |
2100 if (regmatch.startpos[0].col | |
2101 == regmatch.endpos[0].col) | |
2102 try_next_column = TRUE; | |
2103 continue; | |
2104 } | |
2105 } | |
2106 | |
2107 /* | |
2108 * keep the best match so far in next_match_* | |
2109 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2110 // Highlighting must start after startpos and end |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2111 // before endpos. |
7 | 2112 if (hl_startpos.lnum == current_lnum |
2113 && (int)hl_startpos.col < startcol) | |
2114 hl_startpos.col = startcol; | |
2115 limit_pos_zero(&hl_endpos, &endpos); | |
2116 | |
2117 next_match_idx = idx; | |
2118 next_match_col = startcol; | |
2119 next_match_m_endpos = endpos; | |
2120 next_match_h_endpos = hl_endpos; | |
2121 next_match_h_startpos = hl_startpos; | |
2122 next_match_flags = flags; | |
2123 next_match_eos_pos = eos_pos; | |
2124 next_match_eoe_pos = eoe_pos; | |
2125 next_match_end_idx = end_idx; | |
2126 unref_extmatch(next_match_extmatch); | |
2127 next_match_extmatch = cur_extmatch; | |
2128 cur_extmatch = NULL; | |
2129 } | |
2130 } | |
2131 } | |
2132 | |
2133 /* | |
2134 * If we found a match at the current column, use it. | |
2135 */ | |
2136 if (next_match_idx >= 0 && next_match_col == (int)current_col) | |
2137 { | |
2138 synpat_T *lspp; | |
2139 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2140 // When a zero-width item matched which has a nextgroup, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2141 // don't push the item but set nextgroup. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2142 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2143 if (next_match_m_endpos.lnum == current_lnum |
2144 && next_match_m_endpos.col == current_col | |
2145 && lspp->sp_next_list != NULL) | |
2146 { | |
2147 current_next_list = lspp->sp_next_list; | |
2148 current_next_flags = lspp->sp_flags; | |
2149 keep_next_list = TRUE; | |
2150 zero_width_next_list = TRUE; | |
2151 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2152 // Add the index to a list, so that we can check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2153 // later that we don't match it again (and cause an |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2154 // endless loop). |
7 | 2155 if (ga_grow(&zero_width_next_ga, 1) == OK) |
2156 { | |
2157 ((int *)(zero_width_next_ga.ga_data)) | |
2158 [zero_width_next_ga.ga_len++] = next_match_idx; | |
2159 } | |
2160 next_match_idx = -1; | |
2161 } | |
2162 else | |
2163 cur_si = push_next_match(cur_si); | |
2164 found_match = TRUE; | |
2165 } | |
2166 } | |
2167 } | |
2168 | |
2169 /* | |
2170 * Handle searching for nextgroup match. | |
2171 */ | |
2172 if (current_next_list != NULL && !keep_next_list) | |
2173 { | |
2174 /* | |
2175 * If a nextgroup was not found, continue looking for one if: | |
2176 * - this is an empty line and the "skipempty" option was given | |
2177 * - we are on white space and the "skipwhite" option was given | |
2178 */ | |
2179 if (!found_match) | |
2180 { | |
2181 line = syn_getcurline(); | |
2182 if (((current_next_flags & HL_SKIPWHITE) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2183 && VIM_ISWHITE(line[current_col])) |
7 | 2184 || ((current_next_flags & HL_SKIPEMPTY) |
2185 && *line == NUL)) | |
2186 break; | |
2187 } | |
2188 | |
2189 /* | |
2190 * If a nextgroup was found: Use it, and continue looking for | |
2191 * contained matches. | |
2192 * If a nextgroup was not found: Continue looking for a normal | |
2193 * match. | |
2194 * When did set current_next_list for a zero-width item and no | |
2195 * match was found don't loop (would get stuck). | |
2196 */ | |
2197 current_next_list = NULL; | |
2198 next_match_idx = -1; | |
2199 if (!zero_width_next_list) | |
2200 found_match = TRUE; | |
2201 } | |
2202 | |
2203 } while (found_match); | |
2204 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2205 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2206 |
7 | 2207 /* |
2208 * Use attributes from the current state, if within its highlighting. | |
2209 * If not, use attributes from the current-but-one state, etc. | |
2210 */ | |
2211 current_attr = 0; | |
2212 #ifdef FEAT_EVAL | |
2213 current_id = 0; | |
2214 current_trans_id = 0; | |
2215 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2216 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2217 current_flags = 0; |
11579
52e3a77c097b
patch 8.0.0672: third item of synconcealed() changes too often
Christian Brabandt <cb@256bit.org>
parents:
11541
diff
changeset
|
2218 current_seqnr = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2219 #endif |
7 | 2220 if (cur_si != NULL) |
2221 { | |
221 | 2222 #ifndef FEAT_EVAL |
2223 int current_trans_id = 0; | |
2224 #endif | |
7 | 2225 for (idx = current_state.ga_len - 1; idx >= 0; --idx) |
2226 { | |
2227 sip = &CUR_STATE(idx); | |
2228 if ((current_lnum > sip->si_h_startpos.lnum | |
2229 || (current_lnum == sip->si_h_startpos.lnum | |
2230 && current_col >= sip->si_h_startpos.col)) | |
2231 && (sip->si_h_endpos.lnum == 0 | |
2232 || current_lnum < sip->si_h_endpos.lnum | |
2233 || (current_lnum == sip->si_h_endpos.lnum | |
2234 && current_col < sip->si_h_endpos.col))) | |
2235 { | |
2236 current_attr = sip->si_attr; | |
2237 #ifdef FEAT_EVAL | |
2238 current_id = sip->si_id; | |
221 | 2239 #endif |
7 | 2240 current_trans_id = sip->si_trans_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2241 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2242 current_flags = sip->si_flags; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2243 current_seqnr = sip->si_seqnr; |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
2244 current_sub_char = sip->si_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2245 #endif |
7 | 2246 break; |
2247 } | |
2248 } | |
2249 | |
221 | 2250 if (can_spell != NULL) |
2251 { | |
2252 struct sp_syn sps; | |
2253 | |
2254 /* | |
2255 * set "can_spell" to TRUE if spell checking is supposed to be | |
2256 * done in the current item. | |
2257 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2258 if (syn_block->b_spell_cluster_id == 0) |
227 | 2259 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2260 // There is no @Spell cluster: Do spelling for items without |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2261 // @NoSpell cluster. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2262 if (syn_block->b_nospell_cluster_id == 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2263 || current_trans_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2264 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); |
227 | 2265 else |
2266 { | |
2267 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2268 sps.id = syn_block->b_nospell_cluster_id; |
227 | 2269 sps.cont_in_list = NULL; |
2270 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2271 } | |
2272 } | |
221 | 2273 else |
2274 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2275 // The @Spell cluster is defined: Do spelling in items with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2276 // the @Spell cluster. But not when @NoSpell is also there. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2277 // At the toplevel only spell check when ":syn spell toplevel" |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2278 // was used. |
320 | 2279 if (current_trans_id == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2280 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); |
320 | 2281 else |
2282 { | |
2283 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2284 sps.id = syn_block->b_spell_cluster_id; |
320 | 2285 sps.cont_in_list = NULL; |
2286 *can_spell = in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2287 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2288 if (syn_block->b_nospell_cluster_id != 0) |
320 | 2289 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2290 sps.id = syn_block->b_nospell_cluster_id; |
320 | 2291 if (in_id_list(sip, sip->si_cont_list, &sps, 0)) |
2292 *can_spell = FALSE; | |
2293 } | |
2294 } | |
221 | 2295 } |
2296 } | |
2297 | |
2298 | |
7 | 2299 /* |
2300 * Check for end of current state (and the states before it) at the | |
2301 * next column. Don't do this for syncing, because we would miss a | |
2302 * single character match. | |
2303 * First check if the current state ends at the current column. It | |
2304 * may be for an empty match and a containing item might end in the | |
2305 * current column. | |
2306 */ | |
1504 | 2307 if (!syncing && !keep_state) |
7 | 2308 { |
2309 check_state_ends(); | |
442 | 2310 if (current_state.ga_len > 0 |
2311 && syn_getcurline()[current_col] != NUL) | |
7 | 2312 { |
2313 ++current_col; | |
2314 check_state_ends(); | |
2315 --current_col; | |
2316 } | |
2317 } | |
2318 } | |
221 | 2319 else if (can_spell != NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2320 // Default: Only do spelling when there is no @Spell cluster or when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2321 // ":syn spell toplevel" was used. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2322 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2323 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2324 : (syn_block->b_syn_spell == SYNSPL_TOP); |
7 | 2325 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2326 // nextgroup ends at end of line, unless "skipnl" or "skipempty" present |
7 | 2327 if (current_next_list != NULL |
13375
33f514c94943
patch 8.0.1561: crash with rust syntax highligting
Christian Brabandt <cb@256bit.org>
parents:
13339
diff
changeset
|
2328 && (line = syn_getcurline())[current_col] != NUL |
33f514c94943
patch 8.0.1561: crash with rust syntax highligting
Christian Brabandt <cb@256bit.org>
parents:
13339
diff
changeset
|
2329 && line[current_col + 1] == NUL |
7 | 2330 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) |
2331 current_next_list = NULL; | |
2332 | |
2333 if (zero_width_next_ga.ga_len > 0) | |
2334 ga_clear(&zero_width_next_ga); | |
2335 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2336 // No longer need external matches. But keep next_match_extmatch. |
7 | 2337 unref_extmatch(re_extmatch_out); |
2338 re_extmatch_out = NULL; | |
2339 unref_extmatch(cur_extmatch); | |
2340 | |
2341 return current_attr; | |
2342 } | |
2343 | |
2344 | |
2345 /* | |
2346 * Check if we already matched pattern "idx" at the current column. | |
2347 */ | |
2348 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2349 did_match_already(int idx, garray_T *gap) |
7 | 2350 { |
2351 int i; | |
2352 | |
2353 for (i = current_state.ga_len; --i >= 0; ) | |
2354 if (CUR_STATE(i).si_m_startcol == (int)current_col | |
2355 && CUR_STATE(i).si_m_lnum == (int)current_lnum | |
2356 && CUR_STATE(i).si_idx == idx) | |
2357 return TRUE; | |
2358 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2359 // Zero-width matches with a nextgroup argument are not put on the syntax |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2360 // stack, and can only be matched once anyway. |
7 | 2361 for (i = gap->ga_len; --i >= 0; ) |
2362 if (((int *)(gap->ga_data))[i] == idx) | |
2363 return TRUE; | |
2364 | |
2365 return FALSE; | |
2366 } | |
2367 | |
2368 /* | |
2369 * Push the next match onto the stack. | |
2370 */ | |
2371 static stateitem_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2372 push_next_match(stateitem_T *cur_si) |
7 | 2373 { |
2374 synpat_T *spp; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2375 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2376 int save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2377 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2378 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2379 spp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2380 |
2381 /* | |
2382 * Push the item in current_state stack; | |
2383 */ | |
2384 if (push_current_state(next_match_idx) == OK) | |
2385 { | |
2386 /* | |
2387 * If it's a start-skip-end type that crosses lines, figure out how | |
2388 * much it continues in this line. Otherwise just fill in the length. | |
2389 */ | |
2390 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2391 cur_si->si_h_startpos = next_match_h_startpos; | |
2392 cur_si->si_m_startcol = current_col; | |
2393 cur_si->si_m_lnum = current_lnum; | |
2394 cur_si->si_flags = spp->sp_flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2395 #ifdef FEAT_CONCEAL |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2396 cur_si->si_seqnr = next_seqnr++; |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
2397 cur_si->si_cchar = spp->sp_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2398 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2399 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2400 CUR_STATE(current_state.ga_len - 2).si_flags & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2401 #endif |
7 | 2402 cur_si->si_next_list = spp->sp_next_list; |
2403 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); | |
2404 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) | |
2405 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2406 // Try to find the end pattern in the current line |
7 | 2407 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); |
2408 check_keepend(); | |
2409 } | |
2410 else | |
2411 { | |
2412 cur_si->si_m_endpos = next_match_m_endpos; | |
2413 cur_si->si_h_endpos = next_match_h_endpos; | |
2414 cur_si->si_ends = TRUE; | |
2415 cur_si->si_flags |= next_match_flags; | |
2416 cur_si->si_eoe_pos = next_match_eoe_pos; | |
2417 cur_si->si_end_idx = next_match_end_idx; | |
2418 } | |
2419 if (keepend_level < 0 && (cur_si->si_flags & HL_KEEPEND)) | |
2420 keepend_level = current_state.ga_len - 1; | |
2421 check_keepend(); | |
2422 update_si_attr(current_state.ga_len - 1); | |
2423 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2424 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2425 save_flags = cur_si->si_flags & (HL_CONCEAL | HL_CONCEALENDS); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2426 #endif |
7 | 2427 /* |
2428 * If the start pattern has another highlight group, push another item | |
2429 * on the stack for the start pattern. | |
2430 */ | |
2431 if ( spp->sp_type == SPTYPE_START | |
2432 && spp->sp_syn_match_id != 0 | |
2433 && push_current_state(next_match_idx) == OK) | |
2434 { | |
2435 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2436 cur_si->si_h_startpos = next_match_h_startpos; | |
2437 cur_si->si_m_startcol = current_col; | |
2438 cur_si->si_m_lnum = current_lnum; | |
2439 cur_si->si_m_endpos = next_match_eos_pos; | |
2440 cur_si->si_h_endpos = next_match_eos_pos; | |
2441 cur_si->si_ends = TRUE; | |
2442 cur_si->si_end_idx = 0; | |
2443 cur_si->si_flags = HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2444 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2445 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2446 cur_si->si_flags |= save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2447 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2448 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2449 #endif |
7 | 2450 cur_si->si_next_list = NULL; |
2451 check_keepend(); | |
2452 update_si_attr(current_state.ga_len - 1); | |
2453 } | |
2454 } | |
2455 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2456 next_match_idx = -1; // try other match next time |
7 | 2457 |
2458 return cur_si; | |
2459 } | |
2460 | |
2461 /* | |
2462 * Check for end of current state (and the states before it). | |
2463 */ | |
2464 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2465 check_state_ends(void) |
7 | 2466 { |
2467 stateitem_T *cur_si; | |
2863 | 2468 int had_extend; |
7 | 2469 |
2470 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2471 for (;;) | |
2472 { | |
2473 if (cur_si->si_ends | |
2474 && (cur_si->si_m_endpos.lnum < current_lnum | |
2475 || (cur_si->si_m_endpos.lnum == current_lnum | |
2476 && cur_si->si_m_endpos.col <= current_col))) | |
2477 { | |
2478 /* | |
2479 * If there is an end pattern group ID, highlight the end pattern | |
2480 * now. No need to pop the current item from the stack. | |
2481 * Only do this if the end pattern continues beyond the current | |
2482 * position. | |
2483 */ | |
2484 if (cur_si->si_end_idx | |
2485 && (cur_si->si_eoe_pos.lnum > current_lnum | |
2486 || (cur_si->si_eoe_pos.lnum == current_lnum | |
2487 && cur_si->si_eoe_pos.col > current_col))) | |
2488 { | |
2489 cur_si->si_idx = cur_si->si_end_idx; | |
2490 cur_si->si_end_idx = 0; | |
2491 cur_si->si_m_endpos = cur_si->si_eoe_pos; | |
2492 cur_si->si_h_endpos = cur_si->si_eoe_pos; | |
2493 cur_si->si_flags |= HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2494 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2495 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2496 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2497 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2498 #endif |
7 | 2499 update_si_attr(current_state.ga_len - 1); |
36 | 2500 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2501 // nextgroup= should not match in the end pattern |
2831 | 2502 current_next_list = NULL; |
2503 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2504 // what matches next may be different now, clear it |
36 | 2505 next_match_idx = 0; |
2506 next_match_col = MAXCOL; | |
7 | 2507 break; |
2508 } | |
2509 else | |
2510 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2511 // handle next_list, unless at end of line and no "skipnl" or |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2512 // "skipempty" |
7 | 2513 current_next_list = cur_si->si_next_list; |
2514 current_next_flags = cur_si->si_flags; | |
2515 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) | |
2516 && syn_getcurline()[current_col] == NUL) | |
2517 current_next_list = NULL; | |
2518 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2519 // When the ended item has "extend", another item with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2520 // "keepend" now needs to check for its end. |
2863 | 2521 had_extend = (cur_si->si_flags & HL_EXTEND); |
7 | 2522 |
2523 pop_current_state(); | |
2524 | |
2525 if (current_state.ga_len == 0) | |
2526 break; | |
2527 | |
1503 | 2528 if (had_extend && keepend_level >= 0) |
7 | 2529 { |
2530 syn_update_ends(FALSE); | |
2531 if (current_state.ga_len == 0) | |
2532 break; | |
2533 } | |
2534 | |
2535 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2536 | |
2537 /* | |
2538 * Only for a region the search for the end continues after | |
2539 * the end of the contained item. If the contained match | |
2540 * included the end-of-line, break here, the region continues. | |
2541 * Don't do this when: | |
2542 * - "keepend" is used for the contained item | |
2543 * - not at the end of the line (could be end="x$"me=e-1). | |
2544 * - "excludenl" is used (HL_HAS_EOL won't be set) | |
2545 */ | |
2546 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2547 && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type |
7 | 2548 == SPTYPE_START |
2549 && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) | |
2550 { | |
2551 update_si_end(cur_si, (int)current_col, TRUE); | |
2552 check_keepend(); | |
2553 if ((current_next_flags & HL_HAS_EOL) | |
2554 && keepend_level < 0 | |
2555 && syn_getcurline()[current_col] == NUL) | |
2556 break; | |
2557 } | |
2558 } | |
2559 } | |
2560 else | |
2561 break; | |
2562 } | |
2563 } | |
2564 | |
2565 /* | |
2566 * Update an entry in the current_state stack for a match or region. This | |
2567 * fills in si_attr, si_next_list and si_cont_list. | |
2568 */ | |
2569 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2570 update_si_attr(int idx) |
7 | 2571 { |
2572 stateitem_T *sip = &CUR_STATE(idx); | |
2573 synpat_T *spp; | |
2574 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2575 // This should not happen... |
1371 | 2576 if (sip->si_idx < 0) |
2577 return; | |
2578 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2579 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); |
7 | 2580 if (sip->si_flags & HL_MATCH) |
2581 sip->si_id = spp->sp_syn_match_id; | |
2582 else | |
2583 sip->si_id = spp->sp_syn.id; | |
2584 sip->si_attr = syn_id2attr(sip->si_id); | |
2585 sip->si_trans_id = sip->si_id; | |
2586 if (sip->si_flags & HL_MATCH) | |
2587 sip->si_cont_list = NULL; | |
2588 else | |
2589 sip->si_cont_list = spp->sp_cont_list; | |
2590 | |
2591 /* | |
2592 * For transparent items, take attr from outer item. | |
2593 * Also take cont_list, if there is none. | |
2594 * Don't do this for the matchgroup of a start or end pattern. | |
2595 */ | |
2596 if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) | |
2597 { | |
2598 if (idx == 0) | |
2599 { | |
2600 sip->si_attr = 0; | |
2601 sip->si_trans_id = 0; | |
2602 if (sip->si_cont_list == NULL) | |
2603 sip->si_cont_list = ID_LIST_ALL; | |
2604 } | |
2605 else | |
2606 { | |
2607 sip->si_attr = CUR_STATE(idx - 1).si_attr; | |
2608 sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; | |
2609 if (sip->si_cont_list == NULL) | |
2610 { | |
2611 sip->si_flags |= HL_TRANS_CONT; | |
2612 sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; | |
2613 } | |
2614 } | |
2615 } | |
2616 } | |
2617 | |
2618 /* | |
2619 * Check the current stack for patterns with "keepend" flag. | |
2620 * Propagate the match-end to contained items, until a "skipend" item is found. | |
2621 */ | |
2622 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2623 check_keepend(void) |
7 | 2624 { |
2625 int i; | |
2626 lpos_T maxpos; | |
991 | 2627 lpos_T maxpos_h; |
7 | 2628 stateitem_T *sip; |
2629 | |
2630 /* | |
2631 * This check can consume a lot of time; only do it from the level where | |
2632 * there really is a keepend. | |
2633 */ | |
2634 if (keepend_level < 0) | |
2635 return; | |
2636 | |
2637 /* | |
2638 * Find the last index of an "extend" item. "keepend" items before that | |
2639 * won't do anything. If there is no "extend" item "i" will be | |
2640 * "keepend_level" and all "keepend" items will work normally. | |
2641 */ | |
2642 for (i = current_state.ga_len - 1; i > keepend_level; --i) | |
2643 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
2644 break; | |
2645 | |
2646 maxpos.lnum = 0; | |
1702 | 2647 maxpos.col = 0; |
991 | 2648 maxpos_h.lnum = 0; |
1702 | 2649 maxpos_h.col = 0; |
7 | 2650 for ( ; i < current_state.ga_len; ++i) |
2651 { | |
2652 sip = &CUR_STATE(i); | |
2653 if (maxpos.lnum != 0) | |
2654 { | |
2655 limit_pos_zero(&sip->si_m_endpos, &maxpos); | |
991 | 2656 limit_pos_zero(&sip->si_h_endpos, &maxpos_h); |
7 | 2657 limit_pos_zero(&sip->si_eoe_pos, &maxpos); |
2658 sip->si_ends = TRUE; | |
2659 } | |
991 | 2660 if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) |
2661 { | |
2662 if (maxpos.lnum == 0 | |
7 | 2663 || maxpos.lnum > sip->si_m_endpos.lnum |
2664 || (maxpos.lnum == sip->si_m_endpos.lnum | |
991 | 2665 && maxpos.col > sip->si_m_endpos.col)) |
2666 maxpos = sip->si_m_endpos; | |
2667 if (maxpos_h.lnum == 0 | |
2668 || maxpos_h.lnum > sip->si_h_endpos.lnum | |
2669 || (maxpos_h.lnum == sip->si_h_endpos.lnum | |
2670 && maxpos_h.col > sip->si_h_endpos.col)) | |
2671 maxpos_h = sip->si_h_endpos; | |
2672 } | |
7 | 2673 } |
2674 } | |
2675 | |
2676 /* | |
2677 * Update an entry in the current_state stack for a start-skip-end pattern. | |
2678 * This finds the end of the current item, if it's in the current line. | |
2679 * | |
2680 * Return the flags for the matched END. | |
2681 */ | |
2682 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2683 update_si_end( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2684 stateitem_T *sip, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2685 int startcol, // where to start searching for the end |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2686 int force) // when TRUE overrule a previous end |
7 | 2687 { |
2688 lpos_T startpos; | |
2689 lpos_T endpos; | |
2690 lpos_T hl_endpos; | |
2691 lpos_T end_endpos; | |
2692 int end_idx; | |
2693 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2694 // return quickly for a keyword |
1371 | 2695 if (sip->si_idx < 0) |
2696 return; | |
2697 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2698 // Don't update when it's already done. Can be a match of an end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2699 // that started in a previous line. Watch out: can also be a "keepend" |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2700 // from a containing item. |
7 | 2701 if (!force && sip->si_m_endpos.lnum >= current_lnum) |
2702 return; | |
2703 | |
2704 /* | |
2705 * We need to find the end of the region. It may continue in the next | |
2706 * line. | |
2707 */ | |
2708 end_idx = 0; | |
2709 startpos.lnum = current_lnum; | |
2710 startpos.col = startcol; | |
2711 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, | |
2712 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); | |
2713 | |
2714 if (endpos.lnum == 0) | |
2715 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2716 // No end pattern matched. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2717 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) |
7 | 2718 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2719 // a "oneline" never continues in the next line |
7 | 2720 sip->si_ends = TRUE; |
2721 sip->si_m_endpos.lnum = current_lnum; | |
2722 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); | |
2723 } | |
2724 else | |
2725 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2726 // continues in the next line |
7 | 2727 sip->si_ends = FALSE; |
2728 sip->si_m_endpos.lnum = 0; | |
2729 } | |
2730 sip->si_h_endpos = sip->si_m_endpos; | |
2731 } | |
2732 else | |
2733 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2734 // match within this line |
7 | 2735 sip->si_m_endpos = endpos; |
2736 sip->si_h_endpos = hl_endpos; | |
2737 sip->si_eoe_pos = end_endpos; | |
2738 sip->si_ends = TRUE; | |
2739 sip->si_end_idx = end_idx; | |
2740 } | |
2741 } | |
2742 | |
2743 /* | |
2744 * Add a new state to the current state stack. | |
2745 * It is cleared and the index set to "idx". | |
2746 * Return FAIL if it's not possible (out of memory). | |
2747 */ | |
2748 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2749 push_current_state(int idx) |
7 | 2750 { |
2751 if (ga_grow(¤t_state, 1) == FAIL) | |
2752 return FAIL; | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
2753 CLEAR_POINTER(&CUR_STATE(current_state.ga_len)); |
7 | 2754 CUR_STATE(current_state.ga_len).si_idx = idx; |
2755 ++current_state.ga_len; | |
2756 return OK; | |
2757 } | |
2758 | |
2759 /* | |
2760 * Remove a state from the current_state stack. | |
2761 */ | |
2762 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2763 pop_current_state(void) |
7 | 2764 { |
2765 if (current_state.ga_len) | |
2766 { | |
2767 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); | |
2768 --current_state.ga_len; | |
2769 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2770 // after the end of a pattern, try matching a keyword or pattern |
7 | 2771 next_match_idx = -1; |
2772 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2773 // if first state with "keepend" is popped, reset keepend_level |
7 | 2774 if (keepend_level >= current_state.ga_len) |
2775 keepend_level = -1; | |
2776 } | |
2777 | |
2778 /* | |
2779 * Find the end of a start/skip/end syntax region after "startpos". | |
2780 * Only checks one line. | |
2781 * Also handles a match item that continued from a previous line. | |
2782 * If not found, the syntax item continues in the next line. m_endpos->lnum | |
2783 * will be 0. | |
2784 * If found, the end of the region and the end of the highlighting is | |
2785 * computed. | |
2786 */ | |
2787 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2788 find_endpos( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2789 int idx, // index of the pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2790 lpos_T *startpos, // where to start looking for an END match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2791 lpos_T *m_endpos, // return: end of match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2792 lpos_T *hl_endpos, // return: end of highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2793 long *flagsp, // return: flags of matching END |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2794 lpos_T *end_endpos, // return: end of end pattern match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2795 int *end_idx, // return: group ID for end pat. match, or 0 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2796 reg_extmatch_T *start_ext) // submatches from the start pattern |
7 | 2797 { |
2798 colnr_T matchcol; | |
2799 synpat_T *spp, *spp_skip; | |
2800 int start_idx; | |
2801 int best_idx; | |
2802 regmmatch_T regmatch; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2803 regmmatch_T best_regmatch; // startpos/endpos of best match |
7 | 2804 lpos_T pos; |
2805 char_u *line; | |
2806 int had_match = FALSE; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2807 char_u buf_chartab[32]; // chartab array for syn option iskyeyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2808 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2809 // just in case we are invoked for a keyword |
1371 | 2810 if (idx < 0) |
2811 return; | |
2812 | |
7 | 2813 /* |
2814 * Check for being called with a START pattern. | |
2815 * Can happen with a match that continues to the next line, because it | |
2816 * contained a region. | |
2817 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2818 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2819 if (spp->sp_type != SPTYPE_START) |
2820 { | |
2821 *hl_endpos = *startpos; | |
2822 return; | |
2823 } | |
2824 | |
2825 /* | |
2826 * Find the SKIP or first END pattern after the last START pattern. | |
2827 */ | |
2828 for (;;) | |
2829 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2830 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2831 if (spp->sp_type != SPTYPE_START) |
2832 break; | |
2833 ++idx; | |
2834 } | |
2835 | |
2836 /* | |
2837 * Lookup the SKIP pattern (if present) | |
2838 */ | |
2839 if (spp->sp_type == SPTYPE_SKIP) | |
2840 { | |
2841 spp_skip = spp; | |
2842 ++idx; | |
2843 } | |
2844 else | |
2845 spp_skip = NULL; | |
2846 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2847 // Setup external matches for syn_regexec(). |
7 | 2848 unref_extmatch(re_extmatch_in); |
2849 re_extmatch_in = ref_extmatch(start_ext); | |
2850 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2851 matchcol = startpos->col; // start looking for a match at sstart |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2852 start_idx = idx; // remember the first END pattern. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2853 best_regmatch.startpos[0].col = 0; // avoid compiler warning |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2854 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2855 // use syntax iskeyword option |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2856 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2857 |
7 | 2858 for (;;) |
2859 { | |
2860 /* | |
2861 * Find end pattern that matches first after "matchcol". | |
2862 */ | |
2863 best_idx = -1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2864 for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; ++idx) |
7 | 2865 { |
2866 int lc_col = matchcol; | |
6375 | 2867 int r; |
7 | 2868 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2869 spp = &(SYN_ITEMS(syn_block)[idx]); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2870 if (spp->sp_type != SPTYPE_END) // past last END pattern |
7 | 2871 break; |
2872 lc_col -= spp->sp_offsets[SPO_LC_OFF]; | |
2873 if (lc_col < 0) | |
2874 lc_col = 0; | |
2875 | |
2876 regmatch.rmm_ic = spp->sp_ic; | |
2877 regmatch.regprog = spp->sp_prog; | |
6375 | 2878 r = syn_regexec(®match, startpos->lnum, lc_col, |
2879 IF_SYN_TIME(&spp->sp_time)); | |
2880 spp->sp_prog = regmatch.regprog; | |
2881 if (r) | |
7 | 2882 { |
2883 if (best_idx == -1 || regmatch.startpos[0].col | |
2884 < best_regmatch.startpos[0].col) | |
2885 { | |
2886 best_idx = idx; | |
2887 best_regmatch.startpos[0] = regmatch.startpos[0]; | |
2888 best_regmatch.endpos[0] = regmatch.endpos[0]; | |
2889 } | |
2890 } | |
2891 } | |
2892 | |
2893 /* | |
2894 * If all end patterns have been tried, and there is no match, the | |
2895 * item continues until end-of-line. | |
2896 */ | |
2897 if (best_idx == -1) | |
2898 break; | |
2899 | |
2900 /* | |
2901 * If the skip pattern matches before the end pattern, | |
2902 * continue searching after the skip pattern. | |
2903 */ | |
2904 if (spp_skip != NULL) | |
2905 { | |
2906 int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; | |
6375 | 2907 int r; |
7 | 2908 |
2909 if (lc_col < 0) | |
2910 lc_col = 0; | |
2911 regmatch.rmm_ic = spp_skip->sp_ic; | |
2912 regmatch.regprog = spp_skip->sp_prog; | |
6375 | 2913 r = syn_regexec(®match, startpos->lnum, lc_col, |
2914 IF_SYN_TIME(&spp_skip->sp_time)); | |
2915 spp_skip->sp_prog = regmatch.regprog; | |
2916 if (r && regmatch.startpos[0].col | |
7 | 2917 <= best_regmatch.startpos[0].col) |
2918 { | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2919 int line_len; |
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2920 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2921 // Add offset to skip pattern match |
7 | 2922 syn_add_end_off(&pos, ®match, spp_skip, SPO_ME_OFF, 1); |
2923 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2924 // If the skip pattern goes on to the next line, there is no |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2925 // match with an end pattern in this line. |
7 | 2926 if (pos.lnum > startpos->lnum) |
2927 break; | |
2928 | |
2929 line = ml_get_buf(syn_buf, startpos->lnum, FALSE); | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2930 line_len = (int)STRLEN(line); |
7 | 2931 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2932 // take care of an empty match or negative offset |
7 | 2933 if (pos.col <= matchcol) |
2934 ++matchcol; | |
2935 else if (pos.col <= regmatch.endpos[0].col) | |
2936 matchcol = pos.col; | |
2937 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2938 // Be careful not to jump over the NUL at the end-of-line |
7 | 2939 for (matchcol = regmatch.endpos[0].col; |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2940 matchcol < line_len && matchcol < pos.col; |
7 | 2941 ++matchcol) |
2942 ; | |
2943 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2944 // if the skip pattern includes end-of-line, break here |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2945 if (matchcol >= line_len) |
7 | 2946 break; |
2947 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2948 continue; // start with first end pattern again |
7 | 2949 } |
2950 } | |
2951 | |
2952 /* | |
2953 * Match from start pattern to end pattern. | |
2954 * Correct for match and highlight offset of end pattern. | |
2955 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2956 spp = &(SYN_ITEMS(syn_block)[best_idx]); |
7 | 2957 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2958 // can't end before the start |
7 | 2959 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) |
2960 m_endpos->col = startpos->col; | |
2961 | |
2962 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2963 // can't end before the start |
7 | 2964 if (end_endpos->lnum == startpos->lnum |
2965 && end_endpos->col < startpos->col) | |
2966 end_endpos->col = startpos->col; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2967 // can't end after the match |
7 | 2968 limit_pos(end_endpos, m_endpos); |
2969 | |
2970 /* | |
2971 * If the end group is highlighted differently, adjust the pointers. | |
2972 */ | |
2973 if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) | |
2974 { | |
2975 *end_idx = best_idx; | |
2976 if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) | |
2977 { | |
2978 hl_endpos->lnum = best_regmatch.endpos[0].lnum; | |
2979 hl_endpos->col = best_regmatch.endpos[0].col; | |
2980 } | |
2981 else | |
2982 { | |
2983 hl_endpos->lnum = best_regmatch.startpos[0].lnum; | |
2984 hl_endpos->col = best_regmatch.startpos[0].col; | |
2985 } | |
2986 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; | |
2987 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2988 // can't end before the start |
7 | 2989 if (hl_endpos->lnum == startpos->lnum |
2990 && hl_endpos->col < startpos->col) | |
2991 hl_endpos->col = startpos->col; | |
2992 limit_pos(hl_endpos, m_endpos); | |
2993 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2994 // now the match ends where the highlighting ends, it is turned |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2995 // into the matchgroup for the end |
7 | 2996 *m_endpos = *hl_endpos; |
2997 } | |
2998 else | |
2999 { | |
3000 *end_idx = 0; | |
3001 *hl_endpos = *end_endpos; | |
3002 } | |
3003 | |
3004 *flagsp = spp->sp_flags; | |
3005 | |
3006 had_match = TRUE; | |
3007 break; | |
3008 } | |
3009 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3010 // no match for an END pattern in this line |
7 | 3011 if (!had_match) |
3012 m_endpos->lnum = 0; | |
3013 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3014 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3015 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3016 // Remove external matches. |
7 | 3017 unref_extmatch(re_extmatch_in); |
3018 re_extmatch_in = NULL; | |
3019 } | |
3020 | |
3021 /* | |
3022 * Limit "pos" not to be after "limit". | |
3023 */ | |
3024 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3025 limit_pos(lpos_T *pos, lpos_T *limit) |
7 | 3026 { |
3027 if (pos->lnum > limit->lnum) | |
3028 *pos = *limit; | |
3029 else if (pos->lnum == limit->lnum && pos->col > limit->col) | |
3030 pos->col = limit->col; | |
3031 } | |
3032 | |
3033 /* | |
3034 * Limit "pos" not to be after "limit", unless pos->lnum is zero. | |
3035 */ | |
3036 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3037 limit_pos_zero( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3038 lpos_T *pos, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3039 lpos_T *limit) |
7 | 3040 { |
3041 if (pos->lnum == 0) | |
3042 *pos = *limit; | |
3043 else | |
3044 limit_pos(pos, limit); | |
3045 } | |
3046 | |
3047 /* | |
3048 * Add offset to matched text for end of match or highlight. | |
3049 */ | |
3050 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3051 syn_add_end_off( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3052 lpos_T *result, // returned position |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3053 regmmatch_T *regmatch, // start/end of match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3054 synpat_T *spp, // matched pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3055 int idx, // index of offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3056 int extra) // extra chars for offset to start |
7 | 3057 { |
3058 int col; | |
1624 | 3059 int off; |
3060 char_u *base; | |
3061 char_u *p; | |
7 | 3062 |
3063 if (spp->sp_off_flags & (1 << idx)) | |
3064 { | |
3065 result->lnum = regmatch->startpos[0].lnum; | |
1624 | 3066 col = regmatch->startpos[0].col; |
3067 off = spp->sp_offsets[idx] + extra; | |
7 | 3068 } |
3069 else | |
3070 { | |
3071 result->lnum = regmatch->endpos[0].lnum; | |
3072 col = regmatch->endpos[0].col; | |
1624 | 3073 off = spp->sp_offsets[idx]; |
3074 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3075 // Don't go past the end of the line. Matters for "rs=e+2" when there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3076 // is a matchgroup. Watch out for match with last NL in the buffer. |
1624 | 3077 if (result->lnum > syn_buf->b_ml.ml_line_count) |
3078 col = 0; | |
3079 else if (off != 0) | |
3080 { | |
3081 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3082 p = base + col; | |
3083 if (off > 0) | |
3084 { | |
3085 while (off-- > 0 && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3086 MB_PTR_ADV(p); |
1624 | 3087 } |
3088 else if (off < 0) | |
3089 { | |
3090 while (off++ < 0 && base < p) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3091 MB_PTR_BACK(base, p); |
1624 | 3092 } |
3093 col = (int)(p - base); | |
3094 } | |
3095 result->col = col; | |
7 | 3096 } |
3097 | |
3098 /* | |
3099 * Add offset to matched text for start of match or highlight. | |
3100 * Avoid resulting column to become negative. | |
3101 */ | |
3102 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3103 syn_add_start_off( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3104 lpos_T *result, // returned position |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3105 regmmatch_T *regmatch, // start/end of match |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3106 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3107 int idx, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3108 int extra) // extra chars for offset to end |
7 | 3109 { |
3110 int col; | |
1624 | 3111 int off; |
3112 char_u *base; | |
3113 char_u *p; | |
7 | 3114 |
3115 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) | |
3116 { | |
3117 result->lnum = regmatch->endpos[0].lnum; | |
1624 | 3118 col = regmatch->endpos[0].col; |
3119 off = spp->sp_offsets[idx] + extra; | |
7 | 3120 } |
3121 else | |
3122 { | |
3123 result->lnum = regmatch->startpos[0].lnum; | |
3124 col = regmatch->startpos[0].col; | |
1624 | 3125 off = spp->sp_offsets[idx]; |
3126 } | |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3127 if (result->lnum > syn_buf->b_ml.ml_line_count) |
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3128 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3129 // a "\n" at the end of the pattern may take us below the last line |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3130 result->lnum = syn_buf->b_ml.ml_line_count; |
2100
7d121c69f540
updated for version 7.2.383
Bram Moolenaar <bram@zimbu.org>
parents:
2092
diff
changeset
|
3131 col = (int)STRLEN(ml_get_buf(syn_buf, result->lnum, FALSE)); |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3132 } |
1624 | 3133 if (off != 0) |
3134 { | |
3135 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3136 p = base + col; | |
3137 if (off > 0) | |
3138 { | |
3139 while (off-- && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3140 MB_PTR_ADV(p); |
1624 | 3141 } |
3142 else if (off < 0) | |
3143 { | |
3144 while (off++ && base < p) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3145 MB_PTR_BACK(base, p); |
1624 | 3146 } |
3147 col = (int)(p - base); | |
3148 } | |
3149 result->col = col; | |
7 | 3150 } |
3151 | |
3152 /* | |
3153 * Get current line in syntax buffer. | |
3154 */ | |
3155 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3156 syn_getcurline(void) |
7 | 3157 { |
3158 return ml_get_buf(syn_buf, current_lnum, FALSE); | |
3159 } | |
3160 | |
3161 /* | |
410 | 3162 * Call vim_regexec() to find a match with "rmp" in "syn_buf". |
7 | 3163 * Returns TRUE when there is a match. |
3164 */ | |
3165 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3166 syn_regexec( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3167 regmmatch_T *rmp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3168 linenr_T lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3169 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3170 syn_time_T *st UNUSED) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3171 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3172 int r; |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3173 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3174 int timed_out = FALSE; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3175 #endif |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3176 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3177 proftime_T pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3178 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3179 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3180 profile_start(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3181 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3182 |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3183 if (rmp->regprog == NULL) |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3184 // This can happen if a previous call to vim_regexec_multi() tried to |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3185 // use the NFA engine, which resulted in NFA_TOO_EXPENSIVE, and |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3186 // compiling the pattern with the other engine fails. |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3187 return FALSE; |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3188 |
410 | 3189 rmp->rmm_maxcol = syn_buf->b_p_smc; |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3190 r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3191 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3192 syn_tm, &timed_out |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3193 #else |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3194 NULL, NULL |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3195 #endif |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3196 ); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3197 |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3198 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3199 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3200 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3201 profile_end(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3202 profile_add(&st->total, &pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3203 if (profile_cmp(&pt, &st->slowest) < 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3204 st->slowest = pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3205 ++st->count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3206 if (r > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3207 ++st->match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3208 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3209 #endif |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3210 #ifdef FEAT_RELTIME |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3211 if (timed_out && !syn_win->w_s->b_syn_slow) |
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3212 { |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3213 syn_win->w_s->b_syn_slow = TRUE; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3214 msg(_("'redrawtime' exceeded, syntax highlighting disabled")); |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3215 } |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3216 #endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3217 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3218 if (r > 0) |
7 | 3219 { |
3220 rmp->startpos[0].lnum += lnum; | |
3221 rmp->endpos[0].lnum += lnum; | |
3222 return TRUE; | |
3223 } | |
3224 return FALSE; | |
3225 } | |
3226 | |
3227 /* | |
3228 * Check one position in a line for a matching keyword. | |
3229 * The caller must check if a keyword can start at startcol. | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3230 * Return its ID if found, 0 otherwise. |
7 | 3231 */ |
3232 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3233 check_keyword_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3234 char_u *line, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3235 int startcol, // position in line to check for keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3236 int *endcolp, // return: character after found keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3237 long *flagsp, // return: flags of matching keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3238 short **next_listp, // return: next_list of matching keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3239 stateitem_T *cur_si, // item at the top of the stack |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3240 int *ccharp UNUSED) // conceal substitution char |
7 | 3241 { |
134 | 3242 keyentry_T *kp; |
3243 char_u *kwp; | |
7 | 3244 int round; |
134 | 3245 int kwlen; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3246 char_u keyword[MAXKEYWLEN + 1]; // assume max. keyword len is 80 |
134 | 3247 hashtab_T *ht; |
3248 hashitem_T *hi; | |
7 | 3249 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3250 // Find first character after the keyword. First character was already |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3251 // checked. |
134 | 3252 kwp = line + startcol; |
3253 kwlen = 0; | |
7 | 3254 do |
3255 { | |
3256 if (has_mbyte) | |
474 | 3257 kwlen += (*mb_ptr2len)(kwp + kwlen); |
7 | 3258 else |
134 | 3259 ++kwlen; |
3260 } | |
4043 | 3261 while (vim_iswordp_buf(kwp + kwlen, syn_buf)); |
134 | 3262 |
3263 if (kwlen > MAXKEYWLEN) | |
7 | 3264 return 0; |
3265 | |
3266 /* | |
3267 * Must make a copy of the keyword, so we can add a NUL and make it | |
3268 * lowercase. | |
3269 */ | |
419 | 3270 vim_strncpy(keyword, kwp, kwlen); |
7 | 3271 |
3272 /* | |
3273 * Try twice: | |
3274 * 1. matching case | |
3275 * 2. ignoring case | |
3276 */ | |
3277 for (round = 1; round <= 2; ++round) | |
3278 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3279 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; |
134 | 3280 if (ht->ht_used == 0) |
7 | 3281 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3282 if (round == 2) // ignore case |
134 | 3283 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); |
7 | 3284 |
3285 /* | |
134 | 3286 * Find keywords that match. There can be several with different |
3287 * attributes. | |
7 | 3288 * When current_next_list is non-zero accept only that group, otherwise: |
3289 * Accept a not-contained keyword at toplevel. | |
3290 * Accept a keyword at other levels only if it is in the contains list. | |
3291 */ | |
134 | 3292 hi = hash_find(ht, keyword); |
3293 if (!HASHITEM_EMPTY(hi)) | |
3294 for (kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) | |
7 | 3295 { |
134 | 3296 if (current_next_list != 0 |
3297 ? in_id_list(NULL, current_next_list, &kp->k_syn, 0) | |
3298 : (cur_si == NULL | |
3299 ? !(kp->flags & HL_CONTAINED) | |
3300 : in_id_list(cur_si, cur_si->si_cont_list, | |
3301 &kp->k_syn, kp->flags & HL_CONTAINED))) | |
3302 { | |
3303 *endcolp = startcol + kwlen; | |
3304 *flagsp = kp->flags; | |
3305 *next_listp = kp->next_list; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3306 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3307 *ccharp = kp->k_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3308 #endif |
134 | 3309 return kp->k_syn.id; |
3310 } | |
7 | 3311 } |
3312 } | |
3313 return 0; | |
3314 } | |
3315 | |
3316 /* | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3317 * Handle ":syntax conceal" command. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3318 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3319 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3320 syn_cmd_conceal(exarg_T *eap UNUSED, int syncing UNUSED) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3321 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3322 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3323 char_u *arg = eap->arg; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3324 char_u *next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3325 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3326 eap->nextcmd = find_nextcmd(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3327 if (eap->skip) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3328 return; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3329 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3330 next = skiptowhite(arg); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3331 if (*arg == NUL) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3332 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3333 if (curwin->w_s->b_syn_conceal) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3334 msg(_("syntax conceal on")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3335 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3336 msg(_("syntax conceal off")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3337 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3338 else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3339 curwin->w_s->b_syn_conceal = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3340 else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3341 curwin->w_s->b_syn_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3342 else |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3343 semsg(_(e_illegal_arg), arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3344 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3345 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3346 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3347 /* |
7 | 3348 * Handle ":syntax case" command. |
3349 */ | |
3350 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3351 syn_cmd_case(exarg_T *eap, int syncing UNUSED) |
7 | 3352 { |
3353 char_u *arg = eap->arg; | |
3354 char_u *next; | |
3355 | |
3356 eap->nextcmd = find_nextcmd(arg); | |
3357 if (eap->skip) | |
3358 return; | |
3359 | |
3360 next = skiptowhite(arg); | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3361 if (*arg == NUL) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3362 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3363 if (curwin->w_s->b_syn_ic) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3364 msg(_("syntax case ignore")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3365 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3366 msg(_("syntax case match")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3367 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3368 else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3369 curwin->w_s->b_syn_ic = FALSE; |
7 | 3370 else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3371 curwin->w_s->b_syn_ic = TRUE; |
7 | 3372 else |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3373 semsg(_(e_illegal_arg), arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3374 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3375 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3376 /* |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3377 * Handle ":syntax foldlevel" command. |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3378 */ |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3379 static void |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3380 syn_cmd_foldlevel(exarg_T *eap, int syncing UNUSED) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3381 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3382 char_u *arg = eap->arg; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3383 char_u *arg_end; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3384 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3385 eap->nextcmd = find_nextcmd(arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3386 if (eap->skip) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3387 return; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3388 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3389 if (*arg == NUL) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3390 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3391 switch (curwin->w_s->b_syn_foldlevel) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3392 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3393 case SYNFLD_START: msg(_("syntax foldlevel start")); break; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3394 case SYNFLD_MINIMUM: msg(_("syntax foldlevel minimum")); break; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3395 default: break; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3396 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3397 return; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3398 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3399 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3400 arg_end = skiptowhite(arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3401 if (STRNICMP(arg, "start", 5) == 0 && arg_end - arg == 5) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3402 curwin->w_s->b_syn_foldlevel = SYNFLD_START; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3403 else if (STRNICMP(arg, "minimum", 7) == 0 && arg_end - arg == 7) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3404 curwin->w_s->b_syn_foldlevel = SYNFLD_MINIMUM; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3405 else |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3406 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3407 semsg(_(e_illegal_arg), arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3408 return; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3409 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3410 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3411 arg = skipwhite(arg_end); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3412 if (*arg != NUL) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3413 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3414 semsg(_(e_illegal_arg), arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3415 } |
7 | 3416 } |
3417 | |
3418 /* | |
419 | 3419 * Handle ":syntax spell" command. |
3420 */ | |
3421 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3422 syn_cmd_spell(exarg_T *eap, int syncing UNUSED) |
419 | 3423 { |
3424 char_u *arg = eap->arg; | |
3425 char_u *next; | |
3426 | |
3427 eap->nextcmd = find_nextcmd(arg); | |
3428 if (eap->skip) | |
3429 return; | |
3430 | |
3431 next = skiptowhite(arg); | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3432 if (*arg == NUL) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3433 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3434 if (curwin->w_s->b_syn_spell == SYNSPL_TOP) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3435 msg(_("syntax spell toplevel")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3436 else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3437 msg(_("syntax spell notoplevel")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3438 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3439 msg(_("syntax spell default")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3440 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3441 else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3442 curwin->w_s->b_syn_spell = SYNSPL_TOP; |
419 | 3443 else if (STRNICMP(arg, "notoplevel", 10) == 0 && next - arg == 10) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3444 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; |
1064 | 3445 else if (STRNICMP(arg, "default", 7) == 0 && next - arg == 7) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3446 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; |
419 | 3447 else |
6880 | 3448 { |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3449 semsg(_(e_illegal_arg), arg); |
6880 | 3450 return; |
3451 } | |
3452 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3453 // assume spell checking changed, force a redraw |
6880 | 3454 redraw_win_later(curwin, NOT_VALID); |
419 | 3455 } |
3456 | |
3457 /* | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3458 * Handle ":syntax iskeyword" command. |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3459 */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3460 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3461 syn_cmd_iskeyword(exarg_T *eap, int syncing UNUSED) |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3462 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3463 char_u *arg = eap->arg; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3464 char_u save_chartab[32]; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3465 char_u *save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3466 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3467 if (eap->skip) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3468 return; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3469 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3470 arg = skipwhite(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3471 if (*arg == NUL) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3472 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3473 msg_puts("\n"); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3474 if (curwin->w_s->b_syn_isk != empty_option) |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3475 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3476 msg_puts(_("syntax iskeyword ")); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3477 msg_outtrans(curwin->w_s->b_syn_isk); |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3478 } |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3479 else |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3480 msg_outtrans((char_u *)_("syntax iskeyword not set")); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3481 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3482 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3483 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3484 if (STRNICMP(arg, "clear", 5) == 0) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3485 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3486 mch_memmove(curwin->w_s->b_syn_chartab, curbuf->b_chartab, |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3487 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3488 clear_string_option(&curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3489 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3490 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3491 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3492 mch_memmove(save_chartab, curbuf->b_chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3493 save_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3494 curbuf->b_p_isk = vim_strsave(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3495 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3496 buf_init_chartab(curbuf, FALSE); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3497 mch_memmove(curwin->w_s->b_syn_chartab, curbuf->b_chartab, |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3498 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3499 mch_memmove(curbuf->b_chartab, save_chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3500 clear_string_option(&curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3501 curwin->w_s->b_syn_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3502 curbuf->b_p_isk = save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3503 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3504 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3505 redraw_win_later(curwin, NOT_VALID); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3506 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3507 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3508 /* |
7 | 3509 * Clear all syntax info for one buffer. |
3510 */ | |
3511 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3512 syntax_clear(synblock_T *block) |
7 | 3513 { |
3514 int i; | |
3515 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3516 block->b_syn_error = FALSE; // clear previous error |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3517 #ifdef FEAT_RELTIME |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3518 block->b_syn_slow = FALSE; // clear previous timeout |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3519 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3520 block->b_syn_ic = FALSE; // Use case, by default |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3521 block->b_syn_foldlevel = SYNFLD_START; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3522 block->b_syn_spell = SYNSPL_DEFAULT; // default spell checking |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3523 block->b_syn_containedin = FALSE; |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3524 #ifdef FEAT_CONCEAL |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3525 block->b_syn_conceal = FALSE; |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3526 #endif |
7 | 3527 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3528 // free the keywords |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3529 clear_keywtab(&block->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3530 clear_keywtab(&block->b_keywtab_ic); |
7 | 3531 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3532 // free the syntax patterns |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3533 for (i = block->b_syn_patterns.ga_len; --i >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3534 syn_clear_pattern(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3535 ga_clear(&block->b_syn_patterns); |
7 | 3536 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3537 // free the syntax clusters |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3538 for (i = block->b_syn_clusters.ga_len; --i >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3539 syn_clear_cluster(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3540 ga_clear(&block->b_syn_clusters); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3541 block->b_spell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3542 block->b_nospell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3543 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3544 block->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3545 block->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3546 block->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3547 block->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3548 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3549 vim_regfree(block->b_syn_linecont_prog); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3550 block->b_syn_linecont_prog = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
3551 VIM_CLEAR(block->b_syn_linecont_pat); |
7 | 3552 #ifdef FEAT_FOLDING |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3553 block->b_syn_folditems = 0; |
7 | 3554 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3555 clear_string_option(&block->b_syn_isk); |
7 | 3556 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3557 // free the stored states |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3558 syn_stack_free_all(block); |
7 | 3559 invalidate_current_state(); |
2743 | 3560 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3561 // Reset the counter for ":syn include" |
2743 | 3562 running_syn_inc_tag = 0; |
7 | 3563 } |
3564 | |
3565 /* | |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3566 * Get rid of ownsyntax for window "wp". |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3567 */ |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3568 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3569 reset_synblock(win_T *wp) |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3570 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3571 if (wp->w_s != &wp->w_buffer->b_s) |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3572 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3573 syntax_clear(wp->w_s); |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3574 vim_free(wp->w_s); |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3575 wp->w_s = &wp->w_buffer->b_s; |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3576 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3577 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3578 |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3579 /* |
7 | 3580 * Clear syncing info for one buffer. |
3581 */ | |
3582 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3583 syntax_sync_clear(void) |
7 | 3584 { |
3585 int i; | |
3586 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3587 // free the syntax patterns |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3588 for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3589 if (SYN_ITEMS(curwin->w_s)[i].sp_syncing) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3590 syn_remove_pattern(curwin->w_s, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3591 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3592 curwin->w_s->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3593 curwin->w_s->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3594 curwin->w_s->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3595 curwin->w_s->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3596 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3597 vim_regfree(curwin->w_s->b_syn_linecont_prog); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3598 curwin->w_s->b_syn_linecont_prog = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
3599 VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3600 clear_string_option(&curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3601 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3602 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 3603 } |
3604 | |
3605 /* | |
3606 * Remove one pattern from the buffer's pattern list. | |
3607 */ | |
3608 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3609 syn_remove_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3610 synblock_T *block, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3611 int idx) |
7 | 3612 { |
3613 synpat_T *spp; | |
3614 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3615 spp = &(SYN_ITEMS(block)[idx]); |
7 | 3616 #ifdef FEAT_FOLDING |
3617 if (spp->sp_flags & HL_FOLD) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3618 --block->b_syn_folditems; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3619 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3620 syn_clear_pattern(block, idx); |
7 | 3621 mch_memmove(spp, spp + 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3622 sizeof(synpat_T) * (block->b_syn_patterns.ga_len - idx - 1)); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3623 --block->b_syn_patterns.ga_len; |
7 | 3624 } |
3625 | |
3626 /* | |
3627 * Clear and free one syntax pattern. When clearing all, must be called from | |
3628 * last to first! | |
3629 */ | |
3630 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3631 syn_clear_pattern(synblock_T *block, int i) |
7 | 3632 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3633 vim_free(SYN_ITEMS(block)[i].sp_pattern); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3634 vim_regfree(SYN_ITEMS(block)[i].sp_prog); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3635 // Only free sp_cont_list and sp_next_list of first start pattern |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3636 if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3637 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3638 vim_free(SYN_ITEMS(block)[i].sp_cont_list); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3639 vim_free(SYN_ITEMS(block)[i].sp_next_list); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3640 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); |
7 | 3641 } |
3642 } | |
3643 | |
3644 /* | |
3645 * Clear and free one syntax cluster. | |
3646 */ | |
3647 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3648 syn_clear_cluster(synblock_T *block, int i) |
7 | 3649 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3650 vim_free(SYN_CLSTR(block)[i].scl_name); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3651 vim_free(SYN_CLSTR(block)[i].scl_name_u); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3652 vim_free(SYN_CLSTR(block)[i].scl_list); |
7 | 3653 } |
3654 | |
3655 /* | |
3656 * Handle ":syntax clear" command. | |
3657 */ | |
3658 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3659 syn_cmd_clear(exarg_T *eap, int syncing) |
7 | 3660 { |
3661 char_u *arg = eap->arg; | |
3662 char_u *arg_end; | |
3663 int id; | |
3664 | |
3665 eap->nextcmd = find_nextcmd(arg); | |
3666 if (eap->skip) | |
3667 return; | |
3668 | |
3669 /* | |
3670 * We have to disable this within ":syn include @group filename", | |
3671 * because otherwise @group would get deleted. | |
3672 * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn | |
3673 * clear". | |
3674 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3675 if (curwin->w_s->b_syn_topgrp != 0) |
7 | 3676 return; |
3677 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3678 if (ends_excmd2(eap->cmd, arg)) |
7 | 3679 { |
3680 /* | |
3681 * No argument: Clear all syntax items. | |
3682 */ | |
3683 if (syncing) | |
3684 syntax_sync_clear(); | |
3685 else | |
3686 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3687 syntax_clear(curwin->w_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3688 if (curwin->w_s == &curwin->w_buffer->b_s) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3689 do_unlet((char_u *)"b:current_syntax", TRUE); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
3690 do_unlet((char_u *)"w:current_syntax", TRUE); |
7 | 3691 } |
3692 } | |
3693 else | |
3694 { | |
3695 /* | |
3696 * Clear the group IDs that are in the argument. | |
3697 */ | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3698 while (!ends_excmd2(eap->cmd, arg)) |
7 | 3699 { |
3700 arg_end = skiptowhite(arg); | |
3701 if (*arg == '@') | |
3702 { | |
3703 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3704 if (id == 0) | |
3705 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
3706 semsg(_("E391: No such syntax cluster: %s"), arg); |
7 | 3707 break; |
3708 } | |
3709 else | |
3710 { | |
3711 /* | |
3712 * We can't physically delete a cluster without changing | |
3713 * the IDs of other clusters, so we do the next best thing | |
3714 * and make it empty. | |
3715 */ | |
3716 short scl_id = id - SYNID_CLUSTER; | |
3717 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
3718 VIM_CLEAR(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); |
7 | 3719 } |
3720 } | |
3721 else | |
3722 { | |
3723 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3724 if (id == 0) | |
3725 { | |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
3726 semsg(_(e_no_such_highlight_group_name_str), arg); |
7 | 3727 break; |
3728 } | |
3729 else | |
3730 syn_clear_one(id, syncing); | |
3731 } | |
3732 arg = skipwhite(arg_end); | |
3733 } | |
3734 } | |
745 | 3735 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3736 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 3737 } |
3738 | |
3739 /* | |
3740 * Clear one syntax group for the current buffer. | |
3741 */ | |
3742 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3743 syn_clear_one(int id, int syncing) |
7 | 3744 { |
3745 synpat_T *spp; | |
3746 int idx; | |
3747 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3748 // Clear keywords only when not ":syn sync clear group-name" |
7 | 3749 if (!syncing) |
3750 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3751 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3752 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); |
7 | 3753 } |
3754 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3755 // clear the patterns for "id" |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3756 for (idx = curwin->w_s->b_syn_patterns.ga_len; --idx >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3757 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3758 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3759 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3760 continue; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3761 syn_remove_pattern(curwin->w_s, idx); |
7 | 3762 } |
3763 } | |
3764 | |
3765 /* | |
3766 * Handle ":syntax on" command. | |
3767 */ | |
3768 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3769 syn_cmd_on(exarg_T *eap, int syncing UNUSED) |
7 | 3770 { |
3771 syn_cmd_onoff(eap, "syntax"); | |
3772 } | |
3773 | |
3774 /* | |
3775 * Handle ":syntax enable" command. | |
3776 */ | |
3777 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3778 syn_cmd_enable(exarg_T *eap, int syncing UNUSED) |
7 | 3779 { |
3780 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable"); | |
3781 syn_cmd_onoff(eap, "syntax"); | |
148 | 3782 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3783 } |
3784 | |
3785 /* | |
3786 * Handle ":syntax reset" command. | |
8815
50d9fb580ffe
commit https://github.com/vim/vim/commit/8bc189e81aa98ba4aebb03a9dc9527a210fce816
Christian Brabandt <cb@256bit.org>
parents:
8806
diff
changeset
|
3787 * It actually resets highlighting, not syntax. |
7 | 3788 */ |
3789 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3790 syn_cmd_reset(exarg_T *eap, int syncing UNUSED) |
7 | 3791 { |
3792 eap->nextcmd = check_nextcmd(eap->arg); | |
3793 if (!eap->skip) | |
3794 { | |
3795 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset"); | |
3796 do_cmdline_cmd((char_u *)"runtime! syntax/syncolor.vim"); | |
148 | 3797 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3798 } |
3799 } | |
3800 | |
3801 /* | |
3802 * Handle ":syntax manual" command. | |
3803 */ | |
3804 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3805 syn_cmd_manual(exarg_T *eap, int syncing UNUSED) |
7 | 3806 { |
3807 syn_cmd_onoff(eap, "manual"); | |
3808 } | |
3809 | |
3810 /* | |
3811 * Handle ":syntax off" command. | |
3812 */ | |
3813 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3814 syn_cmd_off(exarg_T *eap, int syncing UNUSED) |
7 | 3815 { |
3816 syn_cmd_onoff(eap, "nosyntax"); | |
3817 } | |
3818 | |
3819 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3820 syn_cmd_onoff(exarg_T *eap, char *name) |
7 | 3821 { |
3822 char_u buf[100]; | |
3823 | |
3824 eap->nextcmd = check_nextcmd(eap->arg); | |
3825 if (!eap->skip) | |
3826 { | |
3827 STRCPY(buf, "so "); | |
274 | 3828 vim_snprintf((char *)buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); |
7 | 3829 do_cmdline_cmd(buf); |
3830 } | |
3831 } | |
3832 | |
3833 /* | |
3834 * Handle ":syntax [list]" command: list current syntax words. | |
3835 */ | |
3836 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3837 syn_cmd_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3838 exarg_T *eap, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3839 int syncing) // when TRUE: list syncing items |
7 | 3840 { |
3841 char_u *arg = eap->arg; | |
3842 int id; | |
3843 char_u *arg_end; | |
3844 | |
3845 eap->nextcmd = find_nextcmd(arg); | |
3846 if (eap->skip) | |
3847 return; | |
3848 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3849 if (!syntax_present(curwin)) |
7 | 3850 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3851 msg(_(msg_no_items)); |
7 | 3852 return; |
3853 } | |
3854 | |
3855 if (syncing) | |
3856 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3857 if (curwin->w_s->b_syn_sync_flags & SF_CCOMMENT) |
7 | 3858 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3859 msg_puts(_("syncing on C-style comments")); |
7 | 3860 syn_lines_msg(); |
3861 syn_match_msg(); | |
3862 return; | |
3863 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3864 else if (!(curwin->w_s->b_syn_sync_flags & SF_MATCH)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3865 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3866 if (curwin->w_s->b_syn_sync_minlines == 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3867 msg_puts(_("no syncing")); |
7 | 3868 else |
3869 { | |
22928
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3870 if (curwin->w_s->b_syn_sync_minlines == MAXLNUM) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3871 msg_puts(_("syncing starts at the first line")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3872 else |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3873 { |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3874 msg_puts(_("syncing starts ")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3875 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3876 msg_puts(_(" lines before top line")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3877 } |
7 | 3878 syn_match_msg(); |
3879 } | |
3880 return; | |
3881 } | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3882 msg_puts_title(_("\n--- Syntax sync items ---")); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3883 if (curwin->w_s->b_syn_sync_minlines > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3884 || curwin->w_s->b_syn_sync_maxlines > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3885 || curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3886 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3887 msg_puts(_("\nsyncing on items")); |
7 | 3888 syn_lines_msg(); |
3889 syn_match_msg(); | |
3890 } | |
3891 } | |
3892 else | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3893 msg_puts_title(_("\n--- Syntax items ---")); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3894 if (ends_excmd2(eap->cmd, arg)) |
7 | 3895 { |
3896 /* | |
3897 * No argument: List all group IDs and all syntax clusters. | |
3898 */ | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
3899 for (id = 1; id <= highlight_num_groups() && !got_int; ++id) |
7 | 3900 syn_list_one(id, syncing, FALSE); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3901 for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) |
7 | 3902 syn_list_cluster(id); |
3903 } | |
3904 else | |
3905 { | |
3906 /* | |
3907 * List the group IDs and syntax clusters that are in the argument. | |
3908 */ | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3909 while (!ends_excmd2(eap->cmd, arg) && !got_int) |
7 | 3910 { |
3911 arg_end = skiptowhite(arg); | |
3912 if (*arg == '@') | |
3913 { | |
3914 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3915 if (id == 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
3916 semsg(_("E392: No such syntax cluster: %s"), arg); |
7 | 3917 else |
3918 syn_list_cluster(id - SYNID_CLUSTER); | |
3919 } | |
3920 else | |
3921 { | |
3922 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3923 if (id == 0) | |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
3924 semsg(_(e_no_such_highlight_group_name_str), arg); |
7 | 3925 else |
3926 syn_list_one(id, syncing, TRUE); | |
3927 } | |
3928 arg = skipwhite(arg_end); | |
3929 } | |
3930 } | |
3931 eap->nextcmd = check_nextcmd(arg); | |
3932 } | |
3933 | |
3934 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3935 syn_lines_msg(void) |
7 | 3936 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3937 if (curwin->w_s->b_syn_sync_maxlines > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3938 || curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3939 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3940 msg_puts("; "); |
22928
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3941 if (curwin->w_s->b_syn_sync_minlines == MAXLNUM) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3942 msg_puts(_("from the first line")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3943 else |
7 | 3944 { |
22928
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3945 if (curwin->w_s->b_syn_sync_minlines > 0) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3946 { |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3947 msg_puts(_("minimal ")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3948 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3949 if (curwin->w_s->b_syn_sync_maxlines) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3950 msg_puts(", "); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3951 } |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3952 if (curwin->w_s->b_syn_sync_maxlines > 0) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3953 { |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3954 msg_puts(_("maximal ")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3955 msg_outnum(curwin->w_s->b_syn_sync_maxlines); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3956 } |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3957 msg_puts(_(" lines before top line")); |
7 | 3958 } |
3959 } | |
3960 } | |
3961 | |
3962 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3963 syn_match_msg(void) |
7 | 3964 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3965 if (curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3966 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3967 msg_puts(_("; match ")); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3968 msg_outnum(curwin->w_s->b_syn_sync_linebreaks); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3969 msg_puts(_(" line breaks")); |
7 | 3970 } |
3971 } | |
3972 | |
3973 static int last_matchgroup; | |
3974 | |
3975 struct name_list | |
3976 { | |
3977 int flag; | |
3978 char *name; | |
3979 }; | |
3980 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
3981 static void syn_list_flags(struct name_list *nl, int flags, int attr); |
7 | 3982 |
3983 /* | |
3984 * List one syntax item, for ":syntax" or "syntax list syntax_name". | |
3985 */ | |
3986 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3987 syn_list_one( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3988 int id, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3989 int syncing, // when TRUE: list syncing items |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3990 int link_only) // when TRUE; list link-only too |
7 | 3991 { |
3992 int attr; | |
3993 int idx; | |
3994 int did_header = FALSE; | |
3995 synpat_T *spp; | |
3996 static struct name_list namelist1[] = | |
3997 { | |
3998 {HL_DISPLAY, "display"}, | |
3999 {HL_CONTAINED, "contained"}, | |
4000 {HL_ONELINE, "oneline"}, | |
4001 {HL_KEEPEND, "keepend"}, | |
4002 {HL_EXTEND, "extend"}, | |
4003 {HL_EXCLUDENL, "excludenl"}, | |
4004 {HL_TRANSP, "transparent"}, | |
4005 {HL_FOLD, "fold"}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4006 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4007 {HL_CONCEAL, "conceal"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4008 {HL_CONCEALENDS, "concealends"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4009 #endif |
7 | 4010 {0, NULL} |
4011 }; | |
4012 static struct name_list namelist2[] = | |
4013 { | |
4014 {HL_SKIPWHITE, "skipwhite"}, | |
4015 {HL_SKIPNL, "skipnl"}, | |
4016 {HL_SKIPEMPTY, "skipempty"}, | |
4017 {0, NULL} | |
4018 }; | |
4019 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4020 attr = HL_ATTR(HLF_D); // highlight like directories |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4021 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4022 // list the keywords for "id" |
7 | 4023 if (!syncing) |
4024 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4025 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab, FALSE, attr); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4026 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, |
7 | 4027 did_header, attr); |
4028 } | |
4029 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4030 // list the patterns for "id" |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4031 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len && !got_int; ++idx) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4032 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4033 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 4034 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
4035 continue; | |
4036 | |
4037 (void)syn_list_header(did_header, 999, id); | |
4038 did_header = TRUE; | |
4039 last_matchgroup = 0; | |
4040 if (spp->sp_type == SPTYPE_MATCH) | |
4041 { | |
4042 put_pattern("match", ' ', spp, attr); | |
4043 msg_putchar(' '); | |
4044 } | |
4045 else if (spp->sp_type == SPTYPE_START) | |
4046 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4047 while (SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_START) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4048 put_pattern("start", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4049 if (SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_SKIP) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4050 put_pattern("skip", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4051 while (idx < curwin->w_s->b_syn_patterns.ga_len |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4052 && SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4053 put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
7 | 4054 --idx; |
4055 msg_putchar(' '); | |
4056 } | |
4057 syn_list_flags(namelist1, spp->sp_flags, attr); | |
4058 | |
4059 if (spp->sp_cont_list != NULL) | |
4060 put_id_list((char_u *)"contains", spp->sp_cont_list, attr); | |
4061 | |
4062 if (spp->sp_syn.cont_in_list != NULL) | |
4063 put_id_list((char_u *)"containedin", | |
4064 spp->sp_syn.cont_in_list, attr); | |
4065 | |
4066 if (spp->sp_next_list != NULL) | |
4067 { | |
4068 put_id_list((char_u *)"nextgroup", spp->sp_next_list, attr); | |
4069 syn_list_flags(namelist2, spp->sp_flags, attr); | |
4070 } | |
4071 if (spp->sp_flags & (HL_SYNC_HERE|HL_SYNC_THERE)) | |
4072 { | |
4073 if (spp->sp_flags & HL_SYNC_HERE) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4074 msg_puts_attr("grouphere", attr); |
7 | 4075 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4076 msg_puts_attr("groupthere", attr); |
7 | 4077 msg_putchar(' '); |
4078 if (spp->sp_sync_idx >= 0) | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4079 msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s) |
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4080 [spp->sp_sync_idx].sp_syn.id - 1)); |
7 | 4081 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4082 msg_puts("NONE"); |
7 | 4083 msg_putchar(' '); |
4084 } | |
4085 } | |
4086 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4087 // list the link, if there is one |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4088 if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int) |
7 | 4089 { |
4090 (void)syn_list_header(did_header, 999, id); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4091 msg_puts_attr("links to", attr); |
7 | 4092 msg_putchar(' '); |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4093 msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1)); |
7 | 4094 } |
4095 } | |
4096 | |
4097 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4098 syn_list_flags(struct name_list *nlist, int flags, int attr) |
7 | 4099 { |
4100 int i; | |
4101 | |
3263 | 4102 for (i = 0; nlist[i].flag != 0; ++i) |
4103 if (flags & nlist[i].flag) | |
4104 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4105 msg_puts_attr(nlist[i].name, attr); |
7 | 4106 msg_putchar(' '); |
4107 } | |
4108 } | |
4109 | |
4110 /* | |
4111 * List one syntax cluster, for ":syntax" or "syntax list syntax_name". | |
4112 */ | |
4113 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4114 syn_list_cluster(int id) |
7 | 4115 { |
4116 int endcol = 15; | |
4117 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4118 // slight hack: roughly duplicate the guts of syn_list_header() |
7 | 4119 msg_putchar('\n'); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4120 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); |
7 | 4121 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4122 if (msg_col >= endcol) // output at least one space |
7 | 4123 endcol = msg_col + 1; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4124 if (Columns <= endcol) // avoid hang for tiny window |
7 | 4125 endcol = Columns - 1; |
4126 | |
4127 msg_advance(endcol); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4128 if (SYN_CLSTR(curwin->w_s)[id].scl_list != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4129 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4130 put_id_list((char_u *)"cluster", SYN_CLSTR(curwin->w_s)[id].scl_list, |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4131 HL_ATTR(HLF_D)); |
7 | 4132 } |
4133 else | |
4134 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4135 msg_puts_attr("cluster", HL_ATTR(HLF_D)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4136 msg_puts("=NONE"); |
7 | 4137 } |
4138 } | |
4139 | |
4140 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4141 put_id_list(char_u *name, short *list, int attr) |
7 | 4142 { |
4143 short *p; | |
4144 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4145 msg_puts_attr((char *)name, attr); |
7 | 4146 msg_putchar('='); |
4147 for (p = list; *p; ++p) | |
4148 { | |
4149 if (*p >= SYNID_ALLBUT && *p < SYNID_TOP) | |
4150 { | |
4151 if (p[1]) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4152 msg_puts("ALLBUT"); |
7 | 4153 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4154 msg_puts("ALL"); |
7 | 4155 } |
4156 else if (*p >= SYNID_TOP && *p < SYNID_CONTAINED) | |
4157 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4158 msg_puts("TOP"); |
7 | 4159 } |
4160 else if (*p >= SYNID_CONTAINED && *p < SYNID_CLUSTER) | |
4161 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4162 msg_puts("CONTAINED"); |
7 | 4163 } |
4164 else if (*p >= SYNID_CLUSTER) | |
4165 { | |
4166 short scl_id = *p - SYNID_CLUSTER; | |
4167 | |
4168 msg_putchar('@'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4169 msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); |
7 | 4170 } |
4171 else | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4172 msg_outtrans(highlight_group_name(*p - 1)); |
7 | 4173 if (p[1]) |
4174 msg_putchar(','); | |
4175 } | |
4176 msg_putchar(' '); | |
4177 } | |
4178 | |
4179 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4180 put_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4181 char *s, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4182 int c, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4183 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4184 int attr) |
7 | 4185 { |
4186 long n; | |
4187 int mask; | |
4188 int first; | |
4189 static char *sepchars = "/+=-#@\"|'^&"; | |
4190 int i; | |
4191 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4192 // May have to write "matchgroup=group" |
7 | 4193 if (last_matchgroup != spp->sp_syn_match_id) |
4194 { | |
4195 last_matchgroup = spp->sp_syn_match_id; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4196 msg_puts_attr("matchgroup", attr); |
7 | 4197 msg_putchar('='); |
4198 if (last_matchgroup == 0) | |
4199 msg_outtrans((char_u *)"NONE"); | |
4200 else | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4201 msg_outtrans(highlight_group_name(last_matchgroup - 1)); |
7 | 4202 msg_putchar(' '); |
4203 } | |
4204 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4205 // output the name of the pattern and an '=' or ' ' |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4206 msg_puts_attr(s, attr); |
7 | 4207 msg_putchar(c); |
4208 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4209 // output the pattern, in between a char that is not in the pattern |
7 | 4210 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) |
4211 if (sepchars[++i] == NUL) | |
4212 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4213 i = 0; // no good char found, just use the first one |
7 | 4214 break; |
4215 } | |
4216 msg_putchar(sepchars[i]); | |
4217 msg_outtrans(spp->sp_pattern); | |
4218 msg_putchar(sepchars[i]); | |
4219 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4220 // output any pattern options |
7 | 4221 first = TRUE; |
4222 for (i = 0; i < SPO_COUNT; ++i) | |
4223 { | |
4224 mask = (1 << i); | |
4225 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) | |
4226 { | |
4227 if (!first) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4228 msg_putchar(','); // separate with commas |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4229 msg_puts(spo_name_tab[i]); |
7 | 4230 n = spp->sp_offsets[i]; |
4231 if (i != SPO_LC_OFF) | |
4232 { | |
4233 if (spp->sp_off_flags & mask) | |
4234 msg_putchar('s'); | |
4235 else | |
4236 msg_putchar('e'); | |
4237 if (n > 0) | |
4238 msg_putchar('+'); | |
4239 } | |
4240 if (n || i == SPO_LC_OFF) | |
4241 msg_outnum(n); | |
4242 first = FALSE; | |
4243 } | |
4244 } | |
4245 msg_putchar(' '); | |
4246 } | |
4247 | |
4248 /* | |
4249 * List or clear the keywords for one syntax group. | |
4250 * Return TRUE if the header has been printed. | |
4251 */ | |
4252 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4253 syn_list_keywords( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4254 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4255 hashtab_T *ht, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4256 int did_header, // header has already been printed |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4257 int attr) |
7 | 4258 { |
4259 int outlen; | |
134 | 4260 hashitem_T *hi; |
4261 keyentry_T *kp; | |
4262 int todo; | |
7 | 4263 int prev_contained = 0; |
4264 short *prev_next_list = NULL; | |
4265 short *prev_cont_in_list = NULL; | |
4266 int prev_skipnl = 0; | |
4267 int prev_skipwhite = 0; | |
4268 int prev_skipempty = 0; | |
4269 | |
4270 /* | |
4271 * Unfortunately, this list of keywords is not sorted on alphabet but on | |
4272 * hash value... | |
4273 */ | |
835 | 4274 todo = (int)ht->ht_used; |
134 | 4275 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
4276 { | |
4277 if (!HASHITEM_EMPTY(hi)) | |
4278 { | |
4279 --todo; | |
4280 for (kp = HI2KE(hi); kp != NULL && !got_int; kp = kp->ke_next) | |
7 | 4281 { |
134 | 4282 if (kp->k_syn.id == id) |
7 | 4283 { |
134 | 4284 if (prev_contained != (kp->flags & HL_CONTAINED) |
4285 || prev_skipnl != (kp->flags & HL_SKIPNL) | |
4286 || prev_skipwhite != (kp->flags & HL_SKIPWHITE) | |
4287 || prev_skipempty != (kp->flags & HL_SKIPEMPTY) | |
4288 || prev_cont_in_list != kp->k_syn.cont_in_list | |
4289 || prev_next_list != kp->next_list) | |
4290 outlen = 9999; | |
4291 else | |
4292 outlen = (int)STRLEN(kp->keyword); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4293 // output "contained" and "nextgroup" on each line |
134 | 4294 if (syn_list_header(did_header, outlen, id)) |
4295 { | |
4296 prev_contained = 0; | |
4297 prev_next_list = NULL; | |
4298 prev_cont_in_list = NULL; | |
4299 prev_skipnl = 0; | |
4300 prev_skipwhite = 0; | |
4301 prev_skipempty = 0; | |
4302 } | |
4303 did_header = TRUE; | |
4304 if (prev_contained != (kp->flags & HL_CONTAINED)) | |
4305 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4306 msg_puts_attr("contained", attr); |
134 | 4307 msg_putchar(' '); |
4308 prev_contained = (kp->flags & HL_CONTAINED); | |
4309 } | |
4310 if (kp->k_syn.cont_in_list != prev_cont_in_list) | |
4311 { | |
4312 put_id_list((char_u *)"containedin", | |
4313 kp->k_syn.cont_in_list, attr); | |
4314 msg_putchar(' '); | |
4315 prev_cont_in_list = kp->k_syn.cont_in_list; | |
4316 } | |
4317 if (kp->next_list != prev_next_list) | |
4318 { | |
4319 put_id_list((char_u *)"nextgroup", kp->next_list, attr); | |
4320 msg_putchar(' '); | |
4321 prev_next_list = kp->next_list; | |
4322 if (kp->flags & HL_SKIPNL) | |
4323 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4324 msg_puts_attr("skipnl", attr); |
134 | 4325 msg_putchar(' '); |
4326 prev_skipnl = (kp->flags & HL_SKIPNL); | |
4327 } | |
4328 if (kp->flags & HL_SKIPWHITE) | |
4329 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4330 msg_puts_attr("skipwhite", attr); |
134 | 4331 msg_putchar(' '); |
4332 prev_skipwhite = (kp->flags & HL_SKIPWHITE); | |
4333 } | |
4334 if (kp->flags & HL_SKIPEMPTY) | |
4335 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4336 msg_puts_attr("skipempty", attr); |
134 | 4337 msg_putchar(' '); |
4338 prev_skipempty = (kp->flags & HL_SKIPEMPTY); | |
4339 } | |
4340 } | |
4341 msg_outtrans(kp->keyword); | |
7 | 4342 } |
4343 } | |
4344 } | |
4345 } | |
4346 | |
4347 return did_header; | |
4348 } | |
4349 | |
4350 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4351 syn_clear_keyword(int id, hashtab_T *ht) |
134 | 4352 { |
4353 hashitem_T *hi; | |
4354 keyentry_T *kp; | |
4355 keyentry_T *kp_prev; | |
4356 keyentry_T *kp_next; | |
4357 int todo; | |
4358 | |
4359 hash_lock(ht); | |
835 | 4360 todo = (int)ht->ht_used; |
134 | 4361 for (hi = ht->ht_array; todo > 0; ++hi) |
4362 { | |
4363 if (!HASHITEM_EMPTY(hi)) | |
4364 { | |
4365 --todo; | |
4366 kp_prev = NULL; | |
4367 for (kp = HI2KE(hi); kp != NULL; ) | |
7 | 4368 { |
134 | 4369 if (kp->k_syn.id == id) |
4370 { | |
4371 kp_next = kp->ke_next; | |
4372 if (kp_prev == NULL) | |
4373 { | |
4374 if (kp_next == NULL) | |
4375 hash_remove(ht, hi); | |
4376 else | |
4377 hi->hi_key = KE2HIKEY(kp_next); | |
4378 } | |
4379 else | |
4380 kp_prev->ke_next = kp_next; | |
4381 vim_free(kp->next_list); | |
4382 vim_free(kp->k_syn.cont_in_list); | |
4383 vim_free(kp); | |
4384 kp = kp_next; | |
4385 } | |
7 | 4386 else |
134 | 4387 { |
4388 kp_prev = kp; | |
4389 kp = kp->ke_next; | |
4390 } | |
7 | 4391 } |
134 | 4392 } |
4393 } | |
4394 hash_unlock(ht); | |
4395 } | |
4396 | |
4397 /* | |
4398 * Clear a whole keyword table. | |
7 | 4399 */ |
4400 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4401 clear_keywtab(hashtab_T *ht) |
134 | 4402 { |
4403 hashitem_T *hi; | |
4404 int todo; | |
4405 keyentry_T *kp; | |
4406 keyentry_T *kp_next; | |
4407 | |
835 | 4408 todo = (int)ht->ht_used; |
134 | 4409 for (hi = ht->ht_array; todo > 0; ++hi) |
4410 { | |
4411 if (!HASHITEM_EMPTY(hi)) | |
4412 { | |
4413 --todo; | |
4414 for (kp = HI2KE(hi); kp != NULL; kp = kp_next) | |
7 | 4415 { |
134 | 4416 kp_next = kp->ke_next; |
4417 vim_free(kp->next_list); | |
4418 vim_free(kp->k_syn.cont_in_list); | |
4419 vim_free(kp); | |
7 | 4420 } |
134 | 4421 } |
4422 } | |
4423 hash_clear(ht); | |
4424 hash_init(ht); | |
7 | 4425 } |
4426 | |
4427 /* | |
4428 * Add a keyword to the list of keywords. | |
4429 */ | |
4430 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4431 add_keyword( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4432 char_u *name, // name of keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4433 int id, // group ID for this keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4434 int flags, // flags for this keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4435 short *cont_in_list, // containedin for this keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4436 short *next_list, // nextgroup for this keyword |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4437 int conceal_char) |
7 | 4438 { |
134 | 4439 keyentry_T *kp; |
4440 hashtab_T *ht; | |
4441 hashitem_T *hi; | |
154 | 4442 char_u *name_ic; |
134 | 4443 long_u hash; |
154 | 4444 char_u name_folded[MAXKEYWLEN + 1]; |
7 | 4445 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4446 if (curwin->w_s->b_syn_ic) |
154 | 4447 name_ic = str_foldcase(name, (int)STRLEN(name), |
4448 name_folded, MAXKEYWLEN + 1); | |
4449 else | |
4450 name_ic = name; | |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17401
diff
changeset
|
4451 kp = alloc(offsetof(keyentry_T, keyword) + STRLEN(name_ic) + 1); |
134 | 4452 if (kp == NULL) |
4453 return; | |
4454 STRCPY(kp->keyword, name_ic); | |
4455 kp->k_syn.id = id; | |
4456 kp->k_syn.inc_tag = current_syn_inc_tag; | |
4457 kp->flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4458 kp->k_char = conceal_char; |
134 | 4459 kp->k_syn.cont_in_list = copy_id_list(cont_in_list); |
4460 if (cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4461 curwin->w_s->b_syn_containedin = TRUE; |
134 | 4462 kp->next_list = copy_id_list(next_list); |
4463 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4464 if (curwin->w_s->b_syn_ic) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4465 ht = &curwin->w_s->b_keywtab_ic; |
7 | 4466 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4467 ht = &curwin->w_s->b_keywtab; |
134 | 4468 |
4469 hash = hash_hash(kp->keyword); | |
4470 hi = hash_lookup(ht, kp->keyword, hash); | |
4471 if (HASHITEM_EMPTY(hi)) | |
4472 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4473 // new keyword, add to hashtable |
134 | 4474 kp->ke_next = NULL; |
4475 hash_add_item(ht, hi, kp->keyword, hash); | |
4476 } | |
4477 else | |
4478 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4479 // keyword already exists, prepend to list |
134 | 4480 kp->ke_next = HI2KE(hi); |
4481 hi->hi_key = KE2HIKEY(kp); | |
4482 } | |
7 | 4483 } |
4484 | |
4485 /* | |
4486 * Get the start and end of the group name argument. | |
4487 * Return a pointer to the first argument. | |
4488 * Return NULL if the end of the command was found instead of further args. | |
4489 */ | |
4490 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4491 get_group_name( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4492 char_u *arg, // start of the argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4493 char_u **name_end) // pointer to end of the name |
7 | 4494 { |
4495 char_u *rest; | |
4496 | |
4497 *name_end = skiptowhite(arg); | |
4498 rest = skipwhite(*name_end); | |
4499 | |
4500 /* | |
4501 * Check if there are enough arguments. The first argument may be a | |
4502 * pattern, where '|' is allowed, so only check for NUL. | |
4503 */ | |
4504 if (ends_excmd(*arg) || *rest == NUL) | |
4505 return NULL; | |
4506 return rest; | |
4507 } | |
4508 | |
4509 /* | |
4510 * Check for syntax command option arguments. | |
4511 * This can be called at any place in the list of arguments, and just picks | |
4512 * out the arguments that are known. Can be called several times in a row to | |
4513 * collect all options in between other arguments. | |
4514 * Return a pointer to the next argument (which isn't an option). | |
4515 * Return NULL for any error; | |
4516 */ | |
4517 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4518 get_syn_options( |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4519 char_u *start, // next argument to be checked |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4520 syn_opt_arg_T *opt, // various things |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4521 int *conceal_char UNUSED, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4522 int skip) // TRUE if skipping over command |
154 | 4523 { |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4524 char_u *arg = start; |
7 | 4525 char_u *gname_start, *gname; |
4526 int syn_id; | |
4527 int len; | |
154 | 4528 char *p; |
7 | 4529 int i; |
4530 int fidx; | |
4531 static struct flag | |
4532 { | |
4533 char *name; | |
154 | 4534 int argtype; |
4535 int flags; | |
4536 } flagtab[] = { {"cCoOnNtTaAiInNeEdD", 0, HL_CONTAINED}, | |
4537 {"oOnNeElLiInNeE", 0, HL_ONELINE}, | |
4538 {"kKeEeEpPeEnNdD", 0, HL_KEEPEND}, | |
4539 {"eExXtTeEnNdD", 0, HL_EXTEND}, | |
4540 {"eExXcClLuUdDeEnNlL", 0, HL_EXCLUDENL}, | |
4541 {"tTrRaAnNsSpPaArReEnNtT", 0, HL_TRANSP}, | |
4542 {"sSkKiIpPnNlL", 0, HL_SKIPNL}, | |
4543 {"sSkKiIpPwWhHiItTeE", 0, HL_SKIPWHITE}, | |
4544 {"sSkKiIpPeEmMpPtTyY", 0, HL_SKIPEMPTY}, | |
4545 {"gGrRoOuUpPhHeErReE", 0, HL_SYNC_HERE}, | |
4546 {"gGrRoOuUpPtThHeErReE", 0, HL_SYNC_THERE}, | |
4547 {"dDiIsSpPlLaAyY", 0, HL_DISPLAY}, | |
4548 {"fFoOlLdD", 0, HL_FOLD}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4549 {"cCoOnNcCeEaAlL", 0, HL_CONCEAL}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4550 {"cCoOnNcCeEaAlLeEnNdDsS", 0, HL_CONCEALENDS}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4551 {"cCcChHaArR", 11, 0}, |
154 | 4552 {"cCoOnNtTaAiInNsS", 1, 0}, |
4553 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, | |
4554 {"nNeExXtTgGrRoOuUpP", 3, 0}, | |
7 | 4555 }; |
154 | 4556 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; |
7 | 4557 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4558 if (arg == NULL) // already detected error |
7 | 4559 return NULL; |
4560 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4561 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4562 if (curwin->w_s->b_syn_conceal) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4563 opt->flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4564 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4565 |
7 | 4566 for (;;) |
4567 { | |
154 | 4568 /* |
4569 * This is used very often when a large number of keywords is defined. | |
4570 * Need to skip quickly when no option name is found. | |
4571 * Also avoid tolower(), it's slow. | |
4572 */ | |
4573 if (strchr(first_letters, *arg) == NULL) | |
4574 break; | |
7 | 4575 |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24442
diff
changeset
|
4576 for (fidx = ARRAY_LENGTH(flagtab); --fidx >= 0; ) |
7 | 4577 { |
154 | 4578 p = flagtab[fidx].name; |
4579 for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) | |
4580 if (arg[len] != p[i] && arg[len] != p[i + 1]) | |
4581 break; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4582 if (p[i] == NUL && (VIM_ISWHITE(arg[len]) |
154 | 4583 || (flagtab[fidx].argtype > 0 |
4584 ? arg[len] == '=' | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4585 : ends_excmd2(start, arg + len)))) |
7 | 4586 { |
154 | 4587 if (opt->keyword |
4588 && (flagtab[fidx].flags == HL_DISPLAY | |
4589 || flagtab[fidx].flags == HL_FOLD | |
4590 || flagtab[fidx].flags == HL_EXTEND)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4591 // treat "display", "fold" and "extend" as a keyword |
7 | 4592 fidx = -1; |
4593 break; | |
4594 } | |
4595 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4596 if (fidx < 0) // no match found |
154 | 4597 break; |
4598 | |
4599 if (flagtab[fidx].argtype == 1) | |
4600 { | |
4601 if (!opt->has_cont_list) | |
7 | 4602 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4603 emsg(_("E395: contains argument not accepted here")); |
7 | 4604 return NULL; |
4605 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4606 if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) |
7 | 4607 return NULL; |
4608 } | |
154 | 4609 else if (flagtab[fidx].argtype == 2) |
4610 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4611 if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL) |
7 | 4612 return NULL; |
4613 } | |
154 | 4614 else if (flagtab[fidx].argtype == 3) |
4615 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4616 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) |
7 | 4617 return NULL; |
4618 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4619 else if (flagtab[fidx].argtype == 11 && arg[5] == '=') |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4620 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4621 // cchar=? |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4622 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4623 { |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4624 #ifdef FEAT_CONCEAL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4625 *conceal_char = mb_ptr2char(arg + 6); |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4626 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4627 arg += mb_ptr2len(arg + 6) - 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4628 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4629 else |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4630 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4631 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4632 *conceal_char = arg[6]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4633 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4634 ; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4635 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4636 } |
2686 | 4637 #ifdef FEAT_CONCEAL |
4638 if (!vim_isprintc_strict(*conceal_char)) | |
4639 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4640 emsg(_("E844: invalid cchar value")); |
2686 | 4641 return NULL; |
4642 } | |
4643 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4644 arg = skipwhite(arg + 7); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4645 } |
7 | 4646 else |
154 | 4647 { |
4648 opt->flags |= flagtab[fidx].flags; | |
4649 arg = skipwhite(arg + len); | |
4650 | |
4651 if (flagtab[fidx].flags == HL_SYNC_HERE | |
4652 || flagtab[fidx].flags == HL_SYNC_THERE) | |
4653 { | |
4654 if (opt->sync_idx == NULL) | |
4655 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4656 emsg(_("E393: group[t]here not accepted here")); |
154 | 4657 return NULL; |
4658 } | |
4659 gname_start = arg; | |
4660 arg = skiptowhite(arg); | |
4661 if (gname_start == arg) | |
4662 return NULL; | |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
4663 gname = vim_strnsave(gname_start, arg - gname_start); |
154 | 4664 if (gname == NULL) |
4665 return NULL; | |
4666 if (STRCMP(gname, "NONE") == 0) | |
4667 *opt->sync_idx = NONE_IDX; | |
4668 else | |
4669 { | |
4670 syn_id = syn_name2id(gname); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4671 for (i = curwin->w_s->b_syn_patterns.ga_len; --i >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4672 if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
4673 && SYN_ITEMS(curwin->w_s)[i].sp_type |
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
4674 == SPTYPE_START) |
154 | 4675 { |
4676 *opt->sync_idx = i; | |
4677 break; | |
4678 } | |
4679 if (i < 0) | |
4680 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4681 semsg(_("E394: Didn't find region item for %s"), gname); |
154 | 4682 vim_free(gname); |
4683 return NULL; | |
4684 } | |
4685 } | |
4686 | |
4687 vim_free(gname); | |
4688 arg = skipwhite(arg); | |
4689 } | |
4690 #ifdef FEAT_FOLDING | |
4691 else if (flagtab[fidx].flags == HL_FOLD | |
4692 && foldmethodIsSyntax(curwin)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4693 // Need to update folds later. |
154 | 4694 foldUpdateAll(curwin); |
4695 #endif | |
4696 } | |
4697 } | |
7 | 4698 |
4699 return arg; | |
4700 } | |
4701 | |
4702 /* | |
4703 * Adjustments to syntax item when declared in a ":syn include"'d file. | |
4704 * Set the contained flag, and if the item is not already contained, add it | |
4705 * to the specified top-level group, if any. | |
4706 */ | |
4707 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4708 syn_incl_toplevel(int id, int *flagsp) |
7 | 4709 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4710 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) |
7 | 4711 return; |
4712 *flagsp |= HL_CONTAINED; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4713 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
7 | 4714 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4715 // We have to alloc this, because syn_combine_list() will free it. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
4716 short *grp_list = ALLOC_MULT(short, 2); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4717 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; |
7 | 4718 |
4719 if (grp_list != NULL) | |
4720 { | |
4721 grp_list[0] = id; | |
4722 grp_list[1] = 0; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
4723 syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
4724 &grp_list, CLUSTER_ADD); |
7 | 4725 } |
4726 } | |
4727 } | |
4728 | |
4729 /* | |
4730 * Handle ":syntax include [@{group-name}] filename" command. | |
4731 */ | |
4732 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4733 syn_cmd_include(exarg_T *eap, int syncing UNUSED) |
7 | 4734 { |
4735 char_u *arg = eap->arg; | |
4736 int sgl_id = 1; | |
4737 char_u *group_name_end; | |
4738 char_u *rest; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4739 char *errormsg = NULL; |
7 | 4740 int prev_toplvl_grp; |
4741 int prev_syn_inc_tag; | |
4742 int source = FALSE; | |
4743 | |
4744 eap->nextcmd = find_nextcmd(arg); | |
4745 if (eap->skip) | |
4746 return; | |
4747 | |
4748 if (arg[0] == '@') | |
4749 { | |
4750 ++arg; | |
4751 rest = get_group_name(arg, &group_name_end); | |
4752 if (rest == NULL) | |
4753 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4754 emsg(_("E397: Filename required")); |
7 | 4755 return; |
4756 } | |
4757 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
2743 | 4758 if (sgl_id == 0) |
4759 return; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4760 // separate_nextcmd() and expand_filename() depend on this |
7 | 4761 eap->arg = rest; |
4762 } | |
4763 | |
4764 /* | |
4765 * Everything that's left, up to the next command, should be the | |
4766 * filename to include. | |
4767 */ | |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
17227
diff
changeset
|
4768 eap->argt |= (EX_XFILE | EX_NOSPC); |
7 | 4769 separate_nextcmd(eap); |
4770 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) | |
4771 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4772 // For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4773 // file. Need to expand the file name first. In other cases |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4774 // ":runtime!" is used. |
7 | 4775 source = TRUE; |
4776 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) | |
4777 { | |
4778 if (errormsg != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4779 emsg(errormsg); |
7 | 4780 return; |
4781 } | |
4782 } | |
4783 | |
4784 /* | |
4785 * Save and restore the existing top-level grouplist id and ":syn | |
4786 * include" tag around the actual inclusion. | |
4787 */ | |
2743 | 4788 if (running_syn_inc_tag >= MAX_SYN_INC_TAG) |
4789 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4790 emsg(_("E847: Too many syntax includes")); |
2743 | 4791 return; |
4792 } | |
7 | 4793 prev_syn_inc_tag = current_syn_inc_tag; |
4794 current_syn_inc_tag = ++running_syn_inc_tag; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4795 prev_toplvl_grp = curwin->w_s->b_syn_topgrp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4796 curwin->w_s->b_syn_topgrp = sgl_id; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4797 if (source ? do_source(eap->arg, FALSE, DOSO_NONE, NULL) == FAIL |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
4798 : source_runtime(eap->arg, DIP_ALL) == FAIL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4799 semsg(_(e_notopen), eap->arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4800 curwin->w_s->b_syn_topgrp = prev_toplvl_grp; |
7 | 4801 current_syn_inc_tag = prev_syn_inc_tag; |
4802 } | |
4803 | |
4804 /* | |
4805 * Handle ":syntax keyword {group-name} [{option}] keyword .." command. | |
4806 */ | |
4807 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4808 syn_cmd_keyword(exarg_T *eap, int syncing UNUSED) |
7 | 4809 { |
4810 char_u *arg = eap->arg; | |
4811 char_u *group_name_end; | |
4812 int syn_id; | |
4813 char_u *rest; | |
2743 | 4814 char_u *keyword_copy = NULL; |
7 | 4815 char_u *p; |
154 | 4816 char_u *kw; |
4817 syn_opt_arg_T syn_opt_arg; | |
4818 int cnt; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4819 int conceal_char = NUL; |
7 | 4820 |
4821 rest = get_group_name(arg, &group_name_end); | |
4822 | |
4823 if (rest != NULL) | |
4824 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4825 if (eap->skip) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4826 syn_id = -1; |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4827 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4828 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); |
2743 | 4829 if (syn_id != 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4830 // allocate a buffer, for removing backslashes in the keyword |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16611
diff
changeset
|
4831 keyword_copy = alloc(STRLEN(rest) + 1); |
7 | 4832 if (keyword_copy != NULL) |
4833 { | |
154 | 4834 syn_opt_arg.flags = 0; |
4835 syn_opt_arg.keyword = TRUE; | |
4836 syn_opt_arg.sync_idx = NULL; | |
4837 syn_opt_arg.has_cont_list = FALSE; | |
4838 syn_opt_arg.cont_in_list = NULL; | |
4839 syn_opt_arg.next_list = NULL; | |
4840 | |
7 | 4841 /* |
4842 * The options given apply to ALL keywords, so all options must be | |
4843 * found before keywords can be created. | |
154 | 4844 * 1: collect the options and copy the keywords to keyword_copy. |
7 | 4845 */ |
154 | 4846 cnt = 0; |
4847 p = keyword_copy; | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4848 for ( ; rest != NULL && !ends_excmd2(eap->arg, rest); |
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4849 rest = skipwhite(rest)) |
7 | 4850 { |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4851 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4852 eap->skip); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4853 if (rest == NULL || ends_excmd2(eap->arg, rest)) |
154 | 4854 break; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4855 // Copy the keyword, removing backslashes, and add a NUL. |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4856 while (*rest != NUL && !VIM_ISWHITE(*rest)) |
154 | 4857 { |
4858 if (*rest == '\\' && rest[1] != NUL) | |
4859 ++rest; | |
4860 *p++ = *rest++; | |
4861 } | |
4862 *p++ = NUL; | |
4863 ++cnt; | |
4864 } | |
4865 | |
4866 if (!eap->skip) | |
4867 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4868 // Adjust flags for use of ":syn include". |
154 | 4869 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
4870 | |
7 | 4871 /* |
154 | 4872 * 2: Add an entry for each keyword. |
7 | 4873 */ |
154 | 4874 for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) |
7 | 4875 { |
154 | 4876 for (p = vim_strchr(kw, '['); ; ) |
7 | 4877 { |
154 | 4878 if (p != NULL) |
4879 *p = NUL; | |
4880 add_keyword(kw, syn_id, syn_opt_arg.flags, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4881 syn_opt_arg.cont_in_list, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4882 syn_opt_arg.next_list, conceal_char); |
168 | 4883 if (p == NULL) |
4884 break; | |
4885 if (p[1] == NUL) | |
4886 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4887 semsg(_("E789: Missing ']': %s"), kw); |
7017 | 4888 goto error; |
168 | 4889 } |
4890 if (p[1] == ']') | |
4891 { | |
7017 | 4892 if (p[2] != NUL) |
4893 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4894 semsg(_("E890: trailing char after ']': %s]%s"), |
7017 | 4895 kw, &p[2]); |
4896 goto error; | |
4897 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4898 kw = p + 1; // skip over the "]" |
168 | 4899 break; |
4900 } | |
154 | 4901 if (has_mbyte) |
7 | 4902 { |
474 | 4903 int l = (*mb_ptr2len)(p + 1); |
154 | 4904 |
4905 mch_memmove(p, p + 1, l); | |
4906 p += l; | |
4907 } | |
4908 else | |
4909 { | |
4910 p[0] = p[1]; | |
4911 ++p; | |
7 | 4912 } |
4913 } | |
4914 } | |
4915 } | |
7017 | 4916 error: |
7 | 4917 vim_free(keyword_copy); |
168 | 4918 vim_free(syn_opt_arg.cont_in_list); |
4919 vim_free(syn_opt_arg.next_list); | |
7 | 4920 } |
4921 } | |
4922 | |
4923 if (rest != NULL) | |
4924 eap->nextcmd = check_nextcmd(rest); | |
4925 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4926 semsg(_(e_invarg2), arg); |
7 | 4927 |
745 | 4928 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4929 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 4930 } |
4931 | |
4932 /* | |
4933 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". | |
4934 * | |
4935 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." | |
4936 */ | |
4937 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4938 syn_cmd_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4939 exarg_T *eap, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4940 int syncing) // TRUE for ":syntax sync match .. " |
7 | 4941 { |
4942 char_u *arg = eap->arg; | |
4943 char_u *group_name_end; | |
4944 char_u *rest; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4945 synpat_T item; // the item found in the line |
7 | 4946 int syn_id; |
4947 int idx; | |
154 | 4948 syn_opt_arg_T syn_opt_arg; |
7 | 4949 int sync_idx = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4950 int conceal_char = NUL; |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4951 int orig_called_emsg = called_emsg; |
7 | 4952 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4953 // Isolate the group name, check for validity |
7 | 4954 rest = get_group_name(arg, &group_name_end); |
4955 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4956 // Get options before the pattern |
154 | 4957 syn_opt_arg.flags = 0; |
4958 syn_opt_arg.keyword = FALSE; | |
4959 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; | |
4960 syn_opt_arg.has_cont_list = TRUE; | |
4961 syn_opt_arg.cont_list = NULL; | |
4962 syn_opt_arg.cont_in_list = NULL; | |
4963 syn_opt_arg.next_list = NULL; | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4964 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 4965 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4966 // get the pattern. |
7 | 4967 init_syn_patterns(); |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4968 CLEAR_FIELD(item); |
7 | 4969 rest = get_syn_pattern(rest, &item); |
154 | 4970 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
4971 syn_opt_arg.flags |= HL_HAS_EOL; | |
7 | 4972 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4973 // Get options after the pattern |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4974 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 4975 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4976 if (rest != NULL) // all arguments are valid |
7 | 4977 { |
4978 /* | |
4979 * Check for trailing command and illegal trailing arguments. | |
4980 */ | |
4981 eap->nextcmd = check_nextcmd(rest); | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4982 if (!ends_excmd2(eap->cmd, rest) || eap->skip) |
7 | 4983 rest = NULL; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4984 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL |
7 | 4985 && (syn_id = syn_check_group(arg, |
4986 (int)(group_name_end - arg))) != 0) | |
4987 { | |
154 | 4988 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 4989 /* |
4990 * Store the pattern in the syn_items list | |
4991 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4992 idx = curwin->w_s->b_syn_patterns.ga_len; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4993 SYN_ITEMS(curwin->w_s)[idx] = item; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4994 SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4995 SYN_ITEMS(curwin->w_s)[idx].sp_type = SPTYPE_MATCH; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4996 SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4997 SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = current_syn_inc_tag; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4998 SYN_ITEMS(curwin->w_s)[idx].sp_flags = syn_opt_arg.flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4999 SYN_ITEMS(curwin->w_s)[idx].sp_sync_idx = sync_idx; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5000 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = syn_opt_arg.cont_list; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5001 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5002 syn_opt_arg.cont_in_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5003 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
5004 SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5005 #endif |
154 | 5006 if (syn_opt_arg.cont_in_list != NULL) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5007 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5008 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = syn_opt_arg.next_list; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5009 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5010 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5011 // remember that we found a match for syncing on |
154 | 5012 if (syn_opt_arg.flags & (HL_SYNC_HERE|HL_SYNC_THERE)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5013 curwin->w_s->b_syn_sync_flags |= SF_MATCH; |
7 | 5014 #ifdef FEAT_FOLDING |
154 | 5015 if (syn_opt_arg.flags & HL_FOLD) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5016 ++curwin->w_s->b_syn_folditems; |
7 | 5017 #endif |
5018 | |
745 | 5019 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5020 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5021 return; // don't free the progs and patterns now |
7 | 5022 } |
5023 } | |
5024 | |
5025 /* | |
5026 * Something failed, free the allocated memory. | |
5027 */ | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5028 vim_regfree(item.sp_prog); |
7 | 5029 vim_free(item.sp_pattern); |
154 | 5030 vim_free(syn_opt_arg.cont_list); |
5031 vim_free(syn_opt_arg.cont_in_list); | |
5032 vim_free(syn_opt_arg.next_list); | |
7 | 5033 |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5034 if (rest == NULL && called_emsg == orig_called_emsg) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5035 semsg(_(e_invarg2), arg); |
7 | 5036 } |
5037 | |
5038 /* | |
5039 * Handle ":syntax region {group-name} [matchgroup={group-name}] | |
5040 * start {start} .. [skip {skip}] end {end} .. [{options}]". | |
5041 */ | |
5042 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5043 syn_cmd_region( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5044 exarg_T *eap, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5045 int syncing) // TRUE for ":syntax sync region .." |
7 | 5046 { |
5047 char_u *arg = eap->arg; | |
5048 char_u *group_name_end; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5049 char_u *rest; // next arg, NULL on error |
7 | 5050 char_u *key_end; |
5051 char_u *key = NULL; | |
5052 char_u *p; | |
5053 int item; | |
5054 #define ITEM_START 0 | |
5055 #define ITEM_SKIP 1 | |
5056 #define ITEM_END 2 | |
5057 #define ITEM_MATCHGROUP 3 | |
5058 struct pat_ptr | |
5059 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5060 synpat_T *pp_synp; // pointer to syn_pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5061 int pp_matchgroup_id; // matchgroup ID |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5062 struct pat_ptr *pp_next; // pointer to next pat_ptr |
7 | 5063 } *(pat_ptrs[3]); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5064 // patterns found in the line |
7 | 5065 struct pat_ptr *ppp; |
5066 struct pat_ptr *ppp_next; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5067 int pat_count = 0; // nr of syn_patterns found |
7 | 5068 int syn_id; |
5069 int matchgroup_id = 0; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5070 int not_enough = FALSE; // not enough arguments |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5071 int illegal = FALSE; // illegal arguments |
7 | 5072 int success = FALSE; |
5073 int idx; | |
154 | 5074 syn_opt_arg_T syn_opt_arg; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5075 int conceal_char = NUL; |
7 | 5076 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5077 // Isolate the group name, check for validity |
7 | 5078 rest = get_group_name(arg, &group_name_end); |
5079 | |
5080 pat_ptrs[0] = NULL; | |
5081 pat_ptrs[1] = NULL; | |
5082 pat_ptrs[2] = NULL; | |
5083 | |
5084 init_syn_patterns(); | |
5085 | |
154 | 5086 syn_opt_arg.flags = 0; |
5087 syn_opt_arg.keyword = FALSE; | |
5088 syn_opt_arg.sync_idx = NULL; | |
5089 syn_opt_arg.has_cont_list = TRUE; | |
5090 syn_opt_arg.cont_list = NULL; | |
5091 syn_opt_arg.cont_in_list = NULL; | |
5092 syn_opt_arg.next_list = NULL; | |
5093 | |
7 | 5094 /* |
5095 * get the options, patterns and matchgroup. | |
5096 */ | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5097 while (rest != NULL && !ends_excmd2(eap->cmd, rest)) |
7 | 5098 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5099 // Check for option arguments |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5100 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5101 if (rest == NULL || ends_excmd2(eap->cmd, rest)) |
7 | 5102 break; |
5103 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5104 // must be a pattern or matchgroup then |
7 | 5105 key_end = rest; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5106 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') |
7 | 5107 ++key_end; |
5108 vim_free(key); | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20623
diff
changeset
|
5109 key = vim_strnsave_up(rest, key_end - rest); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5110 if (key == NULL) // out of memory |
7 | 5111 { |
5112 rest = NULL; | |
5113 break; | |
5114 } | |
5115 if (STRCMP(key, "MATCHGROUP") == 0) | |
5116 item = ITEM_MATCHGROUP; | |
5117 else if (STRCMP(key, "START") == 0) | |
5118 item = ITEM_START; | |
5119 else if (STRCMP(key, "END") == 0) | |
5120 item = ITEM_END; | |
5121 else if (STRCMP(key, "SKIP") == 0) | |
5122 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5123 if (pat_ptrs[ITEM_SKIP] != NULL) // one skip pattern allowed |
7 | 5124 { |
5125 illegal = TRUE; | |
5126 break; | |
5127 } | |
5128 item = ITEM_SKIP; | |
5129 } | |
5130 else | |
5131 break; | |
5132 rest = skipwhite(key_end); | |
5133 if (*rest != '=') | |
5134 { | |
5135 rest = NULL; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5136 semsg(_("E398: Missing '=': %s"), arg); |
7 | 5137 break; |
5138 } | |
5139 rest = skipwhite(rest + 1); | |
5140 if (*rest == NUL) | |
5141 { | |
5142 not_enough = TRUE; | |
5143 break; | |
5144 } | |
5145 | |
5146 if (item == ITEM_MATCHGROUP) | |
5147 { | |
5148 p = skiptowhite(rest); | |
5149 if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) | |
5150 matchgroup_id = 0; | |
5151 else | |
5152 { | |
5153 matchgroup_id = syn_check_group(rest, (int)(p - rest)); | |
5154 if (matchgroup_id == 0) | |
5155 { | |
5156 illegal = TRUE; | |
5157 break; | |
5158 } | |
5159 } | |
5160 rest = skipwhite(p); | |
5161 } | |
5162 else | |
5163 { | |
5164 /* | |
5165 * Allocate room for a syn_pattern, and link it in the list of | |
5166 * syn_patterns for this item, at the start (because the list is | |
5167 * used from end to start). | |
5168 */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
5169 ppp = ALLOC_ONE(struct pat_ptr); |
7 | 5170 if (ppp == NULL) |
5171 { | |
5172 rest = NULL; | |
5173 break; | |
5174 } | |
5175 ppp->pp_next = pat_ptrs[item]; | |
5176 pat_ptrs[item] = ppp; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
5177 ppp->pp_synp = ALLOC_CLEAR_ONE(synpat_T); |
7 | 5178 if (ppp->pp_synp == NULL) |
5179 { | |
5180 rest = NULL; | |
5181 break; | |
5182 } | |
5183 | |
5184 /* | |
5185 * Get the syntax pattern and the following offset(s). | |
5186 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5187 // Enable the appropriate \z specials. |
7 | 5188 if (item == ITEM_START) |
5189 reg_do_extmatch = REX_SET; | |
5190 else if (item == ITEM_SKIP || item == ITEM_END) | |
5191 reg_do_extmatch = REX_USE; | |
5192 rest = get_syn_pattern(rest, ppp->pp_synp); | |
5193 reg_do_extmatch = 0; | |
5194 if (item == ITEM_END && vim_regcomp_had_eol() | |
154 | 5195 && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
7 | 5196 ppp->pp_synp->sp_flags |= HL_HAS_EOL; |
5197 ppp->pp_matchgroup_id = matchgroup_id; | |
5198 ++pat_count; | |
5199 } | |
5200 } | |
5201 vim_free(key); | |
5202 if (illegal || not_enough) | |
5203 rest = NULL; | |
5204 | |
5205 /* | |
5206 * Must have a "start" and "end" pattern. | |
5207 */ | |
5208 if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || | |
5209 pat_ptrs[ITEM_END] == NULL)) | |
5210 { | |
5211 not_enough = TRUE; | |
5212 rest = NULL; | |
5213 } | |
5214 | |
5215 if (rest != NULL) | |
5216 { | |
5217 /* | |
5218 * Check for trailing garbage or command. | |
5219 * If OK, add the item. | |
5220 */ | |
5221 eap->nextcmd = check_nextcmd(rest); | |
5222 if (!ends_excmd(*rest) || eap->skip) | |
5223 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5224 else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL |
7 | 5225 && (syn_id = syn_check_group(arg, |
5226 (int)(group_name_end - arg))) != 0) | |
5227 { | |
154 | 5228 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5229 /* |
5230 * Store the start/skip/end in the syn_items list | |
5231 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5232 idx = curwin->w_s->b_syn_patterns.ga_len; |
7 | 5233 for (item = ITEM_START; item <= ITEM_END; ++item) |
5234 { | |
5235 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) | |
5236 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5237 SYN_ITEMS(curwin->w_s)[idx] = *(ppp->pp_synp); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5238 SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5239 SYN_ITEMS(curwin->w_s)[idx].sp_type = |
7 | 5240 (item == ITEM_START) ? SPTYPE_START : |
5241 (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5242 SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5243 SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; |
2743 | 5244 SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = |
5245 current_syn_inc_tag; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5246 SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = |
7 | 5247 ppp->pp_matchgroup_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5248 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
5249 SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5250 #endif |
7 | 5251 if (item == ITEM_START) |
5252 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5253 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = |
154 | 5254 syn_opt_arg.cont_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5255 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5256 syn_opt_arg.cont_in_list; |
5257 if (syn_opt_arg.cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5258 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5259 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = |
154 | 5260 syn_opt_arg.next_list; |
7 | 5261 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5262 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5263 ++idx; |
5264 #ifdef FEAT_FOLDING | |
154 | 5265 if (syn_opt_arg.flags & HL_FOLD) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5266 ++curwin->w_s->b_syn_folditems; |
7 | 5267 #endif |
5268 } | |
5269 } | |
5270 | |
745 | 5271 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5272 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5273 success = TRUE; // don't free the progs and patterns now |
7 | 5274 } |
5275 } | |
5276 | |
5277 /* | |
5278 * Free the allocated memory. | |
5279 */ | |
5280 for (item = ITEM_START; item <= ITEM_END; ++item) | |
5281 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) | |
5282 { | |
17907
4cf69f8d1ec6
patch 8.1.1950: using NULL pointer after an out-of-memory
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
5283 if (!success && ppp->pp_synp != NULL) |
7 | 5284 { |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5285 vim_regfree(ppp->pp_synp->sp_prog); |
7 | 5286 vim_free(ppp->pp_synp->sp_pattern); |
5287 } | |
5288 vim_free(ppp->pp_synp); | |
5289 ppp_next = ppp->pp_next; | |
5290 vim_free(ppp); | |
5291 } | |
5292 | |
5293 if (!success) | |
5294 { | |
154 | 5295 vim_free(syn_opt_arg.cont_list); |
5296 vim_free(syn_opt_arg.cont_in_list); | |
5297 vim_free(syn_opt_arg.next_list); | |
7 | 5298 if (not_enough) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5299 semsg(_("E399: Not enough arguments: syntax region %s"), arg); |
7 | 5300 else if (illegal || rest == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5301 semsg(_(e_invarg2), arg); |
7 | 5302 } |
5303 } | |
5304 | |
5305 /* | |
5306 * A simple syntax group ID comparison function suitable for use in qsort() | |
5307 */ | |
5308 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5309 syn_compare_stub(const void *v1, const void *v2) |
7 | 5310 { |
5311 const short *s1 = v1; | |
5312 const short *s2 = v2; | |
5313 | |
5314 return (*s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0); | |
5315 } | |
5316 | |
5317 /* | |
5318 * Combines lists of syntax clusters. | |
5319 * *clstr1 and *clstr2 must both be allocated memory; they will be consumed. | |
5320 */ | |
5321 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5322 syn_combine_list(short **clstr1, short **clstr2, int list_op) |
7 | 5323 { |
5324 int count1 = 0; | |
5325 int count2 = 0; | |
5326 short *g1; | |
5327 short *g2; | |
5328 short *clstr = NULL; | |
5329 int count; | |
5330 int round; | |
5331 | |
5332 /* | |
5333 * Handle degenerate cases. | |
5334 */ | |
5335 if (*clstr2 == NULL) | |
5336 return; | |
5337 if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) | |
5338 { | |
5339 if (list_op == CLUSTER_REPLACE) | |
5340 vim_free(*clstr1); | |
5341 if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) | |
5342 *clstr1 = *clstr2; | |
5343 else | |
5344 vim_free(*clstr2); | |
5345 return; | |
5346 } | |
5347 | |
5348 for (g1 = *clstr1; *g1; g1++) | |
5349 ++count1; | |
5350 for (g2 = *clstr2; *g2; g2++) | |
5351 ++count2; | |
5352 | |
5353 /* | |
5354 * For speed purposes, sort both lists. | |
5355 */ | |
5356 qsort(*clstr1, (size_t)count1, sizeof(short), syn_compare_stub); | |
5357 qsort(*clstr2, (size_t)count2, sizeof(short), syn_compare_stub); | |
5358 | |
5359 /* | |
5360 * We proceed in two passes; in round 1, we count the elements to place | |
5361 * in the new list, and in round 2, we allocate and populate the new | |
5362 * list. For speed, we use a mergesort-like method, adding the smaller | |
5363 * of the current elements in each list to the new list. | |
5364 */ | |
5365 for (round = 1; round <= 2; round++) | |
5366 { | |
5367 g1 = *clstr1; | |
5368 g2 = *clstr2; | |
5369 count = 0; | |
5370 | |
5371 /* | |
5372 * First, loop through the lists until one of them is empty. | |
5373 */ | |
5374 while (*g1 && *g2) | |
5375 { | |
5376 /* | |
5377 * We always want to add from the first list. | |
5378 */ | |
5379 if (*g1 < *g2) | |
5380 { | |
5381 if (round == 2) | |
5382 clstr[count] = *g1; | |
5383 count++; | |
5384 g1++; | |
5385 continue; | |
5386 } | |
5387 /* | |
5388 * We only want to add from the second list if we're adding the | |
5389 * lists. | |
5390 */ | |
5391 if (list_op == CLUSTER_ADD) | |
5392 { | |
5393 if (round == 2) | |
5394 clstr[count] = *g2; | |
5395 count++; | |
5396 } | |
5397 if (*g1 == *g2) | |
5398 g1++; | |
5399 g2++; | |
5400 } | |
5401 | |
5402 /* | |
5403 * Now add the leftovers from whichever list didn't get finished | |
5404 * first. As before, we only want to add from the second list if | |
5405 * we're adding the lists. | |
5406 */ | |
5407 for (; *g1; g1++, count++) | |
5408 if (round == 2) | |
5409 clstr[count] = *g1; | |
5410 if (list_op == CLUSTER_ADD) | |
5411 for (; *g2; g2++, count++) | |
5412 if (round == 2) | |
5413 clstr[count] = *g2; | |
5414 | |
5415 if (round == 1) | |
5416 { | |
5417 /* | |
5418 * If the group ended up empty, we don't need to allocate any | |
5419 * space for it. | |
5420 */ | |
5421 if (count == 0) | |
5422 { | |
5423 clstr = NULL; | |
5424 break; | |
5425 } | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
5426 clstr = ALLOC_MULT(short, count + 1); |
7 | 5427 if (clstr == NULL) |
5428 break; | |
5429 clstr[count] = 0; | |
5430 } | |
5431 } | |
5432 | |
5433 /* | |
5434 * Finally, put the new list in place. | |
5435 */ | |
5436 vim_free(*clstr1); | |
5437 vim_free(*clstr2); | |
5438 *clstr1 = clstr; | |
5439 } | |
5440 | |
5441 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5442 * Lookup a syntax cluster name and return its ID. |
7 | 5443 * If it is not found, 0 is returned. |
5444 */ | |
5445 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5446 syn_scl_name2id(char_u *name) |
7 | 5447 { |
5448 int i; | |
5449 char_u *name_u; | |
5450 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5451 // Avoid using stricmp() too much, it's slow on some systems |
7 | 5452 name_u = vim_strsave_up(name); |
5453 if (name_u == NULL) | |
5454 return 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5455 for (i = curwin->w_s->b_syn_clusters.ga_len; --i >= 0; ) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5456 if (SYN_CLSTR(curwin->w_s)[i].scl_name_u != NULL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5457 && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) |
7 | 5458 break; |
5459 vim_free(name_u); | |
5460 return (i < 0 ? 0 : i + SYNID_CLUSTER); | |
5461 } | |
5462 | |
5463 /* | |
5464 * Like syn_scl_name2id(), but take a pointer + length argument. | |
5465 */ | |
5466 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5467 syn_scl_namen2id(char_u *linep, int len) |
7 | 5468 { |
5469 char_u *name; | |
5470 int id = 0; | |
5471 | |
5472 name = vim_strnsave(linep, len); | |
5473 if (name != NULL) | |
5474 { | |
5475 id = syn_scl_name2id(name); | |
5476 vim_free(name); | |
5477 } | |
5478 return id; | |
5479 } | |
5480 | |
5481 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5482 * Find syntax cluster name in the table and return its ID. |
7 | 5483 * The argument is a pointer to the name and the length of the name. |
5484 * If it doesn't exist yet, a new entry is created. | |
5485 * Return 0 for failure. | |
5486 */ | |
5487 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5488 syn_check_cluster(char_u *pp, int len) |
7 | 5489 { |
5490 int id; | |
5491 char_u *name; | |
5492 | |
5493 name = vim_strnsave(pp, len); | |
5494 if (name == NULL) | |
5495 return 0; | |
5496 | |
5497 id = syn_scl_name2id(name); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5498 if (id == 0) // doesn't exist yet |
7 | 5499 id = syn_add_cluster(name); |
5500 else | |
5501 vim_free(name); | |
5502 return id; | |
5503 } | |
5504 | |
5505 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5506 * Add new syntax cluster and return its ID. |
7 | 5507 * "name" must be an allocated string, it will be consumed. |
5508 * Return 0 for failure. | |
5509 */ | |
5510 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5511 syn_add_cluster(char_u *name) |
221 | 5512 { |
5513 int len; | |
7 | 5514 |
5515 /* | |
5516 * First call for this growarray: init growing array. | |
5517 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5518 if (curwin->w_s->b_syn_clusters.ga_data == NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5519 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5520 curwin->w_s->b_syn_clusters.ga_itemsize = sizeof(syn_cluster_T); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5521 curwin->w_s->b_syn_clusters.ga_growsize = 10; |
7 | 5522 } |
5523 | |
2743 | 5524 len = curwin->w_s->b_syn_clusters.ga_len; |
5525 if (len >= MAX_CLUSTER_ID) | |
5526 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5527 emsg(_("E848: Too many syntax clusters")); |
2743 | 5528 vim_free(name); |
5529 return 0; | |
5530 } | |
5531 | |
7 | 5532 /* |
5533 * Make room for at least one other cluster entry. | |
5534 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5535 if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) |
7 | 5536 { |
5537 vim_free(name); | |
5538 return 0; | |
5539 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5540 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
5541 CLEAR_POINTER(&(SYN_CLSTR(curwin->w_s)[len])); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5542 SYN_CLSTR(curwin->w_s)[len].scl_name = name; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5543 SYN_CLSTR(curwin->w_s)[len].scl_name_u = vim_strsave_up(name); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5544 SYN_CLSTR(curwin->w_s)[len].scl_list = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5545 ++curwin->w_s->b_syn_clusters.ga_len; |
7 | 5546 |
221 | 5547 if (STRICMP(name, "Spell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5548 curwin->w_s->b_spell_cluster_id = len + SYNID_CLUSTER; |
227 | 5549 if (STRICMP(name, "NoSpell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5550 curwin->w_s->b_nospell_cluster_id = len + SYNID_CLUSTER; |
221 | 5551 |
7 | 5552 return len + SYNID_CLUSTER; |
5553 } | |
5554 | |
5555 /* | |
5556 * Handle ":syntax cluster {cluster-name} [contains={groupname},..] | |
5557 * [add={groupname},..] [remove={groupname},..]". | |
5558 */ | |
5559 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5560 syn_cmd_cluster(exarg_T *eap, int syncing UNUSED) |
7 | 5561 { |
5562 char_u *arg = eap->arg; | |
5563 char_u *group_name_end; | |
5564 char_u *rest; | |
5565 int scl_id; | |
5566 short *clstr_list; | |
5567 int got_clstr = FALSE; | |
5568 int opt_len; | |
5569 int list_op; | |
5570 | |
5571 eap->nextcmd = find_nextcmd(arg); | |
5572 if (eap->skip) | |
5573 return; | |
5574 | |
5575 rest = get_group_name(arg, &group_name_end); | |
5576 | |
5577 if (rest != NULL) | |
5578 { | |
2743 | 5579 scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); |
5580 if (scl_id == 0) | |
5581 return; | |
5582 scl_id -= SYNID_CLUSTER; | |
7 | 5583 |
5584 for (;;) | |
5585 { | |
5586 if (STRNICMP(rest, "add", 3) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5587 && (VIM_ISWHITE(rest[3]) || rest[3] == '=')) |
7 | 5588 { |
5589 opt_len = 3; | |
5590 list_op = CLUSTER_ADD; | |
5591 } | |
5592 else if (STRNICMP(rest, "remove", 6) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5593 && (VIM_ISWHITE(rest[6]) || rest[6] == '=')) |
7 | 5594 { |
5595 opt_len = 6; | |
5596 list_op = CLUSTER_SUBTRACT; | |
5597 } | |
5598 else if (STRNICMP(rest, "contains", 8) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5599 && (VIM_ISWHITE(rest[8]) || rest[8] == '=')) |
7 | 5600 { |
5601 opt_len = 8; | |
5602 list_op = CLUSTER_REPLACE; | |
5603 } | |
5604 else | |
5605 break; | |
5606 | |
5607 clstr_list = NULL; | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5608 if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) |
7 | 5609 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5610 semsg(_(e_invarg2), rest); |
7 | 5611 break; |
5612 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5613 if (scl_id >= 0) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5614 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, |
7 | 5615 &clstr_list, list_op); |
10648
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5616 else |
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5617 vim_free(clstr_list); |
7 | 5618 got_clstr = TRUE; |
5619 } | |
5620 | |
5621 if (got_clstr) | |
5622 { | |
745 | 5623 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5624 syn_stack_free_all(curwin->w_s); // Need to recompute all. |
7 | 5625 } |
5626 } | |
5627 | |
5628 if (!got_clstr) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5629 emsg(_("E400: No cluster specified")); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5630 if (rest == NULL || !ends_excmd2(eap->cmd, rest)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5631 semsg(_(e_invarg2), arg); |
7 | 5632 } |
5633 | |
5634 /* | |
5635 * On first call for current buffer: Init growing array. | |
5636 */ | |
5637 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5638 init_syn_patterns(void) |
7 | 5639 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5640 curwin->w_s->b_syn_patterns.ga_itemsize = sizeof(synpat_T); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5641 curwin->w_s->b_syn_patterns.ga_growsize = 10; |
7 | 5642 } |
5643 | |
5644 /* | |
5645 * Get one pattern for a ":syntax match" or ":syntax region" command. | |
5646 * Stores the pattern and program in a synpat_T. | |
5647 * Returns a pointer to the next argument, or NULL in case of an error. | |
5648 */ | |
5649 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5650 get_syn_pattern(char_u *arg, synpat_T *ci) |
7 | 5651 { |
5652 char_u *end; | |
5653 int *p; | |
5654 int idx; | |
5655 char_u *cpo_save; | |
5656 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5657 // need at least three chars |
6993 | 5658 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) |
7 | 5659 return NULL; |
5660 | |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
5661 end = skip_regexp(arg + 1, *arg, TRUE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5662 if (*end != *arg) // end delimiter not found |
7 | 5663 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5664 semsg(_("E401: Pattern delimiter not found: %s"), arg); |
7 | 5665 return NULL; |
5666 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5667 // store the pattern and compiled regexp program |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5668 if ((ci->sp_pattern = vim_strnsave(arg + 1, end - arg - 1)) == NULL) |
7 | 5669 return NULL; |
5670 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5671 // Make 'cpoptions' empty, to avoid the 'l' flag |
7 | 5672 cpo_save = p_cpo; |
23493
f8382c4e6551
patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents:
23043
diff
changeset
|
5673 p_cpo = empty_option; |
7 | 5674 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); |
5675 p_cpo = cpo_save; | |
5676 | |
5677 if (ci->sp_prog == NULL) | |
5678 return NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5679 ci->sp_ic = curwin->w_s->b_syn_ic; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5680 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5681 syn_clear_time(&ci->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5682 #endif |
7 | 5683 |
5684 /* | |
5685 * Check for a match, highlight or region offset. | |
5686 */ | |
5687 ++end; | |
5688 do | |
5689 { | |
5690 for (idx = SPO_COUNT; --idx >= 0; ) | |
5691 if (STRNCMP(end, spo_name_tab[idx], 3) == 0) | |
5692 break; | |
5693 if (idx >= 0) | |
5694 { | |
5695 p = &(ci->sp_offsets[idx]); | |
5696 if (idx != SPO_LC_OFF) | |
5697 switch (end[3]) | |
5698 { | |
5699 case 's': break; | |
5700 case 'b': break; | |
5701 case 'e': idx += SPO_COUNT; break; | |
5702 default: idx = -1; break; | |
5703 } | |
5704 if (idx >= 0) | |
5705 { | |
5706 ci->sp_off_flags |= (1 << idx); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5707 if (idx == SPO_LC_OFF) // lc=99 |
7 | 5708 { |
5709 end += 3; | |
5710 *p = getdigits(&end); | |
5711 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5712 // "lc=" offset automatically sets "ms=" offset |
7 | 5713 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) |
5714 { | |
5715 ci->sp_off_flags |= (1 << SPO_MS_OFF); | |
5716 ci->sp_offsets[SPO_MS_OFF] = *p; | |
5717 } | |
5718 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5719 else // yy=x+99 |
7 | 5720 { |
5721 end += 4; | |
5722 if (*end == '+') | |
5723 { | |
5724 ++end; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5725 *p = getdigits(&end); // positive offset |
7 | 5726 } |
5727 else if (*end == '-') | |
5728 { | |
5729 ++end; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5730 *p = -getdigits(&end); // negative offset |
7 | 5731 } |
5732 } | |
5733 if (*end != ',') | |
5734 break; | |
5735 ++end; | |
5736 } | |
5737 } | |
5738 } while (idx >= 0); | |
5739 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5740 if (!ends_excmd2(arg, end) && !VIM_ISWHITE(*end)) |
7 | 5741 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5742 semsg(_("E402: Garbage after pattern: %s"), arg); |
7 | 5743 return NULL; |
5744 } | |
5745 return skipwhite(end); | |
5746 } | |
5747 | |
5748 /* | |
5749 * Handle ":syntax sync .." command. | |
5750 */ | |
5751 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5752 syn_cmd_sync(exarg_T *eap, int syncing UNUSED) |
7 | 5753 { |
5754 char_u *arg_start = eap->arg; | |
5755 char_u *arg_end; | |
5756 char_u *key = NULL; | |
5757 char_u *next_arg; | |
5758 int illegal = FALSE; | |
5759 int finished = FALSE; | |
5760 long n; | |
5761 char_u *cpo_save; | |
5762 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5763 if (ends_excmd2(eap->cmd, arg_start)) |
7 | 5764 { |
5765 syn_cmd_list(eap, TRUE); | |
5766 return; | |
5767 } | |
5768 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5769 while (!ends_excmd2(eap->cmd, arg_start)) |
7 | 5770 { |
5771 arg_end = skiptowhite(arg_start); | |
5772 next_arg = skipwhite(arg_end); | |
5773 vim_free(key); | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20623
diff
changeset
|
5774 key = vim_strnsave_up(arg_start, arg_end - arg_start); |
21240
e35955a787a8
patch 8.2.1171: possible crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
5775 if (key == NULL) |
e35955a787a8
patch 8.2.1171: possible crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
5776 break; |
7 | 5777 if (STRCMP(key, "CCOMMENT") == 0) |
5778 { | |
5779 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5780 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5781 if (!ends_excmd2(eap->cmd, next_arg)) |
7 | 5782 { |
5783 arg_end = skiptowhite(next_arg); | |
5784 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5785 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, |
7 | 5786 (int)(arg_end - next_arg)); |
5787 next_arg = skipwhite(arg_end); | |
5788 } | |
5789 else if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5790 curwin->w_s->b_syn_sync_id = syn_name2id((char_u *)"Comment"); |
7 | 5791 } |
5792 else if ( STRNCMP(key, "LINES", 5) == 0 | |
5793 || STRNCMP(key, "MINLINES", 8) == 0 | |
5794 || STRNCMP(key, "MAXLINES", 8) == 0 | |
5795 || STRNCMP(key, "LINEBREAKS", 10) == 0) | |
5796 { | |
5797 if (key[4] == 'S') | |
5798 arg_end = key + 6; | |
5799 else if (key[0] == 'L') | |
5800 arg_end = key + 11; | |
5801 else | |
5802 arg_end = key + 9; | |
5803 if (arg_end[-1] != '=' || !VIM_ISDIGIT(*arg_end)) | |
5804 { | |
5805 illegal = TRUE; | |
5806 break; | |
5807 } | |
5808 n = getdigits(&arg_end); | |
5809 if (!eap->skip) | |
5810 { | |
5811 if (key[4] == 'B') | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5812 curwin->w_s->b_syn_sync_linebreaks = n; |
7 | 5813 else if (key[1] == 'A') |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5814 curwin->w_s->b_syn_sync_maxlines = n; |
7 | 5815 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5816 curwin->w_s->b_syn_sync_minlines = n; |
7 | 5817 } |
5818 } | |
5819 else if (STRCMP(key, "FROMSTART") == 0) | |
5820 { | |
5821 if (!eap->skip) | |
5822 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5823 curwin->w_s->b_syn_sync_minlines = MAXLNUM; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5824 curwin->w_s->b_syn_sync_maxlines = 0; |
7 | 5825 } |
5826 } | |
5827 else if (STRCMP(key, "LINECONT") == 0) | |
5828 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5829 if (*next_arg == NUL) // missing pattern |
7504
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5830 { |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5831 illegal = TRUE; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5832 break; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5833 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5834 if (curwin->w_s->b_syn_linecont_pat != NULL) |
7 | 5835 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5836 emsg(_("E403: syntax sync: line continuations pattern specified twice")); |
7 | 5837 finished = TRUE; |
5838 break; | |
5839 } | |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
5840 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5841 if (*arg_end != *next_arg) // end delimiter not found |
7 | 5842 { |
5843 illegal = TRUE; | |
5844 break; | |
5845 } | |
5846 | |
5847 if (!eap->skip) | |
5848 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5849 // store the pattern and compiled regexp program |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5850 if ((curwin->w_s->b_syn_linecont_pat = |
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5851 vim_strnsave(next_arg + 1, |
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5852 arg_end - next_arg - 1)) == NULL) |
7 | 5853 { |
5854 finished = TRUE; | |
5855 break; | |
5856 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5857 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; |
7 | 5858 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5859 // Make 'cpoptions' empty, to avoid the 'l' flag |
7 | 5860 cpo_save = p_cpo; |
23493
f8382c4e6551
patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents:
23043
diff
changeset
|
5861 p_cpo = empty_option; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5862 curwin->w_s->b_syn_linecont_prog = |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5863 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); |
7 | 5864 p_cpo = cpo_save; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5865 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5866 syn_clear_time(&curwin->w_s->b_syn_linecont_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5867 #endif |
7 | 5868 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5869 if (curwin->w_s->b_syn_linecont_prog == NULL) |
7 | 5870 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
5871 VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); |
7 | 5872 finished = TRUE; |
5873 break; | |
5874 } | |
5875 } | |
5876 next_arg = skipwhite(arg_end + 1); | |
5877 } | |
5878 else | |
5879 { | |
5880 eap->arg = next_arg; | |
5881 if (STRCMP(key, "MATCH") == 0) | |
5882 syn_cmd_match(eap, TRUE); | |
5883 else if (STRCMP(key, "REGION") == 0) | |
5884 syn_cmd_region(eap, TRUE); | |
5885 else if (STRCMP(key, "CLEAR") == 0) | |
5886 syn_cmd_clear(eap, TRUE); | |
5887 else | |
5888 illegal = TRUE; | |
5889 finished = TRUE; | |
5890 break; | |
5891 } | |
5892 arg_start = next_arg; | |
5893 } | |
5894 vim_free(key); | |
5895 if (illegal) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5896 semsg(_("E404: Illegal arguments: %s"), arg_start); |
7 | 5897 else if (!finished) |
5898 { | |
5899 eap->nextcmd = check_nextcmd(arg_start); | |
745 | 5900 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5901 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 5902 } |
5903 } | |
5904 | |
5905 /* | |
5906 * Convert a line of highlight group names into a list of group ID numbers. | |
5907 * "arg" should point to the "contains" or "nextgroup" keyword. | |
5908 * "arg" is advanced to after the last group name. | |
5909 * Careful: the argument is modified (NULs added). | |
5910 * returns FAIL for some error, OK for success. | |
5911 */ | |
5912 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5913 get_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5914 char_u **arg, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5915 int keylen, // length of keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5916 short **list, // where to store the resulting list, if not |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5917 // NULL, the list is silently skipped! |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5918 int skip) |
7 | 5919 { |
5920 char_u *p = NULL; | |
5921 char_u *end; | |
5922 int round; | |
5923 int count; | |
5924 int total_count = 0; | |
5925 short *retval = NULL; | |
5926 char_u *name; | |
5927 regmatch_T regmatch; | |
5928 int id; | |
5929 int i; | |
5930 int failed = FALSE; | |
5931 | |
5932 /* | |
5933 * We parse the list twice: | |
5934 * round == 1: count the number of items, allocate the array. | |
5935 * round == 2: fill the array with the items. | |
5936 * In round 1 new groups may be added, causing the number of items to | |
5937 * grow when a regexp is used. In that case round 1 is done once again. | |
5938 */ | |
5939 for (round = 1; round <= 2; ++round) | |
5940 { | |
5941 /* | |
5942 * skip "contains" | |
5943 */ | |
5944 p = skipwhite(*arg + keylen); | |
5945 if (*p != '=') | |
5946 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5947 semsg(_("E405: Missing equal sign: %s"), *arg); |
7 | 5948 break; |
5949 } | |
5950 p = skipwhite(p + 1); | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5951 if (ends_excmd2(*arg, p)) |
7 | 5952 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5953 semsg(_("E406: Empty argument: %s"), *arg); |
7 | 5954 break; |
5955 } | |
5956 | |
5957 /* | |
5958 * parse the arguments after "contains" | |
5959 */ | |
5960 count = 0; | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5961 while (!ends_excmd2(*arg, p)) |
7 | 5962 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5963 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) |
7 | 5964 ; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5965 name = alloc(end - p + 3); // leave room for "^$" |
7 | 5966 if (name == NULL) |
5967 { | |
5968 failed = TRUE; | |
5969 break; | |
5970 } | |
419 | 5971 vim_strncpy(name + 1, p, end - p); |
7 | 5972 if ( STRCMP(name + 1, "ALLBUT") == 0 |
5973 || STRCMP(name + 1, "ALL") == 0 | |
5974 || STRCMP(name + 1, "TOP") == 0 | |
5975 || STRCMP(name + 1, "CONTAINED") == 0) | |
5976 { | |
5977 if (TOUPPER_ASC(**arg) != 'C') | |
5978 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5979 semsg(_("E407: %s not allowed here"), name + 1); |
7 | 5980 failed = TRUE; |
5981 vim_free(name); | |
5982 break; | |
5983 } | |
5984 if (count != 0) | |
5985 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5986 semsg(_("E408: %s must be first in contains list"), |
10648
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5987 name + 1); |
7 | 5988 failed = TRUE; |
5989 vim_free(name); | |
5990 break; | |
5991 } | |
5992 if (name[1] == 'A') | |
24442
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5993 id = SYNID_ALLBUT + current_syn_inc_tag; |
7 | 5994 else if (name[1] == 'T') |
24442
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5995 { |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5996 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5997 id = curwin->w_s->b_syn_topgrp; |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5998 else |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5999 id = SYNID_TOP + current_syn_inc_tag; |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
6000 } |
7 | 6001 else |
24442
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
6002 id = SYNID_CONTAINED + current_syn_inc_tag; |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
6003 |
7 | 6004 } |
6005 else if (name[1] == '@') | |
6006 { | |
10629
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6007 if (skip) |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6008 id = -1; |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6009 else |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
6010 id = syn_check_cluster(name + 2, (int)(end - p - 1)); |
7 | 6011 } |
6012 else | |
6013 { | |
6014 /* | |
6015 * Handle full group name. | |
6016 */ | |
6017 if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) | |
6018 id = syn_check_group(name + 1, (int)(end - p)); | |
6019 else | |
6020 { | |
6021 /* | |
6022 * Handle match of regexp with group names. | |
6023 */ | |
6024 *name = '^'; | |
6025 STRCAT(name, "$"); | |
6026 regmatch.regprog = vim_regcomp(name, RE_MAGIC); | |
6027 if (regmatch.regprog == NULL) | |
6028 { | |
6029 failed = TRUE; | |
6030 vim_free(name); | |
6031 break; | |
6032 } | |
6033 | |
6034 regmatch.rm_ic = TRUE; | |
6035 id = 0; | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
6036 for (i = highlight_num_groups(); --i >= 0; ) |
7 | 6037 { |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
6038 if (vim_regexec(®match, highlight_group_name(i), |
7 | 6039 (colnr_T)0)) |
6040 { | |
6041 if (round == 2) | |
6042 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6043 // Got more items than expected; can happen |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6044 // when adding items that match: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6045 // "contains=a.*b,axb". |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6046 // Go back to first round |
7 | 6047 if (count >= total_count) |
6048 { | |
6049 vim_free(retval); | |
6050 round = 1; | |
6051 } | |
6052 else | |
6053 retval[count] = i + 1; | |
6054 } | |
6055 ++count; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6056 id = -1; // remember that we found one |
7 | 6057 } |
6058 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6059 vim_regfree(regmatch.regprog); |
7 | 6060 } |
6061 } | |
6062 vim_free(name); | |
6063 if (id == 0) | |
6064 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
6065 semsg(_("E409: Unknown group name: %s"), p); |
7 | 6066 failed = TRUE; |
6067 break; | |
6068 } | |
6069 if (id > 0) | |
6070 { | |
6071 if (round == 2) | |
6072 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6073 // Got more items than expected, go back to first round |
7 | 6074 if (count >= total_count) |
6075 { | |
6076 vim_free(retval); | |
6077 round = 1; | |
6078 } | |
6079 else | |
6080 retval[count] = id; | |
6081 } | |
6082 ++count; | |
6083 } | |
6084 p = skipwhite(end); | |
6085 if (*p != ',') | |
6086 break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6087 p = skipwhite(p + 1); // skip comma in between arguments |
7 | 6088 } |
6089 if (failed) | |
6090 break; | |
6091 if (round == 1) | |
6092 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
6093 retval = ALLOC_MULT(short, count + 1); |
7 | 6094 if (retval == NULL) |
6095 break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6096 retval[count] = 0; // zero means end of the list |
7 | 6097 total_count = count; |
6098 } | |
6099 } | |
6100 | |
6101 *arg = p; | |
6102 if (failed || retval == NULL) | |
6103 { | |
6104 vim_free(retval); | |
6105 return FAIL; | |
6106 } | |
6107 | |
6108 if (*list == NULL) | |
6109 *list = retval; | |
6110 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6111 vim_free(retval); // list already found, don't overwrite it |
7 | 6112 |
6113 return OK; | |
6114 } | |
6115 | |
6116 /* | |
6117 * Make a copy of an ID list. | |
6118 */ | |
6119 static short * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6120 copy_id_list(short *list) |
7 | 6121 { |
6122 int len; | |
6123 int count; | |
6124 short *retval; | |
6125 | |
6126 if (list == NULL) | |
6127 return NULL; | |
6128 | |
6129 for (count = 0; list[count]; ++count) | |
6130 ; | |
6131 len = (count + 1) * sizeof(short); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
6132 retval = alloc(len); |
7 | 6133 if (retval != NULL) |
6134 mch_memmove(retval, list, (size_t)len); | |
6135 | |
6136 return retval; | |
6137 } | |
6138 | |
6139 /* | |
6140 * Check if syntax group "ssp" is in the ID list "list" of "cur_si". | |
6141 * "cur_si" can be NULL if not checking the "containedin" list. | |
6142 * Used to check if a syntax item is in the "contains" or "nextgroup" list of | |
6143 * the current item. | |
6144 * This function is called very often, keep it fast!! | |
6145 */ | |
6146 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6147 in_id_list( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6148 stateitem_T *cur_si, // current item or NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6149 short *list, // id list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6150 struct sp_syn *ssp, // group id and ":syn include" tag of group |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6151 int contained) // group id is contained |
7 | 6152 { |
6153 int retval; | |
6154 short *scl_list; | |
6155 short item; | |
6156 short id = ssp->id; | |
6157 static int depth = 0; | |
6158 int r; | |
6159 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6160 // If ssp has a "containedin" list and "cur_si" is in it, return TRUE. |
36 | 6161 if (cur_si != NULL && ssp->cont_in_list != NULL |
6162 && !(cur_si->si_flags & HL_MATCH)) | |
7 | 6163 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6164 // Ignore transparent items without a contains argument. Double check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6165 // that we don't go back past the first one. |
7 | 6166 while ((cur_si->si_flags & HL_TRANS_CONT) |
6167 && cur_si > (stateitem_T *)(current_state.ga_data)) | |
6168 --cur_si; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6169 // cur_si->si_idx is -1 for keywords, these never contain anything. |
7 | 6170 if (cur_si->si_idx >= 0 && in_id_list(NULL, ssp->cont_in_list, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6171 &(SYN_ITEMS(syn_block)[cur_si->si_idx].sp_syn), |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6172 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) |
7 | 6173 return TRUE; |
6174 } | |
6175 | |
6176 if (list == NULL) | |
6177 return FALSE; | |
6178 | |
6179 /* | |
6180 * If list is ID_LIST_ALL, we are in a transparent item that isn't | |
6181 * inside anything. Only allow not-contained groups. | |
6182 */ | |
6183 if (list == ID_LIST_ALL) | |
6184 return !contained; | |
6185 | |
6186 /* | |
6187 * If the first item is "ALLBUT", return TRUE if "id" is NOT in the | |
6188 * contains list. We also require that "id" is at the same ":syn include" | |
6189 * level as the list. | |
6190 */ | |
6191 item = *list; | |
6192 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) | |
6193 { | |
6194 if (item < SYNID_TOP) | |
6195 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6196 // ALL or ALLBUT: accept all groups in the same file |
7 | 6197 if (item - SYNID_ALLBUT != ssp->inc_tag) |
6198 return FALSE; | |
6199 } | |
6200 else if (item < SYNID_CONTAINED) | |
6201 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6202 // TOP: accept all not-contained groups in the same file |
7 | 6203 if (item - SYNID_TOP != ssp->inc_tag || contained) |
6204 return FALSE; | |
6205 } | |
6206 else | |
6207 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6208 // CONTAINED: accept all contained groups in the same file |
7 | 6209 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) |
6210 return FALSE; | |
6211 } | |
6212 item = *++list; | |
6213 retval = FALSE; | |
6214 } | |
6215 else | |
6216 retval = TRUE; | |
6217 | |
6218 /* | |
6219 * Return "retval" if id is in the contains list. | |
6220 */ | |
6221 while (item != 0) | |
6222 { | |
6223 if (item == id) | |
6224 return retval; | |
6225 if (item >= SYNID_CLUSTER) | |
6226 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6227 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6228 // restrict recursiveness to 30 to avoid an endless loop for a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6229 // cluster that includes itself (indirectly) |
7 | 6230 if (scl_list != NULL && depth < 30) |
6231 { | |
6232 ++depth; | |
6233 r = in_id_list(NULL, scl_list, ssp, contained); | |
6234 --depth; | |
6235 if (r) | |
6236 return retval; | |
6237 } | |
6238 } | |
6239 item = *++list; | |
6240 } | |
6241 return !retval; | |
6242 } | |
6243 | |
6244 struct subcommand | |
6245 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6246 char *name; // subcommand name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6247 void (*func)(exarg_T *, int); // function to call |
7 | 6248 }; |
6249 | |
6250 static struct subcommand subcommands[] = | |
6251 { | |
6252 {"case", syn_cmd_case}, | |
6253 {"clear", syn_cmd_clear}, | |
6254 {"cluster", syn_cmd_cluster}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6255 {"conceal", syn_cmd_conceal}, |
7 | 6256 {"enable", syn_cmd_enable}, |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6257 {"foldlevel", syn_cmd_foldlevel}, |
7 | 6258 {"include", syn_cmd_include}, |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6259 {"iskeyword", syn_cmd_iskeyword}, |
7 | 6260 {"keyword", syn_cmd_keyword}, |
6261 {"list", syn_cmd_list}, | |
6262 {"manual", syn_cmd_manual}, | |
6263 {"match", syn_cmd_match}, | |
6264 {"on", syn_cmd_on}, | |
6265 {"off", syn_cmd_off}, | |
6266 {"region", syn_cmd_region}, | |
6267 {"reset", syn_cmd_reset}, | |
419 | 6268 {"spell", syn_cmd_spell}, |
7 | 6269 {"sync", syn_cmd_sync}, |
6270 {"", syn_cmd_list}, | |
6271 {NULL, NULL} | |
6272 }; | |
6273 | |
6274 /* | |
6275 * ":syntax". | |
6276 * This searches the subcommands[] table for the subcommand name, and calls a | |
6277 * syntax_subcommand() function to do the rest. | |
6278 */ | |
6279 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6280 ex_syntax(exarg_T *eap) |
7 | 6281 { |
6282 char_u *arg = eap->arg; | |
6283 char_u *subcmd_end; | |
6284 char_u *subcmd_name; | |
6285 int i; | |
6286 | |
6287 syn_cmdlinep = eap->cmdlinep; | |
6288 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6289 // isolate subcommand name |
7 | 6290 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) |
6291 ; | |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
6292 subcmd_name = vim_strnsave(arg, subcmd_end - arg); |
7 | 6293 if (subcmd_name != NULL) |
6294 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6295 if (eap->skip) // skip error messages for all subcommands |
7 | 6296 ++emsg_skip; |
6297 for (i = 0; ; ++i) | |
6298 { | |
6299 if (subcommands[i].name == NULL) | |
6300 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
6301 semsg(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); |
7 | 6302 break; |
6303 } | |
6304 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) | |
6305 { | |
6306 eap->arg = skipwhite(subcmd_end); | |
6307 (subcommands[i].func)(eap, FALSE); | |
6308 break; | |
6309 } | |
6310 } | |
6311 vim_free(subcmd_name); | |
6312 if (eap->skip) | |
6313 --emsg_skip; | |
6314 } | |
6315 } | |
6316 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6317 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6318 ex_ownsyntax(exarg_T *eap) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6319 { |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6320 char_u *old_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6321 char_u *new_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6322 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6323 if (curwin->w_s == &curwin->w_buffer->b_s) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6324 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
6325 curwin->w_s = ALLOC_ONE(synblock_T); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6326 memset(curwin->w_s, 0, sizeof(synblock_T)); |
7030
8d513ddfe3ec
commit https://github.com/vim/vim/commit/670acbc70f371409b46b722bd9a1166e53574f42
Christian Brabandt <cb@256bit.org>
parents:
7017
diff
changeset
|
6327 hash_init(&curwin->w_s->b_keywtab); |
8d513ddfe3ec
commit https://github.com/vim/vim/commit/670acbc70f371409b46b722bd9a1166e53574f42
Christian Brabandt <cb@256bit.org>
parents:
7017
diff
changeset
|
6328 hash_init(&curwin->w_s->b_keywtab_ic); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6329 #ifdef FEAT_SPELL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6330 // TODO: keep the spell checking as it was. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6331 curwin->w_p_spell = FALSE; // No spell checking |
22258
a6af570dad75
patch 8.2.1678: crash when using ":set" after ":ownsyntax"
Bram Moolenaar <Bram@vim.org>
parents:
21240
diff
changeset
|
6332 // make sure option values are "empty_option" instead of NULL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6333 clear_string_option(&curwin->w_s->b_p_spc); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6334 clear_string_option(&curwin->w_s->b_p_spf); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6335 clear_string_option(&curwin->w_s->b_p_spl); |
22258
a6af570dad75
patch 8.2.1678: crash when using ":set" after ":ownsyntax"
Bram Moolenaar <Bram@vim.org>
parents:
21240
diff
changeset
|
6336 clear_string_option(&curwin->w_s->b_p_spo); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6337 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6338 clear_string_option(&curwin->w_s->b_syn_isk); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6339 } |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6340 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6341 // save value of b:current_syntax |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6342 old_value = get_var_value((char_u *)"b:current_syntax"); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6343 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6344 old_value = vim_strsave(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6345 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6346 // Apply the "syntax" autocommand event, this finds and loads the syntax |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6347 // file. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6348 apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, TRUE, curbuf); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6349 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6350 // move value of b:current_syntax to w:current_syntax |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6351 new_value = get_var_value((char_u *)"b:current_syntax"); |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6352 if (new_value != NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6353 set_internal_string_var((char_u *)"w:current_syntax", new_value); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6354 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6355 // restore value of b:current_syntax |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6356 if (old_value == NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6357 do_unlet((char_u *)"b:current_syntax", TRUE); |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6358 else |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6359 { |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6360 set_internal_string_var((char_u *)"b:current_syntax", old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6361 vim_free(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6362 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6363 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6364 |
7 | 6365 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6366 syntax_present(win_T *win) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6367 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6368 return (win->w_s->b_syn_patterns.ga_len != 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6369 || win->w_s->b_syn_clusters.ga_len != 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6370 || win->w_s->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6371 || win->w_s->b_keywtab_ic.ht_used > 0); |
7 | 6372 } |
6373 | |
6374 | |
6375 static enum | |
6376 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6377 EXP_SUBCMD, // expand ":syn" sub-commands |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6378 EXP_CASE, // expand ":syn case" arguments |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6379 EXP_SPELL, // expand ":syn spell" arguments |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6380 EXP_SYNC // expand ":syn sync" arguments |
7 | 6381 } expand_what; |
6382 | |
1322 | 6383 /* |
6384 * Reset include_link, include_default, include_none to 0. | |
6385 * Called when we are done expanding. | |
6386 */ | |
6387 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6388 reset_expand_highlight(void) |
1322 | 6389 { |
6390 include_link = include_default = include_none = 0; | |
6391 } | |
6392 | |
6393 /* | |
6394 * Handle command line completion for :match and :echohl command: Add "None" | |
6395 * as highlight group. | |
6396 */ | |
6397 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6398 set_context_in_echohl_cmd(expand_T *xp, char_u *arg) |
1322 | 6399 { |
6400 xp->xp_context = EXPAND_HIGHLIGHT; | |
6401 xp->xp_pattern = arg; | |
6402 include_none = 1; | |
6403 } | |
7 | 6404 |
6405 /* | |
6406 * Handle command line completion for :syntax command. | |
6407 */ | |
6408 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6409 set_context_in_syntax_cmd(expand_T *xp, char_u *arg) |
7 | 6410 { |
6411 char_u *p; | |
6412 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6413 // Default: expand subcommands |
7 | 6414 xp->xp_context = EXPAND_SYNTAX; |
6415 expand_what = EXP_SUBCMD; | |
6416 xp->xp_pattern = arg; | |
1322 | 6417 include_link = 0; |
6418 include_default = 0; | |
7 | 6419 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6420 // (part of) subcommand already typed |
7 | 6421 if (*arg != NUL) |
6422 { | |
6423 p = skiptowhite(arg); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6424 if (*p != NUL) // past first word |
7 | 6425 { |
6426 xp->xp_pattern = skipwhite(p); | |
6427 if (*skiptowhite(xp->xp_pattern) != NUL) | |
6428 xp->xp_context = EXPAND_NOTHING; | |
6429 else if (STRNICMP(arg, "case", p - arg) == 0) | |
6430 expand_what = EXP_CASE; | |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6431 else if (STRNICMP(arg, "spell", p - arg) == 0) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6432 expand_what = EXP_SPELL; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6433 else if (STRNICMP(arg, "sync", p - arg) == 0) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6434 expand_what = EXP_SYNC; |
7 | 6435 else if ( STRNICMP(arg, "keyword", p - arg) == 0 |
6436 || STRNICMP(arg, "region", p - arg) == 0 | |
6437 || STRNICMP(arg, "match", p - arg) == 0 | |
6438 || STRNICMP(arg, "list", p - arg) == 0) | |
6439 xp->xp_context = EXPAND_HIGHLIGHT; | |
6440 else | |
6441 xp->xp_context = EXPAND_NOTHING; | |
6442 } | |
6443 } | |
6444 } | |
6445 | |
6446 /* | |
6447 * Function given to ExpandGeneric() to obtain the list syntax names for | |
6448 * expansion. | |
6449 */ | |
6450 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6451 get_syntax_name(expand_T *xp UNUSED, int idx) |
7 | 6452 { |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6453 switch (expand_what) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6454 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6455 case EXP_SUBCMD: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6456 return (char_u *)subcommands[idx].name; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6457 case EXP_CASE: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6458 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6459 static char *case_args[] = {"match", "ignore", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6460 return (char_u *)case_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6461 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6462 case EXP_SPELL: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6463 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6464 static char *spell_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6465 {"toplevel", "notoplevel", "default", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6466 return (char_u *)spell_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6467 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6468 case EXP_SYNC: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6469 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6470 static char *sync_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6471 {"ccomment", "clear", "fromstart", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6472 "linebreaks=", "linecont", "lines=", "match", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6473 "maxlines=", "minlines=", "region", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6474 return (char_u *)sync_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6475 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6476 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6477 return NULL; |
7 | 6478 } |
6479 | |
6480 | |
6481 /* | |
6482 * Function called for expression evaluation: get syntax ID at file position. | |
6483 */ | |
6484 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6485 syn_get_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6486 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6487 long lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6488 colnr_T col, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6489 int trans, // remove transparency |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6490 int *spellp, // return: can do spell checking |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6491 int keep_state) // keep state of char at "col" |
7 | 6492 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6493 // When the position is not after the current position and in the same |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6494 // line of the same buffer, need to restart parsing. |
499 | 6495 if (wp->w_buffer != syn_buf |
7 | 6496 || lnum != current_lnum |
253 | 6497 || col < current_col) |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6498 syntax_start(wp, lnum); |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6499 else if (wp->w_buffer == syn_buf |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6500 && lnum == current_lnum |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6501 && col > current_col) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6502 // next_match may not be correct when moving around, e.g. with the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6503 // "skip" expression in searchpair() |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6504 next_match_idx = -1; |
7 | 6505 |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6506 (void)get_syntax_attr(col, spellp, keep_state); |
7 | 6507 |
6508 return (trans ? current_trans_id : current_id); | |
6509 } | |
6510 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6511 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6512 /* |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6513 * Get extra information about the syntax item. Must be called right after |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6514 * get_syntax_attr(). |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
6515 * Stores the current item sequence nr in "*seqnrp". |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6516 * Returns the current flags. |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6517 */ |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6518 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6519 get_syntax_info(int *seqnrp) |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
6520 { |
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
6521 *seqnrp = current_seqnr; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6522 return current_flags; |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6523 } |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6524 |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6525 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6526 * Return conceal substitution character |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6527 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6528 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6529 syn_get_sub_char(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6530 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6531 return current_sub_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6532 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6533 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6534 |
1500 | 6535 #if defined(FEAT_EVAL) || defined(PROTO) |
6536 /* | |
6537 * Return the syntax ID at position "i" in the current stack. | |
6538 * The caller must have called syn_get_id() before to fill the stack. | |
6539 * Returns -1 when "i" is out of range. | |
6540 */ | |
6541 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6542 syn_get_stack_item(int i) |
1500 | 6543 { |
1504 | 6544 if (i >= current_state.ga_len) |
6545 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6546 // Need to invalidate the state, because we didn't properly finish it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6547 // for the last character, "keep_state" was TRUE. |
1504 | 6548 invalidate_current_state(); |
6549 current_col = MAXCOL; | |
1500 | 6550 return -1; |
1504 | 6551 } |
1500 | 6552 return CUR_STATE(i).si_id; |
6553 } | |
6554 #endif | |
6555 | |
7 | 6556 #if defined(FEAT_FOLDING) || defined(PROTO) |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6557 static int |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6558 syn_cur_foldlevel(void) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6559 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6560 int level = 0; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6561 int i; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6562 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6563 for (i = 0; i < current_state.ga_len; ++i) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6564 if (CUR_STATE(i).si_flags & HL_FOLD) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6565 ++level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6566 return level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6567 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6568 |
7 | 6569 /* |
6570 * Function called to get folding level for line "lnum" in window "wp". | |
6571 */ | |
6572 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6573 syn_get_foldlevel(win_T *wp, long lnum) |
7 | 6574 { |
6575 int level = 0; | |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6576 int low_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6577 int cur_level; |
7 | 6578 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6579 // Return quickly when there are no fold items at all. |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6580 if (wp->w_s->b_syn_folditems != 0 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6581 && !wp->w_s->b_syn_error |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6582 # ifdef SYN_TIME_LIMIT |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6583 && !wp->w_s->b_syn_slow |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6584 # endif |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6585 ) |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6586 { |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6587 syntax_start(wp, lnum); |
7 | 6588 |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6589 // Start with the fold level at the start of the line. |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6590 level = syn_cur_foldlevel(); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6591 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6592 if (wp->w_s->b_syn_foldlevel == SYNFLD_MINIMUM) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6593 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6594 // Find the lowest fold level that is followed by a higher one. |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6595 cur_level = level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6596 low_level = cur_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6597 while (!current_finished) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6598 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6599 (void)syn_current_attr(FALSE, FALSE, NULL, FALSE); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6600 cur_level = syn_cur_foldlevel(); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6601 if (cur_level < low_level) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6602 low_level = cur_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6603 else if (cur_level > low_level) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6604 level = low_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6605 ++current_col; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6606 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6607 } |
7 | 6608 } |
6609 if (level > wp->w_p_fdn) | |
1028 | 6610 { |
7 | 6611 level = wp->w_p_fdn; |
1028 | 6612 if (level < 0) |
6613 level = 0; | |
6614 } | |
7 | 6615 return level; |
6616 } | |
6617 #endif | |
6618 | |
6567 | 6619 #if defined(FEAT_PROFILE) || defined(PROTO) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6620 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6621 * ":syntime". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6622 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6623 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6624 ex_syntime(exarg_T *eap) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6625 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6626 if (STRCMP(eap->arg, "on") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6627 syn_time_on = TRUE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6628 else if (STRCMP(eap->arg, "off") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6629 syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6630 else if (STRCMP(eap->arg, "clear") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6631 syntime_clear(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6632 else if (STRCMP(eap->arg, "report") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6633 syntime_report(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6634 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
6635 semsg(_(e_invarg2), eap->arg); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6636 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6637 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6638 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6639 syn_clear_time(syn_time_T *st) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6640 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6641 profile_zero(&st->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6642 profile_zero(&st->slowest); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6643 st->count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6644 st->match = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6645 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6646 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6647 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6648 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6649 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6650 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6651 syntime_clear(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6652 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6653 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6654 synpat_T *spp; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6655 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6656 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6657 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6658 msg(_(msg_no_items)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6659 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6660 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6661 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6662 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6663 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6664 syn_clear_time(&spp->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6665 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6666 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6667 |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6668 /* |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6669 * Function given to ExpandGeneric() to obtain the possible arguments of the |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6670 * ":syntime {on,off,clear,report}" command. |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6671 */ |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6672 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6673 get_syntime_arg(expand_T *xp UNUSED, int idx) |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6674 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6675 switch (idx) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6676 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6677 case 0: return (char_u *)"on"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6678 case 1: return (char_u *)"off"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6679 case 2: return (char_u *)"clear"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6680 case 3: return (char_u *)"report"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6681 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6682 return NULL; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6683 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6684 |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6685 typedef struct |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6686 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6687 proftime_T total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6688 int count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6689 int match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6690 proftime_T slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6691 proftime_T average; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6692 int id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6693 char_u *pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6694 } time_entry_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6695 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6696 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6697 syn_compare_syntime(const void *v1, const void *v2) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6698 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6699 const time_entry_T *s1 = v1; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6700 const time_entry_T *s2 = v2; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6701 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6702 return profile_cmp(&s1->total, &s2->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6703 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6704 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6705 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6706 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6707 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6708 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6709 syntime_report(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6710 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6711 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6712 synpat_T *spp; |
22991
cb7df44afe7e
patch 8.2.2042: build failure with +profile but without +reltime
Bram Moolenaar <Bram@vim.org>
parents:
22928
diff
changeset
|
6713 # if defined(FEAT_RELTIME) && defined(FEAT_FLOAT) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6714 proftime_T tm; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6715 # endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6716 int len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6717 proftime_T total_total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6718 int total_count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6719 garray_T ga; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6720 time_entry_T *p; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6721 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6722 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6723 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6724 msg(_(msg_no_items)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6725 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6726 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6727 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6728 ga_init2(&ga, sizeof(time_entry_T), 50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6729 profile_zero(&total_total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6730 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6731 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6732 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6733 if (spp->sp_time.count > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6734 { |
7009 | 6735 (void)ga_grow(&ga, 1); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6736 p = ((time_entry_T *)ga.ga_data) + ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6737 p->total = spp->sp_time.total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6738 profile_add(&total_total, &spp->sp_time.total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6739 p->count = spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6740 p->match = spp->sp_time.match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6741 total_count += spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6742 p->slowest = spp->sp_time.slowest; |
22991
cb7df44afe7e
patch 8.2.2042: build failure with +profile but without +reltime
Bram Moolenaar <Bram@vim.org>
parents:
22928
diff
changeset
|
6743 # if defined(FEAT_RELTIME) && defined(FEAT_FLOAT) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6744 profile_divide(&spp->sp_time.total, spp->sp_time.count, &tm); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6745 p->average = tm; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6746 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6747 p->id = spp->sp_syn.id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6748 p->pattern = spp->sp_pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6749 ++ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6750 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6751 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6752 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6753 // Sort on total time. Skip if there are no items to avoid passing NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6754 // pointer to qsort(). |
10530
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6755 if (ga.ga_len > 1) |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6756 qsort(ga.ga_data, (size_t)ga.ga_len, sizeof(time_entry_T), |
4776
e4bc21965079
updated for version 7.3.1135
Bram Moolenaar <bram@vim.org>
parents:
4766
diff
changeset
|
6757 syn_compare_syntime); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6758 |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6759 msg_puts_title(_(" TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6760 msg_puts("\n"); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6761 for (idx = 0; idx < ga.ga_len && !got_int; ++idx) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6762 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6763 p = ((time_entry_T *)ga.ga_data) + idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6764 |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6765 msg_puts(profile_msg(&p->total)); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6766 msg_puts(" "); // make sure there is always a separating space |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6767 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6768 msg_outnum(p->count); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6769 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6770 msg_advance(20); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6771 msg_outnum(p->match); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6772 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6773 msg_advance(26); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6774 msg_puts(profile_msg(&p->slowest)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6775 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6776 msg_advance(38); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6777 # ifdef FEAT_FLOAT |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6778 msg_puts(profile_msg(&p->average)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6779 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6780 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6781 msg_advance(50); |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
6782 msg_outtrans(highlight_group_name(p->id - 1)); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6783 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6784 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6785 msg_advance(69); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6786 if (Columns < 80) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6787 len = 20; // will wrap anyway |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6788 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6789 len = Columns - 70; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6790 if (len > (int)STRLEN(p->pattern)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6791 len = (int)STRLEN(p->pattern); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6792 msg_outtrans_len(p->pattern, len); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6793 msg_puts("\n"); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6794 } |
4791
65cef998f860
updated for version 7.3.1142
Bram Moolenaar <bram@vim.org>
parents:
4776
diff
changeset
|
6795 ga_clear(&ga); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6796 if (!got_int) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6797 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6798 msg_puts("\n"); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6799 msg_puts(profile_msg(&total_total)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6800 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6801 msg_outnum(total_count); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6802 msg_puts("\n"); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6803 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6804 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6805 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6806 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6807 #endif // FEAT_SYN_HL |