Mercurial > vim
annotate src/syntax.c @ 2253:12ebd6f6dfce vim73
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sun, 06 Jun 2010 16:11:09 +0200 |
parents | a0b5918c33cc |
children | 8b3203df361f |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
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 /* | |
17 * Structure that stores information about a highlight group. | |
18 * The ID of a highlight group is also called group ID. It is the index in | |
19 * the highlight_ga array PLUS ONE. | |
20 */ | |
21 struct hl_group | |
22 { | |
23 char_u *sg_name; /* highlight group name */ | |
24 char_u *sg_name_u; /* uppercase of sg_name */ | |
25 /* for normal terminals */ | |
26 int sg_term; /* "term=" highlighting attributes */ | |
27 char_u *sg_start; /* terminal string for start highl */ | |
28 char_u *sg_stop; /* terminal string for stop highl */ | |
29 int sg_term_attr; /* Screen attr for term mode */ | |
30 /* for color terminals */ | |
31 int sg_cterm; /* "cterm=" highlighting attr */ | |
32 int sg_cterm_bold; /* bold attr was set for light color */ | |
33 int sg_cterm_fg; /* terminal fg color number + 1 */ | |
34 int sg_cterm_bg; /* terminal bg color number + 1 */ | |
35 int sg_cterm_attr; /* Screen attr for color term mode */ | |
36 #ifdef FEAT_GUI | |
37 /* for when using the GUI */ | |
38 int sg_gui; /* "gui=" highlighting attributes */ | |
39 guicolor_T sg_gui_fg; /* GUI foreground color handle */ | |
40 char_u *sg_gui_fg_name;/* GUI foreground color name */ | |
41 guicolor_T sg_gui_bg; /* GUI background color handle */ | |
42 char_u *sg_gui_bg_name;/* GUI background color name */ | |
205 | 43 guicolor_T sg_gui_sp; /* GUI special color handle */ |
44 char_u *sg_gui_sp_name;/* GUI special color name */ | |
7 | 45 GuiFont sg_font; /* GUI font handle */ |
46 #ifdef FEAT_XFONTSET | |
47 GuiFontset sg_fontset; /* GUI fontset handle */ | |
48 #endif | |
49 char_u *sg_font_name; /* GUI font or fontset name */ | |
50 int sg_gui_attr; /* Screen attr for GUI mode */ | |
51 #endif | |
52 int sg_link; /* link to this highlight group ID */ | |
53 int sg_set; /* combination of SG_* flags */ | |
448 | 54 #ifdef FEAT_EVAL |
55 scid_T sg_scriptID; /* script in which the group was last set */ | |
56 #endif | |
7 | 57 }; |
58 | |
59 #define SG_TERM 1 /* term has been set */ | |
60 #define SG_CTERM 2 /* cterm has been set */ | |
61 #define SG_GUI 4 /* gui has been set */ | |
62 #define SG_LINK 8 /* link has been set */ | |
63 | |
64 static garray_T highlight_ga; /* highlight groups for 'highlight' option */ | |
65 | |
66 #define HL_TABLE() ((struct hl_group *)((highlight_ga.ga_data))) | |
67 | |
68 #ifdef FEAT_CMDL_COMPL | |
1322 | 69 /* Flags to indicate an additional string for highlight name completion. */ |
70 static int include_none = 0; /* when 1 include "None" */ | |
71 static int include_default = 0; /* when 1 include "default" */ | |
72 static int include_link = 0; /* when 2 include "link" and "clear" */ | |
7 | 73 #endif |
74 | |
75 /* | |
76 * The "term", "cterm" and "gui" arguments can be any combination of the | |
77 * following names, separated by commas (but no spaces!). | |
78 */ | |
79 static char *(hl_name_table[]) = | |
205 | 80 {"bold", "standout", "underline", "undercurl", |
81 "italic", "reverse", "inverse", "NONE"}; | |
7 | 82 static int hl_attr_table[] = |
205 | 83 {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, 0}; |
7 | 84 |
85 static int get_attr_entry __ARGS((garray_T *table, attrentry_T *aep)); | |
86 static void syn_unadd_group __ARGS((void)); | |
87 static void set_hl_attr __ARGS((int idx)); | |
88 static void highlight_list_one __ARGS((int id)); | |
89 static int highlight_list_arg __ARGS((int id, int didh, int type, int iarg, char_u *sarg, char *name)); | |
90 static int syn_add_group __ARGS((char_u *name)); | |
91 static int syn_list_header __ARGS((int did_header, int outlen, int id)); | |
92 static int hl_has_settings __ARGS((int idx, int check_link)); | |
93 static void highlight_clear __ARGS((int idx)); | |
94 | |
95 #ifdef FEAT_GUI | |
96 static void gui_do_one_color __ARGS((int idx, int do_menu, int do_tooltip)); | |
97 static int set_group_colors __ARGS((char_u *name, guicolor_T *fgp, guicolor_T *bgp, int do_menu, int use_norm, int do_tooltip)); | |
98 static guicolor_T color_name2handle __ARGS((char_u *name)); | |
99 static GuiFont font_name2handle __ARGS((char_u *name)); | |
100 # ifdef FEAT_XFONTSET | |
101 static GuiFontset fontset_name2handle __ARGS((char_u *name, int fixed_width)); | |
102 # endif | |
103 static void hl_do_font __ARGS((int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip)); | |
104 #endif | |
105 | |
106 /* | |
107 * An attribute number is the index in attr_table plus ATTR_OFF. | |
108 */ | |
109 #define ATTR_OFF (HL_ALL + 1) | |
110 | |
111 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
112 | |
113 #define SYN_NAMELEN 50 /* maximum length of a syntax name */ | |
114 | |
115 /* different types of offsets that are possible */ | |
116 #define SPO_MS_OFF 0 /* match start offset */ | |
117 #define SPO_ME_OFF 1 /* match end offset */ | |
118 #define SPO_HS_OFF 2 /* highl. start offset */ | |
119 #define SPO_HE_OFF 3 /* highl. end offset */ | |
120 #define SPO_RS_OFF 4 /* region start offset */ | |
121 #define SPO_RE_OFF 5 /* region end offset */ | |
122 #define SPO_LC_OFF 6 /* leading context offset */ | |
123 #define SPO_COUNT 7 | |
124 | |
125 static char *(spo_name_tab[SPO_COUNT]) = | |
126 {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; | |
127 | |
128 /* | |
129 * The patterns that are being searched for are stored in a syn_pattern. | |
130 * A match item consists of one pattern. | |
131 * A start/end item consists of n start patterns and m end patterns. | |
132 * A start/skip/end item consists of n start patterns, one skip pattern and m | |
133 * end patterns. | |
134 * For the latter two, the patterns are always consecutive: start-skip-end. | |
135 * | |
136 * A character offset can be given for the matched text (_m_start and _m_end) | |
137 * and for the actually highlighted text (_h_start and _h_end). | |
138 */ | |
139 typedef struct syn_pattern | |
140 { | |
141 char sp_type; /* see SPTYPE_ defines below */ | |
142 char sp_syncing; /* this item used for syncing */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
143 int sp_flags; /* see HL_ defines below */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
144 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
145 int sp_char; /* conceal substitute character */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
146 #endif |
7 | 147 struct sp_syn sp_syn; /* struct passed to in_id_list() */ |
148 short sp_syn_match_id; /* highlight group ID of pattern */ | |
149 char_u *sp_pattern; /* regexp to match, pattern */ | |
150 regprog_T *sp_prog; /* regexp to match, program */ | |
151 int sp_ic; /* ignore-case flag for sp_prog */ | |
152 short sp_off_flags; /* see below */ | |
153 int sp_offsets[SPO_COUNT]; /* offsets */ | |
154 short *sp_cont_list; /* cont. group IDs, if non-zero */ | |
155 short *sp_next_list; /* next group IDs, if non-zero */ | |
156 int sp_sync_idx; /* sync item index (syncing only) */ | |
157 int sp_line_id; /* ID of last line where tried */ | |
158 int sp_startcol; /* next match in sp_line_id line */ | |
159 } synpat_T; | |
160 | |
161 /* The sp_off_flags are computed like this: | |
162 * offset from the start of the matched text: (1 << SPO_XX_OFF) | |
163 * offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) | |
164 * When both are present, only one is used. | |
165 */ | |
166 | |
167 #define SPTYPE_MATCH 1 /* match keyword with this group ID */ | |
168 #define SPTYPE_START 2 /* match a regexp, start of item */ | |
169 #define SPTYPE_END 3 /* match a regexp, end of item */ | |
170 #define SPTYPE_SKIP 4 /* match a regexp, skip within item */ | |
171 | |
172 | |
173 #define SYN_ITEMS(buf) ((synpat_T *)((buf)->b_syn_patterns.ga_data)) | |
174 | |
175 #define NONE_IDX -2 /* value of sp_sync_idx for "NONE" */ | |
176 | |
177 /* | |
178 * Flags for b_syn_sync_flags: | |
179 */ | |
180 #define SF_CCOMMENT 0x01 /* sync on a C-style comment */ | |
181 #define SF_MATCH 0x02 /* sync by matching a pattern */ | |
182 | |
183 #define SYN_STATE_P(ssp) ((bufstate_T *)((ssp)->ga_data)) | |
184 | |
185 #define MAXKEYWLEN 80 /* maximum length of a keyword */ | |
186 | |
187 /* | |
188 * The attributes of the syntax item that has been recognized. | |
189 */ | |
190 static int current_attr = 0; /* attr of current syntax word */ | |
191 #ifdef FEAT_EVAL | |
192 static int current_id = 0; /* ID of current char for syn_get_id() */ | |
2020 | 193 static int current_trans_id = 0; /* idem, transparency removed */ |
7 | 194 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
195 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
196 static int current_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
197 static int current_sub_char = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
198 #endif |
7 | 199 |
221 | 200 typedef struct syn_cluster_S |
7 | 201 { |
202 char_u *scl_name; /* syntax cluster name */ | |
203 char_u *scl_name_u; /* uppercase of scl_name */ | |
204 short *scl_list; /* IDs in this syntax cluster */ | |
221 | 205 } syn_cluster_T; |
7 | 206 |
207 /* | |
208 * Methods of combining two clusters | |
209 */ | |
210 #define CLUSTER_REPLACE 1 /* replace first list with second */ | |
211 #define CLUSTER_ADD 2 /* add second list to first */ | |
212 #define CLUSTER_SUBTRACT 3 /* subtract second list from first */ | |
213 | |
221 | 214 #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data)) |
7 | 215 |
216 /* | |
217 * Syntax group IDs have different types: | |
218 * 0 - 9999 normal syntax groups | |
219 * 10000 - 14999 ALLBUT indicator (current_syn_inc_tag added) | |
220 * 15000 - 19999 TOP indicator (current_syn_inc_tag added) | |
221 * 20000 - 24999 CONTAINED indicator (current_syn_inc_tag added) | |
222 * >= 25000 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) | |
223 */ | |
224 #define SYNID_ALLBUT 10000 /* syntax group ID for contains=ALLBUT */ | |
225 #define SYNID_TOP 15000 /* syntax group ID for contains=TOP */ | |
226 #define SYNID_CONTAINED 20000 /* syntax group ID for contains=CONTAINED */ | |
227 #define SYNID_CLUSTER 25000 /* first syntax group ID for clusters */ | |
228 | |
229 /* | |
230 * Annoying Hack(TM): ":syn include" needs this pointer to pass to | |
231 * expand_filename(). Most of the other syntax commands don't need it, so | |
232 * instead of passing it to them, we stow it here. | |
233 */ | |
234 static char_u **syn_cmdlinep; | |
235 | |
236 /* | |
237 * 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
|
238 * files from leaking into ALLBUT lists, we assign a unique ID to the |
7 | 239 * rules in each ":syn include"'d file. |
240 */ | |
241 static int current_syn_inc_tag = 0; | |
242 static int running_syn_inc_tag = 0; | |
243 | |
244 /* | |
134 | 245 * In a hashtable item "hi_key" points to "keyword" in a keyentry. |
246 * This avoids adding a pointer to the hashtable item. | |
247 * KE2HIKEY() converts a var pointer to a hashitem key pointer. | |
248 * HIKEY2KE() converts a hashitem key pointer to a var pointer. | |
249 * HI2KE() converts a hashitem pointer to a var pointer. | |
250 */ | |
251 static keyentry_T dumkey; | |
252 #define KE2HIKEY(kp) ((kp)->keyword) | |
253 #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey))) | |
254 #define HI2KE(hi) HIKEY2KE((hi)->hi_key) | |
255 | |
256 /* | |
7 | 257 * To reduce the time spent in keepend(), remember at which level in the state |
258 * stack the first item with "keepend" is present. When "-1", there is no | |
259 * "keepend" on the stack. | |
260 */ | |
261 static int keepend_level = -1; | |
262 | |
263 /* | |
264 * For the current state we need to remember more than just the idx. | |
265 * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. | |
266 * (The end positions have the column number of the next char) | |
267 */ | |
268 typedef struct state_item | |
269 { | |
1371 | 270 int si_idx; /* index of syntax pattern or |
271 KEYWORD_IDX */ | |
7 | 272 int si_id; /* highlight group ID for keywords */ |
2020 | 273 int si_trans_id; /* idem, transparency removed */ |
7 | 274 int si_m_lnum; /* lnum of the match */ |
275 int si_m_startcol; /* starting column of the match */ | |
276 lpos_T si_m_endpos; /* just after end posn of the match */ | |
277 lpos_T si_h_startpos; /* start position of the highlighting */ | |
278 lpos_T si_h_endpos; /* end position of the highlighting */ | |
279 lpos_T si_eoe_pos; /* end position of end pattern */ | |
280 int si_end_idx; /* group ID for end pattern or zero */ | |
281 int si_ends; /* if match ends before si_m_endpos */ | |
282 int si_attr; /* attributes in this state */ | |
283 long si_flags; /* HL_HAS_EOL flag in this state, and | |
284 * HL_SKIP* for si_next_list */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
285 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
286 int si_char; /* substitution character for conceal */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
287 #endif |
7 | 288 short *si_cont_list; /* list of contained groups */ |
289 short *si_next_list; /* nextgroup IDs after this item ends */ | |
290 reg_extmatch_T *si_extmatch; /* \z(...\) matches from start | |
291 * pattern */ | |
292 } stateitem_T; | |
293 | |
294 #define KEYWORD_IDX -1 /* value of si_idx for keywords */ | |
295 #define ID_LIST_ALL (short *)-1 /* valid of si_cont_list for containing all | |
296 but contained groups */ | |
297 | |
298 /* | |
154 | 299 * Struct to reduce the number of arguments to get_syn_options(), it's used |
300 * very often. | |
301 */ | |
302 typedef struct | |
303 { | |
1222 | 304 int flags; /* flags for contained and transparent */ |
154 | 305 int keyword; /* TRUE for ":syn keyword" */ |
306 int *sync_idx; /* syntax item for "grouphere" argument, NULL | |
307 if not allowed */ | |
308 char has_cont_list; /* TRUE if "cont_list" can be used */ | |
309 short *cont_list; /* group IDs for "contains" argument */ | |
310 short *cont_in_list; /* group IDs for "containedin" argument */ | |
311 short *next_list; /* group IDs for "nextgroup" argument */ | |
312 } syn_opt_arg_T; | |
313 | |
314 /* | |
7 | 315 * The next possible match in the current line for any pattern is remembered, |
316 * to avoid having to try for a match in each column. | |
317 * If next_match_idx == -1, not tried (in this line) yet. | |
318 * If next_match_col == MAXCOL, no match found in this line. | |
319 * (All end positions have the column of the char after the end) | |
320 */ | |
321 static int next_match_col; /* column for start of next match */ | |
322 static lpos_T next_match_m_endpos; /* position for end of next match */ | |
323 static lpos_T next_match_h_startpos; /* pos. for highl. start of next match */ | |
324 static lpos_T next_match_h_endpos; /* pos. for highl. end of next match */ | |
325 static int next_match_idx; /* index of matched item */ | |
326 static long next_match_flags; /* flags for next match */ | |
327 static lpos_T next_match_eos_pos; /* end of start pattn (start region) */ | |
328 static lpos_T next_match_eoe_pos; /* pos. for end of end pattern */ | |
329 static int next_match_end_idx; /* ID of group for end pattn or zero */ | |
330 static reg_extmatch_T *next_match_extmatch = NULL; | |
331 | |
332 /* | |
333 * A state stack is an array of integers or stateitem_T, stored in a | |
334 * garray_T. A state stack is invalid if it's itemsize entry is zero. | |
335 */ | |
336 #define INVALID_STATE(ssp) ((ssp)->ga_itemsize == 0) | |
337 #define VALID_STATE(ssp) ((ssp)->ga_itemsize != 0) | |
338 | |
339 /* | |
340 * The current state (within the line) of the recognition engine. | |
341 * When current_state.ga_itemsize is 0 the current state is invalid. | |
342 */ | |
343 static win_T *syn_win; /* current window for highlighting */ | |
344 static buf_T *syn_buf; /* current buffer for highlighting */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
345 static synblock_T *syn_block; /* current buffer for highlighting */ |
7 | 346 static linenr_T current_lnum = 0; /* lnum of current state */ |
347 static colnr_T current_col = 0; /* column of current state */ | |
348 static int current_state_stored = 0; /* TRUE if stored current state | |
349 * after setting current_finished */ | |
350 static int current_finished = 0; /* current line has been finished */ | |
351 static garray_T current_state /* current stack of state_items */ | |
352 = {0, 0, 0, 0, NULL}; | |
353 static short *current_next_list = NULL; /* when non-zero, nextgroup list */ | |
354 static int current_next_flags = 0; /* flags for current_next_list */ | |
355 static int current_line_id = 0; /* unique number for current line */ | |
356 | |
357 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] | |
358 | |
359 static void syn_sync __ARGS((win_T *wp, linenr_T lnum, synstate_T *last_valid)); | |
360 static int syn_match_linecont __ARGS((linenr_T lnum)); | |
361 static void syn_start_line __ARGS((void)); | |
362 static void syn_update_ends __ARGS((int startofline)); | |
363 static void syn_stack_alloc __ARGS((void)); | |
364 static int syn_stack_cleanup __ARGS((void)); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
365 static void syn_stack_free_entry __ARGS((synblock_T *block, synstate_T *p)); |
7 | 366 static synstate_T *syn_stack_find_entry __ARGS((linenr_T lnum)); |
1512 | 367 static synstate_T *store_current_state __ARGS((void)); |
7 | 368 static void load_current_state __ARGS((synstate_T *from)); |
369 static void invalidate_current_state __ARGS((void)); | |
370 static int syn_stack_equal __ARGS((synstate_T *sp)); | |
371 static void validate_current_state __ARGS((void)); | |
372 static int syn_finish_line __ARGS((int syncing)); | |
1504 | 373 static int syn_current_attr __ARGS((int syncing, int displaying, int *can_spell, int keep_state)); |
7 | 374 static int did_match_already __ARGS((int idx, garray_T *gap)); |
375 static stateitem_T *push_next_match __ARGS((stateitem_T *cur_si)); | |
376 static void check_state_ends __ARGS((void)); | |
377 static void update_si_attr __ARGS((int idx)); | |
378 static void check_keepend __ARGS((void)); | |
379 static void update_si_end __ARGS((stateitem_T *sip, int startcol, int force)); | |
380 static short *copy_id_list __ARGS((short *list)); | |
381 static int in_id_list __ARGS((stateitem_T *item, short *cont_list, struct sp_syn *ssp, int contained)); | |
382 static int push_current_state __ARGS((int idx)); | |
383 static void pop_current_state __ARGS((void)); | |
384 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
385 static void syn_stack_apply_changes_block __ARGS((synblock_T *block, buf_T *buf)); |
7 | 386 static void find_endpos __ARGS((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)); |
387 static void clear_syn_state __ARGS((synstate_T *p)); | |
388 static void clear_current_state __ARGS((void)); | |
389 | |
390 static void limit_pos __ARGS((lpos_T *pos, lpos_T *limit)); | |
391 static void limit_pos_zero __ARGS((lpos_T *pos, lpos_T *limit)); | |
392 static void syn_add_end_off __ARGS((lpos_T *result, regmmatch_T *regmatch, synpat_T *spp, int idx, int extra)); | |
393 static void syn_add_start_off __ARGS((lpos_T *result, regmmatch_T *regmatch, synpat_T *spp, int idx, int extra)); | |
394 static char_u *syn_getcurline __ARGS((void)); | |
395 static int syn_regexec __ARGS((regmmatch_T *rmp, linenr_T lnum, colnr_T col)); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
396 static int check_keyword_id __ARGS((char_u *line, int startcol, int *endcol, long *flags, short **next_list, stateitem_T *cur_si, int *ccharp)); |
7 | 397 static void syn_cmd_case __ARGS((exarg_T *eap, int syncing)); |
419 | 398 static void syn_cmd_spell __ARGS((exarg_T *eap, int syncing)); |
7 | 399 static void syntax_sync_clear __ARGS((void)); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
400 static void syn_remove_pattern __ARGS((synblock_T *block, int idx)); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
401 static void syn_clear_pattern __ARGS((synblock_T *block, int i)); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
402 static void syn_clear_cluster __ARGS((synblock_T *block, int i)); |
7 | 403 static void syn_cmd_clear __ARGS((exarg_T *eap, int syncing)); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
404 static void syn_cmd_conceal __ARGS((exarg_T *eap, int syncing)); |
7 | 405 static void syn_clear_one __ARGS((int id, int syncing)); |
406 static void syn_cmd_on __ARGS((exarg_T *eap, int syncing)); | |
407 static void syn_cmd_enable __ARGS((exarg_T *eap, int syncing)); | |
408 static void syn_cmd_reset __ARGS((exarg_T *eap, int syncing)); | |
409 static void syn_cmd_manual __ARGS((exarg_T *eap, int syncing)); | |
410 static void syn_cmd_off __ARGS((exarg_T *eap, int syncing)); | |
411 static void syn_cmd_onoff __ARGS((exarg_T *eap, char *name)); | |
412 static void syn_cmd_list __ARGS((exarg_T *eap, int syncing)); | |
413 static void syn_lines_msg __ARGS((void)); | |
414 static void syn_match_msg __ARGS((void)); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
415 static void syn_stack_free_block __ARGS((synblock_T *block)); |
7 | 416 static void syn_list_one __ARGS((int id, int syncing, int link_only)); |
417 static void syn_list_cluster __ARGS((int id)); | |
418 static void put_id_list __ARGS((char_u *name, short *list, int attr)); | |
419 static void put_pattern __ARGS((char *s, int c, synpat_T *spp, int attr)); | |
134 | 420 static int syn_list_keywords __ARGS((int id, hashtab_T *ht, int did_header, int attr)); |
421 static void syn_clear_keyword __ARGS((int id, hashtab_T *ht)); | |
422 static void clear_keywtab __ARGS((hashtab_T *ht)); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
423 static void add_keyword __ARGS((char_u *name, int id, int flags, short *cont_in_list, short *next_list, int conceal_char)); |
7 | 424 static char_u *get_group_name __ARGS((char_u *arg, char_u **name_end)); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
425 static char_u *get_syn_options __ARGS((char_u *arg, syn_opt_arg_T *opt, int *conceal_char)); |
7 | 426 static void syn_cmd_include __ARGS((exarg_T *eap, int syncing)); |
427 static void syn_cmd_keyword __ARGS((exarg_T *eap, int syncing)); | |
428 static void syn_cmd_match __ARGS((exarg_T *eap, int syncing)); | |
429 static void syn_cmd_region __ARGS((exarg_T *eap, int syncing)); | |
430 #ifdef __BORLANDC__ | |
431 static int _RTLENTRYF syn_compare_stub __ARGS((const void *v1, const void *v2)); | |
432 #else | |
433 static int syn_compare_stub __ARGS((const void *v1, const void *v2)); | |
434 #endif | |
435 static void syn_cmd_cluster __ARGS((exarg_T *eap, int syncing)); | |
436 static int syn_scl_name2id __ARGS((char_u *name)); | |
437 static int syn_scl_namen2id __ARGS((char_u *linep, int len)); | |
438 static int syn_check_cluster __ARGS((char_u *pp, int len)); | |
439 static int syn_add_cluster __ARGS((char_u *name)); | |
440 static void init_syn_patterns __ARGS((void)); | |
441 static char_u *get_syn_pattern __ARGS((char_u *arg, synpat_T *ci)); | |
442 static void syn_cmd_sync __ARGS((exarg_T *eap, int syncing)); | |
443 static int get_id_list __ARGS((char_u **arg, int keylen, short **list)); | |
444 static void syn_combine_list __ARGS((short **clstr1, short **clstr2, int list_op)); | |
445 static void syn_incl_toplevel __ARGS((int id, int *flagsp)); | |
446 | |
447 /* | |
448 * Start the syntax recognition for a line. This function is normally called | |
449 * from the screen updating, once for each displayed line. | |
450 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get | |
451 * it. Careful: curbuf and curwin are likely to point to another buffer and | |
452 * window. | |
453 */ | |
454 void | |
455 syntax_start(wp, lnum) | |
456 win_T *wp; | |
457 linenr_T lnum; | |
458 { | |
459 synstate_T *p; | |
460 synstate_T *last_valid = NULL; | |
461 synstate_T *last_min_valid = NULL; | |
1512 | 462 synstate_T *sp, *prev = NULL; |
7 | 463 linenr_T parsed_lnum; |
464 linenr_T first_stored; | |
465 int dist; | |
26 | 466 static int changedtick = 0; /* remember the last change ID */ |
7 | 467 |
468 /* | |
469 * After switching buffers, invalidate current_state. | |
26 | 470 * Also do this when a change was made, the current state may be invalid |
471 * then. | |
7 | 472 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
473 if (syn_block != wp->w_s || changedtick != syn_buf->b_changedtick) |
7 | 474 { |
475 invalidate_current_state(); | |
476 syn_buf = wp->w_buffer; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
477 syn_block = wp->w_s; |
7 | 478 } |
26 | 479 changedtick = syn_buf->b_changedtick; |
7 | 480 syn_win = wp; |
481 | |
482 /* | |
483 * Allocate syntax stack when needed. | |
484 */ | |
485 syn_stack_alloc(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
486 if (syn_block->b_sst_array == NULL) |
410 | 487 return; /* out of memory */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
488 syn_block->b_sst_lasttick = display_tick; |
7 | 489 |
490 /* | |
491 * If the state of the end of the previous line is useful, store it. | |
492 */ | |
493 if (VALID_STATE(¤t_state) | |
494 && current_lnum < lnum | |
495 && current_lnum < syn_buf->b_ml.ml_line_count) | |
496 { | |
497 (void)syn_finish_line(FALSE); | |
498 if (!current_state_stored) | |
499 { | |
500 ++current_lnum; | |
1512 | 501 (void)store_current_state(); |
7 | 502 } |
503 | |
504 /* | |
505 * If the current_lnum is now the same as "lnum", keep the current | |
506 * state (this happens very often!). Otherwise invalidate | |
507 * current_state and figure it out below. | |
508 */ | |
509 if (current_lnum != lnum) | |
510 invalidate_current_state(); | |
511 } | |
512 else | |
513 invalidate_current_state(); | |
514 | |
515 /* | |
516 * Try to synchronize from a saved state in b_sst_array[]. | |
517 * Only do this if lnum is not before and not to far beyond a saved state. | |
518 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
519 if (INVALID_STATE(¤t_state) && syn_block->b_sst_array != NULL) |
7 | 520 { |
521 /* Find last valid saved state before start_lnum. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
522 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 523 { |
524 if (p->sst_lnum > lnum) | |
525 break; | |
526 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0) | |
527 { | |
528 last_valid = p; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
529 if (p->sst_lnum >= lnum - syn_block->b_syn_sync_minlines) |
7 | 530 last_min_valid = p; |
531 } | |
532 } | |
533 if (last_min_valid != NULL) | |
534 load_current_state(last_min_valid); | |
535 } | |
536 | |
537 /* | |
538 * If "lnum" is before or far beyond a line with a saved state, need to | |
539 * re-synchronize. | |
540 */ | |
541 if (INVALID_STATE(¤t_state)) | |
542 { | |
543 syn_sync(wp, lnum, last_valid); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
544 first_stored = current_lnum + syn_block->b_syn_sync_minlines; |
7 | 545 } |
546 else | |
547 first_stored = current_lnum; | |
548 | |
549 /* | |
550 * Advance from the sync point or saved state until the current line. | |
551 * Save some entries for syncing with later on. | |
552 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
553 if (syn_block->b_sst_len <= Rows) |
819 | 554 dist = 999999; |
555 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
556 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 557 while (current_lnum < lnum) |
558 { | |
559 syn_start_line(); | |
560 (void)syn_finish_line(FALSE); | |
561 ++current_lnum; | |
562 | |
563 /* If we parsed at least "minlines" lines or started at a valid | |
564 * state, the current state is considered valid. */ | |
565 if (current_lnum >= first_stored) | |
566 { | |
567 /* Check if the saved state entry is for the current line and is | |
568 * equal to the current state. If so, then validate all saved | |
569 * states that depended on a change before the parsed line. */ | |
570 if (prev == NULL) | |
1512 | 571 prev = syn_stack_find_entry(current_lnum - 1); |
572 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
573 sp = syn_block->b_sst_first; |
7 | 574 else |
1512 | 575 sp = prev; |
576 while (sp != NULL && sp->sst_lnum < current_lnum) | |
577 sp = sp->sst_next; | |
7 | 578 if (sp != NULL |
579 && sp->sst_lnum == current_lnum | |
580 && syn_stack_equal(sp)) | |
581 { | |
582 parsed_lnum = current_lnum; | |
583 prev = sp; | |
584 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) | |
585 { | |
586 if (sp->sst_lnum <= lnum) | |
587 /* valid state before desired line, use this one */ | |
588 prev = sp; | |
589 else if (sp->sst_change_lnum == 0) | |
590 /* past saved states depending on change, break here. */ | |
591 break; | |
592 sp->sst_change_lnum = 0; | |
593 sp = sp->sst_next; | |
594 } | |
595 load_current_state(prev); | |
596 } | |
597 /* Store the state at this line when it's the first one, the line | |
598 * where we start parsing, or some distance from the previously | |
599 * saved state. But only when parsed at least 'minlines'. */ | |
600 else if (prev == NULL | |
601 || current_lnum == lnum | |
602 || current_lnum >= prev->sst_lnum + dist) | |
1512 | 603 prev = store_current_state(); |
7 | 604 } |
605 | |
606 /* This can take a long time: break when CTRL-C pressed. The current | |
607 * state will be wrong then. */ | |
608 line_breakcheck(); | |
609 if (got_int) | |
610 { | |
611 current_lnum = lnum; | |
612 break; | |
613 } | |
614 } | |
615 | |
616 syn_start_line(); | |
617 } | |
618 | |
619 /* | |
620 * We cannot simply discard growarrays full of state_items or buf_states; we | |
621 * have to manually release their extmatch pointers first. | |
622 */ | |
623 static void | |
624 clear_syn_state(p) | |
625 synstate_T *p; | |
626 { | |
627 int i; | |
628 garray_T *gap; | |
629 | |
630 if (p->sst_stacksize > SST_FIX_STATES) | |
631 { | |
632 gap = &(p->sst_union.sst_ga); | |
633 for (i = 0; i < gap->ga_len; i++) | |
634 unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch); | |
635 ga_clear(gap); | |
636 } | |
637 else | |
638 { | |
639 for (i = 0; i < p->sst_stacksize; i++) | |
640 unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch); | |
641 } | |
642 } | |
643 | |
644 /* | |
645 * Cleanup the current_state stack. | |
646 */ | |
647 static void | |
648 clear_current_state() | |
649 { | |
650 int i; | |
651 stateitem_T *sip; | |
652 | |
653 sip = (stateitem_T *)(current_state.ga_data); | |
654 for (i = 0; i < current_state.ga_len; i++) | |
655 unref_extmatch(sip[i].si_extmatch); | |
656 ga_clear(¤t_state); | |
657 } | |
658 | |
659 /* | |
660 * Try to find a synchronisation point for line "lnum". | |
661 * | |
662 * This sets current_lnum and the current state. One of three methods is | |
663 * used: | |
664 * 1. Search backwards for the end of a C-comment. | |
665 * 2. Search backwards for given sync patterns. | |
666 * 3. Simply start on a given number of lines above "lnum". | |
667 */ | |
668 static void | |
669 syn_sync(wp, start_lnum, last_valid) | |
670 win_T *wp; | |
671 linenr_T start_lnum; | |
672 synstate_T *last_valid; | |
673 { | |
674 buf_T *curbuf_save; | |
675 win_T *curwin_save; | |
676 pos_T cursor_save; | |
677 int idx; | |
678 linenr_T lnum; | |
679 linenr_T end_lnum; | |
680 linenr_T break_lnum; | |
681 int had_sync_point; | |
682 stateitem_T *cur_si; | |
683 synpat_T *spp; | |
684 char_u *line; | |
685 int found_flags = 0; | |
686 int found_match_idx = 0; | |
687 linenr_T found_current_lnum = 0; | |
688 int found_current_col= 0; | |
689 lpos_T found_m_endpos; | |
442 | 690 colnr_T prev_current_col; |
7 | 691 |
692 /* | |
693 * Clear any current state that might be hanging around. | |
694 */ | |
695 invalidate_current_state(); | |
696 | |
697 /* | |
698 * Start at least "minlines" back. Default starting point for parsing is | |
699 * there. | |
700 * Start further back, to avoid that scrolling backwards will result in | |
701 * resyncing for every line. Now it resyncs only one out of N lines, | |
702 * where N is minlines * 1.5, or minlines * 2 if minlines is small. | |
703 * Watch out for overflow when minlines is MAXLNUM. | |
704 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
705 if (syn_block->b_syn_sync_minlines > start_lnum) |
7 | 706 start_lnum = 1; |
707 else | |
708 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
709 if (syn_block->b_syn_sync_minlines == 1) |
7 | 710 lnum = 1; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
711 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
|
712 lnum = syn_block->b_syn_sync_minlines * 2; |
7 | 713 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
714 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
|
715 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
|
716 && lnum > syn_block->b_syn_sync_maxlines) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
717 lnum = syn_block->b_syn_sync_maxlines; |
7 | 718 if (lnum >= start_lnum) |
719 start_lnum = 1; | |
720 else | |
721 start_lnum -= lnum; | |
722 } | |
723 current_lnum = start_lnum; | |
724 | |
725 /* | |
726 * 1. Search backwards for the end of a C-style comment. | |
727 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
728 if (syn_block->b_syn_sync_flags & SF_CCOMMENT) |
7 | 729 { |
730 /* Need to make syn_buf the current buffer for a moment, to be able to | |
731 * use find_start_comment(). */ | |
732 curwin_save = curwin; | |
733 curwin = wp; | |
734 curbuf_save = curbuf; | |
735 curbuf = syn_buf; | |
736 | |
737 /* | |
738 * Skip lines that end in a backslash. | |
739 */ | |
740 for ( ; start_lnum > 1; --start_lnum) | |
741 { | |
742 line = ml_get(start_lnum - 1); | |
743 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') | |
744 break; | |
745 } | |
746 current_lnum = start_lnum; | |
747 | |
748 /* set cursor to start of search */ | |
749 cursor_save = wp->w_cursor; | |
750 wp->w_cursor.lnum = start_lnum; | |
751 wp->w_cursor.col = 0; | |
752 | |
753 /* | |
754 * If the line is inside a comment, need to find the syntax item that | |
755 * defines the comment. | |
756 * Restrict the search for the end of a comment to b_syn_sync_maxlines. | |
757 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
758 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
|
759 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
760 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
|
761 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
|
762 == syn_block->b_syn_sync_id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
763 && SYN_ITEMS(syn_block)[idx].sp_type == SPTYPE_START) |
7 | 764 { |
765 validate_current_state(); | |
766 if (push_current_state(idx) == OK) | |
767 update_si_attr(current_state.ga_len - 1); | |
768 break; | |
769 } | |
770 } | |
771 | |
772 /* restore cursor and buffer */ | |
773 wp->w_cursor = cursor_save; | |
774 curwin = curwin_save; | |
775 curbuf = curbuf_save; | |
776 } | |
777 | |
778 /* | |
779 * 2. Search backwards for given sync patterns. | |
780 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
781 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
|
782 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
783 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
|
784 && 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
|
785 break_lnum = start_lnum - syn_block->b_syn_sync_maxlines; |
7 | 786 else |
787 break_lnum = 0; | |
788 | |
699 | 789 found_m_endpos.lnum = 0; |
790 found_m_endpos.col = 0; | |
7 | 791 end_lnum = start_lnum; |
792 lnum = start_lnum; | |
793 while (--lnum > break_lnum) | |
794 { | |
795 /* This can take a long time: break when CTRL-C pressed. */ | |
796 line_breakcheck(); | |
797 if (got_int) | |
798 { | |
799 invalidate_current_state(); | |
800 current_lnum = start_lnum; | |
801 break; | |
802 } | |
803 | |
804 /* Check if we have run into a valid saved state stack now. */ | |
805 if (last_valid != NULL && lnum == last_valid->sst_lnum) | |
806 { | |
807 load_current_state(last_valid); | |
808 break; | |
809 } | |
810 | |
811 /* | |
812 * Check if the previous line has the line-continuation pattern. | |
813 */ | |
814 if (lnum > 1 && syn_match_linecont(lnum - 1)) | |
815 continue; | |
816 | |
817 /* | |
818 * Start with nothing on the state stack | |
819 */ | |
820 validate_current_state(); | |
821 | |
822 for (current_lnum = lnum; current_lnum < end_lnum; ++current_lnum) | |
823 { | |
824 syn_start_line(); | |
825 for (;;) | |
826 { | |
827 had_sync_point = syn_finish_line(TRUE); | |
828 /* | |
829 * When a sync point has been found, remember where, and | |
830 * continue to look for another one, further on in the line. | |
831 */ | |
832 if (had_sync_point && current_state.ga_len) | |
833 { | |
834 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
835 if (cur_si->si_m_endpos.lnum > start_lnum) | |
836 { | |
837 /* ignore match that goes to after where started */ | |
838 current_lnum = end_lnum; | |
839 break; | |
840 } | |
1371 | 841 if (cur_si->si_idx < 0) |
842 { | |
843 /* Cannot happen? */ | |
844 found_flags = 0; | |
845 found_match_idx = KEYWORD_IDX; | |
846 } | |
847 else | |
848 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
849 spp = &(SYN_ITEMS(syn_block)[cur_si->si_idx]); |
1371 | 850 found_flags = spp->sp_flags; |
851 found_match_idx = spp->sp_sync_idx; | |
852 } | |
7 | 853 found_current_lnum = current_lnum; |
854 found_current_col = current_col; | |
855 found_m_endpos = cur_si->si_m_endpos; | |
856 /* | |
857 * Continue after the match (be aware of a zero-length | |
858 * match). | |
859 */ | |
860 if (found_m_endpos.lnum > current_lnum) | |
861 { | |
862 current_lnum = found_m_endpos.lnum; | |
863 current_col = found_m_endpos.col; | |
864 if (current_lnum >= end_lnum) | |
865 break; | |
866 } | |
867 else if (found_m_endpos.col > current_col) | |
868 current_col = found_m_endpos.col; | |
869 else | |
870 ++current_col; | |
871 | |
872 /* syn_current_attr() will have skipped the check for | |
442 | 873 * an item that ends here, need to do that now. Be |
874 * careful not to go past the NUL. */ | |
875 prev_current_col = current_col; | |
876 if (syn_getcurline()[current_col] != NUL) | |
877 ++current_col; | |
7 | 878 check_state_ends(); |
442 | 879 current_col = prev_current_col; |
7 | 880 } |
881 else | |
882 break; | |
883 } | |
884 } | |
885 | |
886 /* | |
887 * If a sync point was encountered, break here. | |
888 */ | |
889 if (found_flags) | |
890 { | |
891 /* | |
892 * Put the item that was specified by the sync point on the | |
893 * state stack. If there was no item specified, make the | |
894 * state stack empty. | |
895 */ | |
896 clear_current_state(); | |
897 if (found_match_idx >= 0 | |
898 && push_current_state(found_match_idx) == OK) | |
899 update_si_attr(current_state.ga_len - 1); | |
900 | |
901 /* | |
902 * When using "grouphere", continue from the sync point | |
903 * match, until the end of the line. Parsing starts at | |
904 * the next line. | |
905 * For "groupthere" the parsing starts at start_lnum. | |
906 */ | |
907 if (found_flags & HL_SYNC_HERE) | |
908 { | |
909 if (current_state.ga_len) | |
910 { | |
911 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
912 cur_si->si_h_startpos.lnum = found_current_lnum; | |
913 cur_si->si_h_startpos.col = found_current_col; | |
914 update_si_end(cur_si, (int)current_col, TRUE); | |
915 check_keepend(); | |
916 } | |
917 current_col = found_m_endpos.col; | |
918 current_lnum = found_m_endpos.lnum; | |
919 (void)syn_finish_line(FALSE); | |
920 ++current_lnum; | |
921 } | |
922 else | |
923 current_lnum = start_lnum; | |
924 | |
925 break; | |
926 } | |
927 | |
928 end_lnum = lnum; | |
929 invalidate_current_state(); | |
930 } | |
931 | |
932 /* Ran into start of the file or exceeded maximum number of lines */ | |
933 if (lnum <= break_lnum) | |
934 { | |
935 invalidate_current_state(); | |
936 current_lnum = break_lnum + 1; | |
937 } | |
938 } | |
939 | |
940 validate_current_state(); | |
941 } | |
942 | |
943 /* | |
944 * Return TRUE if the line-continuation pattern matches in line "lnum". | |
945 */ | |
946 static int | |
947 syn_match_linecont(lnum) | |
948 linenr_T lnum; | |
949 { | |
950 regmmatch_T regmatch; | |
951 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
952 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
|
953 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
954 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
|
955 regmatch.regprog = syn_block->b_syn_linecont_prog; |
7 | 956 return syn_regexec(®match, lnum, (colnr_T)0); |
957 } | |
958 return FALSE; | |
959 } | |
960 | |
961 /* | |
962 * Prepare the current state for the start of a line. | |
963 */ | |
964 static void | |
965 syn_start_line() | |
966 { | |
967 current_finished = FALSE; | |
968 current_col = 0; | |
969 | |
970 /* | |
971 * Need to update the end of a start/skip/end that continues from the | |
972 * previous line and regions that have "keepend". | |
973 */ | |
974 if (current_state.ga_len > 0) | |
975 syn_update_ends(TRUE); | |
976 | |
977 next_match_idx = -1; | |
978 ++current_line_id; | |
979 } | |
980 | |
981 /* | |
982 * Check for items in the stack that need their end updated. | |
983 * When "startofline" is TRUE the last item is always updated. | |
984 * When "startofline" is FALSE the item with "keepend" is forcefully updated. | |
985 */ | |
986 static void | |
987 syn_update_ends(startofline) | |
988 int startofline; | |
989 { | |
990 stateitem_T *cur_si; | |
991 int i; | |
991 | 992 int seen_keepend; |
7 | 993 |
994 if (startofline) | |
995 { | |
996 /* Check for a match carried over from a previous line with a | |
997 * contained region. The match ends as soon as the region ends. */ | |
998 for (i = 0; i < current_state.ga_len; ++i) | |
999 { | |
1000 cur_si = &CUR_STATE(i); | |
1001 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1002 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type |
7 | 1003 == SPTYPE_MATCH |
1004 && cur_si->si_m_endpos.lnum < current_lnum) | |
1005 { | |
1006 cur_si->si_flags |= HL_MATCHCONT; | |
1007 cur_si->si_m_endpos.lnum = 0; | |
1008 cur_si->si_m_endpos.col = 0; | |
1009 cur_si->si_h_endpos = cur_si->si_m_endpos; | |
1010 cur_si->si_ends = TRUE; | |
1011 } | |
1012 } | |
1013 } | |
1014 | |
1015 /* | |
1016 * Need to update the end of a start/skip/end that continues from the | |
1017 * previous line. And regions that have "keepend", because they may | |
991 | 1018 * influence contained items. If we've just removed "extend" |
1019 * (startofline == 0) then we should update ends of normal regions | |
1020 * contained inside "keepend" because "extend" could have extended | |
1021 * these "keepend" regions as well as contained normal regions. | |
7 | 1022 * Then check for items ending in column 0. |
1023 */ | |
1024 i = current_state.ga_len - 1; | |
1025 if (keepend_level >= 0) | |
1026 for ( ; i > keepend_level; --i) | |
1027 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
1028 break; | |
991 | 1029 |
1030 seen_keepend = FALSE; | |
7 | 1031 for ( ; i < current_state.ga_len; ++i) |
1032 { | |
1033 cur_si = &CUR_STATE(i); | |
1034 if ((cur_si->si_flags & HL_KEEPEND) | |
991 | 1035 || (seen_keepend && !startofline) |
7 | 1036 || (i == current_state.ga_len - 1 && startofline)) |
1037 { | |
1038 cur_si->si_h_startpos.col = 0; /* start highl. in col 0 */ | |
1039 cur_si->si_h_startpos.lnum = current_lnum; | |
1040 | |
1041 if (!(cur_si->si_flags & HL_MATCHCONT)) | |
1042 update_si_end(cur_si, (int)current_col, !startofline); | |
991 | 1043 |
1044 if (!startofline && (cur_si->si_flags & HL_KEEPEND)) | |
1045 seen_keepend = TRUE; | |
7 | 1046 } |
1047 } | |
1048 check_keepend(); | |
1049 check_state_ends(); | |
1050 } | |
1051 | |
1052 /**************************************** | |
1053 * Handling of the state stack cache. | |
1054 */ | |
1055 | |
1056 /* | |
1057 * EXPLANATION OF THE SYNTAX STATE STACK CACHE | |
1058 * | |
1059 * To speed up syntax highlighting, the state stack for the start of some | |
1060 * lines is cached. These entries can be used to start parsing at that point. | |
1061 * | |
1062 * The stack is kept in b_sst_array[] for each buffer. There is a list of | |
1063 * valid entries. b_sst_first points to the first one, then follow sst_next. | |
1064 * The entries are sorted on line number. The first entry is often for line 2 | |
1065 * (line 1 always starts with an empty stack). | |
1066 * There is also a list for free entries. This construction is used to avoid | |
1067 * having to allocate and free memory blocks too often. | |
1068 * | |
1069 * When making changes to the buffer, this is logged in b_mod_*. When calling | |
1070 * update_screen() to update the display, it will call | |
1071 * syn_stack_apply_changes() for each displayed buffer to adjust the cached | |
1072 * entries. The entries which are inside the changed area are removed, | |
1073 * because they must be recomputed. Entries below the changed have their line | |
1074 * number adjusted for deleted/inserted lines, and have their sst_change_lnum | |
1075 * set to indicate that a check must be made if the changed lines would change | |
1076 * the cached entry. | |
1077 * | |
1078 * When later displaying lines, an entry is stored for each line. Displayed | |
1079 * lines are likely to be displayed again, in which case the state at the | |
1080 * start of the line is needed. | |
1081 * For not displayed lines, an entry is stored for every so many lines. These | |
1082 * entries will be used e.g., when scrolling backwards. The distance between | |
1083 * entries depends on the number of lines in the buffer. For small buffers | |
1084 * the distance is fixed at SST_DIST, for large buffers there is a fixed | |
1085 * number of entries SST_MAX_ENTRIES, and the distance is computed. | |
1086 */ | |
1087 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1088 static void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1089 syn_stack_free_block(block) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1090 synblock_T *block; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1091 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1092 synstate_T *p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1093 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1094 if (block->b_sst_array != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1095 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1096 for (p = block->b_sst_first; p != NULL; p = p->sst_next) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1097 clear_syn_state(p); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1098 vim_free(block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1099 block->b_sst_array = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1100 block->b_sst_len = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1101 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1102 } |
7 | 1103 /* |
1104 * Free b_sst_array[] for buffer "buf". | |
1105 * Used when syntax items changed to force resyncing everywhere. | |
1106 */ | |
1107 void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1108 syn_stack_free_all(block) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1109 synblock_T *block; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1110 { |
7 | 1111 win_T *wp; |
1112 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1113 syn_stack_free_block(block); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1114 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1115 |
7 | 1116 #ifdef FEAT_FOLDING |
1117 /* When using "syntax" fold method, must update all folds. */ | |
1118 FOR_ALL_WINDOWS(wp) | |
1119 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1120 if (wp->w_s == block && foldmethodIsSyntax(wp)) |
7 | 1121 foldUpdateAll(wp); |
1122 } | |
1123 #endif | |
1124 } | |
1125 | |
1126 /* | |
1127 * Allocate the syntax state stack for syn_buf when needed. | |
1128 * If the number of entries in b_sst_array[] is much too big or a bit too | |
1129 * small, reallocate it. | |
1130 * Also used to allocate b_sst_array[] for the first time. | |
1131 */ | |
1132 static void | |
1133 syn_stack_alloc() | |
1134 { | |
1135 long len; | |
1136 synstate_T *to, *from; | |
1137 synstate_T *sstp; | |
1138 | |
1139 len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; | |
1140 if (len < SST_MIN_ENTRIES) | |
1141 len = SST_MIN_ENTRIES; | |
1142 else if (len > SST_MAX_ENTRIES) | |
1143 len = SST_MAX_ENTRIES; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1144 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) |
7 | 1145 { |
1146 /* Allocate 50% too much, to avoid reallocating too often. */ | |
1147 len = syn_buf->b_ml.ml_line_count; | |
1148 len = (len + len / 2) / SST_DIST + Rows * 2; | |
1149 if (len < SST_MIN_ENTRIES) | |
1150 len = SST_MIN_ENTRIES; | |
1151 else if (len > SST_MAX_ENTRIES) | |
1152 len = SST_MAX_ENTRIES; | |
1153 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1154 if (syn_block->b_sst_array != NULL) |
7 | 1155 { |
1156 /* When shrinking the array, cleanup the existing stack. | |
1157 * 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
|
1158 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len |
7 | 1159 && syn_stack_cleanup()) |
1160 ; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1161 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
|
1162 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; |
7 | 1163 } |
1164 | |
1165 sstp = (synstate_T *)alloc_clear((unsigned)(len * sizeof(synstate_T))); | |
1166 if (sstp == NULL) /* out of memory! */ | |
1167 return; | |
1168 | |
1169 to = sstp - 1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1170 if (syn_block->b_sst_array != NULL) |
7 | 1171 { |
1172 /* 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
|
1173 for (from = syn_block->b_sst_first; from != NULL; |
7 | 1174 from = from->sst_next) |
1175 { | |
1176 ++to; | |
1177 *to = *from; | |
1178 to->sst_next = to + 1; | |
1179 } | |
1180 } | |
1181 if (to != sstp - 1) | |
1182 { | |
1183 to->sst_next = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1184 syn_block->b_sst_first = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1185 syn_block->b_sst_freecount = len - (int)(to - sstp) - 1; |
7 | 1186 } |
1187 else | |
1188 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1189 syn_block->b_sst_first = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1190 syn_block->b_sst_freecount = len; |
7 | 1191 } |
1192 | |
1193 /* Create the list of free entries. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1194 syn_block->b_sst_firstfree = to + 1; |
7 | 1195 while (++to < sstp + len) |
1196 to->sst_next = to + 1; | |
1197 (sstp + len - 1)->sst_next = NULL; | |
1198 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1199 vim_free(syn_block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1200 syn_block->b_sst_array = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1201 syn_block->b_sst_len = len; |
7 | 1202 } |
1203 } | |
1204 | |
1205 /* | |
1206 * Check for changes in a buffer to affect stored syntax states. Uses the | |
1207 * b_mod_* fields. | |
1208 * Called from update_screen(), before screen is being updated, once for each | |
1209 * displayed buffer. | |
1210 */ | |
1211 void | |
1212 syn_stack_apply_changes(buf) | |
1213 buf_T *buf; | |
1214 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1215 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1216 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1217 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
|
1218 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1219 FOR_ALL_WINDOWS(wp) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1220 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1221 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
|
1222 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
|
1223 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1224 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1225 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1226 static void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1227 syn_stack_apply_changes_block(block, buf) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1228 synblock_T *block; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1229 buf_T *buf; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1230 { |
7 | 1231 synstate_T *p, *prev, *np; |
1232 linenr_T n; | |
1233 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1234 if (block->b_sst_array == NULL) /* nothing to do */ |
7 | 1235 return; |
1236 | |
1237 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1238 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
|
1239 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1240 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) |
7 | 1241 { |
1242 n = p->sst_lnum + buf->b_mod_xlines; | |
1243 if (n <= buf->b_mod_bot) | |
1244 { | |
1245 /* this state is inside the changed area, remove it */ | |
1246 np = p->sst_next; | |
1247 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1248 block->b_sst_first = np; |
7 | 1249 else |
1250 prev->sst_next = np; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1251 syn_stack_free_entry(block, p); |
7 | 1252 p = np; |
1253 continue; | |
1254 } | |
1255 /* This state is below the changed area. Remember the line | |
1256 * that needs to be parsed before this entry can be made valid | |
1257 * again. */ | |
1258 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) | |
1259 { | |
1260 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) | |
1261 p->sst_change_lnum += buf->b_mod_xlines; | |
1262 else | |
1263 p->sst_change_lnum = buf->b_mod_top; | |
1264 } | |
1265 if (p->sst_change_lnum == 0 | |
1266 || p->sst_change_lnum < buf->b_mod_bot) | |
1267 p->sst_change_lnum = buf->b_mod_bot; | |
1268 | |
1269 p->sst_lnum = n; | |
1270 } | |
1271 prev = p; | |
1272 p = p->sst_next; | |
1273 } | |
1274 } | |
1275 | |
1276 /* | |
1277 * Reduce the number of entries in the state stack for syn_buf. | |
1278 * Returns TRUE if at least one entry was freed. | |
1279 */ | |
1280 static int | |
1281 syn_stack_cleanup() | |
1282 { | |
1283 synstate_T *p, *prev; | |
1284 disptick_T tick; | |
1285 int above; | |
1286 int dist; | |
1287 int retval = FALSE; | |
1288 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1289 if (syn_block->b_sst_array == NULL || syn_block->b_sst_first == NULL) |
7 | 1290 return retval; |
1291 | |
1292 /* 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
|
1293 if (syn_block->b_sst_len <= Rows) |
819 | 1294 dist = 999999; |
1295 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1296 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 1297 |
1298 /* | |
2020 | 1299 * Go through the list to find the "tick" for the oldest entry that can |
7 | 1300 * be removed. Set "above" when the "tick" for the oldest entry is above |
1301 * "b_sst_lasttick" (the display tick wraps around). | |
1302 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1303 tick = syn_block->b_sst_lasttick; |
7 | 1304 above = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1305 prev = syn_block->b_sst_first; |
7 | 1306 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1307 { | |
1308 if (prev->sst_lnum + dist > p->sst_lnum) | |
1309 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1310 if (p->sst_tick > syn_block->b_sst_lasttick) |
7 | 1311 { |
1312 if (!above || p->sst_tick < tick) | |
1313 tick = p->sst_tick; | |
1314 above = TRUE; | |
1315 } | |
1316 else if (!above && p->sst_tick < tick) | |
1317 tick = p->sst_tick; | |
1318 } | |
1319 } | |
1320 | |
1321 /* | |
1322 * Go through the list to make the entries for the oldest tick at an | |
1323 * interval of several lines. | |
1324 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1325 prev = syn_block->b_sst_first; |
7 | 1326 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1327 { | |
1328 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) | |
1329 { | |
1330 /* Move this entry from used list to free list */ | |
1331 prev->sst_next = p->sst_next; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1332 syn_stack_free_entry(syn_block, p); |
7 | 1333 p = prev; |
1334 retval = TRUE; | |
1335 } | |
1336 } | |
1337 return retval; | |
1338 } | |
1339 | |
1340 /* | |
1341 * Free the allocated memory for a syn_state item. | |
1342 * Move the entry into the free list. | |
1343 */ | |
1344 static void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1345 syn_stack_free_entry(block, p) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1346 synblock_T *block; |
7 | 1347 synstate_T *p; |
1348 { | |
1349 clear_syn_state(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1350 p->sst_next = block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1351 block->b_sst_firstfree = p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1352 ++block->b_sst_freecount; |
7 | 1353 } |
1354 | |
1355 /* | |
1356 * Find an entry in the list of state stacks at or before "lnum". | |
1357 * Returns NULL when there is no entry or the first entry is after "lnum". | |
1358 */ | |
1359 static synstate_T * | |
1360 syn_stack_find_entry(lnum) | |
1361 linenr_T lnum; | |
1362 { | |
1363 synstate_T *p, *prev; | |
1364 | |
1365 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1366 for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) |
7 | 1367 { |
1368 if (p->sst_lnum == lnum) | |
1369 return p; | |
1370 if (p->sst_lnum > lnum) | |
1371 break; | |
1372 } | |
1373 return prev; | |
1374 } | |
1375 | |
1376 /* | |
1377 * Try saving the current state in b_sst_array[]. | |
1378 * The current state must be valid for the start of the current_lnum line! | |
1379 */ | |
1380 static synstate_T * | |
1512 | 1381 store_current_state() |
7 | 1382 { |
1383 int i; | |
1384 synstate_T *p; | |
1385 bufstate_T *bp; | |
1386 stateitem_T *cur_si; | |
1512 | 1387 synstate_T *sp = syn_stack_find_entry(current_lnum); |
7 | 1388 |
1389 /* | |
1390 * If the current state contains a start or end pattern that continues | |
1391 * from the previous line, we can't use it. Don't store it then. | |
1392 */ | |
1393 for (i = current_state.ga_len - 1; i >= 0; --i) | |
1394 { | |
1395 cur_si = &CUR_STATE(i); | |
1396 if (cur_si->si_h_startpos.lnum >= current_lnum | |
1397 || cur_si->si_m_endpos.lnum >= current_lnum | |
1398 || cur_si->si_h_endpos.lnum >= current_lnum | |
1399 || (cur_si->si_end_idx | |
1400 && cur_si->si_eoe_pos.lnum >= current_lnum)) | |
1401 break; | |
1402 } | |
1403 if (i >= 0) | |
1404 { | |
1405 if (sp != NULL) | |
1406 { | |
1407 /* 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
|
1408 if (syn_block->b_sst_first == sp) |
7 | 1409 /* it's the first entry */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1410 syn_block->b_sst_first = sp->sst_next; |
7 | 1411 else |
1412 { | |
1413 /* find the entry just before this one to adjust sst_next */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1414 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 1415 if (p->sst_next == sp) |
1416 break; | |
840 | 1417 if (p != NULL) /* just in case */ |
1418 p->sst_next = sp->sst_next; | |
7 | 1419 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1420 syn_stack_free_entry(syn_block, sp); |
7 | 1421 sp = NULL; |
1422 } | |
1423 } | |
1424 else if (sp == NULL || sp->sst_lnum != current_lnum) | |
1425 { | |
1426 /* | |
1427 * Add a new entry | |
1428 */ | |
1429 /* 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
|
1430 if (syn_block->b_sst_freecount == 0) |
7 | 1431 { |
1432 (void)syn_stack_cleanup(); | |
1433 /* "sp" may have been moved to the freelist now */ | |
1434 sp = syn_stack_find_entry(current_lnum); | |
1435 } | |
1436 /* 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
|
1437 if (syn_block->b_sst_freecount == 0) |
7 | 1438 sp = NULL; |
1439 else | |
1440 { | |
1441 /* Take the first item from the free list and put it in the used | |
1442 * list, after *sp */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1443 p = syn_block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1444 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
|
1445 --syn_block->b_sst_freecount; |
7 | 1446 if (sp == NULL) |
1447 { | |
1448 /* Insert in front of the list */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1449 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
|
1450 syn_block->b_sst_first = p; |
7 | 1451 } |
1452 else | |
1453 { | |
1454 /* insert in list after *sp */ | |
1455 p->sst_next = sp->sst_next; | |
1456 sp->sst_next = p; | |
1457 } | |
1458 sp = p; | |
1459 sp->sst_stacksize = 0; | |
1460 sp->sst_lnum = current_lnum; | |
1461 } | |
1462 } | |
1463 if (sp != NULL) | |
1464 { | |
1465 /* When overwriting an existing state stack, clear it first */ | |
1466 clear_syn_state(sp); | |
1467 sp->sst_stacksize = current_state.ga_len; | |
1468 if (current_state.ga_len > SST_FIX_STATES) | |
1469 { | |
1470 /* Need to clear it, might be something remaining from when the | |
1471 * length was less than SST_FIX_STATES. */ | |
1472 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); | |
1473 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) | |
1474 sp->sst_stacksize = 0; | |
1475 else | |
1476 sp->sst_union.sst_ga.ga_len = current_state.ga_len; | |
1477 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1478 } | |
1479 else | |
1480 bp = sp->sst_union.sst_stack; | |
1481 for (i = 0; i < sp->sst_stacksize; ++i) | |
1482 { | |
1483 bp[i].bs_idx = CUR_STATE(i).si_idx; | |
1484 bp[i].bs_flags = CUR_STATE(i).si_flags; | |
1485 bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); | |
1486 } | |
1487 sp->sst_next_flags = current_next_flags; | |
1488 sp->sst_next_list = current_next_list; | |
1489 sp->sst_tick = display_tick; | |
1490 sp->sst_change_lnum = 0; | |
1491 } | |
1492 current_state_stored = TRUE; | |
1493 return sp; | |
1494 } | |
1495 | |
1496 /* | |
1497 * Copy a state stack from "from" in b_sst_array[] to current_state; | |
1498 */ | |
1499 static void | |
1500 load_current_state(from) | |
1501 synstate_T *from; | |
1502 { | |
1503 int i; | |
1504 bufstate_T *bp; | |
1505 | |
1506 clear_current_state(); | |
1507 validate_current_state(); | |
1508 keepend_level = -1; | |
1509 if (from->sst_stacksize | |
1510 && ga_grow(¤t_state, from->sst_stacksize) != FAIL) | |
1511 { | |
1512 if (from->sst_stacksize > SST_FIX_STATES) | |
1513 bp = SYN_STATE_P(&(from->sst_union.sst_ga)); | |
1514 else | |
1515 bp = from->sst_union.sst_stack; | |
1516 for (i = 0; i < from->sst_stacksize; ++i) | |
1517 { | |
1518 CUR_STATE(i).si_idx = bp[i].bs_idx; | |
1519 CUR_STATE(i).si_flags = bp[i].bs_flags; | |
1520 CUR_STATE(i).si_extmatch = ref_extmatch(bp[i].bs_extmatch); | |
1521 if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) | |
1522 keepend_level = i; | |
1523 CUR_STATE(i).si_ends = FALSE; | |
1524 CUR_STATE(i).si_m_lnum = 0; | |
1525 if (CUR_STATE(i).si_idx >= 0) | |
1526 CUR_STATE(i).si_next_list = | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1527 (SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_next_list; |
7 | 1528 else |
1529 CUR_STATE(i).si_next_list = NULL; | |
1530 update_si_attr(i); | |
1531 } | |
1532 current_state.ga_len = from->sst_stacksize; | |
1533 } | |
1534 current_next_list = from->sst_next_list; | |
1535 current_next_flags = from->sst_next_flags; | |
1536 current_lnum = from->sst_lnum; | |
1537 } | |
1538 | |
1539 /* | |
1540 * Compare saved state stack "*sp" with the current state. | |
1541 * Return TRUE when they are equal. | |
1542 */ | |
1543 static int | |
1544 syn_stack_equal(sp) | |
1545 synstate_T *sp; | |
1546 { | |
1547 int i, j; | |
1548 bufstate_T *bp; | |
1549 reg_extmatch_T *six, *bsx; | |
1550 | |
1551 /* First a quick check if the stacks have the same size end nextlist. */ | |
1552 if (sp->sst_stacksize == current_state.ga_len | |
1553 && sp->sst_next_list == current_next_list) | |
1554 { | |
1555 /* Need to compare all states on both stacks. */ | |
1556 if (sp->sst_stacksize > SST_FIX_STATES) | |
1557 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1558 else | |
1559 bp = sp->sst_union.sst_stack; | |
1560 | |
1561 for (i = current_state.ga_len; --i >= 0; ) | |
1562 { | |
1563 /* If the item has another index the state is different. */ | |
1564 if (bp[i].bs_idx != CUR_STATE(i).si_idx) | |
1565 break; | |
1566 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) | |
1567 { | |
1568 /* When the extmatch pointers are different, the strings in | |
1569 * them can still be the same. Check if the extmatch | |
1570 * references are equal. */ | |
1571 bsx = bp[i].bs_extmatch; | |
1572 six = CUR_STATE(i).si_extmatch; | |
1573 /* If one of the extmatch pointers is NULL the states are | |
1574 * different. */ | |
1575 if (bsx == NULL || six == NULL) | |
1576 break; | |
1577 for (j = 0; j < NSUBEXP; ++j) | |
1578 { | |
1579 /* Check each referenced match string. They must all be | |
1580 * equal. */ | |
1581 if (bsx->matches[j] != six->matches[j]) | |
1582 { | |
1583 /* If the pointer is different it can still be the | |
1584 * same text. Compare the strings, ignore case when | |
1585 * the start item has the sp_ic flag set. */ | |
1586 if (bsx->matches[j] == NULL | |
1587 || six->matches[j] == NULL) | |
1588 break; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1589 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic |
7 | 1590 ? MB_STRICMP(bsx->matches[j], |
1591 six->matches[j]) != 0 | |
1592 : STRCMP(bsx->matches[j], six->matches[j]) != 0) | |
1593 break; | |
1594 } | |
1595 } | |
1596 if (j != NSUBEXP) | |
1597 break; | |
1598 } | |
1599 } | |
1600 if (i < 0) | |
1601 return TRUE; | |
1602 } | |
1603 return FALSE; | |
1604 } | |
1605 | |
1606 /* | |
1607 * We stop parsing syntax above line "lnum". If the stored state at or below | |
1608 * this line depended on a change before it, it now depends on the line below | |
1609 * the last parsed line. | |
1610 * The window looks like this: | |
1611 * line which changed | |
1612 * displayed line | |
1613 * displayed line | |
1614 * lnum -> line below window | |
1615 */ | |
1616 void | |
1617 syntax_end_parsing(lnum) | |
1618 linenr_T lnum; | |
1619 { | |
1620 synstate_T *sp; | |
1621 | |
1622 sp = syn_stack_find_entry(lnum); | |
1623 if (sp != NULL && sp->sst_lnum < lnum) | |
1624 sp = sp->sst_next; | |
1625 | |
1626 if (sp != NULL && sp->sst_change_lnum != 0) | |
1627 sp->sst_change_lnum = lnum; | |
1628 } | |
1629 | |
1630 /* | |
1631 * End of handling of the state stack. | |
1632 ****************************************/ | |
1633 | |
1634 static void | |
1635 invalidate_current_state() | |
1636 { | |
1637 clear_current_state(); | |
1638 current_state.ga_itemsize = 0; /* mark current_state invalid */ | |
1639 current_next_list = NULL; | |
1640 keepend_level = -1; | |
1641 } | |
1642 | |
1643 static void | |
1644 validate_current_state() | |
1645 { | |
1646 current_state.ga_itemsize = sizeof(stateitem_T); | |
1647 current_state.ga_growsize = 3; | |
1648 } | |
1649 | |
1650 /* | |
1651 * Return TRUE if the syntax at start of lnum changed since last time. | |
1652 * This will only be called just after get_syntax_attr() for the previous | |
1653 * line, to check if the next line needs to be redrawn too. | |
1654 */ | |
1655 int | |
1656 syntax_check_changed(lnum) | |
1657 linenr_T lnum; | |
1658 { | |
1659 int retval = TRUE; | |
1660 synstate_T *sp; | |
1661 | |
1662 /* | |
1663 * Check the state stack when: | |
1664 * - lnum is just below the previously syntaxed line. | |
1665 * - lnum is not before the lines with saved states. | |
1666 * - lnum is not past the lines with saved states. | |
1667 * - lnum is at or before the last changed line. | |
1668 */ | |
1669 if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) | |
1670 { | |
1671 sp = syn_stack_find_entry(lnum); | |
1672 if (sp != NULL && sp->sst_lnum == lnum) | |
1673 { | |
1674 /* | |
1675 * finish the previous line (needed when not all of the line was | |
1676 * drawn) | |
1677 */ | |
1678 (void)syn_finish_line(FALSE); | |
1679 | |
1680 /* | |
1681 * Compare the current state with the previously saved state of | |
1682 * the line. | |
1683 */ | |
1684 if (syn_stack_equal(sp)) | |
1685 retval = FALSE; | |
1686 | |
1687 /* | |
1688 * Store the current state in b_sst_array[] for later use. | |
1689 */ | |
1690 ++current_lnum; | |
1512 | 1691 (void)store_current_state(); |
7 | 1692 } |
1693 } | |
1694 | |
1695 return retval; | |
1696 } | |
1697 | |
1698 /* | |
1699 * Finish the current line. | |
1700 * This doesn't return any attributes, it only gets the state at the end of | |
1701 * the line. It can start anywhere in the line, as long as the current state | |
1702 * is valid. | |
1703 */ | |
1704 static int | |
1705 syn_finish_line(syncing) | |
1706 int syncing; /* called for syncing */ | |
1707 { | |
1708 stateitem_T *cur_si; | |
442 | 1709 colnr_T prev_current_col; |
7 | 1710 |
1711 if (!current_finished) | |
1712 { | |
1713 while (!current_finished) | |
1714 { | |
1504 | 1715 (void)syn_current_attr(syncing, FALSE, NULL, FALSE); |
7 | 1716 /* |
1717 * When syncing, and found some item, need to check the item. | |
1718 */ | |
1719 if (syncing && current_state.ga_len) | |
1720 { | |
1721 /* | |
1722 * Check for match with sync item. | |
1723 */ | |
1724 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1725 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1726 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags |
7 | 1727 & (HL_SYNC_HERE|HL_SYNC_THERE))) |
1728 return TRUE; | |
1729 | |
1730 /* syn_current_attr() will have skipped the check for an item | |
442 | 1731 * that ends here, need to do that now. Be careful not to go |
1732 * past the NUL. */ | |
1733 prev_current_col = current_col; | |
1734 if (syn_getcurline()[current_col] != NUL) | |
1735 ++current_col; | |
7 | 1736 check_state_ends(); |
442 | 1737 current_col = prev_current_col; |
7 | 1738 } |
1739 ++current_col; | |
1740 } | |
1741 } | |
1742 return FALSE; | |
1743 } | |
1744 | |
1745 /* | |
1746 * Return highlight attributes for next character. | |
1747 * Must first call syntax_start() once for the line. | |
1748 * "col" is normally 0 for the first use in a line, and increments by one each | |
1749 * time. It's allowed to skip characters and to stop before the end of the | |
1750 * line. But only a "col" after a previously used column is allowed. | |
221 | 1751 * When "can_spell" is not NULL set it to TRUE when spell-checking should be |
1752 * done. | |
7 | 1753 */ |
1754 int | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1755 get_syntax_attr(col, p_flags, can_spell, keep_state) |
7 | 1756 colnr_T col; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1757 int *p_flags UNUSED; |
221 | 1758 int *can_spell; |
1504 | 1759 int keep_state; /* keep state of char at "col" */ |
7 | 1760 { |
1761 int attr = 0; | |
1762 | |
1363 | 1763 if (can_spell != NULL) |
1764 /* Default: Only do spelling when there is no @Spell cluster or when | |
1765 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1766 *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
|
1767 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1768 : (syn_block->b_syn_spell == SYNSPL_TOP); |
1363 | 1769 |
7 | 1770 /* check for out of memory situation */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1771 if (syn_block->b_sst_array == NULL) |
7 | 1772 return 0; |
1773 | |
419 | 1774 /* After 'synmaxcol' the attribute is always zero. */ |
431 | 1775 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) |
419 | 1776 { |
1777 clear_current_state(); | |
1778 #ifdef FEAT_EVAL | |
1779 current_id = 0; | |
1780 current_trans_id = 0; | |
1781 #endif | |
1782 return 0; | |
1783 } | |
1784 | |
7 | 1785 /* Make sure current_state is valid */ |
1786 if (INVALID_STATE(¤t_state)) | |
1787 validate_current_state(); | |
1788 | |
1789 /* | |
1790 * Skip from the current column to "col", get the attributes for "col". | |
1791 */ | |
1792 while (current_col <= col) | |
1793 { | |
1504 | 1794 attr = syn_current_attr(FALSE, TRUE, can_spell, |
1795 current_col == col ? keep_state : FALSE); | |
7 | 1796 ++current_col; |
1797 } | |
1798 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1799 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1800 if (p_flags != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1801 *p_flags = current_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1802 #endif |
7 | 1803 return attr; |
1804 } | |
1805 | |
1806 /* | |
1807 * Get syntax attributes for current_lnum, current_col. | |
1808 */ | |
1809 static int | |
1504 | 1810 syn_current_attr(syncing, displaying, can_spell, keep_state) |
7 | 1811 int syncing; /* When 1: called for syncing */ |
1812 int displaying; /* result will be displayed */ | |
221 | 1813 int *can_spell; /* return: do spell checking */ |
1504 | 1814 int keep_state; /* keep syntax stack afterwards */ |
7 | 1815 { |
1816 int syn_id; | |
1817 lpos_T endpos; /* was: char_u *endp; */ | |
1818 lpos_T hl_startpos; /* was: int hl_startcol; */ | |
1819 lpos_T hl_endpos; | |
1820 lpos_T eos_pos; /* end-of-start match (start region) */ | |
1821 lpos_T eoe_pos; /* end-of-end pattern */ | |
1822 int end_idx; /* group ID for end pattern */ | |
1823 int idx; | |
1824 synpat_T *spp; | |
221 | 1825 stateitem_T *cur_si, *sip = NULL; |
7 | 1826 int startcol; |
1827 int endcol; | |
1828 long flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1829 int cchar; |
7 | 1830 short *next_list; |
1831 int found_match; /* found usable match */ | |
1832 static int try_next_column = FALSE; /* must try in next col */ | |
1833 int do_keywords; | |
1834 regmmatch_T regmatch; | |
1835 lpos_T pos; | |
1836 int lc_col; | |
1837 reg_extmatch_T *cur_extmatch = NULL; | |
1838 char_u *line; /* current line. NOTE: becomes invalid after | |
1839 looking for a pattern match! */ | |
1840 | |
1841 /* variables for zero-width matches that have a "nextgroup" argument */ | |
1842 int keep_next_list; | |
1843 int zero_width_next_list = FALSE; | |
1844 garray_T zero_width_next_ga; | |
1845 | |
1846 /* | |
1847 * No character, no attributes! Past end of line? | |
1848 * Do try matching with an empty line (could be the start of a region). | |
1849 */ | |
1850 line = syn_getcurline(); | |
1851 if (line[current_col] == NUL && current_col != 0) | |
1852 { | |
1853 /* | |
1854 * If we found a match after the last column, use it. | |
1855 */ | |
1856 if (next_match_idx >= 0 && next_match_col >= (int)current_col | |
1857 && next_match_col != MAXCOL) | |
1858 (void)push_next_match(NULL); | |
1859 | |
1860 current_finished = TRUE; | |
1861 current_state_stored = FALSE; | |
1862 return 0; | |
1863 } | |
1864 | |
1865 /* if the current or next character is NUL, we will finish the line now */ | |
1866 if (line[current_col] == NUL || line[current_col + 1] == NUL) | |
1867 { | |
1868 current_finished = TRUE; | |
1869 current_state_stored = FALSE; | |
1870 } | |
1871 | |
1872 /* | |
1873 * When in the previous column there was a match but it could not be used | |
1874 * (empty match or already matched in this column) need to try again in | |
1875 * the next column. | |
1876 */ | |
1877 if (try_next_column) | |
1878 { | |
1879 next_match_idx = -1; | |
1880 try_next_column = FALSE; | |
1881 } | |
1882 | |
1883 /* Only check for keywords when not syncing and there are some. */ | |
1884 do_keywords = !syncing | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1885 && (syn_block->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1886 || syn_block->b_keywtab_ic.ht_used > 0); |
7 | 1887 |
1888 /* Init the list of zero-width matches with a nextlist. This is used to | |
1889 * avoid matching the same item in the same position twice. */ | |
1890 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10); | |
1891 | |
1892 /* | |
1893 * Repeat matching keywords and patterns, to find contained items at the | |
1894 * same column. This stops when there are no extra matches at the current | |
1895 * column. | |
1896 */ | |
1897 do | |
1898 { | |
1899 found_match = FALSE; | |
1900 keep_next_list = FALSE; | |
1901 syn_id = 0; | |
1902 | |
1903 /* | |
1904 * 1. Check for a current state. | |
1905 * Only when there is no current state, or if the current state may | |
1906 * contain other things, we need to check for keywords and patterns. | |
1907 * Always need to check for contained items if some item has the | |
1908 * "containedin" argument (takes extra time!). | |
1909 */ | |
1910 if (current_state.ga_len) | |
1911 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1912 else | |
1913 cur_si = NULL; | |
1914 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1915 if (syn_block->b_syn_containedin || cur_si == NULL |
7 | 1916 || cur_si->si_cont_list != NULL) |
1917 { | |
1918 /* | |
1919 * 2. Check for keywords, if on a keyword char after a non-keyword | |
1920 * char. Don't do this when syncing. | |
1921 */ | |
1922 if (do_keywords) | |
1923 { | |
1924 line = syn_getcurline(); | |
1925 if (vim_iswordc_buf(line + current_col, syn_buf) | |
1926 && (current_col == 0 | |
1927 || !vim_iswordc_buf(line + current_col - 1 | |
1928 #ifdef FEAT_MBYTE | |
1929 - (has_mbyte | |
1930 ? (*mb_head_off)(line, line + current_col - 1) | |
1931 : 0) | |
1932 #endif | |
1933 , syn_buf))) | |
1934 { | |
1935 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
|
1936 &endcol, &flags, &next_list, cur_si, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1937 &cchar); |
205 | 1938 if (syn_id != 0) |
7 | 1939 { |
1940 if (push_current_state(KEYWORD_IDX) == OK) | |
1941 { | |
1942 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1943 cur_si->si_m_startcol = current_col; | |
1944 cur_si->si_h_startpos.lnum = current_lnum; | |
1945 cur_si->si_h_startpos.col = 0; /* starts right away */ | |
1946 cur_si->si_m_endpos.lnum = current_lnum; | |
1947 cur_si->si_m_endpos.col = endcol; | |
1948 cur_si->si_h_endpos.lnum = current_lnum; | |
1949 cur_si->si_h_endpos.col = endcol; | |
1950 cur_si->si_ends = TRUE; | |
1951 cur_si->si_end_idx = 0; | |
1952 cur_si->si_flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1953 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1954 cur_si->si_char = cchar; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1955 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1956 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1957 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
|
1958 & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1959 #endif |
7 | 1960 cur_si->si_id = syn_id; |
1961 cur_si->si_trans_id = syn_id; | |
1962 if (flags & HL_TRANSP) | |
1963 { | |
1964 if (current_state.ga_len < 2) | |
1965 { | |
1966 cur_si->si_attr = 0; | |
1967 cur_si->si_trans_id = 0; | |
1968 } | |
1969 else | |
1970 { | |
1971 cur_si->si_attr = CUR_STATE( | |
1972 current_state.ga_len - 2).si_attr; | |
1973 cur_si->si_trans_id = CUR_STATE( | |
1974 current_state.ga_len - 2).si_trans_id; | |
1975 } | |
1976 } | |
1977 else | |
1978 cur_si->si_attr = syn_id2attr(syn_id); | |
1979 cur_si->si_cont_list = NULL; | |
1980 cur_si->si_next_list = next_list; | |
1981 check_keepend(); | |
1982 } | |
1983 else | |
1984 vim_free(next_list); | |
1985 } | |
1986 } | |
1987 } | |
1988 | |
1989 /* | |
205 | 1990 * 3. Check for patterns (only if no keyword found). |
7 | 1991 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1992 if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) |
7 | 1993 { |
1994 /* | |
1995 * If we didn't check for a match yet, or we are past it, check | |
1996 * for any match with a pattern. | |
1997 */ | |
1998 if (next_match_idx < 0 || next_match_col < (int)current_col) | |
1999 { | |
2000 /* | |
2001 * Check all relevant patterns for a match at this | |
2002 * position. This is complicated, because matching with a | |
2003 * pattern takes quite a bit of time, thus we want to | |
2004 * avoid doing it when it's not needed. | |
2005 */ | |
2006 next_match_idx = 0; /* no match in this line yet */ | |
2007 next_match_col = MAXCOL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2008 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
7 | 2009 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2010 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2011 if ( spp->sp_syncing == syncing |
2012 && (displaying || !(spp->sp_flags & HL_DISPLAY)) | |
2013 && (spp->sp_type == SPTYPE_MATCH | |
2014 || spp->sp_type == SPTYPE_START) | |
2015 && (current_next_list != NULL | |
2016 ? in_id_list(NULL, current_next_list, | |
2017 &spp->sp_syn, 0) | |
2018 : (cur_si == NULL | |
2019 ? !(spp->sp_flags & HL_CONTAINED) | |
2020 : in_id_list(cur_si, | |
2021 cur_si->si_cont_list, &spp->sp_syn, | |
2022 spp->sp_flags & HL_CONTAINED)))) | |
2023 { | |
2024 /* If we already tried matching in this line, and | |
2025 * there isn't a match before next_match_col, skip | |
2026 * this item. */ | |
2027 if (spp->sp_line_id == current_line_id | |
2028 && spp->sp_startcol >= next_match_col) | |
2029 continue; | |
2030 spp->sp_line_id = current_line_id; | |
2031 | |
2032 lc_col = current_col - spp->sp_offsets[SPO_LC_OFF]; | |
2033 if (lc_col < 0) | |
2034 lc_col = 0; | |
2035 | |
2036 regmatch.rmm_ic = spp->sp_ic; | |
2037 regmatch.regprog = spp->sp_prog; | |
2038 if (!syn_regexec(®match, current_lnum, | |
2039 (colnr_T)lc_col)) | |
2040 { | |
2041 /* no match in this line, try another one */ | |
2042 spp->sp_startcol = MAXCOL; | |
2043 continue; | |
2044 } | |
2045 | |
2046 /* | |
2047 * Compute the first column of the match. | |
2048 */ | |
2049 syn_add_start_off(&pos, ®match, | |
2050 spp, SPO_MS_OFF, -1); | |
2051 if (pos.lnum > current_lnum) | |
2052 { | |
2053 /* must have used end of match in a next line, | |
2054 * we can't handle that */ | |
2055 spp->sp_startcol = MAXCOL; | |
2056 continue; | |
2057 } | |
2058 startcol = pos.col; | |
2059 | |
2060 /* remember the next column where this pattern | |
2061 * matches in the current line */ | |
2062 spp->sp_startcol = startcol; | |
2063 | |
2064 /* | |
2065 * If a previously found match starts at a lower | |
2066 * column number, don't use this one. | |
2067 */ | |
2068 if (startcol >= next_match_col) | |
2069 continue; | |
2070 | |
2071 /* | |
2072 * If we matched this pattern at this position | |
2073 * before, skip it. Must retry in the next | |
2074 * column, because it may match from there. | |
2075 */ | |
2076 if (did_match_already(idx, &zero_width_next_ga)) | |
2077 { | |
2078 try_next_column = TRUE; | |
2079 continue; | |
2080 } | |
2081 | |
2082 endpos.lnum = regmatch.endpos[0].lnum; | |
2083 endpos.col = regmatch.endpos[0].col; | |
2084 | |
2085 /* Compute the highlight start. */ | |
2086 syn_add_start_off(&hl_startpos, ®match, | |
2087 spp, SPO_HS_OFF, -1); | |
2088 | |
2089 /* Compute the region start. */ | |
2090 /* Default is to use the end of the match. */ | |
2091 syn_add_end_off(&eos_pos, ®match, | |
2092 spp, SPO_RS_OFF, 0); | |
2093 | |
2094 /* | |
2095 * Grab the external submatches before they get | |
2096 * overwritten. Reference count doesn't change. | |
2097 */ | |
2098 unref_extmatch(cur_extmatch); | |
2099 cur_extmatch = re_extmatch_out; | |
2100 re_extmatch_out = NULL; | |
2101 | |
2102 flags = 0; | |
2103 eoe_pos.lnum = 0; /* avoid warning */ | |
2104 eoe_pos.col = 0; | |
2105 end_idx = 0; | |
2106 hl_endpos.lnum = 0; | |
2107 | |
2108 /* | |
2109 * For a "oneline" the end must be found in the | |
2110 * same line too. Search for it after the end of | |
2111 * the match with the start pattern. Set the | |
2112 * resulting end positions at the same time. | |
2113 */ | |
2114 if (spp->sp_type == SPTYPE_START | |
2115 && (spp->sp_flags & HL_ONELINE)) | |
2116 { | |
2117 lpos_T startpos; | |
2118 | |
2119 startpos = endpos; | |
2120 find_endpos(idx, &startpos, &endpos, &hl_endpos, | |
2121 &flags, &eoe_pos, &end_idx, cur_extmatch); | |
2122 if (endpos.lnum == 0) | |
2123 continue; /* not found */ | |
2124 } | |
2125 | |
2126 /* | |
2127 * For a "match" the size must be > 0 after the | |
2128 * end offset needs has been added. Except when | |
2129 * syncing. | |
2130 */ | |
2131 else if (spp->sp_type == SPTYPE_MATCH) | |
2132 { | |
2133 syn_add_end_off(&hl_endpos, ®match, spp, | |
2134 SPO_HE_OFF, 0); | |
2135 syn_add_end_off(&endpos, ®match, spp, | |
2136 SPO_ME_OFF, 0); | |
2137 if (endpos.lnum == current_lnum | |
2138 && (int)endpos.col + syncing < startcol) | |
2139 { | |
2140 /* | |
2141 * If an empty string is matched, may need | |
2142 * to try matching again at next column. | |
2143 */ | |
2144 if (regmatch.startpos[0].col | |
2145 == regmatch.endpos[0].col) | |
2146 try_next_column = TRUE; | |
2147 continue; | |
2148 } | |
2149 } | |
2150 | |
2151 /* | |
2152 * keep the best match so far in next_match_* | |
2153 */ | |
2154 /* Highlighting must start after startpos and end | |
2155 * before endpos. */ | |
2156 if (hl_startpos.lnum == current_lnum | |
2157 && (int)hl_startpos.col < startcol) | |
2158 hl_startpos.col = startcol; | |
2159 limit_pos_zero(&hl_endpos, &endpos); | |
2160 | |
2161 next_match_idx = idx; | |
2162 next_match_col = startcol; | |
2163 next_match_m_endpos = endpos; | |
2164 next_match_h_endpos = hl_endpos; | |
2165 next_match_h_startpos = hl_startpos; | |
2166 next_match_flags = flags; | |
2167 next_match_eos_pos = eos_pos; | |
2168 next_match_eoe_pos = eoe_pos; | |
2169 next_match_end_idx = end_idx; | |
2170 unref_extmatch(next_match_extmatch); | |
2171 next_match_extmatch = cur_extmatch; | |
2172 cur_extmatch = NULL; | |
2173 } | |
2174 } | |
2175 } | |
2176 | |
2177 /* | |
2178 * If we found a match at the current column, use it. | |
2179 */ | |
2180 if (next_match_idx >= 0 && next_match_col == (int)current_col) | |
2181 { | |
2182 synpat_T *lspp; | |
2183 | |
2184 /* When a zero-width item matched which has a nextgroup, | |
2185 * 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
|
2186 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2187 if (next_match_m_endpos.lnum == current_lnum |
2188 && next_match_m_endpos.col == current_col | |
2189 && lspp->sp_next_list != NULL) | |
2190 { | |
2191 current_next_list = lspp->sp_next_list; | |
2192 current_next_flags = lspp->sp_flags; | |
2193 keep_next_list = TRUE; | |
2194 zero_width_next_list = TRUE; | |
2195 | |
2196 /* Add the index to a list, so that we can check | |
2197 * later that we don't match it again (and cause an | |
2198 * endless loop). */ | |
2199 if (ga_grow(&zero_width_next_ga, 1) == OK) | |
2200 { | |
2201 ((int *)(zero_width_next_ga.ga_data)) | |
2202 [zero_width_next_ga.ga_len++] = next_match_idx; | |
2203 } | |
2204 next_match_idx = -1; | |
2205 } | |
2206 else | |
2207 cur_si = push_next_match(cur_si); | |
2208 found_match = TRUE; | |
2209 } | |
2210 } | |
2211 } | |
2212 | |
2213 /* | |
2214 * Handle searching for nextgroup match. | |
2215 */ | |
2216 if (current_next_list != NULL && !keep_next_list) | |
2217 { | |
2218 /* | |
2219 * If a nextgroup was not found, continue looking for one if: | |
2220 * - this is an empty line and the "skipempty" option was given | |
2221 * - we are on white space and the "skipwhite" option was given | |
2222 */ | |
2223 if (!found_match) | |
2224 { | |
2225 line = syn_getcurline(); | |
2226 if (((current_next_flags & HL_SKIPWHITE) | |
2227 && vim_iswhite(line[current_col])) | |
2228 || ((current_next_flags & HL_SKIPEMPTY) | |
2229 && *line == NUL)) | |
2230 break; | |
2231 } | |
2232 | |
2233 /* | |
2234 * If a nextgroup was found: Use it, and continue looking for | |
2235 * contained matches. | |
2236 * If a nextgroup was not found: Continue looking for a normal | |
2237 * match. | |
2238 * When did set current_next_list for a zero-width item and no | |
2239 * match was found don't loop (would get stuck). | |
2240 */ | |
2241 current_next_list = NULL; | |
2242 next_match_idx = -1; | |
2243 if (!zero_width_next_list) | |
2244 found_match = TRUE; | |
2245 } | |
2246 | |
2247 } while (found_match); | |
2248 | |
2249 /* | |
2250 * Use attributes from the current state, if within its highlighting. | |
2251 * If not, use attributes from the current-but-one state, etc. | |
2252 */ | |
2253 current_attr = 0; | |
2254 #ifdef FEAT_EVAL | |
2255 current_id = 0; | |
2256 current_trans_id = 0; | |
2257 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2258 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2259 current_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2260 #endif |
7 | 2261 if (cur_si != NULL) |
2262 { | |
221 | 2263 #ifndef FEAT_EVAL |
2264 int current_trans_id = 0; | |
2265 #endif | |
7 | 2266 for (idx = current_state.ga_len - 1; idx >= 0; --idx) |
2267 { | |
2268 sip = &CUR_STATE(idx); | |
2269 if ((current_lnum > sip->si_h_startpos.lnum | |
2270 || (current_lnum == sip->si_h_startpos.lnum | |
2271 && current_col >= sip->si_h_startpos.col)) | |
2272 && (sip->si_h_endpos.lnum == 0 | |
2273 || current_lnum < sip->si_h_endpos.lnum | |
2274 || (current_lnum == sip->si_h_endpos.lnum | |
2275 && current_col < sip->si_h_endpos.col))) | |
2276 { | |
2277 current_attr = sip->si_attr; | |
2278 #ifdef FEAT_EVAL | |
2279 current_id = sip->si_id; | |
221 | 2280 #endif |
7 | 2281 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
|
2282 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2283 current_flags = sip->si_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2284 current_sub_char = sip->si_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2285 #endif |
7 | 2286 break; |
2287 } | |
2288 } | |
2289 | |
221 | 2290 if (can_spell != NULL) |
2291 { | |
2292 struct sp_syn sps; | |
2293 | |
2294 /* | |
2295 * set "can_spell" to TRUE if spell checking is supposed to be | |
2296 * done in the current item. | |
2297 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2298 if (syn_block->b_spell_cluster_id == 0) |
227 | 2299 { |
320 | 2300 /* There is no @Spell cluster: Do spelling for items without |
2301 * @NoSpell cluster. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2302 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
|
2303 || current_trans_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2304 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); |
227 | 2305 else |
2306 { | |
2307 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2308 sps.id = syn_block->b_nospell_cluster_id; |
227 | 2309 sps.cont_in_list = NULL; |
2310 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2311 } | |
2312 } | |
221 | 2313 else |
2314 { | |
320 | 2315 /* The @Spell cluster is defined: Do spelling in items with |
419 | 2316 * the @Spell cluster. But not when @NoSpell is also there. |
2317 * At the toplevel only spell check when ":syn spell toplevel" | |
2318 * was used. */ | |
320 | 2319 if (current_trans_id == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2320 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); |
320 | 2321 else |
2322 { | |
2323 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2324 sps.id = syn_block->b_spell_cluster_id; |
320 | 2325 sps.cont_in_list = NULL; |
2326 *can_spell = in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2327 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2328 if (syn_block->b_nospell_cluster_id != 0) |
320 | 2329 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2330 sps.id = syn_block->b_nospell_cluster_id; |
320 | 2331 if (in_id_list(sip, sip->si_cont_list, &sps, 0)) |
2332 *can_spell = FALSE; | |
2333 } | |
2334 } | |
221 | 2335 } |
2336 } | |
2337 | |
2338 | |
7 | 2339 /* |
2340 * Check for end of current state (and the states before it) at the | |
2341 * next column. Don't do this for syncing, because we would miss a | |
2342 * single character match. | |
2343 * First check if the current state ends at the current column. It | |
2344 * may be for an empty match and a containing item might end in the | |
2345 * current column. | |
2346 */ | |
1504 | 2347 if (!syncing && !keep_state) |
7 | 2348 { |
2349 check_state_ends(); | |
442 | 2350 if (current_state.ga_len > 0 |
2351 && syn_getcurline()[current_col] != NUL) | |
7 | 2352 { |
2353 ++current_col; | |
2354 check_state_ends(); | |
2355 --current_col; | |
2356 } | |
2357 } | |
2358 } | |
221 | 2359 else if (can_spell != NULL) |
419 | 2360 /* Default: Only do spelling when there is no @Spell cluster or when |
2361 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2362 *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
|
2363 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2364 : (syn_block->b_syn_spell == SYNSPL_TOP); |
7 | 2365 |
2020 | 2366 /* nextgroup ends at end of line, unless "skipnl" or "skipempty" present */ |
7 | 2367 if (current_next_list != NULL |
2368 && syn_getcurline()[current_col + 1] == NUL | |
2369 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) | |
2370 current_next_list = NULL; | |
2371 | |
2372 if (zero_width_next_ga.ga_len > 0) | |
2373 ga_clear(&zero_width_next_ga); | |
2374 | |
2375 /* No longer need external matches. But keep next_match_extmatch. */ | |
2376 unref_extmatch(re_extmatch_out); | |
2377 re_extmatch_out = NULL; | |
2378 unref_extmatch(cur_extmatch); | |
2379 | |
2380 return current_attr; | |
2381 } | |
2382 | |
2383 | |
2384 /* | |
2385 * Check if we already matched pattern "idx" at the current column. | |
2386 */ | |
2387 static int | |
2388 did_match_already(idx, gap) | |
2389 int idx; | |
2390 garray_T *gap; | |
2391 { | |
2392 int i; | |
2393 | |
2394 for (i = current_state.ga_len; --i >= 0; ) | |
2395 if (CUR_STATE(i).si_m_startcol == (int)current_col | |
2396 && CUR_STATE(i).si_m_lnum == (int)current_lnum | |
2397 && CUR_STATE(i).si_idx == idx) | |
2398 return TRUE; | |
2399 | |
2400 /* Zero-width matches with a nextgroup argument are not put on the syntax | |
2401 * stack, and can only be matched once anyway. */ | |
2402 for (i = gap->ga_len; --i >= 0; ) | |
2403 if (((int *)(gap->ga_data))[i] == idx) | |
2404 return TRUE; | |
2405 | |
2406 return FALSE; | |
2407 } | |
2408 | |
2409 /* | |
2410 * Push the next match onto the stack. | |
2411 */ | |
2412 static stateitem_T * | |
2413 push_next_match(cur_si) | |
2414 stateitem_T *cur_si; | |
2415 { | |
2416 synpat_T *spp; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2417 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2418 int save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2419 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2420 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2421 spp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2422 |
2423 /* | |
2424 * Push the item in current_state stack; | |
2425 */ | |
2426 if (push_current_state(next_match_idx) == OK) | |
2427 { | |
2428 /* | |
2429 * If it's a start-skip-end type that crosses lines, figure out how | |
2430 * much it continues in this line. Otherwise just fill in the length. | |
2431 */ | |
2432 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2433 cur_si->si_h_startpos = next_match_h_startpos; | |
2434 cur_si->si_m_startcol = current_col; | |
2435 cur_si->si_m_lnum = current_lnum; | |
2436 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
|
2437 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2438 cur_si->si_char = spp->sp_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2439 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2440 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2441 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
|
2442 #endif |
7 | 2443 cur_si->si_next_list = spp->sp_next_list; |
2444 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); | |
2445 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) | |
2446 { | |
2447 /* Try to find the end pattern in the current line */ | |
2448 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); | |
2449 check_keepend(); | |
2450 } | |
2451 else | |
2452 { | |
2453 cur_si->si_m_endpos = next_match_m_endpos; | |
2454 cur_si->si_h_endpos = next_match_h_endpos; | |
2455 cur_si->si_ends = TRUE; | |
2456 cur_si->si_flags |= next_match_flags; | |
2457 cur_si->si_eoe_pos = next_match_eoe_pos; | |
2458 cur_si->si_end_idx = next_match_end_idx; | |
2459 } | |
2460 if (keepend_level < 0 && (cur_si->si_flags & HL_KEEPEND)) | |
2461 keepend_level = current_state.ga_len - 1; | |
2462 check_keepend(); | |
2463 update_si_attr(current_state.ga_len - 1); | |
2464 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2465 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2466 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
|
2467 #endif |
7 | 2468 /* |
2469 * If the start pattern has another highlight group, push another item | |
2470 * on the stack for the start pattern. | |
2471 */ | |
2472 if ( spp->sp_type == SPTYPE_START | |
2473 && spp->sp_syn_match_id != 0 | |
2474 && push_current_state(next_match_idx) == OK) | |
2475 { | |
2476 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2477 cur_si->si_h_startpos = next_match_h_startpos; | |
2478 cur_si->si_m_startcol = current_col; | |
2479 cur_si->si_m_lnum = current_lnum; | |
2480 cur_si->si_m_endpos = next_match_eos_pos; | |
2481 cur_si->si_h_endpos = next_match_eos_pos; | |
2482 cur_si->si_ends = TRUE; | |
2483 cur_si->si_end_idx = 0; | |
2484 cur_si->si_flags = HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2485 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2486 cur_si->si_flags |= save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2487 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2488 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2489 #endif |
7 | 2490 cur_si->si_next_list = NULL; |
2491 check_keepend(); | |
2492 update_si_attr(current_state.ga_len - 1); | |
2493 } | |
2494 } | |
2495 | |
2496 next_match_idx = -1; /* try other match next time */ | |
2497 | |
2498 return cur_si; | |
2499 } | |
2500 | |
2501 /* | |
2502 * Check for end of current state (and the states before it). | |
2503 */ | |
2504 static void | |
2505 check_state_ends() | |
2506 { | |
2507 stateitem_T *cur_si; | |
2508 int had_extend = FALSE; | |
2509 | |
2510 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2511 for (;;) | |
2512 { | |
2513 if (cur_si->si_ends | |
2514 && (cur_si->si_m_endpos.lnum < current_lnum | |
2515 || (cur_si->si_m_endpos.lnum == current_lnum | |
2516 && cur_si->si_m_endpos.col <= current_col))) | |
2517 { | |
2518 /* | |
2519 * If there is an end pattern group ID, highlight the end pattern | |
2520 * now. No need to pop the current item from the stack. | |
2521 * Only do this if the end pattern continues beyond the current | |
2522 * position. | |
2523 */ | |
2524 if (cur_si->si_end_idx | |
2525 && (cur_si->si_eoe_pos.lnum > current_lnum | |
2526 || (cur_si->si_eoe_pos.lnum == current_lnum | |
2527 && cur_si->si_eoe_pos.col > current_col))) | |
2528 { | |
2529 cur_si->si_idx = cur_si->si_end_idx; | |
2530 cur_si->si_end_idx = 0; | |
2531 cur_si->si_m_endpos = cur_si->si_eoe_pos; | |
2532 cur_si->si_h_endpos = cur_si->si_eoe_pos; | |
2533 cur_si->si_flags |= HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2534 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2535 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2536 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2537 #endif |
7 | 2538 update_si_attr(current_state.ga_len - 1); |
36 | 2539 |
2540 /* what matches next may be different now, clear it */ | |
2541 next_match_idx = 0; | |
2542 next_match_col = MAXCOL; | |
7 | 2543 break; |
2544 } | |
2545 else | |
2546 { | |
2547 /* handle next_list, unless at end of line and no "skipnl" or | |
2548 * "skipempty" */ | |
2549 current_next_list = cur_si->si_next_list; | |
2550 current_next_flags = cur_si->si_flags; | |
2551 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) | |
2552 && syn_getcurline()[current_col] == NUL) | |
2553 current_next_list = NULL; | |
2554 | |
2555 /* When the ended item has "extend", another item with | |
2556 * "keepend" now needs to check for its end. */ | |
2557 if (cur_si->si_flags & HL_EXTEND) | |
2558 had_extend = TRUE; | |
2559 | |
2560 pop_current_state(); | |
2561 | |
2562 if (current_state.ga_len == 0) | |
2563 break; | |
2564 | |
1503 | 2565 if (had_extend && keepend_level >= 0) |
7 | 2566 { |
2567 syn_update_ends(FALSE); | |
2568 if (current_state.ga_len == 0) | |
2569 break; | |
2570 } | |
2571 | |
2572 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2573 | |
2574 /* | |
2575 * Only for a region the search for the end continues after | |
2576 * the end of the contained item. If the contained match | |
2577 * included the end-of-line, break here, the region continues. | |
2578 * Don't do this when: | |
2579 * - "keepend" is used for the contained item | |
2580 * - not at the end of the line (could be end="x$"me=e-1). | |
2581 * - "excludenl" is used (HL_HAS_EOL won't be set) | |
2582 */ | |
2583 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2584 && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type |
7 | 2585 == SPTYPE_START |
2586 && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) | |
2587 { | |
2588 update_si_end(cur_si, (int)current_col, TRUE); | |
2589 check_keepend(); | |
2590 if ((current_next_flags & HL_HAS_EOL) | |
2591 && keepend_level < 0 | |
2592 && syn_getcurline()[current_col] == NUL) | |
2593 break; | |
2594 } | |
2595 } | |
2596 } | |
2597 else | |
2598 break; | |
2599 } | |
2600 } | |
2601 | |
2602 /* | |
2603 * Update an entry in the current_state stack for a match or region. This | |
2604 * fills in si_attr, si_next_list and si_cont_list. | |
2605 */ | |
2606 static void | |
2607 update_si_attr(idx) | |
2608 int idx; | |
2609 { | |
2610 stateitem_T *sip = &CUR_STATE(idx); | |
2611 synpat_T *spp; | |
2612 | |
1371 | 2613 /* This should not happen... */ |
2614 if (sip->si_idx < 0) | |
2615 return; | |
2616 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2617 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); |
7 | 2618 if (sip->si_flags & HL_MATCH) |
2619 sip->si_id = spp->sp_syn_match_id; | |
2620 else | |
2621 sip->si_id = spp->sp_syn.id; | |
2622 sip->si_attr = syn_id2attr(sip->si_id); | |
2623 sip->si_trans_id = sip->si_id; | |
2624 if (sip->si_flags & HL_MATCH) | |
2625 sip->si_cont_list = NULL; | |
2626 else | |
2627 sip->si_cont_list = spp->sp_cont_list; | |
2628 | |
2629 /* | |
2630 * For transparent items, take attr from outer item. | |
2631 * Also take cont_list, if there is none. | |
2632 * Don't do this for the matchgroup of a start or end pattern. | |
2633 */ | |
2634 if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) | |
2635 { | |
2636 if (idx == 0) | |
2637 { | |
2638 sip->si_attr = 0; | |
2639 sip->si_trans_id = 0; | |
2640 if (sip->si_cont_list == NULL) | |
2641 sip->si_cont_list = ID_LIST_ALL; | |
2642 } | |
2643 else | |
2644 { | |
2645 sip->si_attr = CUR_STATE(idx - 1).si_attr; | |
2646 sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; | |
36 | 2647 sip->si_h_startpos = CUR_STATE(idx - 1).si_h_startpos; |
2648 sip->si_h_endpos = CUR_STATE(idx - 1).si_h_endpos; | |
7 | 2649 if (sip->si_cont_list == NULL) |
2650 { | |
2651 sip->si_flags |= HL_TRANS_CONT; | |
2652 sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; | |
2653 } | |
2654 } | |
2655 } | |
2656 } | |
2657 | |
2658 /* | |
2659 * Check the current stack for patterns with "keepend" flag. | |
2660 * Propagate the match-end to contained items, until a "skipend" item is found. | |
2661 */ | |
2662 static void | |
2663 check_keepend() | |
2664 { | |
2665 int i; | |
2666 lpos_T maxpos; | |
991 | 2667 lpos_T maxpos_h; |
7 | 2668 stateitem_T *sip; |
2669 | |
2670 /* | |
2671 * This check can consume a lot of time; only do it from the level where | |
2672 * there really is a keepend. | |
2673 */ | |
2674 if (keepend_level < 0) | |
2675 return; | |
2676 | |
2677 /* | |
2678 * Find the last index of an "extend" item. "keepend" items before that | |
2679 * won't do anything. If there is no "extend" item "i" will be | |
2680 * "keepend_level" and all "keepend" items will work normally. | |
2681 */ | |
2682 for (i = current_state.ga_len - 1; i > keepend_level; --i) | |
2683 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
2684 break; | |
2685 | |
2686 maxpos.lnum = 0; | |
1702 | 2687 maxpos.col = 0; |
991 | 2688 maxpos_h.lnum = 0; |
1702 | 2689 maxpos_h.col = 0; |
7 | 2690 for ( ; i < current_state.ga_len; ++i) |
2691 { | |
2692 sip = &CUR_STATE(i); | |
2693 if (maxpos.lnum != 0) | |
2694 { | |
2695 limit_pos_zero(&sip->si_m_endpos, &maxpos); | |
991 | 2696 limit_pos_zero(&sip->si_h_endpos, &maxpos_h); |
7 | 2697 limit_pos_zero(&sip->si_eoe_pos, &maxpos); |
2698 sip->si_ends = TRUE; | |
2699 } | |
991 | 2700 if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) |
2701 { | |
2702 if (maxpos.lnum == 0 | |
7 | 2703 || maxpos.lnum > sip->si_m_endpos.lnum |
2704 || (maxpos.lnum == sip->si_m_endpos.lnum | |
991 | 2705 && maxpos.col > sip->si_m_endpos.col)) |
2706 maxpos = sip->si_m_endpos; | |
2707 if (maxpos_h.lnum == 0 | |
2708 || maxpos_h.lnum > sip->si_h_endpos.lnum | |
2709 || (maxpos_h.lnum == sip->si_h_endpos.lnum | |
2710 && maxpos_h.col > sip->si_h_endpos.col)) | |
2711 maxpos_h = sip->si_h_endpos; | |
2712 } | |
7 | 2713 } |
2714 } | |
2715 | |
2716 /* | |
2717 * Update an entry in the current_state stack for a start-skip-end pattern. | |
2718 * This finds the end of the current item, if it's in the current line. | |
2719 * | |
2720 * Return the flags for the matched END. | |
2721 */ | |
2722 static void | |
2723 update_si_end(sip, startcol, force) | |
2724 stateitem_T *sip; | |
2725 int startcol; /* where to start searching for the end */ | |
2726 int force; /* when TRUE overrule a previous end */ | |
2727 { | |
2728 lpos_T startpos; | |
2729 lpos_T endpos; | |
2730 lpos_T hl_endpos; | |
2731 lpos_T end_endpos; | |
2732 int end_idx; | |
2733 | |
1371 | 2734 /* return quickly for a keyword */ |
2735 if (sip->si_idx < 0) | |
2736 return; | |
2737 | |
7 | 2738 /* Don't update when it's already done. Can be a match of an end pattern |
2739 * that started in a previous line. Watch out: can also be a "keepend" | |
2740 * from a containing item. */ | |
2741 if (!force && sip->si_m_endpos.lnum >= current_lnum) | |
2742 return; | |
2743 | |
2744 /* | |
2745 * We need to find the end of the region. It may continue in the next | |
2746 * line. | |
2747 */ | |
2748 end_idx = 0; | |
2749 startpos.lnum = current_lnum; | |
2750 startpos.col = startcol; | |
2751 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, | |
2752 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); | |
2753 | |
2754 if (endpos.lnum == 0) | |
2755 { | |
2756 /* No end pattern matched. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2757 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) |
7 | 2758 { |
2759 /* a "oneline" never continues in the next line */ | |
2760 sip->si_ends = TRUE; | |
2761 sip->si_m_endpos.lnum = current_lnum; | |
2762 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); | |
2763 } | |
2764 else | |
2765 { | |
2766 /* continues in the next line */ | |
2767 sip->si_ends = FALSE; | |
2768 sip->si_m_endpos.lnum = 0; | |
2769 } | |
2770 sip->si_h_endpos = sip->si_m_endpos; | |
2771 } | |
2772 else | |
2773 { | |
2774 /* match within this line */ | |
2775 sip->si_m_endpos = endpos; | |
2776 sip->si_h_endpos = hl_endpos; | |
2777 sip->si_eoe_pos = end_endpos; | |
2778 sip->si_ends = TRUE; | |
2779 sip->si_end_idx = end_idx; | |
2780 } | |
2781 } | |
2782 | |
2783 /* | |
2784 * Add a new state to the current state stack. | |
2785 * It is cleared and the index set to "idx". | |
2786 * Return FAIL if it's not possible (out of memory). | |
2787 */ | |
2788 static int | |
2789 push_current_state(idx) | |
2790 int idx; | |
2791 { | |
2792 if (ga_grow(¤t_state, 1) == FAIL) | |
2793 return FAIL; | |
2794 vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T)); | |
2795 CUR_STATE(current_state.ga_len).si_idx = idx; | |
2796 ++current_state.ga_len; | |
2797 return OK; | |
2798 } | |
2799 | |
2800 /* | |
2801 * Remove a state from the current_state stack. | |
2802 */ | |
2803 static void | |
2804 pop_current_state() | |
2805 { | |
2806 if (current_state.ga_len) | |
2807 { | |
2808 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); | |
2809 --current_state.ga_len; | |
2810 } | |
2811 /* after the end of a pattern, try matching a keyword or pattern */ | |
2812 next_match_idx = -1; | |
2813 | |
2814 /* if first state with "keepend" is popped, reset keepend_level */ | |
2815 if (keepend_level >= current_state.ga_len) | |
2816 keepend_level = -1; | |
2817 } | |
2818 | |
2819 /* | |
2820 * Find the end of a start/skip/end syntax region after "startpos". | |
2821 * Only checks one line. | |
2822 * Also handles a match item that continued from a previous line. | |
2823 * If not found, the syntax item continues in the next line. m_endpos->lnum | |
2824 * will be 0. | |
2825 * If found, the end of the region and the end of the highlighting is | |
2826 * computed. | |
2827 */ | |
2828 static void | |
2829 find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos, | |
2830 end_idx, start_ext) | |
2831 int idx; /* index of the pattern */ | |
2832 lpos_T *startpos; /* where to start looking for an END match */ | |
2833 lpos_T *m_endpos; /* return: end of match */ | |
2834 lpos_T *hl_endpos; /* return: end of highlighting */ | |
2835 long *flagsp; /* return: flags of matching END */ | |
2836 lpos_T *end_endpos; /* return: end of end pattern match */ | |
2837 int *end_idx; /* return: group ID for end pat. match, or 0 */ | |
2838 reg_extmatch_T *start_ext; /* submatches from the start pattern */ | |
2839 { | |
2840 colnr_T matchcol; | |
2841 synpat_T *spp, *spp_skip; | |
2842 int start_idx; | |
2843 int best_idx; | |
2844 regmmatch_T regmatch; | |
2845 regmmatch_T best_regmatch; /* startpos/endpos of best match */ | |
2846 lpos_T pos; | |
2847 char_u *line; | |
2848 int had_match = FALSE; | |
2849 | |
1371 | 2850 /* just in case we are invoked for a keyword */ |
2851 if (idx < 0) | |
2852 return; | |
2853 | |
7 | 2854 /* |
2855 * Check for being called with a START pattern. | |
2856 * Can happen with a match that continues to the next line, because it | |
2857 * contained a region. | |
2858 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2859 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2860 if (spp->sp_type != SPTYPE_START) |
2861 { | |
2862 *hl_endpos = *startpos; | |
2863 return; | |
2864 } | |
2865 | |
2866 /* | |
2867 * Find the SKIP or first END pattern after the last START pattern. | |
2868 */ | |
2869 for (;;) | |
2870 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2871 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2872 if (spp->sp_type != SPTYPE_START) |
2873 break; | |
2874 ++idx; | |
2875 } | |
2876 | |
2877 /* | |
2878 * Lookup the SKIP pattern (if present) | |
2879 */ | |
2880 if (spp->sp_type == SPTYPE_SKIP) | |
2881 { | |
2882 spp_skip = spp; | |
2883 ++idx; | |
2884 } | |
2885 else | |
2886 spp_skip = NULL; | |
2887 | |
2888 /* Setup external matches for syn_regexec(). */ | |
2889 unref_extmatch(re_extmatch_in); | |
2890 re_extmatch_in = ref_extmatch(start_ext); | |
2891 | |
2892 matchcol = startpos->col; /* start looking for a match at sstart */ | |
2893 start_idx = idx; /* remember the first END pattern. */ | |
2894 best_regmatch.startpos[0].col = 0; /* avoid compiler warning */ | |
2895 for (;;) | |
2896 { | |
2897 /* | |
2898 * Find end pattern that matches first after "matchcol". | |
2899 */ | |
2900 best_idx = -1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2901 for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; ++idx) |
7 | 2902 { |
2903 int lc_col = matchcol; | |
2904 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2905 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2906 if (spp->sp_type != SPTYPE_END) /* past last END pattern */ |
2907 break; | |
2908 lc_col -= spp->sp_offsets[SPO_LC_OFF]; | |
2909 if (lc_col < 0) | |
2910 lc_col = 0; | |
2911 | |
2912 regmatch.rmm_ic = spp->sp_ic; | |
2913 regmatch.regprog = spp->sp_prog; | |
2914 if (syn_regexec(®match, startpos->lnum, lc_col)) | |
2915 { | |
2916 if (best_idx == -1 || regmatch.startpos[0].col | |
2917 < best_regmatch.startpos[0].col) | |
2918 { | |
2919 best_idx = idx; | |
2920 best_regmatch.startpos[0] = regmatch.startpos[0]; | |
2921 best_regmatch.endpos[0] = regmatch.endpos[0]; | |
2922 } | |
2923 } | |
2924 } | |
2925 | |
2926 /* | |
2927 * If all end patterns have been tried, and there is no match, the | |
2928 * item continues until end-of-line. | |
2929 */ | |
2930 if (best_idx == -1) | |
2931 break; | |
2932 | |
2933 /* | |
2934 * If the skip pattern matches before the end pattern, | |
2935 * continue searching after the skip pattern. | |
2936 */ | |
2937 if (spp_skip != NULL) | |
2938 { | |
2939 int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; | |
2940 | |
2941 if (lc_col < 0) | |
2942 lc_col = 0; | |
2943 regmatch.rmm_ic = spp_skip->sp_ic; | |
2944 regmatch.regprog = spp_skip->sp_prog; | |
2945 if (syn_regexec(®match, startpos->lnum, lc_col) | |
2946 && regmatch.startpos[0].col | |
2947 <= best_regmatch.startpos[0].col) | |
2948 { | |
2949 /* Add offset to skip pattern match */ | |
2950 syn_add_end_off(&pos, ®match, spp_skip, SPO_ME_OFF, 1); | |
2951 | |
2952 /* If the skip pattern goes on to the next line, there is no | |
2953 * match with an end pattern in this line. */ | |
2954 if (pos.lnum > startpos->lnum) | |
2955 break; | |
2956 | |
2957 line = ml_get_buf(syn_buf, startpos->lnum, FALSE); | |
2958 | |
2959 /* take care of an empty match or negative offset */ | |
2960 if (pos.col <= matchcol) | |
2961 ++matchcol; | |
2962 else if (pos.col <= regmatch.endpos[0].col) | |
2963 matchcol = pos.col; | |
2964 else | |
2965 /* Be careful not to jump over the NUL at the end-of-line */ | |
2966 for (matchcol = regmatch.endpos[0].col; | |
2967 line[matchcol] != NUL && matchcol < pos.col; | |
2968 ++matchcol) | |
2969 ; | |
2970 | |
2971 /* if the skip pattern includes end-of-line, break here */ | |
2972 if (line[matchcol] == NUL) | |
2973 break; | |
2974 | |
2975 continue; /* start with first end pattern again */ | |
2976 } | |
2977 } | |
2978 | |
2979 /* | |
2980 * Match from start pattern to end pattern. | |
2981 * Correct for match and highlight offset of end pattern. | |
2982 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2983 spp = &(SYN_ITEMS(syn_block)[best_idx]); |
7 | 2984 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); |
2985 /* can't end before the start */ | |
2986 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) | |
2987 m_endpos->col = startpos->col; | |
2988 | |
2989 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); | |
2990 /* can't end before the start */ | |
2991 if (end_endpos->lnum == startpos->lnum | |
2992 && end_endpos->col < startpos->col) | |
2993 end_endpos->col = startpos->col; | |
2994 /* can't end after the match */ | |
2995 limit_pos(end_endpos, m_endpos); | |
2996 | |
2997 /* | |
2998 * If the end group is highlighted differently, adjust the pointers. | |
2999 */ | |
3000 if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) | |
3001 { | |
3002 *end_idx = best_idx; | |
3003 if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) | |
3004 { | |
3005 hl_endpos->lnum = best_regmatch.endpos[0].lnum; | |
3006 hl_endpos->col = best_regmatch.endpos[0].col; | |
3007 } | |
3008 else | |
3009 { | |
3010 hl_endpos->lnum = best_regmatch.startpos[0].lnum; | |
3011 hl_endpos->col = best_regmatch.startpos[0].col; | |
3012 } | |
3013 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; | |
3014 | |
3015 /* can't end before the start */ | |
3016 if (hl_endpos->lnum == startpos->lnum | |
3017 && hl_endpos->col < startpos->col) | |
3018 hl_endpos->col = startpos->col; | |
3019 limit_pos(hl_endpos, m_endpos); | |
3020 | |
3021 /* now the match ends where the highlighting ends, it is turned | |
3022 * into the matchgroup for the end */ | |
3023 *m_endpos = *hl_endpos; | |
3024 } | |
3025 else | |
3026 { | |
3027 *end_idx = 0; | |
3028 *hl_endpos = *end_endpos; | |
3029 } | |
3030 | |
3031 *flagsp = spp->sp_flags; | |
3032 | |
3033 had_match = TRUE; | |
3034 break; | |
3035 } | |
3036 | |
3037 /* no match for an END pattern in this line */ | |
3038 if (!had_match) | |
3039 m_endpos->lnum = 0; | |
3040 | |
3041 /* Remove external matches. */ | |
3042 unref_extmatch(re_extmatch_in); | |
3043 re_extmatch_in = NULL; | |
3044 } | |
3045 | |
3046 /* | |
3047 * Limit "pos" not to be after "limit". | |
3048 */ | |
3049 static void | |
3050 limit_pos(pos, limit) | |
3051 lpos_T *pos; | |
3052 lpos_T *limit; | |
3053 { | |
3054 if (pos->lnum > limit->lnum) | |
3055 *pos = *limit; | |
3056 else if (pos->lnum == limit->lnum && pos->col > limit->col) | |
3057 pos->col = limit->col; | |
3058 } | |
3059 | |
3060 /* | |
3061 * Limit "pos" not to be after "limit", unless pos->lnum is zero. | |
3062 */ | |
3063 static void | |
3064 limit_pos_zero(pos, limit) | |
3065 lpos_T *pos; | |
3066 lpos_T *limit; | |
3067 { | |
3068 if (pos->lnum == 0) | |
3069 *pos = *limit; | |
3070 else | |
3071 limit_pos(pos, limit); | |
3072 } | |
3073 | |
3074 /* | |
3075 * Add offset to matched text for end of match or highlight. | |
3076 */ | |
3077 static void | |
3078 syn_add_end_off(result, regmatch, spp, idx, extra) | |
3079 lpos_T *result; /* returned position */ | |
3080 regmmatch_T *regmatch; /* start/end of match */ | |
3081 synpat_T *spp; /* matched pattern */ | |
3082 int idx; /* index of offset */ | |
3083 int extra; /* extra chars for offset to start */ | |
3084 { | |
3085 int col; | |
1624 | 3086 int off; |
3087 char_u *base; | |
3088 char_u *p; | |
7 | 3089 |
3090 if (spp->sp_off_flags & (1 << idx)) | |
3091 { | |
3092 result->lnum = regmatch->startpos[0].lnum; | |
1624 | 3093 col = regmatch->startpos[0].col; |
3094 off = spp->sp_offsets[idx] + extra; | |
7 | 3095 } |
3096 else | |
3097 { | |
3098 result->lnum = regmatch->endpos[0].lnum; | |
3099 col = regmatch->endpos[0].col; | |
1624 | 3100 off = spp->sp_offsets[idx]; |
3101 } | |
3102 /* Don't go past the end of the line. Matters for "rs=e+2" when there | |
3103 * is a matchgroup. Watch out for match with last NL in the buffer. */ | |
3104 if (result->lnum > syn_buf->b_ml.ml_line_count) | |
3105 col = 0; | |
3106 else if (off != 0) | |
3107 { | |
3108 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3109 p = base + col; | |
3110 if (off > 0) | |
3111 { | |
3112 while (off-- > 0 && *p != NUL) | |
3113 mb_ptr_adv(p); | |
3114 } | |
3115 else if (off < 0) | |
3116 { | |
3117 while (off++ < 0 && base < p) | |
3118 mb_ptr_back(base, p); | |
3119 } | |
3120 col = (int)(p - base); | |
3121 } | |
3122 result->col = col; | |
7 | 3123 } |
3124 | |
3125 /* | |
3126 * Add offset to matched text for start of match or highlight. | |
3127 * Avoid resulting column to become negative. | |
3128 */ | |
3129 static void | |
3130 syn_add_start_off(result, regmatch, spp, idx, extra) | |
3131 lpos_T *result; /* returned position */ | |
3132 regmmatch_T *regmatch; /* start/end of match */ | |
3133 synpat_T *spp; | |
3134 int idx; | |
3135 int extra; /* extra chars for offset to end */ | |
3136 { | |
3137 int col; | |
1624 | 3138 int off; |
3139 char_u *base; | |
3140 char_u *p; | |
7 | 3141 |
3142 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) | |
3143 { | |
3144 result->lnum = regmatch->endpos[0].lnum; | |
1624 | 3145 col = regmatch->endpos[0].col; |
3146 off = spp->sp_offsets[idx] + extra; | |
7 | 3147 } |
3148 else | |
3149 { | |
3150 result->lnum = regmatch->startpos[0].lnum; | |
3151 col = regmatch->startpos[0].col; | |
1624 | 3152 off = spp->sp_offsets[idx]; |
3153 } | |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3154 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
|
3155 { |
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3156 /* a "\n" at the end of the pattern may take us below the last line */ |
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3157 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
|
3158 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
|
3159 } |
1624 | 3160 if (off != 0) |
3161 { | |
3162 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3163 p = base + col; | |
3164 if (off > 0) | |
3165 { | |
3166 while (off-- && *p != NUL) | |
3167 mb_ptr_adv(p); | |
3168 } | |
3169 else if (off < 0) | |
3170 { | |
3171 while (off++ && base < p) | |
3172 mb_ptr_back(base, p); | |
3173 } | |
3174 col = (int)(p - base); | |
3175 } | |
3176 result->col = col; | |
7 | 3177 } |
3178 | |
3179 /* | |
3180 * Get current line in syntax buffer. | |
3181 */ | |
3182 static char_u * | |
3183 syn_getcurline() | |
3184 { | |
3185 return ml_get_buf(syn_buf, current_lnum, FALSE); | |
3186 } | |
3187 | |
3188 /* | |
410 | 3189 * Call vim_regexec() to find a match with "rmp" in "syn_buf". |
7 | 3190 * Returns TRUE when there is a match. |
3191 */ | |
3192 static int | |
3193 syn_regexec(rmp, lnum, col) | |
3194 regmmatch_T *rmp; | |
3195 linenr_T lnum; | |
3196 colnr_T col; | |
3197 { | |
410 | 3198 rmp->rmm_maxcol = syn_buf->b_p_smc; |
1521 | 3199 if (vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, NULL) > 0) |
7 | 3200 { |
3201 rmp->startpos[0].lnum += lnum; | |
3202 rmp->endpos[0].lnum += lnum; | |
3203 return TRUE; | |
3204 } | |
3205 return FALSE; | |
3206 } | |
3207 | |
3208 /* | |
3209 * Check one position in a line for a matching keyword. | |
3210 * The caller must check if a keyword can start at startcol. | |
3211 * Return it's ID if found, 0 otherwise. | |
3212 */ | |
3213 static int | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3214 check_keyword_id(line, startcol, endcolp, flagsp, next_listp, cur_si, ccharp) |
7 | 3215 char_u *line; |
3216 int startcol; /* position in line to check for keyword */ | |
3217 int *endcolp; /* return: character after found keyword */ | |
3218 long *flagsp; /* return: flags of matching keyword */ | |
3219 short **next_listp; /* return: next_list of matching keyword */ | |
3220 stateitem_T *cur_si; /* item at the top of the stack */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3221 int *ccharp UNUSED; /* conceal substitution char */ |
7 | 3222 { |
134 | 3223 keyentry_T *kp; |
3224 char_u *kwp; | |
7 | 3225 int round; |
134 | 3226 int kwlen; |
7 | 3227 char_u keyword[MAXKEYWLEN + 1]; /* assume max. keyword len is 80 */ |
134 | 3228 hashtab_T *ht; |
3229 hashitem_T *hi; | |
7 | 3230 |
3231 /* Find first character after the keyword. First character was already | |
3232 * checked. */ | |
134 | 3233 kwp = line + startcol; |
3234 kwlen = 0; | |
7 | 3235 do |
3236 { | |
3237 #ifdef FEAT_MBYTE | |
3238 if (has_mbyte) | |
474 | 3239 kwlen += (*mb_ptr2len)(kwp + kwlen); |
7 | 3240 else |
3241 #endif | |
134 | 3242 ++kwlen; |
3243 } | |
3244 while (vim_iswordc_buf(kwp + kwlen, syn_buf)); | |
3245 | |
3246 if (kwlen > MAXKEYWLEN) | |
7 | 3247 return 0; |
3248 | |
3249 /* | |
3250 * Must make a copy of the keyword, so we can add a NUL and make it | |
3251 * lowercase. | |
3252 */ | |
419 | 3253 vim_strncpy(keyword, kwp, kwlen); |
7 | 3254 |
3255 /* | |
3256 * Try twice: | |
3257 * 1. matching case | |
3258 * 2. ignoring case | |
3259 */ | |
3260 for (round = 1; round <= 2; ++round) | |
3261 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3262 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; |
134 | 3263 if (ht->ht_used == 0) |
7 | 3264 continue; |
134 | 3265 if (round == 2) /* ignore case */ |
3266 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); | |
7 | 3267 |
3268 /* | |
134 | 3269 * Find keywords that match. There can be several with different |
3270 * attributes. | |
7 | 3271 * When current_next_list is non-zero accept only that group, otherwise: |
3272 * Accept a not-contained keyword at toplevel. | |
3273 * Accept a keyword at other levels only if it is in the contains list. | |
3274 */ | |
134 | 3275 hi = hash_find(ht, keyword); |
3276 if (!HASHITEM_EMPTY(hi)) | |
3277 for (kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) | |
7 | 3278 { |
134 | 3279 if (current_next_list != 0 |
3280 ? in_id_list(NULL, current_next_list, &kp->k_syn, 0) | |
3281 : (cur_si == NULL | |
3282 ? !(kp->flags & HL_CONTAINED) | |
3283 : in_id_list(cur_si, cur_si->si_cont_list, | |
3284 &kp->k_syn, kp->flags & HL_CONTAINED))) | |
3285 { | |
3286 *endcolp = startcol + kwlen; | |
3287 *flagsp = kp->flags; | |
3288 *next_listp = kp->next_list; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3289 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3290 *ccharp = kp->k_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3291 #endif |
134 | 3292 return kp->k_syn.id; |
3293 } | |
7 | 3294 } |
3295 } | |
3296 return 0; | |
3297 } | |
3298 | |
3299 /* | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3300 * Handle ":syntax conceal" command. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3301 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3302 static void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3303 syn_cmd_conceal(eap, syncing) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3304 exarg_T *eap UNUSED; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3305 int syncing UNUSED; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3306 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3307 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3308 char_u *arg = eap->arg; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3309 char_u *next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3310 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3311 eap->nextcmd = find_nextcmd(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3312 if (eap->skip) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3313 return; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3314 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3315 next = skiptowhite(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3316 if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3317 curwin->w_s->b_syn_conceal = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3318 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
|
3319 curwin->w_s->b_syn_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3320 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3321 EMSG2(_("E390: Illegal argument: %s"), arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3322 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3323 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3324 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3325 /* |
7 | 3326 * Handle ":syntax case" command. |
3327 */ | |
3328 static void | |
3329 syn_cmd_case(eap, syncing) | |
3330 exarg_T *eap; | |
1883 | 3331 int syncing UNUSED; |
7 | 3332 { |
3333 char_u *arg = eap->arg; | |
3334 char_u *next; | |
3335 | |
3336 eap->nextcmd = find_nextcmd(arg); | |
3337 if (eap->skip) | |
3338 return; | |
3339 | |
3340 next = skiptowhite(arg); | |
3341 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
|
3342 curwin->w_s->b_syn_ic = FALSE; |
7 | 3343 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
|
3344 curwin->w_s->b_syn_ic = TRUE; |
7 | 3345 else |
3346 EMSG2(_("E390: Illegal argument: %s"), arg); | |
3347 } | |
3348 | |
3349 /* | |
419 | 3350 * Handle ":syntax spell" command. |
3351 */ | |
3352 static void | |
3353 syn_cmd_spell(eap, syncing) | |
3354 exarg_T *eap; | |
1883 | 3355 int syncing UNUSED; |
419 | 3356 { |
3357 char_u *arg = eap->arg; | |
3358 char_u *next; | |
3359 | |
3360 eap->nextcmd = find_nextcmd(arg); | |
3361 if (eap->skip) | |
3362 return; | |
3363 | |
3364 next = skiptowhite(arg); | |
3365 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
|
3366 curwin->w_s->b_syn_spell = SYNSPL_TOP; |
419 | 3367 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
|
3368 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; |
1064 | 3369 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
|
3370 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; |
419 | 3371 else |
3372 EMSG2(_("E390: Illegal argument: %s"), arg); | |
3373 } | |
3374 | |
3375 /* | |
7 | 3376 * Clear all syntax info for one buffer. |
3377 */ | |
3378 void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3379 syntax_clear(block) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3380 synblock_T *block; |
7 | 3381 { |
3382 int i; | |
3383 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3384 block->b_syn_error = FALSE; /* clear previous error */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3385 block->b_syn_ic = FALSE; /* Use case, by default */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3386 block->b_syn_spell = SYNSPL_DEFAULT; /* default spell checking */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3387 block->b_syn_containedin = FALSE; |
7 | 3388 |
3389 /* free the keywords */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3390 clear_keywtab(&block->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3391 clear_keywtab(&block->b_keywtab_ic); |
7 | 3392 |
3393 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3394 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
|
3395 syn_clear_pattern(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3396 ga_clear(&block->b_syn_patterns); |
7 | 3397 |
3398 /* free the syntax clusters */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3399 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
|
3400 syn_clear_cluster(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3401 ga_clear(&block->b_syn_clusters); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3402 block->b_spell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3403 block->b_nospell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3404 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3405 block->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3406 block->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3407 block->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3408 block->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3409 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3410 vim_free(block->b_syn_linecont_prog); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3411 block->b_syn_linecont_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3412 vim_free(block->b_syn_linecont_pat); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3413 block->b_syn_linecont_pat = NULL; |
7 | 3414 #ifdef FEAT_FOLDING |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3415 block->b_syn_folditems = 0; |
7 | 3416 #endif |
3417 | |
3418 /* free the stored states */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3419 syn_stack_free_all(block); |
7 | 3420 invalidate_current_state(); |
3421 } | |
3422 | |
3423 /* | |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3424 * 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
|
3425 */ |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3426 void |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3427 reset_synblock(wp) |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3428 win_T *wp; |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3429 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3430 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
|
3431 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3432 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
|
3433 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
|
3434 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
|
3435 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3436 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3437 |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3438 /* |
7 | 3439 * Clear syncing info for one buffer. |
3440 */ | |
3441 static void | |
3442 syntax_sync_clear() | |
3443 { | |
3444 int i; | |
3445 | |
3446 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3447 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
|
3448 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
|
3449 syn_remove_pattern(curwin->w_s, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3450 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3451 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
|
3452 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
|
3453 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
|
3454 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
|
3455 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3456 vim_free(curwin->w_s->b_syn_linecont_prog); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3457 curwin->w_s->b_syn_linecont_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3458 vim_free(curwin->w_s->b_syn_linecont_pat); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3459 curwin->w_s->b_syn_linecont_pat = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3460 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3461 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3462 } |
3463 | |
3464 /* | |
3465 * Remove one pattern from the buffer's pattern list. | |
3466 */ | |
3467 static void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3468 syn_remove_pattern(block, idx) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3469 synblock_T *block; |
7 | 3470 int idx; |
3471 { | |
3472 synpat_T *spp; | |
3473 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3474 spp = &(SYN_ITEMS(block)[idx]); |
7 | 3475 #ifdef FEAT_FOLDING |
3476 if (spp->sp_flags & HL_FOLD) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3477 --block->b_syn_folditems; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3478 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3479 syn_clear_pattern(block, idx); |
7 | 3480 mch_memmove(spp, spp + 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3481 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
|
3482 --block->b_syn_patterns.ga_len; |
7 | 3483 } |
3484 | |
3485 /* | |
3486 * Clear and free one syntax pattern. When clearing all, must be called from | |
3487 * last to first! | |
3488 */ | |
3489 static void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3490 syn_clear_pattern(block, i) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3491 synblock_T *block; |
7 | 3492 int i; |
3493 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3494 vim_free(SYN_ITEMS(block)[i].sp_pattern); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3495 vim_free(SYN_ITEMS(block)[i].sp_prog); |
7 | 3496 /* 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
|
3497 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
|
3498 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3499 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
|
3500 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
|
3501 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); |
7 | 3502 } |
3503 } | |
3504 | |
3505 /* | |
3506 * Clear and free one syntax cluster. | |
3507 */ | |
3508 static void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3509 syn_clear_cluster(block, i) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3510 synblock_T *block; |
7 | 3511 int i; |
3512 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3513 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
|
3514 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
|
3515 vim_free(SYN_CLSTR(block)[i].scl_list); |
7 | 3516 } |
3517 | |
3518 /* | |
3519 * Handle ":syntax clear" command. | |
3520 */ | |
3521 static void | |
3522 syn_cmd_clear(eap, syncing) | |
3523 exarg_T *eap; | |
3524 int syncing; | |
3525 { | |
3526 char_u *arg = eap->arg; | |
3527 char_u *arg_end; | |
3528 int id; | |
3529 | |
3530 eap->nextcmd = find_nextcmd(arg); | |
3531 if (eap->skip) | |
3532 return; | |
3533 | |
3534 /* | |
3535 * We have to disable this within ":syn include @group filename", | |
3536 * because otherwise @group would get deleted. | |
3537 * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn | |
3538 * clear". | |
3539 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3540 if (curwin->w_s->b_syn_topgrp != 0) |
7 | 3541 return; |
3542 | |
3543 if (ends_excmd(*arg)) | |
3544 { | |
3545 /* | |
3546 * No argument: Clear all syntax items. | |
3547 */ | |
3548 if (syncing) | |
3549 syntax_sync_clear(); | |
3550 else | |
3551 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3552 syntax_clear(curwin->w_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3553 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
|
3554 do_unlet((char_u *)"b:current_syntax", TRUE); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
3555 do_unlet((char_u *)"w:current_syntax", TRUE); |
7 | 3556 } |
3557 } | |
3558 else | |
3559 { | |
3560 /* | |
3561 * Clear the group IDs that are in the argument. | |
3562 */ | |
3563 while (!ends_excmd(*arg)) | |
3564 { | |
3565 arg_end = skiptowhite(arg); | |
3566 if (*arg == '@') | |
3567 { | |
3568 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3569 if (id == 0) | |
3570 { | |
3571 EMSG2(_("E391: No such syntax cluster: %s"), arg); | |
3572 break; | |
3573 } | |
3574 else | |
3575 { | |
3576 /* | |
3577 * We can't physically delete a cluster without changing | |
3578 * the IDs of other clusters, so we do the next best thing | |
3579 * and make it empty. | |
3580 */ | |
3581 short scl_id = id - SYNID_CLUSTER; | |
3582 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3583 vim_free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3584 SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; |
7 | 3585 } |
3586 } | |
3587 else | |
3588 { | |
3589 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3590 if (id == 0) | |
3591 { | |
3592 EMSG2(_(e_nogroup), arg); | |
3593 break; | |
3594 } | |
3595 else | |
3596 syn_clear_one(id, syncing); | |
3597 } | |
3598 arg = skipwhite(arg_end); | |
3599 } | |
3600 } | |
745 | 3601 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3602 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3603 } |
3604 | |
3605 /* | |
3606 * Clear one syntax group for the current buffer. | |
3607 */ | |
3608 static void | |
3609 syn_clear_one(id, syncing) | |
3610 int id; | |
3611 int syncing; | |
3612 { | |
3613 synpat_T *spp; | |
3614 int idx; | |
3615 | |
3616 /* Clear keywords only when not ":syn sync clear group-name" */ | |
3617 if (!syncing) | |
3618 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3619 (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
|
3620 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); |
7 | 3621 } |
3622 | |
3623 /* clear the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3624 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
|
3625 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3626 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3627 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3628 continue; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3629 syn_remove_pattern(curwin->w_s, idx); |
7 | 3630 } |
3631 } | |
3632 | |
3633 /* | |
3634 * Handle ":syntax on" command. | |
3635 */ | |
3636 static void | |
3637 syn_cmd_on(eap, syncing) | |
3638 exarg_T *eap; | |
1883 | 3639 int syncing UNUSED; |
7 | 3640 { |
3641 syn_cmd_onoff(eap, "syntax"); | |
3642 } | |
3643 | |
3644 /* | |
3645 * Handle ":syntax enable" command. | |
3646 */ | |
3647 static void | |
3648 syn_cmd_enable(eap, syncing) | |
3649 exarg_T *eap; | |
1883 | 3650 int syncing UNUSED; |
7 | 3651 { |
3652 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable"); | |
3653 syn_cmd_onoff(eap, "syntax"); | |
148 | 3654 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3655 } |
3656 | |
3657 /* | |
3658 * Handle ":syntax reset" command. | |
3659 */ | |
3660 static void | |
3661 syn_cmd_reset(eap, syncing) | |
3662 exarg_T *eap; | |
1883 | 3663 int syncing UNUSED; |
7 | 3664 { |
3665 eap->nextcmd = check_nextcmd(eap->arg); | |
3666 if (!eap->skip) | |
3667 { | |
3668 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset"); | |
3669 do_cmdline_cmd((char_u *)"runtime! syntax/syncolor.vim"); | |
148 | 3670 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3671 } |
3672 } | |
3673 | |
3674 /* | |
3675 * Handle ":syntax manual" command. | |
3676 */ | |
3677 static void | |
3678 syn_cmd_manual(eap, syncing) | |
3679 exarg_T *eap; | |
1883 | 3680 int syncing UNUSED; |
7 | 3681 { |
3682 syn_cmd_onoff(eap, "manual"); | |
3683 } | |
3684 | |
3685 /* | |
3686 * Handle ":syntax off" command. | |
3687 */ | |
3688 static void | |
3689 syn_cmd_off(eap, syncing) | |
3690 exarg_T *eap; | |
1883 | 3691 int syncing UNUSED; |
7 | 3692 { |
3693 syn_cmd_onoff(eap, "nosyntax"); | |
3694 } | |
3695 | |
3696 static void | |
3697 syn_cmd_onoff(eap, name) | |
3698 exarg_T *eap; | |
3699 char *name; | |
3700 { | |
3701 char_u buf[100]; | |
3702 | |
3703 eap->nextcmd = check_nextcmd(eap->arg); | |
3704 if (!eap->skip) | |
3705 { | |
3706 STRCPY(buf, "so "); | |
274 | 3707 vim_snprintf((char *)buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); |
7 | 3708 do_cmdline_cmd(buf); |
3709 } | |
3710 } | |
3711 | |
3712 /* | |
3713 * Handle ":syntax [list]" command: list current syntax words. | |
3714 */ | |
3715 static void | |
3716 syn_cmd_list(eap, syncing) | |
3717 exarg_T *eap; | |
3718 int syncing; /* when TRUE: list syncing items */ | |
3719 { | |
3720 char_u *arg = eap->arg; | |
3721 int id; | |
3722 char_u *arg_end; | |
3723 | |
3724 eap->nextcmd = find_nextcmd(arg); | |
3725 if (eap->skip) | |
3726 return; | |
3727 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3728 if (!syntax_present(curwin)) |
7 | 3729 { |
3730 MSG(_("No Syntax items defined for this buffer")); | |
3731 return; | |
3732 } | |
3733 | |
3734 if (syncing) | |
3735 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3736 if (curwin->w_s->b_syn_sync_flags & SF_CCOMMENT) |
7 | 3737 { |
3738 MSG_PUTS(_("syncing on C-style comments")); | |
3739 syn_lines_msg(); | |
3740 syn_match_msg(); | |
3741 return; | |
3742 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3743 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
|
3744 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3745 if (curwin->w_s->b_syn_sync_minlines == 0) |
7 | 3746 MSG_PUTS(_("no syncing")); |
3747 else | |
3748 { | |
3749 MSG_PUTS(_("syncing starts ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3750 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
7 | 3751 MSG_PUTS(_(" lines before top line")); |
3752 syn_match_msg(); | |
3753 } | |
3754 return; | |
3755 } | |
3756 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
|
3757 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
|
3758 || 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
|
3759 || curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3760 { |
3761 MSG_PUTS(_("\nsyncing on items")); | |
3762 syn_lines_msg(); | |
3763 syn_match_msg(); | |
3764 } | |
3765 } | |
3766 else | |
3767 MSG_PUTS_TITLE(_("\n--- Syntax items ---")); | |
3768 if (ends_excmd(*arg)) | |
3769 { | |
3770 /* | |
3771 * No argument: List all group IDs and all syntax clusters. | |
3772 */ | |
3773 for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id) | |
3774 syn_list_one(id, syncing, FALSE); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3775 for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) |
7 | 3776 syn_list_cluster(id); |
3777 } | |
3778 else | |
3779 { | |
3780 /* | |
3781 * List the group IDs and syntax clusters that are in the argument. | |
3782 */ | |
3783 while (!ends_excmd(*arg) && !got_int) | |
3784 { | |
3785 arg_end = skiptowhite(arg); | |
3786 if (*arg == '@') | |
3787 { | |
3788 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3789 if (id == 0) | |
3790 EMSG2(_("E392: No such syntax cluster: %s"), arg); | |
3791 else | |
3792 syn_list_cluster(id - SYNID_CLUSTER); | |
3793 } | |
3794 else | |
3795 { | |
3796 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3797 if (id == 0) | |
3798 EMSG2(_(e_nogroup), arg); | |
3799 else | |
3800 syn_list_one(id, syncing, TRUE); | |
3801 } | |
3802 arg = skipwhite(arg_end); | |
3803 } | |
3804 } | |
3805 eap->nextcmd = check_nextcmd(arg); | |
3806 } | |
3807 | |
3808 static void | |
3809 syn_lines_msg() | |
3810 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3811 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
|
3812 || curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3813 { |
3814 MSG_PUTS("; "); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3815 if (curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3816 { |
3817 MSG_PUTS(_("minimal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3818 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3819 if (curwin->w_s->b_syn_sync_maxlines) |
7 | 3820 MSG_PUTS(", "); |
3821 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3822 if (curwin->w_s->b_syn_sync_maxlines > 0) |
7 | 3823 { |
3824 MSG_PUTS(_("maximal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3825 msg_outnum(curwin->w_s->b_syn_sync_maxlines); |
7 | 3826 } |
3827 MSG_PUTS(_(" lines before top line")); | |
3828 } | |
3829 } | |
3830 | |
3831 static void | |
3832 syn_match_msg() | |
3833 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3834 if (curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3835 { |
3836 MSG_PUTS(_("; match ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3837 msg_outnum(curwin->w_s->b_syn_sync_linebreaks); |
7 | 3838 MSG_PUTS(_(" line breaks")); |
3839 } | |
3840 } | |
3841 | |
3842 static int last_matchgroup; | |
3843 | |
3844 struct name_list | |
3845 { | |
3846 int flag; | |
3847 char *name; | |
3848 }; | |
3849 | |
3850 static void syn_list_flags __ARGS((struct name_list *nl, int flags, int attr)); | |
3851 | |
3852 /* | |
3853 * List one syntax item, for ":syntax" or "syntax list syntax_name". | |
3854 */ | |
3855 static void | |
3856 syn_list_one(id, syncing, link_only) | |
3857 int id; | |
3858 int syncing; /* when TRUE: list syncing items */ | |
3859 int link_only; /* when TRUE; list link-only too */ | |
3860 { | |
3861 int attr; | |
3862 int idx; | |
3863 int did_header = FALSE; | |
3864 synpat_T *spp; | |
3865 static struct name_list namelist1[] = | |
3866 { | |
3867 {HL_DISPLAY, "display"}, | |
3868 {HL_CONTAINED, "contained"}, | |
3869 {HL_ONELINE, "oneline"}, | |
3870 {HL_KEEPEND, "keepend"}, | |
3871 {HL_EXTEND, "extend"}, | |
3872 {HL_EXCLUDENL, "excludenl"}, | |
3873 {HL_TRANSP, "transparent"}, | |
3874 {HL_FOLD, "fold"}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3875 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3876 {HL_CONCEAL, "conceal"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3877 {HL_CONCEALENDS, "concealends"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3878 #endif |
7 | 3879 {0, NULL} |
3880 }; | |
3881 static struct name_list namelist2[] = | |
3882 { | |
3883 {HL_SKIPWHITE, "skipwhite"}, | |
3884 {HL_SKIPNL, "skipnl"}, | |
3885 {HL_SKIPEMPTY, "skipempty"}, | |
3886 {0, NULL} | |
3887 }; | |
3888 | |
3889 attr = hl_attr(HLF_D); /* highlight like directories */ | |
3890 | |
3891 /* list the keywords for "id" */ | |
3892 if (!syncing) | |
3893 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3894 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
|
3895 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, |
7 | 3896 did_header, attr); |
3897 } | |
3898 | |
3899 /* list the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3900 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
|
3901 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3902 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3903 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3904 continue; | |
3905 | |
3906 (void)syn_list_header(did_header, 999, id); | |
3907 did_header = TRUE; | |
3908 last_matchgroup = 0; | |
3909 if (spp->sp_type == SPTYPE_MATCH) | |
3910 { | |
3911 put_pattern("match", ' ', spp, attr); | |
3912 msg_putchar(' '); | |
3913 } | |
3914 else if (spp->sp_type == SPTYPE_START) | |
3915 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3916 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
|
3917 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
|
3918 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
|
3919 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
|
3920 while (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
|
3921 && SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3922 put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
7 | 3923 --idx; |
3924 msg_putchar(' '); | |
3925 } | |
3926 syn_list_flags(namelist1, spp->sp_flags, attr); | |
3927 | |
3928 if (spp->sp_cont_list != NULL) | |
3929 put_id_list((char_u *)"contains", spp->sp_cont_list, attr); | |
3930 | |
3931 if (spp->sp_syn.cont_in_list != NULL) | |
3932 put_id_list((char_u *)"containedin", | |
3933 spp->sp_syn.cont_in_list, attr); | |
3934 | |
3935 if (spp->sp_next_list != NULL) | |
3936 { | |
3937 put_id_list((char_u *)"nextgroup", spp->sp_next_list, attr); | |
3938 syn_list_flags(namelist2, spp->sp_flags, attr); | |
3939 } | |
3940 if (spp->sp_flags & (HL_SYNC_HERE|HL_SYNC_THERE)) | |
3941 { | |
3942 if (spp->sp_flags & HL_SYNC_HERE) | |
3943 msg_puts_attr((char_u *)"grouphere", attr); | |
3944 else | |
3945 msg_puts_attr((char_u *)"groupthere", attr); | |
3946 msg_putchar(' '); | |
3947 if (spp->sp_sync_idx >= 0) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3948 msg_outtrans(HL_TABLE()[SYN_ITEMS(curwin->w_s) |
7 | 3949 [spp->sp_sync_idx].sp_syn.id - 1].sg_name); |
3950 else | |
3951 MSG_PUTS("NONE"); | |
3952 msg_putchar(' '); | |
3953 } | |
3954 } | |
3955 | |
3956 /* list the link, if there is one */ | |
3957 if (HL_TABLE()[id - 1].sg_link && (did_header || link_only) && !got_int) | |
3958 { | |
3959 (void)syn_list_header(did_header, 999, id); | |
3960 msg_puts_attr((char_u *)"links to", attr); | |
3961 msg_putchar(' '); | |
3962 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
3963 } | |
3964 } | |
3965 | |
3966 static void | |
3967 syn_list_flags(nl, flags, attr) | |
3968 struct name_list *nl; | |
3969 int flags; | |
3970 int attr; | |
3971 { | |
3972 int i; | |
3973 | |
3974 for (i = 0; nl[i].flag != 0; ++i) | |
3975 if (flags & nl[i].flag) | |
3976 { | |
3977 msg_puts_attr((char_u *)nl[i].name, attr); | |
3978 msg_putchar(' '); | |
3979 } | |
3980 } | |
3981 | |
3982 /* | |
3983 * List one syntax cluster, for ":syntax" or "syntax list syntax_name". | |
3984 */ | |
3985 static void | |
3986 syn_list_cluster(id) | |
3987 int id; | |
3988 { | |
3989 int endcol = 15; | |
3990 | |
3991 /* slight hack: roughly duplicate the guts of syn_list_header() */ | |
3992 msg_putchar('\n'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3993 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); |
7 | 3994 |
3995 if (msg_col >= endcol) /* output at least one space */ | |
3996 endcol = msg_col + 1; | |
3997 if (Columns <= endcol) /* avoid hang for tiny window */ | |
3998 endcol = Columns - 1; | |
3999 | |
4000 msg_advance(endcol); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4001 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
|
4002 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4003 put_id_list((char_u *)"cluster", SYN_CLSTR(curwin->w_s)[id].scl_list, |
7 | 4004 hl_attr(HLF_D)); |
4005 } | |
4006 else | |
4007 { | |
4008 msg_puts_attr((char_u *)"cluster", hl_attr(HLF_D)); | |
4009 msg_puts((char_u *)"=NONE"); | |
4010 } | |
4011 } | |
4012 | |
4013 static void | |
4014 put_id_list(name, list, attr) | |
4015 char_u *name; | |
4016 short *list; | |
4017 int attr; | |
4018 { | |
4019 short *p; | |
4020 | |
4021 msg_puts_attr(name, attr); | |
4022 msg_putchar('='); | |
4023 for (p = list; *p; ++p) | |
4024 { | |
4025 if (*p >= SYNID_ALLBUT && *p < SYNID_TOP) | |
4026 { | |
4027 if (p[1]) | |
4028 MSG_PUTS("ALLBUT"); | |
4029 else | |
4030 MSG_PUTS("ALL"); | |
4031 } | |
4032 else if (*p >= SYNID_TOP && *p < SYNID_CONTAINED) | |
4033 { | |
4034 MSG_PUTS("TOP"); | |
4035 } | |
4036 else if (*p >= SYNID_CONTAINED && *p < SYNID_CLUSTER) | |
4037 { | |
4038 MSG_PUTS("CONTAINED"); | |
4039 } | |
4040 else if (*p >= SYNID_CLUSTER) | |
4041 { | |
4042 short scl_id = *p - SYNID_CLUSTER; | |
4043 | |
4044 msg_putchar('@'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4045 msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); |
7 | 4046 } |
4047 else | |
4048 msg_outtrans(HL_TABLE()[*p - 1].sg_name); | |
4049 if (p[1]) | |
4050 msg_putchar(','); | |
4051 } | |
4052 msg_putchar(' '); | |
4053 } | |
4054 | |
4055 static void | |
4056 put_pattern(s, c, spp, attr) | |
4057 char *s; | |
4058 int c; | |
4059 synpat_T *spp; | |
4060 int attr; | |
4061 { | |
4062 long n; | |
4063 int mask; | |
4064 int first; | |
4065 static char *sepchars = "/+=-#@\"|'^&"; | |
4066 int i; | |
4067 | |
4068 /* May have to write "matchgroup=group" */ | |
4069 if (last_matchgroup != spp->sp_syn_match_id) | |
4070 { | |
4071 last_matchgroup = spp->sp_syn_match_id; | |
4072 msg_puts_attr((char_u *)"matchgroup", attr); | |
4073 msg_putchar('='); | |
4074 if (last_matchgroup == 0) | |
4075 msg_outtrans((char_u *)"NONE"); | |
4076 else | |
4077 msg_outtrans(HL_TABLE()[last_matchgroup - 1].sg_name); | |
4078 msg_putchar(' '); | |
4079 } | |
4080 | |
4081 /* output the name of the pattern and an '=' or ' ' */ | |
4082 msg_puts_attr((char_u *)s, attr); | |
4083 msg_putchar(c); | |
4084 | |
4085 /* output the pattern, in between a char that is not in the pattern */ | |
4086 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) | |
4087 if (sepchars[++i] == NUL) | |
4088 { | |
4089 i = 0; /* no good char found, just use the first one */ | |
4090 break; | |
4091 } | |
4092 msg_putchar(sepchars[i]); | |
4093 msg_outtrans(spp->sp_pattern); | |
4094 msg_putchar(sepchars[i]); | |
4095 | |
4096 /* output any pattern options */ | |
4097 first = TRUE; | |
4098 for (i = 0; i < SPO_COUNT; ++i) | |
4099 { | |
4100 mask = (1 << i); | |
4101 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) | |
4102 { | |
4103 if (!first) | |
4104 msg_putchar(','); /* separate with commas */ | |
4105 msg_puts((char_u *)spo_name_tab[i]); | |
4106 n = spp->sp_offsets[i]; | |
4107 if (i != SPO_LC_OFF) | |
4108 { | |
4109 if (spp->sp_off_flags & mask) | |
4110 msg_putchar('s'); | |
4111 else | |
4112 msg_putchar('e'); | |
4113 if (n > 0) | |
4114 msg_putchar('+'); | |
4115 } | |
4116 if (n || i == SPO_LC_OFF) | |
4117 msg_outnum(n); | |
4118 first = FALSE; | |
4119 } | |
4120 } | |
4121 msg_putchar(' '); | |
4122 } | |
4123 | |
4124 /* | |
4125 * List or clear the keywords for one syntax group. | |
4126 * Return TRUE if the header has been printed. | |
4127 */ | |
4128 static int | |
134 | 4129 syn_list_keywords(id, ht, did_header, attr) |
7 | 4130 int id; |
134 | 4131 hashtab_T *ht; |
7 | 4132 int did_header; /* header has already been printed */ |
4133 int attr; | |
4134 { | |
4135 int outlen; | |
134 | 4136 hashitem_T *hi; |
4137 keyentry_T *kp; | |
4138 int todo; | |
7 | 4139 int prev_contained = 0; |
4140 short *prev_next_list = NULL; | |
4141 short *prev_cont_in_list = NULL; | |
4142 int prev_skipnl = 0; | |
4143 int prev_skipwhite = 0; | |
4144 int prev_skipempty = 0; | |
4145 | |
4146 /* | |
4147 * Unfortunately, this list of keywords is not sorted on alphabet but on | |
4148 * hash value... | |
4149 */ | |
835 | 4150 todo = (int)ht->ht_used; |
134 | 4151 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
4152 { | |
4153 if (!HASHITEM_EMPTY(hi)) | |
4154 { | |
4155 --todo; | |
4156 for (kp = HI2KE(hi); kp != NULL && !got_int; kp = kp->ke_next) | |
7 | 4157 { |
134 | 4158 if (kp->k_syn.id == id) |
7 | 4159 { |
134 | 4160 if (prev_contained != (kp->flags & HL_CONTAINED) |
4161 || prev_skipnl != (kp->flags & HL_SKIPNL) | |
4162 || prev_skipwhite != (kp->flags & HL_SKIPWHITE) | |
4163 || prev_skipempty != (kp->flags & HL_SKIPEMPTY) | |
4164 || prev_cont_in_list != kp->k_syn.cont_in_list | |
4165 || prev_next_list != kp->next_list) | |
4166 outlen = 9999; | |
4167 else | |
4168 outlen = (int)STRLEN(kp->keyword); | |
4169 /* output "contained" and "nextgroup" on each line */ | |
4170 if (syn_list_header(did_header, outlen, id)) | |
4171 { | |
4172 prev_contained = 0; | |
4173 prev_next_list = NULL; | |
4174 prev_cont_in_list = NULL; | |
4175 prev_skipnl = 0; | |
4176 prev_skipwhite = 0; | |
4177 prev_skipempty = 0; | |
4178 } | |
4179 did_header = TRUE; | |
4180 if (prev_contained != (kp->flags & HL_CONTAINED)) | |
4181 { | |
4182 msg_puts_attr((char_u *)"contained", attr); | |
4183 msg_putchar(' '); | |
4184 prev_contained = (kp->flags & HL_CONTAINED); | |
4185 } | |
4186 if (kp->k_syn.cont_in_list != prev_cont_in_list) | |
4187 { | |
4188 put_id_list((char_u *)"containedin", | |
4189 kp->k_syn.cont_in_list, attr); | |
4190 msg_putchar(' '); | |
4191 prev_cont_in_list = kp->k_syn.cont_in_list; | |
4192 } | |
4193 if (kp->next_list != prev_next_list) | |
4194 { | |
4195 put_id_list((char_u *)"nextgroup", kp->next_list, attr); | |
4196 msg_putchar(' '); | |
4197 prev_next_list = kp->next_list; | |
4198 if (kp->flags & HL_SKIPNL) | |
4199 { | |
4200 msg_puts_attr((char_u *)"skipnl", attr); | |
4201 msg_putchar(' '); | |
4202 prev_skipnl = (kp->flags & HL_SKIPNL); | |
4203 } | |
4204 if (kp->flags & HL_SKIPWHITE) | |
4205 { | |
4206 msg_puts_attr((char_u *)"skipwhite", attr); | |
4207 msg_putchar(' '); | |
4208 prev_skipwhite = (kp->flags & HL_SKIPWHITE); | |
4209 } | |
4210 if (kp->flags & HL_SKIPEMPTY) | |
4211 { | |
4212 msg_puts_attr((char_u *)"skipempty", attr); | |
4213 msg_putchar(' '); | |
4214 prev_skipempty = (kp->flags & HL_SKIPEMPTY); | |
4215 } | |
4216 } | |
4217 msg_outtrans(kp->keyword); | |
7 | 4218 } |
4219 } | |
4220 } | |
4221 } | |
4222 | |
4223 return did_header; | |
4224 } | |
4225 | |
4226 static void | |
134 | 4227 syn_clear_keyword(id, ht) |
7 | 4228 int id; |
134 | 4229 hashtab_T *ht; |
4230 { | |
4231 hashitem_T *hi; | |
4232 keyentry_T *kp; | |
4233 keyentry_T *kp_prev; | |
4234 keyentry_T *kp_next; | |
4235 int todo; | |
4236 | |
4237 hash_lock(ht); | |
835 | 4238 todo = (int)ht->ht_used; |
134 | 4239 for (hi = ht->ht_array; todo > 0; ++hi) |
4240 { | |
4241 if (!HASHITEM_EMPTY(hi)) | |
4242 { | |
4243 --todo; | |
4244 kp_prev = NULL; | |
4245 for (kp = HI2KE(hi); kp != NULL; ) | |
7 | 4246 { |
134 | 4247 if (kp->k_syn.id == id) |
4248 { | |
4249 kp_next = kp->ke_next; | |
4250 if (kp_prev == NULL) | |
4251 { | |
4252 if (kp_next == NULL) | |
4253 hash_remove(ht, hi); | |
4254 else | |
4255 hi->hi_key = KE2HIKEY(kp_next); | |
4256 } | |
4257 else | |
4258 kp_prev->ke_next = kp_next; | |
4259 vim_free(kp->next_list); | |
4260 vim_free(kp->k_syn.cont_in_list); | |
4261 vim_free(kp); | |
4262 kp = kp_next; | |
4263 } | |
7 | 4264 else |
134 | 4265 { |
4266 kp_prev = kp; | |
4267 kp = kp->ke_next; | |
4268 } | |
7 | 4269 } |
134 | 4270 } |
4271 } | |
4272 hash_unlock(ht); | |
4273 } | |
4274 | |
4275 /* | |
4276 * Clear a whole keyword table. | |
7 | 4277 */ |
4278 static void | |
134 | 4279 clear_keywtab(ht) |
4280 hashtab_T *ht; | |
4281 { | |
4282 hashitem_T *hi; | |
4283 int todo; | |
4284 keyentry_T *kp; | |
4285 keyentry_T *kp_next; | |
4286 | |
835 | 4287 todo = (int)ht->ht_used; |
134 | 4288 for (hi = ht->ht_array; todo > 0; ++hi) |
4289 { | |
4290 if (!HASHITEM_EMPTY(hi)) | |
4291 { | |
4292 --todo; | |
4293 for (kp = HI2KE(hi); kp != NULL; kp = kp_next) | |
7 | 4294 { |
134 | 4295 kp_next = kp->ke_next; |
4296 vim_free(kp->next_list); | |
4297 vim_free(kp->k_syn.cont_in_list); | |
4298 vim_free(kp); | |
7 | 4299 } |
134 | 4300 } |
4301 } | |
4302 hash_clear(ht); | |
4303 hash_init(ht); | |
7 | 4304 } |
4305 | |
4306 /* | |
4307 * Add a keyword to the list of keywords. | |
4308 */ | |
4309 static void | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4310 add_keyword(name, id, flags, cont_in_list, next_list, conceal_char) |
7 | 4311 char_u *name; /* name of keyword */ |
4312 int id; /* group ID for this keyword */ | |
4313 int flags; /* flags for this keyword */ | |
4314 short *cont_in_list; /* containedin for this keyword */ | |
4315 short *next_list; /* nextgroup for this keyword */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4316 int conceal_char; |
7 | 4317 { |
134 | 4318 keyentry_T *kp; |
4319 hashtab_T *ht; | |
4320 hashitem_T *hi; | |
154 | 4321 char_u *name_ic; |
134 | 4322 long_u hash; |
154 | 4323 char_u name_folded[MAXKEYWLEN + 1]; |
7 | 4324 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4325 if (curwin->w_s->b_syn_ic) |
154 | 4326 name_ic = str_foldcase(name, (int)STRLEN(name), |
4327 name_folded, MAXKEYWLEN + 1); | |
4328 else | |
4329 name_ic = name; | |
134 | 4330 kp = (keyentry_T *)alloc((int)(sizeof(keyentry_T) + STRLEN(name_ic))); |
4331 if (kp == NULL) | |
4332 return; | |
4333 STRCPY(kp->keyword, name_ic); | |
4334 kp->k_syn.id = id; | |
4335 kp->k_syn.inc_tag = current_syn_inc_tag; | |
4336 kp->flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4337 kp->k_char = conceal_char; |
134 | 4338 kp->k_syn.cont_in_list = copy_id_list(cont_in_list); |
4339 if (cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4340 curwin->w_s->b_syn_containedin = TRUE; |
134 | 4341 kp->next_list = copy_id_list(next_list); |
4342 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4343 if (curwin->w_s->b_syn_ic) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4344 ht = &curwin->w_s->b_keywtab_ic; |
7 | 4345 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4346 ht = &curwin->w_s->b_keywtab; |
134 | 4347 |
4348 hash = hash_hash(kp->keyword); | |
4349 hi = hash_lookup(ht, kp->keyword, hash); | |
4350 if (HASHITEM_EMPTY(hi)) | |
4351 { | |
4352 /* new keyword, add to hashtable */ | |
4353 kp->ke_next = NULL; | |
4354 hash_add_item(ht, hi, kp->keyword, hash); | |
4355 } | |
4356 else | |
4357 { | |
4358 /* keyword already exists, prepend to list */ | |
4359 kp->ke_next = HI2KE(hi); | |
4360 hi->hi_key = KE2HIKEY(kp); | |
4361 } | |
7 | 4362 } |
4363 | |
4364 /* | |
4365 * Get the start and end of the group name argument. | |
4366 * Return a pointer to the first argument. | |
4367 * Return NULL if the end of the command was found instead of further args. | |
4368 */ | |
4369 static char_u * | |
4370 get_group_name(arg, name_end) | |
4371 char_u *arg; /* start of the argument */ | |
4372 char_u **name_end; /* pointer to end of the name */ | |
4373 { | |
4374 char_u *rest; | |
4375 | |
4376 *name_end = skiptowhite(arg); | |
4377 rest = skipwhite(*name_end); | |
4378 | |
4379 /* | |
4380 * Check if there are enough arguments. The first argument may be a | |
4381 * pattern, where '|' is allowed, so only check for NUL. | |
4382 */ | |
4383 if (ends_excmd(*arg) || *rest == NUL) | |
4384 return NULL; | |
4385 return rest; | |
4386 } | |
4387 | |
4388 /* | |
4389 * Check for syntax command option arguments. | |
4390 * This can be called at any place in the list of arguments, and just picks | |
4391 * out the arguments that are known. Can be called several times in a row to | |
4392 * collect all options in between other arguments. | |
4393 * Return a pointer to the next argument (which isn't an option). | |
4394 * Return NULL for any error; | |
4395 */ | |
4396 static char_u * | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4397 get_syn_options(arg, opt, conceal_char) |
154 | 4398 char_u *arg; /* next argument to be checked */ |
4399 syn_opt_arg_T *opt; /* various things */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4400 int *conceal_char UNUSED; |
154 | 4401 { |
7 | 4402 char_u *gname_start, *gname; |
4403 int syn_id; | |
4404 int len; | |
154 | 4405 char *p; |
7 | 4406 int i; |
4407 int fidx; | |
4408 static struct flag | |
4409 { | |
4410 char *name; | |
154 | 4411 int argtype; |
4412 int flags; | |
4413 } flagtab[] = { {"cCoOnNtTaAiInNeEdD", 0, HL_CONTAINED}, | |
4414 {"oOnNeElLiInNeE", 0, HL_ONELINE}, | |
4415 {"kKeEeEpPeEnNdD", 0, HL_KEEPEND}, | |
4416 {"eExXtTeEnNdD", 0, HL_EXTEND}, | |
4417 {"eExXcClLuUdDeEnNlL", 0, HL_EXCLUDENL}, | |
4418 {"tTrRaAnNsSpPaArReEnNtT", 0, HL_TRANSP}, | |
4419 {"sSkKiIpPnNlL", 0, HL_SKIPNL}, | |
4420 {"sSkKiIpPwWhHiItTeE", 0, HL_SKIPWHITE}, | |
4421 {"sSkKiIpPeEmMpPtTyY", 0, HL_SKIPEMPTY}, | |
4422 {"gGrRoOuUpPhHeErReE", 0, HL_SYNC_HERE}, | |
4423 {"gGrRoOuUpPtThHeErReE", 0, HL_SYNC_THERE}, | |
4424 {"dDiIsSpPlLaAyY", 0, HL_DISPLAY}, | |
4425 {"fFoOlLdD", 0, HL_FOLD}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4426 {"cCoOnNcCeEaAlL", 0, HL_CONCEAL}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4427 {"cCoOnNcCeEaAlLeEnNdDsS", 0, HL_CONCEALENDS}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4428 {"cCcChHaArR", 11, 0}, |
154 | 4429 {"cCoOnNtTaAiInNsS", 1, 0}, |
4430 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, | |
4431 {"nNeExXtTgGrRoOuUpP", 3, 0}, | |
7 | 4432 }; |
154 | 4433 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; |
7 | 4434 |
4435 if (arg == NULL) /* already detected error */ | |
4436 return NULL; | |
4437 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4438 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4439 if (curwin->w_s->b_syn_conceal) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4440 opt->flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4441 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4442 |
7 | 4443 for (;;) |
4444 { | |
154 | 4445 /* |
4446 * This is used very often when a large number of keywords is defined. | |
4447 * Need to skip quickly when no option name is found. | |
4448 * Also avoid tolower(), it's slow. | |
4449 */ | |
4450 if (strchr(first_letters, *arg) == NULL) | |
4451 break; | |
7 | 4452 |
4453 for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; ) | |
4454 { | |
154 | 4455 p = flagtab[fidx].name; |
4456 for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) | |
4457 if (arg[len] != p[i] && arg[len] != p[i + 1]) | |
4458 break; | |
4459 if (p[i] == NUL && (vim_iswhite(arg[len]) | |
4460 || (flagtab[fidx].argtype > 0 | |
4461 ? arg[len] == '=' | |
4462 : ends_excmd(arg[len])))) | |
7 | 4463 { |
154 | 4464 if (opt->keyword |
4465 && (flagtab[fidx].flags == HL_DISPLAY | |
4466 || flagtab[fidx].flags == HL_FOLD | |
4467 || flagtab[fidx].flags == HL_EXTEND)) | |
7 | 4468 /* treat "display", "fold" and "extend" as a keyword */ |
4469 fidx = -1; | |
4470 break; | |
4471 } | |
4472 } | |
154 | 4473 if (fidx < 0) /* no match found */ |
4474 break; | |
4475 | |
4476 if (flagtab[fidx].argtype == 1) | |
4477 { | |
4478 if (!opt->has_cont_list) | |
7 | 4479 { |
4480 EMSG(_("E395: contains argument not accepted here")); | |
4481 return NULL; | |
4482 } | |
154 | 4483 if (get_id_list(&arg, 8, &opt->cont_list) == FAIL) |
7 | 4484 return NULL; |
4485 } | |
154 | 4486 else if (flagtab[fidx].argtype == 2) |
4487 { | |
4488 #if 0 /* cannot happen */ | |
4489 if (opt->cont_in_list == NULL) | |
7 | 4490 { |
4491 EMSG(_("E396: containedin argument not accepted here")); | |
4492 return NULL; | |
4493 } | |
154 | 4494 #endif |
4495 if (get_id_list(&arg, 11, &opt->cont_in_list) == FAIL) | |
7 | 4496 return NULL; |
4497 } | |
154 | 4498 else if (flagtab[fidx].argtype == 3) |
4499 { | |
4500 if (get_id_list(&arg, 9, &opt->next_list) == FAIL) | |
7 | 4501 return NULL; |
4502 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4503 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
|
4504 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4505 #ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4506 /* cchar=? */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4507 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4508 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4509 # ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4510 *conceal_char = mb_ptr2char(arg + 6); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4511 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4512 arg += mb_ptr2len(arg + 6) - 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4513 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4514 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4515 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4516 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4517 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4518 *conceal_char = arg[6]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4519 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4520 ; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4521 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4522 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4523 arg = skipwhite(arg + 7); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4524 } |
7 | 4525 else |
154 | 4526 { |
4527 opt->flags |= flagtab[fidx].flags; | |
4528 arg = skipwhite(arg + len); | |
4529 | |
4530 if (flagtab[fidx].flags == HL_SYNC_HERE | |
4531 || flagtab[fidx].flags == HL_SYNC_THERE) | |
4532 { | |
4533 if (opt->sync_idx == NULL) | |
4534 { | |
4535 EMSG(_("E393: group[t]here not accepted here")); | |
4536 return NULL; | |
4537 } | |
4538 gname_start = arg; | |
4539 arg = skiptowhite(arg); | |
4540 if (gname_start == arg) | |
4541 return NULL; | |
4542 gname = vim_strnsave(gname_start, (int)(arg - gname_start)); | |
4543 if (gname == NULL) | |
4544 return NULL; | |
4545 if (STRCMP(gname, "NONE") == 0) | |
4546 *opt->sync_idx = NONE_IDX; | |
4547 else | |
4548 { | |
4549 syn_id = syn_name2id(gname); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4550 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
|
4551 if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4552 && SYN_ITEMS(curwin->w_s)[i].sp_type == SPTYPE_START) |
154 | 4553 { |
4554 *opt->sync_idx = i; | |
4555 break; | |
4556 } | |
4557 if (i < 0) | |
4558 { | |
4559 EMSG2(_("E394: Didn't find region item for %s"), gname); | |
4560 vim_free(gname); | |
4561 return NULL; | |
4562 } | |
4563 } | |
4564 | |
4565 vim_free(gname); | |
4566 arg = skipwhite(arg); | |
4567 } | |
4568 #ifdef FEAT_FOLDING | |
4569 else if (flagtab[fidx].flags == HL_FOLD | |
4570 && foldmethodIsSyntax(curwin)) | |
4571 /* Need to update folds later. */ | |
4572 foldUpdateAll(curwin); | |
4573 #endif | |
4574 } | |
4575 } | |
7 | 4576 |
4577 return arg; | |
4578 } | |
4579 | |
4580 /* | |
4581 * Adjustments to syntax item when declared in a ":syn include"'d file. | |
4582 * Set the contained flag, and if the item is not already contained, add it | |
4583 * to the specified top-level group, if any. | |
4584 */ | |
4585 static void | |
4586 syn_incl_toplevel(id, flagsp) | |
4587 int id; | |
4588 int *flagsp; | |
4589 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4590 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) |
7 | 4591 return; |
4592 *flagsp |= HL_CONTAINED; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4593 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
7 | 4594 { |
4595 /* We have to alloc this, because syn_combine_list() will free it. */ | |
4596 short *grp_list = (short *)alloc((unsigned)(2 * sizeof(short))); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4597 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; |
7 | 4598 |
4599 if (grp_list != NULL) | |
4600 { | |
4601 grp_list[0] = id; | |
4602 grp_list[1] = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4603 syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, &grp_list, |
7 | 4604 CLUSTER_ADD); |
4605 } | |
4606 } | |
4607 } | |
4608 | |
4609 /* | |
4610 * Handle ":syntax include [@{group-name}] filename" command. | |
4611 */ | |
4612 static void | |
4613 syn_cmd_include(eap, syncing) | |
4614 exarg_T *eap; | |
1883 | 4615 int syncing UNUSED; |
7 | 4616 { |
4617 char_u *arg = eap->arg; | |
4618 int sgl_id = 1; | |
4619 char_u *group_name_end; | |
4620 char_u *rest; | |
4621 char_u *errormsg = NULL; | |
4622 int prev_toplvl_grp; | |
4623 int prev_syn_inc_tag; | |
4624 int source = FALSE; | |
4625 | |
4626 eap->nextcmd = find_nextcmd(arg); | |
4627 if (eap->skip) | |
4628 return; | |
4629 | |
4630 if (arg[0] == '@') | |
4631 { | |
4632 ++arg; | |
4633 rest = get_group_name(arg, &group_name_end); | |
4634 if (rest == NULL) | |
4635 { | |
4636 EMSG((char_u *)_("E397: Filename required")); | |
4637 return; | |
4638 } | |
4639 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
4640 /* separate_nextcmd() and expand_filename() depend on this */ | |
4641 eap->arg = rest; | |
4642 } | |
4643 | |
4644 /* | |
4645 * Everything that's left, up to the next command, should be the | |
4646 * filename to include. | |
4647 */ | |
4648 eap->argt |= (XFILE | NOSPC); | |
4649 separate_nextcmd(eap); | |
4650 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) | |
4651 { | |
4652 /* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the | |
4653 * file. Need to expand the file name first. In other cases | |
4654 * ":runtime!" is used. */ | |
4655 source = TRUE; | |
4656 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) | |
4657 { | |
4658 if (errormsg != NULL) | |
4659 EMSG(errormsg); | |
4660 return; | |
4661 } | |
4662 } | |
4663 | |
4664 /* | |
4665 * Save and restore the existing top-level grouplist id and ":syn | |
4666 * include" tag around the actual inclusion. | |
4667 */ | |
4668 prev_syn_inc_tag = current_syn_inc_tag; | |
4669 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
|
4670 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
|
4671 curwin->w_s->b_syn_topgrp = sgl_id; |
1299 | 4672 if (source ? do_source(eap->arg, FALSE, DOSO_NONE) == FAIL |
4673 : source_runtime(eap->arg, TRUE) == FAIL) | |
7 | 4674 EMSG2(_(e_notopen), eap->arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4675 curwin->w_s->b_syn_topgrp = prev_toplvl_grp; |
7 | 4676 current_syn_inc_tag = prev_syn_inc_tag; |
4677 } | |
4678 | |
4679 /* | |
4680 * Handle ":syntax keyword {group-name} [{option}] keyword .." command. | |
4681 */ | |
4682 static void | |
4683 syn_cmd_keyword(eap, syncing) | |
4684 exarg_T *eap; | |
1883 | 4685 int syncing UNUSED; |
7 | 4686 { |
4687 char_u *arg = eap->arg; | |
4688 char_u *group_name_end; | |
4689 int syn_id; | |
4690 char_u *rest; | |
4691 char_u *keyword_copy; | |
4692 char_u *p; | |
154 | 4693 char_u *kw; |
4694 syn_opt_arg_T syn_opt_arg; | |
4695 int cnt; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4696 int conceal_char = NUL; |
7 | 4697 |
4698 rest = get_group_name(arg, &group_name_end); | |
4699 | |
4700 if (rest != NULL) | |
4701 { | |
4702 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); | |
4703 | |
4704 /* allocate a buffer, for removing the backslashes in the keyword */ | |
4705 keyword_copy = alloc((unsigned)STRLEN(rest) + 1); | |
4706 if (keyword_copy != NULL) | |
4707 { | |
154 | 4708 syn_opt_arg.flags = 0; |
4709 syn_opt_arg.keyword = TRUE; | |
4710 syn_opt_arg.sync_idx = NULL; | |
4711 syn_opt_arg.has_cont_list = FALSE; | |
4712 syn_opt_arg.cont_in_list = NULL; | |
4713 syn_opt_arg.next_list = NULL; | |
4714 | |
7 | 4715 /* |
4716 * The options given apply to ALL keywords, so all options must be | |
4717 * found before keywords can be created. | |
154 | 4718 * 1: collect the options and copy the keywords to keyword_copy. |
7 | 4719 */ |
154 | 4720 cnt = 0; |
4721 p = keyword_copy; | |
4722 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) | |
7 | 4723 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4724 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); |
154 | 4725 if (rest == NULL || ends_excmd(*rest)) |
4726 break; | |
4727 /* Copy the keyword, removing backslashes, and add a NUL. */ | |
4728 while (*rest != NUL && !vim_iswhite(*rest)) | |
4729 { | |
4730 if (*rest == '\\' && rest[1] != NUL) | |
4731 ++rest; | |
4732 *p++ = *rest++; | |
4733 } | |
4734 *p++ = NUL; | |
4735 ++cnt; | |
4736 } | |
4737 | |
4738 if (!eap->skip) | |
4739 { | |
4740 /* Adjust flags for use of ":syn include". */ | |
4741 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); | |
4742 | |
7 | 4743 /* |
154 | 4744 * 2: Add an entry for each keyword. |
7 | 4745 */ |
154 | 4746 for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) |
7 | 4747 { |
154 | 4748 for (p = vim_strchr(kw, '['); ; ) |
7 | 4749 { |
154 | 4750 if (p != NULL) |
4751 *p = NUL; | |
4752 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
|
4753 syn_opt_arg.cont_in_list, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4754 syn_opt_arg.next_list, conceal_char); |
168 | 4755 if (p == NULL) |
4756 break; | |
4757 if (p[1] == NUL) | |
4758 { | |
838 | 4759 EMSG2(_("E789: Missing ']': %s"), kw); |
168 | 4760 kw = p + 2; /* skip over the NUL */ |
154 | 4761 break; |
168 | 4762 } |
4763 if (p[1] == ']') | |
4764 { | |
4765 kw = p + 1; /* skip over the "]" */ | |
4766 break; | |
4767 } | |
154 | 4768 #ifdef FEAT_MBYTE |
4769 if (has_mbyte) | |
7 | 4770 { |
474 | 4771 int l = (*mb_ptr2len)(p + 1); |
154 | 4772 |
4773 mch_memmove(p, p + 1, l); | |
4774 p += l; | |
4775 } | |
4776 else | |
7 | 4777 #endif |
154 | 4778 { |
4779 p[0] = p[1]; | |
4780 ++p; | |
7 | 4781 } |
4782 } | |
4783 } | |
4784 } | |
154 | 4785 |
7 | 4786 vim_free(keyword_copy); |
168 | 4787 vim_free(syn_opt_arg.cont_in_list); |
4788 vim_free(syn_opt_arg.next_list); | |
7 | 4789 } |
4790 } | |
4791 | |
4792 if (rest != NULL) | |
4793 eap->nextcmd = check_nextcmd(rest); | |
4794 else | |
4795 EMSG2(_(e_invarg2), arg); | |
4796 | |
745 | 4797 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4798 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 4799 } |
4800 | |
4801 /* | |
4802 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". | |
4803 * | |
4804 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." | |
4805 */ | |
4806 static void | |
4807 syn_cmd_match(eap, syncing) | |
4808 exarg_T *eap; | |
4809 int syncing; /* TRUE for ":syntax sync match .. " */ | |
4810 { | |
4811 char_u *arg = eap->arg; | |
4812 char_u *group_name_end; | |
4813 char_u *rest; | |
4814 synpat_T item; /* the item found in the line */ | |
4815 int syn_id; | |
4816 int idx; | |
154 | 4817 syn_opt_arg_T syn_opt_arg; |
7 | 4818 int sync_idx = 0; |
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 /* Isolate the group name, check for validity */ | |
4822 rest = get_group_name(arg, &group_name_end); | |
4823 | |
4824 /* Get options before the pattern */ | |
154 | 4825 syn_opt_arg.flags = 0; |
4826 syn_opt_arg.keyword = FALSE; | |
4827 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; | |
4828 syn_opt_arg.has_cont_list = TRUE; | |
4829 syn_opt_arg.cont_list = NULL; | |
4830 syn_opt_arg.cont_in_list = NULL; | |
4831 syn_opt_arg.next_list = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4832 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); |
7 | 4833 |
4834 /* get the pattern. */ | |
4835 init_syn_patterns(); | |
4836 vim_memset(&item, 0, sizeof(item)); | |
4837 rest = get_syn_pattern(rest, &item); | |
154 | 4838 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
4839 syn_opt_arg.flags |= HL_HAS_EOL; | |
7 | 4840 |
4841 /* Get options after the pattern */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4842 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); |
7 | 4843 |
4844 if (rest != NULL) /* all arguments are valid */ | |
4845 { | |
4846 /* | |
4847 * Check for trailing command and illegal trailing arguments. | |
4848 */ | |
4849 eap->nextcmd = check_nextcmd(rest); | |
4850 if (!ends_excmd(*rest) || eap->skip) | |
4851 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4852 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL |
7 | 4853 && (syn_id = syn_check_group(arg, |
4854 (int)(group_name_end - arg))) != 0) | |
4855 { | |
154 | 4856 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 4857 /* |
4858 * Store the pattern in the syn_items list | |
4859 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4860 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
|
4861 SYN_ITEMS(curwin->w_s)[idx] = item; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4862 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
|
4863 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
|
4864 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
|
4865 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
|
4866 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
|
4867 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
|
4868 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
|
4869 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 4870 syn_opt_arg.cont_in_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4871 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4872 SYN_ITEMS(curwin->w_s)[idx].sp_char = conceal_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4873 #endif |
154 | 4874 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
|
4875 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4876 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
|
4877 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 4878 |
4879 /* remember that we found a match for syncing on */ | |
154 | 4880 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
|
4881 curwin->w_s->b_syn_sync_flags |= SF_MATCH; |
7 | 4882 #ifdef FEAT_FOLDING |
154 | 4883 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
|
4884 ++curwin->w_s->b_syn_folditems; |
7 | 4885 #endif |
4886 | |
745 | 4887 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4888 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 4889 return; /* don't free the progs and patterns now */ |
4890 } | |
4891 } | |
4892 | |
4893 /* | |
4894 * Something failed, free the allocated memory. | |
4895 */ | |
4896 vim_free(item.sp_prog); | |
4897 vim_free(item.sp_pattern); | |
154 | 4898 vim_free(syn_opt_arg.cont_list); |
4899 vim_free(syn_opt_arg.cont_in_list); | |
4900 vim_free(syn_opt_arg.next_list); | |
7 | 4901 |
4902 if (rest == NULL) | |
4903 EMSG2(_(e_invarg2), arg); | |
4904 } | |
4905 | |
4906 /* | |
4907 * Handle ":syntax region {group-name} [matchgroup={group-name}] | |
4908 * start {start} .. [skip {skip}] end {end} .. [{options}]". | |
4909 */ | |
4910 static void | |
4911 syn_cmd_region(eap, syncing) | |
4912 exarg_T *eap; | |
4913 int syncing; /* TRUE for ":syntax sync region .." */ | |
4914 { | |
4915 char_u *arg = eap->arg; | |
4916 char_u *group_name_end; | |
4917 char_u *rest; /* next arg, NULL on error */ | |
4918 char_u *key_end; | |
4919 char_u *key = NULL; | |
4920 char_u *p; | |
4921 int item; | |
4922 #define ITEM_START 0 | |
4923 #define ITEM_SKIP 1 | |
4924 #define ITEM_END 2 | |
4925 #define ITEM_MATCHGROUP 3 | |
4926 struct pat_ptr | |
4927 { | |
4928 synpat_T *pp_synp; /* pointer to syn_pattern */ | |
4929 int pp_matchgroup_id; /* matchgroup ID */ | |
4930 struct pat_ptr *pp_next; /* pointer to next pat_ptr */ | |
4931 } *(pat_ptrs[3]); | |
4932 /* patterns found in the line */ | |
4933 struct pat_ptr *ppp; | |
4934 struct pat_ptr *ppp_next; | |
4935 int pat_count = 0; /* nr of syn_patterns found */ | |
4936 int syn_id; | |
4937 int matchgroup_id = 0; | |
4938 int not_enough = FALSE; /* not enough arguments */ | |
4939 int illegal = FALSE; /* illegal arguments */ | |
4940 int success = FALSE; | |
4941 int idx; | |
154 | 4942 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
|
4943 int conceal_char = NUL; |
7 | 4944 |
4945 /* Isolate the group name, check for validity */ | |
4946 rest = get_group_name(arg, &group_name_end); | |
4947 | |
4948 pat_ptrs[0] = NULL; | |
4949 pat_ptrs[1] = NULL; | |
4950 pat_ptrs[2] = NULL; | |
4951 | |
4952 init_syn_patterns(); | |
4953 | |
154 | 4954 syn_opt_arg.flags = 0; |
4955 syn_opt_arg.keyword = FALSE; | |
4956 syn_opt_arg.sync_idx = NULL; | |
4957 syn_opt_arg.has_cont_list = TRUE; | |
4958 syn_opt_arg.cont_list = NULL; | |
4959 syn_opt_arg.cont_in_list = NULL; | |
4960 syn_opt_arg.next_list = NULL; | |
4961 | |
7 | 4962 /* |
4963 * get the options, patterns and matchgroup. | |
4964 */ | |
4965 while (rest != NULL && !ends_excmd(*rest)) | |
4966 { | |
4967 /* Check for option arguments */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4968 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char); |
7 | 4969 if (rest == NULL || ends_excmd(*rest)) |
4970 break; | |
4971 | |
4972 /* must be a pattern or matchgroup then */ | |
4973 key_end = rest; | |
4974 while (*key_end && !vim_iswhite(*key_end) && *key_end != '=') | |
4975 ++key_end; | |
4976 vim_free(key); | |
4977 key = vim_strnsave_up(rest, (int)(key_end - rest)); | |
4978 if (key == NULL) /* out of memory */ | |
4979 { | |
4980 rest = NULL; | |
4981 break; | |
4982 } | |
4983 if (STRCMP(key, "MATCHGROUP") == 0) | |
4984 item = ITEM_MATCHGROUP; | |
4985 else if (STRCMP(key, "START") == 0) | |
4986 item = ITEM_START; | |
4987 else if (STRCMP(key, "END") == 0) | |
4988 item = ITEM_END; | |
4989 else if (STRCMP(key, "SKIP") == 0) | |
4990 { | |
4991 if (pat_ptrs[ITEM_SKIP] != NULL) /* one skip pattern allowed */ | |
4992 { | |
4993 illegal = TRUE; | |
4994 break; | |
4995 } | |
4996 item = ITEM_SKIP; | |
4997 } | |
4998 else | |
4999 break; | |
5000 rest = skipwhite(key_end); | |
5001 if (*rest != '=') | |
5002 { | |
5003 rest = NULL; | |
5004 EMSG2(_("E398: Missing '=': %s"), arg); | |
5005 break; | |
5006 } | |
5007 rest = skipwhite(rest + 1); | |
5008 if (*rest == NUL) | |
5009 { | |
5010 not_enough = TRUE; | |
5011 break; | |
5012 } | |
5013 | |
5014 if (item == ITEM_MATCHGROUP) | |
5015 { | |
5016 p = skiptowhite(rest); | |
5017 if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) | |
5018 matchgroup_id = 0; | |
5019 else | |
5020 { | |
5021 matchgroup_id = syn_check_group(rest, (int)(p - rest)); | |
5022 if (matchgroup_id == 0) | |
5023 { | |
5024 illegal = TRUE; | |
5025 break; | |
5026 } | |
5027 } | |
5028 rest = skipwhite(p); | |
5029 } | |
5030 else | |
5031 { | |
5032 /* | |
5033 * Allocate room for a syn_pattern, and link it in the list of | |
5034 * syn_patterns for this item, at the start (because the list is | |
5035 * used from end to start). | |
5036 */ | |
5037 ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr)); | |
5038 if (ppp == NULL) | |
5039 { | |
5040 rest = NULL; | |
5041 break; | |
5042 } | |
5043 ppp->pp_next = pat_ptrs[item]; | |
5044 pat_ptrs[item] = ppp; | |
5045 ppp->pp_synp = (synpat_T *)alloc_clear((unsigned)sizeof(synpat_T)); | |
5046 if (ppp->pp_synp == NULL) | |
5047 { | |
5048 rest = NULL; | |
5049 break; | |
5050 } | |
5051 | |
5052 /* | |
5053 * Get the syntax pattern and the following offset(s). | |
5054 */ | |
5055 /* Enable the appropriate \z specials. */ | |
5056 if (item == ITEM_START) | |
5057 reg_do_extmatch = REX_SET; | |
5058 else if (item == ITEM_SKIP || item == ITEM_END) | |
5059 reg_do_extmatch = REX_USE; | |
5060 rest = get_syn_pattern(rest, ppp->pp_synp); | |
5061 reg_do_extmatch = 0; | |
5062 if (item == ITEM_END && vim_regcomp_had_eol() | |
154 | 5063 && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
7 | 5064 ppp->pp_synp->sp_flags |= HL_HAS_EOL; |
5065 ppp->pp_matchgroup_id = matchgroup_id; | |
5066 ++pat_count; | |
5067 } | |
5068 } | |
5069 vim_free(key); | |
5070 if (illegal || not_enough) | |
5071 rest = NULL; | |
5072 | |
5073 /* | |
5074 * Must have a "start" and "end" pattern. | |
5075 */ | |
5076 if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || | |
5077 pat_ptrs[ITEM_END] == NULL)) | |
5078 { | |
5079 not_enough = TRUE; | |
5080 rest = NULL; | |
5081 } | |
5082 | |
5083 if (rest != NULL) | |
5084 { | |
5085 /* | |
5086 * Check for trailing garbage or command. | |
5087 * If OK, add the item. | |
5088 */ | |
5089 eap->nextcmd = check_nextcmd(rest); | |
5090 if (!ends_excmd(*rest) || eap->skip) | |
5091 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5092 else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL |
7 | 5093 && (syn_id = syn_check_group(arg, |
5094 (int)(group_name_end - arg))) != 0) | |
5095 { | |
154 | 5096 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5097 /* |
5098 * Store the start/skip/end in the syn_items list | |
5099 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5100 idx = curwin->w_s->b_syn_patterns.ga_len; |
7 | 5101 for (item = ITEM_START; item <= ITEM_END; ++item) |
5102 { | |
5103 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) | |
5104 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5105 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
|
5106 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
|
5107 SYN_ITEMS(curwin->w_s)[idx].sp_type = |
7 | 5108 (item == ITEM_START) ? SPTYPE_START : |
5109 (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
|
5110 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
|
5111 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
|
5112 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
|
5113 SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = |
7 | 5114 ppp->pp_matchgroup_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5115 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5116 SYN_ITEMS(curwin->w_s)[idx].sp_char = conceal_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5117 #endif |
7 | 5118 if (item == ITEM_START) |
5119 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5120 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = |
154 | 5121 syn_opt_arg.cont_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5122 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5123 syn_opt_arg.cont_in_list; |
5124 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
|
5125 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5126 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = |
154 | 5127 syn_opt_arg.next_list; |
7 | 5128 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5129 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5130 ++idx; |
5131 #ifdef FEAT_FOLDING | |
154 | 5132 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
|
5133 ++curwin->w_s->b_syn_folditems; |
7 | 5134 #endif |
5135 } | |
5136 } | |
5137 | |
745 | 5138 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5139 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5140 success = TRUE; /* don't free the progs and patterns now */ |
5141 } | |
5142 } | |
5143 | |
5144 /* | |
5145 * Free the allocated memory. | |
5146 */ | |
5147 for (item = ITEM_START; item <= ITEM_END; ++item) | |
5148 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) | |
5149 { | |
5150 if (!success) | |
5151 { | |
5152 vim_free(ppp->pp_synp->sp_prog); | |
5153 vim_free(ppp->pp_synp->sp_pattern); | |
5154 } | |
5155 vim_free(ppp->pp_synp); | |
5156 ppp_next = ppp->pp_next; | |
5157 vim_free(ppp); | |
5158 } | |
5159 | |
5160 if (!success) | |
5161 { | |
154 | 5162 vim_free(syn_opt_arg.cont_list); |
5163 vim_free(syn_opt_arg.cont_in_list); | |
5164 vim_free(syn_opt_arg.next_list); | |
7 | 5165 if (not_enough) |
5166 EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); | |
5167 else if (illegal || rest == NULL) | |
5168 EMSG2(_(e_invarg2), arg); | |
5169 } | |
5170 } | |
5171 | |
5172 /* | |
5173 * A simple syntax group ID comparison function suitable for use in qsort() | |
5174 */ | |
5175 static int | |
5176 #ifdef __BORLANDC__ | |
5177 _RTLENTRYF | |
5178 #endif | |
5179 syn_compare_stub(v1, v2) | |
5180 const void *v1; | |
5181 const void *v2; | |
5182 { | |
5183 const short *s1 = v1; | |
5184 const short *s2 = v2; | |
5185 | |
5186 return (*s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0); | |
5187 } | |
5188 | |
5189 /* | |
5190 * Combines lists of syntax clusters. | |
5191 * *clstr1 and *clstr2 must both be allocated memory; they will be consumed. | |
5192 */ | |
5193 static void | |
5194 syn_combine_list(clstr1, clstr2, list_op) | |
5195 short **clstr1; | |
5196 short **clstr2; | |
5197 int list_op; | |
5198 { | |
5199 int count1 = 0; | |
5200 int count2 = 0; | |
5201 short *g1; | |
5202 short *g2; | |
5203 short *clstr = NULL; | |
5204 int count; | |
5205 int round; | |
5206 | |
5207 /* | |
5208 * Handle degenerate cases. | |
5209 */ | |
5210 if (*clstr2 == NULL) | |
5211 return; | |
5212 if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) | |
5213 { | |
5214 if (list_op == CLUSTER_REPLACE) | |
5215 vim_free(*clstr1); | |
5216 if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) | |
5217 *clstr1 = *clstr2; | |
5218 else | |
5219 vim_free(*clstr2); | |
5220 return; | |
5221 } | |
5222 | |
5223 for (g1 = *clstr1; *g1; g1++) | |
5224 ++count1; | |
5225 for (g2 = *clstr2; *g2; g2++) | |
5226 ++count2; | |
5227 | |
5228 /* | |
5229 * For speed purposes, sort both lists. | |
5230 */ | |
5231 qsort(*clstr1, (size_t)count1, sizeof(short), syn_compare_stub); | |
5232 qsort(*clstr2, (size_t)count2, sizeof(short), syn_compare_stub); | |
5233 | |
5234 /* | |
5235 * We proceed in two passes; in round 1, we count the elements to place | |
5236 * in the new list, and in round 2, we allocate and populate the new | |
5237 * list. For speed, we use a mergesort-like method, adding the smaller | |
5238 * of the current elements in each list to the new list. | |
5239 */ | |
5240 for (round = 1; round <= 2; round++) | |
5241 { | |
5242 g1 = *clstr1; | |
5243 g2 = *clstr2; | |
5244 count = 0; | |
5245 | |
5246 /* | |
5247 * First, loop through the lists until one of them is empty. | |
5248 */ | |
5249 while (*g1 && *g2) | |
5250 { | |
5251 /* | |
5252 * We always want to add from the first list. | |
5253 */ | |
5254 if (*g1 < *g2) | |
5255 { | |
5256 if (round == 2) | |
5257 clstr[count] = *g1; | |
5258 count++; | |
5259 g1++; | |
5260 continue; | |
5261 } | |
5262 /* | |
5263 * We only want to add from the second list if we're adding the | |
5264 * lists. | |
5265 */ | |
5266 if (list_op == CLUSTER_ADD) | |
5267 { | |
5268 if (round == 2) | |
5269 clstr[count] = *g2; | |
5270 count++; | |
5271 } | |
5272 if (*g1 == *g2) | |
5273 g1++; | |
5274 g2++; | |
5275 } | |
5276 | |
5277 /* | |
5278 * Now add the leftovers from whichever list didn't get finished | |
5279 * first. As before, we only want to add from the second list if | |
5280 * we're adding the lists. | |
5281 */ | |
5282 for (; *g1; g1++, count++) | |
5283 if (round == 2) | |
5284 clstr[count] = *g1; | |
5285 if (list_op == CLUSTER_ADD) | |
5286 for (; *g2; g2++, count++) | |
5287 if (round == 2) | |
5288 clstr[count] = *g2; | |
5289 | |
5290 if (round == 1) | |
5291 { | |
5292 /* | |
5293 * If the group ended up empty, we don't need to allocate any | |
5294 * space for it. | |
5295 */ | |
5296 if (count == 0) | |
5297 { | |
5298 clstr = NULL; | |
5299 break; | |
5300 } | |
5301 clstr = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
5302 if (clstr == NULL) | |
5303 break; | |
5304 clstr[count] = 0; | |
5305 } | |
5306 } | |
5307 | |
5308 /* | |
5309 * Finally, put the new list in place. | |
5310 */ | |
5311 vim_free(*clstr1); | |
5312 vim_free(*clstr2); | |
5313 *clstr1 = clstr; | |
5314 } | |
5315 | |
5316 /* | |
5317 * Lookup a syntax cluster name and return it's ID. | |
5318 * If it is not found, 0 is returned. | |
5319 */ | |
5320 static int | |
5321 syn_scl_name2id(name) | |
5322 char_u *name; | |
5323 { | |
5324 int i; | |
5325 char_u *name_u; | |
5326 | |
5327 /* Avoid using stricmp() too much, it's slow on some systems */ | |
5328 name_u = vim_strsave_up(name); | |
5329 if (name_u == NULL) | |
5330 return 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5331 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
|
5332 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
|
5333 && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) |
7 | 5334 break; |
5335 vim_free(name_u); | |
5336 return (i < 0 ? 0 : i + SYNID_CLUSTER); | |
5337 } | |
5338 | |
5339 /* | |
5340 * Like syn_scl_name2id(), but take a pointer + length argument. | |
5341 */ | |
5342 static int | |
5343 syn_scl_namen2id(linep, len) | |
5344 char_u *linep; | |
5345 int len; | |
5346 { | |
5347 char_u *name; | |
5348 int id = 0; | |
5349 | |
5350 name = vim_strnsave(linep, len); | |
5351 if (name != NULL) | |
5352 { | |
5353 id = syn_scl_name2id(name); | |
5354 vim_free(name); | |
5355 } | |
5356 return id; | |
5357 } | |
5358 | |
5359 /* | |
5360 * Find syntax cluster name in the table and return it's ID. | |
5361 * The argument is a pointer to the name and the length of the name. | |
5362 * If it doesn't exist yet, a new entry is created. | |
5363 * Return 0 for failure. | |
5364 */ | |
5365 static int | |
5366 syn_check_cluster(pp, len) | |
5367 char_u *pp; | |
5368 int len; | |
5369 { | |
5370 int id; | |
5371 char_u *name; | |
5372 | |
5373 name = vim_strnsave(pp, len); | |
5374 if (name == NULL) | |
5375 return 0; | |
5376 | |
5377 id = syn_scl_name2id(name); | |
5378 if (id == 0) /* doesn't exist yet */ | |
5379 id = syn_add_cluster(name); | |
5380 else | |
5381 vim_free(name); | |
5382 return id; | |
5383 } | |
5384 | |
5385 /* | |
5386 * Add new syntax cluster and return it's ID. | |
5387 * "name" must be an allocated string, it will be consumed. | |
5388 * Return 0 for failure. | |
5389 */ | |
5390 static int | |
5391 syn_add_cluster(name) | |
221 | 5392 char_u *name; |
5393 { | |
5394 int len; | |
7 | 5395 |
5396 /* | |
5397 * First call for this growarray: init growing array. | |
5398 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5399 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
|
5400 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5401 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
|
5402 curwin->w_s->b_syn_clusters.ga_growsize = 10; |
7 | 5403 } |
5404 | |
5405 /* | |
5406 * Make room for at least one other cluster entry. | |
5407 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5408 if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) |
7 | 5409 { |
5410 vim_free(name); | |
5411 return 0; | |
5412 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5413 len = curwin->w_s->b_syn_clusters.ga_len; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5414 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5415 vim_memset(&(SYN_CLSTR(curwin->w_s)[len]), 0, sizeof(syn_cluster_T)); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5416 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
|
5417 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
|
5418 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
|
5419 ++curwin->w_s->b_syn_clusters.ga_len; |
7 | 5420 |
221 | 5421 if (STRICMP(name, "Spell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5422 curwin->w_s->b_spell_cluster_id = len + SYNID_CLUSTER; |
227 | 5423 if (STRICMP(name, "NoSpell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5424 curwin->w_s->b_nospell_cluster_id = len + SYNID_CLUSTER; |
221 | 5425 |
7 | 5426 return len + SYNID_CLUSTER; |
5427 } | |
5428 | |
5429 /* | |
5430 * Handle ":syntax cluster {cluster-name} [contains={groupname},..] | |
5431 * [add={groupname},..] [remove={groupname},..]". | |
5432 */ | |
5433 static void | |
5434 syn_cmd_cluster(eap, syncing) | |
5435 exarg_T *eap; | |
1883 | 5436 int syncing UNUSED; |
7 | 5437 { |
5438 char_u *arg = eap->arg; | |
5439 char_u *group_name_end; | |
5440 char_u *rest; | |
5441 int scl_id; | |
5442 short *clstr_list; | |
5443 int got_clstr = FALSE; | |
5444 int opt_len; | |
5445 int list_op; | |
5446 | |
5447 eap->nextcmd = find_nextcmd(arg); | |
5448 if (eap->skip) | |
5449 return; | |
5450 | |
5451 rest = get_group_name(arg, &group_name_end); | |
5452 | |
5453 if (rest != NULL) | |
5454 { | |
5455 scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)) | |
221 | 5456 - SYNID_CLUSTER; |
7 | 5457 |
5458 for (;;) | |
5459 { | |
5460 if (STRNICMP(rest, "add", 3) == 0 | |
5461 && (vim_iswhite(rest[3]) || rest[3] == '=')) | |
5462 { | |
5463 opt_len = 3; | |
5464 list_op = CLUSTER_ADD; | |
5465 } | |
5466 else if (STRNICMP(rest, "remove", 6) == 0 | |
5467 && (vim_iswhite(rest[6]) || rest[6] == '=')) | |
5468 { | |
5469 opt_len = 6; | |
5470 list_op = CLUSTER_SUBTRACT; | |
5471 } | |
5472 else if (STRNICMP(rest, "contains", 8) == 0 | |
5473 && (vim_iswhite(rest[8]) || rest[8] == '=')) | |
5474 { | |
5475 opt_len = 8; | |
5476 list_op = CLUSTER_REPLACE; | |
5477 } | |
5478 else | |
5479 break; | |
5480 | |
5481 clstr_list = NULL; | |
5482 if (get_id_list(&rest, opt_len, &clstr_list) == FAIL) | |
5483 { | |
5484 EMSG2(_(e_invarg2), rest); | |
5485 break; | |
5486 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5487 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, |
7 | 5488 &clstr_list, list_op); |
5489 got_clstr = TRUE; | |
5490 } | |
5491 | |
5492 if (got_clstr) | |
5493 { | |
745 | 5494 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5495 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5496 } |
5497 } | |
5498 | |
5499 if (!got_clstr) | |
5500 EMSG(_("E400: No cluster specified")); | |
5501 if (rest == NULL || !ends_excmd(*rest)) | |
5502 EMSG2(_(e_invarg2), arg); | |
5503 } | |
5504 | |
5505 /* | |
5506 * On first call for current buffer: Init growing array. | |
5507 */ | |
5508 static void | |
5509 init_syn_patterns() | |
5510 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5511 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
|
5512 curwin->w_s->b_syn_patterns.ga_growsize = 10; |
7 | 5513 } |
5514 | |
5515 /* | |
5516 * Get one pattern for a ":syntax match" or ":syntax region" command. | |
5517 * Stores the pattern and program in a synpat_T. | |
5518 * Returns a pointer to the next argument, or NULL in case of an error. | |
5519 */ | |
5520 static char_u * | |
5521 get_syn_pattern(arg, ci) | |
5522 char_u *arg; | |
5523 synpat_T *ci; | |
5524 { | |
5525 char_u *end; | |
5526 int *p; | |
5527 int idx; | |
5528 char_u *cpo_save; | |
5529 | |
5530 /* need at least three chars */ | |
5531 if (arg == NULL || arg[1] == NUL || arg[2] == NUL) | |
5532 return NULL; | |
5533 | |
5534 end = skip_regexp(arg + 1, *arg, TRUE, NULL); | |
5535 if (*end != *arg) /* end delimiter not found */ | |
5536 { | |
5537 EMSG2(_("E401: Pattern delimiter not found: %s"), arg); | |
5538 return NULL; | |
5539 } | |
5540 /* store the pattern and compiled regexp program */ | |
5541 if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL) | |
5542 return NULL; | |
5543 | |
5544 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5545 cpo_save = p_cpo; | |
5546 p_cpo = (char_u *)""; | |
5547 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); | |
5548 p_cpo = cpo_save; | |
5549 | |
5550 if (ci->sp_prog == NULL) | |
5551 return NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5552 ci->sp_ic = curwin->w_s->b_syn_ic; |
7 | 5553 |
5554 /* | |
5555 * Check for a match, highlight or region offset. | |
5556 */ | |
5557 ++end; | |
5558 do | |
5559 { | |
5560 for (idx = SPO_COUNT; --idx >= 0; ) | |
5561 if (STRNCMP(end, spo_name_tab[idx], 3) == 0) | |
5562 break; | |
5563 if (idx >= 0) | |
5564 { | |
5565 p = &(ci->sp_offsets[idx]); | |
5566 if (idx != SPO_LC_OFF) | |
5567 switch (end[3]) | |
5568 { | |
5569 case 's': break; | |
5570 case 'b': break; | |
5571 case 'e': idx += SPO_COUNT; break; | |
5572 default: idx = -1; break; | |
5573 } | |
5574 if (idx >= 0) | |
5575 { | |
5576 ci->sp_off_flags |= (1 << idx); | |
5577 if (idx == SPO_LC_OFF) /* lc=99 */ | |
5578 { | |
5579 end += 3; | |
5580 *p = getdigits(&end); | |
5581 | |
5582 /* "lc=" offset automatically sets "ms=" offset */ | |
5583 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) | |
5584 { | |
5585 ci->sp_off_flags |= (1 << SPO_MS_OFF); | |
5586 ci->sp_offsets[SPO_MS_OFF] = *p; | |
5587 } | |
5588 } | |
5589 else /* yy=x+99 */ | |
5590 { | |
5591 end += 4; | |
5592 if (*end == '+') | |
5593 { | |
5594 ++end; | |
5595 *p = getdigits(&end); /* positive offset */ | |
5596 } | |
5597 else if (*end == '-') | |
5598 { | |
5599 ++end; | |
5600 *p = -getdigits(&end); /* negative offset */ | |
5601 } | |
5602 } | |
5603 if (*end != ',') | |
5604 break; | |
5605 ++end; | |
5606 } | |
5607 } | |
5608 } while (idx >= 0); | |
5609 | |
5610 if (!ends_excmd(*end) && !vim_iswhite(*end)) | |
5611 { | |
5612 EMSG2(_("E402: Garbage after pattern: %s"), arg); | |
5613 return NULL; | |
5614 } | |
5615 return skipwhite(end); | |
5616 } | |
5617 | |
5618 /* | |
5619 * Handle ":syntax sync .." command. | |
5620 */ | |
5621 static void | |
5622 syn_cmd_sync(eap, syncing) | |
5623 exarg_T *eap; | |
1883 | 5624 int syncing UNUSED; |
7 | 5625 { |
5626 char_u *arg_start = eap->arg; | |
5627 char_u *arg_end; | |
5628 char_u *key = NULL; | |
5629 char_u *next_arg; | |
5630 int illegal = FALSE; | |
5631 int finished = FALSE; | |
5632 long n; | |
5633 char_u *cpo_save; | |
5634 | |
5635 if (ends_excmd(*arg_start)) | |
5636 { | |
5637 syn_cmd_list(eap, TRUE); | |
5638 return; | |
5639 } | |
5640 | |
5641 while (!ends_excmd(*arg_start)) | |
5642 { | |
5643 arg_end = skiptowhite(arg_start); | |
5644 next_arg = skipwhite(arg_end); | |
5645 vim_free(key); | |
5646 key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); | |
5647 if (STRCMP(key, "CCOMMENT") == 0) | |
5648 { | |
5649 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5650 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; |
7 | 5651 if (!ends_excmd(*next_arg)) |
5652 { | |
5653 arg_end = skiptowhite(next_arg); | |
5654 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5655 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, |
7 | 5656 (int)(arg_end - next_arg)); |
5657 next_arg = skipwhite(arg_end); | |
5658 } | |
5659 else if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5660 curwin->w_s->b_syn_sync_id = syn_name2id((char_u *)"Comment"); |
7 | 5661 } |
5662 else if ( STRNCMP(key, "LINES", 5) == 0 | |
5663 || STRNCMP(key, "MINLINES", 8) == 0 | |
5664 || STRNCMP(key, "MAXLINES", 8) == 0 | |
5665 || STRNCMP(key, "LINEBREAKS", 10) == 0) | |
5666 { | |
5667 if (key[4] == 'S') | |
5668 arg_end = key + 6; | |
5669 else if (key[0] == 'L') | |
5670 arg_end = key + 11; | |
5671 else | |
5672 arg_end = key + 9; | |
5673 if (arg_end[-1] != '=' || !VIM_ISDIGIT(*arg_end)) | |
5674 { | |
5675 illegal = TRUE; | |
5676 break; | |
5677 } | |
5678 n = getdigits(&arg_end); | |
5679 if (!eap->skip) | |
5680 { | |
5681 if (key[4] == 'B') | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5682 curwin->w_s->b_syn_sync_linebreaks = n; |
7 | 5683 else if (key[1] == 'A') |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5684 curwin->w_s->b_syn_sync_maxlines = n; |
7 | 5685 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5686 curwin->w_s->b_syn_sync_minlines = n; |
7 | 5687 } |
5688 } | |
5689 else if (STRCMP(key, "FROMSTART") == 0) | |
5690 { | |
5691 if (!eap->skip) | |
5692 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5693 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
|
5694 curwin->w_s->b_syn_sync_maxlines = 0; |
7 | 5695 } |
5696 } | |
5697 else if (STRCMP(key, "LINECONT") == 0) | |
5698 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5699 if (curwin->w_s->b_syn_linecont_pat != NULL) |
7 | 5700 { |
5701 EMSG(_("E403: syntax sync: line continuations pattern specified twice")); | |
5702 finished = TRUE; | |
5703 break; | |
5704 } | |
5705 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE, NULL); | |
5706 if (*arg_end != *next_arg) /* end delimiter not found */ | |
5707 { | |
5708 illegal = TRUE; | |
5709 break; | |
5710 } | |
5711 | |
5712 if (!eap->skip) | |
5713 { | |
5714 /* store the pattern and compiled regexp program */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5715 if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1, |
7 | 5716 (int)(arg_end - next_arg - 1))) == NULL) |
5717 { | |
5718 finished = TRUE; | |
5719 break; | |
5720 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5721 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; |
7 | 5722 |
5723 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5724 cpo_save = p_cpo; | |
5725 p_cpo = (char_u *)""; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5726 curwin->w_s->b_syn_linecont_prog = |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5727 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); |
7 | 5728 p_cpo = cpo_save; |
5729 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5730 if (curwin->w_s->b_syn_linecont_prog == NULL) |
7 | 5731 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5732 vim_free(curwin->w_s->b_syn_linecont_pat); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5733 curwin->w_s->b_syn_linecont_pat = NULL; |
7 | 5734 finished = TRUE; |
5735 break; | |
5736 } | |
5737 } | |
5738 next_arg = skipwhite(arg_end + 1); | |
5739 } | |
5740 else | |
5741 { | |
5742 eap->arg = next_arg; | |
5743 if (STRCMP(key, "MATCH") == 0) | |
5744 syn_cmd_match(eap, TRUE); | |
5745 else if (STRCMP(key, "REGION") == 0) | |
5746 syn_cmd_region(eap, TRUE); | |
5747 else if (STRCMP(key, "CLEAR") == 0) | |
5748 syn_cmd_clear(eap, TRUE); | |
5749 else | |
5750 illegal = TRUE; | |
5751 finished = TRUE; | |
5752 break; | |
5753 } | |
5754 arg_start = next_arg; | |
5755 } | |
5756 vim_free(key); | |
5757 if (illegal) | |
5758 EMSG2(_("E404: Illegal arguments: %s"), arg_start); | |
5759 else if (!finished) | |
5760 { | |
5761 eap->nextcmd = check_nextcmd(arg_start); | |
745 | 5762 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5763 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5764 } |
5765 } | |
5766 | |
5767 /* | |
5768 * Convert a line of highlight group names into a list of group ID numbers. | |
5769 * "arg" should point to the "contains" or "nextgroup" keyword. | |
5770 * "arg" is advanced to after the last group name. | |
5771 * Careful: the argument is modified (NULs added). | |
5772 * returns FAIL for some error, OK for success. | |
5773 */ | |
5774 static int | |
5775 get_id_list(arg, keylen, list) | |
5776 char_u **arg; | |
5777 int keylen; /* length of keyword */ | |
5778 short **list; /* where to store the resulting list, if not | |
5779 NULL, the list is silently skipped! */ | |
5780 { | |
5781 char_u *p = NULL; | |
5782 char_u *end; | |
5783 int round; | |
5784 int count; | |
5785 int total_count = 0; | |
5786 short *retval = NULL; | |
5787 char_u *name; | |
5788 regmatch_T regmatch; | |
5789 int id; | |
5790 int i; | |
5791 int failed = FALSE; | |
5792 | |
5793 /* | |
5794 * We parse the list twice: | |
5795 * round == 1: count the number of items, allocate the array. | |
5796 * round == 2: fill the array with the items. | |
5797 * In round 1 new groups may be added, causing the number of items to | |
5798 * grow when a regexp is used. In that case round 1 is done once again. | |
5799 */ | |
5800 for (round = 1; round <= 2; ++round) | |
5801 { | |
5802 /* | |
5803 * skip "contains" | |
5804 */ | |
5805 p = skipwhite(*arg + keylen); | |
5806 if (*p != '=') | |
5807 { | |
5808 EMSG2(_("E405: Missing equal sign: %s"), *arg); | |
5809 break; | |
5810 } | |
5811 p = skipwhite(p + 1); | |
5812 if (ends_excmd(*p)) | |
5813 { | |
5814 EMSG2(_("E406: Empty argument: %s"), *arg); | |
5815 break; | |
5816 } | |
5817 | |
5818 /* | |
5819 * parse the arguments after "contains" | |
5820 */ | |
5821 count = 0; | |
5822 while (!ends_excmd(*p)) | |
5823 { | |
5824 for (end = p; *end && !vim_iswhite(*end) && *end != ','; ++end) | |
5825 ; | |
5826 name = alloc((int)(end - p + 3)); /* leave room for "^$" */ | |
5827 if (name == NULL) | |
5828 { | |
5829 failed = TRUE; | |
5830 break; | |
5831 } | |
419 | 5832 vim_strncpy(name + 1, p, end - p); |
7 | 5833 if ( STRCMP(name + 1, "ALLBUT") == 0 |
5834 || STRCMP(name + 1, "ALL") == 0 | |
5835 || STRCMP(name + 1, "TOP") == 0 | |
5836 || STRCMP(name + 1, "CONTAINED") == 0) | |
5837 { | |
5838 if (TOUPPER_ASC(**arg) != 'C') | |
5839 { | |
5840 EMSG2(_("E407: %s not allowed here"), name + 1); | |
5841 failed = TRUE; | |
5842 vim_free(name); | |
5843 break; | |
5844 } | |
5845 if (count != 0) | |
5846 { | |
5847 EMSG2(_("E408: %s must be first in contains list"), name + 1); | |
5848 failed = TRUE; | |
5849 vim_free(name); | |
5850 break; | |
5851 } | |
5852 if (name[1] == 'A') | |
5853 id = SYNID_ALLBUT; | |
5854 else if (name[1] == 'T') | |
5855 id = SYNID_TOP; | |
5856 else | |
5857 id = SYNID_CONTAINED; | |
5858 id += current_syn_inc_tag; | |
5859 } | |
5860 else if (name[1] == '@') | |
5861 { | |
5862 id = syn_check_cluster(name + 2, (int)(end - p - 1)); | |
5863 } | |
5864 else | |
5865 { | |
5866 /* | |
5867 * Handle full group name. | |
5868 */ | |
5869 if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) | |
5870 id = syn_check_group(name + 1, (int)(end - p)); | |
5871 else | |
5872 { | |
5873 /* | |
5874 * Handle match of regexp with group names. | |
5875 */ | |
5876 *name = '^'; | |
5877 STRCAT(name, "$"); | |
5878 regmatch.regprog = vim_regcomp(name, RE_MAGIC); | |
5879 if (regmatch.regprog == NULL) | |
5880 { | |
5881 failed = TRUE; | |
5882 vim_free(name); | |
5883 break; | |
5884 } | |
5885 | |
5886 regmatch.rm_ic = TRUE; | |
5887 id = 0; | |
5888 for (i = highlight_ga.ga_len; --i >= 0; ) | |
5889 { | |
5890 if (vim_regexec(®match, HL_TABLE()[i].sg_name, | |
5891 (colnr_T)0)) | |
5892 { | |
5893 if (round == 2) | |
5894 { | |
5895 /* Got more items than expected; can happen | |
5896 * when adding items that match: | |
5897 * "contains=a.*b,axb". | |
5898 * Go back to first round */ | |
5899 if (count >= total_count) | |
5900 { | |
5901 vim_free(retval); | |
5902 round = 1; | |
5903 } | |
5904 else | |
5905 retval[count] = i + 1; | |
5906 } | |
5907 ++count; | |
5908 id = -1; /* remember that we found one */ | |
5909 } | |
5910 } | |
5911 vim_free(regmatch.regprog); | |
5912 } | |
5913 } | |
5914 vim_free(name); | |
5915 if (id == 0) | |
5916 { | |
5917 EMSG2(_("E409: Unknown group name: %s"), p); | |
5918 failed = TRUE; | |
5919 break; | |
5920 } | |
5921 if (id > 0) | |
5922 { | |
5923 if (round == 2) | |
5924 { | |
5925 /* Got more items than expected, go back to first round */ | |
5926 if (count >= total_count) | |
5927 { | |
5928 vim_free(retval); | |
5929 round = 1; | |
5930 } | |
5931 else | |
5932 retval[count] = id; | |
5933 } | |
5934 ++count; | |
5935 } | |
5936 p = skipwhite(end); | |
5937 if (*p != ',') | |
5938 break; | |
5939 p = skipwhite(p + 1); /* skip comma in between arguments */ | |
5940 } | |
5941 if (failed) | |
5942 break; | |
5943 if (round == 1) | |
5944 { | |
5945 retval = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
5946 if (retval == NULL) | |
5947 break; | |
5948 retval[count] = 0; /* zero means end of the list */ | |
5949 total_count = count; | |
5950 } | |
5951 } | |
5952 | |
5953 *arg = p; | |
5954 if (failed || retval == NULL) | |
5955 { | |
5956 vim_free(retval); | |
5957 return FAIL; | |
5958 } | |
5959 | |
5960 if (*list == NULL) | |
5961 *list = retval; | |
5962 else | |
5963 vim_free(retval); /* list already found, don't overwrite it */ | |
5964 | |
5965 return OK; | |
5966 } | |
5967 | |
5968 /* | |
5969 * Make a copy of an ID list. | |
5970 */ | |
5971 static short * | |
5972 copy_id_list(list) | |
5973 short *list; | |
5974 { | |
5975 int len; | |
5976 int count; | |
5977 short *retval; | |
5978 | |
5979 if (list == NULL) | |
5980 return NULL; | |
5981 | |
5982 for (count = 0; list[count]; ++count) | |
5983 ; | |
5984 len = (count + 1) * sizeof(short); | |
5985 retval = (short *)alloc((unsigned)len); | |
5986 if (retval != NULL) | |
5987 mch_memmove(retval, list, (size_t)len); | |
5988 | |
5989 return retval; | |
5990 } | |
5991 | |
5992 /* | |
5993 * Check if syntax group "ssp" is in the ID list "list" of "cur_si". | |
5994 * "cur_si" can be NULL if not checking the "containedin" list. | |
5995 * Used to check if a syntax item is in the "contains" or "nextgroup" list of | |
5996 * the current item. | |
5997 * This function is called very often, keep it fast!! | |
5998 */ | |
5999 static int | |
6000 in_id_list(cur_si, list, ssp, contained) | |
6001 stateitem_T *cur_si; /* current item or NULL */ | |
6002 short *list; /* id list */ | |
6003 struct sp_syn *ssp; /* group id and ":syn include" tag of group */ | |
6004 int contained; /* group id is contained */ | |
6005 { | |
6006 int retval; | |
6007 short *scl_list; | |
6008 short item; | |
6009 short id = ssp->id; | |
6010 static int depth = 0; | |
6011 int r; | |
6012 | |
6013 /* If spp has a "containedin" list and "cur_si" is in it, return TRUE. */ | |
36 | 6014 if (cur_si != NULL && ssp->cont_in_list != NULL |
6015 && !(cur_si->si_flags & HL_MATCH)) | |
7 | 6016 { |
6017 /* Ignore transparent items without a contains argument. Double check | |
6018 * that we don't go back past the first one. */ | |
6019 while ((cur_si->si_flags & HL_TRANS_CONT) | |
6020 && cur_si > (stateitem_T *)(current_state.ga_data)) | |
6021 --cur_si; | |
6022 /* cur_si->si_idx is -1 for keywords, these never contain anything. */ | |
6023 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
|
6024 &(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
|
6025 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) |
7 | 6026 return TRUE; |
6027 } | |
6028 | |
6029 if (list == NULL) | |
6030 return FALSE; | |
6031 | |
6032 /* | |
6033 * If list is ID_LIST_ALL, we are in a transparent item that isn't | |
6034 * inside anything. Only allow not-contained groups. | |
6035 */ | |
6036 if (list == ID_LIST_ALL) | |
6037 return !contained; | |
6038 | |
6039 /* | |
6040 * If the first item is "ALLBUT", return TRUE if "id" is NOT in the | |
6041 * contains list. We also require that "id" is at the same ":syn include" | |
6042 * level as the list. | |
6043 */ | |
6044 item = *list; | |
6045 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) | |
6046 { | |
6047 if (item < SYNID_TOP) | |
6048 { | |
6049 /* ALL or ALLBUT: accept all groups in the same file */ | |
6050 if (item - SYNID_ALLBUT != ssp->inc_tag) | |
6051 return FALSE; | |
6052 } | |
6053 else if (item < SYNID_CONTAINED) | |
6054 { | |
6055 /* TOP: accept all not-contained groups in the same file */ | |
6056 if (item - SYNID_TOP != ssp->inc_tag || contained) | |
6057 return FALSE; | |
6058 } | |
6059 else | |
6060 { | |
6061 /* CONTAINED: accept all contained groups in the same file */ | |
6062 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) | |
6063 return FALSE; | |
6064 } | |
6065 item = *++list; | |
6066 retval = FALSE; | |
6067 } | |
6068 else | |
6069 retval = TRUE; | |
6070 | |
6071 /* | |
6072 * Return "retval" if id is in the contains list. | |
6073 */ | |
6074 while (item != 0) | |
6075 { | |
6076 if (item == id) | |
6077 return retval; | |
6078 if (item >= SYNID_CLUSTER) | |
6079 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6080 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; |
7 | 6081 /* restrict recursiveness to 30 to avoid an endless loop for a |
6082 * cluster that includes itself (indirectly) */ | |
6083 if (scl_list != NULL && depth < 30) | |
6084 { | |
6085 ++depth; | |
6086 r = in_id_list(NULL, scl_list, ssp, contained); | |
6087 --depth; | |
6088 if (r) | |
6089 return retval; | |
6090 } | |
6091 } | |
6092 item = *++list; | |
6093 } | |
6094 return !retval; | |
6095 } | |
6096 | |
6097 struct subcommand | |
6098 { | |
6099 char *name; /* subcommand name */ | |
6100 void (*func)__ARGS((exarg_T *, int)); /* function to call */ | |
6101 }; | |
6102 | |
6103 static struct subcommand subcommands[] = | |
6104 { | |
6105 {"case", syn_cmd_case}, | |
6106 {"clear", syn_cmd_clear}, | |
6107 {"cluster", syn_cmd_cluster}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6108 {"conceal", syn_cmd_conceal}, |
7 | 6109 {"enable", syn_cmd_enable}, |
6110 {"include", syn_cmd_include}, | |
6111 {"keyword", syn_cmd_keyword}, | |
6112 {"list", syn_cmd_list}, | |
6113 {"manual", syn_cmd_manual}, | |
6114 {"match", syn_cmd_match}, | |
6115 {"on", syn_cmd_on}, | |
6116 {"off", syn_cmd_off}, | |
6117 {"region", syn_cmd_region}, | |
6118 {"reset", syn_cmd_reset}, | |
419 | 6119 {"spell", syn_cmd_spell}, |
7 | 6120 {"sync", syn_cmd_sync}, |
6121 {"", syn_cmd_list}, | |
6122 {NULL, NULL} | |
6123 }; | |
6124 | |
6125 /* | |
6126 * ":syntax". | |
6127 * This searches the subcommands[] table for the subcommand name, and calls a | |
6128 * syntax_subcommand() function to do the rest. | |
6129 */ | |
6130 void | |
6131 ex_syntax(eap) | |
6132 exarg_T *eap; | |
6133 { | |
6134 char_u *arg = eap->arg; | |
6135 char_u *subcmd_end; | |
6136 char_u *subcmd_name; | |
6137 int i; | |
6138 | |
6139 syn_cmdlinep = eap->cmdlinep; | |
6140 | |
6141 /* isolate subcommand name */ | |
6142 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) | |
6143 ; | |
6144 subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg)); | |
6145 if (subcmd_name != NULL) | |
6146 { | |
6147 if (eap->skip) /* skip error messages for all subcommands */ | |
6148 ++emsg_skip; | |
6149 for (i = 0; ; ++i) | |
6150 { | |
6151 if (subcommands[i].name == NULL) | |
6152 { | |
6153 EMSG2(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); | |
6154 break; | |
6155 } | |
6156 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) | |
6157 { | |
6158 eap->arg = skipwhite(subcmd_end); | |
6159 (subcommands[i].func)(eap, FALSE); | |
6160 break; | |
6161 } | |
6162 } | |
6163 vim_free(subcmd_name); | |
6164 if (eap->skip) | |
6165 --emsg_skip; | |
6166 } | |
6167 } | |
6168 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6169 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6170 ex_ownsyntax(eap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6171 exarg_T *eap; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6172 { |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6173 char_u *old_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6174 char_u *new_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6175 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6176 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
|
6177 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6178 curwin->w_s = (synblock_T *)alloc(sizeof(synblock_T)); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6179 memset(curwin->w_s, 0, sizeof(synblock_T)); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6180 #ifdef FEAT_SPELL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6181 curwin->w_p_spell = FALSE; /* No spell checking */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6182 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
|
6183 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
|
6184 vim_free(curwin->w_s->b_cap_prog); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6185 curwin->w_s->b_cap_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6186 clear_string_option(&curwin->w_s->b_p_spl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6187 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6188 } |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6189 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6190 /* save value of b:current_syntax */ |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6191 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
|
6192 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6193 old_value = vim_strsave(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6194 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6195 /* Apply the "syntax" autocommand event, this finds and loads the syntax |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6196 * file. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6197 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
|
6198 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6199 /* move value of b:current_syntax to w:current_syntax */ |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6200 new_value = get_var_value((char_u *)"b:current_syntax"); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6201 set_internal_string_var((char_u *)"w:current_syntax", new_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6202 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6203 /* restore value of b:current_syntax */ |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6204 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6205 { |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6206 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
|
6207 vim_free(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6208 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6209 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6210 |
7 | 6211 int |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6212 syntax_present(win) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6213 win_T *win; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6214 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6215 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
|
6216 || 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
|
6217 || 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
|
6218 || win->w_s->b_keywtab_ic.ht_used > 0); |
7 | 6219 } |
6220 | |
6221 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
6222 | |
6223 static enum | |
6224 { | |
6225 EXP_SUBCMD, /* expand ":syn" sub-commands */ | |
6226 EXP_CASE /* expand ":syn case" arguments */ | |
6227 } expand_what; | |
6228 | |
1322 | 6229 /* |
6230 * Reset include_link, include_default, include_none to 0. | |
6231 * Called when we are done expanding. | |
6232 */ | |
6233 void | |
6234 reset_expand_highlight() | |
6235 { | |
6236 include_link = include_default = include_none = 0; | |
6237 } | |
6238 | |
6239 /* | |
6240 * Handle command line completion for :match and :echohl command: Add "None" | |
6241 * as highlight group. | |
6242 */ | |
6243 void | |
6244 set_context_in_echohl_cmd(xp, arg) | |
6245 expand_T *xp; | |
6246 char_u *arg; | |
6247 { | |
6248 xp->xp_context = EXPAND_HIGHLIGHT; | |
6249 xp->xp_pattern = arg; | |
6250 include_none = 1; | |
6251 } | |
7 | 6252 |
6253 /* | |
6254 * Handle command line completion for :syntax command. | |
6255 */ | |
6256 void | |
6257 set_context_in_syntax_cmd(xp, arg) | |
6258 expand_T *xp; | |
6259 char_u *arg; | |
6260 { | |
6261 char_u *p; | |
6262 | |
6263 /* Default: expand subcommands */ | |
6264 xp->xp_context = EXPAND_SYNTAX; | |
6265 expand_what = EXP_SUBCMD; | |
6266 xp->xp_pattern = arg; | |
1322 | 6267 include_link = 0; |
6268 include_default = 0; | |
7 | 6269 |
6270 /* (part of) subcommand already typed */ | |
6271 if (*arg != NUL) | |
6272 { | |
6273 p = skiptowhite(arg); | |
6274 if (*p != NUL) /* past first word */ | |
6275 { | |
6276 xp->xp_pattern = skipwhite(p); | |
6277 if (*skiptowhite(xp->xp_pattern) != NUL) | |
6278 xp->xp_context = EXPAND_NOTHING; | |
6279 else if (STRNICMP(arg, "case", p - arg) == 0) | |
6280 expand_what = EXP_CASE; | |
6281 else if ( STRNICMP(arg, "keyword", p - arg) == 0 | |
6282 || STRNICMP(arg, "region", p - arg) == 0 | |
6283 || STRNICMP(arg, "match", p - arg) == 0 | |
6284 || STRNICMP(arg, "list", p - arg) == 0) | |
6285 xp->xp_context = EXPAND_HIGHLIGHT; | |
6286 else | |
6287 xp->xp_context = EXPAND_NOTHING; | |
6288 } | |
6289 } | |
6290 } | |
6291 | |
6292 static char *(case_args[]) = {"match", "ignore", NULL}; | |
6293 | |
6294 /* | |
6295 * Function given to ExpandGeneric() to obtain the list syntax names for | |
6296 * expansion. | |
6297 */ | |
6298 char_u * | |
6299 get_syntax_name(xp, idx) | |
1883 | 6300 expand_T *xp UNUSED; |
7 | 6301 int idx; |
6302 { | |
6303 if (expand_what == EXP_SUBCMD) | |
6304 return (char_u *)subcommands[idx].name; | |
6305 return (char_u *)case_args[idx]; | |
6306 } | |
6307 | |
6308 #endif /* FEAT_CMDL_COMPL */ | |
6309 | |
6310 /* | |
6311 * Function called for expression evaluation: get syntax ID at file position. | |
6312 */ | |
6313 int | |
1504 | 6314 syn_get_id(wp, lnum, col, trans, spellp, keep_state) |
499 | 6315 win_T *wp; |
7 | 6316 long lnum; |
253 | 6317 colnr_T col; |
2020 | 6318 int trans; /* remove transparency */ |
1504 | 6319 int *spellp; /* return: can do spell checking */ |
6320 int keep_state; /* keep state of char at "col" */ | |
7 | 6321 { |
6322 /* When the position is not after the current position and in the same | |
6323 * line of the same buffer, need to restart parsing. */ | |
499 | 6324 if (wp->w_buffer != syn_buf |
7 | 6325 || lnum != current_lnum |
253 | 6326 || col < current_col) |
499 | 6327 syntax_start(wp, lnum); |
7 | 6328 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6329 (void)get_syntax_attr(col, NULL, spellp, keep_state); |
7 | 6330 |
6331 return (trans ? current_trans_id : current_id); | |
6332 } | |
6333 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6334 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6335 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6336 * Return conceal substitution character |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6337 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6338 int |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6339 syn_get_sub_char() |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6340 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6341 return current_sub_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6342 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6343 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6344 |
1500 | 6345 #if defined(FEAT_EVAL) || defined(PROTO) |
6346 /* | |
6347 * Return the syntax ID at position "i" in the current stack. | |
6348 * The caller must have called syn_get_id() before to fill the stack. | |
6349 * Returns -1 when "i" is out of range. | |
6350 */ | |
6351 int | |
6352 syn_get_stack_item(i) | |
6353 int i; | |
6354 { | |
1504 | 6355 if (i >= current_state.ga_len) |
6356 { | |
6357 /* Need to invalidate the state, because we didn't properly finish it | |
6358 * for the last character, "keep_state" was TRUE. */ | |
6359 invalidate_current_state(); | |
6360 current_col = MAXCOL; | |
1500 | 6361 return -1; |
1504 | 6362 } |
1500 | 6363 return CUR_STATE(i).si_id; |
6364 } | |
6365 #endif | |
6366 | |
7 | 6367 #if defined(FEAT_FOLDING) || defined(PROTO) |
6368 /* | |
6369 * Function called to get folding level for line "lnum" in window "wp". | |
6370 */ | |
6371 int | |
6372 syn_get_foldlevel(wp, lnum) | |
6373 win_T *wp; | |
6374 long lnum; | |
6375 { | |
6376 int level = 0; | |
6377 int i; | |
6378 | |
6379 /* Return quickly when there are no fold items at all. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6380 if (wp->w_s->b_syn_folditems != 0) |
7 | 6381 { |
6382 syntax_start(wp, lnum); | |
6383 | |
6384 for (i = 0; i < current_state.ga_len; ++i) | |
6385 if (CUR_STATE(i).si_flags & HL_FOLD) | |
6386 ++level; | |
6387 } | |
6388 if (level > wp->w_p_fdn) | |
1028 | 6389 { |
7 | 6390 level = wp->w_p_fdn; |
1028 | 6391 if (level < 0) |
6392 level = 0; | |
6393 } | |
7 | 6394 return level; |
6395 } | |
6396 #endif | |
6397 | |
6398 #endif /* FEAT_SYN_HL */ | |
6399 | |
6400 | |
6401 /************************************** | |
6402 * Highlighting stuff * | |
6403 **************************************/ | |
6404 | |
6405 /* | |
6406 * The default highlight groups. These are compiled-in for fast startup and | |
6407 * they still work when the runtime files can't be found. | |
6408 * When making changes here, also change runtime/colors/default.vim! | |
806 | 6409 * The #ifdefs are needed to reduce the amount of static data. Helps to make |
6410 * the 16 bit DOS (museum) version compile. | |
7 | 6411 */ |
809 | 6412 #ifdef FEAT_GUI |
6413 # define CENT(a, b) b | |
6414 #else | |
6415 # define CENT(a, b) a | |
6416 #endif | |
7 | 6417 static char *(highlight_init_both[]) = |
6418 { | |
809 | 6419 CENT("ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", |
6420 "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), | |
6421 CENT("IncSearch term=reverse cterm=reverse", | |
6422 "IncSearch term=reverse cterm=reverse gui=reverse"), | |
6423 CENT("ModeMsg term=bold cterm=bold", | |
6424 "ModeMsg term=bold cterm=bold gui=bold"), | |
6425 CENT("NonText term=bold ctermfg=Blue", | |
6426 "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), | |
6427 CENT("StatusLine term=reverse,bold cterm=reverse,bold", | |
6428 "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), | |
6429 CENT("StatusLineNC term=reverse cterm=reverse", | |
6430 "StatusLineNC term=reverse cterm=reverse gui=reverse"), | |
806 | 6431 #ifdef FEAT_VERTSPLIT |
809 | 6432 CENT("VertSplit term=reverse cterm=reverse", |
6433 "VertSplit term=reverse cterm=reverse gui=reverse"), | |
806 | 6434 #endif |
6435 #ifdef FEAT_CLIPBOARD | |
809 | 6436 CENT("VisualNOS term=underline,bold cterm=underline,bold", |
6437 "VisualNOS term=underline,bold cterm=underline,bold gui=underline,bold"), | |
806 | 6438 #endif |
6439 #ifdef FEAT_DIFF | |
809 | 6440 CENT("DiffText term=reverse cterm=bold ctermbg=Red", |
6441 "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), | |
806 | 6442 #endif |
6443 #ifdef FEAT_INS_EXPAND | |
809 | 6444 CENT("PmenuThumb cterm=reverse", |
6445 "PmenuThumb cterm=reverse gui=reverse"), | |
6446 CENT("PmenuSbar ctermbg=Grey", | |
6447 "PmenuSbar ctermbg=Grey guibg=Grey"), | |
806 | 6448 #endif |
6449 #ifdef FEAT_WINDOWS | |
809 | 6450 CENT("TabLineSel term=bold cterm=bold", |
6451 "TabLineSel term=bold cterm=bold gui=bold"), | |
6452 CENT("TabLineFill term=reverse cterm=reverse", | |
6453 "TabLineFill term=reverse cterm=reverse gui=reverse"), | |
806 | 6454 #endif |
7 | 6455 #ifdef FEAT_GUI |
6456 "Cursor guibg=fg guifg=bg", | |
809 | 6457 "lCursor guibg=fg guifg=bg", /* should be different, but what? */ |
7 | 6458 #endif |
6459 NULL | |
6460 }; | |
6461 | |
6462 static char *(highlight_init_light[]) = | |
6463 { | |
809 | 6464 CENT("Directory term=bold ctermfg=DarkBlue", |
6465 "Directory term=bold ctermfg=DarkBlue guifg=Blue"), | |
6466 CENT("LineNr term=underline ctermfg=Brown", | |
6467 "LineNr term=underline ctermfg=Brown guifg=Brown"), | |
6468 CENT("MoreMsg term=bold ctermfg=DarkGreen", | |
6469 "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6470 CENT("Question term=standout ctermfg=DarkGreen", | |
6471 "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6472 CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", | |
6473 "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), | |
806 | 6474 #ifdef FEAT_SPELL |
809 | 6475 CENT("SpellBad term=reverse ctermbg=LightRed", |
6476 "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), | |
6477 CENT("SpellCap term=reverse ctermbg=LightBlue", | |
6478 "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), | |
6479 CENT("SpellRare term=reverse ctermbg=LightMagenta", | |
6480 "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), | |
6481 CENT("SpellLocal term=underline ctermbg=Cyan", | |
6482 "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), | |
806 | 6483 #endif |
6484 #ifdef FEAT_INS_EXPAND | |
809 | 6485 CENT("Pmenu ctermbg=LightMagenta", |
6486 "Pmenu ctermbg=LightMagenta guibg=LightMagenta"), | |
6487 CENT("PmenuSel ctermbg=LightGrey", | |
6488 "PmenuSel ctermbg=LightGrey guibg=Grey"), | |
806 | 6489 #endif |
809 | 6490 CENT("SpecialKey term=bold ctermfg=DarkBlue", |
6491 "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), | |
6492 CENT("Title term=bold ctermfg=DarkMagenta", | |
6493 "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), | |
6494 CENT("WarningMsg term=standout ctermfg=DarkRed", | |
6495 "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), | |
806 | 6496 #ifdef FEAT_WILDMENU |
809 | 6497 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
6498 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 6499 #endif |
6500 #ifdef FEAT_FOLDING | |
809 | 6501 CENT("Folded term=standout ctermbg=Grey ctermfg=DarkBlue", |
6502 "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), | |
6503 CENT("FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", | |
6504 "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6505 #endif |
6506 #ifdef FEAT_SIGNS | |
809 | 6507 CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", |
6508 "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6509 #endif |
6510 #ifdef FEAT_VISUAL | |
836 | 6511 CENT("Visual term=reverse", |
6512 "Visual term=reverse guibg=LightGrey"), | |
806 | 6513 #endif |
6514 #ifdef FEAT_DIFF | |
809 | 6515 CENT("DiffAdd term=bold ctermbg=LightBlue", |
6516 "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), | |
6517 CENT("DiffChange term=bold ctermbg=LightMagenta", | |
6518 "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), | |
6519 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", | |
6520 "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), | |
806 | 6521 #endif |
6522 #ifdef FEAT_WINDOWS | |
809 | 6523 CENT("TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", |
6524 "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), | |
806 | 6525 #endif |
6526 #ifdef FEAT_SYN_HL | |
809 | 6527 CENT("CursorColumn term=reverse ctermbg=LightGrey", |
818 | 6528 "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), |
809 | 6529 CENT("CursorLine term=underline cterm=underline", |
818 | 6530 "CursorLine term=underline cterm=underline guibg=Grey90"), |
806 | 6531 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6532 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6533 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6534 "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6535 #endif |
834 | 6536 #ifdef FEAT_AUTOCMD |
6537 CENT("MatchParen term=reverse ctermbg=Cyan", | |
6538 "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), | |
6539 #endif | |
806 | 6540 #ifdef FEAT_GUI |
7 | 6541 "Normal gui=NONE", |
806 | 6542 #endif |
7 | 6543 NULL |
6544 }; | |
6545 | |
6546 static char *(highlight_init_dark[]) = | |
6547 { | |
809 | 6548 CENT("Directory term=bold ctermfg=LightCyan", |
6549 "Directory term=bold ctermfg=LightCyan guifg=Cyan"), | |
6550 CENT("LineNr term=underline ctermfg=Yellow", | |
6551 "LineNr term=underline ctermfg=Yellow guifg=Yellow"), | |
6552 CENT("MoreMsg term=bold ctermfg=LightGreen", | |
6553 "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), | |
6554 CENT("Question term=standout ctermfg=LightGreen", | |
6555 "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), | |
6556 CENT("Search term=reverse ctermbg=Yellow ctermfg=Black", | |
6557 "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
6558 CENT("SpecialKey term=bold ctermfg=LightBlue", | |
6559 "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), | |
806 | 6560 #ifdef FEAT_SPELL |
809 | 6561 CENT("SpellBad term=reverse ctermbg=Red", |
6562 "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), | |
6563 CENT("SpellCap term=reverse ctermbg=Blue", | |
6564 "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), | |
6565 CENT("SpellRare term=reverse ctermbg=Magenta", | |
6566 "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), | |
6567 CENT("SpellLocal term=underline ctermbg=Cyan", | |
6568 "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), | |
806 | 6569 #endif |
6570 #ifdef FEAT_INS_EXPAND | |
809 | 6571 CENT("Pmenu ctermbg=Magenta", |
6572 "Pmenu ctermbg=Magenta guibg=Magenta"), | |
6573 CENT("PmenuSel ctermbg=DarkGrey", | |
6574 "PmenuSel ctermbg=DarkGrey guibg=DarkGrey"), | |
806 | 6575 #endif |
809 | 6576 CENT("Title term=bold ctermfg=LightMagenta", |
6577 "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), | |
6578 CENT("WarningMsg term=standout ctermfg=LightRed", | |
6579 "WarningMsg term=standout ctermfg=LightRed guifg=Red"), | |
806 | 6580 #ifdef FEAT_WILDMENU |
809 | 6581 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
6582 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 6583 #endif |
6584 #ifdef FEAT_FOLDING | |
809 | 6585 CENT("Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", |
6586 "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), | |
6587 CENT("FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", | |
6588 "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 6589 #endif |
6590 #ifdef FEAT_SIGNS | |
809 | 6591 CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", |
6592 "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 6593 #endif |
6594 #ifdef FEAT_VISUAL | |
836 | 6595 CENT("Visual term=reverse", |
6596 "Visual term=reverse guibg=DarkGrey"), | |
806 | 6597 #endif |
6598 #ifdef FEAT_DIFF | |
809 | 6599 CENT("DiffAdd term=bold ctermbg=DarkBlue", |
6600 "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), | |
6601 CENT("DiffChange term=bold ctermbg=DarkMagenta", | |
6602 "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), | |
6603 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", | |
6604 "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), | |
806 | 6605 #endif |
6606 #ifdef FEAT_WINDOWS | |
809 | 6607 CENT("TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", |
6608 "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), | |
806 | 6609 #endif |
6610 #ifdef FEAT_SYN_HL | |
809 | 6611 CENT("CursorColumn term=reverse ctermbg=DarkGrey", |
834 | 6612 "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), |
809 | 6613 CENT("CursorLine term=underline cterm=underline", |
834 | 6614 "CursorLine term=underline cterm=underline guibg=Grey40"), |
6615 #endif | |
6616 #ifdef FEAT_AUTOCMD | |
6617 CENT("MatchParen term=reverse ctermbg=DarkCyan", | |
6618 "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), | |
806 | 6619 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6620 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6621 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6622 "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6623 #endif |
806 | 6624 #ifdef FEAT_GUI |
7 | 6625 "Normal gui=NONE", |
806 | 6626 #endif |
7 | 6627 NULL |
6628 }; | |
6629 | |
6630 void | |
6631 init_highlight(both, reset) | |
6632 int both; /* include groups where 'bg' doesn't matter */ | |
6633 int reset; /* clear group first */ | |
6634 { | |
6635 int i; | |
6636 char **pp; | |
6637 static int had_both = FALSE; | |
6638 #ifdef FEAT_EVAL | |
6639 char_u *p; | |
6640 | |
6641 /* | |
6642 * Try finding the color scheme file. Used when a color file was loaded | |
6643 * and 'background' or 't_Co' is changed. | |
6644 */ | |
6645 p = get_var_value((char_u *)"g:colors_name"); | |
6646 if (p != NULL && load_colors(p) == OK) | |
6647 return; | |
6648 #endif | |
6649 | |
6650 /* | |
6651 * Didn't use a color file, use the compiled-in colors. | |
6652 */ | |
6653 if (both) | |
6654 { | |
6655 had_both = TRUE; | |
6656 pp = highlight_init_both; | |
6657 for (i = 0; pp[i] != NULL; ++i) | |
6658 do_highlight((char_u *)pp[i], reset, TRUE); | |
6659 } | |
6660 else if (!had_both) | |
6661 /* Don't do anything before the call with both == TRUE from main(). | |
6662 * Not everything has been setup then, and that call will overrule | |
6663 * everything anyway. */ | |
6664 return; | |
6665 | |
6666 if (*p_bg == 'l') | |
6667 pp = highlight_init_light; | |
6668 else | |
6669 pp = highlight_init_dark; | |
6670 for (i = 0; pp[i] != NULL; ++i) | |
6671 do_highlight((char_u *)pp[i], reset, TRUE); | |
6672 | |
836 | 6673 /* Reverse looks ugly, but grey may not work for 8 colors. Thus let it |
844 | 6674 * depend on the number of colors available. |
6675 * With 8 colors brown is equal to yellow, need to use black for Search fg | |
1697 | 6676 * to avoid Statement highlighted text disappears. |
6677 * Clear the attributes, needed when changing the t_Co value. */ | |
527 | 6678 if (t_colors > 8) |
1697 | 6679 do_highlight((char_u *)(*p_bg == 'l' |
6680 ? "Visual cterm=NONE ctermbg=LightGrey" | |
6681 : "Visual cterm=NONE ctermbg=DarkGrey"), FALSE, TRUE); | |
836 | 6682 else |
844 | 6683 { |
1697 | 6684 do_highlight((char_u *)"Visual cterm=reverse ctermbg=NONE", |
6685 FALSE, TRUE); | |
844 | 6686 if (*p_bg == 'l') |
6687 do_highlight((char_u *)"Search ctermfg=black", FALSE, TRUE); | |
6688 } | |
527 | 6689 |
7 | 6690 #ifdef FEAT_SYN_HL |
6691 /* | |
6692 * If syntax highlighting is enabled load the highlighting for it. | |
6693 */ | |
6694 if (get_var_value((char_u *)"g:syntax_on") != NULL) | |
24 | 6695 { |
6696 static int recursive = 0; | |
6697 | |
6698 if (recursive >= 5) | |
6699 EMSG(_("E679: recursive loop loading syncolor.vim")); | |
6700 else | |
6701 { | |
6702 ++recursive; | |
480 | 6703 (void)source_runtime((char_u *)"syntax/syncolor.vim", TRUE); |
24 | 6704 --recursive; |
6705 } | |
6706 } | |
7 | 6707 #endif |
6708 } | |
6709 | |
6710 /* | |
12 | 6711 * Load color file "name". |
7 | 6712 * Return OK for success, FAIL for failure. |
6713 */ | |
6714 int | |
12 | 6715 load_colors(name) |
6716 char_u *name; | |
7 | 6717 { |
6718 char_u *buf; | |
6719 int retval = FAIL; | |
6720 static int recursive = FALSE; | |
6721 | |
6722 /* When being called recursively, this is probably because setting | |
6723 * 'background' caused the highlighting to be reloaded. This means it is | |
6724 * working, thus we should return OK. */ | |
6725 if (recursive) | |
6726 return OK; | |
6727 | |
6728 recursive = TRUE; | |
12 | 6729 buf = alloc((unsigned)(STRLEN(name) + 12)); |
7 | 6730 if (buf != NULL) |
6731 { | |
12 | 6732 sprintf((char *)buf, "colors/%s.vim", name); |
480 | 6733 retval = source_runtime(buf, FALSE); |
7 | 6734 vim_free(buf); |
12 | 6735 #ifdef FEAT_AUTOCMD |
6736 apply_autocmds(EVENT_COLORSCHEME, NULL, NULL, FALSE, curbuf); | |
6737 #endif | |
7 | 6738 } |
6739 recursive = FALSE; | |
6740 | |
6741 return retval; | |
6742 } | |
6743 | |
6744 /* | |
6745 * Handle the ":highlight .." command. | |
6746 * When using ":hi clear" this is called recursively for each group with | |
6747 * "forceit" and "init" both TRUE. | |
6748 */ | |
6749 void | |
6750 do_highlight(line, forceit, init) | |
6751 char_u *line; | |
6752 int forceit; | |
6753 int init; /* TRUE when called for initializing */ | |
6754 { | |
6755 char_u *name_end; | |
6756 char_u *p; | |
6757 char_u *linep; | |
6758 char_u *key_start; | |
6759 char_u *arg_start; | |
6760 char_u *key = NULL, *arg = NULL; | |
6761 long i; | |
6762 int off; | |
6763 int len; | |
6764 int attr; | |
6765 int id; | |
6766 int idx; | |
6767 int dodefault = FALSE; | |
6768 int doclear = FALSE; | |
6769 int dolink = FALSE; | |
6770 int error = FALSE; | |
6771 int color; | |
6772 int is_normal_group = FALSE; /* "Normal" group */ | |
6773 #ifdef FEAT_GUI_X11 | |
6774 int is_menu_group = FALSE; /* "Menu" group */ | |
6775 int is_scrollbar_group = FALSE; /* "Scrollbar" group */ | |
6776 int is_tooltip_group = FALSE; /* "Tooltip" group */ | |
6777 int do_colors = FALSE; /* need to update colors? */ | |
6778 #else | |
6779 # define is_menu_group 0 | |
6780 # define is_tooltip_group 0 | |
6781 #endif | |
6782 | |
6783 /* | |
6784 * If no argument, list current highlighting. | |
6785 */ | |
6786 if (ends_excmd(*line)) | |
6787 { | |
6788 for (i = 1; i <= highlight_ga.ga_len && !got_int; ++i) | |
6789 /* TODO: only call when the group has attributes set */ | |
6790 highlight_list_one((int)i); | |
6791 return; | |
6792 } | |
6793 | |
6794 /* | |
6795 * Isolate the name. | |
6796 */ | |
6797 name_end = skiptowhite(line); | |
6798 linep = skipwhite(name_end); | |
6799 | |
6800 /* | |
6801 * Check for "default" argument. | |
6802 */ | |
6803 if (STRNCMP(line, "default", name_end - line) == 0) | |
6804 { | |
6805 dodefault = TRUE; | |
6806 line = linep; | |
6807 name_end = skiptowhite(line); | |
6808 linep = skipwhite(name_end); | |
6809 } | |
6810 | |
6811 /* | |
6812 * Check for "clear" or "link" argument. | |
6813 */ | |
6814 if (STRNCMP(line, "clear", name_end - line) == 0) | |
6815 doclear = TRUE; | |
6816 if (STRNCMP(line, "link", name_end - line) == 0) | |
6817 dolink = TRUE; | |
6818 | |
6819 /* | |
6820 * ":highlight {group-name}": list highlighting for one group. | |
6821 */ | |
6822 if (!doclear && !dolink && ends_excmd(*linep)) | |
6823 { | |
6824 id = syn_namen2id(line, (int)(name_end - line)); | |
6825 if (id == 0) | |
6826 EMSG2(_("E411: highlight group not found: %s"), line); | |
6827 else | |
6828 highlight_list_one(id); | |
6829 return; | |
6830 } | |
6831 | |
6832 /* | |
6833 * Handle ":highlight link {from} {to}" command. | |
6834 */ | |
6835 if (dolink) | |
6836 { | |
6837 char_u *from_start = linep; | |
6838 char_u *from_end; | |
6839 char_u *to_start; | |
6840 char_u *to_end; | |
6841 int from_id; | |
6842 int to_id; | |
6843 | |
6844 from_end = skiptowhite(from_start); | |
6845 to_start = skipwhite(from_end); | |
6846 to_end = skiptowhite(to_start); | |
6847 | |
6848 if (ends_excmd(*from_start) || ends_excmd(*to_start)) | |
6849 { | |
6850 EMSG2(_("E412: Not enough arguments: \":highlight link %s\""), | |
6851 from_start); | |
6852 return; | |
6853 } | |
6854 | |
6855 if (!ends_excmd(*skipwhite(to_end))) | |
6856 { | |
6857 EMSG2(_("E413: Too many arguments: \":highlight link %s\""), from_start); | |
6858 return; | |
6859 } | |
6860 | |
6861 from_id = syn_check_group(from_start, (int)(from_end - from_start)); | |
6862 if (STRNCMP(to_start, "NONE", 4) == 0) | |
6863 to_id = 0; | |
6864 else | |
6865 to_id = syn_check_group(to_start, (int)(to_end - to_start)); | |
6866 | |
6867 if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0)) | |
6868 { | |
6869 /* | |
6870 * Don't allow a link when there already is some highlighting | |
6871 * for the group, unless '!' is used | |
6872 */ | |
6873 if (to_id > 0 && !forceit && !init | |
6874 && hl_has_settings(from_id - 1, dodefault)) | |
6875 { | |
6876 if (sourcing_name == NULL && !dodefault) | |
6877 EMSG(_("E414: group has settings, highlight link ignored")); | |
6878 } | |
6879 else | |
6880 { | |
6881 if (!init) | |
6882 HL_TABLE()[from_id - 1].sg_set |= SG_LINK; | |
6883 HL_TABLE()[from_id - 1].sg_link = to_id; | |
448 | 6884 #ifdef FEAT_EVAL |
6885 HL_TABLE()[from_id - 1].sg_scriptID = current_SID; | |
6886 #endif | |
745 | 6887 redraw_all_later(SOME_VALID); |
7 | 6888 } |
6889 } | |
6890 | |
6891 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
6892 need_highlight_changed = TRUE; | |
6893 | |
6894 return; | |
6895 } | |
6896 | |
6897 if (doclear) | |
6898 { | |
6899 /* | |
6900 * ":highlight clear [group]" command. | |
6901 */ | |
6902 line = linep; | |
6903 if (ends_excmd(*line)) | |
6904 { | |
6905 #ifdef FEAT_GUI | |
6906 /* First, we do not destroy the old values, but allocate the new | |
6907 * ones and update the display. THEN we destroy the old values. | |
6908 * If we destroy the old values first, then the old values | |
6909 * (such as GuiFont's or GuiFontset's) will still be displayed but | |
6910 * invalid because they were free'd. | |
6911 */ | |
6912 if (gui.in_use) | |
6913 { | |
6914 # ifdef FEAT_BEVAL_TIP | |
6915 gui_init_tooltip_font(); | |
6916 # endif | |
6917 # if defined(FEAT_MENU) && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF)) | |
6918 gui_init_menu_font(); | |
6919 # endif | |
6920 } | |
6921 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_X11) | |
6922 gui_mch_def_colors(); | |
6923 # endif | |
6924 # ifdef FEAT_GUI_X11 | |
6925 # ifdef FEAT_MENU | |
6926 | |
6927 /* This only needs to be done when there is no Menu highlight | |
6928 * group defined by default, which IS currently the case. | |
6929 */ | |
6930 gui_mch_new_menu_colors(); | |
6931 # endif | |
6932 if (gui.in_use) | |
6933 { | |
6934 gui_new_scrollbar_colors(); | |
6935 # ifdef FEAT_BEVAL | |
6936 gui_mch_new_tooltip_colors(); | |
6937 # endif | |
6938 # ifdef FEAT_MENU | |
6939 gui_mch_new_menu_font(); | |
6940 # endif | |
6941 } | |
6942 # endif | |
6943 | |
6944 /* Ok, we're done allocating the new default graphics items. | |
6945 * The screen should already be refreshed at this point. | |
6946 * It is now Ok to clear out the old data. | |
6947 */ | |
6948 #endif | |
6949 #ifdef FEAT_EVAL | |
148 | 6950 do_unlet((char_u *)"colors_name", TRUE); |
7 | 6951 #endif |
6952 restore_cterm_colors(); | |
6953 | |
6954 /* | |
6955 * Clear all default highlight groups and load the defaults. | |
6956 */ | |
6957 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
6958 highlight_clear(idx); | |
6959 init_highlight(TRUE, TRUE); | |
6960 #ifdef FEAT_GUI | |
6961 if (gui.in_use) | |
6962 highlight_gui_started(); | |
6963 #endif | |
6964 highlight_changed(); | |
6965 redraw_later_clear(); | |
6966 return; | |
6967 } | |
6968 name_end = skiptowhite(line); | |
6969 linep = skipwhite(name_end); | |
6970 } | |
6971 | |
6972 /* | |
6973 * Find the group name in the table. If it does not exist yet, add it. | |
6974 */ | |
6975 id = syn_check_group(line, (int)(name_end - line)); | |
6976 if (id == 0) /* failed (out of memory) */ | |
6977 return; | |
6978 idx = id - 1; /* index is ID minus one */ | |
6979 | |
6980 /* Return if "default" was used and the group already has settings. */ | |
6981 if (dodefault && hl_has_settings(idx, TRUE)) | |
6982 return; | |
6983 | |
6984 if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0) | |
6985 is_normal_group = TRUE; | |
6986 #ifdef FEAT_GUI_X11 | |
6987 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0) | |
6988 is_menu_group = TRUE; | |
6989 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "SCROLLBAR") == 0) | |
6990 is_scrollbar_group = TRUE; | |
6991 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "TOOLTIP") == 0) | |
6992 is_tooltip_group = TRUE; | |
6993 #endif | |
6994 | |
6995 /* Clear the highlighting for ":hi clear {group}" and ":hi clear". */ | |
6996 if (doclear || (forceit && init)) | |
6997 { | |
6998 highlight_clear(idx); | |
6999 if (!doclear) | |
7000 HL_TABLE()[idx].sg_set = 0; | |
7001 } | |
7002 | |
7003 if (!doclear) | |
7004 while (!ends_excmd(*linep)) | |
7005 { | |
7006 key_start = linep; | |
7007 if (*linep == '=') | |
7008 { | |
7009 EMSG2(_("E415: unexpected equal sign: %s"), key_start); | |
7010 error = TRUE; | |
7011 break; | |
7012 } | |
7013 | |
7014 /* | |
7015 * Isolate the key ("term", "ctermfg", "ctermbg", "font", "guifg" or | |
7016 * "guibg"). | |
7017 */ | |
7018 while (*linep && !vim_iswhite(*linep) && *linep != '=') | |
7019 ++linep; | |
7020 vim_free(key); | |
7021 key = vim_strnsave_up(key_start, (int)(linep - key_start)); | |
7022 if (key == NULL) | |
7023 { | |
7024 error = TRUE; | |
7025 break; | |
7026 } | |
7027 linep = skipwhite(linep); | |
7028 | |
7029 if (STRCMP(key, "NONE") == 0) | |
7030 { | |
7031 if (!init || HL_TABLE()[idx].sg_set == 0) | |
7032 { | |
7033 if (!init) | |
7034 HL_TABLE()[idx].sg_set |= SG_TERM+SG_CTERM+SG_GUI; | |
7035 highlight_clear(idx); | |
7036 } | |
7037 continue; | |
7038 } | |
7039 | |
7040 /* | |
7041 * Check for the equal sign. | |
7042 */ | |
7043 if (*linep != '=') | |
7044 { | |
7045 EMSG2(_("E416: missing equal sign: %s"), key_start); | |
7046 error = TRUE; | |
7047 break; | |
7048 } | |
7049 ++linep; | |
7050 | |
7051 /* | |
7052 * Isolate the argument. | |
7053 */ | |
7054 linep = skipwhite(linep); | |
7055 if (*linep == '\'') /* guifg='color name' */ | |
7056 { | |
7057 arg_start = ++linep; | |
7058 linep = vim_strchr(linep, '\''); | |
7059 if (linep == NULL) | |
7060 { | |
7061 EMSG2(_(e_invarg2), key_start); | |
7062 error = TRUE; | |
7063 break; | |
7064 } | |
7065 } | |
7066 else | |
7067 { | |
7068 arg_start = linep; | |
7069 linep = skiptowhite(linep); | |
7070 } | |
7071 if (linep == arg_start) | |
7072 { | |
7073 EMSG2(_("E417: missing argument: %s"), key_start); | |
7074 error = TRUE; | |
7075 break; | |
7076 } | |
7077 vim_free(arg); | |
7078 arg = vim_strnsave(arg_start, (int)(linep - arg_start)); | |
7079 if (arg == NULL) | |
7080 { | |
7081 error = TRUE; | |
7082 break; | |
7083 } | |
7084 if (*linep == '\'') | |
7085 ++linep; | |
7086 | |
7087 /* | |
7088 * Store the argument. | |
7089 */ | |
7090 if ( STRCMP(key, "TERM") == 0 | |
7091 || STRCMP(key, "CTERM") == 0 | |
7092 || STRCMP(key, "GUI") == 0) | |
7093 { | |
7094 attr = 0; | |
7095 off = 0; | |
7096 while (arg[off] != NUL) | |
7097 { | |
7098 for (i = sizeof(hl_attr_table) / sizeof(int); --i >= 0; ) | |
7099 { | |
7100 len = (int)STRLEN(hl_name_table[i]); | |
7101 if (STRNICMP(arg + off, hl_name_table[i], len) == 0) | |
7102 { | |
7103 attr |= hl_attr_table[i]; | |
7104 off += len; | |
7105 break; | |
7106 } | |
7107 } | |
7108 if (i < 0) | |
7109 { | |
7110 EMSG2(_("E418: Illegal value: %s"), arg); | |
7111 error = TRUE; | |
7112 break; | |
7113 } | |
7114 if (arg[off] == ',') /* another one follows */ | |
7115 ++off; | |
7116 } | |
7117 if (error) | |
7118 break; | |
7119 if (*key == 'T') | |
7120 { | |
7121 if (!init || !(HL_TABLE()[idx].sg_set & SG_TERM)) | |
7122 { | |
7123 if (!init) | |
7124 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7125 HL_TABLE()[idx].sg_term = attr; | |
7126 } | |
7127 } | |
7128 else if (*key == 'C') | |
7129 { | |
7130 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7131 { | |
7132 if (!init) | |
7133 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7134 HL_TABLE()[idx].sg_cterm = attr; | |
7135 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7136 } | |
7137 } | |
7138 #ifdef FEAT_GUI | |
7139 else | |
7140 { | |
7141 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) | |
7142 { | |
7143 if (!init) | |
7144 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7145 HL_TABLE()[idx].sg_gui = attr; | |
7146 } | |
7147 } | |
7148 #endif | |
7149 } | |
7150 else if (STRCMP(key, "FONT") == 0) | |
7151 { | |
7152 /* in non-GUI fonts are simply ignored */ | |
7153 #ifdef FEAT_GUI | |
7154 if (!gui.shell_created) | |
7155 { | |
7156 /* GUI not started yet, always accept the name. */ | |
7157 vim_free(HL_TABLE()[idx].sg_font_name); | |
7158 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7159 } | |
7160 else | |
7161 { | |
7162 GuiFont temp_sg_font = HL_TABLE()[idx].sg_font; | |
7163 # ifdef FEAT_XFONTSET | |
7164 GuiFontset temp_sg_fontset = HL_TABLE()[idx].sg_fontset; | |
7165 # endif | |
7166 /* First, save the current font/fontset. | |
7167 * Then try to allocate the font/fontset. | |
7168 * If the allocation fails, HL_TABLE()[idx].sg_font OR | |
7169 * sg_fontset will be set to NOFONT or NOFONTSET respectively. | |
7170 */ | |
7171 | |
7172 HL_TABLE()[idx].sg_font = NOFONT; | |
7173 # ifdef FEAT_XFONTSET | |
7174 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
7175 # endif | |
7176 hl_do_font(idx, arg, is_normal_group, is_menu_group, | |
7177 is_tooltip_group); | |
7178 | |
7179 # ifdef FEAT_XFONTSET | |
7180 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) | |
7181 { | |
7182 /* New fontset was accepted. Free the old one, if there was | |
7183 * one. | |
7184 */ | |
7185 gui_mch_free_fontset(temp_sg_fontset); | |
7186 vim_free(HL_TABLE()[idx].sg_font_name); | |
7187 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7188 } | |
7189 else | |
7190 HL_TABLE()[idx].sg_fontset = temp_sg_fontset; | |
7191 # endif | |
7192 if (HL_TABLE()[idx].sg_font != NOFONT) | |
7193 { | |
7194 /* New font was accepted. Free the old one, if there was | |
7195 * one. | |
7196 */ | |
7197 gui_mch_free_font(temp_sg_font); | |
7198 vim_free(HL_TABLE()[idx].sg_font_name); | |
7199 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7200 } | |
7201 else | |
7202 HL_TABLE()[idx].sg_font = temp_sg_font; | |
7203 } | |
7204 #endif | |
7205 } | |
7206 else if (STRCMP(key, "CTERMFG") == 0 || STRCMP(key, "CTERMBG") == 0) | |
7207 { | |
7208 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7209 { | |
7210 if (!init) | |
7211 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7212 | |
7213 /* When setting the foreground color, and previously the "bold" | |
7214 * flag was set for a light color, reset it now */ | |
7215 if (key[5] == 'F' && HL_TABLE()[idx].sg_cterm_bold) | |
7216 { | |
7217 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7218 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7219 } | |
7220 | |
7221 if (VIM_ISDIGIT(*arg)) | |
7222 color = atoi((char *)arg); | |
7223 else if (STRICMP(arg, "fg") == 0) | |
7224 { | |
7225 if (cterm_normal_fg_color) | |
7226 color = cterm_normal_fg_color - 1; | |
7227 else | |
7228 { | |
7229 EMSG(_("E419: FG color unknown")); | |
7230 error = TRUE; | |
7231 break; | |
7232 } | |
7233 } | |
7234 else if (STRICMP(arg, "bg") == 0) | |
7235 { | |
7236 if (cterm_normal_bg_color > 0) | |
7237 color = cterm_normal_bg_color - 1; | |
7238 else | |
7239 { | |
7240 EMSG(_("E420: BG color unknown")); | |
7241 error = TRUE; | |
7242 break; | |
7243 } | |
7244 } | |
7245 else | |
7246 { | |
7247 static char *(color_names[28]) = { | |
7248 "Black", "DarkBlue", "DarkGreen", "DarkCyan", | |
7249 "DarkRed", "DarkMagenta", "Brown", "DarkYellow", | |
7250 "Gray", "Grey", | |
7251 "LightGray", "LightGrey", "DarkGray", "DarkGrey", | |
7252 "Blue", "LightBlue", "Green", "LightGreen", | |
7253 "Cyan", "LightCyan", "Red", "LightRed", "Magenta", | |
7254 "LightMagenta", "Yellow", "LightYellow", "White", "NONE"}; | |
7255 static int color_numbers_16[28] = {0, 1, 2, 3, | |
7256 4, 5, 6, 6, | |
7257 7, 7, | |
7258 7, 7, 8, 8, | |
7259 9, 9, 10, 10, | |
7260 11, 11, 12, 12, 13, | |
7261 13, 14, 14, 15, -1}; | |
7262 /* for xterm with 88 colors... */ | |
7263 static int color_numbers_88[28] = {0, 4, 2, 6, | |
7264 1, 5, 32, 72, | |
7265 84, 84, | |
7266 7, 7, 82, 82, | |
7267 12, 43, 10, 61, | |
7268 14, 63, 9, 74, 13, | |
7269 75, 11, 78, 15, -1}; | |
7270 /* for xterm with 256 colors... */ | |
7271 static int color_numbers_256[28] = {0, 4, 2, 6, | |
7272 1, 5, 130, 130, | |
7273 248, 248, | |
7274 7, 7, 242, 242, | |
7275 12, 81, 10, 121, | |
7276 14, 159, 9, 224, 13, | |
7277 225, 11, 229, 15, -1}; | |
7278 /* for terminals with less than 16 colors... */ | |
7279 static int color_numbers_8[28] = {0, 4, 2, 6, | |
7280 1, 5, 3, 3, | |
7281 7, 7, | |
7282 7, 7, 0+8, 0+8, | |
7283 4+8, 4+8, 2+8, 2+8, | |
7284 6+8, 6+8, 1+8, 1+8, 5+8, | |
7285 5+8, 3+8, 3+8, 7+8, -1}; | |
7286 #if defined(__QNXNTO__) | |
7287 static int *color_numbers_8_qansi = color_numbers_8; | |
7288 /* On qnx, the 8 & 16 color arrays are the same */ | |
7289 if (STRNCMP(T_NAME, "qansi", 5) == 0) | |
7290 color_numbers_8_qansi = color_numbers_16; | |
7291 #endif | |
7292 | |
7293 /* reduce calls to STRICMP a bit, it can be slow */ | |
7294 off = TOUPPER_ASC(*arg); | |
7295 for (i = (sizeof(color_names) / sizeof(char *)); --i >= 0; ) | |
7296 if (off == color_names[i][0] | |
7297 && STRICMP(arg + 1, color_names[i] + 1) == 0) | |
7298 break; | |
7299 if (i < 0) | |
7300 { | |
7301 EMSG2(_("E421: Color name or number not recognized: %s"), key_start); | |
7302 error = TRUE; | |
7303 break; | |
7304 } | |
7305 | |
7306 /* Use the _16 table to check if its a valid color name. */ | |
7307 color = color_numbers_16[i]; | |
7308 if (color >= 0) | |
7309 { | |
7310 if (t_colors == 8) | |
7311 { | |
7312 /* t_Co is 8: use the 8 colors table */ | |
7313 #if defined(__QNXNTO__) | |
7314 color = color_numbers_8_qansi[i]; | |
7315 #else | |
7316 color = color_numbers_8[i]; | |
7317 #endif | |
7318 if (key[5] == 'F') | |
7319 { | |
7320 /* set/reset bold attribute to get light foreground | |
7321 * colors (on some terminals, e.g. "linux") */ | |
7322 if (color & 8) | |
7323 { | |
7324 HL_TABLE()[idx].sg_cterm |= HL_BOLD; | |
7325 HL_TABLE()[idx].sg_cterm_bold = TRUE; | |
7326 } | |
7327 else | |
7328 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7329 } | |
7330 color &= 7; /* truncate to 8 colors */ | |
7331 } | |
7332 else if (t_colors == 16 || t_colors == 88 | |
7333 || t_colors == 256) | |
7334 { | |
7335 /* | |
7336 * Guess: if the termcap entry ends in 'm', it is | |
7337 * probably an xterm-like terminal. Use the changed | |
7338 * order for colors. | |
7339 */ | |
7340 if (*T_CAF != NUL) | |
7341 p = T_CAF; | |
7342 else | |
7343 p = T_CSF; | |
7344 if (*p != NUL && *(p + STRLEN(p) - 1) == 'm') | |
7345 switch (t_colors) | |
7346 { | |
7347 case 16: | |
7348 color = color_numbers_8[i]; | |
7349 break; | |
7350 case 88: | |
7351 color = color_numbers_88[i]; | |
7352 break; | |
7353 case 256: | |
7354 color = color_numbers_256[i]; | |
7355 break; | |
7356 } | |
7357 } | |
7358 } | |
7359 } | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7360 /* Add one to the argument, to avoid zero. Zero is used for |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7361 * "NONE", then "color" is -1. */ |
7 | 7362 if (key[5] == 'F') |
7363 { | |
7364 HL_TABLE()[idx].sg_cterm_fg = color + 1; | |
7365 if (is_normal_group) | |
7366 { | |
7367 cterm_normal_fg_color = color + 1; | |
7368 cterm_normal_fg_bold = (HL_TABLE()[idx].sg_cterm & HL_BOLD); | |
7369 #ifdef FEAT_GUI | |
7370 /* Don't do this if the GUI is used. */ | |
7371 if (!gui.in_use && !gui.starting) | |
7372 #endif | |
7373 { | |
7374 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7375 if (termcap_active && color >= 0) |
7 | 7376 term_fg_color(color); |
7377 } | |
7378 } | |
7379 } | |
7380 else | |
7381 { | |
7382 HL_TABLE()[idx].sg_cterm_bg = color + 1; | |
7383 if (is_normal_group) | |
7384 { | |
7385 cterm_normal_bg_color = color + 1; | |
7386 #ifdef FEAT_GUI | |
7387 /* Don't mess with 'background' if the GUI is used. */ | |
7388 if (!gui.in_use && !gui.starting) | |
7389 #endif | |
7390 { | |
7391 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7392 if (color >= 0) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7393 { |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7394 if (termcap_active) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7395 term_bg_color(color); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7396 if (t_colors < 16) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7397 i = (color == 0 || color == 4); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7398 else |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7399 i = (color < 7 || color == 8); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7400 /* Set the 'background' option if the value is |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7401 * wrong. */ |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7402 if (i != (*p_bg == 'd')) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7403 set_option_value((char_u *)"bg", 0L, |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7404 i ? (char_u *)"dark" |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7405 : (char_u *)"light", 0); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7406 } |
7 | 7407 } |
7408 } | |
7409 } | |
7410 } | |
7411 } | |
7412 else if (STRCMP(key, "GUIFG") == 0) | |
7413 { | |
7414 #ifdef FEAT_GUI /* in non-GUI guifg colors are simply ignored */ | |
205 | 7415 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7416 { |
205 | 7417 if (!init) |
7418 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7419 | |
7420 i = color_name2handle(arg); | |
7421 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) | |
7422 { | |
7423 HL_TABLE()[idx].sg_gui_fg = i; | |
7424 vim_free(HL_TABLE()[idx].sg_gui_fg_name); | |
7425 if (STRCMP(arg, "NONE")) | |
7426 HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg); | |
7427 else | |
7428 HL_TABLE()[idx].sg_gui_fg_name = NULL; | |
7 | 7429 # ifdef FEAT_GUI_X11 |
205 | 7430 if (is_menu_group) |
7431 gui.menu_fg_pixel = i; | |
7432 if (is_scrollbar_group) | |
7433 gui.scroll_fg_pixel = i; | |
7 | 7434 # ifdef FEAT_BEVAL |
205 | 7435 if (is_tooltip_group) |
7436 gui.tooltip_fg_pixel = i; | |
7 | 7437 # endif |
205 | 7438 do_colors = TRUE; |
7 | 7439 # endif |
205 | 7440 } |
7 | 7441 } |
7442 #endif | |
7443 } | |
7444 else if (STRCMP(key, "GUIBG") == 0) | |
7445 { | |
7446 #ifdef FEAT_GUI /* in non-GUI guibg colors are simply ignored */ | |
205 | 7447 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7448 { |
205 | 7449 if (!init) |
7450 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7451 | |
7452 i = color_name2handle(arg); | |
7453 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) | |
7454 { | |
7455 HL_TABLE()[idx].sg_gui_bg = i; | |
7456 vim_free(HL_TABLE()[idx].sg_gui_bg_name); | |
7457 if (STRCMP(arg, "NONE") != 0) | |
7458 HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg); | |
7459 else | |
7460 HL_TABLE()[idx].sg_gui_bg_name = NULL; | |
7 | 7461 # ifdef FEAT_GUI_X11 |
205 | 7462 if (is_menu_group) |
7463 gui.menu_bg_pixel = i; | |
7464 if (is_scrollbar_group) | |
7465 gui.scroll_bg_pixel = i; | |
7 | 7466 # ifdef FEAT_BEVAL |
205 | 7467 if (is_tooltip_group) |
7468 gui.tooltip_bg_pixel = i; | |
7 | 7469 # endif |
205 | 7470 do_colors = TRUE; |
7 | 7471 # endif |
205 | 7472 } |
7 | 7473 } |
205 | 7474 #endif |
7475 } | |
7476 else if (STRCMP(key, "GUISP") == 0) | |
7477 { | |
7478 #ifdef FEAT_GUI /* in non-GUI guisp colors are simply ignored */ | |
7479 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) | |
7480 { | |
7481 if (!init) | |
7482 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7483 | |
7484 i = color_name2handle(arg); | |
7485 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) | |
7486 { | |
7487 HL_TABLE()[idx].sg_gui_sp = i; | |
7488 vim_free(HL_TABLE()[idx].sg_gui_sp_name); | |
7489 if (STRCMP(arg, "NONE") != 0) | |
7490 HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg); | |
7491 else | |
7492 HL_TABLE()[idx].sg_gui_sp_name = NULL; | |
7493 } | |
7494 } | |
7 | 7495 #endif |
7496 } | |
7497 else if (STRCMP(key, "START") == 0 || STRCMP(key, "STOP") == 0) | |
7498 { | |
7499 char_u buf[100]; | |
7500 char_u *tname; | |
7501 | |
7502 if (!init) | |
7503 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7504 | |
7505 /* | |
7506 * The "start" and "stop" arguments can be a literal escape | |
1222 | 7507 * sequence, or a comma separated list of terminal codes. |
7 | 7508 */ |
7509 if (STRNCMP(arg, "t_", 2) == 0) | |
7510 { | |
7511 off = 0; | |
7512 buf[0] = 0; | |
7513 while (arg[off] != NUL) | |
7514 { | |
7515 /* Isolate one termcap name */ | |
7516 for (len = 0; arg[off + len] && | |
7517 arg[off + len] != ','; ++len) | |
7518 ; | |
7519 tname = vim_strnsave(arg + off, len); | |
7520 if (tname == NULL) /* out of memory */ | |
7521 { | |
7522 error = TRUE; | |
7523 break; | |
7524 } | |
7525 /* lookup the escape sequence for the item */ | |
7526 p = get_term_code(tname); | |
7527 vim_free(tname); | |
7528 if (p == NULL) /* ignore non-existing things */ | |
7529 p = (char_u *)""; | |
7530 | |
7531 /* Append it to the already found stuff */ | |
7532 if ((int)(STRLEN(buf) + STRLEN(p)) >= 99) | |
7533 { | |
7534 EMSG2(_("E422: terminal code too long: %s"), arg); | |
7535 error = TRUE; | |
7536 break; | |
7537 } | |
7538 STRCAT(buf, p); | |
7539 | |
7540 /* Advance to the next item */ | |
7541 off += len; | |
7542 if (arg[off] == ',') /* another one follows */ | |
7543 ++off; | |
7544 } | |
7545 } | |
7546 else | |
7547 { | |
7548 /* | |
7549 * Copy characters from arg[] to buf[], translating <> codes. | |
7550 */ | |
7551 for (p = arg, off = 0; off < 100 && *p; ) | |
7552 { | |
7553 len = trans_special(&p, buf + off, FALSE); | |
7554 if (len) /* recognized special char */ | |
7555 off += len; | |
7556 else /* copy as normal char */ | |
7557 buf[off++] = *p++; | |
7558 } | |
7559 buf[off] = NUL; | |
7560 } | |
7561 if (error) | |
7562 break; | |
7563 | |
7564 if (STRCMP(buf, "NONE") == 0) /* resetting the value */ | |
7565 p = NULL; | |
7566 else | |
7567 p = vim_strsave(buf); | |
7568 if (key[2] == 'A') | |
7569 { | |
7570 vim_free(HL_TABLE()[idx].sg_start); | |
7571 HL_TABLE()[idx].sg_start = p; | |
7572 } | |
7573 else | |
7574 { | |
7575 vim_free(HL_TABLE()[idx].sg_stop); | |
7576 HL_TABLE()[idx].sg_stop = p; | |
7577 } | |
7578 } | |
7579 else | |
7580 { | |
7581 EMSG2(_("E423: Illegal argument: %s"), key_start); | |
7582 error = TRUE; | |
7583 break; | |
7584 } | |
7585 | |
7586 /* | |
7587 * When highlighting has been given for a group, don't link it. | |
7588 */ | |
7589 if (!init || !(HL_TABLE()[idx].sg_set & SG_LINK)) | |
7590 HL_TABLE()[idx].sg_link = 0; | |
7591 | |
7592 /* | |
7593 * Continue with next argument. | |
7594 */ | |
7595 linep = skipwhite(linep); | |
7596 } | |
7597 | |
7598 /* | |
7599 * If there is an error, and it's a new entry, remove it from the table. | |
7600 */ | |
7601 if (error && idx == highlight_ga.ga_len) | |
7602 syn_unadd_group(); | |
7603 else | |
7604 { | |
7605 if (is_normal_group) | |
7606 { | |
7607 HL_TABLE()[idx].sg_term_attr = 0; | |
7608 HL_TABLE()[idx].sg_cterm_attr = 0; | |
7609 #ifdef FEAT_GUI | |
7610 HL_TABLE()[idx].sg_gui_attr = 0; | |
7611 /* | |
7612 * Need to update all groups, because they might be using "bg" | |
7613 * and/or "fg", which have been changed now. | |
7614 */ | |
7615 if (gui.in_use) | |
7616 highlight_gui_started(); | |
7617 #endif | |
7618 } | |
7619 #ifdef FEAT_GUI_X11 | |
7620 # ifdef FEAT_MENU | |
7621 else if (is_menu_group) | |
7622 { | |
7623 if (gui.in_use && do_colors) | |
7624 gui_mch_new_menu_colors(); | |
7625 } | |
7626 # endif | |
7627 else if (is_scrollbar_group) | |
7628 { | |
7629 if (gui.in_use && do_colors) | |
7630 gui_new_scrollbar_colors(); | |
7631 } | |
7632 # ifdef FEAT_BEVAL | |
7633 else if (is_tooltip_group) | |
7634 { | |
7635 if (gui.in_use && do_colors) | |
7636 gui_mch_new_tooltip_colors(); | |
7637 } | |
7638 # endif | |
7639 #endif | |
7640 else | |
7641 set_hl_attr(idx); | |
448 | 7642 #ifdef FEAT_EVAL |
7643 HL_TABLE()[idx].sg_scriptID = current_SID; | |
7644 #endif | |
819 | 7645 redraw_all_later(NOT_VALID); |
7 | 7646 } |
7647 vim_free(key); | |
7648 vim_free(arg); | |
7649 | |
7650 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
7651 need_highlight_changed = TRUE; | |
7652 } | |
7653 | |
356 | 7654 #if defined(EXITFREE) || defined(PROTO) |
7655 void | |
7656 free_highlight() | |
7657 { | |
7658 int i; | |
7659 | |
7660 for (i = 0; i < highlight_ga.ga_len; ++i) | |
359 | 7661 { |
356 | 7662 highlight_clear(i); |
359 | 7663 vim_free(HL_TABLE()[i].sg_name); |
7664 vim_free(HL_TABLE()[i].sg_name_u); | |
7665 } | |
356 | 7666 ga_clear(&highlight_ga); |
7667 } | |
7668 #endif | |
7669 | |
7 | 7670 /* |
7671 * Reset the cterm colors to what they were before Vim was started, if | |
7672 * possible. Otherwise reset them to zero. | |
7673 */ | |
7674 void | |
7675 restore_cterm_colors() | |
7676 { | |
7677 #if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32)) | |
7678 /* Since t_me has been set, this probably means that the user | |
7679 * wants to use this as default colors. Need to reset default | |
7680 * background/foreground colors. */ | |
7681 mch_set_normal_colors(); | |
7682 #else | |
7683 cterm_normal_fg_color = 0; | |
7684 cterm_normal_fg_bold = 0; | |
7685 cterm_normal_bg_color = 0; | |
7686 #endif | |
7687 } | |
7688 | |
7689 /* | |
7690 * Return TRUE if highlight group "idx" has any settings. | |
7691 * When "check_link" is TRUE also check for an existing link. | |
7692 */ | |
7693 static int | |
7694 hl_has_settings(idx, check_link) | |
7695 int idx; | |
7696 int check_link; | |
7697 { | |
7698 return ( HL_TABLE()[idx].sg_term_attr != 0 | |
7699 || HL_TABLE()[idx].sg_cterm_attr != 0 | |
7700 #ifdef FEAT_GUI | |
7701 || HL_TABLE()[idx].sg_gui_attr != 0 | |
7702 #endif | |
7703 || (check_link && (HL_TABLE()[idx].sg_set & SG_LINK))); | |
7704 } | |
7705 | |
7706 /* | |
7707 * Clear highlighting for one group. | |
7708 */ | |
7709 static void | |
7710 highlight_clear(idx) | |
7711 int idx; | |
7712 { | |
7713 HL_TABLE()[idx].sg_term = 0; | |
7714 vim_free(HL_TABLE()[idx].sg_start); | |
7715 HL_TABLE()[idx].sg_start = NULL; | |
7716 vim_free(HL_TABLE()[idx].sg_stop); | |
7717 HL_TABLE()[idx].sg_stop = NULL; | |
7718 HL_TABLE()[idx].sg_term_attr = 0; | |
7719 HL_TABLE()[idx].sg_cterm = 0; | |
7720 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7721 HL_TABLE()[idx].sg_cterm_fg = 0; | |
7722 HL_TABLE()[idx].sg_cterm_bg = 0; | |
7723 HL_TABLE()[idx].sg_cterm_attr = 0; | |
7724 #ifdef FEAT_GUI /* in non-GUI fonts are simply ignored */ | |
7725 HL_TABLE()[idx].sg_gui = 0; | |
7726 HL_TABLE()[idx].sg_gui_fg = INVALCOLOR; | |
7727 vim_free(HL_TABLE()[idx].sg_gui_fg_name); | |
7728 HL_TABLE()[idx].sg_gui_fg_name = NULL; | |
7729 HL_TABLE()[idx].sg_gui_bg = INVALCOLOR; | |
7730 vim_free(HL_TABLE()[idx].sg_gui_bg_name); | |
7731 HL_TABLE()[idx].sg_gui_bg_name = NULL; | |
205 | 7732 HL_TABLE()[idx].sg_gui_sp = INVALCOLOR; |
7733 vim_free(HL_TABLE()[idx].sg_gui_sp_name); | |
7734 HL_TABLE()[idx].sg_gui_sp_name = NULL; | |
7 | 7735 gui_mch_free_font(HL_TABLE()[idx].sg_font); |
7736 HL_TABLE()[idx].sg_font = NOFONT; | |
7737 # ifdef FEAT_XFONTSET | |
7738 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
7739 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
7740 # endif | |
7741 vim_free(HL_TABLE()[idx].sg_font_name); | |
7742 HL_TABLE()[idx].sg_font_name = NULL; | |
7743 HL_TABLE()[idx].sg_gui_attr = 0; | |
7744 #endif | |
448 | 7745 #ifdef FEAT_EVAL |
7746 /* Clear the script ID only when there is no link, since that is not | |
7747 * cleared. */ | |
7748 if (HL_TABLE()[idx].sg_link == 0) | |
7749 HL_TABLE()[idx].sg_scriptID = 0; | |
7750 #endif | |
7 | 7751 } |
7752 | |
7753 #if defined(FEAT_GUI) || defined(PROTO) | |
7754 /* | |
7755 * Set the normal foreground and background colors according to the "Normal" | |
2020 | 7756 * highlighting group. For X11 also set "Menu", "Scrollbar", and |
7 | 7757 * "Tooltip" colors. |
7758 */ | |
7759 void | |
7760 set_normal_colors() | |
7761 { | |
7762 if (set_group_colors((char_u *)"Normal", | |
205 | 7763 &gui.norm_pixel, &gui.back_pixel, |
7764 FALSE, TRUE, FALSE)) | |
7 | 7765 { |
7766 gui_mch_new_colors(); | |
7767 must_redraw = CLEAR; | |
7768 } | |
7769 #ifdef FEAT_GUI_X11 | |
7770 if (set_group_colors((char_u *)"Menu", | |
205 | 7771 &gui.menu_fg_pixel, &gui.menu_bg_pixel, |
7772 TRUE, FALSE, FALSE)) | |
7 | 7773 { |
7774 # ifdef FEAT_MENU | |
7775 gui_mch_new_menu_colors(); | |
7776 # endif | |
7777 must_redraw = CLEAR; | |
7778 } | |
7779 # ifdef FEAT_BEVAL | |
7780 if (set_group_colors((char_u *)"Tooltip", | |
7781 &gui.tooltip_fg_pixel, &gui.tooltip_bg_pixel, | |
7782 FALSE, FALSE, TRUE)) | |
7783 { | |
7784 # ifdef FEAT_TOOLBAR | |
7785 gui_mch_new_tooltip_colors(); | |
7786 # endif | |
7787 must_redraw = CLEAR; | |
7788 } | |
7789 #endif | |
7790 if (set_group_colors((char_u *)"Scrollbar", | |
205 | 7791 &gui.scroll_fg_pixel, &gui.scroll_bg_pixel, |
7792 FALSE, FALSE, FALSE)) | |
7 | 7793 { |
7794 gui_new_scrollbar_colors(); | |
7795 must_redraw = CLEAR; | |
7796 } | |
7797 #endif | |
7798 } | |
7799 | |
7800 /* | |
7801 * Set the colors for "Normal", "Menu", "Tooltip" or "Scrollbar". | |
7802 */ | |
7803 static int | |
7804 set_group_colors(name, fgp, bgp, do_menu, use_norm, do_tooltip) | |
7805 char_u *name; | |
7806 guicolor_T *fgp; | |
7807 guicolor_T *bgp; | |
7808 int do_menu; | |
7809 int use_norm; | |
7810 int do_tooltip; | |
7811 { | |
7812 int idx; | |
7813 | |
7814 idx = syn_name2id(name) - 1; | |
7815 if (idx >= 0) | |
7816 { | |
7817 gui_do_one_color(idx, do_menu, do_tooltip); | |
7818 | |
7819 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR) | |
7820 *fgp = HL_TABLE()[idx].sg_gui_fg; | |
7821 else if (use_norm) | |
7822 *fgp = gui.def_norm_pixel; | |
7823 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR) | |
7824 *bgp = HL_TABLE()[idx].sg_gui_bg; | |
7825 else if (use_norm) | |
7826 *bgp = gui.def_back_pixel; | |
7827 return TRUE; | |
7828 } | |
7829 return FALSE; | |
7830 } | |
7831 | |
7832 /* | |
7833 * Get the font of the "Normal" group. | |
7834 * Returns "" when it's not found or not set. | |
7835 */ | |
7836 char_u * | |
7837 hl_get_font_name() | |
7838 { | |
7839 int id; | |
7840 char_u *s; | |
7841 | |
7842 id = syn_name2id((char_u *)"Normal"); | |
7843 if (id > 0) | |
7844 { | |
7845 s = HL_TABLE()[id - 1].sg_font_name; | |
7846 if (s != NULL) | |
7847 return s; | |
7848 } | |
7849 return (char_u *)""; | |
7850 } | |
7851 | |
7852 /* | |
7853 * Set font for "Normal" group. Called by gui_mch_init_font() when a font has | |
7854 * actually chosen to be used. | |
7855 */ | |
7856 void | |
7857 hl_set_font_name(font_name) | |
7858 char_u *font_name; | |
7859 { | |
7860 int id; | |
7861 | |
7862 id = syn_name2id((char_u *)"Normal"); | |
7863 if (id > 0) | |
7864 { | |
7865 vim_free(HL_TABLE()[id - 1].sg_font_name); | |
7866 HL_TABLE()[id - 1].sg_font_name = vim_strsave(font_name); | |
7867 } | |
7868 } | |
7869 | |
7870 /* | |
7871 * Set background color for "Normal" group. Called by gui_set_bg_color() | |
7872 * when the color is known. | |
7873 */ | |
7874 void | |
7875 hl_set_bg_color_name(name) | |
7876 char_u *name; /* must have been allocated */ | |
7877 { | |
7878 int id; | |
7879 | |
7880 if (name != NULL) | |
7881 { | |
7882 id = syn_name2id((char_u *)"Normal"); | |
7883 if (id > 0) | |
7884 { | |
7885 vim_free(HL_TABLE()[id - 1].sg_gui_bg_name); | |
7886 HL_TABLE()[id - 1].sg_gui_bg_name = name; | |
7887 } | |
7888 } | |
7889 } | |
7890 | |
7891 /* | |
7892 * Set foreground color for "Normal" group. Called by gui_set_fg_color() | |
7893 * when the color is known. | |
7894 */ | |
7895 void | |
7896 hl_set_fg_color_name(name) | |
7897 char_u *name; /* must have been allocated */ | |
7898 { | |
7899 int id; | |
7900 | |
7901 if (name != NULL) | |
7902 { | |
7903 id = syn_name2id((char_u *)"Normal"); | |
7904 if (id > 0) | |
7905 { | |
7906 vim_free(HL_TABLE()[id - 1].sg_gui_fg_name); | |
7907 HL_TABLE()[id - 1].sg_gui_fg_name = name; | |
7908 } | |
7909 } | |
7910 } | |
7911 | |
7912 /* | |
7913 * Return the handle for a color name. | |
7914 * Returns INVALCOLOR when failed. | |
7915 */ | |
7916 static guicolor_T | |
7917 color_name2handle(name) | |
7918 char_u *name; | |
7919 { | |
7920 if (STRCMP(name, "NONE") == 0) | |
7921 return INVALCOLOR; | |
7922 | |
7923 if (STRICMP(name, "fg") == 0 || STRICMP(name, "foreground") == 0) | |
7924 return gui.norm_pixel; | |
7925 if (STRICMP(name, "bg") == 0 || STRICMP(name, "background") == 0) | |
7926 return gui.back_pixel; | |
7927 | |
7928 return gui_get_color(name); | |
7929 } | |
7930 | |
7931 /* | |
7932 * Return the handle for a font name. | |
7933 * Returns NOFONT when failed. | |
7934 */ | |
7935 static GuiFont | |
7936 font_name2handle(name) | |
7937 char_u *name; | |
7938 { | |
7939 if (STRCMP(name, "NONE") == 0) | |
7940 return NOFONT; | |
7941 | |
7942 return gui_mch_get_font(name, TRUE); | |
7943 } | |
7944 | |
7945 # ifdef FEAT_XFONTSET | |
7946 /* | |
7947 * Return the handle for a fontset name. | |
7948 * Returns NOFONTSET when failed. | |
7949 */ | |
7950 static GuiFontset | |
7951 fontset_name2handle(name, fixed_width) | |
7952 char_u *name; | |
7953 int fixed_width; | |
7954 { | |
7955 if (STRCMP(name, "NONE") == 0) | |
7956 return NOFONTSET; | |
7957 | |
7958 return gui_mch_get_fontset(name, TRUE, fixed_width); | |
7959 } | |
7960 # endif | |
7961 | |
7962 /* | |
7963 * Get the font or fontset for one highlight group. | |
7964 */ | |
7965 static void | |
7966 hl_do_font(idx, arg, do_normal, do_menu, do_tooltip) | |
7967 int idx; | |
7968 char_u *arg; | |
1883 | 7969 int do_normal; /* set normal font */ |
7970 int do_menu UNUSED; /* set menu font */ | |
7971 int do_tooltip UNUSED; /* set tooltip font */ | |
7 | 7972 { |
7973 # ifdef FEAT_XFONTSET | |
7974 /* If 'guifontset' is not empty, first try using the name as a | |
7975 * fontset. If that doesn't work, use it as a font name. */ | |
7976 if (*p_guifontset != NUL | |
7977 # ifdef FONTSET_ALWAYS | |
7978 || do_menu | |
7979 # endif | |
7980 # ifdef FEAT_BEVAL_TIP | |
7981 /* In Athena & Motif, the Tooltip highlight group is always a fontset */ | |
7982 || do_tooltip | |
7983 # endif | |
7984 ) | |
7985 HL_TABLE()[idx].sg_fontset = fontset_name2handle(arg, 0 | |
7986 # ifdef FONTSET_ALWAYS | |
7987 || do_menu | |
7988 # endif | |
7989 # ifdef FEAT_BEVAL_TIP | |
7990 || do_tooltip | |
7991 # endif | |
7992 ); | |
7993 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) | |
7994 { | |
7995 /* If it worked and it's the Normal group, use it as the | |
7996 * normal fontset. Same for the Menu group. */ | |
7997 if (do_normal) | |
7998 gui_init_font(arg, TRUE); | |
7999 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8000 if (do_menu) | |
8001 { | |
8002 # ifdef FONTSET_ALWAYS | |
8003 gui.menu_fontset = HL_TABLE()[idx].sg_fontset; | |
8004 # else | |
8005 /* YIKES! This is a bug waiting to crash the program */ | |
8006 gui.menu_font = HL_TABLE()[idx].sg_fontset; | |
8007 # endif | |
8008 gui_mch_new_menu_font(); | |
8009 } | |
8010 # ifdef FEAT_BEVAL | |
8011 if (do_tooltip) | |
8012 { | |
8013 /* The Athena widget set cannot currently handle switching between | |
8014 * displaying a single font and a fontset. | |
8015 * If the XtNinternational resource is set to True at widget | |
1222 | 8016 * creation, then a fontset is always used, otherwise an |
7 | 8017 * XFontStruct is used. |
8018 */ | |
8019 gui.tooltip_fontset = (XFontSet)HL_TABLE()[idx].sg_fontset; | |
8020 gui_mch_new_tooltip_font(); | |
8021 } | |
8022 # endif | |
8023 # endif | |
8024 } | |
8025 else | |
8026 # endif | |
8027 { | |
8028 HL_TABLE()[idx].sg_font = font_name2handle(arg); | |
8029 /* If it worked and it's the Normal group, use it as the | |
8030 * normal font. Same for the Menu group. */ | |
8031 if (HL_TABLE()[idx].sg_font != NOFONT) | |
8032 { | |
8033 if (do_normal) | |
8034 gui_init_font(arg, FALSE); | |
8035 #ifndef FONTSET_ALWAYS | |
8036 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8037 if (do_menu) | |
8038 { | |
8039 gui.menu_font = HL_TABLE()[idx].sg_font; | |
8040 gui_mch_new_menu_font(); | |
8041 } | |
8042 # endif | |
8043 #endif | |
8044 } | |
8045 } | |
8046 } | |
8047 | |
8048 #endif /* FEAT_GUI */ | |
8049 | |
8050 /* | |
8051 * Table with the specifications for an attribute number. | |
8052 * Note that this table is used by ALL buffers. This is required because the | |
8053 * GUI can redraw at any time for any buffer. | |
8054 */ | |
298 | 8055 static garray_T term_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8056 |
8057 #define TERM_ATTR_ENTRY(idx) ((attrentry_T *)term_attr_table.ga_data)[idx] | |
8058 | |
298 | 8059 static garray_T cterm_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8060 |
8061 #define CTERM_ATTR_ENTRY(idx) ((attrentry_T *)cterm_attr_table.ga_data)[idx] | |
8062 | |
8063 #ifdef FEAT_GUI | |
298 | 8064 static garray_T gui_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8065 |
8066 #define GUI_ATTR_ENTRY(idx) ((attrentry_T *)gui_attr_table.ga_data)[idx] | |
8067 #endif | |
8068 | |
8069 /* | |
8070 * Return the attr number for a set of colors and font. | |
8071 * Add a new entry to the term_attr_table, cterm_attr_table or gui_attr_table | |
8072 * if the combination is new. | |
8073 * Return 0 for error (no more room). | |
8074 */ | |
8075 static int | |
8076 get_attr_entry(table, aep) | |
8077 garray_T *table; | |
8078 attrentry_T *aep; | |
8079 { | |
8080 int i; | |
359 | 8081 attrentry_T *taep; |
7 | 8082 static int recursive = FALSE; |
8083 | |
8084 /* | |
8085 * Init the table, in case it wasn't done yet. | |
8086 */ | |
8087 table->ga_itemsize = sizeof(attrentry_T); | |
8088 table->ga_growsize = 7; | |
8089 | |
8090 /* | |
8091 * Try to find an entry with the same specifications. | |
8092 */ | |
8093 for (i = 0; i < table->ga_len; ++i) | |
8094 { | |
359 | 8095 taep = &(((attrentry_T *)table->ga_data)[i]); |
8096 if ( aep->ae_attr == taep->ae_attr | |
7 | 8097 && ( |
8098 #ifdef FEAT_GUI | |
8099 (table == &gui_attr_table | |
359 | 8100 && (aep->ae_u.gui.fg_color == taep->ae_u.gui.fg_color |
8101 && aep->ae_u.gui.bg_color | |
8102 == taep->ae_u.gui.bg_color | |
8103 && aep->ae_u.gui.sp_color | |
8104 == taep->ae_u.gui.sp_color | |
8105 && aep->ae_u.gui.font == taep->ae_u.gui.font | |
7 | 8106 # ifdef FEAT_XFONTSET |
359 | 8107 && aep->ae_u.gui.fontset == taep->ae_u.gui.fontset |
7 | 8108 # endif |
8109 )) | |
8110 || | |
8111 #endif | |
8112 (table == &term_attr_table | |
359 | 8113 && (aep->ae_u.term.start == NULL) |
8114 == (taep->ae_u.term.start == NULL) | |
7 | 8115 && (aep->ae_u.term.start == NULL |
8116 || STRCMP(aep->ae_u.term.start, | |
359 | 8117 taep->ae_u.term.start) == 0) |
8118 && (aep->ae_u.term.stop == NULL) | |
8119 == (taep->ae_u.term.stop == NULL) | |
7 | 8120 && (aep->ae_u.term.stop == NULL |
8121 || STRCMP(aep->ae_u.term.stop, | |
359 | 8122 taep->ae_u.term.stop) == 0)) |
7 | 8123 || (table == &cterm_attr_table |
359 | 8124 && aep->ae_u.cterm.fg_color |
8125 == taep->ae_u.cterm.fg_color | |
8126 && aep->ae_u.cterm.bg_color | |
8127 == taep->ae_u.cterm.bg_color) | |
7 | 8128 )) |
8129 | |
8130 return i + ATTR_OFF; | |
8131 } | |
8132 | |
271 | 8133 if (table->ga_len + ATTR_OFF > MAX_TYPENR) |
7 | 8134 { |
8135 /* | |
8136 * Running out of attribute entries! remove all attributes, and | |
8137 * compute new ones for all groups. | |
8138 * When called recursively, we are really out of numbers. | |
8139 */ | |
8140 if (recursive) | |
8141 { | |
8142 EMSG(_("E424: Too many different highlighting attributes in use")); | |
8143 return 0; | |
8144 } | |
8145 recursive = TRUE; | |
8146 | |
359 | 8147 clear_hl_tables(); |
8148 | |
7 | 8149 must_redraw = CLEAR; |
8150 | |
8151 for (i = 0; i < highlight_ga.ga_len; ++i) | |
8152 set_hl_attr(i); | |
8153 | |
8154 recursive = FALSE; | |
8155 } | |
8156 | |
8157 /* | |
8158 * This is a new combination of colors and font, add an entry. | |
8159 */ | |
8160 if (ga_grow(table, 1) == FAIL) | |
8161 return 0; | |
8162 | |
359 | 8163 taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); |
8164 vim_memset(taep, 0, sizeof(attrentry_T)); | |
8165 taep->ae_attr = aep->ae_attr; | |
7 | 8166 #ifdef FEAT_GUI |
8167 if (table == &gui_attr_table) | |
8168 { | |
359 | 8169 taep->ae_u.gui.fg_color = aep->ae_u.gui.fg_color; |
8170 taep->ae_u.gui.bg_color = aep->ae_u.gui.bg_color; | |
8171 taep->ae_u.gui.sp_color = aep->ae_u.gui.sp_color; | |
8172 taep->ae_u.gui.font = aep->ae_u.gui.font; | |
7 | 8173 # ifdef FEAT_XFONTSET |
359 | 8174 taep->ae_u.gui.fontset = aep->ae_u.gui.fontset; |
7 | 8175 # endif |
8176 } | |
8177 #endif | |
8178 if (table == &term_attr_table) | |
8179 { | |
8180 if (aep->ae_u.term.start == NULL) | |
359 | 8181 taep->ae_u.term.start = NULL; |
7 | 8182 else |
359 | 8183 taep->ae_u.term.start = vim_strsave(aep->ae_u.term.start); |
7 | 8184 if (aep->ae_u.term.stop == NULL) |
359 | 8185 taep->ae_u.term.stop = NULL; |
7 | 8186 else |
359 | 8187 taep->ae_u.term.stop = vim_strsave(aep->ae_u.term.stop); |
7 | 8188 } |
8189 else if (table == &cterm_attr_table) | |
8190 { | |
359 | 8191 taep->ae_u.cterm.fg_color = aep->ae_u.cterm.fg_color; |
8192 taep->ae_u.cterm.bg_color = aep->ae_u.cterm.bg_color; | |
7 | 8193 } |
8194 ++table->ga_len; | |
8195 return (table->ga_len - 1 + ATTR_OFF); | |
8196 } | |
8197 | |
359 | 8198 /* |
8199 * Clear all highlight tables. | |
8200 */ | |
8201 void | |
8202 clear_hl_tables() | |
8203 { | |
8204 int i; | |
8205 attrentry_T *taep; | |
8206 | |
8207 #ifdef FEAT_GUI | |
8208 ga_clear(&gui_attr_table); | |
8209 #endif | |
8210 for (i = 0; i < term_attr_table.ga_len; ++i) | |
8211 { | |
8212 taep = &(((attrentry_T *)term_attr_table.ga_data)[i]); | |
8213 vim_free(taep->ae_u.term.start); | |
8214 vim_free(taep->ae_u.term.stop); | |
8215 } | |
8216 ga_clear(&term_attr_table); | |
8217 ga_clear(&cterm_attr_table); | |
8218 } | |
8219 | |
745 | 8220 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL) || defined(PROTO) |
221 | 8221 /* |
348 | 8222 * Combine special attributes (e.g., for spelling) with other attributes |
8223 * (e.g., for syntax highlighting). | |
8224 * "prim_attr" overrules "char_attr". | |
221 | 8225 * This creates a new group when required. |
8226 * Since we expect there to be few spelling mistakes we don't cache the | |
8227 * result. | |
8228 * Return the resulting attributes. | |
8229 */ | |
8230 int | |
348 | 8231 hl_combine_attr(char_attr, prim_attr) |
221 | 8232 int char_attr; |
348 | 8233 int prim_attr; |
221 | 8234 { |
8235 attrentry_T *char_aep = NULL; | |
8236 attrentry_T *spell_aep; | |
8237 attrentry_T new_en; | |
8238 | |
8239 if (char_attr == 0) | |
348 | 8240 return prim_attr; |
8241 if (char_attr <= HL_ALL && prim_attr <= HL_ALL) | |
8242 return char_attr | prim_attr; | |
221 | 8243 #ifdef FEAT_GUI |
8244 if (gui.in_use) | |
8245 { | |
8246 if (char_attr > HL_ALL) | |
8247 char_aep = syn_gui_attr2entry(char_attr); | |
8248 if (char_aep != NULL) | |
8249 new_en = *char_aep; | |
8250 else | |
8251 { | |
8252 vim_memset(&new_en, 0, sizeof(new_en)); | |
548 | 8253 new_en.ae_u.gui.fg_color = INVALCOLOR; |
8254 new_en.ae_u.gui.bg_color = INVALCOLOR; | |
8255 new_en.ae_u.gui.sp_color = INVALCOLOR; | |
221 | 8256 if (char_attr <= HL_ALL) |
8257 new_en.ae_attr = char_attr; | |
8258 } | |
8259 | |
348 | 8260 if (prim_attr <= HL_ALL) |
8261 new_en.ae_attr |= prim_attr; | |
221 | 8262 else |
8263 { | |
348 | 8264 spell_aep = syn_gui_attr2entry(prim_attr); |
221 | 8265 if (spell_aep != NULL) |
8266 { | |
8267 new_en.ae_attr |= spell_aep->ae_attr; | |
8268 if (spell_aep->ae_u.gui.fg_color != INVALCOLOR) | |
8269 new_en.ae_u.gui.fg_color = spell_aep->ae_u.gui.fg_color; | |
8270 if (spell_aep->ae_u.gui.bg_color != INVALCOLOR) | |
8271 new_en.ae_u.gui.bg_color = spell_aep->ae_u.gui.bg_color; | |
8272 if (spell_aep->ae_u.gui.sp_color != INVALCOLOR) | |
8273 new_en.ae_u.gui.sp_color = spell_aep->ae_u.gui.sp_color; | |
8274 if (spell_aep->ae_u.gui.font != NOFONT) | |
8275 new_en.ae_u.gui.font = spell_aep->ae_u.gui.font; | |
8276 # ifdef FEAT_XFONTSET | |
8277 if (spell_aep->ae_u.gui.fontset != NOFONTSET) | |
8278 new_en.ae_u.gui.fontset = spell_aep->ae_u.gui.fontset; | |
8279 # endif | |
8280 } | |
8281 } | |
8282 return get_attr_entry(&gui_attr_table, &new_en); | |
8283 } | |
8284 #endif | |
8285 | |
8286 if (t_colors > 1) | |
8287 { | |
8288 if (char_attr > HL_ALL) | |
8289 char_aep = syn_cterm_attr2entry(char_attr); | |
8290 if (char_aep != NULL) | |
8291 new_en = *char_aep; | |
8292 else | |
8293 { | |
8294 vim_memset(&new_en, 0, sizeof(new_en)); | |
8295 if (char_attr <= HL_ALL) | |
8296 new_en.ae_attr = char_attr; | |
8297 } | |
8298 | |
348 | 8299 if (prim_attr <= HL_ALL) |
8300 new_en.ae_attr |= prim_attr; | |
221 | 8301 else |
8302 { | |
348 | 8303 spell_aep = syn_cterm_attr2entry(prim_attr); |
221 | 8304 if (spell_aep != NULL) |
8305 { | |
8306 new_en.ae_attr |= spell_aep->ae_attr; | |
8307 if (spell_aep->ae_u.cterm.fg_color > 0) | |
8308 new_en.ae_u.cterm.fg_color = spell_aep->ae_u.cterm.fg_color; | |
8309 if (spell_aep->ae_u.cterm.bg_color > 0) | |
8310 new_en.ae_u.cterm.bg_color = spell_aep->ae_u.cterm.bg_color; | |
8311 } | |
8312 } | |
8313 return get_attr_entry(&cterm_attr_table, &new_en); | |
8314 } | |
8315 | |
8316 if (char_attr > HL_ALL) | |
8317 char_aep = syn_term_attr2entry(char_attr); | |
8318 if (char_aep != NULL) | |
8319 new_en = *char_aep; | |
8320 else | |
8321 { | |
8322 vim_memset(&new_en, 0, sizeof(new_en)); | |
8323 if (char_attr <= HL_ALL) | |
8324 new_en.ae_attr = char_attr; | |
8325 } | |
8326 | |
348 | 8327 if (prim_attr <= HL_ALL) |
8328 new_en.ae_attr |= prim_attr; | |
221 | 8329 else |
8330 { | |
607 | 8331 spell_aep = syn_term_attr2entry(prim_attr); |
221 | 8332 if (spell_aep != NULL) |
8333 { | |
8334 new_en.ae_attr |= spell_aep->ae_attr; | |
8335 if (spell_aep->ae_u.term.start != NULL) | |
8336 { | |
8337 new_en.ae_u.term.start = spell_aep->ae_u.term.start; | |
8338 new_en.ae_u.term.stop = spell_aep->ae_u.term.stop; | |
8339 } | |
8340 } | |
8341 } | |
8342 return get_attr_entry(&term_attr_table, &new_en); | |
8343 } | |
8344 #endif | |
8345 | |
7 | 8346 #ifdef FEAT_GUI |
8347 | |
8348 attrentry_T * | |
8349 syn_gui_attr2entry(attr) | |
8350 int attr; | |
8351 { | |
8352 attr -= ATTR_OFF; | |
8353 if (attr >= gui_attr_table.ga_len) /* did ":syntax clear" */ | |
8354 return NULL; | |
8355 return &(GUI_ATTR_ENTRY(attr)); | |
8356 } | |
8357 #endif /* FEAT_GUI */ | |
8358 | |
745 | 8359 /* |
8360 * Get the highlight attributes (HL_BOLD etc.) from an attribute nr. | |
8361 * Only to be used when "attr" > HL_ALL. | |
8362 */ | |
8363 int | |
8364 syn_attr2attr(attr) | |
8365 int attr; | |
8366 { | |
8367 attrentry_T *aep; | |
8368 | |
8369 #ifdef FEAT_GUI | |
8370 if (gui.in_use) | |
8371 aep = syn_gui_attr2entry(attr); | |
8372 else | |
8373 #endif | |
8374 if (t_colors > 1) | |
8375 aep = syn_cterm_attr2entry(attr); | |
8376 else | |
8377 aep = syn_term_attr2entry(attr); | |
8378 | |
8379 if (aep == NULL) /* highlighting not set */ | |
8380 return 0; | |
8381 return aep->ae_attr; | |
8382 } | |
8383 | |
8384 | |
7 | 8385 attrentry_T * |
8386 syn_term_attr2entry(attr) | |
8387 int attr; | |
8388 { | |
8389 attr -= ATTR_OFF; | |
8390 if (attr >= term_attr_table.ga_len) /* did ":syntax clear" */ | |
8391 return NULL; | |
8392 return &(TERM_ATTR_ENTRY(attr)); | |
8393 } | |
8394 | |
8395 attrentry_T * | |
8396 syn_cterm_attr2entry(attr) | |
8397 int attr; | |
8398 { | |
8399 attr -= ATTR_OFF; | |
8400 if (attr >= cterm_attr_table.ga_len) /* did ":syntax clear" */ | |
8401 return NULL; | |
8402 return &(CTERM_ATTR_ENTRY(attr)); | |
8403 } | |
8404 | |
8405 #define LIST_ATTR 1 | |
8406 #define LIST_STRING 2 | |
8407 #define LIST_INT 3 | |
8408 | |
8409 static void | |
8410 highlight_list_one(id) | |
8411 int id; | |
8412 { | |
8413 struct hl_group *sgp; | |
8414 int didh = FALSE; | |
8415 | |
8416 sgp = &HL_TABLE()[id - 1]; /* index is ID minus one */ | |
8417 | |
8418 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8419 sgp->sg_term, NULL, "term"); | |
8420 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8421 0, sgp->sg_start, "start"); | |
8422 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8423 0, sgp->sg_stop, "stop"); | |
8424 | |
8425 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8426 sgp->sg_cterm, NULL, "cterm"); | |
8427 didh = highlight_list_arg(id, didh, LIST_INT, | |
8428 sgp->sg_cterm_fg, NULL, "ctermfg"); | |
8429 didh = highlight_list_arg(id, didh, LIST_INT, | |
8430 sgp->sg_cterm_bg, NULL, "ctermbg"); | |
8431 | |
8432 #ifdef FEAT_GUI | |
8433 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8434 sgp->sg_gui, NULL, "gui"); | |
8435 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8436 0, sgp->sg_gui_fg_name, "guifg"); | |
8437 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8438 0, sgp->sg_gui_bg_name, "guibg"); | |
8439 didh = highlight_list_arg(id, didh, LIST_STRING, | |
301 | 8440 0, sgp->sg_gui_sp_name, "guisp"); |
8441 didh = highlight_list_arg(id, didh, LIST_STRING, | |
7 | 8442 0, sgp->sg_font_name, "font"); |
8443 #endif | |
8444 | |
448 | 8445 if (sgp->sg_link && !got_int) |
7 | 8446 { |
8447 (void)syn_list_header(didh, 9999, id); | |
448 | 8448 didh = TRUE; |
7 | 8449 msg_puts_attr((char_u *)"links to", hl_attr(HLF_D)); |
8450 msg_putchar(' '); | |
8451 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
8452 } | |
448 | 8453 |
694 | 8454 if (!didh) |
8455 highlight_list_arg(id, didh, LIST_STRING, 0, (char_u *)"cleared", ""); | |
448 | 8456 #ifdef FEAT_EVAL |
694 | 8457 if (p_verbose > 0) |
448 | 8458 last_set_msg(sgp->sg_scriptID); |
8459 #endif | |
7 | 8460 } |
8461 | |
8462 static int | |
8463 highlight_list_arg(id, didh, type, iarg, sarg, name) | |
8464 int id; | |
8465 int didh; | |
8466 int type; | |
8467 int iarg; | |
8468 char_u *sarg; | |
8469 char *name; | |
8470 { | |
8471 char_u buf[100]; | |
8472 char_u *ts; | |
8473 int i; | |
8474 | |
448 | 8475 if (got_int) |
8476 return FALSE; | |
7 | 8477 if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) |
8478 { | |
8479 ts = buf; | |
8480 if (type == LIST_INT) | |
8481 sprintf((char *)buf, "%d", iarg - 1); | |
8482 else if (type == LIST_STRING) | |
8483 ts = sarg; | |
8484 else /* type == LIST_ATTR */ | |
8485 { | |
8486 buf[0] = NUL; | |
8487 for (i = 0; hl_attr_table[i] != 0; ++i) | |
8488 { | |
8489 if (iarg & hl_attr_table[i]) | |
8490 { | |
8491 if (buf[0] != NUL) | |
8492 STRCAT(buf, ","); | |
8493 STRCAT(buf, hl_name_table[i]); | |
8494 iarg &= ~hl_attr_table[i]; /* don't want "inverse" */ | |
8495 } | |
8496 } | |
8497 } | |
8498 | |
8499 (void)syn_list_header(didh, | |
8500 (int)(vim_strsize(ts) + STRLEN(name) + 1), id); | |
8501 didh = TRUE; | |
448 | 8502 if (!got_int) |
8503 { | |
694 | 8504 if (*name != NUL) |
8505 { | |
8506 MSG_PUTS_ATTR(name, hl_attr(HLF_D)); | |
8507 MSG_PUTS_ATTR("=", hl_attr(HLF_D)); | |
8508 } | |
448 | 8509 msg_outtrans(ts); |
8510 } | |
7 | 8511 } |
8512 return didh; | |
8513 } | |
8514 | |
8515 #if (((defined(FEAT_EVAL) || defined(FEAT_PRINTER))) && defined(FEAT_SYN_HL)) || defined(PROTO) | |
8516 /* | |
8517 * Return "1" if highlight group "id" has attribute "flag". | |
8518 * Return NULL otherwise. | |
8519 */ | |
8520 char_u * | |
8521 highlight_has_attr(id, flag, modec) | |
8522 int id; | |
8523 int flag; | |
8524 int modec; /* 'g' for GUI, 'c' for cterm, 't' for term */ | |
8525 { | |
8526 int attr; | |
8527 | |
8528 if (id <= 0 || id > highlight_ga.ga_len) | |
8529 return NULL; | |
8530 | |
8531 #ifdef FEAT_GUI | |
8532 if (modec == 'g') | |
8533 attr = HL_TABLE()[id - 1].sg_gui; | |
8534 else | |
8535 #endif | |
8536 if (modec == 'c') | |
8537 attr = HL_TABLE()[id - 1].sg_cterm; | |
8538 else | |
8539 attr = HL_TABLE()[id - 1].sg_term; | |
8540 | |
8541 if (attr & flag) | |
8542 return (char_u *)"1"; | |
8543 return NULL; | |
8544 } | |
8545 #endif | |
8546 | |
8547 #if (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) || defined(PROTO) | |
8548 /* | |
8549 * Return color name of highlight group "id". | |
8550 */ | |
8551 char_u * | |
8552 highlight_color(id, what, modec) | |
8553 int id; | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8554 char_u *what; /* "font", "fg", "bg", "sp", "fg#", "bg#" or "sp#" */ |
7 | 8555 int modec; /* 'g' for GUI, 'c' for cterm, 't' for term */ |
8556 { | |
8557 static char_u name[20]; | |
8558 int n; | |
205 | 8559 int fg = FALSE; |
8560 # ifdef FEAT_GUI | |
8561 int sp = FALSE; | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8562 int font = FALSE; |
205 | 8563 # endif |
7 | 8564 |
8565 if (id <= 0 || id > highlight_ga.ga_len) | |
8566 return NULL; | |
8567 | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8568 if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g') |
7 | 8569 fg = TRUE; |
205 | 8570 # ifdef FEAT_GUI |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8571 else if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'o' |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8572 && TOLOWER_ASC(what[2]) == 'n' && TOLOWER_ASC(what[3]) == 't') |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8573 font = TRUE; |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8574 else if (TOLOWER_ASC(what[0]) == 's' && TOLOWER_ASC(what[1]) == 'p') |
205 | 8575 sp = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8576 else if (!(TOLOWER_ASC(what[0]) == 'b' && TOLOWER_ASC(what[1]) == 'g')) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8577 return NULL; |
7 | 8578 if (modec == 'g') |
8579 { | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8580 /* return font name */ |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8581 if (font) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8582 return HL_TABLE()[id - 1].sg_font_name; |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8583 |
7 | 8584 /* return #RRGGBB form (only possible when GUI is running) */ |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8585 if (gui.in_use && what[2] == '#') |
7 | 8586 { |
8587 guicolor_T color; | |
8588 long_u rgb; | |
8589 static char_u buf[10]; | |
8590 | |
8591 if (fg) | |
8592 color = HL_TABLE()[id - 1].sg_gui_fg; | |
205 | 8593 else if (sp) |
8594 color = HL_TABLE()[id - 1].sg_gui_sp; | |
7 | 8595 else |
8596 color = HL_TABLE()[id - 1].sg_gui_bg; | |
8597 if (color == INVALCOLOR) | |
8598 return NULL; | |
8599 rgb = gui_mch_get_rgb(color); | |
8600 sprintf((char *)buf, "#%02x%02x%02x", | |
8601 (unsigned)(rgb >> 16), | |
8602 (unsigned)(rgb >> 8) & 255, | |
8603 (unsigned)rgb & 255); | |
8604 return buf; | |
8605 } | |
8606 if (fg) | |
8607 return (HL_TABLE()[id - 1].sg_gui_fg_name); | |
205 | 8608 if (sp) |
8609 return (HL_TABLE()[id - 1].sg_gui_sp_name); | |
7 | 8610 return (HL_TABLE()[id - 1].sg_gui_bg_name); |
8611 } | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8612 if (font || sp) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
8613 return NULL; |
205 | 8614 # endif |
7 | 8615 if (modec == 'c') |
8616 { | |
8617 if (fg) | |
8618 n = HL_TABLE()[id - 1].sg_cterm_fg - 1; | |
8619 else | |
8620 n = HL_TABLE()[id - 1].sg_cterm_bg - 1; | |
8621 sprintf((char *)name, "%d", n); | |
8622 return name; | |
8623 } | |
8624 /* term doesn't have color */ | |
8625 return NULL; | |
8626 } | |
8627 #endif | |
8628 | |
8629 #if (defined(FEAT_SYN_HL) && defined(FEAT_GUI) && defined(FEAT_PRINTER)) \ | |
8630 || defined(PROTO) | |
8631 /* | |
8632 * Return color name of highlight group "id" as RGB value. | |
8633 */ | |
8634 long_u | |
8635 highlight_gui_color_rgb(id, fg) | |
8636 int id; | |
8637 int fg; /* TRUE = fg, FALSE = bg */ | |
8638 { | |
8639 guicolor_T color; | |
8640 | |
8641 if (id <= 0 || id > highlight_ga.ga_len) | |
8642 return 0L; | |
8643 | |
8644 if (fg) | |
8645 color = HL_TABLE()[id - 1].sg_gui_fg; | |
8646 else | |
8647 color = HL_TABLE()[id - 1].sg_gui_bg; | |
8648 | |
8649 if (color == INVALCOLOR) | |
8650 return 0L; | |
8651 | |
8652 return gui_mch_get_rgb(color); | |
8653 } | |
8654 #endif | |
8655 | |
8656 /* | |
8657 * Output the syntax list header. | |
8658 * Return TRUE when started a new line. | |
8659 */ | |
8660 static int | |
8661 syn_list_header(did_header, outlen, id) | |
8662 int did_header; /* did header already */ | |
8663 int outlen; /* length of string that comes */ | |
8664 int id; /* highlight group id */ | |
8665 { | |
8666 int endcol = 19; | |
8667 int newline = TRUE; | |
8668 | |
8669 if (!did_header) | |
8670 { | |
8671 msg_putchar('\n'); | |
448 | 8672 if (got_int) |
8673 return TRUE; | |
7 | 8674 msg_outtrans(HL_TABLE()[id - 1].sg_name); |
8675 endcol = 15; | |
8676 } | |
8677 else if (msg_col + outlen + 1 >= Columns) | |
448 | 8678 { |
7 | 8679 msg_putchar('\n'); |
448 | 8680 if (got_int) |
8681 return TRUE; | |
8682 } | |
7 | 8683 else |
8684 { | |
8685 if (msg_col >= endcol) /* wrap around is like starting a new line */ | |
8686 newline = FALSE; | |
8687 } | |
8688 | |
8689 if (msg_col >= endcol) /* output at least one space */ | |
8690 endcol = msg_col + 1; | |
8691 if (Columns <= endcol) /* avoid hang for tiny window */ | |
8692 endcol = Columns - 1; | |
8693 | |
8694 msg_advance(endcol); | |
8695 | |
8696 /* Show "xxx" with the attributes. */ | |
8697 if (!did_header) | |
8698 { | |
8699 msg_puts_attr((char_u *)"xxx", syn_id2attr(id)); | |
8700 msg_putchar(' '); | |
8701 } | |
8702 | |
8703 return newline; | |
8704 } | |
8705 | |
8706 /* | |
8707 * Set the attribute numbers for a highlight group. | |
8708 * Called after one of the attributes has changed. | |
8709 */ | |
8710 static void | |
8711 set_hl_attr(idx) | |
8712 int idx; /* index in array */ | |
8713 { | |
8714 attrentry_T at_en; | |
8715 struct hl_group *sgp = HL_TABLE() + idx; | |
8716 | |
8717 /* The "Normal" group doesn't need an attribute number */ | |
8718 if (sgp->sg_name_u != NULL && STRCMP(sgp->sg_name_u, "NORMAL") == 0) | |
8719 return; | |
8720 | |
8721 #ifdef FEAT_GUI | |
8722 /* | |
8723 * For the GUI mode: If there are other than "normal" highlighting | |
8724 * attributes, need to allocate an attr number. | |
8725 */ | |
8726 if (sgp->sg_gui_fg == INVALCOLOR | |
8727 && sgp->sg_gui_bg == INVALCOLOR | |
205 | 8728 && sgp->sg_gui_sp == INVALCOLOR |
7 | 8729 && sgp->sg_font == NOFONT |
8730 # ifdef FEAT_XFONTSET | |
8731 && sgp->sg_fontset == NOFONTSET | |
8732 # endif | |
8733 ) | |
8734 { | |
8735 sgp->sg_gui_attr = sgp->sg_gui; | |
8736 } | |
8737 else | |
8738 { | |
8739 at_en.ae_attr = sgp->sg_gui; | |
8740 at_en.ae_u.gui.fg_color = sgp->sg_gui_fg; | |
8741 at_en.ae_u.gui.bg_color = sgp->sg_gui_bg; | |
205 | 8742 at_en.ae_u.gui.sp_color = sgp->sg_gui_sp; |
7 | 8743 at_en.ae_u.gui.font = sgp->sg_font; |
8744 # ifdef FEAT_XFONTSET | |
8745 at_en.ae_u.gui.fontset = sgp->sg_fontset; | |
8746 # endif | |
8747 sgp->sg_gui_attr = get_attr_entry(&gui_attr_table, &at_en); | |
8748 } | |
8749 #endif | |
8750 /* | |
8751 * For the term mode: If there are other than "normal" highlighting | |
8752 * attributes, need to allocate an attr number. | |
8753 */ | |
8754 if (sgp->sg_start == NULL && sgp->sg_stop == NULL) | |
8755 sgp->sg_term_attr = sgp->sg_term; | |
8756 else | |
8757 { | |
8758 at_en.ae_attr = sgp->sg_term; | |
8759 at_en.ae_u.term.start = sgp->sg_start; | |
8760 at_en.ae_u.term.stop = sgp->sg_stop; | |
8761 sgp->sg_term_attr = get_attr_entry(&term_attr_table, &at_en); | |
8762 } | |
8763 | |
8764 /* | |
8765 * For the color term mode: If there are other than "normal" | |
8766 * highlighting attributes, need to allocate an attr number. | |
8767 */ | |
8768 if (sgp->sg_cterm_fg == 0 && sgp->sg_cterm_bg == 0) | |
8769 sgp->sg_cterm_attr = sgp->sg_cterm; | |
8770 else | |
8771 { | |
8772 at_en.ae_attr = sgp->sg_cterm; | |
8773 at_en.ae_u.cterm.fg_color = sgp->sg_cterm_fg; | |
8774 at_en.ae_u.cterm.bg_color = sgp->sg_cterm_bg; | |
8775 sgp->sg_cterm_attr = get_attr_entry(&cterm_attr_table, &at_en); | |
8776 } | |
8777 } | |
8778 | |
8779 /* | |
8780 * Lookup a highlight group name and return it's ID. | |
8781 * If it is not found, 0 is returned. | |
8782 */ | |
8783 int | |
8784 syn_name2id(name) | |
8785 char_u *name; | |
8786 { | |
8787 int i; | |
8788 char_u name_u[200]; | |
8789 | |
8790 /* Avoid using stricmp() too much, it's slow on some systems */ | |
8791 /* Avoid alloc()/free(), these are slow too. ID names over 200 chars | |
8792 * don't deserve to be found! */ | |
419 | 8793 vim_strncpy(name_u, name, 199); |
7 | 8794 vim_strup(name_u); |
8795 for (i = highlight_ga.ga_len; --i >= 0; ) | |
8796 if (HL_TABLE()[i].sg_name_u != NULL | |
8797 && STRCMP(name_u, HL_TABLE()[i].sg_name_u) == 0) | |
8798 break; | |
8799 return i + 1; | |
8800 } | |
8801 | |
8802 #if defined(FEAT_EVAL) || defined(PROTO) | |
8803 /* | |
8804 * Return TRUE if highlight group "name" exists. | |
8805 */ | |
8806 int | |
8807 highlight_exists(name) | |
8808 char_u *name; | |
8809 { | |
8810 return (syn_name2id(name) > 0); | |
8811 } | |
819 | 8812 |
8813 # if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) | |
8814 /* | |
8815 * Return the name of highlight group "id". | |
8816 * When not a valid ID return an empty string. | |
8817 */ | |
8818 char_u * | |
8819 syn_id2name(id) | |
8820 int id; | |
8821 { | |
1326 | 8822 if (id <= 0 || id > highlight_ga.ga_len) |
819 | 8823 return (char_u *)""; |
8824 return HL_TABLE()[id - 1].sg_name; | |
8825 } | |
8826 # endif | |
7 | 8827 #endif |
8828 | |
8829 /* | |
8830 * Like syn_name2id(), but take a pointer + length argument. | |
8831 */ | |
8832 int | |
8833 syn_namen2id(linep, len) | |
8834 char_u *linep; | |
8835 int len; | |
8836 { | |
8837 char_u *name; | |
8838 int id = 0; | |
8839 | |
8840 name = vim_strnsave(linep, len); | |
8841 if (name != NULL) | |
8842 { | |
8843 id = syn_name2id(name); | |
8844 vim_free(name); | |
8845 } | |
8846 return id; | |
8847 } | |
8848 | |
8849 /* | |
8850 * Find highlight group name in the table and return it's ID. | |
8851 * The argument is a pointer to the name and the length of the name. | |
8852 * If it doesn't exist yet, a new entry is created. | |
8853 * Return 0 for failure. | |
8854 */ | |
8855 int | |
8856 syn_check_group(pp, len) | |
8857 char_u *pp; | |
8858 int len; | |
8859 { | |
8860 int id; | |
8861 char_u *name; | |
8862 | |
8863 name = vim_strnsave(pp, len); | |
8864 if (name == NULL) | |
8865 return 0; | |
8866 | |
8867 id = syn_name2id(name); | |
8868 if (id == 0) /* doesn't exist yet */ | |
8869 id = syn_add_group(name); | |
8870 else | |
8871 vim_free(name); | |
8872 return id; | |
8873 } | |
8874 | |
8875 /* | |
8876 * Add new highlight group and return it's ID. | |
8877 * "name" must be an allocated string, it will be consumed. | |
8878 * Return 0 for failure. | |
8879 */ | |
8880 static int | |
8881 syn_add_group(name) | |
8882 char_u *name; | |
8883 { | |
8884 char_u *p; | |
8885 | |
8886 /* Check that the name is ASCII letters, digits and underscore. */ | |
8887 for (p = name; *p != NUL; ++p) | |
8888 { | |
8889 if (!vim_isprintc(*p)) | |
8890 { | |
8891 EMSG(_("E669: Unprintable character in group name")); | |
2020 | 8892 vim_free(name); |
7 | 8893 return 0; |
8894 } | |
8895 else if (!ASCII_ISALNUM(*p) && *p != '_') | |
8896 { | |
8897 /* This is an error, but since there previously was no check only | |
8898 * give a warning. */ | |
16 | 8899 msg_source(hl_attr(HLF_W)); |
7 | 8900 MSG(_("W18: Invalid character in group name")); |
8901 break; | |
8902 } | |
8903 } | |
8904 | |
8905 /* | |
8906 * First call for this growarray: init growing array. | |
8907 */ | |
8908 if (highlight_ga.ga_data == NULL) | |
8909 { | |
8910 highlight_ga.ga_itemsize = sizeof(struct hl_group); | |
8911 highlight_ga.ga_growsize = 10; | |
8912 } | |
8913 | |
8914 /* | |
8915 * Make room for at least one other syntax_highlight entry. | |
8916 */ | |
8917 if (ga_grow(&highlight_ga, 1) == FAIL) | |
8918 { | |
8919 vim_free(name); | |
8920 return 0; | |
8921 } | |
8922 | |
8923 vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(struct hl_group)); | |
8924 HL_TABLE()[highlight_ga.ga_len].sg_name = name; | |
8925 HL_TABLE()[highlight_ga.ga_len].sg_name_u = vim_strsave_up(name); | |
8926 #ifdef FEAT_GUI | |
8927 HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR; | |
8928 HL_TABLE()[highlight_ga.ga_len].sg_gui_fg = INVALCOLOR; | |
205 | 8929 HL_TABLE()[highlight_ga.ga_len].sg_gui_sp = INVALCOLOR; |
7 | 8930 #endif |
8931 ++highlight_ga.ga_len; | |
8932 | |
8933 return highlight_ga.ga_len; /* ID is index plus one */ | |
8934 } | |
8935 | |
8936 /* | |
8937 * When, just after calling syn_add_group(), an error is discovered, this | |
8938 * function deletes the new name. | |
8939 */ | |
8940 static void | |
8941 syn_unadd_group() | |
8942 { | |
8943 --highlight_ga.ga_len; | |
8944 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name); | |
8945 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); | |
8946 } | |
8947 | |
8948 /* | |
8949 * Translate a group ID to highlight attributes. | |
8950 */ | |
8951 int | |
8952 syn_id2attr(hl_id) | |
8953 int hl_id; | |
8954 { | |
8955 int attr; | |
8956 struct hl_group *sgp; | |
8957 | |
8958 hl_id = syn_get_final_id(hl_id); | |
8959 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
8960 | |
8961 #ifdef FEAT_GUI | |
8962 /* | |
8963 * Only use GUI attr when the GUI is being used. | |
8964 */ | |
8965 if (gui.in_use) | |
8966 attr = sgp->sg_gui_attr; | |
8967 else | |
8968 #endif | |
8969 if (t_colors > 1) | |
8970 attr = sgp->sg_cterm_attr; | |
8971 else | |
8972 attr = sgp->sg_term_attr; | |
8973 | |
8974 return attr; | |
8975 } | |
8976 | |
8977 #ifdef FEAT_GUI | |
8978 /* | |
8979 * Get the GUI colors and attributes for a group ID. | |
8980 * NOTE: the colors will be INVALCOLOR when not set, the color otherwise. | |
8981 */ | |
8982 int | |
8983 syn_id2colors(hl_id, fgp, bgp) | |
8984 int hl_id; | |
8985 guicolor_T *fgp; | |
8986 guicolor_T *bgp; | |
8987 { | |
8988 struct hl_group *sgp; | |
8989 | |
8990 hl_id = syn_get_final_id(hl_id); | |
8991 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
8992 | |
8993 *fgp = sgp->sg_gui_fg; | |
8994 *bgp = sgp->sg_gui_bg; | |
8995 return sgp->sg_gui; | |
8996 } | |
8997 #endif | |
8998 | |
8999 /* | |
9000 * Translate a group ID to the final group ID (following links). | |
9001 */ | |
9002 int | |
9003 syn_get_final_id(hl_id) | |
9004 int hl_id; | |
9005 { | |
9006 int count; | |
9007 struct hl_group *sgp; | |
9008 | |
9009 if (hl_id > highlight_ga.ga_len || hl_id < 1) | |
9010 return 0; /* Can be called from eval!! */ | |
9011 | |
9012 /* | |
9013 * Follow links until there is no more. | |
9014 * Look out for loops! Break after 100 links. | |
9015 */ | |
9016 for (count = 100; --count >= 0; ) | |
9017 { | |
9018 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9019 if (sgp->sg_link == 0 || sgp->sg_link > highlight_ga.ga_len) | |
9020 break; | |
9021 hl_id = sgp->sg_link; | |
9022 } | |
9023 | |
9024 return hl_id; | |
9025 } | |
9026 | |
9027 #ifdef FEAT_GUI | |
9028 /* | |
9029 * Call this function just after the GUI has started. | |
9030 * It finds the font and color handles for the highlighting groups. | |
9031 */ | |
9032 void | |
9033 highlight_gui_started() | |
9034 { | |
9035 int idx; | |
9036 | |
9037 /* First get the colors from the "Normal" and "Menu" group, if set */ | |
9038 set_normal_colors(); | |
9039 | |
9040 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9041 gui_do_one_color(idx, FALSE, FALSE); | |
9042 | |
9043 highlight_changed(); | |
9044 } | |
9045 | |
9046 static void | |
9047 gui_do_one_color(idx, do_menu, do_tooltip) | |
9048 int idx; | |
9049 int do_menu; /* TRUE: might set the menu font */ | |
9050 int do_tooltip; /* TRUE: might set the tooltip font */ | |
9051 { | |
9052 int didit = FALSE; | |
9053 | |
9054 if (HL_TABLE()[idx].sg_font_name != NULL) | |
9055 { | |
9056 hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu, | |
9057 do_tooltip); | |
9058 didit = TRUE; | |
9059 } | |
9060 if (HL_TABLE()[idx].sg_gui_fg_name != NULL) | |
9061 { | |
9062 HL_TABLE()[idx].sg_gui_fg = | |
9063 color_name2handle(HL_TABLE()[idx].sg_gui_fg_name); | |
9064 didit = TRUE; | |
9065 } | |
9066 if (HL_TABLE()[idx].sg_gui_bg_name != NULL) | |
9067 { | |
9068 HL_TABLE()[idx].sg_gui_bg = | |
9069 color_name2handle(HL_TABLE()[idx].sg_gui_bg_name); | |
9070 didit = TRUE; | |
9071 } | |
205 | 9072 if (HL_TABLE()[idx].sg_gui_sp_name != NULL) |
9073 { | |
9074 HL_TABLE()[idx].sg_gui_sp = | |
9075 color_name2handle(HL_TABLE()[idx].sg_gui_sp_name); | |
9076 didit = TRUE; | |
9077 } | |
7 | 9078 if (didit) /* need to get a new attr number */ |
9079 set_hl_attr(idx); | |
9080 } | |
9081 | |
9082 #endif | |
9083 | |
9084 /* | |
9085 * Translate the 'highlight' option into attributes in highlight_attr[] and | |
9086 * set up the user highlights User1..9. If FEAT_STL_OPT is in use, a set of | |
9087 * corresponding highlights to use on top of HLF_SNC is computed. | |
9088 * Called only when the 'highlight' option has been changed and upon first | |
9089 * screen redraw after any :highlight command. | |
9090 * Return FAIL when an invalid flag is found in 'highlight'. OK otherwise. | |
9091 */ | |
9092 int | |
9093 highlight_changed() | |
9094 { | |
9095 int hlf; | |
9096 int i; | |
9097 char_u *p; | |
9098 int attr; | |
9099 char_u *end; | |
9100 int id; | |
9101 #ifdef USER_HIGHLIGHT | |
9102 char_u userhl[10]; | |
9103 # ifdef FEAT_STL_OPT | |
9104 int id_SNC = -1; | |
9105 int id_S = -1; | |
9106 int hlcnt; | |
9107 # endif | |
9108 #endif | |
9109 static int hl_flags[HLF_COUNT] = HL_FLAGS; | |
9110 | |
9111 need_highlight_changed = FALSE; | |
9112 | |
9113 /* | |
9114 * Clear all attributes. | |
9115 */ | |
9116 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9117 highlight_attr[hlf] = 0; | |
9118 | |
9119 /* | |
9120 * First set all attributes to their default value. | |
9121 * Then use the attributes from the 'highlight' option. | |
9122 */ | |
9123 for (i = 0; i < 2; ++i) | |
9124 { | |
9125 if (i) | |
9126 p = p_hl; | |
9127 else | |
9128 p = get_highlight_default(); | |
9129 if (p == NULL) /* just in case */ | |
9130 continue; | |
9131 | |
9132 while (*p) | |
9133 { | |
9134 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9135 if (hl_flags[hlf] == *p) | |
9136 break; | |
9137 ++p; | |
9138 if (hlf == (int)HLF_COUNT || *p == NUL) | |
9139 return FAIL; | |
9140 | |
9141 /* | |
9142 * Allow several hl_flags to be combined, like "bu" for | |
9143 * bold-underlined. | |
9144 */ | |
9145 attr = 0; | |
9146 for ( ; *p && *p != ','; ++p) /* parse upto comma */ | |
9147 { | |
9148 if (vim_iswhite(*p)) /* ignore white space */ | |
9149 continue; | |
9150 | |
9151 if (attr > HL_ALL) /* Combination with ':' is not allowed. */ | |
9152 return FAIL; | |
9153 | |
9154 switch (*p) | |
9155 { | |
9156 case 'b': attr |= HL_BOLD; | |
9157 break; | |
9158 case 'i': attr |= HL_ITALIC; | |
9159 break; | |
9160 case '-': | |
9161 case 'n': /* no highlighting */ | |
9162 break; | |
9163 case 'r': attr |= HL_INVERSE; | |
9164 break; | |
9165 case 's': attr |= HL_STANDOUT; | |
9166 break; | |
9167 case 'u': attr |= HL_UNDERLINE; | |
9168 break; | |
205 | 9169 case 'c': attr |= HL_UNDERCURL; |
9170 break; | |
7 | 9171 case ':': ++p; /* highlight group name */ |
9172 if (attr || *p == NUL) /* no combinations */ | |
9173 return FAIL; | |
9174 end = vim_strchr(p, ','); | |
9175 if (end == NULL) | |
9176 end = p + STRLEN(p); | |
9177 id = syn_check_group(p, (int)(end - p)); | |
9178 if (id == 0) | |
9179 return FAIL; | |
9180 attr = syn_id2attr(id); | |
9181 p = end - 1; | |
9182 #if defined(FEAT_STL_OPT) && defined(USER_HIGHLIGHT) | |
9183 if (hlf == (int)HLF_SNC) | |
9184 id_SNC = syn_get_final_id(id); | |
9185 else if (hlf == (int)HLF_S) | |
9186 id_S = syn_get_final_id(id); | |
9187 #endif | |
9188 break; | |
9189 default: return FAIL; | |
9190 } | |
9191 } | |
9192 highlight_attr[hlf] = attr; | |
9193 | |
9194 p = skip_to_option_part(p); /* skip comma and spaces */ | |
9195 } | |
9196 } | |
9197 | |
9198 #ifdef USER_HIGHLIGHT | |
9199 /* Setup the user highlights | |
9200 * | |
9201 * Temporarily utilize 10 more hl entries. Have to be in there | |
9202 * simultaneously in case of table overflows in get_attr_entry() | |
9203 */ | |
9204 # ifdef FEAT_STL_OPT | |
9205 if (ga_grow(&highlight_ga, 10) == FAIL) | |
9206 return FAIL; | |
9207 hlcnt = highlight_ga.ga_len; | |
9208 if (id_S == 0) | |
9209 { /* Make sure id_S is always valid to simplify code below */ | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2136
diff
changeset
|
9210 vim_memset(&HL_TABLE()[hlcnt + 9], 0, sizeof(struct hl_group)); |
7 | 9211 HL_TABLE()[hlcnt + 9].sg_term = highlight_attr[HLF_S]; |
9212 id_S = hlcnt + 10; | |
9213 } | |
9214 # endif | |
9215 for (i = 0; i < 9; i++) | |
9216 { | |
9217 sprintf((char *)userhl, "User%d", i + 1); | |
9218 id = syn_name2id(userhl); | |
9219 if (id == 0) | |
9220 { | |
9221 highlight_user[i] = 0; | |
9222 # ifdef FEAT_STL_OPT | |
9223 highlight_stlnc[i] = 0; | |
9224 # endif | |
9225 } | |
9226 else | |
9227 { | |
9228 # ifdef FEAT_STL_OPT | |
9229 struct hl_group *hlt = HL_TABLE(); | |
9230 # endif | |
9231 | |
9232 highlight_user[i] = syn_id2attr(id); | |
9233 # ifdef FEAT_STL_OPT | |
9234 if (id_SNC == 0) | |
9235 { | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2136
diff
changeset
|
9236 vim_memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group)); |
7 | 9237 hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC]; |
9238 hlt[hlcnt + i].sg_cterm = highlight_attr[HLF_SNC]; | |
9239 # ifdef FEAT_GUI | |
9240 hlt[hlcnt + i].sg_gui = highlight_attr[HLF_SNC]; | |
9241 # endif | |
9242 } | |
9243 else | |
9244 mch_memmove(&hlt[hlcnt + i], | |
9245 &hlt[id_SNC - 1], | |
9246 sizeof(struct hl_group)); | |
9247 hlt[hlcnt + i].sg_link = 0; | |
9248 | |
9249 /* Apply difference between UserX and HLF_S to HLF_SNC */ | |
9250 hlt[hlcnt + i].sg_term ^= | |
9251 hlt[id - 1].sg_term ^ hlt[id_S - 1].sg_term; | |
9252 if (hlt[id - 1].sg_start != hlt[id_S - 1].sg_start) | |
9253 hlt[hlcnt + i].sg_start = hlt[id - 1].sg_start; | |
9254 if (hlt[id - 1].sg_stop != hlt[id_S - 1].sg_stop) | |
9255 hlt[hlcnt + i].sg_stop = hlt[id - 1].sg_stop; | |
9256 hlt[hlcnt + i].sg_cterm ^= | |
9257 hlt[id - 1].sg_cterm ^ hlt[id_S - 1].sg_cterm; | |
9258 if (hlt[id - 1].sg_cterm_fg != hlt[id_S - 1].sg_cterm_fg) | |
9259 hlt[hlcnt + i].sg_cterm_fg = hlt[id - 1].sg_cterm_fg; | |
9260 if (hlt[id - 1].sg_cterm_bg != hlt[id_S - 1].sg_cterm_bg) | |
9261 hlt[hlcnt + i].sg_cterm_bg = hlt[id - 1].sg_cterm_bg; | |
9262 # ifdef FEAT_GUI | |
9263 hlt[hlcnt + i].sg_gui ^= | |
9264 hlt[id - 1].sg_gui ^ hlt[id_S - 1].sg_gui; | |
9265 if (hlt[id - 1].sg_gui_fg != hlt[id_S - 1].sg_gui_fg) | |
9266 hlt[hlcnt + i].sg_gui_fg = hlt[id - 1].sg_gui_fg; | |
9267 if (hlt[id - 1].sg_gui_bg != hlt[id_S - 1].sg_gui_bg) | |
9268 hlt[hlcnt + i].sg_gui_bg = hlt[id - 1].sg_gui_bg; | |
205 | 9269 if (hlt[id - 1].sg_gui_sp != hlt[id_S - 1].sg_gui_sp) |
9270 hlt[hlcnt + i].sg_gui_sp = hlt[id - 1].sg_gui_sp; | |
7 | 9271 if (hlt[id - 1].sg_font != hlt[id_S - 1].sg_font) |
9272 hlt[hlcnt + i].sg_font = hlt[id - 1].sg_font; | |
9273 # ifdef FEAT_XFONTSET | |
9274 if (hlt[id - 1].sg_fontset != hlt[id_S - 1].sg_fontset) | |
9275 hlt[hlcnt + i].sg_fontset = hlt[id - 1].sg_fontset; | |
9276 # endif | |
9277 # endif | |
9278 highlight_ga.ga_len = hlcnt + i + 1; | |
9279 set_hl_attr(hlcnt + i); /* At long last we can apply */ | |
9280 highlight_stlnc[i] = syn_id2attr(hlcnt + i + 1); | |
9281 # endif | |
9282 } | |
9283 } | |
9284 # ifdef FEAT_STL_OPT | |
9285 highlight_ga.ga_len = hlcnt; | |
9286 # endif | |
9287 | |
9288 #endif /* USER_HIGHLIGHT */ | |
9289 | |
9290 return OK; | |
9291 } | |
9292 | |
1322 | 9293 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
7 | 9294 |
9295 static void highlight_list __ARGS((void)); | |
9296 static void highlight_list_two __ARGS((int cnt, int attr)); | |
9297 | |
9298 /* | |
9299 * Handle command line completion for :highlight command. | |
9300 */ | |
9301 void | |
9302 set_context_in_highlight_cmd(xp, arg) | |
9303 expand_T *xp; | |
9304 char_u *arg; | |
9305 { | |
9306 char_u *p; | |
9307 | |
9308 /* Default: expand group names */ | |
9309 xp->xp_context = EXPAND_HIGHLIGHT; | |
9310 xp->xp_pattern = arg; | |
1322 | 9311 include_link = 2; |
9312 include_default = 1; | |
7 | 9313 |
9314 /* (part of) subcommand already typed */ | |
9315 if (*arg != NUL) | |
9316 { | |
9317 p = skiptowhite(arg); | |
9318 if (*p != NUL) /* past "default" or group name */ | |
9319 { | |
1322 | 9320 include_default = 0; |
7 | 9321 if (STRNCMP("default", arg, p - arg) == 0) |
9322 { | |
9323 arg = skipwhite(p); | |
9324 xp->xp_pattern = arg; | |
9325 p = skiptowhite(arg); | |
9326 } | |
9327 if (*p != NUL) /* past group name */ | |
9328 { | |
1322 | 9329 include_link = 0; |
7 | 9330 if (arg[1] == 'i' && arg[0] == 'N') |
9331 highlight_list(); | |
9332 if (STRNCMP("link", arg, p - arg) == 0 | |
9333 || STRNCMP("clear", arg, p - arg) == 0) | |
9334 { | |
9335 xp->xp_pattern = skipwhite(p); | |
9336 p = skiptowhite(xp->xp_pattern); | |
9337 if (*p != NUL) /* past first group name */ | |
9338 { | |
9339 xp->xp_pattern = skipwhite(p); | |
9340 p = skiptowhite(xp->xp_pattern); | |
9341 } | |
9342 } | |
9343 if (*p != NUL) /* past group name(s) */ | |
9344 xp->xp_context = EXPAND_NOTHING; | |
9345 } | |
9346 } | |
9347 } | |
9348 } | |
9349 | |
9350 /* | |
9351 * List highlighting matches in a nice way. | |
9352 */ | |
9353 static void | |
9354 highlight_list() | |
9355 { | |
9356 int i; | |
9357 | |
9358 for (i = 10; --i >= 0; ) | |
9359 highlight_list_two(i, hl_attr(HLF_D)); | |
9360 for (i = 40; --i >= 0; ) | |
9361 highlight_list_two(99, 0); | |
9362 } | |
9363 | |
9364 static void | |
9365 highlight_list_two(cnt, attr) | |
9366 int cnt; | |
9367 int attr; | |
9368 { | |
9369 msg_puts_attr((char_u *)("N \bI \b! \b" + cnt / 11), attr); | |
9370 msg_clr_eos(); | |
9371 out_flush(); | |
9372 ui_delay(cnt == 99 ? 40L : (long)cnt * 50L, FALSE); | |
9373 } | |
9374 | |
9375 #endif /* FEAT_CMDL_COMPL */ | |
9376 | |
9377 #if defined(FEAT_CMDL_COMPL) || (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) \ | |
9378 || defined(FEAT_SIGNS) || defined(PROTO) | |
9379 /* | |
9380 * Function given to ExpandGeneric() to obtain the list of group names. | |
9381 * Also used for synIDattr() function. | |
9382 */ | |
9383 char_u * | |
9384 get_highlight_name(xp, idx) | |
1883 | 9385 expand_T *xp UNUSED; |
7 | 9386 int idx; |
9387 { | |
9388 #ifdef FEAT_CMDL_COMPL | |
1322 | 9389 if (idx == highlight_ga.ga_len && include_none != 0) |
9390 return (char_u *)"none"; | |
9391 if (idx == highlight_ga.ga_len + include_none && include_default != 0) | |
9392 return (char_u *)"default"; | |
9393 if (idx == highlight_ga.ga_len + include_none + include_default | |
9394 && include_link != 0) | |
7 | 9395 return (char_u *)"link"; |
1322 | 9396 if (idx == highlight_ga.ga_len + include_none + include_default + 1 |
9397 && include_link != 0) | |
7 | 9398 return (char_u *)"clear"; |
9399 #endif | |
9400 if (idx < 0 || idx >= highlight_ga.ga_len) | |
9401 return NULL; | |
9402 return HL_TABLE()[idx].sg_name; | |
9403 } | |
9404 #endif | |
9405 | |
1322 | 9406 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 9407 /* |
9408 * Free all the highlight group fonts. | |
9409 * Used when quitting for systems which need it. | |
9410 */ | |
9411 void | |
9412 free_highlight_fonts() | |
9413 { | |
9414 int idx; | |
9415 | |
9416 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9417 { | |
9418 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
9419 HL_TABLE()[idx].sg_font = NOFONT; | |
9420 # ifdef FEAT_XFONTSET | |
9421 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
9422 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
9423 # endif | |
9424 } | |
9425 | |
9426 gui_mch_free_font(gui.norm_font); | |
9427 # ifdef FEAT_XFONTSET | |
9428 gui_mch_free_fontset(gui.fontset); | |
9429 # endif | |
9430 # ifndef HAVE_GTK2 | |
9431 gui_mch_free_font(gui.bold_font); | |
9432 gui_mch_free_font(gui.ital_font); | |
9433 gui_mch_free_font(gui.boldital_font); | |
9434 # endif | |
9435 } | |
9436 #endif | |
9437 | |
9438 /************************************** | |
9439 * End of Highlighting stuff * | |
9440 **************************************/ |