Mercurial > vim
annotate src/syntax.c @ 11129:f4ea50924c6d v8.0.0452
patch 8.0.0452: some macros are in lower case
commit https://github.com/vim/vim/commit/1c46544412382db8b3203d6c78e550df885540bd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 12 20:10:05 2017 +0100
patch 8.0.0452: some macros are in lower case
Problem: Some macros are in lower case.
Solution: Make a few more macros upper case.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 12 Mar 2017 20:15:06 +0100 |
parents | 506f5d8b7d8b |
children | 501f46f7644c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * syntax.c: code for syntax highlighting | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
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 */ | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
25 int sg_cleared; /* "hi clear" was used */ |
7 | 26 /* for normal terminals */ |
27 int sg_term; /* "term=" highlighting attributes */ | |
28 char_u *sg_start; /* terminal string for start highl */ | |
29 char_u *sg_stop; /* terminal string for stop highl */ | |
30 int sg_term_attr; /* Screen attr for term mode */ | |
31 /* for color terminals */ | |
32 int sg_cterm; /* "cterm=" highlighting attr */ | |
33 int sg_cterm_bold; /* bold attr was set for light color */ | |
34 int sg_cterm_fg; /* terminal fg color number + 1 */ | |
35 int sg_cterm_bg; /* terminal bg color number + 1 */ | |
36 int sg_cterm_attr; /* Screen attr for color term mode */ | |
37 /* for when using the GUI */ | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
38 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 39 guicolor_T sg_gui_fg; /* GUI foreground color handle */ |
40 guicolor_T sg_gui_bg; /* GUI background color handle */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
41 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
42 #ifdef FEAT_GUI |
205 | 43 guicolor_T sg_gui_sp; /* GUI special color handle */ |
7 | 44 GuiFont sg_font; /* GUI font handle */ |
45 #ifdef FEAT_XFONTSET | |
46 GuiFontset sg_fontset; /* GUI fontset handle */ | |
47 #endif | |
48 char_u *sg_font_name; /* GUI font or fontset name */ | |
49 int sg_gui_attr; /* Screen attr for GUI mode */ | |
50 #endif | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
51 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
52 /* Store the sp color name for the GUI or synIDattr() */ |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
53 int sg_gui; /* "gui=" highlighting attributes */ |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
54 char_u *sg_gui_fg_name;/* GUI foreground color name */ |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
55 char_u *sg_gui_bg_name;/* GUI background color name */ |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
56 char_u *sg_gui_sp_name;/* GUI special color name */ |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
57 #endif |
7 | 58 int sg_link; /* link to this highlight group ID */ |
59 int sg_set; /* combination of SG_* flags */ | |
448 | 60 #ifdef FEAT_EVAL |
61 scid_T sg_scriptID; /* script in which the group was last set */ | |
62 #endif | |
7 | 63 }; |
64 | |
65 #define SG_TERM 1 /* term has been set */ | |
66 #define SG_CTERM 2 /* cterm has been set */ | |
67 #define SG_GUI 4 /* gui has been set */ | |
68 #define SG_LINK 8 /* link has been set */ | |
69 | |
70 static garray_T highlight_ga; /* highlight groups for 'highlight' option */ | |
71 | |
72 #define HL_TABLE() ((struct hl_group *)((highlight_ga.ga_data))) | |
73 | |
2756 | 74 #define MAX_HL_ID 20000 /* maximum value for a highlight ID. */ |
75 | |
7 | 76 #ifdef FEAT_CMDL_COMPL |
1322 | 77 /* Flags to indicate an additional string for highlight name completion. */ |
78 static int include_none = 0; /* when 1 include "None" */ | |
79 static int include_default = 0; /* when 1 include "default" */ | |
80 static int include_link = 0; /* when 2 include "link" and "clear" */ | |
7 | 81 #endif |
82 | |
83 /* | |
84 * The "term", "cterm" and "gui" arguments can be any combination of the | |
85 * following names, separated by commas (but no spaces!). | |
86 */ | |
87 static char *(hl_name_table[]) = | |
205 | 88 {"bold", "standout", "underline", "undercurl", |
89 "italic", "reverse", "inverse", "NONE"}; | |
7 | 90 static int hl_attr_table[] = |
205 | 91 {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, 0}; |
7 | 92 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
93 static int get_attr_entry(garray_T *table, attrentry_T *aep); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
94 static void syn_unadd_group(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
95 static void set_hl_attr(int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
96 static void highlight_list_one(int id); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
97 static int highlight_list_arg(int id, int didh, int type, int iarg, char_u *sarg, char *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
98 static int syn_add_group(char_u *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
99 static int syn_list_header(int did_header, int outlen, int id); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
100 static int hl_has_settings(int idx, int check_link); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
101 static void highlight_clear(int idx); |
7 | 102 |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
103 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
104 static void gui_do_one_color(int idx, int do_menu, int do_tooltip); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
105 static guicolor_T color_name2handle(char_u *name); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
106 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
107 #ifdef FEAT_GUI |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
108 static int set_group_colors(char_u *name, guicolor_T *fgp, guicolor_T *bgp, int do_menu, int use_norm, int do_tooltip); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
109 static GuiFont font_name2handle(char_u *name); |
7 | 110 # ifdef FEAT_XFONTSET |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
111 static GuiFontset fontset_name2handle(char_u *name, int fixed_width); |
7 | 112 # endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
113 static void hl_do_font(int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip, int free_font); |
7 | 114 #endif |
115 | |
116 /* | |
117 * An attribute number is the index in attr_table plus ATTR_OFF. | |
118 */ | |
119 #define ATTR_OFF (HL_ALL + 1) | |
120 | |
121 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
122 | |
123 #define SYN_NAMELEN 50 /* maximum length of a syntax name */ | |
124 | |
125 /* different types of offsets that are possible */ | |
126 #define SPO_MS_OFF 0 /* match start offset */ | |
127 #define SPO_ME_OFF 1 /* match end offset */ | |
128 #define SPO_HS_OFF 2 /* highl. start offset */ | |
129 #define SPO_HE_OFF 3 /* highl. end offset */ | |
130 #define SPO_RS_OFF 4 /* region start offset */ | |
131 #define SPO_RE_OFF 5 /* region end offset */ | |
132 #define SPO_LC_OFF 6 /* leading context offset */ | |
133 #define SPO_COUNT 7 | |
134 | |
135 static char *(spo_name_tab[SPO_COUNT]) = | |
136 {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; | |
137 | |
138 /* | |
139 * The patterns that are being searched for are stored in a syn_pattern. | |
140 * A match item consists of one pattern. | |
141 * A start/end item consists of n start patterns and m end patterns. | |
142 * A start/skip/end item consists of n start patterns, one skip pattern and m | |
143 * end patterns. | |
144 * For the latter two, the patterns are always consecutive: start-skip-end. | |
145 * | |
146 * A character offset can be given for the matched text (_m_start and _m_end) | |
147 * and for the actually highlighted text (_h_start and _h_end). | |
148 */ | |
149 typedef struct syn_pattern | |
150 { | |
151 char sp_type; /* see SPTYPE_ defines below */ | |
152 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
|
153 int sp_flags; /* see HL_ defines below */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
154 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
155 int sp_cchar; /* conceal substitute character */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
156 #endif |
7 | 157 struct sp_syn sp_syn; /* struct passed to in_id_list() */ |
158 short sp_syn_match_id; /* highlight group ID of pattern */ | |
159 char_u *sp_pattern; /* regexp to match, pattern */ | |
160 regprog_T *sp_prog; /* regexp to match, program */ | |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
161 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
162 syn_time_T sp_time; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
163 #endif |
7 | 164 int sp_ic; /* ignore-case flag for sp_prog */ |
165 short sp_off_flags; /* see below */ | |
166 int sp_offsets[SPO_COUNT]; /* offsets */ | |
167 short *sp_cont_list; /* cont. group IDs, if non-zero */ | |
168 short *sp_next_list; /* next group IDs, if non-zero */ | |
169 int sp_sync_idx; /* sync item index (syncing only) */ | |
170 int sp_line_id; /* ID of last line where tried */ | |
171 int sp_startcol; /* next match in sp_line_id line */ | |
172 } synpat_T; | |
173 | |
174 /* The sp_off_flags are computed like this: | |
175 * offset from the start of the matched text: (1 << SPO_XX_OFF) | |
176 * offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) | |
177 * When both are present, only one is used. | |
178 */ | |
179 | |
180 #define SPTYPE_MATCH 1 /* match keyword with this group ID */ | |
181 #define SPTYPE_START 2 /* match a regexp, start of item */ | |
182 #define SPTYPE_END 3 /* match a regexp, end of item */ | |
183 #define SPTYPE_SKIP 4 /* match a regexp, skip within item */ | |
184 | |
185 | |
186 #define SYN_ITEMS(buf) ((synpat_T *)((buf)->b_syn_patterns.ga_data)) | |
187 | |
188 #define NONE_IDX -2 /* value of sp_sync_idx for "NONE" */ | |
189 | |
190 /* | |
191 * Flags for b_syn_sync_flags: | |
192 */ | |
193 #define SF_CCOMMENT 0x01 /* sync on a C-style comment */ | |
194 #define SF_MATCH 0x02 /* sync by matching a pattern */ | |
195 | |
196 #define SYN_STATE_P(ssp) ((bufstate_T *)((ssp)->ga_data)) | |
197 | |
198 #define MAXKEYWLEN 80 /* maximum length of a keyword */ | |
199 | |
200 /* | |
201 * The attributes of the syntax item that has been recognized. | |
202 */ | |
203 static int current_attr = 0; /* attr of current syntax word */ | |
204 #ifdef FEAT_EVAL | |
205 static int current_id = 0; /* ID of current char for syn_get_id() */ | |
2020 | 206 static int current_trans_id = 0; /* idem, transparency removed */ |
7 | 207 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
208 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
209 static int current_flags = 0; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
210 static int current_seqnr = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
211 static int current_sub_char = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
212 #endif |
7 | 213 |
221 | 214 typedef struct syn_cluster_S |
7 | 215 { |
216 char_u *scl_name; /* syntax cluster name */ | |
217 char_u *scl_name_u; /* uppercase of scl_name */ | |
218 short *scl_list; /* IDs in this syntax cluster */ | |
221 | 219 } syn_cluster_T; |
7 | 220 |
221 /* | |
222 * Methods of combining two clusters | |
223 */ | |
224 #define CLUSTER_REPLACE 1 /* replace first list with second */ | |
225 #define CLUSTER_ADD 2 /* add second list to first */ | |
226 #define CLUSTER_SUBTRACT 3 /* subtract second list from first */ | |
227 | |
221 | 228 #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data)) |
7 | 229 |
230 /* | |
231 * Syntax group IDs have different types: | |
2743 | 232 * 0 - 19999 normal syntax groups |
233 * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) | |
234 * 21000 - 21999 TOP indicator (current_syn_inc_tag added) | |
235 * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) | |
236 * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) | |
237 */ | |
2756 | 238 #define SYNID_ALLBUT MAX_HL_ID /* syntax group ID for contains=ALLBUT */ |
2743 | 239 #define SYNID_TOP 21000 /* syntax group ID for contains=TOP */ |
240 #define SYNID_CONTAINED 22000 /* syntax group ID for contains=CONTAINED */ | |
241 #define SYNID_CLUSTER 23000 /* first syntax group ID for clusters */ | |
242 | |
243 #define MAX_SYN_INC_TAG 999 /* maximum before the above overflow */ | |
244 #define MAX_CLUSTER_ID (32767 - SYNID_CLUSTER) | |
7 | 245 |
246 /* | |
247 * Annoying Hack(TM): ":syn include" needs this pointer to pass to | |
248 * expand_filename(). Most of the other syntax commands don't need it, so | |
249 * instead of passing it to them, we stow it here. | |
250 */ | |
251 static char_u **syn_cmdlinep; | |
252 | |
253 /* | |
254 * 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
|
255 * files from leaking into ALLBUT lists, we assign a unique ID to the |
7 | 256 * rules in each ":syn include"'d file. |
257 */ | |
258 static int current_syn_inc_tag = 0; | |
259 static int running_syn_inc_tag = 0; | |
260 | |
261 /* | |
134 | 262 * In a hashtable item "hi_key" points to "keyword" in a keyentry. |
263 * This avoids adding a pointer to the hashtable item. | |
264 * KE2HIKEY() converts a var pointer to a hashitem key pointer. | |
265 * HIKEY2KE() converts a hashitem key pointer to a var pointer. | |
266 * HI2KE() converts a hashitem pointer to a var pointer. | |
267 */ | |
268 static keyentry_T dumkey; | |
269 #define KE2HIKEY(kp) ((kp)->keyword) | |
270 #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey))) | |
271 #define HI2KE(hi) HIKEY2KE((hi)->hi_key) | |
272 | |
273 /* | |
7 | 274 * To reduce the time spent in keepend(), remember at which level in the state |
275 * stack the first item with "keepend" is present. When "-1", there is no | |
276 * "keepend" on the stack. | |
277 */ | |
278 static int keepend_level = -1; | |
279 | |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
280 static char msg_no_items[] = N_("No Syntax items defined for this buffer"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
281 |
7 | 282 /* |
283 * For the current state we need to remember more than just the idx. | |
284 * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. | |
285 * (The end positions have the column number of the next char) | |
286 */ | |
287 typedef struct state_item | |
288 { | |
1371 | 289 int si_idx; /* index of syntax pattern or |
290 KEYWORD_IDX */ | |
7 | 291 int si_id; /* highlight group ID for keywords */ |
2020 | 292 int si_trans_id; /* idem, transparency removed */ |
7 | 293 int si_m_lnum; /* lnum of the match */ |
294 int si_m_startcol; /* starting column of the match */ | |
295 lpos_T si_m_endpos; /* just after end posn of the match */ | |
296 lpos_T si_h_startpos; /* start position of the highlighting */ | |
297 lpos_T si_h_endpos; /* end position of the highlighting */ | |
298 lpos_T si_eoe_pos; /* end position of end pattern */ | |
299 int si_end_idx; /* group ID for end pattern or zero */ | |
300 int si_ends; /* if match ends before si_m_endpos */ | |
301 int si_attr; /* attributes in this state */ | |
302 long si_flags; /* HL_HAS_EOL flag in this state, and | |
303 * HL_SKIP* for si_next_list */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
304 #ifdef FEAT_CONCEAL |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
305 int si_seqnr; /* sequence number */ |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
306 int si_cchar; /* substitution character for conceal */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
307 #endif |
7 | 308 short *si_cont_list; /* list of contained groups */ |
309 short *si_next_list; /* nextgroup IDs after this item ends */ | |
310 reg_extmatch_T *si_extmatch; /* \z(...\) matches from start | |
311 * pattern */ | |
312 } stateitem_T; | |
313 | |
314 #define KEYWORD_IDX -1 /* value of si_idx for keywords */ | |
315 #define ID_LIST_ALL (short *)-1 /* valid of si_cont_list for containing all | |
316 but contained groups */ | |
317 | |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
318 #ifdef FEAT_CONCEAL |
6698 | 319 static int next_seqnr = 1; /* value to use for si_seqnr */ |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
320 #endif |
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
321 |
7 | 322 /* |
154 | 323 * Struct to reduce the number of arguments to get_syn_options(), it's used |
324 * very often. | |
325 */ | |
326 typedef struct | |
327 { | |
1222 | 328 int flags; /* flags for contained and transparent */ |
154 | 329 int keyword; /* TRUE for ":syn keyword" */ |
330 int *sync_idx; /* syntax item for "grouphere" argument, NULL | |
331 if not allowed */ | |
332 char has_cont_list; /* TRUE if "cont_list" can be used */ | |
333 short *cont_list; /* group IDs for "contains" argument */ | |
334 short *cont_in_list; /* group IDs for "containedin" argument */ | |
335 short *next_list; /* group IDs for "nextgroup" argument */ | |
336 } syn_opt_arg_T; | |
337 | |
338 /* | |
7 | 339 * The next possible match in the current line for any pattern is remembered, |
340 * to avoid having to try for a match in each column. | |
341 * If next_match_idx == -1, not tried (in this line) yet. | |
342 * If next_match_col == MAXCOL, no match found in this line. | |
343 * (All end positions have the column of the char after the end) | |
344 */ | |
345 static int next_match_col; /* column for start of next match */ | |
346 static lpos_T next_match_m_endpos; /* position for end of next match */ | |
347 static lpos_T next_match_h_startpos; /* pos. for highl. start of next match */ | |
348 static lpos_T next_match_h_endpos; /* pos. for highl. end of next match */ | |
349 static int next_match_idx; /* index of matched item */ | |
350 static long next_match_flags; /* flags for next match */ | |
351 static lpos_T next_match_eos_pos; /* end of start pattn (start region) */ | |
352 static lpos_T next_match_eoe_pos; /* pos. for end of end pattern */ | |
353 static int next_match_end_idx; /* ID of group for end pattn or zero */ | |
354 static reg_extmatch_T *next_match_extmatch = NULL; | |
355 | |
356 /* | |
357 * A state stack is an array of integers or stateitem_T, stored in a | |
358 * garray_T. A state stack is invalid if it's itemsize entry is zero. | |
359 */ | |
360 #define INVALID_STATE(ssp) ((ssp)->ga_itemsize == 0) | |
361 #define VALID_STATE(ssp) ((ssp)->ga_itemsize != 0) | |
362 | |
363 /* | |
364 * The current state (within the line) of the recognition engine. | |
365 * When current_state.ga_itemsize is 0 the current state is invalid. | |
366 */ | |
367 static win_T *syn_win; /* current window for highlighting */ | |
368 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
|
369 static synblock_T *syn_block; /* current buffer for highlighting */ |
7 | 370 static linenr_T current_lnum = 0; /* lnum of current state */ |
371 static colnr_T current_col = 0; /* column of current state */ | |
372 static int current_state_stored = 0; /* TRUE if stored current state | |
373 * after setting current_finished */ | |
374 static int current_finished = 0; /* current line has been finished */ | |
375 static garray_T current_state /* current stack of state_items */ | |
376 = {0, 0, 0, 0, NULL}; | |
377 static short *current_next_list = NULL; /* when non-zero, nextgroup list */ | |
378 static int current_next_flags = 0; /* flags for current_next_list */ | |
379 static int current_line_id = 0; /* unique number for current line */ | |
380 | |
381 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] | |
382 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
383 static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
384 static void save_chartab(char_u *chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
385 static void restore_chartab(char_u *chartab); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
386 static int syn_match_linecont(linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
387 static void syn_start_line(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
388 static void syn_update_ends(int startofline); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
389 static void syn_stack_alloc(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
390 static int syn_stack_cleanup(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
391 static void syn_stack_free_entry(synblock_T *block, synstate_T *p); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
392 static synstate_T *syn_stack_find_entry(linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
393 static synstate_T *store_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
394 static void load_current_state(synstate_T *from); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
395 static void invalidate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
396 static int syn_stack_equal(synstate_T *sp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
397 static void validate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
398 static int syn_finish_line(int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
399 static int syn_current_attr(int syncing, int displaying, int *can_spell, int keep_state); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
400 static int did_match_already(int idx, garray_T *gap); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
401 static stateitem_T *push_next_match(stateitem_T *cur_si); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
402 static void check_state_ends(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
403 static void update_si_attr(int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
404 static void check_keepend(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
405 static void update_si_end(stateitem_T *sip, int startcol, int force); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
406 static short *copy_id_list(short *list); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
407 static int in_id_list(stateitem_T *item, short *cont_list, struct sp_syn *ssp, int contained); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
408 static int push_current_state(int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
409 static void pop_current_state(void); |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
410 #ifdef FEAT_PROFILE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
411 static void syn_clear_time(syn_time_T *tt); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
412 static void syntime_clear(void); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
413 #ifdef __BORLANDC__ |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
414 static int _RTLENTRYF syn_compare_syntime(const void *v1, const void *v2); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
415 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
416 static int syn_compare_syntime(const void *v1, const void *v2); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
417 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
418 static void syntime_report(void); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
419 static int syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
420 # define IF_SYN_TIME(p) (p) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
421 #else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
422 # define IF_SYN_TIME(p) NULL |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
423 typedef int syn_time_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
424 #endif |
7 | 425 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
426 static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
427 static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, long *flagsp, lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
428 static void clear_syn_state(synstate_T *p); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
429 static void clear_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
430 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
431 static void limit_pos(lpos_T *pos, lpos_T *limit); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
432 static void limit_pos_zero(lpos_T *pos, lpos_T *limit); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
433 static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp, int idx, int extra); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
434 static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp, int idx, int extra); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
435 static char_u *syn_getcurline(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
436 static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T *st); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
437 static int check_keyword_id(char_u *line, int startcol, int *endcol, long *flags, short **next_list, stateitem_T *cur_si, int *ccharp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
438 static void syn_cmd_case(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
439 static void syn_cmd_spell(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
440 static void syntax_sync_clear(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
441 static void syn_remove_pattern(synblock_T *block, int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
442 static void syn_clear_pattern(synblock_T *block, int i); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
443 static void syn_clear_cluster(synblock_T *block, int i); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
444 static void syn_cmd_clear(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
445 static void syn_cmd_conceal(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
446 static void syn_clear_one(int id, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
447 static void syn_cmd_on(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
448 static void syn_cmd_enable(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
449 static void syn_cmd_reset(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
450 static void syn_cmd_manual(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
451 static void syn_cmd_off(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
452 static void syn_cmd_onoff(exarg_T *eap, char *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
453 static void syn_cmd_list(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
454 static void syn_lines_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
455 static void syn_match_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
456 static void syn_stack_free_block(synblock_T *block); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
457 static void syn_list_one(int id, int syncing, int link_only); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
458 static void syn_list_cluster(int id); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
459 static void put_id_list(char_u *name, short *list, int attr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
460 static void put_pattern(char *s, int c, synpat_T *spp, int attr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
461 static int syn_list_keywords(int id, hashtab_T *ht, int did_header, int attr); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
462 static void syn_clear_keyword(int id, hashtab_T *ht); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
463 static void clear_keywtab(hashtab_T *ht); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
464 static void add_keyword(char_u *name, int id, int flags, short *cont_in_list, short *next_list, int conceal_char); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
465 static char_u *get_group_name(char_u *arg, char_u **name_end); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
466 static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, int *conceal_char, int skip); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
467 static void syn_cmd_include(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
468 static void syn_cmd_iskeyword(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
469 static void syn_cmd_keyword(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
470 static void syn_cmd_match(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
471 static void syn_cmd_region(exarg_T *eap, int syncing); |
7 | 472 #ifdef __BORLANDC__ |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
473 static int _RTLENTRYF syn_compare_stub(const void *v1, const void *v2); |
7 | 474 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
475 static int syn_compare_stub(const void *v1, const void *v2); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
476 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
477 static void syn_cmd_cluster(exarg_T *eap, int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
478 static int syn_scl_name2id(char_u *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
479 static int syn_scl_namen2id(char_u *linep, int len); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
480 static int syn_check_cluster(char_u *pp, int len); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
481 static int syn_add_cluster(char_u *name); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
482 static void init_syn_patterns(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
483 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
484 static void syn_cmd_sync(exarg_T *eap, int syncing); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
485 static int get_id_list(char_u **arg, int keylen, short **list, int skip); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
486 static void syn_combine_list(short **clstr1, short **clstr2, int list_op); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
487 static void syn_incl_toplevel(int id, int *flagsp); |
7 | 488 |
489 /* | |
490 * Start the syntax recognition for a line. This function is normally called | |
491 * from the screen updating, once for each displayed line. | |
492 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get | |
493 * it. Careful: curbuf and curwin are likely to point to another buffer and | |
494 * window. | |
495 */ | |
496 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
497 syntax_start(win_T *wp, linenr_T lnum) |
7 | 498 { |
499 synstate_T *p; | |
500 synstate_T *last_valid = NULL; | |
501 synstate_T *last_min_valid = NULL; | |
1512 | 502 synstate_T *sp, *prev = NULL; |
7 | 503 linenr_T parsed_lnum; |
504 linenr_T first_stored; | |
505 int dist; | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10660
diff
changeset
|
506 static varnumber_T changedtick = 0; /* remember the last change ID */ |
7 | 507 |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
508 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
509 current_sub_char = NUL; |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
510 #endif |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
511 |
7 | 512 /* |
513 * After switching buffers, invalidate current_state. | |
26 | 514 * Also do this when a change was made, the current state may be invalid |
515 * then. | |
7 | 516 */ |
8806
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
517 if (syn_block != wp->w_s |
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
518 || syn_buf != wp->w_buffer |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
519 || changedtick != CHANGEDTICK(syn_buf)) |
7 | 520 { |
521 invalidate_current_state(); | |
522 syn_buf = wp->w_buffer; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
523 syn_block = wp->w_s; |
7 | 524 } |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
525 changedtick = CHANGEDTICK(syn_buf); |
7 | 526 syn_win = wp; |
527 | |
528 /* | |
529 * Allocate syntax stack when needed. | |
530 */ | |
531 syn_stack_alloc(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
532 if (syn_block->b_sst_array == NULL) |
410 | 533 return; /* out of memory */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
534 syn_block->b_sst_lasttick = display_tick; |
7 | 535 |
536 /* | |
537 * If the state of the end of the previous line is useful, store it. | |
538 */ | |
539 if (VALID_STATE(¤t_state) | |
540 && current_lnum < lnum | |
541 && current_lnum < syn_buf->b_ml.ml_line_count) | |
542 { | |
543 (void)syn_finish_line(FALSE); | |
544 if (!current_state_stored) | |
545 { | |
546 ++current_lnum; | |
1512 | 547 (void)store_current_state(); |
7 | 548 } |
549 | |
550 /* | |
551 * If the current_lnum is now the same as "lnum", keep the current | |
552 * state (this happens very often!). Otherwise invalidate | |
553 * current_state and figure it out below. | |
554 */ | |
555 if (current_lnum != lnum) | |
556 invalidate_current_state(); | |
557 } | |
558 else | |
559 invalidate_current_state(); | |
560 | |
561 /* | |
562 * Try to synchronize from a saved state in b_sst_array[]. | |
563 * Only do this if lnum is not before and not to far beyond a saved state. | |
564 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
565 if (INVALID_STATE(¤t_state) && syn_block->b_sst_array != NULL) |
7 | 566 { |
567 /* 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
|
568 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 569 { |
570 if (p->sst_lnum > lnum) | |
571 break; | |
572 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0) | |
573 { | |
574 last_valid = p; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
575 if (p->sst_lnum >= lnum - syn_block->b_syn_sync_minlines) |
7 | 576 last_min_valid = p; |
577 } | |
578 } | |
579 if (last_min_valid != NULL) | |
580 load_current_state(last_min_valid); | |
581 } | |
582 | |
583 /* | |
584 * If "lnum" is before or far beyond a line with a saved state, need to | |
585 * re-synchronize. | |
586 */ | |
587 if (INVALID_STATE(¤t_state)) | |
588 { | |
589 syn_sync(wp, lnum, last_valid); | |
2906 | 590 if (current_lnum == 1) |
591 /* First line is always valid, no matter "minlines". */ | |
592 first_stored = 1; | |
593 else | |
594 /* Need to parse "minlines" lines before state can be considered | |
595 * valid to store. */ | |
596 first_stored = current_lnum + syn_block->b_syn_sync_minlines; | |
7 | 597 } |
598 else | |
599 first_stored = current_lnum; | |
600 | |
601 /* | |
602 * Advance from the sync point or saved state until the current line. | |
603 * Save some entries for syncing with later on. | |
604 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
605 if (syn_block->b_sst_len <= Rows) |
819 | 606 dist = 999999; |
607 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
608 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 609 while (current_lnum < lnum) |
610 { | |
611 syn_start_line(); | |
612 (void)syn_finish_line(FALSE); | |
613 ++current_lnum; | |
614 | |
615 /* If we parsed at least "minlines" lines or started at a valid | |
616 * state, the current state is considered valid. */ | |
617 if (current_lnum >= first_stored) | |
618 { | |
619 /* Check if the saved state entry is for the current line and is | |
620 * equal to the current state. If so, then validate all saved | |
621 * states that depended on a change before the parsed line. */ | |
622 if (prev == NULL) | |
1512 | 623 prev = syn_stack_find_entry(current_lnum - 1); |
624 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
625 sp = syn_block->b_sst_first; |
7 | 626 else |
1512 | 627 sp = prev; |
628 while (sp != NULL && sp->sst_lnum < current_lnum) | |
629 sp = sp->sst_next; | |
7 | 630 if (sp != NULL |
631 && sp->sst_lnum == current_lnum | |
632 && syn_stack_equal(sp)) | |
633 { | |
634 parsed_lnum = current_lnum; | |
635 prev = sp; | |
636 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) | |
637 { | |
638 if (sp->sst_lnum <= lnum) | |
639 /* valid state before desired line, use this one */ | |
640 prev = sp; | |
641 else if (sp->sst_change_lnum == 0) | |
642 /* past saved states depending on change, break here. */ | |
643 break; | |
644 sp->sst_change_lnum = 0; | |
645 sp = sp->sst_next; | |
646 } | |
647 load_current_state(prev); | |
648 } | |
649 /* Store the state at this line when it's the first one, the line | |
650 * where we start parsing, or some distance from the previously | |
651 * saved state. But only when parsed at least 'minlines'. */ | |
652 else if (prev == NULL | |
653 || current_lnum == lnum | |
654 || current_lnum >= prev->sst_lnum + dist) | |
1512 | 655 prev = store_current_state(); |
7 | 656 } |
657 | |
658 /* This can take a long time: break when CTRL-C pressed. The current | |
659 * state will be wrong then. */ | |
660 line_breakcheck(); | |
661 if (got_int) | |
662 { | |
663 current_lnum = lnum; | |
664 break; | |
665 } | |
666 } | |
667 | |
668 syn_start_line(); | |
669 } | |
670 | |
671 /* | |
672 * We cannot simply discard growarrays full of state_items or buf_states; we | |
673 * have to manually release their extmatch pointers first. | |
674 */ | |
675 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
676 clear_syn_state(synstate_T *p) |
7 | 677 { |
678 int i; | |
679 garray_T *gap; | |
680 | |
681 if (p->sst_stacksize > SST_FIX_STATES) | |
682 { | |
683 gap = &(p->sst_union.sst_ga); | |
684 for (i = 0; i < gap->ga_len; i++) | |
685 unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch); | |
686 ga_clear(gap); | |
687 } | |
688 else | |
689 { | |
690 for (i = 0; i < p->sst_stacksize; i++) | |
691 unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch); | |
692 } | |
693 } | |
694 | |
695 /* | |
696 * Cleanup the current_state stack. | |
697 */ | |
698 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
699 clear_current_state(void) |
7 | 700 { |
701 int i; | |
702 stateitem_T *sip; | |
703 | |
704 sip = (stateitem_T *)(current_state.ga_data); | |
705 for (i = 0; i < current_state.ga_len; i++) | |
706 unref_extmatch(sip[i].si_extmatch); | |
707 ga_clear(¤t_state); | |
708 } | |
709 | |
710 /* | |
711 * Try to find a synchronisation point for line "lnum". | |
712 * | |
713 * This sets current_lnum and the current state. One of three methods is | |
714 * used: | |
715 * 1. Search backwards for the end of a C-comment. | |
716 * 2. Search backwards for given sync patterns. | |
717 * 3. Simply start on a given number of lines above "lnum". | |
718 */ | |
719 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
720 syn_sync( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
721 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
722 linenr_T start_lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
723 synstate_T *last_valid) |
7 | 724 { |
725 buf_T *curbuf_save; | |
726 win_T *curwin_save; | |
727 pos_T cursor_save; | |
728 int idx; | |
729 linenr_T lnum; | |
730 linenr_T end_lnum; | |
731 linenr_T break_lnum; | |
732 int had_sync_point; | |
733 stateitem_T *cur_si; | |
734 synpat_T *spp; | |
735 char_u *line; | |
736 int found_flags = 0; | |
737 int found_match_idx = 0; | |
738 linenr_T found_current_lnum = 0; | |
739 int found_current_col= 0; | |
740 lpos_T found_m_endpos; | |
442 | 741 colnr_T prev_current_col; |
7 | 742 |
743 /* | |
744 * Clear any current state that might be hanging around. | |
745 */ | |
746 invalidate_current_state(); | |
747 | |
748 /* | |
749 * Start at least "minlines" back. Default starting point for parsing is | |
750 * there. | |
751 * Start further back, to avoid that scrolling backwards will result in | |
752 * resyncing for every line. Now it resyncs only one out of N lines, | |
753 * where N is minlines * 1.5, or minlines * 2 if minlines is small. | |
754 * Watch out for overflow when minlines is MAXLNUM. | |
755 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
756 if (syn_block->b_syn_sync_minlines > start_lnum) |
7 | 757 start_lnum = 1; |
758 else | |
759 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
760 if (syn_block->b_syn_sync_minlines == 1) |
7 | 761 lnum = 1; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
762 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
|
763 lnum = syn_block->b_syn_sync_minlines * 2; |
7 | 764 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
765 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
|
766 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
|
767 && lnum > syn_block->b_syn_sync_maxlines) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
768 lnum = syn_block->b_syn_sync_maxlines; |
7 | 769 if (lnum >= start_lnum) |
770 start_lnum = 1; | |
771 else | |
772 start_lnum -= lnum; | |
773 } | |
774 current_lnum = start_lnum; | |
775 | |
776 /* | |
777 * 1. Search backwards for the end of a C-style comment. | |
778 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
779 if (syn_block->b_syn_sync_flags & SF_CCOMMENT) |
7 | 780 { |
781 /* Need to make syn_buf the current buffer for a moment, to be able to | |
782 * use find_start_comment(). */ | |
783 curwin_save = curwin; | |
784 curwin = wp; | |
785 curbuf_save = curbuf; | |
786 curbuf = syn_buf; | |
787 | |
788 /* | |
789 * Skip lines that end in a backslash. | |
790 */ | |
791 for ( ; start_lnum > 1; --start_lnum) | |
792 { | |
793 line = ml_get(start_lnum - 1); | |
794 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') | |
795 break; | |
796 } | |
797 current_lnum = start_lnum; | |
798 | |
799 /* set cursor to start of search */ | |
800 cursor_save = wp->w_cursor; | |
801 wp->w_cursor.lnum = start_lnum; | |
802 wp->w_cursor.col = 0; | |
803 | |
804 /* | |
805 * If the line is inside a comment, need to find the syntax item that | |
806 * defines the comment. | |
807 * Restrict the search for the end of a comment to b_syn_sync_maxlines. | |
808 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
809 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
|
810 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
811 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
|
812 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
|
813 == syn_block->b_syn_sync_id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
814 && SYN_ITEMS(syn_block)[idx].sp_type == SPTYPE_START) |
7 | 815 { |
816 validate_current_state(); | |
817 if (push_current_state(idx) == OK) | |
818 update_si_attr(current_state.ga_len - 1); | |
819 break; | |
820 } | |
821 } | |
822 | |
823 /* restore cursor and buffer */ | |
824 wp->w_cursor = cursor_save; | |
825 curwin = curwin_save; | |
826 curbuf = curbuf_save; | |
827 } | |
828 | |
829 /* | |
830 * 2. Search backwards for given sync patterns. | |
831 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
832 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
|
833 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
834 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
|
835 && 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
|
836 break_lnum = start_lnum - syn_block->b_syn_sync_maxlines; |
7 | 837 else |
838 break_lnum = 0; | |
839 | |
699 | 840 found_m_endpos.lnum = 0; |
841 found_m_endpos.col = 0; | |
7 | 842 end_lnum = start_lnum; |
843 lnum = start_lnum; | |
844 while (--lnum > break_lnum) | |
845 { | |
846 /* This can take a long time: break when CTRL-C pressed. */ | |
847 line_breakcheck(); | |
848 if (got_int) | |
849 { | |
850 invalidate_current_state(); | |
851 current_lnum = start_lnum; | |
852 break; | |
853 } | |
854 | |
855 /* Check if we have run into a valid saved state stack now. */ | |
856 if (last_valid != NULL && lnum == last_valid->sst_lnum) | |
857 { | |
858 load_current_state(last_valid); | |
859 break; | |
860 } | |
861 | |
862 /* | |
863 * Check if the previous line has the line-continuation pattern. | |
864 */ | |
865 if (lnum > 1 && syn_match_linecont(lnum - 1)) | |
866 continue; | |
867 | |
868 /* | |
869 * Start with nothing on the state stack | |
870 */ | |
871 validate_current_state(); | |
872 | |
873 for (current_lnum = lnum; current_lnum < end_lnum; ++current_lnum) | |
874 { | |
875 syn_start_line(); | |
876 for (;;) | |
877 { | |
878 had_sync_point = syn_finish_line(TRUE); | |
879 /* | |
880 * When a sync point has been found, remember where, and | |
881 * continue to look for another one, further on in the line. | |
882 */ | |
883 if (had_sync_point && current_state.ga_len) | |
884 { | |
885 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
886 if (cur_si->si_m_endpos.lnum > start_lnum) | |
887 { | |
888 /* ignore match that goes to after where started */ | |
889 current_lnum = end_lnum; | |
890 break; | |
891 } | |
1371 | 892 if (cur_si->si_idx < 0) |
893 { | |
894 /* Cannot happen? */ | |
895 found_flags = 0; | |
896 found_match_idx = KEYWORD_IDX; | |
897 } | |
898 else | |
899 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
900 spp = &(SYN_ITEMS(syn_block)[cur_si->si_idx]); |
1371 | 901 found_flags = spp->sp_flags; |
902 found_match_idx = spp->sp_sync_idx; | |
903 } | |
7 | 904 found_current_lnum = current_lnum; |
905 found_current_col = current_col; | |
906 found_m_endpos = cur_si->si_m_endpos; | |
907 /* | |
908 * Continue after the match (be aware of a zero-length | |
909 * match). | |
910 */ | |
911 if (found_m_endpos.lnum > current_lnum) | |
912 { | |
913 current_lnum = found_m_endpos.lnum; | |
914 current_col = found_m_endpos.col; | |
915 if (current_lnum >= end_lnum) | |
916 break; | |
917 } | |
918 else if (found_m_endpos.col > current_col) | |
919 current_col = found_m_endpos.col; | |
920 else | |
921 ++current_col; | |
922 | |
923 /* syn_current_attr() will have skipped the check for | |
442 | 924 * an item that ends here, need to do that now. Be |
925 * careful not to go past the NUL. */ | |
926 prev_current_col = current_col; | |
927 if (syn_getcurline()[current_col] != NUL) | |
928 ++current_col; | |
7 | 929 check_state_ends(); |
442 | 930 current_col = prev_current_col; |
7 | 931 } |
932 else | |
933 break; | |
934 } | |
935 } | |
936 | |
937 /* | |
938 * If a sync point was encountered, break here. | |
939 */ | |
940 if (found_flags) | |
941 { | |
942 /* | |
943 * Put the item that was specified by the sync point on the | |
944 * state stack. If there was no item specified, make the | |
945 * state stack empty. | |
946 */ | |
947 clear_current_state(); | |
948 if (found_match_idx >= 0 | |
949 && push_current_state(found_match_idx) == OK) | |
950 update_si_attr(current_state.ga_len - 1); | |
951 | |
952 /* | |
953 * When using "grouphere", continue from the sync point | |
954 * match, until the end of the line. Parsing starts at | |
955 * the next line. | |
956 * For "groupthere" the parsing starts at start_lnum. | |
957 */ | |
958 if (found_flags & HL_SYNC_HERE) | |
959 { | |
960 if (current_state.ga_len) | |
961 { | |
962 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
963 cur_si->si_h_startpos.lnum = found_current_lnum; | |
964 cur_si->si_h_startpos.col = found_current_col; | |
965 update_si_end(cur_si, (int)current_col, TRUE); | |
966 check_keepend(); | |
967 } | |
968 current_col = found_m_endpos.col; | |
969 current_lnum = found_m_endpos.lnum; | |
970 (void)syn_finish_line(FALSE); | |
971 ++current_lnum; | |
972 } | |
973 else | |
974 current_lnum = start_lnum; | |
975 | |
976 break; | |
977 } | |
978 | |
979 end_lnum = lnum; | |
980 invalidate_current_state(); | |
981 } | |
982 | |
983 /* Ran into start of the file or exceeded maximum number of lines */ | |
984 if (lnum <= break_lnum) | |
985 { | |
986 invalidate_current_state(); | |
987 current_lnum = break_lnum + 1; | |
988 } | |
989 } | |
990 | |
991 validate_current_state(); | |
992 } | |
993 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
994 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
995 save_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
996 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
997 if (syn_block->b_syn_isk != empty_option) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
998 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
999 mch_memmove(chartab, syn_buf->b_chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1000 mch_memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1001 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1002 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1003 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1004 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1005 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1006 restore_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1007 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1008 if (syn_win->w_s->b_syn_isk != empty_option) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1009 mch_memmove(syn_buf->b_chartab, chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1010 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1011 |
7 | 1012 /* |
1013 * Return TRUE if the line-continuation pattern matches in line "lnum". | |
1014 */ | |
1015 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1016 syn_match_linecont(linenr_T lnum) |
7 | 1017 { |
1018 regmmatch_T regmatch; | |
6375 | 1019 int r; |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1020 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ |
7 | 1021 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1022 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
|
1023 { |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1024 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1025 save_chartab(buf_chartab); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1026 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
|
1027 regmatch.regprog = syn_block->b_syn_linecont_prog; |
6375 | 1028 r = syn_regexec(®match, lnum, (colnr_T)0, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1029 IF_SYN_TIME(&syn_block->b_syn_linecont_time)); |
6375 | 1030 syn_block->b_syn_linecont_prog = regmatch.regprog; |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1031 restore_chartab(buf_chartab); |
6375 | 1032 return r; |
7 | 1033 } |
1034 return FALSE; | |
1035 } | |
1036 | |
1037 /* | |
1038 * Prepare the current state for the start of a line. | |
1039 */ | |
1040 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1041 syn_start_line(void) |
7 | 1042 { |
1043 current_finished = FALSE; | |
1044 current_col = 0; | |
1045 | |
1046 /* | |
1047 * Need to update the end of a start/skip/end that continues from the | |
1048 * previous line and regions that have "keepend". | |
1049 */ | |
1050 if (current_state.ga_len > 0) | |
2863 | 1051 { |
7 | 1052 syn_update_ends(TRUE); |
2863 | 1053 check_state_ends(); |
1054 } | |
7 | 1055 |
1056 next_match_idx = -1; | |
1057 ++current_line_id; | |
1058 } | |
1059 | |
1060 /* | |
1061 * Check for items in the stack that need their end updated. | |
1062 * When "startofline" is TRUE the last item is always updated. | |
1063 * When "startofline" is FALSE the item with "keepend" is forcefully updated. | |
1064 */ | |
1065 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1066 syn_update_ends(int startofline) |
7 | 1067 { |
1068 stateitem_T *cur_si; | |
1069 int i; | |
991 | 1070 int seen_keepend; |
7 | 1071 |
1072 if (startofline) | |
1073 { | |
1074 /* Check for a match carried over from a previous line with a | |
1075 * contained region. The match ends as soon as the region ends. */ | |
1076 for (i = 0; i < current_state.ga_len; ++i) | |
1077 { | |
1078 cur_si = &CUR_STATE(i); | |
1079 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1080 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type |
7 | 1081 == SPTYPE_MATCH |
1082 && cur_si->si_m_endpos.lnum < current_lnum) | |
1083 { | |
1084 cur_si->si_flags |= HL_MATCHCONT; | |
1085 cur_si->si_m_endpos.lnum = 0; | |
1086 cur_si->si_m_endpos.col = 0; | |
1087 cur_si->si_h_endpos = cur_si->si_m_endpos; | |
1088 cur_si->si_ends = TRUE; | |
1089 } | |
1090 } | |
1091 } | |
1092 | |
1093 /* | |
1094 * Need to update the end of a start/skip/end that continues from the | |
1095 * previous line. And regions that have "keepend", because they may | |
991 | 1096 * influence contained items. If we've just removed "extend" |
1097 * (startofline == 0) then we should update ends of normal regions | |
1098 * contained inside "keepend" because "extend" could have extended | |
1099 * these "keepend" regions as well as contained normal regions. | |
7 | 1100 * Then check for items ending in column 0. |
1101 */ | |
1102 i = current_state.ga_len - 1; | |
1103 if (keepend_level >= 0) | |
1104 for ( ; i > keepend_level; --i) | |
1105 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
1106 break; | |
991 | 1107 |
1108 seen_keepend = FALSE; | |
7 | 1109 for ( ; i < current_state.ga_len; ++i) |
1110 { | |
1111 cur_si = &CUR_STATE(i); | |
1112 if ((cur_si->si_flags & HL_KEEPEND) | |
991 | 1113 || (seen_keepend && !startofline) |
7 | 1114 || (i == current_state.ga_len - 1 && startofline)) |
1115 { | |
1116 cur_si->si_h_startpos.col = 0; /* start highl. in col 0 */ | |
1117 cur_si->si_h_startpos.lnum = current_lnum; | |
1118 | |
1119 if (!(cur_si->si_flags & HL_MATCHCONT)) | |
1120 update_si_end(cur_si, (int)current_col, !startofline); | |
991 | 1121 |
1122 if (!startofline && (cur_si->si_flags & HL_KEEPEND)) | |
1123 seen_keepend = TRUE; | |
7 | 1124 } |
1125 } | |
1126 check_keepend(); | |
1127 } | |
1128 | |
1129 /**************************************** | |
1130 * Handling of the state stack cache. | |
1131 */ | |
1132 | |
1133 /* | |
1134 * EXPLANATION OF THE SYNTAX STATE STACK CACHE | |
1135 * | |
1136 * To speed up syntax highlighting, the state stack for the start of some | |
1137 * lines is cached. These entries can be used to start parsing at that point. | |
1138 * | |
1139 * The stack is kept in b_sst_array[] for each buffer. There is a list of | |
1140 * valid entries. b_sst_first points to the first one, then follow sst_next. | |
1141 * The entries are sorted on line number. The first entry is often for line 2 | |
1142 * (line 1 always starts with an empty stack). | |
1143 * There is also a list for free entries. This construction is used to avoid | |
1144 * having to allocate and free memory blocks too often. | |
1145 * | |
1146 * When making changes to the buffer, this is logged in b_mod_*. When calling | |
1147 * update_screen() to update the display, it will call | |
1148 * syn_stack_apply_changes() for each displayed buffer to adjust the cached | |
1149 * entries. The entries which are inside the changed area are removed, | |
1150 * because they must be recomputed. Entries below the changed have their line | |
1151 * number adjusted for deleted/inserted lines, and have their sst_change_lnum | |
1152 * set to indicate that a check must be made if the changed lines would change | |
1153 * the cached entry. | |
1154 * | |
1155 * When later displaying lines, an entry is stored for each line. Displayed | |
1156 * lines are likely to be displayed again, in which case the state at the | |
1157 * start of the line is needed. | |
1158 * For not displayed lines, an entry is stored for every so many lines. These | |
1159 * entries will be used e.g., when scrolling backwards. The distance between | |
1160 * entries depends on the number of lines in the buffer. For small buffers | |
1161 * the distance is fixed at SST_DIST, for large buffers there is a fixed | |
1162 * number of entries SST_MAX_ENTRIES, and the distance is computed. | |
1163 */ | |
1164 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1165 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1166 syn_stack_free_block(synblock_T *block) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1167 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1168 synstate_T *p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1169 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1170 if (block->b_sst_array != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1171 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1172 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
|
1173 clear_syn_state(p); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1174 vim_free(block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1175 block->b_sst_array = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1176 block->b_sst_len = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1177 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1178 } |
7 | 1179 /* |
1180 * Free b_sst_array[] for buffer "buf". | |
1181 * Used when syntax items changed to force resyncing everywhere. | |
1182 */ | |
1183 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1184 syn_stack_free_all(synblock_T *block) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1185 { |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1186 #ifdef FEAT_FOLDING |
7 | 1187 win_T *wp; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1188 #endif |
7 | 1189 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1190 syn_stack_free_block(block); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1191 |
7 | 1192 #ifdef FEAT_FOLDING |
1193 /* When using "syntax" fold method, must update all folds. */ | |
1194 FOR_ALL_WINDOWS(wp) | |
1195 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1196 if (wp->w_s == block && foldmethodIsSyntax(wp)) |
7 | 1197 foldUpdateAll(wp); |
1198 } | |
1199 #endif | |
1200 } | |
1201 | |
1202 /* | |
1203 * Allocate the syntax state stack for syn_buf when needed. | |
1204 * If the number of entries in b_sst_array[] is much too big or a bit too | |
1205 * small, reallocate it. | |
1206 * Also used to allocate b_sst_array[] for the first time. | |
1207 */ | |
1208 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1209 syn_stack_alloc(void) |
7 | 1210 { |
1211 long len; | |
1212 synstate_T *to, *from; | |
1213 synstate_T *sstp; | |
1214 | |
1215 len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; | |
1216 if (len < SST_MIN_ENTRIES) | |
1217 len = SST_MIN_ENTRIES; | |
1218 else if (len > SST_MAX_ENTRIES) | |
1219 len = SST_MAX_ENTRIES; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1220 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) |
7 | 1221 { |
1222 /* Allocate 50% too much, to avoid reallocating too often. */ | |
1223 len = syn_buf->b_ml.ml_line_count; | |
1224 len = (len + len / 2) / SST_DIST + Rows * 2; | |
1225 if (len < SST_MIN_ENTRIES) | |
1226 len = SST_MIN_ENTRIES; | |
1227 else if (len > SST_MAX_ENTRIES) | |
1228 len = SST_MAX_ENTRIES; | |
1229 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1230 if (syn_block->b_sst_array != NULL) |
7 | 1231 { |
1232 /* When shrinking the array, cleanup the existing stack. | |
1233 * 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
|
1234 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len |
7 | 1235 && syn_stack_cleanup()) |
1236 ; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1237 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
|
1238 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; |
7 | 1239 } |
1240 | |
1241 sstp = (synstate_T *)alloc_clear((unsigned)(len * sizeof(synstate_T))); | |
1242 if (sstp == NULL) /* out of memory! */ | |
1243 return; | |
1244 | |
1245 to = sstp - 1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1246 if (syn_block->b_sst_array != NULL) |
7 | 1247 { |
1248 /* 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
|
1249 for (from = syn_block->b_sst_first; from != NULL; |
7 | 1250 from = from->sst_next) |
1251 { | |
1252 ++to; | |
1253 *to = *from; | |
1254 to->sst_next = to + 1; | |
1255 } | |
1256 } | |
1257 if (to != sstp - 1) | |
1258 { | |
1259 to->sst_next = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1260 syn_block->b_sst_first = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1261 syn_block->b_sst_freecount = len - (int)(to - sstp) - 1; |
7 | 1262 } |
1263 else | |
1264 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1265 syn_block->b_sst_first = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1266 syn_block->b_sst_freecount = len; |
7 | 1267 } |
1268 | |
1269 /* Create the list of free entries. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1270 syn_block->b_sst_firstfree = to + 1; |
7 | 1271 while (++to < sstp + len) |
1272 to->sst_next = to + 1; | |
1273 (sstp + len - 1)->sst_next = NULL; | |
1274 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1275 vim_free(syn_block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1276 syn_block->b_sst_array = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1277 syn_block->b_sst_len = len; |
7 | 1278 } |
1279 } | |
1280 | |
1281 /* | |
1282 * Check for changes in a buffer to affect stored syntax states. Uses the | |
1283 * b_mod_* fields. | |
1284 * Called from update_screen(), before screen is being updated, once for each | |
1285 * displayed buffer. | |
1286 */ | |
1287 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1288 syn_stack_apply_changes(buf_T *buf) |
7 | 1289 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1290 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1291 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1292 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
|
1293 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1294 FOR_ALL_WINDOWS(wp) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1295 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1296 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
|
1297 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
|
1298 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1299 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1300 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1301 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1302 syn_stack_apply_changes_block(synblock_T *block, buf_T *buf) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1303 { |
7 | 1304 synstate_T *p, *prev, *np; |
1305 linenr_T n; | |
1306 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1307 if (block->b_sst_array == NULL) /* nothing to do */ |
7 | 1308 return; |
1309 | |
1310 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1311 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
|
1312 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1313 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) |
7 | 1314 { |
1315 n = p->sst_lnum + buf->b_mod_xlines; | |
1316 if (n <= buf->b_mod_bot) | |
1317 { | |
1318 /* this state is inside the changed area, remove it */ | |
1319 np = p->sst_next; | |
1320 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1321 block->b_sst_first = np; |
7 | 1322 else |
1323 prev->sst_next = np; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1324 syn_stack_free_entry(block, p); |
7 | 1325 p = np; |
1326 continue; | |
1327 } | |
1328 /* This state is below the changed area. Remember the line | |
1329 * that needs to be parsed before this entry can be made valid | |
1330 * again. */ | |
1331 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) | |
1332 { | |
1333 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) | |
1334 p->sst_change_lnum += buf->b_mod_xlines; | |
1335 else | |
1336 p->sst_change_lnum = buf->b_mod_top; | |
1337 } | |
1338 if (p->sst_change_lnum == 0 | |
1339 || p->sst_change_lnum < buf->b_mod_bot) | |
1340 p->sst_change_lnum = buf->b_mod_bot; | |
1341 | |
1342 p->sst_lnum = n; | |
1343 } | |
1344 prev = p; | |
1345 p = p->sst_next; | |
1346 } | |
1347 } | |
1348 | |
1349 /* | |
1350 * Reduce the number of entries in the state stack for syn_buf. | |
1351 * Returns TRUE if at least one entry was freed. | |
1352 */ | |
1353 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1354 syn_stack_cleanup(void) |
7 | 1355 { |
1356 synstate_T *p, *prev; | |
1357 disptick_T tick; | |
1358 int above; | |
1359 int dist; | |
1360 int retval = FALSE; | |
1361 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1362 if (syn_block->b_sst_array == NULL || syn_block->b_sst_first == NULL) |
7 | 1363 return retval; |
1364 | |
1365 /* 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
|
1366 if (syn_block->b_sst_len <= Rows) |
819 | 1367 dist = 999999; |
1368 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1369 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 1370 |
1371 /* | |
2020 | 1372 * Go through the list to find the "tick" for the oldest entry that can |
7 | 1373 * be removed. Set "above" when the "tick" for the oldest entry is above |
1374 * "b_sst_lasttick" (the display tick wraps around). | |
1375 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1376 tick = syn_block->b_sst_lasttick; |
7 | 1377 above = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1378 prev = syn_block->b_sst_first; |
7 | 1379 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1380 { | |
1381 if (prev->sst_lnum + dist > p->sst_lnum) | |
1382 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1383 if (p->sst_tick > syn_block->b_sst_lasttick) |
7 | 1384 { |
1385 if (!above || p->sst_tick < tick) | |
1386 tick = p->sst_tick; | |
1387 above = TRUE; | |
1388 } | |
1389 else if (!above && p->sst_tick < tick) | |
1390 tick = p->sst_tick; | |
1391 } | |
1392 } | |
1393 | |
1394 /* | |
1395 * Go through the list to make the entries for the oldest tick at an | |
1396 * interval of several lines. | |
1397 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1398 prev = syn_block->b_sst_first; |
7 | 1399 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1400 { | |
1401 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) | |
1402 { | |
1403 /* Move this entry from used list to free list */ | |
1404 prev->sst_next = p->sst_next; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1405 syn_stack_free_entry(syn_block, p); |
7 | 1406 p = prev; |
1407 retval = TRUE; | |
1408 } | |
1409 } | |
1410 return retval; | |
1411 } | |
1412 | |
1413 /* | |
1414 * Free the allocated memory for a syn_state item. | |
1415 * Move the entry into the free list. | |
1416 */ | |
1417 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1418 syn_stack_free_entry(synblock_T *block, synstate_T *p) |
7 | 1419 { |
1420 clear_syn_state(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1421 p->sst_next = block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1422 block->b_sst_firstfree = p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1423 ++block->b_sst_freecount; |
7 | 1424 } |
1425 | |
1426 /* | |
1427 * Find an entry in the list of state stacks at or before "lnum". | |
1428 * Returns NULL when there is no entry or the first entry is after "lnum". | |
1429 */ | |
1430 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1431 syn_stack_find_entry(linenr_T lnum) |
7 | 1432 { |
1433 synstate_T *p, *prev; | |
1434 | |
1435 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1436 for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) |
7 | 1437 { |
1438 if (p->sst_lnum == lnum) | |
1439 return p; | |
1440 if (p->sst_lnum > lnum) | |
1441 break; | |
1442 } | |
1443 return prev; | |
1444 } | |
1445 | |
1446 /* | |
1447 * Try saving the current state in b_sst_array[]. | |
1448 * The current state must be valid for the start of the current_lnum line! | |
1449 */ | |
1450 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1451 store_current_state(void) |
7 | 1452 { |
1453 int i; | |
1454 synstate_T *p; | |
1455 bufstate_T *bp; | |
1456 stateitem_T *cur_si; | |
1512 | 1457 synstate_T *sp = syn_stack_find_entry(current_lnum); |
7 | 1458 |
1459 /* | |
1460 * If the current state contains a start or end pattern that continues | |
1461 * from the previous line, we can't use it. Don't store it then. | |
1462 */ | |
1463 for (i = current_state.ga_len - 1; i >= 0; --i) | |
1464 { | |
1465 cur_si = &CUR_STATE(i); | |
1466 if (cur_si->si_h_startpos.lnum >= current_lnum | |
1467 || cur_si->si_m_endpos.lnum >= current_lnum | |
1468 || cur_si->si_h_endpos.lnum >= current_lnum | |
1469 || (cur_si->si_end_idx | |
1470 && cur_si->si_eoe_pos.lnum >= current_lnum)) | |
1471 break; | |
1472 } | |
1473 if (i >= 0) | |
1474 { | |
1475 if (sp != NULL) | |
1476 { | |
1477 /* 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
|
1478 if (syn_block->b_sst_first == sp) |
7 | 1479 /* it's the first entry */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1480 syn_block->b_sst_first = sp->sst_next; |
7 | 1481 else |
1482 { | |
1483 /* 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
|
1484 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 1485 if (p->sst_next == sp) |
1486 break; | |
840 | 1487 if (p != NULL) /* just in case */ |
1488 p->sst_next = sp->sst_next; | |
7 | 1489 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1490 syn_stack_free_entry(syn_block, sp); |
7 | 1491 sp = NULL; |
1492 } | |
1493 } | |
1494 else if (sp == NULL || sp->sst_lnum != current_lnum) | |
1495 { | |
1496 /* | |
1497 * Add a new entry | |
1498 */ | |
1499 /* 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
|
1500 if (syn_block->b_sst_freecount == 0) |
7 | 1501 { |
1502 (void)syn_stack_cleanup(); | |
1503 /* "sp" may have been moved to the freelist now */ | |
1504 sp = syn_stack_find_entry(current_lnum); | |
1505 } | |
1506 /* 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
|
1507 if (syn_block->b_sst_freecount == 0) |
7 | 1508 sp = NULL; |
1509 else | |
1510 { | |
1511 /* Take the first item from the free list and put it in the used | |
1512 * list, after *sp */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1513 p = syn_block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1514 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
|
1515 --syn_block->b_sst_freecount; |
7 | 1516 if (sp == NULL) |
1517 { | |
1518 /* Insert in front of the list */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1519 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
|
1520 syn_block->b_sst_first = p; |
7 | 1521 } |
1522 else | |
1523 { | |
1524 /* insert in list after *sp */ | |
1525 p->sst_next = sp->sst_next; | |
1526 sp->sst_next = p; | |
1527 } | |
1528 sp = p; | |
1529 sp->sst_stacksize = 0; | |
1530 sp->sst_lnum = current_lnum; | |
1531 } | |
1532 } | |
1533 if (sp != NULL) | |
1534 { | |
1535 /* When overwriting an existing state stack, clear it first */ | |
1536 clear_syn_state(sp); | |
1537 sp->sst_stacksize = current_state.ga_len; | |
1538 if (current_state.ga_len > SST_FIX_STATES) | |
1539 { | |
1540 /* Need to clear it, might be something remaining from when the | |
1541 * length was less than SST_FIX_STATES. */ | |
1542 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); | |
1543 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) | |
1544 sp->sst_stacksize = 0; | |
1545 else | |
1546 sp->sst_union.sst_ga.ga_len = current_state.ga_len; | |
1547 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1548 } | |
1549 else | |
1550 bp = sp->sst_union.sst_stack; | |
1551 for (i = 0; i < sp->sst_stacksize; ++i) | |
1552 { | |
1553 bp[i].bs_idx = CUR_STATE(i).si_idx; | |
1554 bp[i].bs_flags = CUR_STATE(i).si_flags; | |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1555 #ifdef FEAT_CONCEAL |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1556 bp[i].bs_seqnr = CUR_STATE(i).si_seqnr; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1557 bp[i].bs_cchar = CUR_STATE(i).si_cchar; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1558 #endif |
7 | 1559 bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); |
1560 } | |
1561 sp->sst_next_flags = current_next_flags; | |
1562 sp->sst_next_list = current_next_list; | |
1563 sp->sst_tick = display_tick; | |
1564 sp->sst_change_lnum = 0; | |
1565 } | |
1566 current_state_stored = TRUE; | |
1567 return sp; | |
1568 } | |
1569 | |
1570 /* | |
1571 * Copy a state stack from "from" in b_sst_array[] to current_state; | |
1572 */ | |
1573 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1574 load_current_state(synstate_T *from) |
7 | 1575 { |
1576 int i; | |
1577 bufstate_T *bp; | |
1578 | |
1579 clear_current_state(); | |
1580 validate_current_state(); | |
1581 keepend_level = -1; | |
1582 if (from->sst_stacksize | |
1583 && ga_grow(¤t_state, from->sst_stacksize) != FAIL) | |
1584 { | |
1585 if (from->sst_stacksize > SST_FIX_STATES) | |
1586 bp = SYN_STATE_P(&(from->sst_union.sst_ga)); | |
1587 else | |
1588 bp = from->sst_union.sst_stack; | |
1589 for (i = 0; i < from->sst_stacksize; ++i) | |
1590 { | |
1591 CUR_STATE(i).si_idx = bp[i].bs_idx; | |
1592 CUR_STATE(i).si_flags = bp[i].bs_flags; | |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1593 #ifdef FEAT_CONCEAL |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1594 CUR_STATE(i).si_seqnr = bp[i].bs_seqnr; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1595 CUR_STATE(i).si_cchar = bp[i].bs_cchar; |
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
1596 #endif |
7 | 1597 CUR_STATE(i).si_extmatch = ref_extmatch(bp[i].bs_extmatch); |
1598 if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) | |
1599 keepend_level = i; | |
1600 CUR_STATE(i).si_ends = FALSE; | |
1601 CUR_STATE(i).si_m_lnum = 0; | |
1602 if (CUR_STATE(i).si_idx >= 0) | |
1603 CUR_STATE(i).si_next_list = | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1604 (SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_next_list; |
7 | 1605 else |
1606 CUR_STATE(i).si_next_list = NULL; | |
1607 update_si_attr(i); | |
1608 } | |
1609 current_state.ga_len = from->sst_stacksize; | |
1610 } | |
1611 current_next_list = from->sst_next_list; | |
1612 current_next_flags = from->sst_next_flags; | |
1613 current_lnum = from->sst_lnum; | |
1614 } | |
1615 | |
1616 /* | |
1617 * Compare saved state stack "*sp" with the current state. | |
1618 * Return TRUE when they are equal. | |
1619 */ | |
1620 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1621 syn_stack_equal(synstate_T *sp) |
7 | 1622 { |
1623 int i, j; | |
1624 bufstate_T *bp; | |
1625 reg_extmatch_T *six, *bsx; | |
1626 | |
1627 /* First a quick check if the stacks have the same size end nextlist. */ | |
1628 if (sp->sst_stacksize == current_state.ga_len | |
1629 && sp->sst_next_list == current_next_list) | |
1630 { | |
1631 /* Need to compare all states on both stacks. */ | |
1632 if (sp->sst_stacksize > SST_FIX_STATES) | |
1633 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1634 else | |
1635 bp = sp->sst_union.sst_stack; | |
1636 | |
1637 for (i = current_state.ga_len; --i >= 0; ) | |
1638 { | |
1639 /* If the item has another index the state is different. */ | |
1640 if (bp[i].bs_idx != CUR_STATE(i).si_idx) | |
1641 break; | |
1642 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) | |
1643 { | |
1644 /* When the extmatch pointers are different, the strings in | |
1645 * them can still be the same. Check if the extmatch | |
1646 * references are equal. */ | |
1647 bsx = bp[i].bs_extmatch; | |
1648 six = CUR_STATE(i).si_extmatch; | |
1649 /* If one of the extmatch pointers is NULL the states are | |
1650 * different. */ | |
1651 if (bsx == NULL || six == NULL) | |
1652 break; | |
1653 for (j = 0; j < NSUBEXP; ++j) | |
1654 { | |
1655 /* Check each referenced match string. They must all be | |
1656 * equal. */ | |
1657 if (bsx->matches[j] != six->matches[j]) | |
1658 { | |
1659 /* If the pointer is different it can still be the | |
1660 * same text. Compare the strings, ignore case when | |
1661 * the start item has the sp_ic flag set. */ | |
1662 if (bsx->matches[j] == NULL | |
1663 || six->matches[j] == NULL) | |
1664 break; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1665 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic |
7 | 1666 ? MB_STRICMP(bsx->matches[j], |
1667 six->matches[j]) != 0 | |
1668 : STRCMP(bsx->matches[j], six->matches[j]) != 0) | |
1669 break; | |
1670 } | |
1671 } | |
1672 if (j != NSUBEXP) | |
1673 break; | |
1674 } | |
1675 } | |
1676 if (i < 0) | |
1677 return TRUE; | |
1678 } | |
1679 return FALSE; | |
1680 } | |
1681 | |
1682 /* | |
1683 * We stop parsing syntax above line "lnum". If the stored state at or below | |
1684 * this line depended on a change before it, it now depends on the line below | |
1685 * the last parsed line. | |
1686 * The window looks like this: | |
1687 * line which changed | |
1688 * displayed line | |
1689 * displayed line | |
1690 * lnum -> line below window | |
1691 */ | |
1692 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1693 syntax_end_parsing(linenr_T lnum) |
7 | 1694 { |
1695 synstate_T *sp; | |
1696 | |
1697 sp = syn_stack_find_entry(lnum); | |
1698 if (sp != NULL && sp->sst_lnum < lnum) | |
1699 sp = sp->sst_next; | |
1700 | |
1701 if (sp != NULL && sp->sst_change_lnum != 0) | |
1702 sp->sst_change_lnum = lnum; | |
1703 } | |
1704 | |
1705 /* | |
1706 * End of handling of the state stack. | |
1707 ****************************************/ | |
1708 | |
1709 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1710 invalidate_current_state(void) |
7 | 1711 { |
1712 clear_current_state(); | |
1713 current_state.ga_itemsize = 0; /* mark current_state invalid */ | |
1714 current_next_list = NULL; | |
1715 keepend_level = -1; | |
1716 } | |
1717 | |
1718 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1719 validate_current_state(void) |
7 | 1720 { |
1721 current_state.ga_itemsize = sizeof(stateitem_T); | |
1722 current_state.ga_growsize = 3; | |
1723 } | |
1724 | |
1725 /* | |
1726 * Return TRUE if the syntax at start of lnum changed since last time. | |
1727 * This will only be called just after get_syntax_attr() for the previous | |
1728 * line, to check if the next line needs to be redrawn too. | |
1729 */ | |
1730 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1731 syntax_check_changed(linenr_T lnum) |
7 | 1732 { |
1733 int retval = TRUE; | |
1734 synstate_T *sp; | |
1735 | |
1736 /* | |
1737 * Check the state stack when: | |
1738 * - lnum is just below the previously syntaxed line. | |
1739 * - lnum is not before the lines with saved states. | |
1740 * - lnum is not past the lines with saved states. | |
1741 * - lnum is at or before the last changed line. | |
1742 */ | |
1743 if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) | |
1744 { | |
1745 sp = syn_stack_find_entry(lnum); | |
1746 if (sp != NULL && sp->sst_lnum == lnum) | |
1747 { | |
1748 /* | |
1749 * finish the previous line (needed when not all of the line was | |
1750 * drawn) | |
1751 */ | |
1752 (void)syn_finish_line(FALSE); | |
1753 | |
1754 /* | |
1755 * Compare the current state with the previously saved state of | |
1756 * the line. | |
1757 */ | |
1758 if (syn_stack_equal(sp)) | |
1759 retval = FALSE; | |
1760 | |
1761 /* | |
1762 * Store the current state in b_sst_array[] for later use. | |
1763 */ | |
1764 ++current_lnum; | |
1512 | 1765 (void)store_current_state(); |
7 | 1766 } |
1767 } | |
1768 | |
1769 return retval; | |
1770 } | |
1771 | |
1772 /* | |
1773 * Finish the current line. | |
1774 * This doesn't return any attributes, it only gets the state at the end of | |
1775 * the line. It can start anywhere in the line, as long as the current state | |
1776 * is valid. | |
1777 */ | |
1778 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1779 syn_finish_line( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1780 int syncing) /* called for syncing */ |
7 | 1781 { |
1782 stateitem_T *cur_si; | |
442 | 1783 colnr_T prev_current_col; |
7 | 1784 |
1785 if (!current_finished) | |
1786 { | |
1787 while (!current_finished) | |
1788 { | |
1504 | 1789 (void)syn_current_attr(syncing, FALSE, NULL, FALSE); |
7 | 1790 /* |
1791 * When syncing, and found some item, need to check the item. | |
1792 */ | |
1793 if (syncing && current_state.ga_len) | |
1794 { | |
1795 /* | |
1796 * Check for match with sync item. | |
1797 */ | |
1798 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1799 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1800 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags |
7 | 1801 & (HL_SYNC_HERE|HL_SYNC_THERE))) |
1802 return TRUE; | |
1803 | |
1804 /* syn_current_attr() will have skipped the check for an item | |
442 | 1805 * that ends here, need to do that now. Be careful not to go |
1806 * past the NUL. */ | |
1807 prev_current_col = current_col; | |
1808 if (syn_getcurline()[current_col] != NUL) | |
1809 ++current_col; | |
7 | 1810 check_state_ends(); |
442 | 1811 current_col = prev_current_col; |
7 | 1812 } |
1813 ++current_col; | |
1814 } | |
1815 } | |
1816 return FALSE; | |
1817 } | |
1818 | |
1819 /* | |
1820 * Return highlight attributes for next character. | |
1821 * Must first call syntax_start() once for the line. | |
1822 * "col" is normally 0 for the first use in a line, and increments by one each | |
1823 * time. It's allowed to skip characters and to stop before the end of the | |
1824 * line. But only a "col" after a previously used column is allowed. | |
221 | 1825 * When "can_spell" is not NULL set it to TRUE when spell-checking should be |
1826 * done. | |
7 | 1827 */ |
1828 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1829 get_syntax_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1830 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1831 int *can_spell, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1832 int keep_state) /* keep state of char at "col" */ |
7 | 1833 { |
1834 int attr = 0; | |
1835 | |
1363 | 1836 if (can_spell != NULL) |
1837 /* Default: Only do spelling when there is no @Spell cluster or when | |
1838 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1839 *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
|
1840 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1841 : (syn_block->b_syn_spell == SYNSPL_TOP); |
1363 | 1842 |
7 | 1843 /* check for out of memory situation */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1844 if (syn_block->b_sst_array == NULL) |
7 | 1845 return 0; |
1846 | |
419 | 1847 /* After 'synmaxcol' the attribute is always zero. */ |
431 | 1848 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) |
419 | 1849 { |
1850 clear_current_state(); | |
1851 #ifdef FEAT_EVAL | |
1852 current_id = 0; | |
1853 current_trans_id = 0; | |
1854 #endif | |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1855 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1856 current_flags = 0; |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1857 #endif |
419 | 1858 return 0; |
1859 } | |
1860 | |
7 | 1861 /* Make sure current_state is valid */ |
1862 if (INVALID_STATE(¤t_state)) | |
1863 validate_current_state(); | |
1864 | |
1865 /* | |
1866 * Skip from the current column to "col", get the attributes for "col". | |
1867 */ | |
1868 while (current_col <= col) | |
1869 { | |
1504 | 1870 attr = syn_current_attr(FALSE, TRUE, can_spell, |
1871 current_col == col ? keep_state : FALSE); | |
7 | 1872 ++current_col; |
1873 } | |
1874 | |
1875 return attr; | |
1876 } | |
1877 | |
1878 /* | |
1879 * Get syntax attributes for current_lnum, current_col. | |
1880 */ | |
1881 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1882 syn_current_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1883 int syncing, /* When 1: called for syncing */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1884 int displaying, /* result will be displayed */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1885 int *can_spell, /* return: do spell checking */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1886 int keep_state) /* keep syntax stack afterwards */ |
7 | 1887 { |
1888 int syn_id; | |
1889 lpos_T endpos; /* was: char_u *endp; */ | |
1890 lpos_T hl_startpos; /* was: int hl_startcol; */ | |
1891 lpos_T hl_endpos; | |
1892 lpos_T eos_pos; /* end-of-start match (start region) */ | |
1893 lpos_T eoe_pos; /* end-of-end pattern */ | |
1894 int end_idx; /* group ID for end pattern */ | |
1895 int idx; | |
1896 synpat_T *spp; | |
221 | 1897 stateitem_T *cur_si, *sip = NULL; |
7 | 1898 int startcol; |
1899 int endcol; | |
1900 long flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1901 int cchar; |
7 | 1902 short *next_list; |
1903 int found_match; /* found usable match */ | |
1904 static int try_next_column = FALSE; /* must try in next col */ | |
1905 int do_keywords; | |
1906 regmmatch_T regmatch; | |
1907 lpos_T pos; | |
1908 int lc_col; | |
1909 reg_extmatch_T *cur_extmatch = NULL; | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1910 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ |
7 | 1911 char_u *line; /* current line. NOTE: becomes invalid after |
1912 looking for a pattern match! */ | |
1913 | |
1914 /* variables for zero-width matches that have a "nextgroup" argument */ | |
1915 int keep_next_list; | |
1916 int zero_width_next_list = FALSE; | |
1917 garray_T zero_width_next_ga; | |
1918 | |
1919 /* | |
1920 * No character, no attributes! Past end of line? | |
1921 * Do try matching with an empty line (could be the start of a region). | |
1922 */ | |
1923 line = syn_getcurline(); | |
1924 if (line[current_col] == NUL && current_col != 0) | |
1925 { | |
1926 /* | |
1927 * If we found a match after the last column, use it. | |
1928 */ | |
1929 if (next_match_idx >= 0 && next_match_col >= (int)current_col | |
1930 && next_match_col != MAXCOL) | |
1931 (void)push_next_match(NULL); | |
1932 | |
1933 current_finished = TRUE; | |
1934 current_state_stored = FALSE; | |
1935 return 0; | |
1936 } | |
1937 | |
1938 /* if the current or next character is NUL, we will finish the line now */ | |
1939 if (line[current_col] == NUL || line[current_col + 1] == NUL) | |
1940 { | |
1941 current_finished = TRUE; | |
1942 current_state_stored = FALSE; | |
1943 } | |
1944 | |
1945 /* | |
1946 * When in the previous column there was a match but it could not be used | |
1947 * (empty match or already matched in this column) need to try again in | |
1948 * the next column. | |
1949 */ | |
1950 if (try_next_column) | |
1951 { | |
1952 next_match_idx = -1; | |
1953 try_next_column = FALSE; | |
1954 } | |
1955 | |
1956 /* Only check for keywords when not syncing and there are some. */ | |
1957 do_keywords = !syncing | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1958 && (syn_block->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1959 || syn_block->b_keywtab_ic.ht_used > 0); |
7 | 1960 |
1961 /* Init the list of zero-width matches with a nextlist. This is used to | |
1962 * avoid matching the same item in the same position twice. */ | |
1963 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10); | |
1964 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1965 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1966 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1967 |
7 | 1968 /* |
1969 * Repeat matching keywords and patterns, to find contained items at the | |
1970 * same column. This stops when there are no extra matches at the current | |
1971 * column. | |
1972 */ | |
1973 do | |
1974 { | |
1975 found_match = FALSE; | |
1976 keep_next_list = FALSE; | |
1977 syn_id = 0; | |
1978 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1979 |
7 | 1980 /* |
1981 * 1. Check for a current state. | |
1982 * Only when there is no current state, or if the current state may | |
1983 * contain other things, we need to check for keywords and patterns. | |
1984 * Always need to check for contained items if some item has the | |
1985 * "containedin" argument (takes extra time!). | |
1986 */ | |
1987 if (current_state.ga_len) | |
1988 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1989 else | |
1990 cur_si = NULL; | |
1991 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1992 if (syn_block->b_syn_containedin || cur_si == NULL |
7 | 1993 || cur_si->si_cont_list != NULL) |
1994 { | |
1995 /* | |
1996 * 2. Check for keywords, if on a keyword char after a non-keyword | |
1997 * char. Don't do this when syncing. | |
1998 */ | |
1999 if (do_keywords) | |
2000 { | |
2001 line = syn_getcurline(); | |
4043 | 2002 if (vim_iswordp_buf(line + current_col, syn_buf) |
7 | 2003 && (current_col == 0 |
4043 | 2004 || !vim_iswordp_buf(line + current_col - 1 |
7 | 2005 #ifdef FEAT_MBYTE |
2006 - (has_mbyte | |
2007 ? (*mb_head_off)(line, line + current_col - 1) | |
2008 : 0) | |
2009 #endif | |
2010 , syn_buf))) | |
2011 { | |
2012 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
|
2013 &endcol, &flags, &next_list, cur_si, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2014 &cchar); |
205 | 2015 if (syn_id != 0) |
7 | 2016 { |
2017 if (push_current_state(KEYWORD_IDX) == OK) | |
2018 { | |
2019 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2020 cur_si->si_m_startcol = current_col; | |
2021 cur_si->si_h_startpos.lnum = current_lnum; | |
2022 cur_si->si_h_startpos.col = 0; /* starts right away */ | |
2023 cur_si->si_m_endpos.lnum = current_lnum; | |
2024 cur_si->si_m_endpos.col = endcol; | |
2025 cur_si->si_h_endpos.lnum = current_lnum; | |
2026 cur_si->si_h_endpos.col = endcol; | |
2027 cur_si->si_ends = TRUE; | |
2028 cur_si->si_end_idx = 0; | |
2029 cur_si->si_flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2030 #ifdef FEAT_CONCEAL |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2031 cur_si->si_seqnr = next_seqnr++; |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
2032 cur_si->si_cchar = cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2033 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2034 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2035 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
|
2036 & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2037 #endif |
7 | 2038 cur_si->si_id = syn_id; |
2039 cur_si->si_trans_id = syn_id; | |
2040 if (flags & HL_TRANSP) | |
2041 { | |
2042 if (current_state.ga_len < 2) | |
2043 { | |
2044 cur_si->si_attr = 0; | |
2045 cur_si->si_trans_id = 0; | |
2046 } | |
2047 else | |
2048 { | |
2049 cur_si->si_attr = CUR_STATE( | |
2050 current_state.ga_len - 2).si_attr; | |
2051 cur_si->si_trans_id = CUR_STATE( | |
2052 current_state.ga_len - 2).si_trans_id; | |
2053 } | |
2054 } | |
2055 else | |
2056 cur_si->si_attr = syn_id2attr(syn_id); | |
2057 cur_si->si_cont_list = NULL; | |
2058 cur_si->si_next_list = next_list; | |
2059 check_keepend(); | |
2060 } | |
2061 else | |
2062 vim_free(next_list); | |
2063 } | |
2064 } | |
2065 } | |
2066 | |
2067 /* | |
205 | 2068 * 3. Check for patterns (only if no keyword found). |
7 | 2069 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2070 if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) |
7 | 2071 { |
2072 /* | |
2073 * If we didn't check for a match yet, or we are past it, check | |
2074 * for any match with a pattern. | |
2075 */ | |
2076 if (next_match_idx < 0 || next_match_col < (int)current_col) | |
2077 { | |
2078 /* | |
2079 * Check all relevant patterns for a match at this | |
2080 * position. This is complicated, because matching with a | |
2081 * pattern takes quite a bit of time, thus we want to | |
2082 * avoid doing it when it's not needed. | |
2083 */ | |
2084 next_match_idx = 0; /* no match in this line yet */ | |
2085 next_match_col = MAXCOL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2086 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
7 | 2087 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2088 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2089 if ( spp->sp_syncing == syncing |
2090 && (displaying || !(spp->sp_flags & HL_DISPLAY)) | |
2091 && (spp->sp_type == SPTYPE_MATCH | |
2092 || spp->sp_type == SPTYPE_START) | |
2093 && (current_next_list != NULL | |
2094 ? in_id_list(NULL, current_next_list, | |
2095 &spp->sp_syn, 0) | |
2096 : (cur_si == NULL | |
2097 ? !(spp->sp_flags & HL_CONTAINED) | |
2098 : in_id_list(cur_si, | |
2099 cur_si->si_cont_list, &spp->sp_syn, | |
2100 spp->sp_flags & HL_CONTAINED)))) | |
2101 { | |
6375 | 2102 int r; |
2103 | |
7 | 2104 /* If we already tried matching in this line, and |
2105 * there isn't a match before next_match_col, skip | |
2106 * this item. */ | |
2107 if (spp->sp_line_id == current_line_id | |
2108 && spp->sp_startcol >= next_match_col) | |
2109 continue; | |
2110 spp->sp_line_id = current_line_id; | |
2111 | |
2112 lc_col = current_col - spp->sp_offsets[SPO_LC_OFF]; | |
2113 if (lc_col < 0) | |
2114 lc_col = 0; | |
2115 | |
2116 regmatch.rmm_ic = spp->sp_ic; | |
2117 regmatch.regprog = spp->sp_prog; | |
6375 | 2118 r = syn_regexec(®match, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2119 current_lnum, |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2120 (colnr_T)lc_col, |
6375 | 2121 IF_SYN_TIME(&spp->sp_time)); |
2122 spp->sp_prog = regmatch.regprog; | |
2123 if (!r) | |
7 | 2124 { |
2125 /* no match in this line, try another one */ | |
2126 spp->sp_startcol = MAXCOL; | |
2127 continue; | |
2128 } | |
2129 | |
2130 /* | |
2131 * Compute the first column of the match. | |
2132 */ | |
2133 syn_add_start_off(&pos, ®match, | |
2134 spp, SPO_MS_OFF, -1); | |
2135 if (pos.lnum > current_lnum) | |
2136 { | |
2137 /* must have used end of match in a next line, | |
2138 * we can't handle that */ | |
2139 spp->sp_startcol = MAXCOL; | |
2140 continue; | |
2141 } | |
2142 startcol = pos.col; | |
2143 | |
2144 /* remember the next column where this pattern | |
2145 * matches in the current line */ | |
2146 spp->sp_startcol = startcol; | |
2147 | |
2148 /* | |
2149 * If a previously found match starts at a lower | |
2150 * column number, don't use this one. | |
2151 */ | |
2152 if (startcol >= next_match_col) | |
2153 continue; | |
2154 | |
2155 /* | |
2156 * If we matched this pattern at this position | |
2157 * before, skip it. Must retry in the next | |
2158 * column, because it may match from there. | |
2159 */ | |
2160 if (did_match_already(idx, &zero_width_next_ga)) | |
2161 { | |
2162 try_next_column = TRUE; | |
2163 continue; | |
2164 } | |
2165 | |
2166 endpos.lnum = regmatch.endpos[0].lnum; | |
2167 endpos.col = regmatch.endpos[0].col; | |
2168 | |
2169 /* Compute the highlight start. */ | |
2170 syn_add_start_off(&hl_startpos, ®match, | |
2171 spp, SPO_HS_OFF, -1); | |
2172 | |
2173 /* Compute the region start. */ | |
2174 /* Default is to use the end of the match. */ | |
2175 syn_add_end_off(&eos_pos, ®match, | |
2176 spp, SPO_RS_OFF, 0); | |
2177 | |
2178 /* | |
2179 * Grab the external submatches before they get | |
2180 * overwritten. Reference count doesn't change. | |
2181 */ | |
2182 unref_extmatch(cur_extmatch); | |
2183 cur_extmatch = re_extmatch_out; | |
2184 re_extmatch_out = NULL; | |
2185 | |
2186 flags = 0; | |
2187 eoe_pos.lnum = 0; /* avoid warning */ | |
2188 eoe_pos.col = 0; | |
2189 end_idx = 0; | |
2190 hl_endpos.lnum = 0; | |
2191 | |
2192 /* | |
2193 * For a "oneline" the end must be found in the | |
2194 * same line too. Search for it after the end of | |
2195 * the match with the start pattern. Set the | |
2196 * resulting end positions at the same time. | |
2197 */ | |
2198 if (spp->sp_type == SPTYPE_START | |
2199 && (spp->sp_flags & HL_ONELINE)) | |
2200 { | |
2201 lpos_T startpos; | |
2202 | |
2203 startpos = endpos; | |
2204 find_endpos(idx, &startpos, &endpos, &hl_endpos, | |
2205 &flags, &eoe_pos, &end_idx, cur_extmatch); | |
2206 if (endpos.lnum == 0) | |
2207 continue; /* not found */ | |
2208 } | |
2209 | |
2210 /* | |
2211 * For a "match" the size must be > 0 after the | |
2212 * end offset needs has been added. Except when | |
2213 * syncing. | |
2214 */ | |
2215 else if (spp->sp_type == SPTYPE_MATCH) | |
2216 { | |
2217 syn_add_end_off(&hl_endpos, ®match, spp, | |
2218 SPO_HE_OFF, 0); | |
2219 syn_add_end_off(&endpos, ®match, spp, | |
2220 SPO_ME_OFF, 0); | |
2221 if (endpos.lnum == current_lnum | |
2222 && (int)endpos.col + syncing < startcol) | |
2223 { | |
2224 /* | |
2225 * If an empty string is matched, may need | |
2226 * to try matching again at next column. | |
2227 */ | |
2228 if (regmatch.startpos[0].col | |
2229 == regmatch.endpos[0].col) | |
2230 try_next_column = TRUE; | |
2231 continue; | |
2232 } | |
2233 } | |
2234 | |
2235 /* | |
2236 * keep the best match so far in next_match_* | |
2237 */ | |
2238 /* Highlighting must start after startpos and end | |
2239 * before endpos. */ | |
2240 if (hl_startpos.lnum == current_lnum | |
2241 && (int)hl_startpos.col < startcol) | |
2242 hl_startpos.col = startcol; | |
2243 limit_pos_zero(&hl_endpos, &endpos); | |
2244 | |
2245 next_match_idx = idx; | |
2246 next_match_col = startcol; | |
2247 next_match_m_endpos = endpos; | |
2248 next_match_h_endpos = hl_endpos; | |
2249 next_match_h_startpos = hl_startpos; | |
2250 next_match_flags = flags; | |
2251 next_match_eos_pos = eos_pos; | |
2252 next_match_eoe_pos = eoe_pos; | |
2253 next_match_end_idx = end_idx; | |
2254 unref_extmatch(next_match_extmatch); | |
2255 next_match_extmatch = cur_extmatch; | |
2256 cur_extmatch = NULL; | |
2257 } | |
2258 } | |
2259 } | |
2260 | |
2261 /* | |
2262 * If we found a match at the current column, use it. | |
2263 */ | |
2264 if (next_match_idx >= 0 && next_match_col == (int)current_col) | |
2265 { | |
2266 synpat_T *lspp; | |
2267 | |
2268 /* When a zero-width item matched which has a nextgroup, | |
2269 * 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
|
2270 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2271 if (next_match_m_endpos.lnum == current_lnum |
2272 && next_match_m_endpos.col == current_col | |
2273 && lspp->sp_next_list != NULL) | |
2274 { | |
2275 current_next_list = lspp->sp_next_list; | |
2276 current_next_flags = lspp->sp_flags; | |
2277 keep_next_list = TRUE; | |
2278 zero_width_next_list = TRUE; | |
2279 | |
2280 /* Add the index to a list, so that we can check | |
2281 * later that we don't match it again (and cause an | |
2282 * endless loop). */ | |
2283 if (ga_grow(&zero_width_next_ga, 1) == OK) | |
2284 { | |
2285 ((int *)(zero_width_next_ga.ga_data)) | |
2286 [zero_width_next_ga.ga_len++] = next_match_idx; | |
2287 } | |
2288 next_match_idx = -1; | |
2289 } | |
2290 else | |
2291 cur_si = push_next_match(cur_si); | |
2292 found_match = TRUE; | |
2293 } | |
2294 } | |
2295 } | |
2296 | |
2297 /* | |
2298 * Handle searching for nextgroup match. | |
2299 */ | |
2300 if (current_next_list != NULL && !keep_next_list) | |
2301 { | |
2302 /* | |
2303 * If a nextgroup was not found, continue looking for one if: | |
2304 * - this is an empty line and the "skipempty" option was given | |
2305 * - we are on white space and the "skipwhite" option was given | |
2306 */ | |
2307 if (!found_match) | |
2308 { | |
2309 line = syn_getcurline(); | |
2310 if (((current_next_flags & HL_SKIPWHITE) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2311 && VIM_ISWHITE(line[current_col])) |
7 | 2312 || ((current_next_flags & HL_SKIPEMPTY) |
2313 && *line == NUL)) | |
2314 break; | |
2315 } | |
2316 | |
2317 /* | |
2318 * If a nextgroup was found: Use it, and continue looking for | |
2319 * contained matches. | |
2320 * If a nextgroup was not found: Continue looking for a normal | |
2321 * match. | |
2322 * When did set current_next_list for a zero-width item and no | |
2323 * match was found don't loop (would get stuck). | |
2324 */ | |
2325 current_next_list = NULL; | |
2326 next_match_idx = -1; | |
2327 if (!zero_width_next_list) | |
2328 found_match = TRUE; | |
2329 } | |
2330 | |
2331 } while (found_match); | |
2332 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2333 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2334 |
7 | 2335 /* |
2336 * Use attributes from the current state, if within its highlighting. | |
2337 * If not, use attributes from the current-but-one state, etc. | |
2338 */ | |
2339 current_attr = 0; | |
2340 #ifdef FEAT_EVAL | |
2341 current_id = 0; | |
2342 current_trans_id = 0; | |
2343 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2344 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2345 current_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2346 #endif |
7 | 2347 if (cur_si != NULL) |
2348 { | |
221 | 2349 #ifndef FEAT_EVAL |
2350 int current_trans_id = 0; | |
2351 #endif | |
7 | 2352 for (idx = current_state.ga_len - 1; idx >= 0; --idx) |
2353 { | |
2354 sip = &CUR_STATE(idx); | |
2355 if ((current_lnum > sip->si_h_startpos.lnum | |
2356 || (current_lnum == sip->si_h_startpos.lnum | |
2357 && current_col >= sip->si_h_startpos.col)) | |
2358 && (sip->si_h_endpos.lnum == 0 | |
2359 || current_lnum < sip->si_h_endpos.lnum | |
2360 || (current_lnum == sip->si_h_endpos.lnum | |
2361 && current_col < sip->si_h_endpos.col))) | |
2362 { | |
2363 current_attr = sip->si_attr; | |
2364 #ifdef FEAT_EVAL | |
2365 current_id = sip->si_id; | |
221 | 2366 #endif |
7 | 2367 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
|
2368 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2369 current_flags = sip->si_flags; |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2370 current_seqnr = sip->si_seqnr; |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
2371 current_sub_char = sip->si_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2372 #endif |
7 | 2373 break; |
2374 } | |
2375 } | |
2376 | |
221 | 2377 if (can_spell != NULL) |
2378 { | |
2379 struct sp_syn sps; | |
2380 | |
2381 /* | |
2382 * set "can_spell" to TRUE if spell checking is supposed to be | |
2383 * done in the current item. | |
2384 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2385 if (syn_block->b_spell_cluster_id == 0) |
227 | 2386 { |
320 | 2387 /* There is no @Spell cluster: Do spelling for items without |
2388 * @NoSpell cluster. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2389 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
|
2390 || current_trans_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2391 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); |
227 | 2392 else |
2393 { | |
2394 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2395 sps.id = syn_block->b_nospell_cluster_id; |
227 | 2396 sps.cont_in_list = NULL; |
2397 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2398 } | |
2399 } | |
221 | 2400 else |
2401 { | |
320 | 2402 /* The @Spell cluster is defined: Do spelling in items with |
419 | 2403 * the @Spell cluster. But not when @NoSpell is also there. |
2404 * At the toplevel only spell check when ":syn spell toplevel" | |
2405 * was used. */ | |
320 | 2406 if (current_trans_id == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2407 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); |
320 | 2408 else |
2409 { | |
2410 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2411 sps.id = syn_block->b_spell_cluster_id; |
320 | 2412 sps.cont_in_list = NULL; |
2413 *can_spell = in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2414 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2415 if (syn_block->b_nospell_cluster_id != 0) |
320 | 2416 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2417 sps.id = syn_block->b_nospell_cluster_id; |
320 | 2418 if (in_id_list(sip, sip->si_cont_list, &sps, 0)) |
2419 *can_spell = FALSE; | |
2420 } | |
2421 } | |
221 | 2422 } |
2423 } | |
2424 | |
2425 | |
7 | 2426 /* |
2427 * Check for end of current state (and the states before it) at the | |
2428 * next column. Don't do this for syncing, because we would miss a | |
2429 * single character match. | |
2430 * First check if the current state ends at the current column. It | |
2431 * may be for an empty match and a containing item might end in the | |
2432 * current column. | |
2433 */ | |
1504 | 2434 if (!syncing && !keep_state) |
7 | 2435 { |
2436 check_state_ends(); | |
442 | 2437 if (current_state.ga_len > 0 |
2438 && syn_getcurline()[current_col] != NUL) | |
7 | 2439 { |
2440 ++current_col; | |
2441 check_state_ends(); | |
2442 --current_col; | |
2443 } | |
2444 } | |
2445 } | |
221 | 2446 else if (can_spell != NULL) |
419 | 2447 /* Default: Only do spelling when there is no @Spell cluster or when |
2448 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2449 *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
|
2450 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2451 : (syn_block->b_syn_spell == SYNSPL_TOP); |
7 | 2452 |
2020 | 2453 /* nextgroup ends at end of line, unless "skipnl" or "skipempty" present */ |
7 | 2454 if (current_next_list != NULL |
2455 && syn_getcurline()[current_col + 1] == NUL | |
2456 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) | |
2457 current_next_list = NULL; | |
2458 | |
2459 if (zero_width_next_ga.ga_len > 0) | |
2460 ga_clear(&zero_width_next_ga); | |
2461 | |
2462 /* No longer need external matches. But keep next_match_extmatch. */ | |
2463 unref_extmatch(re_extmatch_out); | |
2464 re_extmatch_out = NULL; | |
2465 unref_extmatch(cur_extmatch); | |
2466 | |
2467 return current_attr; | |
2468 } | |
2469 | |
2470 | |
2471 /* | |
2472 * Check if we already matched pattern "idx" at the current column. | |
2473 */ | |
2474 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2475 did_match_already(int idx, garray_T *gap) |
7 | 2476 { |
2477 int i; | |
2478 | |
2479 for (i = current_state.ga_len; --i >= 0; ) | |
2480 if (CUR_STATE(i).si_m_startcol == (int)current_col | |
2481 && CUR_STATE(i).si_m_lnum == (int)current_lnum | |
2482 && CUR_STATE(i).si_idx == idx) | |
2483 return TRUE; | |
2484 | |
2485 /* Zero-width matches with a nextgroup argument are not put on the syntax | |
2486 * stack, and can only be matched once anyway. */ | |
2487 for (i = gap->ga_len; --i >= 0; ) | |
2488 if (((int *)(gap->ga_data))[i] == idx) | |
2489 return TRUE; | |
2490 | |
2491 return FALSE; | |
2492 } | |
2493 | |
2494 /* | |
2495 * Push the next match onto the stack. | |
2496 */ | |
2497 static stateitem_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2498 push_next_match(stateitem_T *cur_si) |
7 | 2499 { |
2500 synpat_T *spp; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2501 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2502 int save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2503 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2504 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2505 spp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2506 |
2507 /* | |
2508 * Push the item in current_state stack; | |
2509 */ | |
2510 if (push_current_state(next_match_idx) == OK) | |
2511 { | |
2512 /* | |
2513 * If it's a start-skip-end type that crosses lines, figure out how | |
2514 * much it continues in this line. Otherwise just fill in the length. | |
2515 */ | |
2516 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2517 cur_si->si_h_startpos = next_match_h_startpos; | |
2518 cur_si->si_m_startcol = current_col; | |
2519 cur_si->si_m_lnum = current_lnum; | |
2520 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
|
2521 #ifdef FEAT_CONCEAL |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
2522 cur_si->si_seqnr = next_seqnr++; |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
2523 cur_si->si_cchar = spp->sp_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2524 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2525 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2526 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
|
2527 #endif |
7 | 2528 cur_si->si_next_list = spp->sp_next_list; |
2529 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); | |
2530 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) | |
2531 { | |
2532 /* Try to find the end pattern in the current line */ | |
2533 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); | |
2534 check_keepend(); | |
2535 } | |
2536 else | |
2537 { | |
2538 cur_si->si_m_endpos = next_match_m_endpos; | |
2539 cur_si->si_h_endpos = next_match_h_endpos; | |
2540 cur_si->si_ends = TRUE; | |
2541 cur_si->si_flags |= next_match_flags; | |
2542 cur_si->si_eoe_pos = next_match_eoe_pos; | |
2543 cur_si->si_end_idx = next_match_end_idx; | |
2544 } | |
2545 if (keepend_level < 0 && (cur_si->si_flags & HL_KEEPEND)) | |
2546 keepend_level = current_state.ga_len - 1; | |
2547 check_keepend(); | |
2548 update_si_attr(current_state.ga_len - 1); | |
2549 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2550 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2551 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
|
2552 #endif |
7 | 2553 /* |
2554 * If the start pattern has another highlight group, push another item | |
2555 * on the stack for the start pattern. | |
2556 */ | |
2557 if ( spp->sp_type == SPTYPE_START | |
2558 && spp->sp_syn_match_id != 0 | |
2559 && push_current_state(next_match_idx) == OK) | |
2560 { | |
2561 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2562 cur_si->si_h_startpos = next_match_h_startpos; | |
2563 cur_si->si_m_startcol = current_col; | |
2564 cur_si->si_m_lnum = current_lnum; | |
2565 cur_si->si_m_endpos = next_match_eos_pos; | |
2566 cur_si->si_h_endpos = next_match_eos_pos; | |
2567 cur_si->si_ends = TRUE; | |
2568 cur_si->si_end_idx = 0; | |
2569 cur_si->si_flags = HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2570 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2571 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2572 cur_si->si_flags |= save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2573 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2574 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2575 #endif |
7 | 2576 cur_si->si_next_list = NULL; |
2577 check_keepend(); | |
2578 update_si_attr(current_state.ga_len - 1); | |
2579 } | |
2580 } | |
2581 | |
2582 next_match_idx = -1; /* try other match next time */ | |
2583 | |
2584 return cur_si; | |
2585 } | |
2586 | |
2587 /* | |
2588 * Check for end of current state (and the states before it). | |
2589 */ | |
2590 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2591 check_state_ends(void) |
7 | 2592 { |
2593 stateitem_T *cur_si; | |
2863 | 2594 int had_extend; |
7 | 2595 |
2596 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2597 for (;;) | |
2598 { | |
2599 if (cur_si->si_ends | |
2600 && (cur_si->si_m_endpos.lnum < current_lnum | |
2601 || (cur_si->si_m_endpos.lnum == current_lnum | |
2602 && cur_si->si_m_endpos.col <= current_col))) | |
2603 { | |
2604 /* | |
2605 * If there is an end pattern group ID, highlight the end pattern | |
2606 * now. No need to pop the current item from the stack. | |
2607 * Only do this if the end pattern continues beyond the current | |
2608 * position. | |
2609 */ | |
2610 if (cur_si->si_end_idx | |
2611 && (cur_si->si_eoe_pos.lnum > current_lnum | |
2612 || (cur_si->si_eoe_pos.lnum == current_lnum | |
2613 && cur_si->si_eoe_pos.col > current_col))) | |
2614 { | |
2615 cur_si->si_idx = cur_si->si_end_idx; | |
2616 cur_si->si_end_idx = 0; | |
2617 cur_si->si_m_endpos = cur_si->si_eoe_pos; | |
2618 cur_si->si_h_endpos = cur_si->si_eoe_pos; | |
2619 cur_si->si_flags |= HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2620 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2621 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2622 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2623 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2624 #endif |
7 | 2625 update_si_attr(current_state.ga_len - 1); |
36 | 2626 |
2831 | 2627 /* nextgroup= should not match in the end pattern */ |
2628 current_next_list = NULL; | |
2629 | |
36 | 2630 /* what matches next may be different now, clear it */ |
2631 next_match_idx = 0; | |
2632 next_match_col = MAXCOL; | |
7 | 2633 break; |
2634 } | |
2635 else | |
2636 { | |
2637 /* handle next_list, unless at end of line and no "skipnl" or | |
2638 * "skipempty" */ | |
2639 current_next_list = cur_si->si_next_list; | |
2640 current_next_flags = cur_si->si_flags; | |
2641 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) | |
2642 && syn_getcurline()[current_col] == NUL) | |
2643 current_next_list = NULL; | |
2644 | |
2645 /* When the ended item has "extend", another item with | |
2646 * "keepend" now needs to check for its end. */ | |
2863 | 2647 had_extend = (cur_si->si_flags & HL_EXTEND); |
7 | 2648 |
2649 pop_current_state(); | |
2650 | |
2651 if (current_state.ga_len == 0) | |
2652 break; | |
2653 | |
1503 | 2654 if (had_extend && keepend_level >= 0) |
7 | 2655 { |
2656 syn_update_ends(FALSE); | |
2657 if (current_state.ga_len == 0) | |
2658 break; | |
2659 } | |
2660 | |
2661 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2662 | |
2663 /* | |
2664 * Only for a region the search for the end continues after | |
2665 * the end of the contained item. If the contained match | |
2666 * included the end-of-line, break here, the region continues. | |
2667 * Don't do this when: | |
2668 * - "keepend" is used for the contained item | |
2669 * - not at the end of the line (could be end="x$"me=e-1). | |
2670 * - "excludenl" is used (HL_HAS_EOL won't be set) | |
2671 */ | |
2672 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2673 && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type |
7 | 2674 == SPTYPE_START |
2675 && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) | |
2676 { | |
2677 update_si_end(cur_si, (int)current_col, TRUE); | |
2678 check_keepend(); | |
2679 if ((current_next_flags & HL_HAS_EOL) | |
2680 && keepend_level < 0 | |
2681 && syn_getcurline()[current_col] == NUL) | |
2682 break; | |
2683 } | |
2684 } | |
2685 } | |
2686 else | |
2687 break; | |
2688 } | |
2689 } | |
2690 | |
2691 /* | |
2692 * Update an entry in the current_state stack for a match or region. This | |
2693 * fills in si_attr, si_next_list and si_cont_list. | |
2694 */ | |
2695 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2696 update_si_attr(int idx) |
7 | 2697 { |
2698 stateitem_T *sip = &CUR_STATE(idx); | |
2699 synpat_T *spp; | |
2700 | |
1371 | 2701 /* This should not happen... */ |
2702 if (sip->si_idx < 0) | |
2703 return; | |
2704 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2705 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); |
7 | 2706 if (sip->si_flags & HL_MATCH) |
2707 sip->si_id = spp->sp_syn_match_id; | |
2708 else | |
2709 sip->si_id = spp->sp_syn.id; | |
2710 sip->si_attr = syn_id2attr(sip->si_id); | |
2711 sip->si_trans_id = sip->si_id; | |
2712 if (sip->si_flags & HL_MATCH) | |
2713 sip->si_cont_list = NULL; | |
2714 else | |
2715 sip->si_cont_list = spp->sp_cont_list; | |
2716 | |
2717 /* | |
2718 * For transparent items, take attr from outer item. | |
2719 * Also take cont_list, if there is none. | |
2720 * Don't do this for the matchgroup of a start or end pattern. | |
2721 */ | |
2722 if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) | |
2723 { | |
2724 if (idx == 0) | |
2725 { | |
2726 sip->si_attr = 0; | |
2727 sip->si_trans_id = 0; | |
2728 if (sip->si_cont_list == NULL) | |
2729 sip->si_cont_list = ID_LIST_ALL; | |
2730 } | |
2731 else | |
2732 { | |
2733 sip->si_attr = CUR_STATE(idx - 1).si_attr; | |
2734 sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; | |
36 | 2735 sip->si_h_startpos = CUR_STATE(idx - 1).si_h_startpos; |
2736 sip->si_h_endpos = CUR_STATE(idx - 1).si_h_endpos; | |
7 | 2737 if (sip->si_cont_list == NULL) |
2738 { | |
2739 sip->si_flags |= HL_TRANS_CONT; | |
2740 sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; | |
2741 } | |
2742 } | |
2743 } | |
2744 } | |
2745 | |
2746 /* | |
2747 * Check the current stack for patterns with "keepend" flag. | |
2748 * Propagate the match-end to contained items, until a "skipend" item is found. | |
2749 */ | |
2750 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2751 check_keepend(void) |
7 | 2752 { |
2753 int i; | |
2754 lpos_T maxpos; | |
991 | 2755 lpos_T maxpos_h; |
7 | 2756 stateitem_T *sip; |
2757 | |
2758 /* | |
2759 * This check can consume a lot of time; only do it from the level where | |
2760 * there really is a keepend. | |
2761 */ | |
2762 if (keepend_level < 0) | |
2763 return; | |
2764 | |
2765 /* | |
2766 * Find the last index of an "extend" item. "keepend" items before that | |
2767 * won't do anything. If there is no "extend" item "i" will be | |
2768 * "keepend_level" and all "keepend" items will work normally. | |
2769 */ | |
2770 for (i = current_state.ga_len - 1; i > keepend_level; --i) | |
2771 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
2772 break; | |
2773 | |
2774 maxpos.lnum = 0; | |
1702 | 2775 maxpos.col = 0; |
991 | 2776 maxpos_h.lnum = 0; |
1702 | 2777 maxpos_h.col = 0; |
7 | 2778 for ( ; i < current_state.ga_len; ++i) |
2779 { | |
2780 sip = &CUR_STATE(i); | |
2781 if (maxpos.lnum != 0) | |
2782 { | |
2783 limit_pos_zero(&sip->si_m_endpos, &maxpos); | |
991 | 2784 limit_pos_zero(&sip->si_h_endpos, &maxpos_h); |
7 | 2785 limit_pos_zero(&sip->si_eoe_pos, &maxpos); |
2786 sip->si_ends = TRUE; | |
2787 } | |
991 | 2788 if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) |
2789 { | |
2790 if (maxpos.lnum == 0 | |
7 | 2791 || maxpos.lnum > sip->si_m_endpos.lnum |
2792 || (maxpos.lnum == sip->si_m_endpos.lnum | |
991 | 2793 && maxpos.col > sip->si_m_endpos.col)) |
2794 maxpos = sip->si_m_endpos; | |
2795 if (maxpos_h.lnum == 0 | |
2796 || maxpos_h.lnum > sip->si_h_endpos.lnum | |
2797 || (maxpos_h.lnum == sip->si_h_endpos.lnum | |
2798 && maxpos_h.col > sip->si_h_endpos.col)) | |
2799 maxpos_h = sip->si_h_endpos; | |
2800 } | |
7 | 2801 } |
2802 } | |
2803 | |
2804 /* | |
2805 * Update an entry in the current_state stack for a start-skip-end pattern. | |
2806 * This finds the end of the current item, if it's in the current line. | |
2807 * | |
2808 * Return the flags for the matched END. | |
2809 */ | |
2810 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2811 update_si_end( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2812 stateitem_T *sip, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2813 int startcol, /* where to start searching for the end */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2814 int force) /* when TRUE overrule a previous end */ |
7 | 2815 { |
2816 lpos_T startpos; | |
2817 lpos_T endpos; | |
2818 lpos_T hl_endpos; | |
2819 lpos_T end_endpos; | |
2820 int end_idx; | |
2821 | |
1371 | 2822 /* return quickly for a keyword */ |
2823 if (sip->si_idx < 0) | |
2824 return; | |
2825 | |
7 | 2826 /* Don't update when it's already done. Can be a match of an end pattern |
2827 * that started in a previous line. Watch out: can also be a "keepend" | |
2828 * from a containing item. */ | |
2829 if (!force && sip->si_m_endpos.lnum >= current_lnum) | |
2830 return; | |
2831 | |
2832 /* | |
2833 * We need to find the end of the region. It may continue in the next | |
2834 * line. | |
2835 */ | |
2836 end_idx = 0; | |
2837 startpos.lnum = current_lnum; | |
2838 startpos.col = startcol; | |
2839 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, | |
2840 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); | |
2841 | |
2842 if (endpos.lnum == 0) | |
2843 { | |
2844 /* No end pattern matched. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2845 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) |
7 | 2846 { |
2847 /* a "oneline" never continues in the next line */ | |
2848 sip->si_ends = TRUE; | |
2849 sip->si_m_endpos.lnum = current_lnum; | |
2850 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); | |
2851 } | |
2852 else | |
2853 { | |
2854 /* continues in the next line */ | |
2855 sip->si_ends = FALSE; | |
2856 sip->si_m_endpos.lnum = 0; | |
2857 } | |
2858 sip->si_h_endpos = sip->si_m_endpos; | |
2859 } | |
2860 else | |
2861 { | |
2862 /* match within this line */ | |
2863 sip->si_m_endpos = endpos; | |
2864 sip->si_h_endpos = hl_endpos; | |
2865 sip->si_eoe_pos = end_endpos; | |
2866 sip->si_ends = TRUE; | |
2867 sip->si_end_idx = end_idx; | |
2868 } | |
2869 } | |
2870 | |
2871 /* | |
2872 * Add a new state to the current state stack. | |
2873 * It is cleared and the index set to "idx". | |
2874 * Return FAIL if it's not possible (out of memory). | |
2875 */ | |
2876 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2877 push_current_state(int idx) |
7 | 2878 { |
2879 if (ga_grow(¤t_state, 1) == FAIL) | |
2880 return FAIL; | |
2881 vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T)); | |
2882 CUR_STATE(current_state.ga_len).si_idx = idx; | |
2883 ++current_state.ga_len; | |
2884 return OK; | |
2885 } | |
2886 | |
2887 /* | |
2888 * Remove a state from the current_state stack. | |
2889 */ | |
2890 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2891 pop_current_state(void) |
7 | 2892 { |
2893 if (current_state.ga_len) | |
2894 { | |
2895 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); | |
2896 --current_state.ga_len; | |
2897 } | |
2898 /* after the end of a pattern, try matching a keyword or pattern */ | |
2899 next_match_idx = -1; | |
2900 | |
2901 /* if first state with "keepend" is popped, reset keepend_level */ | |
2902 if (keepend_level >= current_state.ga_len) | |
2903 keepend_level = -1; | |
2904 } | |
2905 | |
2906 /* | |
2907 * Find the end of a start/skip/end syntax region after "startpos". | |
2908 * Only checks one line. | |
2909 * Also handles a match item that continued from a previous line. | |
2910 * If not found, the syntax item continues in the next line. m_endpos->lnum | |
2911 * will be 0. | |
2912 * If found, the end of the region and the end of the highlighting is | |
2913 * computed. | |
2914 */ | |
2915 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2916 find_endpos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2917 int idx, /* index of the pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2918 lpos_T *startpos, /* where to start looking for an END match */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2919 lpos_T *m_endpos, /* return: end of match */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2920 lpos_T *hl_endpos, /* return: end of highlighting */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2921 long *flagsp, /* return: flags of matching END */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2922 lpos_T *end_endpos, /* return: end of end pattern match */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2923 int *end_idx, /* return: group ID for end pat. match, or 0 */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2924 reg_extmatch_T *start_ext) /* submatches from the start pattern */ |
7 | 2925 { |
2926 colnr_T matchcol; | |
2927 synpat_T *spp, *spp_skip; | |
2928 int start_idx; | |
2929 int best_idx; | |
2930 regmmatch_T regmatch; | |
2931 regmmatch_T best_regmatch; /* startpos/endpos of best match */ | |
2932 lpos_T pos; | |
2933 char_u *line; | |
2934 int had_match = FALSE; | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2935 char_u buf_chartab[32]; /* chartab array for syn option iskyeyword */ |
7 | 2936 |
1371 | 2937 /* just in case we are invoked for a keyword */ |
2938 if (idx < 0) | |
2939 return; | |
2940 | |
7 | 2941 /* |
2942 * Check for being called with a START pattern. | |
2943 * Can happen with a match that continues to the next line, because it | |
2944 * contained a region. | |
2945 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2946 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2947 if (spp->sp_type != SPTYPE_START) |
2948 { | |
2949 *hl_endpos = *startpos; | |
2950 return; | |
2951 } | |
2952 | |
2953 /* | |
2954 * Find the SKIP or first END pattern after the last START pattern. | |
2955 */ | |
2956 for (;;) | |
2957 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2958 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2959 if (spp->sp_type != SPTYPE_START) |
2960 break; | |
2961 ++idx; | |
2962 } | |
2963 | |
2964 /* | |
2965 * Lookup the SKIP pattern (if present) | |
2966 */ | |
2967 if (spp->sp_type == SPTYPE_SKIP) | |
2968 { | |
2969 spp_skip = spp; | |
2970 ++idx; | |
2971 } | |
2972 else | |
2973 spp_skip = NULL; | |
2974 | |
2975 /* Setup external matches for syn_regexec(). */ | |
2976 unref_extmatch(re_extmatch_in); | |
2977 re_extmatch_in = ref_extmatch(start_ext); | |
2978 | |
2979 matchcol = startpos->col; /* start looking for a match at sstart */ | |
2980 start_idx = idx; /* remember the first END pattern. */ | |
2981 best_regmatch.startpos[0].col = 0; /* avoid compiler warning */ | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2982 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2983 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2984 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2985 |
7 | 2986 for (;;) |
2987 { | |
2988 /* | |
2989 * Find end pattern that matches first after "matchcol". | |
2990 */ | |
2991 best_idx = -1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2992 for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; ++idx) |
7 | 2993 { |
2994 int lc_col = matchcol; | |
6375 | 2995 int r; |
7 | 2996 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2997 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2998 if (spp->sp_type != SPTYPE_END) /* past last END pattern */ |
2999 break; | |
3000 lc_col -= spp->sp_offsets[SPO_LC_OFF]; | |
3001 if (lc_col < 0) | |
3002 lc_col = 0; | |
3003 | |
3004 regmatch.rmm_ic = spp->sp_ic; | |
3005 regmatch.regprog = spp->sp_prog; | |
6375 | 3006 r = syn_regexec(®match, startpos->lnum, lc_col, |
3007 IF_SYN_TIME(&spp->sp_time)); | |
3008 spp->sp_prog = regmatch.regprog; | |
3009 if (r) | |
7 | 3010 { |
3011 if (best_idx == -1 || regmatch.startpos[0].col | |
3012 < best_regmatch.startpos[0].col) | |
3013 { | |
3014 best_idx = idx; | |
3015 best_regmatch.startpos[0] = regmatch.startpos[0]; | |
3016 best_regmatch.endpos[0] = regmatch.endpos[0]; | |
3017 } | |
3018 } | |
3019 } | |
3020 | |
3021 /* | |
3022 * If all end patterns have been tried, and there is no match, the | |
3023 * item continues until end-of-line. | |
3024 */ | |
3025 if (best_idx == -1) | |
3026 break; | |
3027 | |
3028 /* | |
3029 * If the skip pattern matches before the end pattern, | |
3030 * continue searching after the skip pattern. | |
3031 */ | |
3032 if (spp_skip != NULL) | |
3033 { | |
3034 int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; | |
6375 | 3035 int r; |
7 | 3036 |
3037 if (lc_col < 0) | |
3038 lc_col = 0; | |
3039 regmatch.rmm_ic = spp_skip->sp_ic; | |
3040 regmatch.regprog = spp_skip->sp_prog; | |
6375 | 3041 r = syn_regexec(®match, startpos->lnum, lc_col, |
3042 IF_SYN_TIME(&spp_skip->sp_time)); | |
3043 spp_skip->sp_prog = regmatch.regprog; | |
3044 if (r && regmatch.startpos[0].col | |
7 | 3045 <= best_regmatch.startpos[0].col) |
3046 { | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3047 int line_len; |
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3048 |
7 | 3049 /* Add offset to skip pattern match */ |
3050 syn_add_end_off(&pos, ®match, spp_skip, SPO_ME_OFF, 1); | |
3051 | |
3052 /* If the skip pattern goes on to the next line, there is no | |
3053 * match with an end pattern in this line. */ | |
3054 if (pos.lnum > startpos->lnum) | |
3055 break; | |
3056 | |
3057 line = ml_get_buf(syn_buf, startpos->lnum, FALSE); | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3058 line_len = (int)STRLEN(line); |
7 | 3059 |
3060 /* take care of an empty match or negative offset */ | |
3061 if (pos.col <= matchcol) | |
3062 ++matchcol; | |
3063 else if (pos.col <= regmatch.endpos[0].col) | |
3064 matchcol = pos.col; | |
3065 else | |
3066 /* Be careful not to jump over the NUL at the end-of-line */ | |
3067 for (matchcol = regmatch.endpos[0].col; | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3068 matchcol < line_len && matchcol < pos.col; |
7 | 3069 ++matchcol) |
3070 ; | |
3071 | |
3072 /* if the skip pattern includes end-of-line, break here */ | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3073 if (matchcol >= line_len) |
7 | 3074 break; |
3075 | |
3076 continue; /* start with first end pattern again */ | |
3077 } | |
3078 } | |
3079 | |
3080 /* | |
3081 * Match from start pattern to end pattern. | |
3082 * Correct for match and highlight offset of end pattern. | |
3083 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3084 spp = &(SYN_ITEMS(syn_block)[best_idx]); |
7 | 3085 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); |
3086 /* can't end before the start */ | |
3087 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) | |
3088 m_endpos->col = startpos->col; | |
3089 | |
3090 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); | |
3091 /* can't end before the start */ | |
3092 if (end_endpos->lnum == startpos->lnum | |
3093 && end_endpos->col < startpos->col) | |
3094 end_endpos->col = startpos->col; | |
3095 /* can't end after the match */ | |
3096 limit_pos(end_endpos, m_endpos); | |
3097 | |
3098 /* | |
3099 * If the end group is highlighted differently, adjust the pointers. | |
3100 */ | |
3101 if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) | |
3102 { | |
3103 *end_idx = best_idx; | |
3104 if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) | |
3105 { | |
3106 hl_endpos->lnum = best_regmatch.endpos[0].lnum; | |
3107 hl_endpos->col = best_regmatch.endpos[0].col; | |
3108 } | |
3109 else | |
3110 { | |
3111 hl_endpos->lnum = best_regmatch.startpos[0].lnum; | |
3112 hl_endpos->col = best_regmatch.startpos[0].col; | |
3113 } | |
3114 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; | |
3115 | |
3116 /* can't end before the start */ | |
3117 if (hl_endpos->lnum == startpos->lnum | |
3118 && hl_endpos->col < startpos->col) | |
3119 hl_endpos->col = startpos->col; | |
3120 limit_pos(hl_endpos, m_endpos); | |
3121 | |
3122 /* now the match ends where the highlighting ends, it is turned | |
3123 * into the matchgroup for the end */ | |
3124 *m_endpos = *hl_endpos; | |
3125 } | |
3126 else | |
3127 { | |
3128 *end_idx = 0; | |
3129 *hl_endpos = *end_endpos; | |
3130 } | |
3131 | |
3132 *flagsp = spp->sp_flags; | |
3133 | |
3134 had_match = TRUE; | |
3135 break; | |
3136 } | |
3137 | |
3138 /* no match for an END pattern in this line */ | |
3139 if (!had_match) | |
3140 m_endpos->lnum = 0; | |
3141 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3142 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3143 |
7 | 3144 /* Remove external matches. */ |
3145 unref_extmatch(re_extmatch_in); | |
3146 re_extmatch_in = NULL; | |
3147 } | |
3148 | |
3149 /* | |
3150 * Limit "pos" not to be after "limit". | |
3151 */ | |
3152 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3153 limit_pos(lpos_T *pos, lpos_T *limit) |
7 | 3154 { |
3155 if (pos->lnum > limit->lnum) | |
3156 *pos = *limit; | |
3157 else if (pos->lnum == limit->lnum && pos->col > limit->col) | |
3158 pos->col = limit->col; | |
3159 } | |
3160 | |
3161 /* | |
3162 * Limit "pos" not to be after "limit", unless pos->lnum is zero. | |
3163 */ | |
3164 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3165 limit_pos_zero( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3166 lpos_T *pos, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3167 lpos_T *limit) |
7 | 3168 { |
3169 if (pos->lnum == 0) | |
3170 *pos = *limit; | |
3171 else | |
3172 limit_pos(pos, limit); | |
3173 } | |
3174 | |
3175 /* | |
3176 * Add offset to matched text for end of match or highlight. | |
3177 */ | |
3178 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3179 syn_add_end_off( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3180 lpos_T *result, /* returned position */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3181 regmmatch_T *regmatch, /* start/end of match */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3182 synpat_T *spp, /* matched pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3183 int idx, /* index of offset */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3184 int extra) /* extra chars for offset to start */ |
7 | 3185 { |
3186 int col; | |
1624 | 3187 int off; |
3188 char_u *base; | |
3189 char_u *p; | |
7 | 3190 |
3191 if (spp->sp_off_flags & (1 << idx)) | |
3192 { | |
3193 result->lnum = regmatch->startpos[0].lnum; | |
1624 | 3194 col = regmatch->startpos[0].col; |
3195 off = spp->sp_offsets[idx] + extra; | |
7 | 3196 } |
3197 else | |
3198 { | |
3199 result->lnum = regmatch->endpos[0].lnum; | |
3200 col = regmatch->endpos[0].col; | |
1624 | 3201 off = spp->sp_offsets[idx]; |
3202 } | |
3203 /* Don't go past the end of the line. Matters for "rs=e+2" when there | |
3204 * is a matchgroup. Watch out for match with last NL in the buffer. */ | |
3205 if (result->lnum > syn_buf->b_ml.ml_line_count) | |
3206 col = 0; | |
3207 else if (off != 0) | |
3208 { | |
3209 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3210 p = base + col; | |
3211 if (off > 0) | |
3212 { | |
3213 while (off-- > 0 && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3214 MB_PTR_ADV(p); |
1624 | 3215 } |
3216 else if (off < 0) | |
3217 { | |
3218 while (off++ < 0 && base < p) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3219 MB_PTR_BACK(base, p); |
1624 | 3220 } |
3221 col = (int)(p - base); | |
3222 } | |
3223 result->col = col; | |
7 | 3224 } |
3225 | |
3226 /* | |
3227 * Add offset to matched text for start of match or highlight. | |
3228 * Avoid resulting column to become negative. | |
3229 */ | |
3230 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3231 syn_add_start_off( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3232 lpos_T *result, /* returned position */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3233 regmmatch_T *regmatch, /* start/end of match */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3234 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3235 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3236 int extra) /* extra chars for offset to end */ |
7 | 3237 { |
3238 int col; | |
1624 | 3239 int off; |
3240 char_u *base; | |
3241 char_u *p; | |
7 | 3242 |
3243 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) | |
3244 { | |
3245 result->lnum = regmatch->endpos[0].lnum; | |
1624 | 3246 col = regmatch->endpos[0].col; |
3247 off = spp->sp_offsets[idx] + extra; | |
7 | 3248 } |
3249 else | |
3250 { | |
3251 result->lnum = regmatch->startpos[0].lnum; | |
3252 col = regmatch->startpos[0].col; | |
1624 | 3253 off = spp->sp_offsets[idx]; |
3254 } | |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3255 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
|
3256 { |
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3257 /* 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
|
3258 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
|
3259 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
|
3260 } |
1624 | 3261 if (off != 0) |
3262 { | |
3263 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3264 p = base + col; | |
3265 if (off > 0) | |
3266 { | |
3267 while (off-- && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3268 MB_PTR_ADV(p); |
1624 | 3269 } |
3270 else if (off < 0) | |
3271 { | |
3272 while (off++ && base < p) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3273 MB_PTR_BACK(base, p); |
1624 | 3274 } |
3275 col = (int)(p - base); | |
3276 } | |
3277 result->col = col; | |
7 | 3278 } |
3279 | |
3280 /* | |
3281 * Get current line in syntax buffer. | |
3282 */ | |
3283 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3284 syn_getcurline(void) |
7 | 3285 { |
3286 return ml_get_buf(syn_buf, current_lnum, FALSE); | |
3287 } | |
3288 | |
3289 /* | |
410 | 3290 * Call vim_regexec() to find a match with "rmp" in "syn_buf". |
7 | 3291 * Returns TRUE when there is a match. |
3292 */ | |
3293 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3294 syn_regexec( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3295 regmmatch_T *rmp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3296 linenr_T lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3297 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3298 syn_time_T *st UNUSED) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3299 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3300 int r; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3301 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3302 proftime_T pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3303 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3304 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3305 profile_start(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3306 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3307 |
410 | 3308 rmp->rmm_maxcol = syn_buf->b_p_smc; |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3309 r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, NULL); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3310 |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3311 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3312 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3313 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3314 profile_end(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3315 profile_add(&st->total, &pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3316 if (profile_cmp(&pt, &st->slowest) < 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3317 st->slowest = pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3318 ++st->count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3319 if (r > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3320 ++st->match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3321 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3322 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3323 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3324 if (r > 0) |
7 | 3325 { |
3326 rmp->startpos[0].lnum += lnum; | |
3327 rmp->endpos[0].lnum += lnum; | |
3328 return TRUE; | |
3329 } | |
3330 return FALSE; | |
3331 } | |
3332 | |
3333 /* | |
3334 * Check one position in a line for a matching keyword. | |
3335 * The caller must check if a keyword can start at startcol. | |
3336 * Return it's ID if found, 0 otherwise. | |
3337 */ | |
3338 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3339 check_keyword_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3340 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3341 int startcol, /* position in line to check for keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3342 int *endcolp, /* return: character after found keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3343 long *flagsp, /* return: flags of matching keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3344 short **next_listp, /* return: next_list of matching keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3345 stateitem_T *cur_si, /* item at the top of the stack */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3346 int *ccharp UNUSED) /* conceal substitution char */ |
7 | 3347 { |
134 | 3348 keyentry_T *kp; |
3349 char_u *kwp; | |
7 | 3350 int round; |
134 | 3351 int kwlen; |
7 | 3352 char_u keyword[MAXKEYWLEN + 1]; /* assume max. keyword len is 80 */ |
134 | 3353 hashtab_T *ht; |
3354 hashitem_T *hi; | |
7 | 3355 |
3356 /* Find first character after the keyword. First character was already | |
3357 * checked. */ | |
134 | 3358 kwp = line + startcol; |
3359 kwlen = 0; | |
7 | 3360 do |
3361 { | |
3362 #ifdef FEAT_MBYTE | |
3363 if (has_mbyte) | |
474 | 3364 kwlen += (*mb_ptr2len)(kwp + kwlen); |
7 | 3365 else |
3366 #endif | |
134 | 3367 ++kwlen; |
3368 } | |
4043 | 3369 while (vim_iswordp_buf(kwp + kwlen, syn_buf)); |
134 | 3370 |
3371 if (kwlen > MAXKEYWLEN) | |
7 | 3372 return 0; |
3373 | |
3374 /* | |
3375 * Must make a copy of the keyword, so we can add a NUL and make it | |
3376 * lowercase. | |
3377 */ | |
419 | 3378 vim_strncpy(keyword, kwp, kwlen); |
7 | 3379 |
3380 /* | |
3381 * Try twice: | |
3382 * 1. matching case | |
3383 * 2. ignoring case | |
3384 */ | |
3385 for (round = 1; round <= 2; ++round) | |
3386 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3387 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; |
134 | 3388 if (ht->ht_used == 0) |
7 | 3389 continue; |
134 | 3390 if (round == 2) /* ignore case */ |
3391 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); | |
7 | 3392 |
3393 /* | |
134 | 3394 * Find keywords that match. There can be several with different |
3395 * attributes. | |
7 | 3396 * When current_next_list is non-zero accept only that group, otherwise: |
3397 * Accept a not-contained keyword at toplevel. | |
3398 * Accept a keyword at other levels only if it is in the contains list. | |
3399 */ | |
134 | 3400 hi = hash_find(ht, keyword); |
3401 if (!HASHITEM_EMPTY(hi)) | |
3402 for (kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) | |
7 | 3403 { |
134 | 3404 if (current_next_list != 0 |
3405 ? in_id_list(NULL, current_next_list, &kp->k_syn, 0) | |
3406 : (cur_si == NULL | |
3407 ? !(kp->flags & HL_CONTAINED) | |
3408 : in_id_list(cur_si, cur_si->si_cont_list, | |
3409 &kp->k_syn, kp->flags & HL_CONTAINED))) | |
3410 { | |
3411 *endcolp = startcol + kwlen; | |
3412 *flagsp = kp->flags; | |
3413 *next_listp = kp->next_list; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3414 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3415 *ccharp = kp->k_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3416 #endif |
134 | 3417 return kp->k_syn.id; |
3418 } | |
7 | 3419 } |
3420 } | |
3421 return 0; | |
3422 } | |
3423 | |
3424 /* | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3425 * Handle ":syntax conceal" command. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3426 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3427 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3428 syn_cmd_conceal(exarg_T *eap UNUSED, int syncing UNUSED) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3429 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3430 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3431 char_u *arg = eap->arg; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3432 char_u *next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3433 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3434 eap->nextcmd = find_nextcmd(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3435 if (eap->skip) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3436 return; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3437 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3438 next = skiptowhite(arg); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3439 if (*arg == NUL) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3440 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3441 if (curwin->w_s->b_syn_conceal) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3442 MSG(_("syn conceal on")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3443 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3444 MSG(_("syn conceal off")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3445 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3446 else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3447 curwin->w_s->b_syn_conceal = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3448 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
|
3449 curwin->w_s->b_syn_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3450 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3451 EMSG2(_("E390: Illegal argument: %s"), arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3452 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3453 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3454 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3455 /* |
7 | 3456 * Handle ":syntax case" command. |
3457 */ | |
3458 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3459 syn_cmd_case(exarg_T *eap, int syncing UNUSED) |
7 | 3460 { |
3461 char_u *arg = eap->arg; | |
3462 char_u *next; | |
3463 | |
3464 eap->nextcmd = find_nextcmd(arg); | |
3465 if (eap->skip) | |
3466 return; | |
3467 | |
3468 next = skiptowhite(arg); | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3469 if (*arg == NUL) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3470 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3471 if (curwin->w_s->b_syn_ic) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3472 MSG(_("syntax case ignore")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3473 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3474 MSG(_("syntax case match")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3475 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3476 else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3477 curwin->w_s->b_syn_ic = FALSE; |
7 | 3478 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
|
3479 curwin->w_s->b_syn_ic = TRUE; |
7 | 3480 else |
3481 EMSG2(_("E390: Illegal argument: %s"), arg); | |
3482 } | |
3483 | |
3484 /* | |
419 | 3485 * Handle ":syntax spell" command. |
3486 */ | |
3487 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3488 syn_cmd_spell(exarg_T *eap, int syncing UNUSED) |
419 | 3489 { |
3490 char_u *arg = eap->arg; | |
3491 char_u *next; | |
3492 | |
3493 eap->nextcmd = find_nextcmd(arg); | |
3494 if (eap->skip) | |
3495 return; | |
3496 | |
3497 next = skiptowhite(arg); | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3498 if (*arg == NUL) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3499 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3500 if (curwin->w_s->b_syn_spell == SYNSPL_TOP) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3501 MSG(_("syntax spell toplevel")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3502 else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3503 MSG(_("syntax spell notoplevel")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3504 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3505 MSG(_("syntax spell default")); |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3506 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3507 else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3508 curwin->w_s->b_syn_spell = SYNSPL_TOP; |
419 | 3509 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
|
3510 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; |
1064 | 3511 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
|
3512 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; |
419 | 3513 else |
6880 | 3514 { |
419 | 3515 EMSG2(_("E390: Illegal argument: %s"), arg); |
6880 | 3516 return; |
3517 } | |
3518 | |
3519 /* assume spell checking changed, force a redraw */ | |
3520 redraw_win_later(curwin, NOT_VALID); | |
419 | 3521 } |
3522 | |
3523 /* | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3524 * Handle ":syntax iskeyword" command. |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3525 */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3526 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3527 syn_cmd_iskeyword(exarg_T *eap, int syncing UNUSED) |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3528 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3529 char_u *arg = eap->arg; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3530 char_u save_chartab[32]; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3531 char_u *save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3532 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3533 if (eap->skip) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3534 return; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3535 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3536 arg = skipwhite(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3537 if (*arg == NUL) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3538 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3539 MSG_PUTS("\n"); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3540 MSG_PUTS(_("syntax iskeyword ")); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3541 if (curwin->w_s->b_syn_isk != empty_option) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3542 msg_outtrans(curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3543 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3544 msg_outtrans((char_u *)"not set"); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3545 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3546 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3547 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3548 if (STRNICMP(arg, "clear", 5) == 0) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3549 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3550 mch_memmove(curwin->w_s->b_syn_chartab, curbuf->b_chartab, |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3551 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3552 clear_string_option(&curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3553 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3554 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3555 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3556 mch_memmove(save_chartab, curbuf->b_chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3557 save_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3558 curbuf->b_p_isk = vim_strsave(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3559 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3560 buf_init_chartab(curbuf, FALSE); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3561 mch_memmove(curwin->w_s->b_syn_chartab, curbuf->b_chartab, |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3562 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3563 mch_memmove(curbuf->b_chartab, save_chartab, (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3564 clear_string_option(&curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3565 curwin->w_s->b_syn_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3566 curbuf->b_p_isk = save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3567 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3568 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3569 redraw_win_later(curwin, NOT_VALID); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3570 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3571 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3572 /* |
7 | 3573 * Clear all syntax info for one buffer. |
3574 */ | |
3575 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3576 syntax_clear(synblock_T *block) |
7 | 3577 { |
3578 int i; | |
3579 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3580 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
|
3581 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
|
3582 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
|
3583 block->b_syn_containedin = FALSE; |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3584 #ifdef FEAT_CONCEAL |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3585 block->b_syn_conceal = FALSE; |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3586 #endif |
7 | 3587 |
3588 /* free the keywords */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3589 clear_keywtab(&block->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3590 clear_keywtab(&block->b_keywtab_ic); |
7 | 3591 |
3592 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3593 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
|
3594 syn_clear_pattern(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3595 ga_clear(&block->b_syn_patterns); |
7 | 3596 |
3597 /* free the syntax clusters */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3598 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
|
3599 syn_clear_cluster(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3600 ga_clear(&block->b_syn_clusters); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3601 block->b_spell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3602 block->b_nospell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3603 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3604 block->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3605 block->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3606 block->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3607 block->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3608 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3609 vim_regfree(block->b_syn_linecont_prog); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3610 block->b_syn_linecont_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3611 vim_free(block->b_syn_linecont_pat); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3612 block->b_syn_linecont_pat = NULL; |
7 | 3613 #ifdef FEAT_FOLDING |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3614 block->b_syn_folditems = 0; |
7 | 3615 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3616 clear_string_option(&block->b_syn_isk); |
7 | 3617 |
3618 /* free the stored states */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3619 syn_stack_free_all(block); |
7 | 3620 invalidate_current_state(); |
2743 | 3621 |
3622 /* Reset the counter for ":syn include" */ | |
3623 running_syn_inc_tag = 0; | |
7 | 3624 } |
3625 | |
3626 /* | |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3627 * 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
|
3628 */ |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3629 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3630 reset_synblock(win_T *wp) |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3631 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3632 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
|
3633 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3634 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
|
3635 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
|
3636 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
|
3637 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3638 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3639 |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3640 /* |
7 | 3641 * Clear syncing info for one buffer. |
3642 */ | |
3643 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3644 syntax_sync_clear(void) |
7 | 3645 { |
3646 int i; | |
3647 | |
3648 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3649 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
|
3650 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
|
3651 syn_remove_pattern(curwin->w_s, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3652 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3653 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
|
3654 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
|
3655 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
|
3656 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
|
3657 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3658 vim_regfree(curwin->w_s->b_syn_linecont_prog); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3659 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
|
3660 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
|
3661 curwin->w_s->b_syn_linecont_pat = NULL; |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3662 clear_string_option(&curwin->w_s->b_syn_isk); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3663 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3664 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3665 } |
3666 | |
3667 /* | |
3668 * Remove one pattern from the buffer's pattern list. | |
3669 */ | |
3670 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3671 syn_remove_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3672 synblock_T *block, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3673 int idx) |
7 | 3674 { |
3675 synpat_T *spp; | |
3676 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3677 spp = &(SYN_ITEMS(block)[idx]); |
7 | 3678 #ifdef FEAT_FOLDING |
3679 if (spp->sp_flags & HL_FOLD) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3680 --block->b_syn_folditems; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3681 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3682 syn_clear_pattern(block, idx); |
7 | 3683 mch_memmove(spp, spp + 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3684 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
|
3685 --block->b_syn_patterns.ga_len; |
7 | 3686 } |
3687 | |
3688 /* | |
3689 * Clear and free one syntax pattern. When clearing all, must be called from | |
3690 * last to first! | |
3691 */ | |
3692 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3693 syn_clear_pattern(synblock_T *block, int i) |
7 | 3694 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3695 vim_free(SYN_ITEMS(block)[i].sp_pattern); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3696 vim_regfree(SYN_ITEMS(block)[i].sp_prog); |
7 | 3697 /* 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
|
3698 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
|
3699 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3700 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
|
3701 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
|
3702 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); |
7 | 3703 } |
3704 } | |
3705 | |
3706 /* | |
3707 * Clear and free one syntax cluster. | |
3708 */ | |
3709 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3710 syn_clear_cluster(synblock_T *block, int i) |
7 | 3711 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3712 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
|
3713 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
|
3714 vim_free(SYN_CLSTR(block)[i].scl_list); |
7 | 3715 } |
3716 | |
3717 /* | |
3718 * Handle ":syntax clear" command. | |
3719 */ | |
3720 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3721 syn_cmd_clear(exarg_T *eap, int syncing) |
7 | 3722 { |
3723 char_u *arg = eap->arg; | |
3724 char_u *arg_end; | |
3725 int id; | |
3726 | |
3727 eap->nextcmd = find_nextcmd(arg); | |
3728 if (eap->skip) | |
3729 return; | |
3730 | |
3731 /* | |
3732 * We have to disable this within ":syn include @group filename", | |
3733 * because otherwise @group would get deleted. | |
3734 * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn | |
3735 * clear". | |
3736 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3737 if (curwin->w_s->b_syn_topgrp != 0) |
7 | 3738 return; |
3739 | |
3740 if (ends_excmd(*arg)) | |
3741 { | |
3742 /* | |
3743 * No argument: Clear all syntax items. | |
3744 */ | |
3745 if (syncing) | |
3746 syntax_sync_clear(); | |
3747 else | |
3748 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3749 syntax_clear(curwin->w_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3750 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
|
3751 do_unlet((char_u *)"b:current_syntax", TRUE); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
3752 do_unlet((char_u *)"w:current_syntax", TRUE); |
7 | 3753 } |
3754 } | |
3755 else | |
3756 { | |
3757 /* | |
3758 * Clear the group IDs that are in the argument. | |
3759 */ | |
3760 while (!ends_excmd(*arg)) | |
3761 { | |
3762 arg_end = skiptowhite(arg); | |
3763 if (*arg == '@') | |
3764 { | |
3765 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3766 if (id == 0) | |
3767 { | |
3768 EMSG2(_("E391: No such syntax cluster: %s"), arg); | |
3769 break; | |
3770 } | |
3771 else | |
3772 { | |
3773 /* | |
3774 * We can't physically delete a cluster without changing | |
3775 * the IDs of other clusters, so we do the next best thing | |
3776 * and make it empty. | |
3777 */ | |
3778 short scl_id = id - SYNID_CLUSTER; | |
3779 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3780 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
|
3781 SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; |
7 | 3782 } |
3783 } | |
3784 else | |
3785 { | |
3786 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3787 if (id == 0) | |
3788 { | |
3789 EMSG2(_(e_nogroup), arg); | |
3790 break; | |
3791 } | |
3792 else | |
3793 syn_clear_one(id, syncing); | |
3794 } | |
3795 arg = skipwhite(arg_end); | |
3796 } | |
3797 } | |
745 | 3798 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3799 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3800 } |
3801 | |
3802 /* | |
3803 * Clear one syntax group for the current buffer. | |
3804 */ | |
3805 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3806 syn_clear_one(int id, int syncing) |
7 | 3807 { |
3808 synpat_T *spp; | |
3809 int idx; | |
3810 | |
3811 /* Clear keywords only when not ":syn sync clear group-name" */ | |
3812 if (!syncing) | |
3813 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3814 (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
|
3815 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); |
7 | 3816 } |
3817 | |
3818 /* clear the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3819 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
|
3820 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3821 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3822 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3823 continue; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3824 syn_remove_pattern(curwin->w_s, idx); |
7 | 3825 } |
3826 } | |
3827 | |
3828 /* | |
3829 * Handle ":syntax on" command. | |
3830 */ | |
3831 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3832 syn_cmd_on(exarg_T *eap, int syncing UNUSED) |
7 | 3833 { |
3834 syn_cmd_onoff(eap, "syntax"); | |
3835 } | |
3836 | |
3837 /* | |
3838 * Handle ":syntax enable" command. | |
3839 */ | |
3840 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3841 syn_cmd_enable(exarg_T *eap, int syncing UNUSED) |
7 | 3842 { |
3843 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable"); | |
3844 syn_cmd_onoff(eap, "syntax"); | |
148 | 3845 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3846 } |
3847 | |
3848 /* | |
3849 * Handle ":syntax reset" command. | |
8815
50d9fb580ffe
commit https://github.com/vim/vim/commit/8bc189e81aa98ba4aebb03a9dc9527a210fce816
Christian Brabandt <cb@256bit.org>
parents:
8806
diff
changeset
|
3850 * It actually resets highlighting, not syntax. |
7 | 3851 */ |
3852 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3853 syn_cmd_reset(exarg_T *eap, int syncing UNUSED) |
7 | 3854 { |
3855 eap->nextcmd = check_nextcmd(eap->arg); | |
3856 if (!eap->skip) | |
3857 { | |
3858 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset"); | |
3859 do_cmdline_cmd((char_u *)"runtime! syntax/syncolor.vim"); | |
148 | 3860 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3861 } |
3862 } | |
3863 | |
3864 /* | |
3865 * Handle ":syntax manual" command. | |
3866 */ | |
3867 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3868 syn_cmd_manual(exarg_T *eap, int syncing UNUSED) |
7 | 3869 { |
3870 syn_cmd_onoff(eap, "manual"); | |
3871 } | |
3872 | |
3873 /* | |
3874 * Handle ":syntax off" command. | |
3875 */ | |
3876 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3877 syn_cmd_off(exarg_T *eap, int syncing UNUSED) |
7 | 3878 { |
3879 syn_cmd_onoff(eap, "nosyntax"); | |
3880 } | |
3881 | |
3882 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3883 syn_cmd_onoff(exarg_T *eap, char *name) |
7 | 3884 { |
3885 char_u buf[100]; | |
3886 | |
3887 eap->nextcmd = check_nextcmd(eap->arg); | |
3888 if (!eap->skip) | |
3889 { | |
3890 STRCPY(buf, "so "); | |
274 | 3891 vim_snprintf((char *)buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); |
7 | 3892 do_cmdline_cmd(buf); |
3893 } | |
3894 } | |
3895 | |
3896 /* | |
3897 * Handle ":syntax [list]" command: list current syntax words. | |
3898 */ | |
3899 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3900 syn_cmd_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3901 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3902 int syncing) /* when TRUE: list syncing items */ |
7 | 3903 { |
3904 char_u *arg = eap->arg; | |
3905 int id; | |
3906 char_u *arg_end; | |
3907 | |
3908 eap->nextcmd = find_nextcmd(arg); | |
3909 if (eap->skip) | |
3910 return; | |
3911 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3912 if (!syntax_present(curwin)) |
7 | 3913 { |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3914 MSG(_(msg_no_items)); |
7 | 3915 return; |
3916 } | |
3917 | |
3918 if (syncing) | |
3919 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3920 if (curwin->w_s->b_syn_sync_flags & SF_CCOMMENT) |
7 | 3921 { |
3922 MSG_PUTS(_("syncing on C-style comments")); | |
3923 syn_lines_msg(); | |
3924 syn_match_msg(); | |
3925 return; | |
3926 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3927 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
|
3928 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3929 if (curwin->w_s->b_syn_sync_minlines == 0) |
7 | 3930 MSG_PUTS(_("no syncing")); |
3931 else | |
3932 { | |
3933 MSG_PUTS(_("syncing starts ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3934 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
7 | 3935 MSG_PUTS(_(" lines before top line")); |
3936 syn_match_msg(); | |
3937 } | |
3938 return; | |
3939 } | |
3940 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
|
3941 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
|
3942 || 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
|
3943 || curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3944 { |
3945 MSG_PUTS(_("\nsyncing on items")); | |
3946 syn_lines_msg(); | |
3947 syn_match_msg(); | |
3948 } | |
3949 } | |
3950 else | |
3951 MSG_PUTS_TITLE(_("\n--- Syntax items ---")); | |
3952 if (ends_excmd(*arg)) | |
3953 { | |
3954 /* | |
3955 * No argument: List all group IDs and all syntax clusters. | |
3956 */ | |
3957 for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id) | |
3958 syn_list_one(id, syncing, FALSE); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3959 for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) |
7 | 3960 syn_list_cluster(id); |
3961 } | |
3962 else | |
3963 { | |
3964 /* | |
3965 * List the group IDs and syntax clusters that are in the argument. | |
3966 */ | |
3967 while (!ends_excmd(*arg) && !got_int) | |
3968 { | |
3969 arg_end = skiptowhite(arg); | |
3970 if (*arg == '@') | |
3971 { | |
3972 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3973 if (id == 0) | |
3974 EMSG2(_("E392: No such syntax cluster: %s"), arg); | |
3975 else | |
3976 syn_list_cluster(id - SYNID_CLUSTER); | |
3977 } | |
3978 else | |
3979 { | |
3980 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3981 if (id == 0) | |
3982 EMSG2(_(e_nogroup), arg); | |
3983 else | |
3984 syn_list_one(id, syncing, TRUE); | |
3985 } | |
3986 arg = skipwhite(arg_end); | |
3987 } | |
3988 } | |
3989 eap->nextcmd = check_nextcmd(arg); | |
3990 } | |
3991 | |
3992 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3993 syn_lines_msg(void) |
7 | 3994 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3995 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
|
3996 || curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3997 { |
3998 MSG_PUTS("; "); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3999 if (curwin->w_s->b_syn_sync_minlines > 0) |
7 | 4000 { |
4001 MSG_PUTS(_("minimal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4002 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
|
4003 if (curwin->w_s->b_syn_sync_maxlines) |
7 | 4004 MSG_PUTS(", "); |
4005 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4006 if (curwin->w_s->b_syn_sync_maxlines > 0) |
7 | 4007 { |
4008 MSG_PUTS(_("maximal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4009 msg_outnum(curwin->w_s->b_syn_sync_maxlines); |
7 | 4010 } |
4011 MSG_PUTS(_(" lines before top line")); | |
4012 } | |
4013 } | |
4014 | |
4015 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4016 syn_match_msg(void) |
7 | 4017 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4018 if (curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 4019 { |
4020 MSG_PUTS(_("; match ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4021 msg_outnum(curwin->w_s->b_syn_sync_linebreaks); |
7 | 4022 MSG_PUTS(_(" line breaks")); |
4023 } | |
4024 } | |
4025 | |
4026 static int last_matchgroup; | |
4027 | |
4028 struct name_list | |
4029 { | |
4030 int flag; | |
4031 char *name; | |
4032 }; | |
4033 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
4034 static void syn_list_flags(struct name_list *nl, int flags, int attr); |
7 | 4035 |
4036 /* | |
4037 * List one syntax item, for ":syntax" or "syntax list syntax_name". | |
4038 */ | |
4039 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4040 syn_list_one( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4041 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4042 int syncing, /* when TRUE: list syncing items */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4043 int link_only) /* when TRUE; list link-only too */ |
7 | 4044 { |
4045 int attr; | |
4046 int idx; | |
4047 int did_header = FALSE; | |
4048 synpat_T *spp; | |
4049 static struct name_list namelist1[] = | |
4050 { | |
4051 {HL_DISPLAY, "display"}, | |
4052 {HL_CONTAINED, "contained"}, | |
4053 {HL_ONELINE, "oneline"}, | |
4054 {HL_KEEPEND, "keepend"}, | |
4055 {HL_EXTEND, "extend"}, | |
4056 {HL_EXCLUDENL, "excludenl"}, | |
4057 {HL_TRANSP, "transparent"}, | |
4058 {HL_FOLD, "fold"}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4059 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4060 {HL_CONCEAL, "conceal"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4061 {HL_CONCEALENDS, "concealends"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4062 #endif |
7 | 4063 {0, NULL} |
4064 }; | |
4065 static struct name_list namelist2[] = | |
4066 { | |
4067 {HL_SKIPWHITE, "skipwhite"}, | |
4068 {HL_SKIPNL, "skipnl"}, | |
4069 {HL_SKIPEMPTY, "skipempty"}, | |
4070 {0, NULL} | |
4071 }; | |
4072 | |
4073 attr = hl_attr(HLF_D); /* highlight like directories */ | |
4074 | |
4075 /* list the keywords for "id" */ | |
4076 if (!syncing) | |
4077 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4078 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
|
4079 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, |
7 | 4080 did_header, attr); |
4081 } | |
4082 | |
4083 /* list the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4084 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
|
4085 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4086 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 4087 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
4088 continue; | |
4089 | |
4090 (void)syn_list_header(did_header, 999, id); | |
4091 did_header = TRUE; | |
4092 last_matchgroup = 0; | |
4093 if (spp->sp_type == SPTYPE_MATCH) | |
4094 { | |
4095 put_pattern("match", ' ', spp, attr); | |
4096 msg_putchar(' '); | |
4097 } | |
4098 else if (spp->sp_type == SPTYPE_START) | |
4099 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4100 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
|
4101 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
|
4102 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
|
4103 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
|
4104 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
|
4105 && 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
|
4106 put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
7 | 4107 --idx; |
4108 msg_putchar(' '); | |
4109 } | |
4110 syn_list_flags(namelist1, spp->sp_flags, attr); | |
4111 | |
4112 if (spp->sp_cont_list != NULL) | |
4113 put_id_list((char_u *)"contains", spp->sp_cont_list, attr); | |
4114 | |
4115 if (spp->sp_syn.cont_in_list != NULL) | |
4116 put_id_list((char_u *)"containedin", | |
4117 spp->sp_syn.cont_in_list, attr); | |
4118 | |
4119 if (spp->sp_next_list != NULL) | |
4120 { | |
4121 put_id_list((char_u *)"nextgroup", spp->sp_next_list, attr); | |
4122 syn_list_flags(namelist2, spp->sp_flags, attr); | |
4123 } | |
4124 if (spp->sp_flags & (HL_SYNC_HERE|HL_SYNC_THERE)) | |
4125 { | |
4126 if (spp->sp_flags & HL_SYNC_HERE) | |
4127 msg_puts_attr((char_u *)"grouphere", attr); | |
4128 else | |
4129 msg_puts_attr((char_u *)"groupthere", attr); | |
4130 msg_putchar(' '); | |
4131 if (spp->sp_sync_idx >= 0) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4132 msg_outtrans(HL_TABLE()[SYN_ITEMS(curwin->w_s) |
7 | 4133 [spp->sp_sync_idx].sp_syn.id - 1].sg_name); |
4134 else | |
4135 MSG_PUTS("NONE"); | |
4136 msg_putchar(' '); | |
4137 } | |
4138 } | |
4139 | |
4140 /* list the link, if there is one */ | |
4141 if (HL_TABLE()[id - 1].sg_link && (did_header || link_only) && !got_int) | |
4142 { | |
4143 (void)syn_list_header(did_header, 999, id); | |
4144 msg_puts_attr((char_u *)"links to", attr); | |
4145 msg_putchar(' '); | |
4146 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
4147 } | |
4148 } | |
4149 | |
4150 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4151 syn_list_flags(struct name_list *nlist, int flags, int attr) |
7 | 4152 { |
4153 int i; | |
4154 | |
3263 | 4155 for (i = 0; nlist[i].flag != 0; ++i) |
4156 if (flags & nlist[i].flag) | |
4157 { | |
4158 msg_puts_attr((char_u *)nlist[i].name, attr); | |
7 | 4159 msg_putchar(' '); |
4160 } | |
4161 } | |
4162 | |
4163 /* | |
4164 * List one syntax cluster, for ":syntax" or "syntax list syntax_name". | |
4165 */ | |
4166 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4167 syn_list_cluster(int id) |
7 | 4168 { |
4169 int endcol = 15; | |
4170 | |
4171 /* slight hack: roughly duplicate the guts of syn_list_header() */ | |
4172 msg_putchar('\n'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4173 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); |
7 | 4174 |
4175 if (msg_col >= endcol) /* output at least one space */ | |
4176 endcol = msg_col + 1; | |
4177 if (Columns <= endcol) /* avoid hang for tiny window */ | |
4178 endcol = Columns - 1; | |
4179 | |
4180 msg_advance(endcol); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4181 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
|
4182 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4183 put_id_list((char_u *)"cluster", SYN_CLSTR(curwin->w_s)[id].scl_list, |
7 | 4184 hl_attr(HLF_D)); |
4185 } | |
4186 else | |
4187 { | |
4188 msg_puts_attr((char_u *)"cluster", hl_attr(HLF_D)); | |
4189 msg_puts((char_u *)"=NONE"); | |
4190 } | |
4191 } | |
4192 | |
4193 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4194 put_id_list(char_u *name, short *list, int attr) |
7 | 4195 { |
4196 short *p; | |
4197 | |
4198 msg_puts_attr(name, attr); | |
4199 msg_putchar('='); | |
4200 for (p = list; *p; ++p) | |
4201 { | |
4202 if (*p >= SYNID_ALLBUT && *p < SYNID_TOP) | |
4203 { | |
4204 if (p[1]) | |
4205 MSG_PUTS("ALLBUT"); | |
4206 else | |
4207 MSG_PUTS("ALL"); | |
4208 } | |
4209 else if (*p >= SYNID_TOP && *p < SYNID_CONTAINED) | |
4210 { | |
4211 MSG_PUTS("TOP"); | |
4212 } | |
4213 else if (*p >= SYNID_CONTAINED && *p < SYNID_CLUSTER) | |
4214 { | |
4215 MSG_PUTS("CONTAINED"); | |
4216 } | |
4217 else if (*p >= SYNID_CLUSTER) | |
4218 { | |
4219 short scl_id = *p - SYNID_CLUSTER; | |
4220 | |
4221 msg_putchar('@'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4222 msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); |
7 | 4223 } |
4224 else | |
4225 msg_outtrans(HL_TABLE()[*p - 1].sg_name); | |
4226 if (p[1]) | |
4227 msg_putchar(','); | |
4228 } | |
4229 msg_putchar(' '); | |
4230 } | |
4231 | |
4232 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4233 put_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4234 char *s, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4235 int c, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4236 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4237 int attr) |
7 | 4238 { |
4239 long n; | |
4240 int mask; | |
4241 int first; | |
4242 static char *sepchars = "/+=-#@\"|'^&"; | |
4243 int i; | |
4244 | |
4245 /* May have to write "matchgroup=group" */ | |
4246 if (last_matchgroup != spp->sp_syn_match_id) | |
4247 { | |
4248 last_matchgroup = spp->sp_syn_match_id; | |
4249 msg_puts_attr((char_u *)"matchgroup", attr); | |
4250 msg_putchar('='); | |
4251 if (last_matchgroup == 0) | |
4252 msg_outtrans((char_u *)"NONE"); | |
4253 else | |
4254 msg_outtrans(HL_TABLE()[last_matchgroup - 1].sg_name); | |
4255 msg_putchar(' '); | |
4256 } | |
4257 | |
4258 /* output the name of the pattern and an '=' or ' ' */ | |
4259 msg_puts_attr((char_u *)s, attr); | |
4260 msg_putchar(c); | |
4261 | |
4262 /* output the pattern, in between a char that is not in the pattern */ | |
4263 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) | |
4264 if (sepchars[++i] == NUL) | |
4265 { | |
4266 i = 0; /* no good char found, just use the first one */ | |
4267 break; | |
4268 } | |
4269 msg_putchar(sepchars[i]); | |
4270 msg_outtrans(spp->sp_pattern); | |
4271 msg_putchar(sepchars[i]); | |
4272 | |
4273 /* output any pattern options */ | |
4274 first = TRUE; | |
4275 for (i = 0; i < SPO_COUNT; ++i) | |
4276 { | |
4277 mask = (1 << i); | |
4278 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) | |
4279 { | |
4280 if (!first) | |
4281 msg_putchar(','); /* separate with commas */ | |
4282 msg_puts((char_u *)spo_name_tab[i]); | |
4283 n = spp->sp_offsets[i]; | |
4284 if (i != SPO_LC_OFF) | |
4285 { | |
4286 if (spp->sp_off_flags & mask) | |
4287 msg_putchar('s'); | |
4288 else | |
4289 msg_putchar('e'); | |
4290 if (n > 0) | |
4291 msg_putchar('+'); | |
4292 } | |
4293 if (n || i == SPO_LC_OFF) | |
4294 msg_outnum(n); | |
4295 first = FALSE; | |
4296 } | |
4297 } | |
4298 msg_putchar(' '); | |
4299 } | |
4300 | |
4301 /* | |
4302 * List or clear the keywords for one syntax group. | |
4303 * Return TRUE if the header has been printed. | |
4304 */ | |
4305 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4306 syn_list_keywords( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4307 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4308 hashtab_T *ht, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4309 int did_header, /* header has already been printed */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4310 int attr) |
7 | 4311 { |
4312 int outlen; | |
134 | 4313 hashitem_T *hi; |
4314 keyentry_T *kp; | |
4315 int todo; | |
7 | 4316 int prev_contained = 0; |
4317 short *prev_next_list = NULL; | |
4318 short *prev_cont_in_list = NULL; | |
4319 int prev_skipnl = 0; | |
4320 int prev_skipwhite = 0; | |
4321 int prev_skipempty = 0; | |
4322 | |
4323 /* | |
4324 * Unfortunately, this list of keywords is not sorted on alphabet but on | |
4325 * hash value... | |
4326 */ | |
835 | 4327 todo = (int)ht->ht_used; |
134 | 4328 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
4329 { | |
4330 if (!HASHITEM_EMPTY(hi)) | |
4331 { | |
4332 --todo; | |
4333 for (kp = HI2KE(hi); kp != NULL && !got_int; kp = kp->ke_next) | |
7 | 4334 { |
134 | 4335 if (kp->k_syn.id == id) |
7 | 4336 { |
134 | 4337 if (prev_contained != (kp->flags & HL_CONTAINED) |
4338 || prev_skipnl != (kp->flags & HL_SKIPNL) | |
4339 || prev_skipwhite != (kp->flags & HL_SKIPWHITE) | |
4340 || prev_skipempty != (kp->flags & HL_SKIPEMPTY) | |
4341 || prev_cont_in_list != kp->k_syn.cont_in_list | |
4342 || prev_next_list != kp->next_list) | |
4343 outlen = 9999; | |
4344 else | |
4345 outlen = (int)STRLEN(kp->keyword); | |
4346 /* output "contained" and "nextgroup" on each line */ | |
4347 if (syn_list_header(did_header, outlen, id)) | |
4348 { | |
4349 prev_contained = 0; | |
4350 prev_next_list = NULL; | |
4351 prev_cont_in_list = NULL; | |
4352 prev_skipnl = 0; | |
4353 prev_skipwhite = 0; | |
4354 prev_skipempty = 0; | |
4355 } | |
4356 did_header = TRUE; | |
4357 if (prev_contained != (kp->flags & HL_CONTAINED)) | |
4358 { | |
4359 msg_puts_attr((char_u *)"contained", attr); | |
4360 msg_putchar(' '); | |
4361 prev_contained = (kp->flags & HL_CONTAINED); | |
4362 } | |
4363 if (kp->k_syn.cont_in_list != prev_cont_in_list) | |
4364 { | |
4365 put_id_list((char_u *)"containedin", | |
4366 kp->k_syn.cont_in_list, attr); | |
4367 msg_putchar(' '); | |
4368 prev_cont_in_list = kp->k_syn.cont_in_list; | |
4369 } | |
4370 if (kp->next_list != prev_next_list) | |
4371 { | |
4372 put_id_list((char_u *)"nextgroup", kp->next_list, attr); | |
4373 msg_putchar(' '); | |
4374 prev_next_list = kp->next_list; | |
4375 if (kp->flags & HL_SKIPNL) | |
4376 { | |
4377 msg_puts_attr((char_u *)"skipnl", attr); | |
4378 msg_putchar(' '); | |
4379 prev_skipnl = (kp->flags & HL_SKIPNL); | |
4380 } | |
4381 if (kp->flags & HL_SKIPWHITE) | |
4382 { | |
4383 msg_puts_attr((char_u *)"skipwhite", attr); | |
4384 msg_putchar(' '); | |
4385 prev_skipwhite = (kp->flags & HL_SKIPWHITE); | |
4386 } | |
4387 if (kp->flags & HL_SKIPEMPTY) | |
4388 { | |
4389 msg_puts_attr((char_u *)"skipempty", attr); | |
4390 msg_putchar(' '); | |
4391 prev_skipempty = (kp->flags & HL_SKIPEMPTY); | |
4392 } | |
4393 } | |
4394 msg_outtrans(kp->keyword); | |
7 | 4395 } |
4396 } | |
4397 } | |
4398 } | |
4399 | |
4400 return did_header; | |
4401 } | |
4402 | |
4403 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4404 syn_clear_keyword(int id, hashtab_T *ht) |
134 | 4405 { |
4406 hashitem_T *hi; | |
4407 keyentry_T *kp; | |
4408 keyentry_T *kp_prev; | |
4409 keyentry_T *kp_next; | |
4410 int todo; | |
4411 | |
4412 hash_lock(ht); | |
835 | 4413 todo = (int)ht->ht_used; |
134 | 4414 for (hi = ht->ht_array; todo > 0; ++hi) |
4415 { | |
4416 if (!HASHITEM_EMPTY(hi)) | |
4417 { | |
4418 --todo; | |
4419 kp_prev = NULL; | |
4420 for (kp = HI2KE(hi); kp != NULL; ) | |
7 | 4421 { |
134 | 4422 if (kp->k_syn.id == id) |
4423 { | |
4424 kp_next = kp->ke_next; | |
4425 if (kp_prev == NULL) | |
4426 { | |
4427 if (kp_next == NULL) | |
4428 hash_remove(ht, hi); | |
4429 else | |
4430 hi->hi_key = KE2HIKEY(kp_next); | |
4431 } | |
4432 else | |
4433 kp_prev->ke_next = kp_next; | |
4434 vim_free(kp->next_list); | |
4435 vim_free(kp->k_syn.cont_in_list); | |
4436 vim_free(kp); | |
4437 kp = kp_next; | |
4438 } | |
7 | 4439 else |
134 | 4440 { |
4441 kp_prev = kp; | |
4442 kp = kp->ke_next; | |
4443 } | |
7 | 4444 } |
134 | 4445 } |
4446 } | |
4447 hash_unlock(ht); | |
4448 } | |
4449 | |
4450 /* | |
4451 * Clear a whole keyword table. | |
7 | 4452 */ |
4453 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4454 clear_keywtab(hashtab_T *ht) |
134 | 4455 { |
4456 hashitem_T *hi; | |
4457 int todo; | |
4458 keyentry_T *kp; | |
4459 keyentry_T *kp_next; | |
4460 | |
835 | 4461 todo = (int)ht->ht_used; |
134 | 4462 for (hi = ht->ht_array; todo > 0; ++hi) |
4463 { | |
4464 if (!HASHITEM_EMPTY(hi)) | |
4465 { | |
4466 --todo; | |
4467 for (kp = HI2KE(hi); kp != NULL; kp = kp_next) | |
7 | 4468 { |
134 | 4469 kp_next = kp->ke_next; |
4470 vim_free(kp->next_list); | |
4471 vim_free(kp->k_syn.cont_in_list); | |
4472 vim_free(kp); | |
7 | 4473 } |
134 | 4474 } |
4475 } | |
4476 hash_clear(ht); | |
4477 hash_init(ht); | |
7 | 4478 } |
4479 | |
4480 /* | |
4481 * Add a keyword to the list of keywords. | |
4482 */ | |
4483 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4484 add_keyword( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4485 char_u *name, /* name of keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4486 int id, /* group ID for this keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4487 int flags, /* flags for this keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4488 short *cont_in_list, /* containedin for this keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4489 short *next_list, /* nextgroup for this keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4490 int conceal_char) |
7 | 4491 { |
134 | 4492 keyentry_T *kp; |
4493 hashtab_T *ht; | |
4494 hashitem_T *hi; | |
154 | 4495 char_u *name_ic; |
134 | 4496 long_u hash; |
154 | 4497 char_u name_folded[MAXKEYWLEN + 1]; |
7 | 4498 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4499 if (curwin->w_s->b_syn_ic) |
154 | 4500 name_ic = str_foldcase(name, (int)STRLEN(name), |
4501 name_folded, MAXKEYWLEN + 1); | |
4502 else | |
4503 name_ic = name; | |
134 | 4504 kp = (keyentry_T *)alloc((int)(sizeof(keyentry_T) + STRLEN(name_ic))); |
4505 if (kp == NULL) | |
4506 return; | |
4507 STRCPY(kp->keyword, name_ic); | |
4508 kp->k_syn.id = id; | |
4509 kp->k_syn.inc_tag = current_syn_inc_tag; | |
4510 kp->flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4511 kp->k_char = conceal_char; |
134 | 4512 kp->k_syn.cont_in_list = copy_id_list(cont_in_list); |
4513 if (cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4514 curwin->w_s->b_syn_containedin = TRUE; |
134 | 4515 kp->next_list = copy_id_list(next_list); |
4516 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4517 if (curwin->w_s->b_syn_ic) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4518 ht = &curwin->w_s->b_keywtab_ic; |
7 | 4519 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4520 ht = &curwin->w_s->b_keywtab; |
134 | 4521 |
4522 hash = hash_hash(kp->keyword); | |
4523 hi = hash_lookup(ht, kp->keyword, hash); | |
4524 if (HASHITEM_EMPTY(hi)) | |
4525 { | |
4526 /* new keyword, add to hashtable */ | |
4527 kp->ke_next = NULL; | |
4528 hash_add_item(ht, hi, kp->keyword, hash); | |
4529 } | |
4530 else | |
4531 { | |
4532 /* keyword already exists, prepend to list */ | |
4533 kp->ke_next = HI2KE(hi); | |
4534 hi->hi_key = KE2HIKEY(kp); | |
4535 } | |
7 | 4536 } |
4537 | |
4538 /* | |
4539 * Get the start and end of the group name argument. | |
4540 * Return a pointer to the first argument. | |
4541 * Return NULL if the end of the command was found instead of further args. | |
4542 */ | |
4543 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4544 get_group_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4545 char_u *arg, /* start of the argument */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4546 char_u **name_end) /* pointer to end of the name */ |
7 | 4547 { |
4548 char_u *rest; | |
4549 | |
4550 *name_end = skiptowhite(arg); | |
4551 rest = skipwhite(*name_end); | |
4552 | |
4553 /* | |
4554 * Check if there are enough arguments. The first argument may be a | |
4555 * pattern, where '|' is allowed, so only check for NUL. | |
4556 */ | |
4557 if (ends_excmd(*arg) || *rest == NUL) | |
4558 return NULL; | |
4559 return rest; | |
4560 } | |
4561 | |
4562 /* | |
4563 * Check for syntax command option arguments. | |
4564 * This can be called at any place in the list of arguments, and just picks | |
4565 * out the arguments that are known. Can be called several times in a row to | |
4566 * collect all options in between other arguments. | |
4567 * Return a pointer to the next argument (which isn't an option). | |
4568 * Return NULL for any error; | |
4569 */ | |
4570 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4571 get_syn_options( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4572 char_u *arg, /* next argument to be checked */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4573 syn_opt_arg_T *opt, /* various things */ |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4574 int *conceal_char UNUSED, |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4575 int skip) /* TRUE if skipping over command */ |
154 | 4576 { |
7 | 4577 char_u *gname_start, *gname; |
4578 int syn_id; | |
4579 int len; | |
154 | 4580 char *p; |
7 | 4581 int i; |
4582 int fidx; | |
4583 static struct flag | |
4584 { | |
4585 char *name; | |
154 | 4586 int argtype; |
4587 int flags; | |
4588 } flagtab[] = { {"cCoOnNtTaAiInNeEdD", 0, HL_CONTAINED}, | |
4589 {"oOnNeElLiInNeE", 0, HL_ONELINE}, | |
4590 {"kKeEeEpPeEnNdD", 0, HL_KEEPEND}, | |
4591 {"eExXtTeEnNdD", 0, HL_EXTEND}, | |
4592 {"eExXcClLuUdDeEnNlL", 0, HL_EXCLUDENL}, | |
4593 {"tTrRaAnNsSpPaArReEnNtT", 0, HL_TRANSP}, | |
4594 {"sSkKiIpPnNlL", 0, HL_SKIPNL}, | |
4595 {"sSkKiIpPwWhHiItTeE", 0, HL_SKIPWHITE}, | |
4596 {"sSkKiIpPeEmMpPtTyY", 0, HL_SKIPEMPTY}, | |
4597 {"gGrRoOuUpPhHeErReE", 0, HL_SYNC_HERE}, | |
4598 {"gGrRoOuUpPtThHeErReE", 0, HL_SYNC_THERE}, | |
4599 {"dDiIsSpPlLaAyY", 0, HL_DISPLAY}, | |
4600 {"fFoOlLdD", 0, HL_FOLD}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4601 {"cCoOnNcCeEaAlL", 0, HL_CONCEAL}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4602 {"cCoOnNcCeEaAlLeEnNdDsS", 0, HL_CONCEALENDS}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4603 {"cCcChHaArR", 11, 0}, |
154 | 4604 {"cCoOnNtTaAiInNsS", 1, 0}, |
4605 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, | |
4606 {"nNeExXtTgGrRoOuUpP", 3, 0}, | |
7 | 4607 }; |
154 | 4608 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; |
7 | 4609 |
4610 if (arg == NULL) /* already detected error */ | |
4611 return NULL; | |
4612 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4613 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4614 if (curwin->w_s->b_syn_conceal) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4615 opt->flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4616 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4617 |
7 | 4618 for (;;) |
4619 { | |
154 | 4620 /* |
4621 * This is used very often when a large number of keywords is defined. | |
4622 * Need to skip quickly when no option name is found. | |
4623 * Also avoid tolower(), it's slow. | |
4624 */ | |
4625 if (strchr(first_letters, *arg) == NULL) | |
4626 break; | |
7 | 4627 |
4628 for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; ) | |
4629 { | |
154 | 4630 p = flagtab[fidx].name; |
4631 for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) | |
4632 if (arg[len] != p[i] && arg[len] != p[i + 1]) | |
4633 break; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4634 if (p[i] == NUL && (VIM_ISWHITE(arg[len]) |
154 | 4635 || (flagtab[fidx].argtype > 0 |
4636 ? arg[len] == '=' | |
4637 : ends_excmd(arg[len])))) | |
7 | 4638 { |
154 | 4639 if (opt->keyword |
4640 && (flagtab[fidx].flags == HL_DISPLAY | |
4641 || flagtab[fidx].flags == HL_FOLD | |
4642 || flagtab[fidx].flags == HL_EXTEND)) | |
7 | 4643 /* treat "display", "fold" and "extend" as a keyword */ |
4644 fidx = -1; | |
4645 break; | |
4646 } | |
4647 } | |
154 | 4648 if (fidx < 0) /* no match found */ |
4649 break; | |
4650 | |
4651 if (flagtab[fidx].argtype == 1) | |
4652 { | |
4653 if (!opt->has_cont_list) | |
7 | 4654 { |
4655 EMSG(_("E395: contains argument not accepted here")); | |
4656 return NULL; | |
4657 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4658 if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) |
7 | 4659 return NULL; |
4660 } | |
154 | 4661 else if (flagtab[fidx].argtype == 2) |
4662 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4663 if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL) |
7 | 4664 return NULL; |
4665 } | |
154 | 4666 else if (flagtab[fidx].argtype == 3) |
4667 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4668 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) |
7 | 4669 return NULL; |
4670 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4671 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
|
4672 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4673 #ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4674 /* cchar=? */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4675 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4676 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4677 # ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4678 *conceal_char = mb_ptr2char(arg + 6); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4679 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4680 arg += mb_ptr2len(arg + 6) - 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4681 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4682 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4683 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4684 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4685 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4686 *conceal_char = arg[6]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4687 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4688 ; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4689 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4690 } |
2686 | 4691 #ifdef FEAT_CONCEAL |
4692 if (!vim_isprintc_strict(*conceal_char)) | |
4693 { | |
4694 EMSG(_("E844: invalid cchar value")); | |
4695 return NULL; | |
4696 } | |
4697 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4698 arg = skipwhite(arg + 7); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4699 } |
7 | 4700 else |
154 | 4701 { |
4702 opt->flags |= flagtab[fidx].flags; | |
4703 arg = skipwhite(arg + len); | |
4704 | |
4705 if (flagtab[fidx].flags == HL_SYNC_HERE | |
4706 || flagtab[fidx].flags == HL_SYNC_THERE) | |
4707 { | |
4708 if (opt->sync_idx == NULL) | |
4709 { | |
4710 EMSG(_("E393: group[t]here not accepted here")); | |
4711 return NULL; | |
4712 } | |
4713 gname_start = arg; | |
4714 arg = skiptowhite(arg); | |
4715 if (gname_start == arg) | |
4716 return NULL; | |
4717 gname = vim_strnsave(gname_start, (int)(arg - gname_start)); | |
4718 if (gname == NULL) | |
4719 return NULL; | |
4720 if (STRCMP(gname, "NONE") == 0) | |
4721 *opt->sync_idx = NONE_IDX; | |
4722 else | |
4723 { | |
4724 syn_id = syn_name2id(gname); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4725 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
|
4726 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
|
4727 && SYN_ITEMS(curwin->w_s)[i].sp_type == SPTYPE_START) |
154 | 4728 { |
4729 *opt->sync_idx = i; | |
4730 break; | |
4731 } | |
4732 if (i < 0) | |
4733 { | |
4734 EMSG2(_("E394: Didn't find region item for %s"), gname); | |
4735 vim_free(gname); | |
4736 return NULL; | |
4737 } | |
4738 } | |
4739 | |
4740 vim_free(gname); | |
4741 arg = skipwhite(arg); | |
4742 } | |
4743 #ifdef FEAT_FOLDING | |
4744 else if (flagtab[fidx].flags == HL_FOLD | |
4745 && foldmethodIsSyntax(curwin)) | |
4746 /* Need to update folds later. */ | |
4747 foldUpdateAll(curwin); | |
4748 #endif | |
4749 } | |
4750 } | |
7 | 4751 |
4752 return arg; | |
4753 } | |
4754 | |
4755 /* | |
4756 * Adjustments to syntax item when declared in a ":syn include"'d file. | |
4757 * Set the contained flag, and if the item is not already contained, add it | |
4758 * to the specified top-level group, if any. | |
4759 */ | |
4760 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4761 syn_incl_toplevel(int id, int *flagsp) |
7 | 4762 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4763 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) |
7 | 4764 return; |
4765 *flagsp |= HL_CONTAINED; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4766 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
7 | 4767 { |
4768 /* We have to alloc this, because syn_combine_list() will free it. */ | |
4769 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
|
4770 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; |
7 | 4771 |
4772 if (grp_list != NULL) | |
4773 { | |
4774 grp_list[0] = id; | |
4775 grp_list[1] = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4776 syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, &grp_list, |
7 | 4777 CLUSTER_ADD); |
4778 } | |
4779 } | |
4780 } | |
4781 | |
4782 /* | |
4783 * Handle ":syntax include [@{group-name}] filename" command. | |
4784 */ | |
4785 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4786 syn_cmd_include(exarg_T *eap, int syncing UNUSED) |
7 | 4787 { |
4788 char_u *arg = eap->arg; | |
4789 int sgl_id = 1; | |
4790 char_u *group_name_end; | |
4791 char_u *rest; | |
4792 char_u *errormsg = NULL; | |
4793 int prev_toplvl_grp; | |
4794 int prev_syn_inc_tag; | |
4795 int source = FALSE; | |
4796 | |
4797 eap->nextcmd = find_nextcmd(arg); | |
4798 if (eap->skip) | |
4799 return; | |
4800 | |
4801 if (arg[0] == '@') | |
4802 { | |
4803 ++arg; | |
4804 rest = get_group_name(arg, &group_name_end); | |
4805 if (rest == NULL) | |
4806 { | |
4807 EMSG((char_u *)_("E397: Filename required")); | |
4808 return; | |
4809 } | |
4810 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
2743 | 4811 if (sgl_id == 0) |
4812 return; | |
7 | 4813 /* separate_nextcmd() and expand_filename() depend on this */ |
4814 eap->arg = rest; | |
4815 } | |
4816 | |
4817 /* | |
4818 * Everything that's left, up to the next command, should be the | |
4819 * filename to include. | |
4820 */ | |
4821 eap->argt |= (XFILE | NOSPC); | |
4822 separate_nextcmd(eap); | |
4823 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) | |
4824 { | |
4825 /* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the | |
4826 * file. Need to expand the file name first. In other cases | |
4827 * ":runtime!" is used. */ | |
4828 source = TRUE; | |
4829 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) | |
4830 { | |
4831 if (errormsg != NULL) | |
4832 EMSG(errormsg); | |
4833 return; | |
4834 } | |
4835 } | |
4836 | |
4837 /* | |
4838 * Save and restore the existing top-level grouplist id and ":syn | |
4839 * include" tag around the actual inclusion. | |
4840 */ | |
2743 | 4841 if (running_syn_inc_tag >= MAX_SYN_INC_TAG) |
4842 { | |
4843 EMSG((char_u *)_("E847: Too many syntax includes")); | |
4844 return; | |
4845 } | |
7 | 4846 prev_syn_inc_tag = current_syn_inc_tag; |
4847 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
|
4848 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
|
4849 curwin->w_s->b_syn_topgrp = sgl_id; |
1299 | 4850 if (source ? do_source(eap->arg, FALSE, DOSO_NONE) == FAIL |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
4851 : source_runtime(eap->arg, DIP_ALL) == FAIL) |
7 | 4852 EMSG2(_(e_notopen), eap->arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4853 curwin->w_s->b_syn_topgrp = prev_toplvl_grp; |
7 | 4854 current_syn_inc_tag = prev_syn_inc_tag; |
4855 } | |
4856 | |
4857 /* | |
4858 * Handle ":syntax keyword {group-name} [{option}] keyword .." command. | |
4859 */ | |
4860 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4861 syn_cmd_keyword(exarg_T *eap, int syncing UNUSED) |
7 | 4862 { |
4863 char_u *arg = eap->arg; | |
4864 char_u *group_name_end; | |
4865 int syn_id; | |
4866 char_u *rest; | |
2743 | 4867 char_u *keyword_copy = NULL; |
7 | 4868 char_u *p; |
154 | 4869 char_u *kw; |
4870 syn_opt_arg_T syn_opt_arg; | |
4871 int cnt; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4872 int conceal_char = NUL; |
7 | 4873 |
4874 rest = get_group_name(arg, &group_name_end); | |
4875 | |
4876 if (rest != NULL) | |
4877 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4878 if (eap->skip) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4879 syn_id = -1; |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4880 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4881 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); |
2743 | 4882 if (syn_id != 0) |
4883 /* allocate a buffer, for removing backslashes in the keyword */ | |
4884 keyword_copy = alloc((unsigned)STRLEN(rest) + 1); | |
7 | 4885 if (keyword_copy != NULL) |
4886 { | |
154 | 4887 syn_opt_arg.flags = 0; |
4888 syn_opt_arg.keyword = TRUE; | |
4889 syn_opt_arg.sync_idx = NULL; | |
4890 syn_opt_arg.has_cont_list = FALSE; | |
4891 syn_opt_arg.cont_in_list = NULL; | |
4892 syn_opt_arg.next_list = NULL; | |
4893 | |
7 | 4894 /* |
4895 * The options given apply to ALL keywords, so all options must be | |
4896 * found before keywords can be created. | |
154 | 4897 * 1: collect the options and copy the keywords to keyword_copy. |
7 | 4898 */ |
154 | 4899 cnt = 0; |
4900 p = keyword_copy; | |
4901 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) | |
7 | 4902 { |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4903 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4904 eap->skip); |
154 | 4905 if (rest == NULL || ends_excmd(*rest)) |
4906 break; | |
4907 /* Copy the keyword, removing backslashes, and add a NUL. */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4908 while (*rest != NUL && !VIM_ISWHITE(*rest)) |
154 | 4909 { |
4910 if (*rest == '\\' && rest[1] != NUL) | |
4911 ++rest; | |
4912 *p++ = *rest++; | |
4913 } | |
4914 *p++ = NUL; | |
4915 ++cnt; | |
4916 } | |
4917 | |
4918 if (!eap->skip) | |
4919 { | |
4920 /* Adjust flags for use of ":syn include". */ | |
4921 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); | |
4922 | |
7 | 4923 /* |
154 | 4924 * 2: Add an entry for each keyword. |
7 | 4925 */ |
154 | 4926 for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) |
7 | 4927 { |
154 | 4928 for (p = vim_strchr(kw, '['); ; ) |
7 | 4929 { |
154 | 4930 if (p != NULL) |
4931 *p = NUL; | |
4932 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
|
4933 syn_opt_arg.cont_in_list, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4934 syn_opt_arg.next_list, conceal_char); |
168 | 4935 if (p == NULL) |
4936 break; | |
4937 if (p[1] == NUL) | |
4938 { | |
838 | 4939 EMSG2(_("E789: Missing ']': %s"), kw); |
7017 | 4940 goto error; |
168 | 4941 } |
4942 if (p[1] == ']') | |
4943 { | |
7017 | 4944 if (p[2] != NUL) |
4945 { | |
4946 EMSG3(_("E890: trailing char after ']': %s]%s"), | |
4947 kw, &p[2]); | |
4948 goto error; | |
4949 } | |
168 | 4950 kw = p + 1; /* skip over the "]" */ |
4951 break; | |
4952 } | |
154 | 4953 #ifdef FEAT_MBYTE |
4954 if (has_mbyte) | |
7 | 4955 { |
474 | 4956 int l = (*mb_ptr2len)(p + 1); |
154 | 4957 |
4958 mch_memmove(p, p + 1, l); | |
4959 p += l; | |
4960 } | |
4961 else | |
7 | 4962 #endif |
154 | 4963 { |
4964 p[0] = p[1]; | |
4965 ++p; | |
7 | 4966 } |
4967 } | |
4968 } | |
4969 } | |
7017 | 4970 error: |
7 | 4971 vim_free(keyword_copy); |
168 | 4972 vim_free(syn_opt_arg.cont_in_list); |
4973 vim_free(syn_opt_arg.next_list); | |
7 | 4974 } |
4975 } | |
4976 | |
4977 if (rest != NULL) | |
4978 eap->nextcmd = check_nextcmd(rest); | |
4979 else | |
4980 EMSG2(_(e_invarg2), arg); | |
4981 | |
745 | 4982 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4983 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 4984 } |
4985 | |
4986 /* | |
4987 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". | |
4988 * | |
4989 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." | |
4990 */ | |
4991 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4992 syn_cmd_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4993 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4994 int syncing) /* TRUE for ":syntax sync match .. " */ |
7 | 4995 { |
4996 char_u *arg = eap->arg; | |
4997 char_u *group_name_end; | |
4998 char_u *rest; | |
4999 synpat_T item; /* the item found in the line */ | |
5000 int syn_id; | |
5001 int idx; | |
154 | 5002 syn_opt_arg_T syn_opt_arg; |
7 | 5003 int sync_idx = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5004 int conceal_char = NUL; |
7 | 5005 |
5006 /* Isolate the group name, check for validity */ | |
5007 rest = get_group_name(arg, &group_name_end); | |
5008 | |
5009 /* Get options before the pattern */ | |
154 | 5010 syn_opt_arg.flags = 0; |
5011 syn_opt_arg.keyword = FALSE; | |
5012 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; | |
5013 syn_opt_arg.has_cont_list = TRUE; | |
5014 syn_opt_arg.cont_list = NULL; | |
5015 syn_opt_arg.cont_in_list = NULL; | |
5016 syn_opt_arg.next_list = NULL; | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5017 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5018 |
5019 /* get the pattern. */ | |
5020 init_syn_patterns(); | |
5021 vim_memset(&item, 0, sizeof(item)); | |
5022 rest = get_syn_pattern(rest, &item); | |
154 | 5023 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
5024 syn_opt_arg.flags |= HL_HAS_EOL; | |
7 | 5025 |
5026 /* Get options after the pattern */ | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5027 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5028 |
5029 if (rest != NULL) /* all arguments are valid */ | |
5030 { | |
5031 /* | |
5032 * Check for trailing command and illegal trailing arguments. | |
5033 */ | |
5034 eap->nextcmd = check_nextcmd(rest); | |
5035 if (!ends_excmd(*rest) || eap->skip) | |
5036 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5037 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL |
7 | 5038 && (syn_id = syn_check_group(arg, |
5039 (int)(group_name_end - arg))) != 0) | |
5040 { | |
154 | 5041 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5042 /* |
5043 * Store the pattern in the syn_items list | |
5044 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5045 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
|
5046 SYN_ITEMS(curwin->w_s)[idx] = item; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5047 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
|
5048 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
|
5049 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
|
5050 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
|
5051 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
|
5052 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
|
5053 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
|
5054 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5055 syn_opt_arg.cont_in_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5056 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
5057 SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5058 #endif |
154 | 5059 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
|
5060 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5061 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
|
5062 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5063 |
5064 /* remember that we found a match for syncing on */ | |
154 | 5065 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
|
5066 curwin->w_s->b_syn_sync_flags |= SF_MATCH; |
7 | 5067 #ifdef FEAT_FOLDING |
154 | 5068 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
|
5069 ++curwin->w_s->b_syn_folditems; |
7 | 5070 #endif |
5071 | |
745 | 5072 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5073 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5074 return; /* don't free the progs and patterns now */ |
5075 } | |
5076 } | |
5077 | |
5078 /* | |
5079 * Something failed, free the allocated memory. | |
5080 */ | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5081 vim_regfree(item.sp_prog); |
7 | 5082 vim_free(item.sp_pattern); |
154 | 5083 vim_free(syn_opt_arg.cont_list); |
5084 vim_free(syn_opt_arg.cont_in_list); | |
5085 vim_free(syn_opt_arg.next_list); | |
7 | 5086 |
5087 if (rest == NULL) | |
5088 EMSG2(_(e_invarg2), arg); | |
5089 } | |
5090 | |
5091 /* | |
5092 * Handle ":syntax region {group-name} [matchgroup={group-name}] | |
5093 * start {start} .. [skip {skip}] end {end} .. [{options}]". | |
5094 */ | |
5095 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5096 syn_cmd_region( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5097 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5098 int syncing) /* TRUE for ":syntax sync region .." */ |
7 | 5099 { |
5100 char_u *arg = eap->arg; | |
5101 char_u *group_name_end; | |
5102 char_u *rest; /* next arg, NULL on error */ | |
5103 char_u *key_end; | |
5104 char_u *key = NULL; | |
5105 char_u *p; | |
5106 int item; | |
5107 #define ITEM_START 0 | |
5108 #define ITEM_SKIP 1 | |
5109 #define ITEM_END 2 | |
5110 #define ITEM_MATCHGROUP 3 | |
5111 struct pat_ptr | |
5112 { | |
5113 synpat_T *pp_synp; /* pointer to syn_pattern */ | |
5114 int pp_matchgroup_id; /* matchgroup ID */ | |
5115 struct pat_ptr *pp_next; /* pointer to next pat_ptr */ | |
5116 } *(pat_ptrs[3]); | |
5117 /* patterns found in the line */ | |
5118 struct pat_ptr *ppp; | |
5119 struct pat_ptr *ppp_next; | |
5120 int pat_count = 0; /* nr of syn_patterns found */ | |
5121 int syn_id; | |
5122 int matchgroup_id = 0; | |
5123 int not_enough = FALSE; /* not enough arguments */ | |
5124 int illegal = FALSE; /* illegal arguments */ | |
5125 int success = FALSE; | |
5126 int idx; | |
154 | 5127 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
|
5128 int conceal_char = NUL; |
7 | 5129 |
5130 /* Isolate the group name, check for validity */ | |
5131 rest = get_group_name(arg, &group_name_end); | |
5132 | |
5133 pat_ptrs[0] = NULL; | |
5134 pat_ptrs[1] = NULL; | |
5135 pat_ptrs[2] = NULL; | |
5136 | |
5137 init_syn_patterns(); | |
5138 | |
154 | 5139 syn_opt_arg.flags = 0; |
5140 syn_opt_arg.keyword = FALSE; | |
5141 syn_opt_arg.sync_idx = NULL; | |
5142 syn_opt_arg.has_cont_list = TRUE; | |
5143 syn_opt_arg.cont_list = NULL; | |
5144 syn_opt_arg.cont_in_list = NULL; | |
5145 syn_opt_arg.next_list = NULL; | |
5146 | |
7 | 5147 /* |
5148 * get the options, patterns and matchgroup. | |
5149 */ | |
5150 while (rest != NULL && !ends_excmd(*rest)) | |
5151 { | |
5152 /* Check for option arguments */ | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5153 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5154 if (rest == NULL || ends_excmd(*rest)) |
5155 break; | |
5156 | |
5157 /* must be a pattern or matchgroup then */ | |
5158 key_end = rest; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5159 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') |
7 | 5160 ++key_end; |
5161 vim_free(key); | |
5162 key = vim_strnsave_up(rest, (int)(key_end - rest)); | |
5163 if (key == NULL) /* out of memory */ | |
5164 { | |
5165 rest = NULL; | |
5166 break; | |
5167 } | |
5168 if (STRCMP(key, "MATCHGROUP") == 0) | |
5169 item = ITEM_MATCHGROUP; | |
5170 else if (STRCMP(key, "START") == 0) | |
5171 item = ITEM_START; | |
5172 else if (STRCMP(key, "END") == 0) | |
5173 item = ITEM_END; | |
5174 else if (STRCMP(key, "SKIP") == 0) | |
5175 { | |
5176 if (pat_ptrs[ITEM_SKIP] != NULL) /* one skip pattern allowed */ | |
5177 { | |
5178 illegal = TRUE; | |
5179 break; | |
5180 } | |
5181 item = ITEM_SKIP; | |
5182 } | |
5183 else | |
5184 break; | |
5185 rest = skipwhite(key_end); | |
5186 if (*rest != '=') | |
5187 { | |
5188 rest = NULL; | |
5189 EMSG2(_("E398: Missing '=': %s"), arg); | |
5190 break; | |
5191 } | |
5192 rest = skipwhite(rest + 1); | |
5193 if (*rest == NUL) | |
5194 { | |
5195 not_enough = TRUE; | |
5196 break; | |
5197 } | |
5198 | |
5199 if (item == ITEM_MATCHGROUP) | |
5200 { | |
5201 p = skiptowhite(rest); | |
5202 if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) | |
5203 matchgroup_id = 0; | |
5204 else | |
5205 { | |
5206 matchgroup_id = syn_check_group(rest, (int)(p - rest)); | |
5207 if (matchgroup_id == 0) | |
5208 { | |
5209 illegal = TRUE; | |
5210 break; | |
5211 } | |
5212 } | |
5213 rest = skipwhite(p); | |
5214 } | |
5215 else | |
5216 { | |
5217 /* | |
5218 * Allocate room for a syn_pattern, and link it in the list of | |
5219 * syn_patterns for this item, at the start (because the list is | |
5220 * used from end to start). | |
5221 */ | |
5222 ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr)); | |
5223 if (ppp == NULL) | |
5224 { | |
5225 rest = NULL; | |
5226 break; | |
5227 } | |
5228 ppp->pp_next = pat_ptrs[item]; | |
5229 pat_ptrs[item] = ppp; | |
5230 ppp->pp_synp = (synpat_T *)alloc_clear((unsigned)sizeof(synpat_T)); | |
5231 if (ppp->pp_synp == NULL) | |
5232 { | |
5233 rest = NULL; | |
5234 break; | |
5235 } | |
5236 | |
5237 /* | |
5238 * Get the syntax pattern and the following offset(s). | |
5239 */ | |
5240 /* Enable the appropriate \z specials. */ | |
5241 if (item == ITEM_START) | |
5242 reg_do_extmatch = REX_SET; | |
5243 else if (item == ITEM_SKIP || item == ITEM_END) | |
5244 reg_do_extmatch = REX_USE; | |
5245 rest = get_syn_pattern(rest, ppp->pp_synp); | |
5246 reg_do_extmatch = 0; | |
5247 if (item == ITEM_END && vim_regcomp_had_eol() | |
154 | 5248 && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
7 | 5249 ppp->pp_synp->sp_flags |= HL_HAS_EOL; |
5250 ppp->pp_matchgroup_id = matchgroup_id; | |
5251 ++pat_count; | |
5252 } | |
5253 } | |
5254 vim_free(key); | |
5255 if (illegal || not_enough) | |
5256 rest = NULL; | |
5257 | |
5258 /* | |
5259 * Must have a "start" and "end" pattern. | |
5260 */ | |
5261 if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || | |
5262 pat_ptrs[ITEM_END] == NULL)) | |
5263 { | |
5264 not_enough = TRUE; | |
5265 rest = NULL; | |
5266 } | |
5267 | |
5268 if (rest != NULL) | |
5269 { | |
5270 /* | |
5271 * Check for trailing garbage or command. | |
5272 * If OK, add the item. | |
5273 */ | |
5274 eap->nextcmd = check_nextcmd(rest); | |
5275 if (!ends_excmd(*rest) || eap->skip) | |
5276 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5277 else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL |
7 | 5278 && (syn_id = syn_check_group(arg, |
5279 (int)(group_name_end - arg))) != 0) | |
5280 { | |
154 | 5281 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5282 /* |
5283 * Store the start/skip/end in the syn_items list | |
5284 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5285 idx = curwin->w_s->b_syn_patterns.ga_len; |
7 | 5286 for (item = ITEM_START; item <= ITEM_END; ++item) |
5287 { | |
5288 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) | |
5289 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5290 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
|
5291 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
|
5292 SYN_ITEMS(curwin->w_s)[idx].sp_type = |
7 | 5293 (item == ITEM_START) ? SPTYPE_START : |
5294 (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
|
5295 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
|
5296 SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; |
2743 | 5297 SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = |
5298 current_syn_inc_tag; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5299 SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = |
7 | 5300 ppp->pp_matchgroup_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5301 #ifdef FEAT_CONCEAL |
2425
b5ee68272ae5
Fix: concealed regions didn't get redrawn correctly when moving the cursor
Bram Moolenaar <bram@vim.org>
parents:
2418
diff
changeset
|
5302 SYN_ITEMS(curwin->w_s)[idx].sp_cchar = conceal_char; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5303 #endif |
7 | 5304 if (item == ITEM_START) |
5305 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5306 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = |
154 | 5307 syn_opt_arg.cont_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5308 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5309 syn_opt_arg.cont_in_list; |
5310 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
|
5311 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5312 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = |
154 | 5313 syn_opt_arg.next_list; |
7 | 5314 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5315 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5316 ++idx; |
5317 #ifdef FEAT_FOLDING | |
154 | 5318 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
|
5319 ++curwin->w_s->b_syn_folditems; |
7 | 5320 #endif |
5321 } | |
5322 } | |
5323 | |
745 | 5324 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5325 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5326 success = TRUE; /* don't free the progs and patterns now */ |
5327 } | |
5328 } | |
5329 | |
5330 /* | |
5331 * Free the allocated memory. | |
5332 */ | |
5333 for (item = ITEM_START; item <= ITEM_END; ++item) | |
5334 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) | |
5335 { | |
5336 if (!success) | |
5337 { | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5338 vim_regfree(ppp->pp_synp->sp_prog); |
7 | 5339 vim_free(ppp->pp_synp->sp_pattern); |
5340 } | |
5341 vim_free(ppp->pp_synp); | |
5342 ppp_next = ppp->pp_next; | |
5343 vim_free(ppp); | |
5344 } | |
5345 | |
5346 if (!success) | |
5347 { | |
154 | 5348 vim_free(syn_opt_arg.cont_list); |
5349 vim_free(syn_opt_arg.cont_in_list); | |
5350 vim_free(syn_opt_arg.next_list); | |
7 | 5351 if (not_enough) |
5352 EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); | |
5353 else if (illegal || rest == NULL) | |
5354 EMSG2(_(e_invarg2), arg); | |
5355 } | |
5356 } | |
5357 | |
5358 /* | |
5359 * A simple syntax group ID comparison function suitable for use in qsort() | |
5360 */ | |
5361 static int | |
5362 #ifdef __BORLANDC__ | |
5363 _RTLENTRYF | |
5364 #endif | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5365 syn_compare_stub(const void *v1, const void *v2) |
7 | 5366 { |
5367 const short *s1 = v1; | |
5368 const short *s2 = v2; | |
5369 | |
5370 return (*s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0); | |
5371 } | |
5372 | |
5373 /* | |
5374 * Combines lists of syntax clusters. | |
5375 * *clstr1 and *clstr2 must both be allocated memory; they will be consumed. | |
5376 */ | |
5377 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5378 syn_combine_list(short **clstr1, short **clstr2, int list_op) |
7 | 5379 { |
5380 int count1 = 0; | |
5381 int count2 = 0; | |
5382 short *g1; | |
5383 short *g2; | |
5384 short *clstr = NULL; | |
5385 int count; | |
5386 int round; | |
5387 | |
5388 /* | |
5389 * Handle degenerate cases. | |
5390 */ | |
5391 if (*clstr2 == NULL) | |
5392 return; | |
5393 if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) | |
5394 { | |
5395 if (list_op == CLUSTER_REPLACE) | |
5396 vim_free(*clstr1); | |
5397 if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) | |
5398 *clstr1 = *clstr2; | |
5399 else | |
5400 vim_free(*clstr2); | |
5401 return; | |
5402 } | |
5403 | |
5404 for (g1 = *clstr1; *g1; g1++) | |
5405 ++count1; | |
5406 for (g2 = *clstr2; *g2; g2++) | |
5407 ++count2; | |
5408 | |
5409 /* | |
5410 * For speed purposes, sort both lists. | |
5411 */ | |
5412 qsort(*clstr1, (size_t)count1, sizeof(short), syn_compare_stub); | |
5413 qsort(*clstr2, (size_t)count2, sizeof(short), syn_compare_stub); | |
5414 | |
5415 /* | |
5416 * We proceed in two passes; in round 1, we count the elements to place | |
5417 * in the new list, and in round 2, we allocate and populate the new | |
5418 * list. For speed, we use a mergesort-like method, adding the smaller | |
5419 * of the current elements in each list to the new list. | |
5420 */ | |
5421 for (round = 1; round <= 2; round++) | |
5422 { | |
5423 g1 = *clstr1; | |
5424 g2 = *clstr2; | |
5425 count = 0; | |
5426 | |
5427 /* | |
5428 * First, loop through the lists until one of them is empty. | |
5429 */ | |
5430 while (*g1 && *g2) | |
5431 { | |
5432 /* | |
5433 * We always want to add from the first list. | |
5434 */ | |
5435 if (*g1 < *g2) | |
5436 { | |
5437 if (round == 2) | |
5438 clstr[count] = *g1; | |
5439 count++; | |
5440 g1++; | |
5441 continue; | |
5442 } | |
5443 /* | |
5444 * We only want to add from the second list if we're adding the | |
5445 * lists. | |
5446 */ | |
5447 if (list_op == CLUSTER_ADD) | |
5448 { | |
5449 if (round == 2) | |
5450 clstr[count] = *g2; | |
5451 count++; | |
5452 } | |
5453 if (*g1 == *g2) | |
5454 g1++; | |
5455 g2++; | |
5456 } | |
5457 | |
5458 /* | |
5459 * Now add the leftovers from whichever list didn't get finished | |
5460 * first. As before, we only want to add from the second list if | |
5461 * we're adding the lists. | |
5462 */ | |
5463 for (; *g1; g1++, count++) | |
5464 if (round == 2) | |
5465 clstr[count] = *g1; | |
5466 if (list_op == CLUSTER_ADD) | |
5467 for (; *g2; g2++, count++) | |
5468 if (round == 2) | |
5469 clstr[count] = *g2; | |
5470 | |
5471 if (round == 1) | |
5472 { | |
5473 /* | |
5474 * If the group ended up empty, we don't need to allocate any | |
5475 * space for it. | |
5476 */ | |
5477 if (count == 0) | |
5478 { | |
5479 clstr = NULL; | |
5480 break; | |
5481 } | |
5482 clstr = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
5483 if (clstr == NULL) | |
5484 break; | |
5485 clstr[count] = 0; | |
5486 } | |
5487 } | |
5488 | |
5489 /* | |
5490 * Finally, put the new list in place. | |
5491 */ | |
5492 vim_free(*clstr1); | |
5493 vim_free(*clstr2); | |
5494 *clstr1 = clstr; | |
5495 } | |
5496 | |
5497 /* | |
5498 * Lookup a syntax cluster name and return it's ID. | |
5499 * If it is not found, 0 is returned. | |
5500 */ | |
5501 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5502 syn_scl_name2id(char_u *name) |
7 | 5503 { |
5504 int i; | |
5505 char_u *name_u; | |
5506 | |
5507 /* Avoid using stricmp() too much, it's slow on some systems */ | |
5508 name_u = vim_strsave_up(name); | |
5509 if (name_u == NULL) | |
5510 return 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5511 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
|
5512 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
|
5513 && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) |
7 | 5514 break; |
5515 vim_free(name_u); | |
5516 return (i < 0 ? 0 : i + SYNID_CLUSTER); | |
5517 } | |
5518 | |
5519 /* | |
5520 * Like syn_scl_name2id(), but take a pointer + length argument. | |
5521 */ | |
5522 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5523 syn_scl_namen2id(char_u *linep, int len) |
7 | 5524 { |
5525 char_u *name; | |
5526 int id = 0; | |
5527 | |
5528 name = vim_strnsave(linep, len); | |
5529 if (name != NULL) | |
5530 { | |
5531 id = syn_scl_name2id(name); | |
5532 vim_free(name); | |
5533 } | |
5534 return id; | |
5535 } | |
5536 | |
5537 /* | |
5538 * Find syntax cluster name in the table and return it's ID. | |
5539 * The argument is a pointer to the name and the length of the name. | |
5540 * If it doesn't exist yet, a new entry is created. | |
5541 * Return 0 for failure. | |
5542 */ | |
5543 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5544 syn_check_cluster(char_u *pp, int len) |
7 | 5545 { |
5546 int id; | |
5547 char_u *name; | |
5548 | |
5549 name = vim_strnsave(pp, len); | |
5550 if (name == NULL) | |
5551 return 0; | |
5552 | |
5553 id = syn_scl_name2id(name); | |
5554 if (id == 0) /* doesn't exist yet */ | |
5555 id = syn_add_cluster(name); | |
5556 else | |
5557 vim_free(name); | |
5558 return id; | |
5559 } | |
5560 | |
5561 /* | |
5562 * Add new syntax cluster and return it's ID. | |
5563 * "name" must be an allocated string, it will be consumed. | |
5564 * Return 0 for failure. | |
5565 */ | |
5566 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5567 syn_add_cluster(char_u *name) |
221 | 5568 { |
5569 int len; | |
7 | 5570 |
5571 /* | |
5572 * First call for this growarray: init growing array. | |
5573 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5574 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
|
5575 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5576 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
|
5577 curwin->w_s->b_syn_clusters.ga_growsize = 10; |
7 | 5578 } |
5579 | |
2743 | 5580 len = curwin->w_s->b_syn_clusters.ga_len; |
5581 if (len >= MAX_CLUSTER_ID) | |
5582 { | |
5583 EMSG((char_u *)_("E848: Too many syntax clusters")); | |
5584 vim_free(name); | |
5585 return 0; | |
5586 } | |
5587 | |
7 | 5588 /* |
5589 * Make room for at least one other cluster entry. | |
5590 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5591 if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) |
7 | 5592 { |
5593 vim_free(name); | |
5594 return 0; | |
5595 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5596 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5597 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
|
5598 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
|
5599 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
|
5600 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
|
5601 ++curwin->w_s->b_syn_clusters.ga_len; |
7 | 5602 |
221 | 5603 if (STRICMP(name, "Spell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5604 curwin->w_s->b_spell_cluster_id = len + SYNID_CLUSTER; |
227 | 5605 if (STRICMP(name, "NoSpell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5606 curwin->w_s->b_nospell_cluster_id = len + SYNID_CLUSTER; |
221 | 5607 |
7 | 5608 return len + SYNID_CLUSTER; |
5609 } | |
5610 | |
5611 /* | |
5612 * Handle ":syntax cluster {cluster-name} [contains={groupname},..] | |
5613 * [add={groupname},..] [remove={groupname},..]". | |
5614 */ | |
5615 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5616 syn_cmd_cluster(exarg_T *eap, int syncing UNUSED) |
7 | 5617 { |
5618 char_u *arg = eap->arg; | |
5619 char_u *group_name_end; | |
5620 char_u *rest; | |
5621 int scl_id; | |
5622 short *clstr_list; | |
5623 int got_clstr = FALSE; | |
5624 int opt_len; | |
5625 int list_op; | |
5626 | |
5627 eap->nextcmd = find_nextcmd(arg); | |
5628 if (eap->skip) | |
5629 return; | |
5630 | |
5631 rest = get_group_name(arg, &group_name_end); | |
5632 | |
5633 if (rest != NULL) | |
5634 { | |
2743 | 5635 scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); |
5636 if (scl_id == 0) | |
5637 return; | |
5638 scl_id -= SYNID_CLUSTER; | |
7 | 5639 |
5640 for (;;) | |
5641 { | |
5642 if (STRNICMP(rest, "add", 3) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5643 && (VIM_ISWHITE(rest[3]) || rest[3] == '=')) |
7 | 5644 { |
5645 opt_len = 3; | |
5646 list_op = CLUSTER_ADD; | |
5647 } | |
5648 else if (STRNICMP(rest, "remove", 6) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5649 && (VIM_ISWHITE(rest[6]) || rest[6] == '=')) |
7 | 5650 { |
5651 opt_len = 6; | |
5652 list_op = CLUSTER_SUBTRACT; | |
5653 } | |
5654 else if (STRNICMP(rest, "contains", 8) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5655 && (VIM_ISWHITE(rest[8]) || rest[8] == '=')) |
7 | 5656 { |
5657 opt_len = 8; | |
5658 list_op = CLUSTER_REPLACE; | |
5659 } | |
5660 else | |
5661 break; | |
5662 | |
5663 clstr_list = NULL; | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5664 if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) |
7 | 5665 { |
5666 EMSG2(_(e_invarg2), rest); | |
5667 break; | |
5668 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5669 if (scl_id >= 0) |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5670 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, |
7 | 5671 &clstr_list, list_op); |
10648
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5672 else |
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5673 vim_free(clstr_list); |
7 | 5674 got_clstr = TRUE; |
5675 } | |
5676 | |
5677 if (got_clstr) | |
5678 { | |
745 | 5679 redraw_curbuf_later(SOME_VALID); |
2743 | 5680 syn_stack_free_all(curwin->w_s); /* Need to recompute all. */ |
7 | 5681 } |
5682 } | |
5683 | |
5684 if (!got_clstr) | |
5685 EMSG(_("E400: No cluster specified")); | |
5686 if (rest == NULL || !ends_excmd(*rest)) | |
5687 EMSG2(_(e_invarg2), arg); | |
5688 } | |
5689 | |
5690 /* | |
5691 * On first call for current buffer: Init growing array. | |
5692 */ | |
5693 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5694 init_syn_patterns(void) |
7 | 5695 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5696 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
|
5697 curwin->w_s->b_syn_patterns.ga_growsize = 10; |
7 | 5698 } |
5699 | |
5700 /* | |
5701 * Get one pattern for a ":syntax match" or ":syntax region" command. | |
5702 * Stores the pattern and program in a synpat_T. | |
5703 * Returns a pointer to the next argument, or NULL in case of an error. | |
5704 */ | |
5705 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5706 get_syn_pattern(char_u *arg, synpat_T *ci) |
7 | 5707 { |
5708 char_u *end; | |
5709 int *p; | |
5710 int idx; | |
5711 char_u *cpo_save; | |
5712 | |
5713 /* need at least three chars */ | |
6993 | 5714 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) |
7 | 5715 return NULL; |
5716 | |
5717 end = skip_regexp(arg + 1, *arg, TRUE, NULL); | |
5718 if (*end != *arg) /* end delimiter not found */ | |
5719 { | |
5720 EMSG2(_("E401: Pattern delimiter not found: %s"), arg); | |
5721 return NULL; | |
5722 } | |
5723 /* store the pattern and compiled regexp program */ | |
5724 if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL) | |
5725 return NULL; | |
5726 | |
5727 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5728 cpo_save = p_cpo; | |
5729 p_cpo = (char_u *)""; | |
5730 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); | |
5731 p_cpo = cpo_save; | |
5732 | |
5733 if (ci->sp_prog == NULL) | |
5734 return NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5735 ci->sp_ic = curwin->w_s->b_syn_ic; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5736 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5737 syn_clear_time(&ci->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5738 #endif |
7 | 5739 |
5740 /* | |
5741 * Check for a match, highlight or region offset. | |
5742 */ | |
5743 ++end; | |
5744 do | |
5745 { | |
5746 for (idx = SPO_COUNT; --idx >= 0; ) | |
5747 if (STRNCMP(end, spo_name_tab[idx], 3) == 0) | |
5748 break; | |
5749 if (idx >= 0) | |
5750 { | |
5751 p = &(ci->sp_offsets[idx]); | |
5752 if (idx != SPO_LC_OFF) | |
5753 switch (end[3]) | |
5754 { | |
5755 case 's': break; | |
5756 case 'b': break; | |
5757 case 'e': idx += SPO_COUNT; break; | |
5758 default: idx = -1; break; | |
5759 } | |
5760 if (idx >= 0) | |
5761 { | |
5762 ci->sp_off_flags |= (1 << idx); | |
5763 if (idx == SPO_LC_OFF) /* lc=99 */ | |
5764 { | |
5765 end += 3; | |
5766 *p = getdigits(&end); | |
5767 | |
5768 /* "lc=" offset automatically sets "ms=" offset */ | |
5769 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) | |
5770 { | |
5771 ci->sp_off_flags |= (1 << SPO_MS_OFF); | |
5772 ci->sp_offsets[SPO_MS_OFF] = *p; | |
5773 } | |
5774 } | |
5775 else /* yy=x+99 */ | |
5776 { | |
5777 end += 4; | |
5778 if (*end == '+') | |
5779 { | |
5780 ++end; | |
5781 *p = getdigits(&end); /* positive offset */ | |
5782 } | |
5783 else if (*end == '-') | |
5784 { | |
5785 ++end; | |
5786 *p = -getdigits(&end); /* negative offset */ | |
5787 } | |
5788 } | |
5789 if (*end != ',') | |
5790 break; | |
5791 ++end; | |
5792 } | |
5793 } | |
5794 } while (idx >= 0); | |
5795 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5796 if (!ends_excmd(*end) && !VIM_ISWHITE(*end)) |
7 | 5797 { |
5798 EMSG2(_("E402: Garbage after pattern: %s"), arg); | |
5799 return NULL; | |
5800 } | |
5801 return skipwhite(end); | |
5802 } | |
5803 | |
5804 /* | |
5805 * Handle ":syntax sync .." command. | |
5806 */ | |
5807 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5808 syn_cmd_sync(exarg_T *eap, int syncing UNUSED) |
7 | 5809 { |
5810 char_u *arg_start = eap->arg; | |
5811 char_u *arg_end; | |
5812 char_u *key = NULL; | |
5813 char_u *next_arg; | |
5814 int illegal = FALSE; | |
5815 int finished = FALSE; | |
5816 long n; | |
5817 char_u *cpo_save; | |
5818 | |
5819 if (ends_excmd(*arg_start)) | |
5820 { | |
5821 syn_cmd_list(eap, TRUE); | |
5822 return; | |
5823 } | |
5824 | |
5825 while (!ends_excmd(*arg_start)) | |
5826 { | |
5827 arg_end = skiptowhite(arg_start); | |
5828 next_arg = skipwhite(arg_end); | |
5829 vim_free(key); | |
5830 key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); | |
5831 if (STRCMP(key, "CCOMMENT") == 0) | |
5832 { | |
5833 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5834 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; |
7 | 5835 if (!ends_excmd(*next_arg)) |
5836 { | |
5837 arg_end = skiptowhite(next_arg); | |
5838 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5839 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, |
7 | 5840 (int)(arg_end - next_arg)); |
5841 next_arg = skipwhite(arg_end); | |
5842 } | |
5843 else if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5844 curwin->w_s->b_syn_sync_id = syn_name2id((char_u *)"Comment"); |
7 | 5845 } |
5846 else if ( STRNCMP(key, "LINES", 5) == 0 | |
5847 || STRNCMP(key, "MINLINES", 8) == 0 | |
5848 || STRNCMP(key, "MAXLINES", 8) == 0 | |
5849 || STRNCMP(key, "LINEBREAKS", 10) == 0) | |
5850 { | |
5851 if (key[4] == 'S') | |
5852 arg_end = key + 6; | |
5853 else if (key[0] == 'L') | |
5854 arg_end = key + 11; | |
5855 else | |
5856 arg_end = key + 9; | |
5857 if (arg_end[-1] != '=' || !VIM_ISDIGIT(*arg_end)) | |
5858 { | |
5859 illegal = TRUE; | |
5860 break; | |
5861 } | |
5862 n = getdigits(&arg_end); | |
5863 if (!eap->skip) | |
5864 { | |
5865 if (key[4] == 'B') | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5866 curwin->w_s->b_syn_sync_linebreaks = n; |
7 | 5867 else if (key[1] == 'A') |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5868 curwin->w_s->b_syn_sync_maxlines = n; |
7 | 5869 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5870 curwin->w_s->b_syn_sync_minlines = n; |
7 | 5871 } |
5872 } | |
5873 else if (STRCMP(key, "FROMSTART") == 0) | |
5874 { | |
5875 if (!eap->skip) | |
5876 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5877 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
|
5878 curwin->w_s->b_syn_sync_maxlines = 0; |
7 | 5879 } |
5880 } | |
5881 else if (STRCMP(key, "LINECONT") == 0) | |
5882 { | |
7504
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5883 if (*next_arg == NUL) /* missing pattern */ |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5884 { |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5885 illegal = TRUE; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5886 break; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5887 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5888 if (curwin->w_s->b_syn_linecont_pat != NULL) |
7 | 5889 { |
5890 EMSG(_("E403: syntax sync: line continuations pattern specified twice")); | |
5891 finished = TRUE; | |
5892 break; | |
5893 } | |
5894 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE, NULL); | |
5895 if (*arg_end != *next_arg) /* end delimiter not found */ | |
5896 { | |
5897 illegal = TRUE; | |
5898 break; | |
5899 } | |
5900 | |
5901 if (!eap->skip) | |
5902 { | |
5903 /* 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
|
5904 if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1, |
7 | 5905 (int)(arg_end - next_arg - 1))) == NULL) |
5906 { | |
5907 finished = TRUE; | |
5908 break; | |
5909 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5910 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; |
7 | 5911 |
5912 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5913 cpo_save = p_cpo; | |
5914 p_cpo = (char_u *)""; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5915 curwin->w_s->b_syn_linecont_prog = |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5916 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); |
7 | 5917 p_cpo = cpo_save; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5918 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5919 syn_clear_time(&curwin->w_s->b_syn_linecont_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5920 #endif |
7 | 5921 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5922 if (curwin->w_s->b_syn_linecont_prog == NULL) |
7 | 5923 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5924 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
|
5925 curwin->w_s->b_syn_linecont_pat = NULL; |
7 | 5926 finished = TRUE; |
5927 break; | |
5928 } | |
5929 } | |
5930 next_arg = skipwhite(arg_end + 1); | |
5931 } | |
5932 else | |
5933 { | |
5934 eap->arg = next_arg; | |
5935 if (STRCMP(key, "MATCH") == 0) | |
5936 syn_cmd_match(eap, TRUE); | |
5937 else if (STRCMP(key, "REGION") == 0) | |
5938 syn_cmd_region(eap, TRUE); | |
5939 else if (STRCMP(key, "CLEAR") == 0) | |
5940 syn_cmd_clear(eap, TRUE); | |
5941 else | |
5942 illegal = TRUE; | |
5943 finished = TRUE; | |
5944 break; | |
5945 } | |
5946 arg_start = next_arg; | |
5947 } | |
5948 vim_free(key); | |
5949 if (illegal) | |
5950 EMSG2(_("E404: Illegal arguments: %s"), arg_start); | |
5951 else if (!finished) | |
5952 { | |
5953 eap->nextcmd = check_nextcmd(arg_start); | |
745 | 5954 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5955 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5956 } |
5957 } | |
5958 | |
5959 /* | |
5960 * Convert a line of highlight group names into a list of group ID numbers. | |
5961 * "arg" should point to the "contains" or "nextgroup" keyword. | |
5962 * "arg" is advanced to after the last group name. | |
5963 * Careful: the argument is modified (NULs added). | |
5964 * returns FAIL for some error, OK for success. | |
5965 */ | |
5966 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5967 get_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5968 char_u **arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5969 int keylen, /* length of keyword */ |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5970 short **list, /* where to store the resulting list, if not |
7 | 5971 NULL, the list is silently skipped! */ |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5972 int skip) |
7 | 5973 { |
5974 char_u *p = NULL; | |
5975 char_u *end; | |
5976 int round; | |
5977 int count; | |
5978 int total_count = 0; | |
5979 short *retval = NULL; | |
5980 char_u *name; | |
5981 regmatch_T regmatch; | |
5982 int id; | |
5983 int i; | |
5984 int failed = FALSE; | |
5985 | |
5986 /* | |
5987 * We parse the list twice: | |
5988 * round == 1: count the number of items, allocate the array. | |
5989 * round == 2: fill the array with the items. | |
5990 * In round 1 new groups may be added, causing the number of items to | |
5991 * grow when a regexp is used. In that case round 1 is done once again. | |
5992 */ | |
5993 for (round = 1; round <= 2; ++round) | |
5994 { | |
5995 /* | |
5996 * skip "contains" | |
5997 */ | |
5998 p = skipwhite(*arg + keylen); | |
5999 if (*p != '=') | |
6000 { | |
6001 EMSG2(_("E405: Missing equal sign: %s"), *arg); | |
6002 break; | |
6003 } | |
6004 p = skipwhite(p + 1); | |
6005 if (ends_excmd(*p)) | |
6006 { | |
6007 EMSG2(_("E406: Empty argument: %s"), *arg); | |
6008 break; | |
6009 } | |
6010 | |
6011 /* | |
6012 * parse the arguments after "contains" | |
6013 */ | |
6014 count = 0; | |
6015 while (!ends_excmd(*p)) | |
6016 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6017 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) |
7 | 6018 ; |
6019 name = alloc((int)(end - p + 3)); /* leave room for "^$" */ | |
6020 if (name == NULL) | |
6021 { | |
6022 failed = TRUE; | |
6023 break; | |
6024 } | |
419 | 6025 vim_strncpy(name + 1, p, end - p); |
7 | 6026 if ( STRCMP(name + 1, "ALLBUT") == 0 |
6027 || STRCMP(name + 1, "ALL") == 0 | |
6028 || STRCMP(name + 1, "TOP") == 0 | |
6029 || STRCMP(name + 1, "CONTAINED") == 0) | |
6030 { | |
6031 if (TOUPPER_ASC(**arg) != 'C') | |
6032 { | |
6033 EMSG2(_("E407: %s not allowed here"), name + 1); | |
6034 failed = TRUE; | |
6035 vim_free(name); | |
6036 break; | |
6037 } | |
6038 if (count != 0) | |
6039 { | |
10648
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
6040 EMSG2(_("E408: %s must be first in contains list"), |
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
6041 name + 1); |
7 | 6042 failed = TRUE; |
6043 vim_free(name); | |
6044 break; | |
6045 } | |
6046 if (name[1] == 'A') | |
6047 id = SYNID_ALLBUT; | |
6048 else if (name[1] == 'T') | |
6049 id = SYNID_TOP; | |
6050 else | |
6051 id = SYNID_CONTAINED; | |
6052 id += current_syn_inc_tag; | |
6053 } | |
6054 else if (name[1] == '@') | |
6055 { | |
10629
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6056 if (skip) |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6057 id = -1; |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6058 else |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
6059 id = syn_check_cluster(name + 2, (int)(end - p - 1)); |
7 | 6060 } |
6061 else | |
6062 { | |
6063 /* | |
6064 * Handle full group name. | |
6065 */ | |
6066 if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) | |
6067 id = syn_check_group(name + 1, (int)(end - p)); | |
6068 else | |
6069 { | |
6070 /* | |
6071 * Handle match of regexp with group names. | |
6072 */ | |
6073 *name = '^'; | |
6074 STRCAT(name, "$"); | |
6075 regmatch.regprog = vim_regcomp(name, RE_MAGIC); | |
6076 if (regmatch.regprog == NULL) | |
6077 { | |
6078 failed = TRUE; | |
6079 vim_free(name); | |
6080 break; | |
6081 } | |
6082 | |
6083 regmatch.rm_ic = TRUE; | |
6084 id = 0; | |
6085 for (i = highlight_ga.ga_len; --i >= 0; ) | |
6086 { | |
6087 if (vim_regexec(®match, HL_TABLE()[i].sg_name, | |
6088 (colnr_T)0)) | |
6089 { | |
6090 if (round == 2) | |
6091 { | |
6092 /* Got more items than expected; can happen | |
6093 * when adding items that match: | |
6094 * "contains=a.*b,axb". | |
6095 * Go back to first round */ | |
6096 if (count >= total_count) | |
6097 { | |
6098 vim_free(retval); | |
6099 round = 1; | |
6100 } | |
6101 else | |
6102 retval[count] = i + 1; | |
6103 } | |
6104 ++count; | |
6105 id = -1; /* remember that we found one */ | |
6106 } | |
6107 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6108 vim_regfree(regmatch.regprog); |
7 | 6109 } |
6110 } | |
6111 vim_free(name); | |
6112 if (id == 0) | |
6113 { | |
6114 EMSG2(_("E409: Unknown group name: %s"), p); | |
6115 failed = TRUE; | |
6116 break; | |
6117 } | |
6118 if (id > 0) | |
6119 { | |
6120 if (round == 2) | |
6121 { | |
6122 /* Got more items than expected, go back to first round */ | |
6123 if (count >= total_count) | |
6124 { | |
6125 vim_free(retval); | |
6126 round = 1; | |
6127 } | |
6128 else | |
6129 retval[count] = id; | |
6130 } | |
6131 ++count; | |
6132 } | |
6133 p = skipwhite(end); | |
6134 if (*p != ',') | |
6135 break; | |
6136 p = skipwhite(p + 1); /* skip comma in between arguments */ | |
6137 } | |
6138 if (failed) | |
6139 break; | |
6140 if (round == 1) | |
6141 { | |
6142 retval = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
6143 if (retval == NULL) | |
6144 break; | |
6145 retval[count] = 0; /* zero means end of the list */ | |
6146 total_count = count; | |
6147 } | |
6148 } | |
6149 | |
6150 *arg = p; | |
6151 if (failed || retval == NULL) | |
6152 { | |
6153 vim_free(retval); | |
6154 return FAIL; | |
6155 } | |
6156 | |
6157 if (*list == NULL) | |
6158 *list = retval; | |
6159 else | |
6160 vim_free(retval); /* list already found, don't overwrite it */ | |
6161 | |
6162 return OK; | |
6163 } | |
6164 | |
6165 /* | |
6166 * Make a copy of an ID list. | |
6167 */ | |
6168 static short * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6169 copy_id_list(short *list) |
7 | 6170 { |
6171 int len; | |
6172 int count; | |
6173 short *retval; | |
6174 | |
6175 if (list == NULL) | |
6176 return NULL; | |
6177 | |
6178 for (count = 0; list[count]; ++count) | |
6179 ; | |
6180 len = (count + 1) * sizeof(short); | |
6181 retval = (short *)alloc((unsigned)len); | |
6182 if (retval != NULL) | |
6183 mch_memmove(retval, list, (size_t)len); | |
6184 | |
6185 return retval; | |
6186 } | |
6187 | |
6188 /* | |
6189 * Check if syntax group "ssp" is in the ID list "list" of "cur_si". | |
6190 * "cur_si" can be NULL if not checking the "containedin" list. | |
6191 * Used to check if a syntax item is in the "contains" or "nextgroup" list of | |
6192 * the current item. | |
6193 * This function is called very often, keep it fast!! | |
6194 */ | |
6195 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6196 in_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6197 stateitem_T *cur_si, /* current item or NULL */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6198 short *list, /* id list */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6199 struct sp_syn *ssp, /* group id and ":syn include" tag of group */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6200 int contained) /* group id is contained */ |
7 | 6201 { |
6202 int retval; | |
6203 short *scl_list; | |
6204 short item; | |
6205 short id = ssp->id; | |
6206 static int depth = 0; | |
6207 int r; | |
6208 | |
4352 | 6209 /* If ssp has a "containedin" list and "cur_si" is in it, return TRUE. */ |
36 | 6210 if (cur_si != NULL && ssp->cont_in_list != NULL |
6211 && !(cur_si->si_flags & HL_MATCH)) | |
7 | 6212 { |
6213 /* Ignore transparent items without a contains argument. Double check | |
6214 * that we don't go back past the first one. */ | |
6215 while ((cur_si->si_flags & HL_TRANS_CONT) | |
6216 && cur_si > (stateitem_T *)(current_state.ga_data)) | |
6217 --cur_si; | |
6218 /* cur_si->si_idx is -1 for keywords, these never contain anything. */ | |
6219 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
|
6220 &(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
|
6221 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) |
7 | 6222 return TRUE; |
6223 } | |
6224 | |
6225 if (list == NULL) | |
6226 return FALSE; | |
6227 | |
6228 /* | |
6229 * If list is ID_LIST_ALL, we are in a transparent item that isn't | |
6230 * inside anything. Only allow not-contained groups. | |
6231 */ | |
6232 if (list == ID_LIST_ALL) | |
6233 return !contained; | |
6234 | |
6235 /* | |
6236 * If the first item is "ALLBUT", return TRUE if "id" is NOT in the | |
6237 * contains list. We also require that "id" is at the same ":syn include" | |
6238 * level as the list. | |
6239 */ | |
6240 item = *list; | |
6241 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) | |
6242 { | |
6243 if (item < SYNID_TOP) | |
6244 { | |
6245 /* ALL or ALLBUT: accept all groups in the same file */ | |
6246 if (item - SYNID_ALLBUT != ssp->inc_tag) | |
6247 return FALSE; | |
6248 } | |
6249 else if (item < SYNID_CONTAINED) | |
6250 { | |
6251 /* TOP: accept all not-contained groups in the same file */ | |
6252 if (item - SYNID_TOP != ssp->inc_tag || contained) | |
6253 return FALSE; | |
6254 } | |
6255 else | |
6256 { | |
6257 /* CONTAINED: accept all contained groups in the same file */ | |
6258 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) | |
6259 return FALSE; | |
6260 } | |
6261 item = *++list; | |
6262 retval = FALSE; | |
6263 } | |
6264 else | |
6265 retval = TRUE; | |
6266 | |
6267 /* | |
6268 * Return "retval" if id is in the contains list. | |
6269 */ | |
6270 while (item != 0) | |
6271 { | |
6272 if (item == id) | |
6273 return retval; | |
6274 if (item >= SYNID_CLUSTER) | |
6275 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6276 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; |
7 | 6277 /* restrict recursiveness to 30 to avoid an endless loop for a |
6278 * cluster that includes itself (indirectly) */ | |
6279 if (scl_list != NULL && depth < 30) | |
6280 { | |
6281 ++depth; | |
6282 r = in_id_list(NULL, scl_list, ssp, contained); | |
6283 --depth; | |
6284 if (r) | |
6285 return retval; | |
6286 } | |
6287 } | |
6288 item = *++list; | |
6289 } | |
6290 return !retval; | |
6291 } | |
6292 | |
6293 struct subcommand | |
6294 { | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6295 char *name; /* subcommand name */ |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6296 void (*func)(exarg_T *, int); /* function to call */ |
7 | 6297 }; |
6298 | |
6299 static struct subcommand subcommands[] = | |
6300 { | |
6301 {"case", syn_cmd_case}, | |
6302 {"clear", syn_cmd_clear}, | |
6303 {"cluster", syn_cmd_cluster}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6304 {"conceal", syn_cmd_conceal}, |
7 | 6305 {"enable", syn_cmd_enable}, |
6306 {"include", syn_cmd_include}, | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6307 {"iskeyword", syn_cmd_iskeyword}, |
7 | 6308 {"keyword", syn_cmd_keyword}, |
6309 {"list", syn_cmd_list}, | |
6310 {"manual", syn_cmd_manual}, | |
6311 {"match", syn_cmd_match}, | |
6312 {"on", syn_cmd_on}, | |
6313 {"off", syn_cmd_off}, | |
6314 {"region", syn_cmd_region}, | |
6315 {"reset", syn_cmd_reset}, | |
419 | 6316 {"spell", syn_cmd_spell}, |
7 | 6317 {"sync", syn_cmd_sync}, |
6318 {"", syn_cmd_list}, | |
6319 {NULL, NULL} | |
6320 }; | |
6321 | |
6322 /* | |
6323 * ":syntax". | |
6324 * This searches the subcommands[] table for the subcommand name, and calls a | |
6325 * syntax_subcommand() function to do the rest. | |
6326 */ | |
6327 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6328 ex_syntax(exarg_T *eap) |
7 | 6329 { |
6330 char_u *arg = eap->arg; | |
6331 char_u *subcmd_end; | |
6332 char_u *subcmd_name; | |
6333 int i; | |
6334 | |
6335 syn_cmdlinep = eap->cmdlinep; | |
6336 | |
6337 /* isolate subcommand name */ | |
6338 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) | |
6339 ; | |
6340 subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg)); | |
6341 if (subcmd_name != NULL) | |
6342 { | |
6343 if (eap->skip) /* skip error messages for all subcommands */ | |
6344 ++emsg_skip; | |
6345 for (i = 0; ; ++i) | |
6346 { | |
6347 if (subcommands[i].name == NULL) | |
6348 { | |
6349 EMSG2(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); | |
6350 break; | |
6351 } | |
6352 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) | |
6353 { | |
6354 eap->arg = skipwhite(subcmd_end); | |
6355 (subcommands[i].func)(eap, FALSE); | |
6356 break; | |
6357 } | |
6358 } | |
6359 vim_free(subcmd_name); | |
6360 if (eap->skip) | |
6361 --emsg_skip; | |
6362 } | |
6363 } | |
6364 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6365 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6366 ex_ownsyntax(exarg_T *eap) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6367 { |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6368 char_u *old_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6369 char_u *new_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6370 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6371 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
|
6372 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6373 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
|
6374 memset(curwin->w_s, 0, sizeof(synblock_T)); |
7030
8d513ddfe3ec
commit https://github.com/vim/vim/commit/670acbc70f371409b46b722bd9a1166e53574f42
Christian Brabandt <cb@256bit.org>
parents:
7017
diff
changeset
|
6375 hash_init(&curwin->w_s->b_keywtab); |
8d513ddfe3ec
commit https://github.com/vim/vim/commit/670acbc70f371409b46b722bd9a1166e53574f42
Christian Brabandt <cb@256bit.org>
parents:
7017
diff
changeset
|
6376 hash_init(&curwin->w_s->b_keywtab_ic); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6377 #ifdef FEAT_SPELL |
6386 | 6378 /* TODO: keep the spell checking as it was. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6379 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
|
6380 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
|
6381 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
|
6382 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
|
6383 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6384 clear_string_option(&curwin->w_s->b_syn_isk); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6385 } |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6386 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6387 /* save value of b:current_syntax */ |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6388 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
|
6389 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6390 old_value = vim_strsave(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6391 |
8362
a541dd5cfd3a
commit https://github.com/vim/vim/commit/d1413d90983fc6c579ad66ba4d4611b057197f94
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
6392 #ifdef FEAT_AUTOCMD |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6393 /* 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
|
6394 * file. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6395 apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, TRUE, curbuf); |
8362
a541dd5cfd3a
commit https://github.com/vim/vim/commit/d1413d90983fc6c579ad66ba4d4611b057197f94
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
6396 #endif |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6397 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6398 /* 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
|
6399 new_value = get_var_value((char_u *)"b:current_syntax"); |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6400 if (new_value != NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6401 set_internal_string_var((char_u *)"w:current_syntax", new_value); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6402 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6403 /* restore value of b:current_syntax */ |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6404 if (old_value == NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6405 do_unlet((char_u *)"b:current_syntax", TRUE); |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6406 else |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6407 { |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6408 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
|
6409 vim_free(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6410 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6411 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6412 |
7 | 6413 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6414 syntax_present(win_T *win) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6415 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6416 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
|
6417 || 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
|
6418 || 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
|
6419 || win->w_s->b_keywtab_ic.ht_used > 0); |
7 | 6420 } |
6421 | |
6422 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
6423 | |
6424 static enum | |
6425 { | |
6426 EXP_SUBCMD, /* expand ":syn" sub-commands */ | |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6427 EXP_CASE, /* expand ":syn case" arguments */ |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6428 EXP_SPELL, /* expand ":syn spell" arguments */ |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6429 EXP_SYNC /* expand ":syn sync" arguments */ |
7 | 6430 } expand_what; |
6431 | |
1322 | 6432 /* |
6433 * Reset include_link, include_default, include_none to 0. | |
6434 * Called when we are done expanding. | |
6435 */ | |
6436 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6437 reset_expand_highlight(void) |
1322 | 6438 { |
6439 include_link = include_default = include_none = 0; | |
6440 } | |
6441 | |
6442 /* | |
6443 * Handle command line completion for :match and :echohl command: Add "None" | |
6444 * as highlight group. | |
6445 */ | |
6446 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6447 set_context_in_echohl_cmd(expand_T *xp, char_u *arg) |
1322 | 6448 { |
6449 xp->xp_context = EXPAND_HIGHLIGHT; | |
6450 xp->xp_pattern = arg; | |
6451 include_none = 1; | |
6452 } | |
7 | 6453 |
6454 /* | |
6455 * Handle command line completion for :syntax command. | |
6456 */ | |
6457 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6458 set_context_in_syntax_cmd(expand_T *xp, char_u *arg) |
7 | 6459 { |
6460 char_u *p; | |
6461 | |
6462 /* Default: expand subcommands */ | |
6463 xp->xp_context = EXPAND_SYNTAX; | |
6464 expand_what = EXP_SUBCMD; | |
6465 xp->xp_pattern = arg; | |
1322 | 6466 include_link = 0; |
6467 include_default = 0; | |
7 | 6468 |
6469 /* (part of) subcommand already typed */ | |
6470 if (*arg != NUL) | |
6471 { | |
6472 p = skiptowhite(arg); | |
6473 if (*p != NUL) /* past first word */ | |
6474 { | |
6475 xp->xp_pattern = skipwhite(p); | |
6476 if (*skiptowhite(xp->xp_pattern) != NUL) | |
6477 xp->xp_context = EXPAND_NOTHING; | |
6478 else if (STRNICMP(arg, "case", p - arg) == 0) | |
6479 expand_what = EXP_CASE; | |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6480 else if (STRNICMP(arg, "spell", p - arg) == 0) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6481 expand_what = EXP_SPELL; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6482 else if (STRNICMP(arg, "sync", p - arg) == 0) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6483 expand_what = EXP_SYNC; |
7 | 6484 else if ( STRNICMP(arg, "keyword", p - arg) == 0 |
6485 || STRNICMP(arg, "region", p - arg) == 0 | |
6486 || STRNICMP(arg, "match", p - arg) == 0 | |
6487 || STRNICMP(arg, "list", p - arg) == 0) | |
6488 xp->xp_context = EXPAND_HIGHLIGHT; | |
6489 else | |
6490 xp->xp_context = EXPAND_NOTHING; | |
6491 } | |
6492 } | |
6493 } | |
6494 | |
6495 /* | |
6496 * Function given to ExpandGeneric() to obtain the list syntax names for | |
6497 * expansion. | |
6498 */ | |
6499 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6500 get_syntax_name(expand_T *xp UNUSED, int idx) |
7 | 6501 { |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6502 switch (expand_what) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6503 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6504 case EXP_SUBCMD: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6505 return (char_u *)subcommands[idx].name; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6506 case EXP_CASE: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6507 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6508 static char *case_args[] = {"match", "ignore", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6509 return (char_u *)case_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6510 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6511 case EXP_SPELL: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6512 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6513 static char *spell_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6514 {"toplevel", "notoplevel", "default", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6515 return (char_u *)spell_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6516 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6517 case EXP_SYNC: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6518 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6519 static char *sync_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6520 {"ccomment", "clear", "fromstart", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6521 "linebreaks=", "linecont", "lines=", "match", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6522 "maxlines=", "minlines=", "region", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6523 return (char_u *)sync_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6524 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6525 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6526 return NULL; |
7 | 6527 } |
6528 | |
6529 #endif /* FEAT_CMDL_COMPL */ | |
6530 | |
6531 /* | |
6532 * Function called for expression evaluation: get syntax ID at file position. | |
6533 */ | |
6534 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6535 syn_get_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6536 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6537 long lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6538 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6539 int trans, /* remove transparency */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6540 int *spellp, /* return: can do spell checking */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6541 int keep_state) /* keep state of char at "col" */ |
7 | 6542 { |
6543 /* When the position is not after the current position and in the same | |
6544 * line of the same buffer, need to restart parsing. */ | |
499 | 6545 if (wp->w_buffer != syn_buf |
7 | 6546 || lnum != current_lnum |
253 | 6547 || col < current_col) |
499 | 6548 syntax_start(wp, lnum); |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6549 else if (wp->w_buffer == syn_buf |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6550 && lnum == current_lnum |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6551 && col > current_col) |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6552 /* next_match may not be correct when moving around, e.g. with the |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6553 * "skip" expression in searchpair() */ |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6554 next_match_idx = -1; |
7 | 6555 |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6556 (void)get_syntax_attr(col, spellp, keep_state); |
7 | 6557 |
6558 return (trans ? current_trans_id : current_id); | |
6559 } | |
6560 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6561 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6562 /* |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6563 * Get extra information about the syntax item. Must be called right after |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6564 * get_syntax_attr(). |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
6565 * Stores the current item sequence nr in "*seqnrp". |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6566 * Returns the current flags. |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6567 */ |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6568 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6569 get_syntax_info(int *seqnrp) |
2392
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
6570 { |
0371401d9d33
Give each syntax item a sequence number, so that we know when it starts and
Bram Moolenaar <bram@vim.org>
parents:
2375
diff
changeset
|
6571 *seqnrp = current_seqnr; |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6572 return current_flags; |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6573 } |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6574 |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6575 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6576 * Return conceal substitution character |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6577 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6578 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6579 syn_get_sub_char(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6580 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6581 return current_sub_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6582 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6583 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6584 |
1500 | 6585 #if defined(FEAT_EVAL) || defined(PROTO) |
6586 /* | |
6587 * Return the syntax ID at position "i" in the current stack. | |
6588 * The caller must have called syn_get_id() before to fill the stack. | |
6589 * Returns -1 when "i" is out of range. | |
6590 */ | |
6591 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6592 syn_get_stack_item(int i) |
1500 | 6593 { |
1504 | 6594 if (i >= current_state.ga_len) |
6595 { | |
6596 /* Need to invalidate the state, because we didn't properly finish it | |
6597 * for the last character, "keep_state" was TRUE. */ | |
6598 invalidate_current_state(); | |
6599 current_col = MAXCOL; | |
1500 | 6600 return -1; |
1504 | 6601 } |
1500 | 6602 return CUR_STATE(i).si_id; |
6603 } | |
6604 #endif | |
6605 | |
7 | 6606 #if defined(FEAT_FOLDING) || defined(PROTO) |
6607 /* | |
6608 * Function called to get folding level for line "lnum" in window "wp". | |
6609 */ | |
6610 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6611 syn_get_foldlevel(win_T *wp, long lnum) |
7 | 6612 { |
6613 int level = 0; | |
6614 int i; | |
6615 | |
6616 /* 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
|
6617 if (wp->w_s->b_syn_folditems != 0) |
7 | 6618 { |
6619 syntax_start(wp, lnum); | |
6620 | |
6621 for (i = 0; i < current_state.ga_len; ++i) | |
6622 if (CUR_STATE(i).si_flags & HL_FOLD) | |
6623 ++level; | |
6624 } | |
6625 if (level > wp->w_p_fdn) | |
1028 | 6626 { |
7 | 6627 level = wp->w_p_fdn; |
1028 | 6628 if (level < 0) |
6629 level = 0; | |
6630 } | |
7 | 6631 return level; |
6632 } | |
6633 #endif | |
6634 | |
6567 | 6635 #if defined(FEAT_PROFILE) || defined(PROTO) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6636 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6637 * ":syntime". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6638 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6639 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6640 ex_syntime(exarg_T *eap) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6641 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6642 if (STRCMP(eap->arg, "on") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6643 syn_time_on = TRUE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6644 else if (STRCMP(eap->arg, "off") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6645 syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6646 else if (STRCMP(eap->arg, "clear") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6647 syntime_clear(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6648 else if (STRCMP(eap->arg, "report") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6649 syntime_report(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6650 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6651 EMSG2(_(e_invarg2), eap->arg); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6652 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6653 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6654 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6655 syn_clear_time(syn_time_T *st) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6656 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6657 profile_zero(&st->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6658 profile_zero(&st->slowest); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6659 st->count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6660 st->match = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6661 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6662 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6663 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6664 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6665 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6666 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6667 syntime_clear(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6668 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6669 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6670 synpat_T *spp; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6671 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6672 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6673 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6674 MSG(_(msg_no_items)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6675 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6676 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6677 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6678 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6679 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6680 syn_clear_time(&spp->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6681 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6682 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6683 |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6684 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6685 /* |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6686 * Function given to ExpandGeneric() to obtain the possible arguments of the |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6687 * ":syntime {on,off,clear,report}" command. |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6688 */ |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6689 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6690 get_syntime_arg(expand_T *xp UNUSED, int idx) |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6691 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6692 switch (idx) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6693 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6694 case 0: return (char_u *)"on"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6695 case 1: return (char_u *)"off"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6696 case 2: return (char_u *)"clear"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6697 case 3: return (char_u *)"report"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6698 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6699 return NULL; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6700 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6701 #endif |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6702 |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6703 typedef struct |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6704 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6705 proftime_T total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6706 int count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6707 int match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6708 proftime_T slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6709 proftime_T average; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6710 int id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6711 char_u *pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6712 } time_entry_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6713 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6714 static int |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6715 #ifdef __BORLANDC__ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6716 _RTLENTRYF |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6717 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6718 syn_compare_syntime(const void *v1, const void *v2) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6719 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6720 const time_entry_T *s1 = v1; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6721 const time_entry_T *s2 = v2; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6722 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6723 return profile_cmp(&s1->total, &s2->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6724 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6725 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6726 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6727 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6728 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6729 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6730 syntime_report(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6731 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6732 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6733 synpat_T *spp; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6734 # ifdef FEAT_FLOAT |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6735 proftime_T tm; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6736 # endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6737 int len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6738 proftime_T total_total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6739 int total_count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6740 garray_T ga; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6741 time_entry_T *p; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6742 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6743 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6744 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6745 MSG(_(msg_no_items)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6746 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6747 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6748 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6749 ga_init2(&ga, sizeof(time_entry_T), 50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6750 profile_zero(&total_total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6751 for (idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; ++idx) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6752 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6753 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6754 if (spp->sp_time.count > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6755 { |
7009 | 6756 (void)ga_grow(&ga, 1); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6757 p = ((time_entry_T *)ga.ga_data) + ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6758 p->total = spp->sp_time.total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6759 profile_add(&total_total, &spp->sp_time.total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6760 p->count = spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6761 p->match = spp->sp_time.match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6762 total_count += spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6763 p->slowest = spp->sp_time.slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6764 # ifdef FEAT_FLOAT |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6765 profile_divide(&spp->sp_time.total, spp->sp_time.count, &tm); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6766 p->average = tm; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6767 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6768 p->id = spp->sp_syn.id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6769 p->pattern = spp->sp_pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6770 ++ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6771 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6772 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6773 |
10530
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6774 /* Sort on total time. Skip if there are no items to avoid passing NULL |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6775 * pointer to qsort(). */ |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6776 if (ga.ga_len > 1) |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6777 qsort(ga.ga_data, (size_t)ga.ga_len, sizeof(time_entry_T), |
4776
e4bc21965079
updated for version 7.3.1135
Bram Moolenaar <bram@vim.org>
parents:
4766
diff
changeset
|
6778 syn_compare_syntime); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6779 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6780 MSG_PUTS_TITLE(_(" TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN")); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6781 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6782 for (idx = 0; idx < ga.ga_len && !got_int; ++idx) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6783 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6784 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6785 p = ((time_entry_T *)ga.ga_data) + idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6786 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6787 MSG_PUTS(profile_msg(&p->total)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6788 MSG_PUTS(" "); /* make sure there is always a separating space */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6789 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6790 msg_outnum(p->count); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6791 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6792 msg_advance(20); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6793 msg_outnum(p->match); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6794 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6795 msg_advance(26); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6796 MSG_PUTS(profile_msg(&p->slowest)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6797 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6798 msg_advance(38); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6799 # ifdef FEAT_FLOAT |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6800 MSG_PUTS(profile_msg(&p->average)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6801 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6802 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6803 msg_advance(50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6804 msg_outtrans(HL_TABLE()[p->id - 1].sg_name); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6805 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6806 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6807 msg_advance(69); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6808 if (Columns < 80) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6809 len = 20; /* will wrap anyway */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6810 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6811 len = Columns - 70; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6812 if (len > (int)STRLEN(p->pattern)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6813 len = (int)STRLEN(p->pattern); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6814 msg_outtrans_len(p->pattern, len); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6815 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6816 } |
4791
65cef998f860
updated for version 7.3.1142
Bram Moolenaar <bram@vim.org>
parents:
4776
diff
changeset
|
6817 ga_clear(&ga); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6818 if (!got_int) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6819 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6820 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6821 MSG_PUTS(profile_msg(&total_total)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6822 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6823 msg_outnum(total_count); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6824 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6825 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6826 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6827 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6828 |
7 | 6829 #endif /* FEAT_SYN_HL */ |
6830 | |
6831 /************************************** | |
6832 * Highlighting stuff * | |
6833 **************************************/ | |
6834 | |
6835 /* | |
6836 * The default highlight groups. These are compiled-in for fast startup and | |
6837 * they still work when the runtime files can't be found. | |
6838 * When making changes here, also change runtime/colors/default.vim! | |
806 | 6839 * The #ifdefs are needed to reduce the amount of static data. Helps to make |
6840 * the 16 bit DOS (museum) version compile. | |
7 | 6841 */ |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
6842 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
809 | 6843 # define CENT(a, b) b |
6844 #else | |
6845 # define CENT(a, b) a | |
6846 #endif | |
7 | 6847 static char *(highlight_init_both[]) = |
6848 { | |
809 | 6849 CENT("ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", |
6850 "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), | |
6851 CENT("IncSearch term=reverse cterm=reverse", | |
6852 "IncSearch term=reverse cterm=reverse gui=reverse"), | |
6853 CENT("ModeMsg term=bold cterm=bold", | |
6854 "ModeMsg term=bold cterm=bold gui=bold"), | |
6855 CENT("NonText term=bold ctermfg=Blue", | |
6856 "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), | |
6857 CENT("StatusLine term=reverse,bold cterm=reverse,bold", | |
6858 "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), | |
6859 CENT("StatusLineNC term=reverse cterm=reverse", | |
6860 "StatusLineNC term=reverse cterm=reverse gui=reverse"), | |
9877
7da89d9c744b
commit https://github.com/vim/vim/commit/58b853460add42098ab08017df9e030fb14fd34b
Christian Brabandt <cb@256bit.org>
parents:
9869
diff
changeset
|
6861 "default link EndOfBuffer NonText", |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
6862 #ifdef FEAT_WINDOWS |
809 | 6863 CENT("VertSplit term=reverse cterm=reverse", |
6864 "VertSplit term=reverse cterm=reverse gui=reverse"), | |
806 | 6865 #endif |
6866 #ifdef FEAT_CLIPBOARD | |
809 | 6867 CENT("VisualNOS term=underline,bold cterm=underline,bold", |
6868 "VisualNOS term=underline,bold cterm=underline,bold gui=underline,bold"), | |
806 | 6869 #endif |
6870 #ifdef FEAT_DIFF | |
809 | 6871 CENT("DiffText term=reverse cterm=bold ctermbg=Red", |
6872 "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), | |
806 | 6873 #endif |
6874 #ifdef FEAT_INS_EXPAND | |
809 | 6875 CENT("PmenuSbar ctermbg=Grey", |
6876 "PmenuSbar ctermbg=Grey guibg=Grey"), | |
806 | 6877 #endif |
6878 #ifdef FEAT_WINDOWS | |
809 | 6879 CENT("TabLineSel term=bold cterm=bold", |
6880 "TabLineSel term=bold cterm=bold gui=bold"), | |
6881 CENT("TabLineFill term=reverse cterm=reverse", | |
6882 "TabLineFill term=reverse cterm=reverse gui=reverse"), | |
806 | 6883 #endif |
7 | 6884 #ifdef FEAT_GUI |
6885 "Cursor guibg=fg guifg=bg", | |
809 | 6886 "lCursor guibg=fg guifg=bg", /* should be different, but what? */ |
7 | 6887 #endif |
6888 NULL | |
6889 }; | |
6890 | |
6891 static char *(highlight_init_light[]) = | |
6892 { | |
809 | 6893 CENT("Directory term=bold ctermfg=DarkBlue", |
6894 "Directory term=bold ctermfg=DarkBlue guifg=Blue"), | |
6895 CENT("LineNr term=underline ctermfg=Brown", | |
6896 "LineNr term=underline ctermfg=Brown guifg=Brown"), | |
3427 | 6897 CENT("CursorLineNr term=bold ctermfg=Brown", |
6898 "CursorLineNr term=bold ctermfg=Brown gui=bold guifg=Brown"), | |
809 | 6899 CENT("MoreMsg term=bold ctermfg=DarkGreen", |
6900 "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6901 CENT("Question term=standout ctermfg=DarkGreen", | |
6902 "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6903 CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", | |
6904 "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), | |
806 | 6905 #ifdef FEAT_SPELL |
809 | 6906 CENT("SpellBad term=reverse ctermbg=LightRed", |
6907 "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), | |
6908 CENT("SpellCap term=reverse ctermbg=LightBlue", | |
6909 "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), | |
6910 CENT("SpellRare term=reverse ctermbg=LightMagenta", | |
6911 "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), | |
6912 CENT("SpellLocal term=underline ctermbg=Cyan", | |
6913 "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), | |
806 | 6914 #endif |
6915 #ifdef FEAT_INS_EXPAND | |
3419 | 6916 CENT("PmenuThumb ctermbg=Black", |
6917 "PmenuThumb ctermbg=Black guibg=Black"), | |
6918 CENT("Pmenu ctermbg=LightMagenta ctermfg=Black", | |
6919 "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta"), | |
6920 CENT("PmenuSel ctermbg=LightGrey ctermfg=Black", | |
6921 "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey"), | |
806 | 6922 #endif |
809 | 6923 CENT("SpecialKey term=bold ctermfg=DarkBlue", |
6924 "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), | |
6925 CENT("Title term=bold ctermfg=DarkMagenta", | |
6926 "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), | |
6927 CENT("WarningMsg term=standout ctermfg=DarkRed", | |
6928 "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), | |
806 | 6929 #ifdef FEAT_WILDMENU |
809 | 6930 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
6931 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 6932 #endif |
6933 #ifdef FEAT_FOLDING | |
809 | 6934 CENT("Folded term=standout ctermbg=Grey ctermfg=DarkBlue", |
6935 "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), | |
6936 CENT("FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", | |
6937 "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6938 #endif |
6939 #ifdef FEAT_SIGNS | |
809 | 6940 CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", |
6941 "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6942 #endif |
836 | 6943 CENT("Visual term=reverse", |
6944 "Visual term=reverse guibg=LightGrey"), | |
806 | 6945 #ifdef FEAT_DIFF |
809 | 6946 CENT("DiffAdd term=bold ctermbg=LightBlue", |
6947 "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), | |
6948 CENT("DiffChange term=bold ctermbg=LightMagenta", | |
6949 "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), | |
6950 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", | |
6951 "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), | |
806 | 6952 #endif |
6953 #ifdef FEAT_WINDOWS | |
809 | 6954 CENT("TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", |
6955 "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), | |
806 | 6956 #endif |
6957 #ifdef FEAT_SYN_HL | |
809 | 6958 CENT("CursorColumn term=reverse ctermbg=LightGrey", |
818 | 6959 "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), |
809 | 6960 CENT("CursorLine term=underline cterm=underline", |
818 | 6961 "CursorLine term=underline cterm=underline guibg=Grey90"), |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
6962 CENT("ColorColumn term=reverse ctermbg=LightRed", |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
6963 "ColorColumn term=reverse ctermbg=LightRed guibg=LightRed"), |
806 | 6964 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6965 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6966 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6967 "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
|
6968 #endif |
834 | 6969 #ifdef FEAT_AUTOCMD |
6970 CENT("MatchParen term=reverse ctermbg=Cyan", | |
6971 "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), | |
6972 #endif | |
806 | 6973 #ifdef FEAT_GUI |
7 | 6974 "Normal gui=NONE", |
806 | 6975 #endif |
7 | 6976 NULL |
6977 }; | |
6978 | |
6979 static char *(highlight_init_dark[]) = | |
6980 { | |
809 | 6981 CENT("Directory term=bold ctermfg=LightCyan", |
6982 "Directory term=bold ctermfg=LightCyan guifg=Cyan"), | |
6983 CENT("LineNr term=underline ctermfg=Yellow", | |
6984 "LineNr term=underline ctermfg=Yellow guifg=Yellow"), | |
3427 | 6985 CENT("CursorLineNr term=bold ctermfg=Yellow", |
6986 "CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow"), | |
809 | 6987 CENT("MoreMsg term=bold ctermfg=LightGreen", |
6988 "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), | |
6989 CENT("Question term=standout ctermfg=LightGreen", | |
6990 "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), | |
6991 CENT("Search term=reverse ctermbg=Yellow ctermfg=Black", | |
6992 "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
6993 CENT("SpecialKey term=bold ctermfg=LightBlue", | |
6994 "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), | |
806 | 6995 #ifdef FEAT_SPELL |
809 | 6996 CENT("SpellBad term=reverse ctermbg=Red", |
6997 "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), | |
6998 CENT("SpellCap term=reverse ctermbg=Blue", | |
6999 "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), | |
7000 CENT("SpellRare term=reverse ctermbg=Magenta", | |
7001 "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), | |
7002 CENT("SpellLocal term=underline ctermbg=Cyan", | |
7003 "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), | |
806 | 7004 #endif |
7005 #ifdef FEAT_INS_EXPAND | |
3419 | 7006 CENT("PmenuThumb ctermbg=White", |
7007 "PmenuThumb ctermbg=White guibg=White"), | |
7008 CENT("Pmenu ctermbg=Magenta ctermfg=Black", | |
7009 "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta"), | |
3695 | 7010 CENT("PmenuSel ctermbg=Black ctermfg=DarkGrey", |
7011 "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey"), | |
806 | 7012 #endif |
809 | 7013 CENT("Title term=bold ctermfg=LightMagenta", |
7014 "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), | |
7015 CENT("WarningMsg term=standout ctermfg=LightRed", | |
7016 "WarningMsg term=standout ctermfg=LightRed guifg=Red"), | |
806 | 7017 #ifdef FEAT_WILDMENU |
809 | 7018 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
7019 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 7020 #endif |
7021 #ifdef FEAT_FOLDING | |
809 | 7022 CENT("Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", |
7023 "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), | |
7024 CENT("FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", | |
7025 "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 7026 #endif |
7027 #ifdef FEAT_SIGNS | |
809 | 7028 CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", |
7029 "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 7030 #endif |
836 | 7031 CENT("Visual term=reverse", |
7032 "Visual term=reverse guibg=DarkGrey"), | |
806 | 7033 #ifdef FEAT_DIFF |
809 | 7034 CENT("DiffAdd term=bold ctermbg=DarkBlue", |
7035 "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), | |
7036 CENT("DiffChange term=bold ctermbg=DarkMagenta", | |
7037 "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), | |
7038 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", | |
7039 "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), | |
806 | 7040 #endif |
7041 #ifdef FEAT_WINDOWS | |
809 | 7042 CENT("TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", |
7043 "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), | |
806 | 7044 #endif |
7045 #ifdef FEAT_SYN_HL | |
809 | 7046 CENT("CursorColumn term=reverse ctermbg=DarkGrey", |
834 | 7047 "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), |
809 | 7048 CENT("CursorLine term=underline cterm=underline", |
834 | 7049 "CursorLine term=underline cterm=underline guibg=Grey40"), |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
7050 CENT("ColorColumn term=reverse ctermbg=DarkRed", |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
7051 "ColorColumn term=reverse ctermbg=DarkRed guibg=DarkRed"), |
834 | 7052 #endif |
7053 #ifdef FEAT_AUTOCMD | |
7054 CENT("MatchParen term=reverse ctermbg=DarkCyan", | |
7055 "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), | |
806 | 7056 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7057 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7058 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7059 "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
|
7060 #endif |
806 | 7061 #ifdef FEAT_GUI |
7 | 7062 "Normal gui=NONE", |
806 | 7063 #endif |
7 | 7064 NULL |
7065 }; | |
7066 | |
7067 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7068 init_highlight( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7069 int both, /* include groups where 'bg' doesn't matter */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7070 int reset) /* clear group first */ |
7 | 7071 { |
7072 int i; | |
7073 char **pp; | |
7074 static int had_both = FALSE; | |
7075 #ifdef FEAT_EVAL | |
7076 char_u *p; | |
7077 | |
7078 /* | |
7079 * Try finding the color scheme file. Used when a color file was loaded | |
7080 * and 'background' or 't_Co' is changed. | |
7081 */ | |
7082 p = get_var_value((char_u *)"g:colors_name"); | |
6671 | 7083 if (p != NULL) |
7084 { | |
7085 /* The value of g:colors_name could be freed when sourcing the script, | |
7086 * making "p" invalid, so copy it. */ | |
7087 char_u *copy_p = vim_strsave(p); | |
7088 int r; | |
7089 | |
7090 if (copy_p != NULL) | |
7091 { | |
7092 r = load_colors(copy_p); | |
7093 vim_free(copy_p); | |
7094 if (r == OK) | |
7095 return; | |
7096 } | |
7097 } | |
7098 | |
7 | 7099 #endif |
7100 | |
7101 /* | |
7102 * Didn't use a color file, use the compiled-in colors. | |
7103 */ | |
7104 if (both) | |
7105 { | |
7106 had_both = TRUE; | |
7107 pp = highlight_init_both; | |
7108 for (i = 0; pp[i] != NULL; ++i) | |
7109 do_highlight((char_u *)pp[i], reset, TRUE); | |
7110 } | |
7111 else if (!had_both) | |
7112 /* Don't do anything before the call with both == TRUE from main(). | |
7113 * Not everything has been setup then, and that call will overrule | |
7114 * everything anyway. */ | |
7115 return; | |
7116 | |
7117 if (*p_bg == 'l') | |
7118 pp = highlight_init_light; | |
7119 else | |
7120 pp = highlight_init_dark; | |
7121 for (i = 0; pp[i] != NULL; ++i) | |
7122 do_highlight((char_u *)pp[i], reset, TRUE); | |
7123 | |
836 | 7124 /* Reverse looks ugly, but grey may not work for 8 colors. Thus let it |
844 | 7125 * depend on the number of colors available. |
7126 * With 8 colors brown is equal to yellow, need to use black for Search fg | |
1697 | 7127 * to avoid Statement highlighted text disappears. |
7128 * Clear the attributes, needed when changing the t_Co value. */ | |
527 | 7129 if (t_colors > 8) |
1697 | 7130 do_highlight((char_u *)(*p_bg == 'l' |
7131 ? "Visual cterm=NONE ctermbg=LightGrey" | |
7132 : "Visual cterm=NONE ctermbg=DarkGrey"), FALSE, TRUE); | |
836 | 7133 else |
844 | 7134 { |
1697 | 7135 do_highlight((char_u *)"Visual cterm=reverse ctermbg=NONE", |
7136 FALSE, TRUE); | |
844 | 7137 if (*p_bg == 'l') |
7138 do_highlight((char_u *)"Search ctermfg=black", FALSE, TRUE); | |
7139 } | |
527 | 7140 |
7 | 7141 #ifdef FEAT_SYN_HL |
7142 /* | |
7143 * If syntax highlighting is enabled load the highlighting for it. | |
7144 */ | |
7145 if (get_var_value((char_u *)"g:syntax_on") != NULL) | |
24 | 7146 { |
7147 static int recursive = 0; | |
7148 | |
7149 if (recursive >= 5) | |
7150 EMSG(_("E679: recursive loop loading syncolor.vim")); | |
7151 else | |
7152 { | |
7153 ++recursive; | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
7154 (void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL); |
24 | 7155 --recursive; |
7156 } | |
7157 } | |
7 | 7158 #endif |
7159 } | |
7160 | |
7161 /* | |
12 | 7162 * Load color file "name". |
7 | 7163 * Return OK for success, FAIL for failure. |
7164 */ | |
7165 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7166 load_colors(char_u *name) |
7 | 7167 { |
7168 char_u *buf; | |
7169 int retval = FAIL; | |
7170 static int recursive = FALSE; | |
7171 | |
7172 /* When being called recursively, this is probably because setting | |
7173 * 'background' caused the highlighting to be reloaded. This means it is | |
7174 * working, thus we should return OK. */ | |
7175 if (recursive) | |
7176 return OK; | |
7177 | |
7178 recursive = TRUE; | |
12 | 7179 buf = alloc((unsigned)(STRLEN(name) + 12)); |
7 | 7180 if (buf != NULL) |
7181 { | |
12 | 7182 sprintf((char *)buf, "colors/%s.vim", name); |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
7183 retval = source_runtime(buf, DIP_START + DIP_OPT); |
7 | 7184 vim_free(buf); |
12 | 7185 #ifdef FEAT_AUTOCMD |
5521 | 7186 apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); |
12 | 7187 #endif |
7 | 7188 } |
7189 recursive = FALSE; | |
7190 | |
7191 return retval; | |
7192 } | |
7193 | |
7194 /* | |
7195 * Handle the ":highlight .." command. | |
7196 * When using ":hi clear" this is called recursively for each group with | |
7197 * "forceit" and "init" both TRUE. | |
7198 */ | |
7199 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7200 do_highlight( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7201 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7202 int forceit, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7203 int init) /* TRUE when called for initializing */ |
7 | 7204 { |
7205 char_u *name_end; | |
7206 char_u *p; | |
7207 char_u *linep; | |
7208 char_u *key_start; | |
7209 char_u *arg_start; | |
7210 char_u *key = NULL, *arg = NULL; | |
7211 long i; | |
7212 int off; | |
7213 int len; | |
7214 int attr; | |
7215 int id; | |
7216 int idx; | |
7217 int dodefault = FALSE; | |
7218 int doclear = FALSE; | |
7219 int dolink = FALSE; | |
7220 int error = FALSE; | |
7221 int color; | |
7222 int is_normal_group = FALSE; /* "Normal" group */ | |
7223 #ifdef FEAT_GUI_X11 | |
7224 int is_menu_group = FALSE; /* "Menu" group */ | |
7225 int is_scrollbar_group = FALSE; /* "Scrollbar" group */ | |
7226 int is_tooltip_group = FALSE; /* "Tooltip" group */ | |
7227 int do_colors = FALSE; /* need to update colors? */ | |
7228 #else | |
7229 # define is_menu_group 0 | |
7230 # define is_tooltip_group 0 | |
7231 #endif | |
7232 | |
7233 /* | |
7234 * If no argument, list current highlighting. | |
7235 */ | |
7236 if (ends_excmd(*line)) | |
7237 { | |
7238 for (i = 1; i <= highlight_ga.ga_len && !got_int; ++i) | |
7239 /* TODO: only call when the group has attributes set */ | |
7240 highlight_list_one((int)i); | |
7241 return; | |
7242 } | |
7243 | |
7244 /* | |
7245 * Isolate the name. | |
7246 */ | |
7247 name_end = skiptowhite(line); | |
7248 linep = skipwhite(name_end); | |
7249 | |
7250 /* | |
7251 * Check for "default" argument. | |
7252 */ | |
7253 if (STRNCMP(line, "default", name_end - line) == 0) | |
7254 { | |
7255 dodefault = TRUE; | |
7256 line = linep; | |
7257 name_end = skiptowhite(line); | |
7258 linep = skipwhite(name_end); | |
7259 } | |
7260 | |
7261 /* | |
7262 * Check for "clear" or "link" argument. | |
7263 */ | |
7264 if (STRNCMP(line, "clear", name_end - line) == 0) | |
7265 doclear = TRUE; | |
7266 if (STRNCMP(line, "link", name_end - line) == 0) | |
7267 dolink = TRUE; | |
7268 | |
7269 /* | |
7270 * ":highlight {group-name}": list highlighting for one group. | |
7271 */ | |
7272 if (!doclear && !dolink && ends_excmd(*linep)) | |
7273 { | |
7274 id = syn_namen2id(line, (int)(name_end - line)); | |
7275 if (id == 0) | |
7276 EMSG2(_("E411: highlight group not found: %s"), line); | |
7277 else | |
7278 highlight_list_one(id); | |
7279 return; | |
7280 } | |
7281 | |
7282 /* | |
7283 * Handle ":highlight link {from} {to}" command. | |
7284 */ | |
7285 if (dolink) | |
7286 { | |
7287 char_u *from_start = linep; | |
7288 char_u *from_end; | |
7289 char_u *to_start; | |
7290 char_u *to_end; | |
7291 int from_id; | |
7292 int to_id; | |
7293 | |
7294 from_end = skiptowhite(from_start); | |
7295 to_start = skipwhite(from_end); | |
7296 to_end = skiptowhite(to_start); | |
7297 | |
7298 if (ends_excmd(*from_start) || ends_excmd(*to_start)) | |
7299 { | |
7300 EMSG2(_("E412: Not enough arguments: \":highlight link %s\""), | |
7301 from_start); | |
7302 return; | |
7303 } | |
7304 | |
7305 if (!ends_excmd(*skipwhite(to_end))) | |
7306 { | |
7307 EMSG2(_("E413: Too many arguments: \":highlight link %s\""), from_start); | |
7308 return; | |
7309 } | |
7310 | |
7311 from_id = syn_check_group(from_start, (int)(from_end - from_start)); | |
7312 if (STRNCMP(to_start, "NONE", 4) == 0) | |
7313 to_id = 0; | |
7314 else | |
7315 to_id = syn_check_group(to_start, (int)(to_end - to_start)); | |
7316 | |
7317 if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0)) | |
7318 { | |
7319 /* | |
7320 * Don't allow a link when there already is some highlighting | |
7321 * for the group, unless '!' is used | |
7322 */ | |
7323 if (to_id > 0 && !forceit && !init | |
7324 && hl_has_settings(from_id - 1, dodefault)) | |
7325 { | |
7326 if (sourcing_name == NULL && !dodefault) | |
7327 EMSG(_("E414: group has settings, highlight link ignored")); | |
7328 } | |
7329 else | |
7330 { | |
7331 if (!init) | |
7332 HL_TABLE()[from_id - 1].sg_set |= SG_LINK; | |
7333 HL_TABLE()[from_id - 1].sg_link = to_id; | |
448 | 7334 #ifdef FEAT_EVAL |
7335 HL_TABLE()[from_id - 1].sg_scriptID = current_SID; | |
7336 #endif | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
7337 HL_TABLE()[from_id - 1].sg_cleared = FALSE; |
745 | 7338 redraw_all_later(SOME_VALID); |
7 | 7339 } |
7340 } | |
7341 | |
7342 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
7343 need_highlight_changed = TRUE; | |
7344 | |
7345 return; | |
7346 } | |
7347 | |
7348 if (doclear) | |
7349 { | |
7350 /* | |
7351 * ":highlight clear [group]" command. | |
7352 */ | |
7353 line = linep; | |
7354 if (ends_excmd(*line)) | |
7355 { | |
7356 #ifdef FEAT_GUI | |
7357 /* First, we do not destroy the old values, but allocate the new | |
7358 * ones and update the display. THEN we destroy the old values. | |
7359 * If we destroy the old values first, then the old values | |
7360 * (such as GuiFont's or GuiFontset's) will still be displayed but | |
7361 * invalid because they were free'd. | |
7362 */ | |
7363 if (gui.in_use) | |
7364 { | |
7365 # ifdef FEAT_BEVAL_TIP | |
7366 gui_init_tooltip_font(); | |
7367 # endif | |
7368 # if defined(FEAT_MENU) && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF)) | |
7369 gui_init_menu_font(); | |
7370 # endif | |
7371 } | |
7372 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_X11) | |
7373 gui_mch_def_colors(); | |
7374 # endif | |
7375 # ifdef FEAT_GUI_X11 | |
7376 # ifdef FEAT_MENU | |
7377 | |
7378 /* This only needs to be done when there is no Menu highlight | |
7379 * group defined by default, which IS currently the case. | |
7380 */ | |
7381 gui_mch_new_menu_colors(); | |
7382 # endif | |
7383 if (gui.in_use) | |
7384 { | |
7385 gui_new_scrollbar_colors(); | |
7386 # ifdef FEAT_BEVAL | |
7387 gui_mch_new_tooltip_colors(); | |
7388 # endif | |
7389 # ifdef FEAT_MENU | |
7390 gui_mch_new_menu_font(); | |
7391 # endif | |
7392 } | |
7393 # endif | |
7394 | |
7395 /* Ok, we're done allocating the new default graphics items. | |
7396 * The screen should already be refreshed at this point. | |
7397 * It is now Ok to clear out the old data. | |
7398 */ | |
7399 #endif | |
7400 #ifdef FEAT_EVAL | |
148 | 7401 do_unlet((char_u *)"colors_name", TRUE); |
7 | 7402 #endif |
7403 restore_cterm_colors(); | |
7404 | |
7405 /* | |
7406 * Clear all default highlight groups and load the defaults. | |
7407 */ | |
7408 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
7409 highlight_clear(idx); | |
7410 init_highlight(TRUE, TRUE); | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7411 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
7412 if (USE_24BIT) |
7 | 7413 highlight_gui_started(); |
7414 #endif | |
7415 highlight_changed(); | |
7416 redraw_later_clear(); | |
7417 return; | |
7418 } | |
7419 name_end = skiptowhite(line); | |
7420 linep = skipwhite(name_end); | |
7421 } | |
7422 | |
7423 /* | |
7424 * Find the group name in the table. If it does not exist yet, add it. | |
7425 */ | |
7426 id = syn_check_group(line, (int)(name_end - line)); | |
7427 if (id == 0) /* failed (out of memory) */ | |
7428 return; | |
7429 idx = id - 1; /* index is ID minus one */ | |
7430 | |
7431 /* Return if "default" was used and the group already has settings. */ | |
7432 if (dodefault && hl_has_settings(idx, TRUE)) | |
7433 return; | |
7434 | |
7435 if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0) | |
7436 is_normal_group = TRUE; | |
7437 #ifdef FEAT_GUI_X11 | |
7438 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0) | |
7439 is_menu_group = TRUE; | |
7440 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "SCROLLBAR") == 0) | |
7441 is_scrollbar_group = TRUE; | |
7442 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "TOOLTIP") == 0) | |
7443 is_tooltip_group = TRUE; | |
7444 #endif | |
7445 | |
7446 /* Clear the highlighting for ":hi clear {group}" and ":hi clear". */ | |
7447 if (doclear || (forceit && init)) | |
7448 { | |
7449 highlight_clear(idx); | |
7450 if (!doclear) | |
7451 HL_TABLE()[idx].sg_set = 0; | |
7452 } | |
7453 | |
7454 if (!doclear) | |
7455 while (!ends_excmd(*linep)) | |
7456 { | |
7457 key_start = linep; | |
7458 if (*linep == '=') | |
7459 { | |
7460 EMSG2(_("E415: unexpected equal sign: %s"), key_start); | |
7461 error = TRUE; | |
7462 break; | |
7463 } | |
7464 | |
7465 /* | |
7466 * Isolate the key ("term", "ctermfg", "ctermbg", "font", "guifg" or | |
7467 * "guibg"). | |
7468 */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
7469 while (*linep && !VIM_ISWHITE(*linep) && *linep != '=') |
7 | 7470 ++linep; |
7471 vim_free(key); | |
7472 key = vim_strnsave_up(key_start, (int)(linep - key_start)); | |
7473 if (key == NULL) | |
7474 { | |
7475 error = TRUE; | |
7476 break; | |
7477 } | |
7478 linep = skipwhite(linep); | |
7479 | |
7480 if (STRCMP(key, "NONE") == 0) | |
7481 { | |
7482 if (!init || HL_TABLE()[idx].sg_set == 0) | |
7483 { | |
7484 if (!init) | |
7485 HL_TABLE()[idx].sg_set |= SG_TERM+SG_CTERM+SG_GUI; | |
7486 highlight_clear(idx); | |
7487 } | |
7488 continue; | |
7489 } | |
7490 | |
7491 /* | |
7492 * Check for the equal sign. | |
7493 */ | |
7494 if (*linep != '=') | |
7495 { | |
7496 EMSG2(_("E416: missing equal sign: %s"), key_start); | |
7497 error = TRUE; | |
7498 break; | |
7499 } | |
7500 ++linep; | |
7501 | |
7502 /* | |
7503 * Isolate the argument. | |
7504 */ | |
7505 linep = skipwhite(linep); | |
7506 if (*linep == '\'') /* guifg='color name' */ | |
7507 { | |
7508 arg_start = ++linep; | |
7509 linep = vim_strchr(linep, '\''); | |
7510 if (linep == NULL) | |
7511 { | |
7512 EMSG2(_(e_invarg2), key_start); | |
7513 error = TRUE; | |
7514 break; | |
7515 } | |
7516 } | |
7517 else | |
7518 { | |
7519 arg_start = linep; | |
7520 linep = skiptowhite(linep); | |
7521 } | |
7522 if (linep == arg_start) | |
7523 { | |
7524 EMSG2(_("E417: missing argument: %s"), key_start); | |
7525 error = TRUE; | |
7526 break; | |
7527 } | |
7528 vim_free(arg); | |
7529 arg = vim_strnsave(arg_start, (int)(linep - arg_start)); | |
7530 if (arg == NULL) | |
7531 { | |
7532 error = TRUE; | |
7533 break; | |
7534 } | |
7535 if (*linep == '\'') | |
7536 ++linep; | |
7537 | |
7538 /* | |
7539 * Store the argument. | |
7540 */ | |
7541 if ( STRCMP(key, "TERM") == 0 | |
7542 || STRCMP(key, "CTERM") == 0 | |
7543 || STRCMP(key, "GUI") == 0) | |
7544 { | |
7545 attr = 0; | |
7546 off = 0; | |
7547 while (arg[off] != NUL) | |
7548 { | |
7549 for (i = sizeof(hl_attr_table) / sizeof(int); --i >= 0; ) | |
7550 { | |
7551 len = (int)STRLEN(hl_name_table[i]); | |
7552 if (STRNICMP(arg + off, hl_name_table[i], len) == 0) | |
7553 { | |
7554 attr |= hl_attr_table[i]; | |
7555 off += len; | |
7556 break; | |
7557 } | |
7558 } | |
7559 if (i < 0) | |
7560 { | |
7561 EMSG2(_("E418: Illegal value: %s"), arg); | |
7562 error = TRUE; | |
7563 break; | |
7564 } | |
7565 if (arg[off] == ',') /* another one follows */ | |
7566 ++off; | |
7567 } | |
7568 if (error) | |
7569 break; | |
7570 if (*key == 'T') | |
7571 { | |
7572 if (!init || !(HL_TABLE()[idx].sg_set & SG_TERM)) | |
7573 { | |
7574 if (!init) | |
7575 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7576 HL_TABLE()[idx].sg_term = attr; | |
7577 } | |
7578 } | |
7579 else if (*key == 'C') | |
7580 { | |
7581 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7582 { | |
7583 if (!init) | |
7584 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7585 HL_TABLE()[idx].sg_cterm = attr; | |
7586 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7587 } | |
7588 } | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7589 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 7590 else |
7591 { | |
7592 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) | |
7593 { | |
7594 if (!init) | |
7595 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7596 HL_TABLE()[idx].sg_gui = attr; | |
7597 } | |
7598 } | |
7599 #endif | |
7600 } | |
7601 else if (STRCMP(key, "FONT") == 0) | |
7602 { | |
7603 /* in non-GUI fonts are simply ignored */ | |
7604 #ifdef FEAT_GUI | |
7605 if (!gui.shell_created) | |
7606 { | |
7607 /* GUI not started yet, always accept the name. */ | |
7608 vim_free(HL_TABLE()[idx].sg_font_name); | |
7609 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7610 } | |
7611 else | |
7612 { | |
7613 GuiFont temp_sg_font = HL_TABLE()[idx].sg_font; | |
7614 # ifdef FEAT_XFONTSET | |
7615 GuiFontset temp_sg_fontset = HL_TABLE()[idx].sg_fontset; | |
7616 # endif | |
7617 /* First, save the current font/fontset. | |
7618 * Then try to allocate the font/fontset. | |
7619 * If the allocation fails, HL_TABLE()[idx].sg_font OR | |
7620 * sg_fontset will be set to NOFONT or NOFONTSET respectively. | |
7621 */ | |
7622 | |
7623 HL_TABLE()[idx].sg_font = NOFONT; | |
7624 # ifdef FEAT_XFONTSET | |
7625 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
7626 # endif | |
7627 hl_do_font(idx, arg, is_normal_group, is_menu_group, | |
3881 | 7628 is_tooltip_group, FALSE); |
7 | 7629 |
7630 # ifdef FEAT_XFONTSET | |
7631 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) | |
7632 { | |
3881 | 7633 /* New fontset was accepted. Free the old one, if there |
7634 * was one. */ | |
7 | 7635 gui_mch_free_fontset(temp_sg_fontset); |
7636 vim_free(HL_TABLE()[idx].sg_font_name); | |
7637 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7638 } | |
7639 else | |
7640 HL_TABLE()[idx].sg_fontset = temp_sg_fontset; | |
7641 # endif | |
7642 if (HL_TABLE()[idx].sg_font != NOFONT) | |
7643 { | |
7644 /* New font was accepted. Free the old one, if there was | |
3881 | 7645 * one. */ |
7 | 7646 gui_mch_free_font(temp_sg_font); |
7647 vim_free(HL_TABLE()[idx].sg_font_name); | |
7648 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7649 } | |
7650 else | |
7651 HL_TABLE()[idx].sg_font = temp_sg_font; | |
7652 } | |
7653 #endif | |
7654 } | |
7655 else if (STRCMP(key, "CTERMFG") == 0 || STRCMP(key, "CTERMBG") == 0) | |
7656 { | |
7657 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7658 { | |
7659 if (!init) | |
7660 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7661 | |
7662 /* When setting the foreground color, and previously the "bold" | |
7663 * flag was set for a light color, reset it now */ | |
7664 if (key[5] == 'F' && HL_TABLE()[idx].sg_cterm_bold) | |
7665 { | |
7666 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7667 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7668 } | |
7669 | |
7670 if (VIM_ISDIGIT(*arg)) | |
7671 color = atoi((char *)arg); | |
7672 else if (STRICMP(arg, "fg") == 0) | |
7673 { | |
7674 if (cterm_normal_fg_color) | |
7675 color = cterm_normal_fg_color - 1; | |
7676 else | |
7677 { | |
7678 EMSG(_("E419: FG color unknown")); | |
7679 error = TRUE; | |
7680 break; | |
7681 } | |
7682 } | |
7683 else if (STRICMP(arg, "bg") == 0) | |
7684 { | |
7685 if (cterm_normal_bg_color > 0) | |
7686 color = cterm_normal_bg_color - 1; | |
7687 else | |
7688 { | |
7689 EMSG(_("E420: BG color unknown")); | |
7690 error = TRUE; | |
7691 break; | |
7692 } | |
7693 } | |
7694 else | |
7695 { | |
7696 static char *(color_names[28]) = { | |
7697 "Black", "DarkBlue", "DarkGreen", "DarkCyan", | |
7698 "DarkRed", "DarkMagenta", "Brown", "DarkYellow", | |
7699 "Gray", "Grey", | |
7700 "LightGray", "LightGrey", "DarkGray", "DarkGrey", | |
7701 "Blue", "LightBlue", "Green", "LightGreen", | |
7702 "Cyan", "LightCyan", "Red", "LightRed", "Magenta", | |
7703 "LightMagenta", "Yellow", "LightYellow", "White", "NONE"}; | |
7704 static int color_numbers_16[28] = {0, 1, 2, 3, | |
7705 4, 5, 6, 6, | |
7706 7, 7, | |
7707 7, 7, 8, 8, | |
7708 9, 9, 10, 10, | |
7709 11, 11, 12, 12, 13, | |
7710 13, 14, 14, 15, -1}; | |
7711 /* for xterm with 88 colors... */ | |
7712 static int color_numbers_88[28] = {0, 4, 2, 6, | |
7713 1, 5, 32, 72, | |
7714 84, 84, | |
7715 7, 7, 82, 82, | |
7716 12, 43, 10, 61, | |
7717 14, 63, 9, 74, 13, | |
7718 75, 11, 78, 15, -1}; | |
7719 /* for xterm with 256 colors... */ | |
7720 static int color_numbers_256[28] = {0, 4, 2, 6, | |
7721 1, 5, 130, 130, | |
7722 248, 248, | |
7723 7, 7, 242, 242, | |
7724 12, 81, 10, 121, | |
7725 14, 159, 9, 224, 13, | |
7726 225, 11, 229, 15, -1}; | |
7727 /* for terminals with less than 16 colors... */ | |
7728 static int color_numbers_8[28] = {0, 4, 2, 6, | |
7729 1, 5, 3, 3, | |
7730 7, 7, | |
7731 7, 7, 0+8, 0+8, | |
7732 4+8, 4+8, 2+8, 2+8, | |
7733 6+8, 6+8, 1+8, 1+8, 5+8, | |
7734 5+8, 3+8, 3+8, 7+8, -1}; | |
7735 #if defined(__QNXNTO__) | |
7736 static int *color_numbers_8_qansi = color_numbers_8; | |
7737 /* On qnx, the 8 & 16 color arrays are the same */ | |
7738 if (STRNCMP(T_NAME, "qansi", 5) == 0) | |
7739 color_numbers_8_qansi = color_numbers_16; | |
7740 #endif | |
7741 | |
7742 /* reduce calls to STRICMP a bit, it can be slow */ | |
7743 off = TOUPPER_ASC(*arg); | |
7744 for (i = (sizeof(color_names) / sizeof(char *)); --i >= 0; ) | |
7745 if (off == color_names[i][0] | |
7746 && STRICMP(arg + 1, color_names[i] + 1) == 0) | |
7747 break; | |
7748 if (i < 0) | |
7749 { | |
7750 EMSG2(_("E421: Color name or number not recognized: %s"), key_start); | |
7751 error = TRUE; | |
7752 break; | |
7753 } | |
7754 | |
7755 /* Use the _16 table to check if its a valid color name. */ | |
7756 color = color_numbers_16[i]; | |
7757 if (color >= 0) | |
7758 { | |
7759 if (t_colors == 8) | |
7760 { | |
7761 /* t_Co is 8: use the 8 colors table */ | |
7762 #if defined(__QNXNTO__) | |
7763 color = color_numbers_8_qansi[i]; | |
7764 #else | |
7765 color = color_numbers_8[i]; | |
7766 #endif | |
7767 if (key[5] == 'F') | |
7768 { | |
7769 /* set/reset bold attribute to get light foreground | |
7770 * colors (on some terminals, e.g. "linux") */ | |
7771 if (color & 8) | |
7772 { | |
7773 HL_TABLE()[idx].sg_cterm |= HL_BOLD; | |
7774 HL_TABLE()[idx].sg_cterm_bold = TRUE; | |
7775 } | |
7776 else | |
7777 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7778 } | |
7779 color &= 7; /* truncate to 8 colors */ | |
7780 } | |
7781 else if (t_colors == 16 || t_colors == 88 | |
7467
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7782 || t_colors >= 256) |
7 | 7783 { |
7784 /* | |
7785 * Guess: if the termcap entry ends in 'm', it is | |
7786 * probably an xterm-like terminal. Use the changed | |
7787 * order for colors. | |
7788 */ | |
7789 if (*T_CAF != NUL) | |
7790 p = T_CAF; | |
7791 else | |
7792 p = T_CSF; | |
7467
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7793 if (*p != NUL && (t_colors > 256 |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7794 || *(p + STRLEN(p) - 1) == 'm')) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7795 { |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7796 if (t_colors == 88) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7797 color = color_numbers_88[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7798 else if (t_colors >= 256) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7799 color = color_numbers_256[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7800 else |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7801 color = color_numbers_8[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7802 } |
7 | 7803 } |
7804 } | |
7805 } | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7806 /* 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
|
7807 * "NONE", then "color" is -1. */ |
7 | 7808 if (key[5] == 'F') |
7809 { | |
7810 HL_TABLE()[idx].sg_cterm_fg = color + 1; | |
7811 if (is_normal_group) | |
7812 { | |
7813 cterm_normal_fg_color = color + 1; | |
7814 cterm_normal_fg_bold = (HL_TABLE()[idx].sg_cterm & HL_BOLD); | |
7815 #ifdef FEAT_GUI | |
7816 /* Don't do this if the GUI is used. */ | |
7817 if (!gui.in_use && !gui.starting) | |
7818 #endif | |
7819 { | |
7820 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7821 if (termcap_active && color >= 0) |
7 | 7822 term_fg_color(color); |
7823 } | |
7824 } | |
7825 } | |
7826 else | |
7827 { | |
7828 HL_TABLE()[idx].sg_cterm_bg = color + 1; | |
7829 if (is_normal_group) | |
7830 { | |
7831 cterm_normal_bg_color = color + 1; | |
7832 #ifdef FEAT_GUI | |
7833 /* Don't mess with 'background' if the GUI is used. */ | |
7834 if (!gui.in_use && !gui.starting) | |
7835 #endif | |
7836 { | |
7837 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7838 if (color >= 0) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7839 { |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7840 if (termcap_active) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7841 term_bg_color(color); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7842 if (t_colors < 16) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7843 i = (color == 0 || color == 4); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7844 else |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7845 i = (color < 7 || color == 8); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7846 /* Set the 'background' option if the value is |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7847 * wrong. */ |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7848 if (i != (*p_bg == 'd')) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7849 set_option_value((char_u *)"bg", 0L, |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7850 i ? (char_u *)"dark" |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7851 : (char_u *)"light", 0); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7852 } |
7 | 7853 } |
7854 } | |
7855 } | |
7856 } | |
7857 } | |
7858 else if (STRCMP(key, "GUIFG") == 0) | |
7859 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7860 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7861 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7862 { |
205 | 7863 if (!init) |
7864 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7865 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7866 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7867 /* In GUI guifg colors are only used when recognized */ |
205 | 7868 i = color_name2handle(arg); |
9029
f06767547415
commit https://github.com/vim/vim/commit/631225627d448b591e529a5d3e7ac74ef44b8459
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
7869 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) |
205 | 7870 { |
7871 HL_TABLE()[idx].sg_gui_fg = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7872 # endif |
205 | 7873 vim_free(HL_TABLE()[idx].sg_gui_fg_name); |
7874 if (STRCMP(arg, "NONE")) | |
7875 HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg); | |
7876 else | |
7877 HL_TABLE()[idx].sg_gui_fg_name = NULL; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7878 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7879 # ifdef FEAT_GUI_X11 |
205 | 7880 if (is_menu_group) |
7881 gui.menu_fg_pixel = i; | |
7882 if (is_scrollbar_group) | |
7883 gui.scroll_fg_pixel = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7884 # ifdef FEAT_BEVAL |
205 | 7885 if (is_tooltip_group) |
7886 gui.tooltip_fg_pixel = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7887 # endif |
205 | 7888 do_colors = TRUE; |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7889 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7890 } |
7 | 7891 # endif |
7892 } | |
7893 #endif | |
7894 } | |
7895 else if (STRCMP(key, "GUIBG") == 0) | |
7896 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7897 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7898 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7899 { |
205 | 7900 if (!init) |
7901 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7902 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7903 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7904 /* In GUI guifg colors are only used when recognized */ |
205 | 7905 i = color_name2handle(arg); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
7906 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) |
205 | 7907 { |
7908 HL_TABLE()[idx].sg_gui_bg = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7909 # endif |
205 | 7910 vim_free(HL_TABLE()[idx].sg_gui_bg_name); |
7911 if (STRCMP(arg, "NONE") != 0) | |
7912 HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg); | |
7913 else | |
7914 HL_TABLE()[idx].sg_gui_bg_name = NULL; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7915 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7916 # ifdef FEAT_GUI_X11 |
205 | 7917 if (is_menu_group) |
7918 gui.menu_bg_pixel = i; | |
7919 if (is_scrollbar_group) | |
7920 gui.scroll_bg_pixel = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7921 # ifdef FEAT_BEVAL |
205 | 7922 if (is_tooltip_group) |
7923 gui.tooltip_bg_pixel = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7924 # endif |
205 | 7925 do_colors = TRUE; |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7926 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7927 } |
7 | 7928 # endif |
7929 } | |
205 | 7930 #endif |
7931 } | |
7932 else if (STRCMP(key, "GUISP") == 0) | |
7933 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7934 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7935 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7936 { | |
7937 if (!init) | |
7938 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7939 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7940 # ifdef FEAT_GUI |
205 | 7941 i = color_name2handle(arg); |
7942 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) | |
7943 { | |
7944 HL_TABLE()[idx].sg_gui_sp = i; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7945 # endif |
205 | 7946 vim_free(HL_TABLE()[idx].sg_gui_sp_name); |
7947 if (STRCMP(arg, "NONE") != 0) | |
7948 HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg); | |
7949 else | |
7950 HL_TABLE()[idx].sg_gui_sp_name = NULL; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7951 # ifdef FEAT_GUI |
205 | 7952 } |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7953 # endif |
205 | 7954 } |
7 | 7955 #endif |
7956 } | |
7957 else if (STRCMP(key, "START") == 0 || STRCMP(key, "STOP") == 0) | |
7958 { | |
7959 char_u buf[100]; | |
7960 char_u *tname; | |
7961 | |
7962 if (!init) | |
7963 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7964 | |
7965 /* | |
7966 * The "start" and "stop" arguments can be a literal escape | |
1222 | 7967 * sequence, or a comma separated list of terminal codes. |
7 | 7968 */ |
7969 if (STRNCMP(arg, "t_", 2) == 0) | |
7970 { | |
7971 off = 0; | |
7972 buf[0] = 0; | |
7973 while (arg[off] != NUL) | |
7974 { | |
7975 /* Isolate one termcap name */ | |
7976 for (len = 0; arg[off + len] && | |
7977 arg[off + len] != ','; ++len) | |
7978 ; | |
7979 tname = vim_strnsave(arg + off, len); | |
7980 if (tname == NULL) /* out of memory */ | |
7981 { | |
7982 error = TRUE; | |
7983 break; | |
7984 } | |
7985 /* lookup the escape sequence for the item */ | |
7986 p = get_term_code(tname); | |
7987 vim_free(tname); | |
7988 if (p == NULL) /* ignore non-existing things */ | |
7989 p = (char_u *)""; | |
7990 | |
7991 /* Append it to the already found stuff */ | |
7992 if ((int)(STRLEN(buf) + STRLEN(p)) >= 99) | |
7993 { | |
7994 EMSG2(_("E422: terminal code too long: %s"), arg); | |
7995 error = TRUE; | |
7996 break; | |
7997 } | |
7998 STRCAT(buf, p); | |
7999 | |
8000 /* Advance to the next item */ | |
8001 off += len; | |
8002 if (arg[off] == ',') /* another one follows */ | |
8003 ++off; | |
8004 } | |
8005 } | |
8006 else | |
8007 { | |
8008 /* | |
8009 * Copy characters from arg[] to buf[], translating <> codes. | |
8010 */ | |
2593 | 8011 for (p = arg, off = 0; off < 100 - 6 && *p; ) |
7 | 8012 { |
9869
989d44d35a66
commit https://github.com/vim/vim/commit/35a4cfa200917dd171b1fff3cd5b6cee9add673d
Christian Brabandt <cb@256bit.org>
parents:
9141
diff
changeset
|
8013 len = trans_special(&p, buf + off, FALSE, FALSE); |
2593 | 8014 if (len > 0) /* recognized special char */ |
7 | 8015 off += len; |
8016 else /* copy as normal char */ | |
8017 buf[off++] = *p++; | |
8018 } | |
8019 buf[off] = NUL; | |
8020 } | |
8021 if (error) | |
8022 break; | |
8023 | |
8024 if (STRCMP(buf, "NONE") == 0) /* resetting the value */ | |
8025 p = NULL; | |
8026 else | |
8027 p = vim_strsave(buf); | |
8028 if (key[2] == 'A') | |
8029 { | |
8030 vim_free(HL_TABLE()[idx].sg_start); | |
8031 HL_TABLE()[idx].sg_start = p; | |
8032 } | |
8033 else | |
8034 { | |
8035 vim_free(HL_TABLE()[idx].sg_stop); | |
8036 HL_TABLE()[idx].sg_stop = p; | |
8037 } | |
8038 } | |
8039 else | |
8040 { | |
8041 EMSG2(_("E423: Illegal argument: %s"), key_start); | |
8042 error = TRUE; | |
8043 break; | |
8044 } | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8045 HL_TABLE()[idx].sg_cleared = FALSE; |
7 | 8046 |
8047 /* | |
8048 * When highlighting has been given for a group, don't link it. | |
8049 */ | |
8050 if (!init || !(HL_TABLE()[idx].sg_set & SG_LINK)) | |
8051 HL_TABLE()[idx].sg_link = 0; | |
8052 | |
8053 /* | |
8054 * Continue with next argument. | |
8055 */ | |
8056 linep = skipwhite(linep); | |
8057 } | |
8058 | |
8059 /* | |
8060 * If there is an error, and it's a new entry, remove it from the table. | |
8061 */ | |
8062 if (error && idx == highlight_ga.ga_len) | |
8063 syn_unadd_group(); | |
8064 else | |
8065 { | |
8066 if (is_normal_group) | |
8067 { | |
8068 HL_TABLE()[idx].sg_term_attr = 0; | |
8069 HL_TABLE()[idx].sg_cterm_attr = 0; | |
8070 #ifdef FEAT_GUI | |
8071 HL_TABLE()[idx].sg_gui_attr = 0; | |
8072 /* | |
8073 * Need to update all groups, because they might be using "bg" | |
8074 * and/or "fg", which have been changed now. | |
8075 */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8076 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8077 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8078 if (USE_24BIT) |
7 | 8079 highlight_gui_started(); |
8080 #endif | |
8081 } | |
8082 #ifdef FEAT_GUI_X11 | |
8083 # ifdef FEAT_MENU | |
8084 else if (is_menu_group) | |
8085 { | |
8086 if (gui.in_use && do_colors) | |
8087 gui_mch_new_menu_colors(); | |
8088 } | |
8089 # endif | |
8090 else if (is_scrollbar_group) | |
8091 { | |
8092 if (gui.in_use && do_colors) | |
8093 gui_new_scrollbar_colors(); | |
8094 } | |
8095 # ifdef FEAT_BEVAL | |
8096 else if (is_tooltip_group) | |
8097 { | |
8098 if (gui.in_use && do_colors) | |
8099 gui_mch_new_tooltip_colors(); | |
8100 } | |
8101 # endif | |
8102 #endif | |
8103 else | |
8104 set_hl_attr(idx); | |
448 | 8105 #ifdef FEAT_EVAL |
8106 HL_TABLE()[idx].sg_scriptID = current_SID; | |
8107 #endif | |
819 | 8108 redraw_all_later(NOT_VALID); |
7 | 8109 } |
8110 vim_free(key); | |
8111 vim_free(arg); | |
8112 | |
8113 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
8114 need_highlight_changed = TRUE; | |
8115 } | |
8116 | |
356 | 8117 #if defined(EXITFREE) || defined(PROTO) |
8118 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8119 free_highlight(void) |
356 | 8120 { |
8121 int i; | |
8122 | |
8123 for (i = 0; i < highlight_ga.ga_len; ++i) | |
359 | 8124 { |
356 | 8125 highlight_clear(i); |
359 | 8126 vim_free(HL_TABLE()[i].sg_name); |
8127 vim_free(HL_TABLE()[i].sg_name_u); | |
8128 } | |
356 | 8129 ga_clear(&highlight_ga); |
8130 } | |
8131 #endif | |
8132 | |
7 | 8133 /* |
8134 * Reset the cterm colors to what they were before Vim was started, if | |
8135 * possible. Otherwise reset them to zero. | |
8136 */ | |
8137 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8138 restore_cterm_colors(void) |
7 | 8139 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
8140 #if defined(WIN3264) && !defined(FEAT_GUI_W32) |
7 | 8141 /* Since t_me has been set, this probably means that the user |
8142 * wants to use this as default colors. Need to reset default | |
8143 * background/foreground colors. */ | |
8144 mch_set_normal_colors(); | |
8145 #else | |
8146 cterm_normal_fg_color = 0; | |
8147 cterm_normal_fg_bold = 0; | |
8148 cterm_normal_bg_color = 0; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8149 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8150 cterm_normal_fg_gui_color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8151 cterm_normal_bg_gui_color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8152 # endif |
7 | 8153 #endif |
8154 } | |
8155 | |
8156 /* | |
8157 * Return TRUE if highlight group "idx" has any settings. | |
8158 * When "check_link" is TRUE also check for an existing link. | |
8159 */ | |
8160 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8161 hl_has_settings(int idx, int check_link) |
7 | 8162 { |
8163 return ( HL_TABLE()[idx].sg_term_attr != 0 | |
8164 || HL_TABLE()[idx].sg_cterm_attr != 0 | |
5954 | 8165 || HL_TABLE()[idx].sg_cterm_fg != 0 |
8166 || HL_TABLE()[idx].sg_cterm_bg != 0 | |
7 | 8167 #ifdef FEAT_GUI |
8168 || HL_TABLE()[idx].sg_gui_attr != 0 | |
5954 | 8169 || HL_TABLE()[idx].sg_gui_fg_name != NULL |
8170 || HL_TABLE()[idx].sg_gui_bg_name != NULL | |
8171 || HL_TABLE()[idx].sg_gui_sp_name != NULL | |
11119
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
11073
diff
changeset
|
8172 || HL_TABLE()[idx].sg_font_name != NULL |
7 | 8173 #endif |
8174 || (check_link && (HL_TABLE()[idx].sg_set & SG_LINK))); | |
8175 } | |
8176 | |
8177 /* | |
8178 * Clear highlighting for one group. | |
8179 */ | |
8180 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8181 highlight_clear(int idx) |
7 | 8182 { |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8183 HL_TABLE()[idx].sg_cleared = TRUE; |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8184 |
7 | 8185 HL_TABLE()[idx].sg_term = 0; |
8186 vim_free(HL_TABLE()[idx].sg_start); | |
8187 HL_TABLE()[idx].sg_start = NULL; | |
8188 vim_free(HL_TABLE()[idx].sg_stop); | |
8189 HL_TABLE()[idx].sg_stop = NULL; | |
8190 HL_TABLE()[idx].sg_term_attr = 0; | |
8191 HL_TABLE()[idx].sg_cterm = 0; | |
8192 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
8193 HL_TABLE()[idx].sg_cterm_fg = 0; | |
8194 HL_TABLE()[idx].sg_cterm_bg = 0; | |
8195 HL_TABLE()[idx].sg_cterm_attr = 0; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8196 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 8197 HL_TABLE()[idx].sg_gui = 0; |
8198 vim_free(HL_TABLE()[idx].sg_gui_fg_name); | |
8199 HL_TABLE()[idx].sg_gui_fg_name = NULL; | |
8200 vim_free(HL_TABLE()[idx].sg_gui_bg_name); | |
8201 HL_TABLE()[idx].sg_gui_bg_name = NULL; | |
205 | 8202 vim_free(HL_TABLE()[idx].sg_gui_sp_name); |
8203 HL_TABLE()[idx].sg_gui_sp_name = NULL; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8204 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8205 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8206 HL_TABLE()[idx].sg_gui_fg = INVALCOLOR; |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8207 HL_TABLE()[idx].sg_gui_bg = INVALCOLOR; |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8208 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8209 #ifdef FEAT_GUI |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8210 HL_TABLE()[idx].sg_gui_sp = INVALCOLOR; |
7 | 8211 gui_mch_free_font(HL_TABLE()[idx].sg_font); |
8212 HL_TABLE()[idx].sg_font = NOFONT; | |
8213 # ifdef FEAT_XFONTSET | |
8214 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
8215 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
8216 # endif | |
8217 vim_free(HL_TABLE()[idx].sg_font_name); | |
8218 HL_TABLE()[idx].sg_font_name = NULL; | |
8219 HL_TABLE()[idx].sg_gui_attr = 0; | |
8220 #endif | |
448 | 8221 #ifdef FEAT_EVAL |
8222 /* Clear the script ID only when there is no link, since that is not | |
8223 * cleared. */ | |
8224 if (HL_TABLE()[idx].sg_link == 0) | |
8225 HL_TABLE()[idx].sg_scriptID = 0; | |
8226 #endif | |
7 | 8227 } |
8228 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8229 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
7 | 8230 /* |
8231 * Set the normal foreground and background colors according to the "Normal" | |
2020 | 8232 * highlighting group. For X11 also set "Menu", "Scrollbar", and |
7 | 8233 * "Tooltip" colors. |
8234 */ | |
8235 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8236 set_normal_colors(void) |
7 | 8237 { |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8238 #ifdef FEAT_GUI |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8239 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8240 if (gui.in_use) |
7 | 8241 # endif |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8242 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8243 if (set_group_colors((char_u *)"Normal", |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8244 &gui.norm_pixel, &gui.back_pixel, |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8245 FALSE, TRUE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8246 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8247 gui_mch_new_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8248 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8249 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8250 # ifdef FEAT_GUI_X11 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8251 if (set_group_colors((char_u *)"Menu", |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8252 &gui.menu_fg_pixel, &gui.menu_bg_pixel, |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8253 TRUE, FALSE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8254 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8255 # ifdef FEAT_MENU |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8256 gui_mch_new_menu_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8257 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8258 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8259 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8260 # ifdef FEAT_BEVAL |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8261 if (set_group_colors((char_u *)"Tooltip", |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8262 &gui.tooltip_fg_pixel, &gui.tooltip_bg_pixel, |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8263 FALSE, FALSE, TRUE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8264 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8265 # ifdef FEAT_TOOLBAR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8266 gui_mch_new_tooltip_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8267 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8268 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8269 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8270 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8271 if (set_group_colors((char_u *)"Scrollbar", |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8272 &gui.scroll_fg_pixel, &gui.scroll_bg_pixel, |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8273 FALSE, FALSE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8274 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8275 gui_new_scrollbar_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8276 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8277 } |
7 | 8278 # endif |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8279 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8280 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8281 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8282 # ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8283 else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8284 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8285 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8286 int idx; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8287 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8288 idx = syn_name2id((char_u *)"Normal") - 1; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8289 if (idx >= 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8290 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8291 gui_do_one_color(idx, FALSE, FALSE); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8292 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8293 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8294 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8295 cterm_normal_fg_gui_color = HL_TABLE()[idx].sg_gui_fg; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8296 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8297 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8298 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8299 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8300 cterm_normal_bg_gui_color = HL_TABLE()[idx].sg_gui_bg; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8301 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8302 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8303 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8304 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8305 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8306 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8307 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8308 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8309 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 8310 /* |
8311 * Set the colors for "Normal", "Menu", "Tooltip" or "Scrollbar". | |
8312 */ | |
8313 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8314 set_group_colors( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8315 char_u *name, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8316 guicolor_T *fgp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8317 guicolor_T *bgp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8318 int do_menu, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8319 int use_norm, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8320 int do_tooltip) |
7 | 8321 { |
8322 int idx; | |
8323 | |
8324 idx = syn_name2id(name) - 1; | |
8325 if (idx >= 0) | |
8326 { | |
8327 gui_do_one_color(idx, do_menu, do_tooltip); | |
8328 | |
8329 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR) | |
8330 *fgp = HL_TABLE()[idx].sg_gui_fg; | |
8331 else if (use_norm) | |
8332 *fgp = gui.def_norm_pixel; | |
8333 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR) | |
8334 *bgp = HL_TABLE()[idx].sg_gui_bg; | |
8335 else if (use_norm) | |
8336 *bgp = gui.def_back_pixel; | |
8337 return TRUE; | |
8338 } | |
8339 return FALSE; | |
8340 } | |
8341 | |
8342 /* | |
8343 * Get the font of the "Normal" group. | |
8344 * Returns "" when it's not found or not set. | |
8345 */ | |
8346 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8347 hl_get_font_name(void) |
7 | 8348 { |
8349 int id; | |
8350 char_u *s; | |
8351 | |
8352 id = syn_name2id((char_u *)"Normal"); | |
8353 if (id > 0) | |
8354 { | |
8355 s = HL_TABLE()[id - 1].sg_font_name; | |
8356 if (s != NULL) | |
8357 return s; | |
8358 } | |
8359 return (char_u *)""; | |
8360 } | |
8361 | |
8362 /* | |
8363 * Set font for "Normal" group. Called by gui_mch_init_font() when a font has | |
8364 * actually chosen to be used. | |
8365 */ | |
8366 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8367 hl_set_font_name(char_u *font_name) |
7 | 8368 { |
8369 int id; | |
8370 | |
8371 id = syn_name2id((char_u *)"Normal"); | |
8372 if (id > 0) | |
8373 { | |
8374 vim_free(HL_TABLE()[id - 1].sg_font_name); | |
8375 HL_TABLE()[id - 1].sg_font_name = vim_strsave(font_name); | |
8376 } | |
8377 } | |
8378 | |
8379 /* | |
8380 * Set background color for "Normal" group. Called by gui_set_bg_color() | |
8381 * when the color is known. | |
8382 */ | |
8383 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8384 hl_set_bg_color_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8385 char_u *name) /* must have been allocated */ |
7 | 8386 { |
8387 int id; | |
8388 | |
8389 if (name != NULL) | |
8390 { | |
8391 id = syn_name2id((char_u *)"Normal"); | |
8392 if (id > 0) | |
8393 { | |
8394 vim_free(HL_TABLE()[id - 1].sg_gui_bg_name); | |
8395 HL_TABLE()[id - 1].sg_gui_bg_name = name; | |
8396 } | |
8397 } | |
8398 } | |
8399 | |
8400 /* | |
8401 * Set foreground color for "Normal" group. Called by gui_set_fg_color() | |
8402 * when the color is known. | |
8403 */ | |
8404 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8405 hl_set_fg_color_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8406 char_u *name) /* must have been allocated */ |
7 | 8407 { |
8408 int id; | |
8409 | |
8410 if (name != NULL) | |
8411 { | |
8412 id = syn_name2id((char_u *)"Normal"); | |
8413 if (id > 0) | |
8414 { | |
8415 vim_free(HL_TABLE()[id - 1].sg_gui_fg_name); | |
8416 HL_TABLE()[id - 1].sg_gui_fg_name = name; | |
8417 } | |
8418 } | |
8419 } | |
8420 | |
8421 /* | |
8422 * Return the handle for a font name. | |
8423 * Returns NOFONT when failed. | |
8424 */ | |
8425 static GuiFont | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8426 font_name2handle(char_u *name) |
7 | 8427 { |
8428 if (STRCMP(name, "NONE") == 0) | |
8429 return NOFONT; | |
8430 | |
8431 return gui_mch_get_font(name, TRUE); | |
8432 } | |
8433 | |
8434 # ifdef FEAT_XFONTSET | |
8435 /* | |
8436 * Return the handle for a fontset name. | |
8437 * Returns NOFONTSET when failed. | |
8438 */ | |
8439 static GuiFontset | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8440 fontset_name2handle(char_u *name, int fixed_width) |
7 | 8441 { |
8442 if (STRCMP(name, "NONE") == 0) | |
8443 return NOFONTSET; | |
8444 | |
8445 return gui_mch_get_fontset(name, TRUE, fixed_width); | |
8446 } | |
8447 # endif | |
8448 | |
8449 /* | |
8450 * Get the font or fontset for one highlight group. | |
8451 */ | |
8452 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8453 hl_do_font( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8454 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8455 char_u *arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8456 int do_normal, /* set normal font */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8457 int do_menu UNUSED, /* set menu font */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8458 int do_tooltip UNUSED, /* set tooltip font */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8459 int free_font) /* free current font/fontset */ |
7 | 8460 { |
8461 # ifdef FEAT_XFONTSET | |
8462 /* If 'guifontset' is not empty, first try using the name as a | |
8463 * fontset. If that doesn't work, use it as a font name. */ | |
8464 if (*p_guifontset != NUL | |
8465 # ifdef FONTSET_ALWAYS | |
8466 || do_menu | |
8467 # endif | |
8468 # ifdef FEAT_BEVAL_TIP | |
8469 /* In Athena & Motif, the Tooltip highlight group is always a fontset */ | |
8470 || do_tooltip | |
8471 # endif | |
8472 ) | |
4344 | 8473 { |
3900 | 8474 if (free_font) |
3881 | 8475 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); |
7 | 8476 HL_TABLE()[idx].sg_fontset = fontset_name2handle(arg, 0 |
8477 # ifdef FONTSET_ALWAYS | |
8478 || do_menu | |
8479 # endif | |
8480 # ifdef FEAT_BEVAL_TIP | |
8481 || do_tooltip | |
8482 # endif | |
8483 ); | |
4344 | 8484 } |
7 | 8485 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) |
8486 { | |
3881 | 8487 /* If it worked and it's the Normal group, use it as the normal |
8488 * fontset. Same for the Menu group. */ | |
7 | 8489 if (do_normal) |
8490 gui_init_font(arg, TRUE); | |
8491 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8492 if (do_menu) | |
8493 { | |
8494 # ifdef FONTSET_ALWAYS | |
8495 gui.menu_fontset = HL_TABLE()[idx].sg_fontset; | |
8496 # else | |
8497 /* YIKES! This is a bug waiting to crash the program */ | |
8498 gui.menu_font = HL_TABLE()[idx].sg_fontset; | |
8499 # endif | |
8500 gui_mch_new_menu_font(); | |
8501 } | |
8502 # ifdef FEAT_BEVAL | |
8503 if (do_tooltip) | |
8504 { | |
8505 /* The Athena widget set cannot currently handle switching between | |
8506 * displaying a single font and a fontset. | |
8507 * If the XtNinternational resource is set to True at widget | |
1222 | 8508 * creation, then a fontset is always used, otherwise an |
7 | 8509 * XFontStruct is used. |
8510 */ | |
8511 gui.tooltip_fontset = (XFontSet)HL_TABLE()[idx].sg_fontset; | |
8512 gui_mch_new_tooltip_font(); | |
8513 } | |
8514 # endif | |
8515 # endif | |
8516 } | |
8517 else | |
8518 # endif | |
8519 { | |
3881 | 8520 if (free_font) |
8521 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
7 | 8522 HL_TABLE()[idx].sg_font = font_name2handle(arg); |
8523 /* If it worked and it's the Normal group, use it as the | |
8524 * normal font. Same for the Menu group. */ | |
8525 if (HL_TABLE()[idx].sg_font != NOFONT) | |
8526 { | |
8527 if (do_normal) | |
8528 gui_init_font(arg, FALSE); | |
8529 #ifndef FONTSET_ALWAYS | |
8530 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8531 if (do_menu) | |
8532 { | |
8533 gui.menu_font = HL_TABLE()[idx].sg_font; | |
8534 gui_mch_new_menu_font(); | |
8535 } | |
8536 # endif | |
8537 #endif | |
8538 } | |
8539 } | |
8540 } | |
8541 | |
8542 #endif /* FEAT_GUI */ | |
8543 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8544 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8545 /* |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8546 * Return the handle for a color name. |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8547 * Returns INVALCOLOR when failed. |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8548 */ |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8549 static guicolor_T |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8550 color_name2handle(char_u *name) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8551 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8552 if (STRCMP(name, "NONE") == 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8553 return INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8554 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8555 if (STRICMP(name, "fg") == 0 || STRICMP(name, "foreground") == 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8556 { |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8557 #if defined(FEAT_TERMGUICOLORS) && defined(FEAT_GUI) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8558 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8559 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8560 #ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8561 return gui.norm_pixel; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8562 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8563 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8564 if (cterm_normal_fg_gui_color != INVALCOLOR) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8565 return cterm_normal_fg_gui_color; |
9141
d6662acfc3de
commit https://github.com/vim/vim/commit/d80629cef03cd40b0bf06c402dfe0b720b3bf608
Christian Brabandt <cb@256bit.org>
parents:
9054
diff
changeset
|
8566 /* Guess that the foreground is black or white. */ |
d6662acfc3de
commit https://github.com/vim/vim/commit/d80629cef03cd40b0bf06c402dfe0b720b3bf608
Christian Brabandt <cb@256bit.org>
parents:
9054
diff
changeset
|
8567 return GUI_GET_COLOR((char_u *)(*p_bg == 'l' ? "black" : "white")); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8568 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8569 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8570 if (STRICMP(name, "bg") == 0 || STRICMP(name, "background") == 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8571 { |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8572 #if defined(FEAT_TERMGUICOLORS) && defined(FEAT_GUI) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8573 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8574 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8575 #ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8576 return gui.back_pixel; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8577 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8578 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8579 if (cterm_normal_bg_gui_color != INVALCOLOR) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8580 return cterm_normal_bg_gui_color; |
9141
d6662acfc3de
commit https://github.com/vim/vim/commit/d80629cef03cd40b0bf06c402dfe0b720b3bf608
Christian Brabandt <cb@256bit.org>
parents:
9054
diff
changeset
|
8581 /* Guess that the background is white or black. */ |
d6662acfc3de
commit https://github.com/vim/vim/commit/d80629cef03cd40b0bf06c402dfe0b720b3bf608
Christian Brabandt <cb@256bit.org>
parents:
9054
diff
changeset
|
8582 return GUI_GET_COLOR((char_u *)(*p_bg == 'l' ? "white" : "black")); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8583 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8584 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8585 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8586 return GUI_GET_COLOR(name); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8587 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8588 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8589 |
7 | 8590 /* |
8591 * Table with the specifications for an attribute number. | |
8592 * Note that this table is used by ALL buffers. This is required because the | |
8593 * GUI can redraw at any time for any buffer. | |
8594 */ | |
298 | 8595 static garray_T term_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8596 |
8597 #define TERM_ATTR_ENTRY(idx) ((attrentry_T *)term_attr_table.ga_data)[idx] | |
8598 | |
298 | 8599 static garray_T cterm_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8600 |
8601 #define CTERM_ATTR_ENTRY(idx) ((attrentry_T *)cterm_attr_table.ga_data)[idx] | |
8602 | |
8603 #ifdef FEAT_GUI | |
298 | 8604 static garray_T gui_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8605 |
8606 #define GUI_ATTR_ENTRY(idx) ((attrentry_T *)gui_attr_table.ga_data)[idx] | |
8607 #endif | |
8608 | |
8609 /* | |
8610 * Return the attr number for a set of colors and font. | |
8611 * Add a new entry to the term_attr_table, cterm_attr_table or gui_attr_table | |
8612 * if the combination is new. | |
8613 * Return 0 for error (no more room). | |
8614 */ | |
8615 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8616 get_attr_entry(garray_T *table, attrentry_T *aep) |
7 | 8617 { |
8618 int i; | |
359 | 8619 attrentry_T *taep; |
7 | 8620 static int recursive = FALSE; |
8621 | |
8622 /* | |
8623 * Init the table, in case it wasn't done yet. | |
8624 */ | |
8625 table->ga_itemsize = sizeof(attrentry_T); | |
8626 table->ga_growsize = 7; | |
8627 | |
8628 /* | |
8629 * Try to find an entry with the same specifications. | |
8630 */ | |
8631 for (i = 0; i < table->ga_len; ++i) | |
8632 { | |
359 | 8633 taep = &(((attrentry_T *)table->ga_data)[i]); |
8634 if ( aep->ae_attr == taep->ae_attr | |
7 | 8635 && ( |
8636 #ifdef FEAT_GUI | |
8637 (table == &gui_attr_table | |
359 | 8638 && (aep->ae_u.gui.fg_color == taep->ae_u.gui.fg_color |
8639 && aep->ae_u.gui.bg_color | |
8640 == taep->ae_u.gui.bg_color | |
8641 && aep->ae_u.gui.sp_color | |
8642 == taep->ae_u.gui.sp_color | |
8643 && aep->ae_u.gui.font == taep->ae_u.gui.font | |
7 | 8644 # ifdef FEAT_XFONTSET |
359 | 8645 && aep->ae_u.gui.fontset == taep->ae_u.gui.fontset |
7 | 8646 # endif |
8647 )) | |
8648 || | |
8649 #endif | |
8650 (table == &term_attr_table | |
359 | 8651 && (aep->ae_u.term.start == NULL) |
8652 == (taep->ae_u.term.start == NULL) | |
7 | 8653 && (aep->ae_u.term.start == NULL |
8654 || STRCMP(aep->ae_u.term.start, | |
359 | 8655 taep->ae_u.term.start) == 0) |
8656 && (aep->ae_u.term.stop == NULL) | |
8657 == (taep->ae_u.term.stop == NULL) | |
7 | 8658 && (aep->ae_u.term.stop == NULL |
8659 || STRCMP(aep->ae_u.term.stop, | |
359 | 8660 taep->ae_u.term.stop) == 0)) |
7 | 8661 || (table == &cterm_attr_table |
359 | 8662 && aep->ae_u.cterm.fg_color |
8663 == taep->ae_u.cterm.fg_color | |
8664 && aep->ae_u.cterm.bg_color | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8665 == taep->ae_u.cterm.bg_color |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8666 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8667 && aep->ae_u.cterm.fg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8668 == taep->ae_u.cterm.fg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8669 && aep->ae_u.cterm.bg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8670 == taep->ae_u.cterm.bg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8671 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8672 ))) |
7 | 8673 |
8674 return i + ATTR_OFF; | |
8675 } | |
8676 | |
271 | 8677 if (table->ga_len + ATTR_OFF > MAX_TYPENR) |
7 | 8678 { |
8679 /* | |
8680 * Running out of attribute entries! remove all attributes, and | |
8681 * compute new ones for all groups. | |
8682 * When called recursively, we are really out of numbers. | |
8683 */ | |
8684 if (recursive) | |
8685 { | |
8686 EMSG(_("E424: Too many different highlighting attributes in use")); | |
8687 return 0; | |
8688 } | |
8689 recursive = TRUE; | |
8690 | |
359 | 8691 clear_hl_tables(); |
8692 | |
7 | 8693 must_redraw = CLEAR; |
8694 | |
8695 for (i = 0; i < highlight_ga.ga_len; ++i) | |
8696 set_hl_attr(i); | |
8697 | |
8698 recursive = FALSE; | |
8699 } | |
8700 | |
8701 /* | |
8702 * This is a new combination of colors and font, add an entry. | |
8703 */ | |
8704 if (ga_grow(table, 1) == FAIL) | |
8705 return 0; | |
8706 | |
359 | 8707 taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); |
8708 vim_memset(taep, 0, sizeof(attrentry_T)); | |
8709 taep->ae_attr = aep->ae_attr; | |
7 | 8710 #ifdef FEAT_GUI |
8711 if (table == &gui_attr_table) | |
8712 { | |
359 | 8713 taep->ae_u.gui.fg_color = aep->ae_u.gui.fg_color; |
8714 taep->ae_u.gui.bg_color = aep->ae_u.gui.bg_color; | |
8715 taep->ae_u.gui.sp_color = aep->ae_u.gui.sp_color; | |
8716 taep->ae_u.gui.font = aep->ae_u.gui.font; | |
7 | 8717 # ifdef FEAT_XFONTSET |
359 | 8718 taep->ae_u.gui.fontset = aep->ae_u.gui.fontset; |
7 | 8719 # endif |
8720 } | |
8721 #endif | |
8722 if (table == &term_attr_table) | |
8723 { | |
8724 if (aep->ae_u.term.start == NULL) | |
359 | 8725 taep->ae_u.term.start = NULL; |
7 | 8726 else |
359 | 8727 taep->ae_u.term.start = vim_strsave(aep->ae_u.term.start); |
7 | 8728 if (aep->ae_u.term.stop == NULL) |
359 | 8729 taep->ae_u.term.stop = NULL; |
7 | 8730 else |
359 | 8731 taep->ae_u.term.stop = vim_strsave(aep->ae_u.term.stop); |
7 | 8732 } |
8733 else if (table == &cterm_attr_table) | |
8734 { | |
359 | 8735 taep->ae_u.cterm.fg_color = aep->ae_u.cterm.fg_color; |
8736 taep->ae_u.cterm.bg_color = aep->ae_u.cterm.bg_color; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8737 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8738 taep->ae_u.cterm.fg_rgb = aep->ae_u.cterm.fg_rgb; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8739 taep->ae_u.cterm.bg_rgb = aep->ae_u.cterm.bg_rgb; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8740 #endif |
7 | 8741 } |
8742 ++table->ga_len; | |
8743 return (table->ga_len - 1 + ATTR_OFF); | |
8744 } | |
8745 | |
359 | 8746 /* |
8747 * Clear all highlight tables. | |
8748 */ | |
8749 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8750 clear_hl_tables(void) |
359 | 8751 { |
8752 int i; | |
8753 attrentry_T *taep; | |
8754 | |
8755 #ifdef FEAT_GUI | |
8756 ga_clear(&gui_attr_table); | |
8757 #endif | |
8758 for (i = 0; i < term_attr_table.ga_len; ++i) | |
8759 { | |
8760 taep = &(((attrentry_T *)term_attr_table.ga_data)[i]); | |
8761 vim_free(taep->ae_u.term.start); | |
8762 vim_free(taep->ae_u.term.stop); | |
8763 } | |
8764 ga_clear(&term_attr_table); | |
8765 ga_clear(&cterm_attr_table); | |
8766 } | |
8767 | |
745 | 8768 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL) || defined(PROTO) |
221 | 8769 /* |
348 | 8770 * Combine special attributes (e.g., for spelling) with other attributes |
8771 * (e.g., for syntax highlighting). | |
8772 * "prim_attr" overrules "char_attr". | |
221 | 8773 * This creates a new group when required. |
8774 * Since we expect there to be few spelling mistakes we don't cache the | |
8775 * result. | |
8776 * Return the resulting attributes. | |
8777 */ | |
8778 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8779 hl_combine_attr(int char_attr, int prim_attr) |
221 | 8780 { |
8781 attrentry_T *char_aep = NULL; | |
8782 attrentry_T *spell_aep; | |
8783 attrentry_T new_en; | |
8784 | |
8785 if (char_attr == 0) | |
348 | 8786 return prim_attr; |
8787 if (char_attr <= HL_ALL && prim_attr <= HL_ALL) | |
8788 return char_attr | prim_attr; | |
221 | 8789 #ifdef FEAT_GUI |
8790 if (gui.in_use) | |
8791 { | |
8792 if (char_attr > HL_ALL) | |
8793 char_aep = syn_gui_attr2entry(char_attr); | |
8794 if (char_aep != NULL) | |
8795 new_en = *char_aep; | |
8796 else | |
8797 { | |
8798 vim_memset(&new_en, 0, sizeof(new_en)); | |
548 | 8799 new_en.ae_u.gui.fg_color = INVALCOLOR; |
8800 new_en.ae_u.gui.bg_color = INVALCOLOR; | |
8801 new_en.ae_u.gui.sp_color = INVALCOLOR; | |
221 | 8802 if (char_attr <= HL_ALL) |
8803 new_en.ae_attr = char_attr; | |
8804 } | |
8805 | |
348 | 8806 if (prim_attr <= HL_ALL) |
8807 new_en.ae_attr |= prim_attr; | |
221 | 8808 else |
8809 { | |
348 | 8810 spell_aep = syn_gui_attr2entry(prim_attr); |
221 | 8811 if (spell_aep != NULL) |
8812 { | |
8813 new_en.ae_attr |= spell_aep->ae_attr; | |
8814 if (spell_aep->ae_u.gui.fg_color != INVALCOLOR) | |
8815 new_en.ae_u.gui.fg_color = spell_aep->ae_u.gui.fg_color; | |
8816 if (spell_aep->ae_u.gui.bg_color != INVALCOLOR) | |
8817 new_en.ae_u.gui.bg_color = spell_aep->ae_u.gui.bg_color; | |
8818 if (spell_aep->ae_u.gui.sp_color != INVALCOLOR) | |
8819 new_en.ae_u.gui.sp_color = spell_aep->ae_u.gui.sp_color; | |
8820 if (spell_aep->ae_u.gui.font != NOFONT) | |
8821 new_en.ae_u.gui.font = spell_aep->ae_u.gui.font; | |
8822 # ifdef FEAT_XFONTSET | |
8823 if (spell_aep->ae_u.gui.fontset != NOFONTSET) | |
8824 new_en.ae_u.gui.fontset = spell_aep->ae_u.gui.fontset; | |
8825 # endif | |
8826 } | |
8827 } | |
8828 return get_attr_entry(&gui_attr_table, &new_en); | |
8829 } | |
8830 #endif | |
8831 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8832 if (IS_CTERM) |
221 | 8833 { |
8834 if (char_attr > HL_ALL) | |
8835 char_aep = syn_cterm_attr2entry(char_attr); | |
8836 if (char_aep != NULL) | |
8837 new_en = *char_aep; | |
8838 else | |
8839 { | |
8840 vim_memset(&new_en, 0, sizeof(new_en)); | |
10499
e88ffb09ff38
commit https://github.com/vim/vim/commit/0cdb72aa38c4a0140c94d56bf8bc17cb30260ebf
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
8841 #ifdef FEAT_TERMGUICOLORS |
e88ffb09ff38
commit https://github.com/vim/vim/commit/0cdb72aa38c4a0140c94d56bf8bc17cb30260ebf
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
8842 new_en.ae_u.cterm.bg_rgb = INVALCOLOR; |
e88ffb09ff38
commit https://github.com/vim/vim/commit/0cdb72aa38c4a0140c94d56bf8bc17cb30260ebf
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
8843 new_en.ae_u.cterm.fg_rgb = INVALCOLOR; |
e88ffb09ff38
commit https://github.com/vim/vim/commit/0cdb72aa38c4a0140c94d56bf8bc17cb30260ebf
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
8844 #endif |
221 | 8845 if (char_attr <= HL_ALL) |
8846 new_en.ae_attr = char_attr; | |
8847 } | |
8848 | |
348 | 8849 if (prim_attr <= HL_ALL) |
8850 new_en.ae_attr |= prim_attr; | |
221 | 8851 else |
8852 { | |
348 | 8853 spell_aep = syn_cterm_attr2entry(prim_attr); |
221 | 8854 if (spell_aep != NULL) |
8855 { | |
8856 new_en.ae_attr |= spell_aep->ae_attr; | |
8857 if (spell_aep->ae_u.cterm.fg_color > 0) | |
8858 new_en.ae_u.cterm.fg_color = spell_aep->ae_u.cterm.fg_color; | |
8859 if (spell_aep->ae_u.cterm.bg_color > 0) | |
8860 new_en.ae_u.cterm.bg_color = spell_aep->ae_u.cterm.bg_color; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8861 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8862 if (spell_aep->ae_u.cterm.fg_rgb != INVALCOLOR) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8863 new_en.ae_u.cterm.fg_rgb = spell_aep->ae_u.cterm.fg_rgb; |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8864 if (spell_aep->ae_u.cterm.bg_rgb != INVALCOLOR) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8865 new_en.ae_u.cterm.bg_rgb = spell_aep->ae_u.cterm.bg_rgb; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8866 #endif |
221 | 8867 } |
8868 } | |
8869 return get_attr_entry(&cterm_attr_table, &new_en); | |
8870 } | |
8871 | |
8872 if (char_attr > HL_ALL) | |
8873 char_aep = syn_term_attr2entry(char_attr); | |
8874 if (char_aep != NULL) | |
8875 new_en = *char_aep; | |
8876 else | |
8877 { | |
8878 vim_memset(&new_en, 0, sizeof(new_en)); | |
8879 if (char_attr <= HL_ALL) | |
8880 new_en.ae_attr = char_attr; | |
8881 } | |
8882 | |
348 | 8883 if (prim_attr <= HL_ALL) |
8884 new_en.ae_attr |= prim_attr; | |
221 | 8885 else |
8886 { | |
607 | 8887 spell_aep = syn_term_attr2entry(prim_attr); |
221 | 8888 if (spell_aep != NULL) |
8889 { | |
8890 new_en.ae_attr |= spell_aep->ae_attr; | |
8891 if (spell_aep->ae_u.term.start != NULL) | |
8892 { | |
8893 new_en.ae_u.term.start = spell_aep->ae_u.term.start; | |
8894 new_en.ae_u.term.stop = spell_aep->ae_u.term.stop; | |
8895 } | |
8896 } | |
8897 } | |
8898 return get_attr_entry(&term_attr_table, &new_en); | |
8899 } | |
8900 #endif | |
8901 | |
7 | 8902 #ifdef FEAT_GUI |
8903 | |
8904 attrentry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8905 syn_gui_attr2entry(int attr) |
7 | 8906 { |
8907 attr -= ATTR_OFF; | |
8908 if (attr >= gui_attr_table.ga_len) /* did ":syntax clear" */ | |
8909 return NULL; | |
8910 return &(GUI_ATTR_ENTRY(attr)); | |
8911 } | |
8912 #endif /* FEAT_GUI */ | |
8913 | |
745 | 8914 /* |
8915 * Get the highlight attributes (HL_BOLD etc.) from an attribute nr. | |
8916 * Only to be used when "attr" > HL_ALL. | |
8917 */ | |
8918 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8919 syn_attr2attr(int attr) |
745 | 8920 { |
8921 attrentry_T *aep; | |
8922 | |
8923 #ifdef FEAT_GUI | |
8924 if (gui.in_use) | |
8925 aep = syn_gui_attr2entry(attr); | |
8926 else | |
8927 #endif | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8928 if (IS_CTERM) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8929 aep = syn_cterm_attr2entry(attr); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8930 else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8931 aep = syn_term_attr2entry(attr); |
745 | 8932 |
8933 if (aep == NULL) /* highlighting not set */ | |
8934 return 0; | |
8935 return aep->ae_attr; | |
8936 } | |
8937 | |
8938 | |
7 | 8939 attrentry_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8940 syn_term_attr2entry(int attr) |
7 | 8941 { |
8942 attr -= ATTR_OFF; | |
8943 if (attr >= term_attr_table.ga_len) /* did ":syntax clear" */ | |
8944 return NULL; | |
8945 return &(TERM_ATTR_ENTRY(attr)); | |
8946 } | |
8947 | |
8948 attrentry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8949 syn_cterm_attr2entry(int attr) |
7 | 8950 { |
8951 attr -= ATTR_OFF; | |
8952 if (attr >= cterm_attr_table.ga_len) /* did ":syntax clear" */ | |
8953 return NULL; | |
8954 return &(CTERM_ATTR_ENTRY(attr)); | |
8955 } | |
8956 | |
8957 #define LIST_ATTR 1 | |
8958 #define LIST_STRING 2 | |
8959 #define LIST_INT 3 | |
8960 | |
8961 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8962 highlight_list_one(int id) |
7 | 8963 { |
8964 struct hl_group *sgp; | |
8965 int didh = FALSE; | |
8966 | |
8967 sgp = &HL_TABLE()[id - 1]; /* index is ID minus one */ | |
8968 | |
8969 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8970 sgp->sg_term, NULL, "term"); | |
8971 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8972 0, sgp->sg_start, "start"); | |
8973 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8974 0, sgp->sg_stop, "stop"); | |
8975 | |
8976 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8977 sgp->sg_cterm, NULL, "cterm"); | |
8978 didh = highlight_list_arg(id, didh, LIST_INT, | |
8979 sgp->sg_cterm_fg, NULL, "ctermfg"); | |
8980 didh = highlight_list_arg(id, didh, LIST_INT, | |
8981 sgp->sg_cterm_bg, NULL, "ctermbg"); | |
8982 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8983 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 8984 didh = highlight_list_arg(id, didh, LIST_ATTR, |
8985 sgp->sg_gui, NULL, "gui"); | |
8986 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8987 0, sgp->sg_gui_fg_name, "guifg"); | |
8988 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8989 0, sgp->sg_gui_bg_name, "guibg"); | |
8990 didh = highlight_list_arg(id, didh, LIST_STRING, | |
301 | 8991 0, sgp->sg_gui_sp_name, "guisp"); |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8992 #endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8993 #ifdef FEAT_GUI |
301 | 8994 didh = highlight_list_arg(id, didh, LIST_STRING, |
7 | 8995 0, sgp->sg_font_name, "font"); |
8996 #endif | |
8997 | |
448 | 8998 if (sgp->sg_link && !got_int) |
7 | 8999 { |
9000 (void)syn_list_header(didh, 9999, id); | |
448 | 9001 didh = TRUE; |
7 | 9002 msg_puts_attr((char_u *)"links to", hl_attr(HLF_D)); |
9003 msg_putchar(' '); | |
9004 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
9005 } | |
448 | 9006 |
694 | 9007 if (!didh) |
9008 highlight_list_arg(id, didh, LIST_STRING, 0, (char_u *)"cleared", ""); | |
448 | 9009 #ifdef FEAT_EVAL |
694 | 9010 if (p_verbose > 0) |
448 | 9011 last_set_msg(sgp->sg_scriptID); |
9012 #endif | |
7 | 9013 } |
9014 | |
9015 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9016 highlight_list_arg( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9017 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9018 int didh, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9019 int type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9020 int iarg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9021 char_u *sarg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9022 char *name) |
7 | 9023 { |
9024 char_u buf[100]; | |
9025 char_u *ts; | |
9026 int i; | |
9027 | |
448 | 9028 if (got_int) |
9029 return FALSE; | |
7 | 9030 if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) |
9031 { | |
9032 ts = buf; | |
9033 if (type == LIST_INT) | |
9034 sprintf((char *)buf, "%d", iarg - 1); | |
9035 else if (type == LIST_STRING) | |
9036 ts = sarg; | |
9037 else /* type == LIST_ATTR */ | |
9038 { | |
9039 buf[0] = NUL; | |
9040 for (i = 0; hl_attr_table[i] != 0; ++i) | |
9041 { | |
9042 if (iarg & hl_attr_table[i]) | |
9043 { | |
9044 if (buf[0] != NUL) | |
2768 | 9045 vim_strcat(buf, (char_u *)",", 100); |
9046 vim_strcat(buf, (char_u *)hl_name_table[i], 100); | |
7 | 9047 iarg &= ~hl_attr_table[i]; /* don't want "inverse" */ |
9048 } | |
9049 } | |
9050 } | |
9051 | |
9052 (void)syn_list_header(didh, | |
9053 (int)(vim_strsize(ts) + STRLEN(name) + 1), id); | |
9054 didh = TRUE; | |
448 | 9055 if (!got_int) |
9056 { | |
694 | 9057 if (*name != NUL) |
9058 { | |
9059 MSG_PUTS_ATTR(name, hl_attr(HLF_D)); | |
9060 MSG_PUTS_ATTR("=", hl_attr(HLF_D)); | |
9061 } | |
448 | 9062 msg_outtrans(ts); |
9063 } | |
7 | 9064 } |
9065 return didh; | |
9066 } | |
9067 | |
9068 #if (((defined(FEAT_EVAL) || defined(FEAT_PRINTER))) && defined(FEAT_SYN_HL)) || defined(PROTO) | |
9069 /* | |
9070 * Return "1" if highlight group "id" has attribute "flag". | |
9071 * Return NULL otherwise. | |
9072 */ | |
9073 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9074 highlight_has_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9075 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9076 int flag, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9077 int modec) /* 'g' for GUI, 'c' for cterm, 't' for term */ |
7 | 9078 { |
9079 int attr; | |
9080 | |
9081 if (id <= 0 || id > highlight_ga.ga_len) | |
9082 return NULL; | |
9083 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9084 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9085 if (modec == 'g') |
9086 attr = HL_TABLE()[id - 1].sg_gui; | |
9087 else | |
9088 #endif | |
9089 if (modec == 'c') | |
9090 attr = HL_TABLE()[id - 1].sg_cterm; | |
9091 else | |
9092 attr = HL_TABLE()[id - 1].sg_term; | |
9093 | |
9094 if (attr & flag) | |
9095 return (char_u *)"1"; | |
9096 return NULL; | |
9097 } | |
9098 #endif | |
9099 | |
9100 #if (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) || defined(PROTO) | |
9101 /* | |
9102 * Return color name of highlight group "id". | |
9103 */ | |
9104 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9105 highlight_color( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9106 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9107 char_u *what, /* "font", "fg", "bg", "sp", "fg#", "bg#" or "sp#" */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9108 int modec) /* 'g' for GUI, 'c' for cterm, 't' for term */ |
7 | 9109 { |
9110 static char_u name[20]; | |
9111 int n; | |
205 | 9112 int fg = FALSE; |
9113 int sp = FALSE; | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9114 int font = FALSE; |
7 | 9115 |
9116 if (id <= 0 || id > highlight_ga.ga_len) | |
9117 return NULL; | |
9118 | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9119 if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g') |
7 | 9120 fg = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9121 else if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'o' |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
9122 && TOLOWER_ASC(what[2]) == 'n' && TOLOWER_ASC(what[3]) == 't') |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9123 font = TRUE; |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9124 else if (TOLOWER_ASC(what[0]) == 's' && TOLOWER_ASC(what[1]) == 'p') |
205 | 9125 sp = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9126 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
|
9127 return NULL; |
7 | 9128 if (modec == 'g') |
9129 { | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9130 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9131 # ifdef FEAT_GUI |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9132 /* return font name */ |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9133 if (font) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9134 return HL_TABLE()[id - 1].sg_font_name; |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9135 # endif |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9136 |
7 | 9137 /* return #RRGGBB form (only possible when GUI is running) */ |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9138 if ((USE_24BIT) && what[2] == '#') |
7 | 9139 { |
9140 guicolor_T color; | |
9141 long_u rgb; | |
9142 static char_u buf[10]; | |
9143 | |
9144 if (fg) | |
9145 color = HL_TABLE()[id - 1].sg_gui_fg; | |
205 | 9146 else if (sp) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9147 # ifdef FEAT_GUI |
205 | 9148 color = HL_TABLE()[id - 1].sg_gui_sp; |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9149 # else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9150 color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9151 # endif |
7 | 9152 else |
9153 color = HL_TABLE()[id - 1].sg_gui_bg; | |
9154 if (color == INVALCOLOR) | |
9155 return NULL; | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
9156 rgb = (long_u)GUI_MCH_GET_RGB(color); |
7 | 9157 sprintf((char *)buf, "#%02x%02x%02x", |
9158 (unsigned)(rgb >> 16), | |
9159 (unsigned)(rgb >> 8) & 255, | |
9160 (unsigned)rgb & 255); | |
9161 return buf; | |
9162 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9163 # endif |
7 | 9164 if (fg) |
9165 return (HL_TABLE()[id - 1].sg_gui_fg_name); | |
205 | 9166 if (sp) |
9167 return (HL_TABLE()[id - 1].sg_gui_sp_name); | |
7 | 9168 return (HL_TABLE()[id - 1].sg_gui_bg_name); |
9169 } | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9170 if (font || sp) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9171 return NULL; |
7 | 9172 if (modec == 'c') |
9173 { | |
9174 if (fg) | |
9175 n = HL_TABLE()[id - 1].sg_cterm_fg - 1; | |
9176 else | |
9177 n = HL_TABLE()[id - 1].sg_cterm_bg - 1; | |
8514
260d01c1cd17
commit https://github.com/vim/vim/commit/385111bd86e0b38667879c3e89506ca1ae98e1df
Christian Brabandt <cb@256bit.org>
parents:
8362
diff
changeset
|
9178 if (n < 0) |
260d01c1cd17
commit https://github.com/vim/vim/commit/385111bd86e0b38667879c3e89506ca1ae98e1df
Christian Brabandt <cb@256bit.org>
parents:
8362
diff
changeset
|
9179 return NULL; |
7 | 9180 sprintf((char *)name, "%d", n); |
9181 return name; | |
9182 } | |
9183 /* term doesn't have color */ | |
9184 return NULL; | |
9185 } | |
9186 #endif | |
9187 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9188 #if (defined(FEAT_SYN_HL) \ |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9189 && (defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)) \ |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9190 && defined(FEAT_PRINTER)) || defined(PROTO) |
7 | 9191 /* |
9192 * Return color name of highlight group "id" as RGB value. | |
9193 */ | |
9194 long_u | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9195 highlight_gui_color_rgb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9196 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9197 int fg) /* TRUE = fg, FALSE = bg */ |
7 | 9198 { |
9199 guicolor_T color; | |
9200 | |
9201 if (id <= 0 || id > highlight_ga.ga_len) | |
9202 return 0L; | |
9203 | |
9204 if (fg) | |
9205 color = HL_TABLE()[id - 1].sg_gui_fg; | |
9206 else | |
9207 color = HL_TABLE()[id - 1].sg_gui_bg; | |
9208 | |
9209 if (color == INVALCOLOR) | |
9210 return 0L; | |
9211 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9212 return GUI_MCH_GET_RGB(color); |
7 | 9213 } |
9214 #endif | |
9215 | |
9216 /* | |
9217 * Output the syntax list header. | |
9218 * Return TRUE when started a new line. | |
9219 */ | |
9220 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9221 syn_list_header( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9222 int did_header, /* did header already */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9223 int outlen, /* length of string that comes */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9224 int id) /* highlight group id */ |
7 | 9225 { |
9226 int endcol = 19; | |
9227 int newline = TRUE; | |
9228 | |
9229 if (!did_header) | |
9230 { | |
9231 msg_putchar('\n'); | |
448 | 9232 if (got_int) |
9233 return TRUE; | |
7 | 9234 msg_outtrans(HL_TABLE()[id - 1].sg_name); |
9235 endcol = 15; | |
9236 } | |
9237 else if (msg_col + outlen + 1 >= Columns) | |
448 | 9238 { |
7 | 9239 msg_putchar('\n'); |
448 | 9240 if (got_int) |
9241 return TRUE; | |
9242 } | |
7 | 9243 else |
9244 { | |
9245 if (msg_col >= endcol) /* wrap around is like starting a new line */ | |
9246 newline = FALSE; | |
9247 } | |
9248 | |
9249 if (msg_col >= endcol) /* output at least one space */ | |
9250 endcol = msg_col + 1; | |
9251 if (Columns <= endcol) /* avoid hang for tiny window */ | |
9252 endcol = Columns - 1; | |
9253 | |
9254 msg_advance(endcol); | |
9255 | |
9256 /* Show "xxx" with the attributes. */ | |
9257 if (!did_header) | |
9258 { | |
9259 msg_puts_attr((char_u *)"xxx", syn_id2attr(id)); | |
9260 msg_putchar(' '); | |
9261 } | |
9262 | |
9263 return newline; | |
9264 } | |
9265 | |
9266 /* | |
9267 * Set the attribute numbers for a highlight group. | |
9268 * Called after one of the attributes has changed. | |
9269 */ | |
9270 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9271 set_hl_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9272 int idx) /* index in array */ |
7 | 9273 { |
9274 attrentry_T at_en; | |
9275 struct hl_group *sgp = HL_TABLE() + idx; | |
9276 | |
9277 /* The "Normal" group doesn't need an attribute number */ | |
9278 if (sgp->sg_name_u != NULL && STRCMP(sgp->sg_name_u, "NORMAL") == 0) | |
9279 return; | |
9280 | |
9281 #ifdef FEAT_GUI | |
9282 /* | |
9283 * For the GUI mode: If there are other than "normal" highlighting | |
9284 * attributes, need to allocate an attr number. | |
9285 */ | |
9286 if (sgp->sg_gui_fg == INVALCOLOR | |
9287 && sgp->sg_gui_bg == INVALCOLOR | |
205 | 9288 && sgp->sg_gui_sp == INVALCOLOR |
7 | 9289 && sgp->sg_font == NOFONT |
9290 # ifdef FEAT_XFONTSET | |
9291 && sgp->sg_fontset == NOFONTSET | |
9292 # endif | |
9293 ) | |
9294 { | |
9295 sgp->sg_gui_attr = sgp->sg_gui; | |
9296 } | |
9297 else | |
9298 { | |
9299 at_en.ae_attr = sgp->sg_gui; | |
9300 at_en.ae_u.gui.fg_color = sgp->sg_gui_fg; | |
9301 at_en.ae_u.gui.bg_color = sgp->sg_gui_bg; | |
205 | 9302 at_en.ae_u.gui.sp_color = sgp->sg_gui_sp; |
7 | 9303 at_en.ae_u.gui.font = sgp->sg_font; |
9304 # ifdef FEAT_XFONTSET | |
9305 at_en.ae_u.gui.fontset = sgp->sg_fontset; | |
9306 # endif | |
9307 sgp->sg_gui_attr = get_attr_entry(&gui_attr_table, &at_en); | |
9308 } | |
9309 #endif | |
9310 /* | |
9311 * For the term mode: If there are other than "normal" highlighting | |
9312 * attributes, need to allocate an attr number. | |
9313 */ | |
9314 if (sgp->sg_start == NULL && sgp->sg_stop == NULL) | |
9315 sgp->sg_term_attr = sgp->sg_term; | |
9316 else | |
9317 { | |
9318 at_en.ae_attr = sgp->sg_term; | |
9319 at_en.ae_u.term.start = sgp->sg_start; | |
9320 at_en.ae_u.term.stop = sgp->sg_stop; | |
9321 sgp->sg_term_attr = get_attr_entry(&term_attr_table, &at_en); | |
9322 } | |
9323 | |
9324 /* | |
9325 * For the color term mode: If there are other than "normal" | |
9326 * highlighting attributes, need to allocate an attr number. | |
9327 */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9328 if (sgp->sg_cterm_fg == 0 && sgp->sg_cterm_bg == 0 |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9329 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9330 && sgp->sg_gui_fg == INVALCOLOR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9331 && sgp->sg_gui_bg == INVALCOLOR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9332 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9333 ) |
7 | 9334 sgp->sg_cterm_attr = sgp->sg_cterm; |
9335 else | |
9336 { | |
9337 at_en.ae_attr = sgp->sg_cterm; | |
9338 at_en.ae_u.cterm.fg_color = sgp->sg_cterm_fg; | |
9339 at_en.ae_u.cterm.bg_color = sgp->sg_cterm_bg; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9340 # ifdef FEAT_TERMGUICOLORS |
9054
f129fd3ebd98
commit https://github.com/vim/vim/commit/187147aedd588070d0676664d5076d046644094e
Christian Brabandt <cb@256bit.org>
parents:
9029
diff
changeset
|
9341 at_en.ae_u.cterm.fg_rgb = GUI_MCH_GET_RGB2(sgp->sg_gui_fg); |
f129fd3ebd98
commit https://github.com/vim/vim/commit/187147aedd588070d0676664d5076d046644094e
Christian Brabandt <cb@256bit.org>
parents:
9029
diff
changeset
|
9342 at_en.ae_u.cterm.bg_rgb = GUI_MCH_GET_RGB2(sgp->sg_gui_bg); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9343 # endif |
7 | 9344 sgp->sg_cterm_attr = get_attr_entry(&cterm_attr_table, &at_en); |
9345 } | |
9346 } | |
9347 | |
9348 /* | |
9349 * Lookup a highlight group name and return it's ID. | |
9350 * If it is not found, 0 is returned. | |
9351 */ | |
9352 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9353 syn_name2id(char_u *name) |
7 | 9354 { |
9355 int i; | |
9356 char_u name_u[200]; | |
9357 | |
9358 /* Avoid using stricmp() too much, it's slow on some systems */ | |
9359 /* Avoid alloc()/free(), these are slow too. ID names over 200 chars | |
9360 * don't deserve to be found! */ | |
419 | 9361 vim_strncpy(name_u, name, 199); |
7 | 9362 vim_strup(name_u); |
9363 for (i = highlight_ga.ga_len; --i >= 0; ) | |
9364 if (HL_TABLE()[i].sg_name_u != NULL | |
9365 && STRCMP(name_u, HL_TABLE()[i].sg_name_u) == 0) | |
9366 break; | |
9367 return i + 1; | |
9368 } | |
9369 | |
9370 #if defined(FEAT_EVAL) || defined(PROTO) | |
9371 /* | |
9372 * Return TRUE if highlight group "name" exists. | |
9373 */ | |
9374 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9375 highlight_exists(char_u *name) |
7 | 9376 { |
9377 return (syn_name2id(name) > 0); | |
9378 } | |
819 | 9379 |
9380 # if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) | |
9381 /* | |
9382 * Return the name of highlight group "id". | |
9383 * When not a valid ID return an empty string. | |
9384 */ | |
9385 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9386 syn_id2name(int id) |
819 | 9387 { |
1326 | 9388 if (id <= 0 || id > highlight_ga.ga_len) |
819 | 9389 return (char_u *)""; |
9390 return HL_TABLE()[id - 1].sg_name; | |
9391 } | |
9392 # endif | |
7 | 9393 #endif |
9394 | |
9395 /* | |
9396 * Like syn_name2id(), but take a pointer + length argument. | |
9397 */ | |
9398 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9399 syn_namen2id(char_u *linep, int len) |
7 | 9400 { |
9401 char_u *name; | |
9402 int id = 0; | |
9403 | |
9404 name = vim_strnsave(linep, len); | |
9405 if (name != NULL) | |
9406 { | |
9407 id = syn_name2id(name); | |
9408 vim_free(name); | |
9409 } | |
9410 return id; | |
9411 } | |
9412 | |
9413 /* | |
9414 * Find highlight group name in the table and return it's ID. | |
9415 * The argument is a pointer to the name and the length of the name. | |
9416 * If it doesn't exist yet, a new entry is created. | |
9417 * Return 0 for failure. | |
9418 */ | |
9419 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9420 syn_check_group(char_u *pp, int len) |
7 | 9421 { |
9422 int id; | |
9423 char_u *name; | |
9424 | |
9425 name = vim_strnsave(pp, len); | |
9426 if (name == NULL) | |
9427 return 0; | |
9428 | |
9429 id = syn_name2id(name); | |
9430 if (id == 0) /* doesn't exist yet */ | |
9431 id = syn_add_group(name); | |
9432 else | |
9433 vim_free(name); | |
9434 return id; | |
9435 } | |
9436 | |
9437 /* | |
9438 * Add new highlight group and return it's ID. | |
9439 * "name" must be an allocated string, it will be consumed. | |
9440 * Return 0 for failure. | |
9441 */ | |
9442 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9443 syn_add_group(char_u *name) |
7 | 9444 { |
9445 char_u *p; | |
9446 | |
9447 /* Check that the name is ASCII letters, digits and underscore. */ | |
9448 for (p = name; *p != NUL; ++p) | |
9449 { | |
9450 if (!vim_isprintc(*p)) | |
9451 { | |
9452 EMSG(_("E669: Unprintable character in group name")); | |
2020 | 9453 vim_free(name); |
7 | 9454 return 0; |
9455 } | |
9456 else if (!ASCII_ISALNUM(*p) && *p != '_') | |
9457 { | |
9458 /* This is an error, but since there previously was no check only | |
9459 * give a warning. */ | |
16 | 9460 msg_source(hl_attr(HLF_W)); |
7 | 9461 MSG(_("W18: Invalid character in group name")); |
9462 break; | |
9463 } | |
9464 } | |
9465 | |
9466 /* | |
9467 * First call for this growarray: init growing array. | |
9468 */ | |
9469 if (highlight_ga.ga_data == NULL) | |
9470 { | |
9471 highlight_ga.ga_itemsize = sizeof(struct hl_group); | |
9472 highlight_ga.ga_growsize = 10; | |
9473 } | |
9474 | |
2756 | 9475 if (highlight_ga.ga_len >= MAX_HL_ID) |
9476 { | |
9477 EMSG(_("E849: Too many highlight and syntax groups")); | |
2743 | 9478 vim_free(name); |
9479 return 0; | |
9480 } | |
9481 | |
7 | 9482 /* |
9483 * Make room for at least one other syntax_highlight entry. | |
9484 */ | |
9485 if (ga_grow(&highlight_ga, 1) == FAIL) | |
9486 { | |
9487 vim_free(name); | |
9488 return 0; | |
9489 } | |
9490 | |
9491 vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(struct hl_group)); | |
9492 HL_TABLE()[highlight_ga.ga_len].sg_name = name; | |
9493 HL_TABLE()[highlight_ga.ga_len].sg_name_u = vim_strsave_up(name); | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9494 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 9495 HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR; |
9496 HL_TABLE()[highlight_ga.ga_len].sg_gui_fg = INVALCOLOR; | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9497 # ifdef FEAT_GUI |
205 | 9498 HL_TABLE()[highlight_ga.ga_len].sg_gui_sp = INVALCOLOR; |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9499 # endif |
7 | 9500 #endif |
9501 ++highlight_ga.ga_len; | |
9502 | |
9503 return highlight_ga.ga_len; /* ID is index plus one */ | |
9504 } | |
9505 | |
9506 /* | |
9507 * When, just after calling syn_add_group(), an error is discovered, this | |
9508 * function deletes the new name. | |
9509 */ | |
9510 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9511 syn_unadd_group(void) |
7 | 9512 { |
9513 --highlight_ga.ga_len; | |
9514 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name); | |
9515 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); | |
9516 } | |
9517 | |
9518 /* | |
9519 * Translate a group ID to highlight attributes. | |
9520 */ | |
9521 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9522 syn_id2attr(int hl_id) |
7 | 9523 { |
9524 int attr; | |
9525 struct hl_group *sgp; | |
9526 | |
9527 hl_id = syn_get_final_id(hl_id); | |
9528 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9529 | |
9530 #ifdef FEAT_GUI | |
9531 /* | |
9532 * Only use GUI attr when the GUI is being used. | |
9533 */ | |
9534 if (gui.in_use) | |
9535 attr = sgp->sg_gui_attr; | |
9536 else | |
9537 #endif | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9538 if (IS_CTERM) |
7 | 9539 attr = sgp->sg_cterm_attr; |
9540 else | |
9541 attr = sgp->sg_term_attr; | |
9542 | |
9543 return attr; | |
9544 } | |
9545 | |
9546 #ifdef FEAT_GUI | |
9547 /* | |
9548 * Get the GUI colors and attributes for a group ID. | |
9549 * NOTE: the colors will be INVALCOLOR when not set, the color otherwise. | |
9550 */ | |
9551 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9552 syn_id2colors(int hl_id, guicolor_T *fgp, guicolor_T *bgp) |
7 | 9553 { |
9554 struct hl_group *sgp; | |
9555 | |
9556 hl_id = syn_get_final_id(hl_id); | |
9557 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9558 | |
9559 *fgp = sgp->sg_gui_fg; | |
9560 *bgp = sgp->sg_gui_bg; | |
9561 return sgp->sg_gui; | |
9562 } | |
9563 #endif | |
9564 | |
9565 /* | |
9566 * Translate a group ID to the final group ID (following links). | |
9567 */ | |
9568 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9569 syn_get_final_id(int hl_id) |
7 | 9570 { |
9571 int count; | |
9572 struct hl_group *sgp; | |
9573 | |
9574 if (hl_id > highlight_ga.ga_len || hl_id < 1) | |
9575 return 0; /* Can be called from eval!! */ | |
9576 | |
9577 /* | |
9578 * Follow links until there is no more. | |
9579 * Look out for loops! Break after 100 links. | |
9580 */ | |
9581 for (count = 100; --count >= 0; ) | |
9582 { | |
9583 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9584 if (sgp->sg_link == 0 || sgp->sg_link > highlight_ga.ga_len) | |
9585 break; | |
9586 hl_id = sgp->sg_link; | |
9587 } | |
9588 | |
9589 return hl_id; | |
9590 } | |
9591 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9592 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 9593 /* |
9594 * Call this function just after the GUI has started. | |
9595 * It finds the font and color handles for the highlighting groups. | |
9596 */ | |
9597 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9598 highlight_gui_started(void) |
7 | 9599 { |
9600 int idx; | |
9601 | |
9602 /* First get the colors from the "Normal" and "Menu" group, if set */ | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9603 # if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9604 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9605 if (USE_24BIT) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9606 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9607 set_normal_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9608 # endif |
7 | 9609 |
9610 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9611 gui_do_one_color(idx, FALSE, FALSE); | |
9612 | |
9613 highlight_changed(); | |
9614 } | |
9615 | |
9616 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9617 gui_do_one_color( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9618 int idx, |
8975
9c097bfad637
commit https://github.com/vim/vim/commit/380130f1e18da92a44372728fe044f56db58585b
Christian Brabandt <cb@256bit.org>
parents:
8969
diff
changeset
|
9619 int do_menu UNUSED, /* TRUE: might set the menu font */ |
9c097bfad637
commit https://github.com/vim/vim/commit/380130f1e18da92a44372728fe044f56db58585b
Christian Brabandt <cb@256bit.org>
parents:
8969
diff
changeset
|
9620 int do_tooltip UNUSED) /* TRUE: might set the tooltip font */ |
7 | 9621 { |
9622 int didit = FALSE; | |
9623 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9624 # ifdef FEAT_GUI |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9625 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9626 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9627 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9628 if (HL_TABLE()[idx].sg_font_name != NULL) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9629 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9630 hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu, |
3881 | 9631 do_tooltip, TRUE); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9632 didit = TRUE; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9633 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9634 # endif |
7 | 9635 if (HL_TABLE()[idx].sg_gui_fg_name != NULL) |
9636 { | |
9637 HL_TABLE()[idx].sg_gui_fg = | |
9638 color_name2handle(HL_TABLE()[idx].sg_gui_fg_name); | |
9639 didit = TRUE; | |
9640 } | |
9641 if (HL_TABLE()[idx].sg_gui_bg_name != NULL) | |
9642 { | |
9643 HL_TABLE()[idx].sg_gui_bg = | |
9644 color_name2handle(HL_TABLE()[idx].sg_gui_bg_name); | |
9645 didit = TRUE; | |
9646 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9647 # ifdef FEAT_GUI |
205 | 9648 if (HL_TABLE()[idx].sg_gui_sp_name != NULL) |
9649 { | |
9650 HL_TABLE()[idx].sg_gui_sp = | |
9651 color_name2handle(HL_TABLE()[idx].sg_gui_sp_name); | |
9652 didit = TRUE; | |
9653 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9654 # endif |
7 | 9655 if (didit) /* need to get a new attr number */ |
9656 set_hl_attr(idx); | |
9657 } | |
9658 #endif | |
9659 | |
9660 /* | |
9661 * Translate the 'highlight' option into attributes in highlight_attr[] and | |
9662 * set up the user highlights User1..9. If FEAT_STL_OPT is in use, a set of | |
9663 * corresponding highlights to use on top of HLF_SNC is computed. | |
9664 * Called only when the 'highlight' option has been changed and upon first | |
9665 * screen redraw after any :highlight command. | |
9666 * Return FAIL when an invalid flag is found in 'highlight'. OK otherwise. | |
9667 */ | |
9668 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9669 highlight_changed(void) |
7 | 9670 { |
9671 int hlf; | |
9672 int i; | |
9673 char_u *p; | |
9674 int attr; | |
9675 char_u *end; | |
9676 int id; | |
9677 #ifdef USER_HIGHLIGHT | |
9678 char_u userhl[10]; | |
9679 # ifdef FEAT_STL_OPT | |
9680 int id_SNC = -1; | |
9681 int id_S = -1; | |
9682 int hlcnt; | |
9683 # endif | |
9684 #endif | |
9685 static int hl_flags[HLF_COUNT] = HL_FLAGS; | |
9686 | |
9687 need_highlight_changed = FALSE; | |
9688 | |
9689 /* | |
9690 * Clear all attributes. | |
9691 */ | |
9692 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9693 highlight_attr[hlf] = 0; | |
9694 | |
9695 /* | |
9696 * First set all attributes to their default value. | |
9697 * Then use the attributes from the 'highlight' option. | |
9698 */ | |
9699 for (i = 0; i < 2; ++i) | |
9700 { | |
9701 if (i) | |
9702 p = p_hl; | |
9703 else | |
9704 p = get_highlight_default(); | |
9705 if (p == NULL) /* just in case */ | |
9706 continue; | |
9707 | |
9708 while (*p) | |
9709 { | |
9710 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9711 if (hl_flags[hlf] == *p) | |
9712 break; | |
9713 ++p; | |
9714 if (hlf == (int)HLF_COUNT || *p == NUL) | |
9715 return FAIL; | |
9716 | |
9717 /* | |
9718 * Allow several hl_flags to be combined, like "bu" for | |
9719 * bold-underlined. | |
9720 */ | |
9721 attr = 0; | |
9722 for ( ; *p && *p != ','; ++p) /* parse upto comma */ | |
9723 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
9724 if (VIM_ISWHITE(*p)) /* ignore white space */ |
7 | 9725 continue; |
9726 | |
9727 if (attr > HL_ALL) /* Combination with ':' is not allowed. */ | |
9728 return FAIL; | |
9729 | |
9730 switch (*p) | |
9731 { | |
9732 case 'b': attr |= HL_BOLD; | |
9733 break; | |
9734 case 'i': attr |= HL_ITALIC; | |
9735 break; | |
9736 case '-': | |
9737 case 'n': /* no highlighting */ | |
9738 break; | |
9739 case 'r': attr |= HL_INVERSE; | |
9740 break; | |
9741 case 's': attr |= HL_STANDOUT; | |
9742 break; | |
9743 case 'u': attr |= HL_UNDERLINE; | |
9744 break; | |
205 | 9745 case 'c': attr |= HL_UNDERCURL; |
9746 break; | |
7 | 9747 case ':': ++p; /* highlight group name */ |
9748 if (attr || *p == NUL) /* no combinations */ | |
9749 return FAIL; | |
9750 end = vim_strchr(p, ','); | |
9751 if (end == NULL) | |
9752 end = p + STRLEN(p); | |
9753 id = syn_check_group(p, (int)(end - p)); | |
9754 if (id == 0) | |
9755 return FAIL; | |
9756 attr = syn_id2attr(id); | |
9757 p = end - 1; | |
9758 #if defined(FEAT_STL_OPT) && defined(USER_HIGHLIGHT) | |
9759 if (hlf == (int)HLF_SNC) | |
9760 id_SNC = syn_get_final_id(id); | |
9761 else if (hlf == (int)HLF_S) | |
9762 id_S = syn_get_final_id(id); | |
9763 #endif | |
9764 break; | |
9765 default: return FAIL; | |
9766 } | |
9767 } | |
9768 highlight_attr[hlf] = attr; | |
9769 | |
9770 p = skip_to_option_part(p); /* skip comma and spaces */ | |
9771 } | |
9772 } | |
9773 | |
9774 #ifdef USER_HIGHLIGHT | |
9775 /* Setup the user highlights | |
9776 * | |
9777 * Temporarily utilize 10 more hl entries. Have to be in there | |
9778 * simultaneously in case of table overflows in get_attr_entry() | |
9779 */ | |
9780 # ifdef FEAT_STL_OPT | |
9781 if (ga_grow(&highlight_ga, 10) == FAIL) | |
9782 return FAIL; | |
9783 hlcnt = highlight_ga.ga_len; | |
9784 if (id_S == 0) | |
9785 { /* 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
|
9786 vim_memset(&HL_TABLE()[hlcnt + 9], 0, sizeof(struct hl_group)); |
7 | 9787 HL_TABLE()[hlcnt + 9].sg_term = highlight_attr[HLF_S]; |
9788 id_S = hlcnt + 10; | |
9789 } | |
9790 # endif | |
9791 for (i = 0; i < 9; i++) | |
9792 { | |
9793 sprintf((char *)userhl, "User%d", i + 1); | |
9794 id = syn_name2id(userhl); | |
9795 if (id == 0) | |
9796 { | |
9797 highlight_user[i] = 0; | |
9798 # ifdef FEAT_STL_OPT | |
9799 highlight_stlnc[i] = 0; | |
9800 # endif | |
9801 } | |
9802 else | |
9803 { | |
9804 # ifdef FEAT_STL_OPT | |
9805 struct hl_group *hlt = HL_TABLE(); | |
9806 # endif | |
9807 | |
9808 highlight_user[i] = syn_id2attr(id); | |
9809 # ifdef FEAT_STL_OPT | |
9810 if (id_SNC == 0) | |
9811 { | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2136
diff
changeset
|
9812 vim_memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group)); |
7 | 9813 hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC]; |
9814 hlt[hlcnt + i].sg_cterm = highlight_attr[HLF_SNC]; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9815 # if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9816 hlt[hlcnt + i].sg_gui = highlight_attr[HLF_SNC]; |
9817 # endif | |
9818 } | |
9819 else | |
9820 mch_memmove(&hlt[hlcnt + i], | |
9821 &hlt[id_SNC - 1], | |
9822 sizeof(struct hl_group)); | |
9823 hlt[hlcnt + i].sg_link = 0; | |
9824 | |
9825 /* Apply difference between UserX and HLF_S to HLF_SNC */ | |
9826 hlt[hlcnt + i].sg_term ^= | |
9827 hlt[id - 1].sg_term ^ hlt[id_S - 1].sg_term; | |
9828 if (hlt[id - 1].sg_start != hlt[id_S - 1].sg_start) | |
9829 hlt[hlcnt + i].sg_start = hlt[id - 1].sg_start; | |
9830 if (hlt[id - 1].sg_stop != hlt[id_S - 1].sg_stop) | |
9831 hlt[hlcnt + i].sg_stop = hlt[id - 1].sg_stop; | |
9832 hlt[hlcnt + i].sg_cterm ^= | |
9833 hlt[id - 1].sg_cterm ^ hlt[id_S - 1].sg_cterm; | |
9834 if (hlt[id - 1].sg_cterm_fg != hlt[id_S - 1].sg_cterm_fg) | |
9835 hlt[hlcnt + i].sg_cterm_fg = hlt[id - 1].sg_cterm_fg; | |
9836 if (hlt[id - 1].sg_cterm_bg != hlt[id_S - 1].sg_cterm_bg) | |
9837 hlt[hlcnt + i].sg_cterm_bg = hlt[id - 1].sg_cterm_bg; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9838 # if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9839 hlt[hlcnt + i].sg_gui ^= |
9840 hlt[id - 1].sg_gui ^ hlt[id_S - 1].sg_gui; | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9841 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9842 # ifdef FEAT_GUI |
7 | 9843 if (hlt[id - 1].sg_gui_fg != hlt[id_S - 1].sg_gui_fg) |
9844 hlt[hlcnt + i].sg_gui_fg = hlt[id - 1].sg_gui_fg; | |
9845 if (hlt[id - 1].sg_gui_bg != hlt[id_S - 1].sg_gui_bg) | |
9846 hlt[hlcnt + i].sg_gui_bg = hlt[id - 1].sg_gui_bg; | |
205 | 9847 if (hlt[id - 1].sg_gui_sp != hlt[id_S - 1].sg_gui_sp) |
9848 hlt[hlcnt + i].sg_gui_sp = hlt[id - 1].sg_gui_sp; | |
7 | 9849 if (hlt[id - 1].sg_font != hlt[id_S - 1].sg_font) |
9850 hlt[hlcnt + i].sg_font = hlt[id - 1].sg_font; | |
9851 # ifdef FEAT_XFONTSET | |
9852 if (hlt[id - 1].sg_fontset != hlt[id_S - 1].sg_fontset) | |
9853 hlt[hlcnt + i].sg_fontset = hlt[id - 1].sg_fontset; | |
9854 # endif | |
9855 # endif | |
9856 highlight_ga.ga_len = hlcnt + i + 1; | |
9857 set_hl_attr(hlcnt + i); /* At long last we can apply */ | |
9858 highlight_stlnc[i] = syn_id2attr(hlcnt + i + 1); | |
9859 # endif | |
9860 } | |
9861 } | |
9862 # ifdef FEAT_STL_OPT | |
9863 highlight_ga.ga_len = hlcnt; | |
9864 # endif | |
9865 | |
9866 #endif /* USER_HIGHLIGHT */ | |
9867 | |
9868 return OK; | |
9869 } | |
9870 | |
1322 | 9871 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
7 | 9872 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
9873 static void highlight_list(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
9874 static void highlight_list_two(int cnt, int attr); |
7 | 9875 |
9876 /* | |
9877 * Handle command line completion for :highlight command. | |
9878 */ | |
9879 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9880 set_context_in_highlight_cmd(expand_T *xp, char_u *arg) |
7 | 9881 { |
9882 char_u *p; | |
9883 | |
9884 /* Default: expand group names */ | |
9885 xp->xp_context = EXPAND_HIGHLIGHT; | |
9886 xp->xp_pattern = arg; | |
1322 | 9887 include_link = 2; |
9888 include_default = 1; | |
7 | 9889 |
9890 /* (part of) subcommand already typed */ | |
9891 if (*arg != NUL) | |
9892 { | |
9893 p = skiptowhite(arg); | |
9894 if (*p != NUL) /* past "default" or group name */ | |
9895 { | |
1322 | 9896 include_default = 0; |
7 | 9897 if (STRNCMP("default", arg, p - arg) == 0) |
9898 { | |
9899 arg = skipwhite(p); | |
9900 xp->xp_pattern = arg; | |
9901 p = skiptowhite(arg); | |
9902 } | |
9903 if (*p != NUL) /* past group name */ | |
9904 { | |
1322 | 9905 include_link = 0; |
7 | 9906 if (arg[1] == 'i' && arg[0] == 'N') |
9907 highlight_list(); | |
9908 if (STRNCMP("link", arg, p - arg) == 0 | |
9909 || STRNCMP("clear", arg, p - arg) == 0) | |
9910 { | |
9911 xp->xp_pattern = skipwhite(p); | |
9912 p = skiptowhite(xp->xp_pattern); | |
9913 if (*p != NUL) /* past first group name */ | |
9914 { | |
9915 xp->xp_pattern = skipwhite(p); | |
9916 p = skiptowhite(xp->xp_pattern); | |
9917 } | |
9918 } | |
9919 if (*p != NUL) /* past group name(s) */ | |
9920 xp->xp_context = EXPAND_NOTHING; | |
9921 } | |
9922 } | |
9923 } | |
9924 } | |
9925 | |
9926 /* | |
9927 * List highlighting matches in a nice way. | |
9928 */ | |
9929 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9930 highlight_list(void) |
7 | 9931 { |
9932 int i; | |
9933 | |
9934 for (i = 10; --i >= 0; ) | |
9935 highlight_list_two(i, hl_attr(HLF_D)); | |
9936 for (i = 40; --i >= 0; ) | |
9937 highlight_list_two(99, 0); | |
9938 } | |
9939 | |
9940 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9941 highlight_list_two(int cnt, int attr) |
7 | 9942 { |
3543 | 9943 msg_puts_attr((char_u *)&("N \bI \b! \b"[cnt / 11]), attr); |
7 | 9944 msg_clr_eos(); |
9945 out_flush(); | |
9946 ui_delay(cnt == 99 ? 40L : (long)cnt * 50L, FALSE); | |
9947 } | |
9948 | |
9949 #endif /* FEAT_CMDL_COMPL */ | |
9950 | |
9951 #if defined(FEAT_CMDL_COMPL) || (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) \ | |
9952 || defined(FEAT_SIGNS) || defined(PROTO) | |
9953 /* | |
9954 * Function given to ExpandGeneric() to obtain the list of group names. | |
9955 * Also used for synIDattr() function. | |
9956 */ | |
9957 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9958 get_highlight_name(expand_T *xp UNUSED, int idx) |
7 | 9959 { |
10660
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9960 if (idx < 0) |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9961 return NULL; |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9962 /* Items are never removed from the table, skip the ones that were cleared. |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9963 */ |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9964 while (idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared) |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9965 ++idx; |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
9966 |
7 | 9967 #ifdef FEAT_CMDL_COMPL |
1322 | 9968 if (idx == highlight_ga.ga_len && include_none != 0) |
9969 return (char_u *)"none"; | |
9970 if (idx == highlight_ga.ga_len + include_none && include_default != 0) | |
9971 return (char_u *)"default"; | |
9972 if (idx == highlight_ga.ga_len + include_none + include_default | |
9973 && include_link != 0) | |
7 | 9974 return (char_u *)"link"; |
1322 | 9975 if (idx == highlight_ga.ga_len + include_none + include_default + 1 |
9976 && include_link != 0) | |
7 | 9977 return (char_u *)"clear"; |
9978 #endif | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9979 if (idx >= highlight_ga.ga_len) |
7 | 9980 return NULL; |
9981 return HL_TABLE()[idx].sg_name; | |
9982 } | |
9983 #endif | |
9984 | |
1322 | 9985 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 9986 /* |
9987 * Free all the highlight group fonts. | |
9988 * Used when quitting for systems which need it. | |
9989 */ | |
9990 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9991 free_highlight_fonts(void) |
7 | 9992 { |
9993 int idx; | |
9994 | |
9995 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9996 { | |
9997 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
9998 HL_TABLE()[idx].sg_font = NOFONT; | |
9999 # ifdef FEAT_XFONTSET | |
10000 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
10001 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
10002 # endif | |
10003 } | |
10004 | |
10005 gui_mch_free_font(gui.norm_font); | |
10006 # ifdef FEAT_XFONTSET | |
10007 gui_mch_free_fontset(gui.fontset); | |
10008 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2256
diff
changeset
|
10009 # ifndef FEAT_GUI_GTK |
7 | 10010 gui_mch_free_font(gui.bold_font); |
10011 gui_mch_free_font(gui.ital_font); | |
10012 gui_mch_free_font(gui.boldital_font); | |
10013 # endif | |
10014 } | |
10015 #endif | |
10016 | |
10017 /************************************** | |
10018 * End of Highlighting stuff * | |
10019 **************************************/ |