Mercurial > vim
annotate src/syntax.c @ 10641:bcd353707cfc
Added tag v8.0.0210 for changeset 27be410d6d297c2be375da46e0c7f3c24c2b85fc
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 21 Jan 2017 20:15:05 +0100 |
parents | 16fc46021e51 |
children | 4f3decf25b7d |
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; | |
26 | 506 static int 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 |
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
519 || changedtick != syn_buf->b_changedtick) |
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 } |
26 | 525 changedtick = syn_buf->b_changedtick; |
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 { |
7 | 1186 win_T *wp; |
1187 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1188 syn_stack_free_block(block); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1189 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1190 |
7 | 1191 #ifdef FEAT_FOLDING |
1192 /* When using "syntax" fold method, must update all folds. */ | |
1193 FOR_ALL_WINDOWS(wp) | |
1194 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1195 if (wp->w_s == block && foldmethodIsSyntax(wp)) |
7 | 1196 foldUpdateAll(wp); |
1197 } | |
1198 #endif | |
1199 } | |
1200 | |
1201 /* | |
1202 * Allocate the syntax state stack for syn_buf when needed. | |
1203 * If the number of entries in b_sst_array[] is much too big or a bit too | |
1204 * small, reallocate it. | |
1205 * Also used to allocate b_sst_array[] for the first time. | |
1206 */ | |
1207 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1208 syn_stack_alloc(void) |
7 | 1209 { |
1210 long len; | |
1211 synstate_T *to, *from; | |
1212 synstate_T *sstp; | |
1213 | |
1214 len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; | |
1215 if (len < SST_MIN_ENTRIES) | |
1216 len = SST_MIN_ENTRIES; | |
1217 else if (len > SST_MAX_ENTRIES) | |
1218 len = SST_MAX_ENTRIES; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1219 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) |
7 | 1220 { |
1221 /* Allocate 50% too much, to avoid reallocating too often. */ | |
1222 len = syn_buf->b_ml.ml_line_count; | |
1223 len = (len + len / 2) / SST_DIST + Rows * 2; | |
1224 if (len < SST_MIN_ENTRIES) | |
1225 len = SST_MIN_ENTRIES; | |
1226 else if (len > SST_MAX_ENTRIES) | |
1227 len = SST_MAX_ENTRIES; | |
1228 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1229 if (syn_block->b_sst_array != NULL) |
7 | 1230 { |
1231 /* When shrinking the array, cleanup the existing stack. | |
1232 * 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
|
1233 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len |
7 | 1234 && syn_stack_cleanup()) |
1235 ; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1236 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
|
1237 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; |
7 | 1238 } |
1239 | |
1240 sstp = (synstate_T *)alloc_clear((unsigned)(len * sizeof(synstate_T))); | |
1241 if (sstp == NULL) /* out of memory! */ | |
1242 return; | |
1243 | |
1244 to = sstp - 1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1245 if (syn_block->b_sst_array != NULL) |
7 | 1246 { |
1247 /* 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
|
1248 for (from = syn_block->b_sst_first; from != NULL; |
7 | 1249 from = from->sst_next) |
1250 { | |
1251 ++to; | |
1252 *to = *from; | |
1253 to->sst_next = to + 1; | |
1254 } | |
1255 } | |
1256 if (to != sstp - 1) | |
1257 { | |
1258 to->sst_next = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1259 syn_block->b_sst_first = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1260 syn_block->b_sst_freecount = len - (int)(to - sstp) - 1; |
7 | 1261 } |
1262 else | |
1263 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1264 syn_block->b_sst_first = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1265 syn_block->b_sst_freecount = len; |
7 | 1266 } |
1267 | |
1268 /* Create the list of free entries. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1269 syn_block->b_sst_firstfree = to + 1; |
7 | 1270 while (++to < sstp + len) |
1271 to->sst_next = to + 1; | |
1272 (sstp + len - 1)->sst_next = NULL; | |
1273 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1274 vim_free(syn_block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1275 syn_block->b_sst_array = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1276 syn_block->b_sst_len = len; |
7 | 1277 } |
1278 } | |
1279 | |
1280 /* | |
1281 * Check for changes in a buffer to affect stored syntax states. Uses the | |
1282 * b_mod_* fields. | |
1283 * Called from update_screen(), before screen is being updated, once for each | |
1284 * displayed buffer. | |
1285 */ | |
1286 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1287 syn_stack_apply_changes(buf_T *buf) |
7 | 1288 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1289 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1290 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1291 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
|
1292 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1293 FOR_ALL_WINDOWS(wp) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1294 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1295 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
|
1296 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
|
1297 } |
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 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1301 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
|
1302 { |
7 | 1303 synstate_T *p, *prev, *np; |
1304 linenr_T n; | |
1305 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1306 if (block->b_sst_array == NULL) /* nothing to do */ |
7 | 1307 return; |
1308 | |
1309 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1310 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
|
1311 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1312 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) |
7 | 1313 { |
1314 n = p->sst_lnum + buf->b_mod_xlines; | |
1315 if (n <= buf->b_mod_bot) | |
1316 { | |
1317 /* this state is inside the changed area, remove it */ | |
1318 np = p->sst_next; | |
1319 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1320 block->b_sst_first = np; |
7 | 1321 else |
1322 prev->sst_next = np; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1323 syn_stack_free_entry(block, p); |
7 | 1324 p = np; |
1325 continue; | |
1326 } | |
1327 /* This state is below the changed area. Remember the line | |
1328 * that needs to be parsed before this entry can be made valid | |
1329 * again. */ | |
1330 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) | |
1331 { | |
1332 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) | |
1333 p->sst_change_lnum += buf->b_mod_xlines; | |
1334 else | |
1335 p->sst_change_lnum = buf->b_mod_top; | |
1336 } | |
1337 if (p->sst_change_lnum == 0 | |
1338 || p->sst_change_lnum < buf->b_mod_bot) | |
1339 p->sst_change_lnum = buf->b_mod_bot; | |
1340 | |
1341 p->sst_lnum = n; | |
1342 } | |
1343 prev = p; | |
1344 p = p->sst_next; | |
1345 } | |
1346 } | |
1347 | |
1348 /* | |
1349 * Reduce the number of entries in the state stack for syn_buf. | |
1350 * Returns TRUE if at least one entry was freed. | |
1351 */ | |
1352 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1353 syn_stack_cleanup(void) |
7 | 1354 { |
1355 synstate_T *p, *prev; | |
1356 disptick_T tick; | |
1357 int above; | |
1358 int dist; | |
1359 int retval = FALSE; | |
1360 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1361 if (syn_block->b_sst_array == NULL || syn_block->b_sst_first == NULL) |
7 | 1362 return retval; |
1363 | |
1364 /* 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
|
1365 if (syn_block->b_sst_len <= Rows) |
819 | 1366 dist = 999999; |
1367 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1368 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 1369 |
1370 /* | |
2020 | 1371 * Go through the list to find the "tick" for the oldest entry that can |
7 | 1372 * be removed. Set "above" when the "tick" for the oldest entry is above |
1373 * "b_sst_lasttick" (the display tick wraps around). | |
1374 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1375 tick = syn_block->b_sst_lasttick; |
7 | 1376 above = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1377 prev = syn_block->b_sst_first; |
7 | 1378 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1379 { | |
1380 if (prev->sst_lnum + dist > p->sst_lnum) | |
1381 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1382 if (p->sst_tick > syn_block->b_sst_lasttick) |
7 | 1383 { |
1384 if (!above || p->sst_tick < tick) | |
1385 tick = p->sst_tick; | |
1386 above = TRUE; | |
1387 } | |
1388 else if (!above && p->sst_tick < tick) | |
1389 tick = p->sst_tick; | |
1390 } | |
1391 } | |
1392 | |
1393 /* | |
1394 * Go through the list to make the entries for the oldest tick at an | |
1395 * interval of several lines. | |
1396 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1397 prev = syn_block->b_sst_first; |
7 | 1398 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1399 { | |
1400 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) | |
1401 { | |
1402 /* Move this entry from used list to free list */ | |
1403 prev->sst_next = p->sst_next; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1404 syn_stack_free_entry(syn_block, p); |
7 | 1405 p = prev; |
1406 retval = TRUE; | |
1407 } | |
1408 } | |
1409 return retval; | |
1410 } | |
1411 | |
1412 /* | |
1413 * Free the allocated memory for a syn_state item. | |
1414 * Move the entry into the free list. | |
1415 */ | |
1416 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1417 syn_stack_free_entry(synblock_T *block, synstate_T *p) |
7 | 1418 { |
1419 clear_syn_state(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1420 p->sst_next = block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1421 block->b_sst_firstfree = p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1422 ++block->b_sst_freecount; |
7 | 1423 } |
1424 | |
1425 /* | |
1426 * Find an entry in the list of state stacks at or before "lnum". | |
1427 * Returns NULL when there is no entry or the first entry is after "lnum". | |
1428 */ | |
1429 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1430 syn_stack_find_entry(linenr_T lnum) |
7 | 1431 { |
1432 synstate_T *p, *prev; | |
1433 | |
1434 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1435 for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) |
7 | 1436 { |
1437 if (p->sst_lnum == lnum) | |
1438 return p; | |
1439 if (p->sst_lnum > lnum) | |
1440 break; | |
1441 } | |
1442 return prev; | |
1443 } | |
1444 | |
1445 /* | |
1446 * Try saving the current state in b_sst_array[]. | |
1447 * The current state must be valid for the start of the current_lnum line! | |
1448 */ | |
1449 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1450 store_current_state(void) |
7 | 1451 { |
1452 int i; | |
1453 synstate_T *p; | |
1454 bufstate_T *bp; | |
1455 stateitem_T *cur_si; | |
1512 | 1456 synstate_T *sp = syn_stack_find_entry(current_lnum); |
7 | 1457 |
1458 /* | |
1459 * If the current state contains a start or end pattern that continues | |
1460 * from the previous line, we can't use it. Don't store it then. | |
1461 */ | |
1462 for (i = current_state.ga_len - 1; i >= 0; --i) | |
1463 { | |
1464 cur_si = &CUR_STATE(i); | |
1465 if (cur_si->si_h_startpos.lnum >= current_lnum | |
1466 || cur_si->si_m_endpos.lnum >= current_lnum | |
1467 || cur_si->si_h_endpos.lnum >= current_lnum | |
1468 || (cur_si->si_end_idx | |
1469 && cur_si->si_eoe_pos.lnum >= current_lnum)) | |
1470 break; | |
1471 } | |
1472 if (i >= 0) | |
1473 { | |
1474 if (sp != NULL) | |
1475 { | |
1476 /* 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
|
1477 if (syn_block->b_sst_first == sp) |
7 | 1478 /* it's the first entry */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1479 syn_block->b_sst_first = sp->sst_next; |
7 | 1480 else |
1481 { | |
1482 /* 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
|
1483 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 1484 if (p->sst_next == sp) |
1485 break; | |
840 | 1486 if (p != NULL) /* just in case */ |
1487 p->sst_next = sp->sst_next; | |
7 | 1488 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1489 syn_stack_free_entry(syn_block, sp); |
7 | 1490 sp = NULL; |
1491 } | |
1492 } | |
1493 else if (sp == NULL || sp->sst_lnum != current_lnum) | |
1494 { | |
1495 /* | |
1496 * Add a new entry | |
1497 */ | |
1498 /* 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
|
1499 if (syn_block->b_sst_freecount == 0) |
7 | 1500 { |
1501 (void)syn_stack_cleanup(); | |
1502 /* "sp" may have been moved to the freelist now */ | |
1503 sp = syn_stack_find_entry(current_lnum); | |
1504 } | |
1505 /* 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
|
1506 if (syn_block->b_sst_freecount == 0) |
7 | 1507 sp = NULL; |
1508 else | |
1509 { | |
1510 /* Take the first item from the free list and put it in the used | |
1511 * list, after *sp */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1512 p = syn_block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1513 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
|
1514 --syn_block->b_sst_freecount; |
7 | 1515 if (sp == NULL) |
1516 { | |
1517 /* Insert in front of the list */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1518 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
|
1519 syn_block->b_sst_first = p; |
7 | 1520 } |
1521 else | |
1522 { | |
1523 /* insert in list after *sp */ | |
1524 p->sst_next = sp->sst_next; | |
1525 sp->sst_next = p; | |
1526 } | |
1527 sp = p; | |
1528 sp->sst_stacksize = 0; | |
1529 sp->sst_lnum = current_lnum; | |
1530 } | |
1531 } | |
1532 if (sp != NULL) | |
1533 { | |
1534 /* When overwriting an existing state stack, clear it first */ | |
1535 clear_syn_state(sp); | |
1536 sp->sst_stacksize = current_state.ga_len; | |
1537 if (current_state.ga_len > SST_FIX_STATES) | |
1538 { | |
1539 /* Need to clear it, might be something remaining from when the | |
1540 * length was less than SST_FIX_STATES. */ | |
1541 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); | |
1542 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) | |
1543 sp->sst_stacksize = 0; | |
1544 else | |
1545 sp->sst_union.sst_ga.ga_len = current_state.ga_len; | |
1546 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1547 } | |
1548 else | |
1549 bp = sp->sst_union.sst_stack; | |
1550 for (i = 0; i < sp->sst_stacksize; ++i) | |
1551 { | |
1552 bp[i].bs_idx = CUR_STATE(i).si_idx; | |
1553 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
|
1554 #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
|
1555 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
|
1556 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
|
1557 #endif |
7 | 1558 bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); |
1559 } | |
1560 sp->sst_next_flags = current_next_flags; | |
1561 sp->sst_next_list = current_next_list; | |
1562 sp->sst_tick = display_tick; | |
1563 sp->sst_change_lnum = 0; | |
1564 } | |
1565 current_state_stored = TRUE; | |
1566 return sp; | |
1567 } | |
1568 | |
1569 /* | |
1570 * Copy a state stack from "from" in b_sst_array[] to current_state; | |
1571 */ | |
1572 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1573 load_current_state(synstate_T *from) |
7 | 1574 { |
1575 int i; | |
1576 bufstate_T *bp; | |
1577 | |
1578 clear_current_state(); | |
1579 validate_current_state(); | |
1580 keepend_level = -1; | |
1581 if (from->sst_stacksize | |
1582 && ga_grow(¤t_state, from->sst_stacksize) != FAIL) | |
1583 { | |
1584 if (from->sst_stacksize > SST_FIX_STATES) | |
1585 bp = SYN_STATE_P(&(from->sst_union.sst_ga)); | |
1586 else | |
1587 bp = from->sst_union.sst_stack; | |
1588 for (i = 0; i < from->sst_stacksize; ++i) | |
1589 { | |
1590 CUR_STATE(i).si_idx = bp[i].bs_idx; | |
1591 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
|
1592 #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
|
1593 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
|
1594 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
|
1595 #endif |
7 | 1596 CUR_STATE(i).si_extmatch = ref_extmatch(bp[i].bs_extmatch); |
1597 if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) | |
1598 keepend_level = i; | |
1599 CUR_STATE(i).si_ends = FALSE; | |
1600 CUR_STATE(i).si_m_lnum = 0; | |
1601 if (CUR_STATE(i).si_idx >= 0) | |
1602 CUR_STATE(i).si_next_list = | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1603 (SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_next_list; |
7 | 1604 else |
1605 CUR_STATE(i).si_next_list = NULL; | |
1606 update_si_attr(i); | |
1607 } | |
1608 current_state.ga_len = from->sst_stacksize; | |
1609 } | |
1610 current_next_list = from->sst_next_list; | |
1611 current_next_flags = from->sst_next_flags; | |
1612 current_lnum = from->sst_lnum; | |
1613 } | |
1614 | |
1615 /* | |
1616 * Compare saved state stack "*sp" with the current state. | |
1617 * Return TRUE when they are equal. | |
1618 */ | |
1619 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1620 syn_stack_equal(synstate_T *sp) |
7 | 1621 { |
1622 int i, j; | |
1623 bufstate_T *bp; | |
1624 reg_extmatch_T *six, *bsx; | |
1625 | |
1626 /* First a quick check if the stacks have the same size end nextlist. */ | |
1627 if (sp->sst_stacksize == current_state.ga_len | |
1628 && sp->sst_next_list == current_next_list) | |
1629 { | |
1630 /* Need to compare all states on both stacks. */ | |
1631 if (sp->sst_stacksize > SST_FIX_STATES) | |
1632 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1633 else | |
1634 bp = sp->sst_union.sst_stack; | |
1635 | |
1636 for (i = current_state.ga_len; --i >= 0; ) | |
1637 { | |
1638 /* If the item has another index the state is different. */ | |
1639 if (bp[i].bs_idx != CUR_STATE(i).si_idx) | |
1640 break; | |
1641 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) | |
1642 { | |
1643 /* When the extmatch pointers are different, the strings in | |
1644 * them can still be the same. Check if the extmatch | |
1645 * references are equal. */ | |
1646 bsx = bp[i].bs_extmatch; | |
1647 six = CUR_STATE(i).si_extmatch; | |
1648 /* If one of the extmatch pointers is NULL the states are | |
1649 * different. */ | |
1650 if (bsx == NULL || six == NULL) | |
1651 break; | |
1652 for (j = 0; j < NSUBEXP; ++j) | |
1653 { | |
1654 /* Check each referenced match string. They must all be | |
1655 * equal. */ | |
1656 if (bsx->matches[j] != six->matches[j]) | |
1657 { | |
1658 /* If the pointer is different it can still be the | |
1659 * same text. Compare the strings, ignore case when | |
1660 * the start item has the sp_ic flag set. */ | |
1661 if (bsx->matches[j] == NULL | |
1662 || six->matches[j] == NULL) | |
1663 break; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1664 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic |
7 | 1665 ? MB_STRICMP(bsx->matches[j], |
1666 six->matches[j]) != 0 | |
1667 : STRCMP(bsx->matches[j], six->matches[j]) != 0) | |
1668 break; | |
1669 } | |
1670 } | |
1671 if (j != NSUBEXP) | |
1672 break; | |
1673 } | |
1674 } | |
1675 if (i < 0) | |
1676 return TRUE; | |
1677 } | |
1678 return FALSE; | |
1679 } | |
1680 | |
1681 /* | |
1682 * We stop parsing syntax above line "lnum". If the stored state at or below | |
1683 * this line depended on a change before it, it now depends on the line below | |
1684 * the last parsed line. | |
1685 * The window looks like this: | |
1686 * line which changed | |
1687 * displayed line | |
1688 * displayed line | |
1689 * lnum -> line below window | |
1690 */ | |
1691 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1692 syntax_end_parsing(linenr_T lnum) |
7 | 1693 { |
1694 synstate_T *sp; | |
1695 | |
1696 sp = syn_stack_find_entry(lnum); | |
1697 if (sp != NULL && sp->sst_lnum < lnum) | |
1698 sp = sp->sst_next; | |
1699 | |
1700 if (sp != NULL && sp->sst_change_lnum != 0) | |
1701 sp->sst_change_lnum = lnum; | |
1702 } | |
1703 | |
1704 /* | |
1705 * End of handling of the state stack. | |
1706 ****************************************/ | |
1707 | |
1708 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1709 invalidate_current_state(void) |
7 | 1710 { |
1711 clear_current_state(); | |
1712 current_state.ga_itemsize = 0; /* mark current_state invalid */ | |
1713 current_next_list = NULL; | |
1714 keepend_level = -1; | |
1715 } | |
1716 | |
1717 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1718 validate_current_state(void) |
7 | 1719 { |
1720 current_state.ga_itemsize = sizeof(stateitem_T); | |
1721 current_state.ga_growsize = 3; | |
1722 } | |
1723 | |
1724 /* | |
1725 * Return TRUE if the syntax at start of lnum changed since last time. | |
1726 * This will only be called just after get_syntax_attr() for the previous | |
1727 * line, to check if the next line needs to be redrawn too. | |
1728 */ | |
1729 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1730 syntax_check_changed(linenr_T lnum) |
7 | 1731 { |
1732 int retval = TRUE; | |
1733 synstate_T *sp; | |
1734 | |
1735 /* | |
1736 * Check the state stack when: | |
1737 * - lnum is just below the previously syntaxed line. | |
1738 * - lnum is not before the lines with saved states. | |
1739 * - lnum is not past the lines with saved states. | |
1740 * - lnum is at or before the last changed line. | |
1741 */ | |
1742 if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) | |
1743 { | |
1744 sp = syn_stack_find_entry(lnum); | |
1745 if (sp != NULL && sp->sst_lnum == lnum) | |
1746 { | |
1747 /* | |
1748 * finish the previous line (needed when not all of the line was | |
1749 * drawn) | |
1750 */ | |
1751 (void)syn_finish_line(FALSE); | |
1752 | |
1753 /* | |
1754 * Compare the current state with the previously saved state of | |
1755 * the line. | |
1756 */ | |
1757 if (syn_stack_equal(sp)) | |
1758 retval = FALSE; | |
1759 | |
1760 /* | |
1761 * Store the current state in b_sst_array[] for later use. | |
1762 */ | |
1763 ++current_lnum; | |
1512 | 1764 (void)store_current_state(); |
7 | 1765 } |
1766 } | |
1767 | |
1768 return retval; | |
1769 } | |
1770 | |
1771 /* | |
1772 * Finish the current line. | |
1773 * This doesn't return any attributes, it only gets the state at the end of | |
1774 * the line. It can start anywhere in the line, as long as the current state | |
1775 * is valid. | |
1776 */ | |
1777 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1778 syn_finish_line( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1779 int syncing) /* called for syncing */ |
7 | 1780 { |
1781 stateitem_T *cur_si; | |
442 | 1782 colnr_T prev_current_col; |
7 | 1783 |
1784 if (!current_finished) | |
1785 { | |
1786 while (!current_finished) | |
1787 { | |
1504 | 1788 (void)syn_current_attr(syncing, FALSE, NULL, FALSE); |
7 | 1789 /* |
1790 * When syncing, and found some item, need to check the item. | |
1791 */ | |
1792 if (syncing && current_state.ga_len) | |
1793 { | |
1794 /* | |
1795 * Check for match with sync item. | |
1796 */ | |
1797 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1798 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1799 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags |
7 | 1800 & (HL_SYNC_HERE|HL_SYNC_THERE))) |
1801 return TRUE; | |
1802 | |
1803 /* syn_current_attr() will have skipped the check for an item | |
442 | 1804 * that ends here, need to do that now. Be careful not to go |
1805 * past the NUL. */ | |
1806 prev_current_col = current_col; | |
1807 if (syn_getcurline()[current_col] != NUL) | |
1808 ++current_col; | |
7 | 1809 check_state_ends(); |
442 | 1810 current_col = prev_current_col; |
7 | 1811 } |
1812 ++current_col; | |
1813 } | |
1814 } | |
1815 return FALSE; | |
1816 } | |
1817 | |
1818 /* | |
1819 * Return highlight attributes for next character. | |
1820 * Must first call syntax_start() once for the line. | |
1821 * "col" is normally 0 for the first use in a line, and increments by one each | |
1822 * time. It's allowed to skip characters and to stop before the end of the | |
1823 * line. But only a "col" after a previously used column is allowed. | |
221 | 1824 * When "can_spell" is not NULL set it to TRUE when spell-checking should be |
1825 * done. | |
7 | 1826 */ |
1827 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1828 get_syntax_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1829 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1830 int *can_spell, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1831 int keep_state) /* keep state of char at "col" */ |
7 | 1832 { |
1833 int attr = 0; | |
1834 | |
1363 | 1835 if (can_spell != NULL) |
1836 /* Default: Only do spelling when there is no @Spell cluster or when | |
1837 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1838 *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
|
1839 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1840 : (syn_block->b_syn_spell == SYNSPL_TOP); |
1363 | 1841 |
7 | 1842 /* check for out of memory situation */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1843 if (syn_block->b_sst_array == NULL) |
7 | 1844 return 0; |
1845 | |
419 | 1846 /* After 'synmaxcol' the attribute is always zero. */ |
431 | 1847 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) |
419 | 1848 { |
1849 clear_current_state(); | |
1850 #ifdef FEAT_EVAL | |
1851 current_id = 0; | |
1852 current_trans_id = 0; | |
1853 #endif | |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1854 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1855 current_flags = 0; |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1856 #endif |
419 | 1857 return 0; |
1858 } | |
1859 | |
7 | 1860 /* Make sure current_state is valid */ |
1861 if (INVALID_STATE(¤t_state)) | |
1862 validate_current_state(); | |
1863 | |
1864 /* | |
1865 * Skip from the current column to "col", get the attributes for "col". | |
1866 */ | |
1867 while (current_col <= col) | |
1868 { | |
1504 | 1869 attr = syn_current_attr(FALSE, TRUE, can_spell, |
1870 current_col == col ? keep_state : FALSE); | |
7 | 1871 ++current_col; |
1872 } | |
1873 | |
1874 return attr; | |
1875 } | |
1876 | |
1877 /* | |
1878 * Get syntax attributes for current_lnum, current_col. | |
1879 */ | |
1880 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1881 syn_current_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1882 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
|
1883 int displaying, /* result will be displayed */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1884 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
|
1885 int keep_state) /* keep syntax stack afterwards */ |
7 | 1886 { |
1887 int syn_id; | |
1888 lpos_T endpos; /* was: char_u *endp; */ | |
1889 lpos_T hl_startpos; /* was: int hl_startcol; */ | |
1890 lpos_T hl_endpos; | |
1891 lpos_T eos_pos; /* end-of-start match (start region) */ | |
1892 lpos_T eoe_pos; /* end-of-end pattern */ | |
1893 int end_idx; /* group ID for end pattern */ | |
1894 int idx; | |
1895 synpat_T *spp; | |
221 | 1896 stateitem_T *cur_si, *sip = NULL; |
7 | 1897 int startcol; |
1898 int endcol; | |
1899 long flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1900 int cchar; |
7 | 1901 short *next_list; |
1902 int found_match; /* found usable match */ | |
1903 static int try_next_column = FALSE; /* must try in next col */ | |
1904 int do_keywords; | |
1905 regmmatch_T regmatch; | |
1906 lpos_T pos; | |
1907 int lc_col; | |
1908 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
|
1909 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ |
7 | 1910 char_u *line; /* current line. NOTE: becomes invalid after |
1911 looking for a pattern match! */ | |
1912 | |
1913 /* variables for zero-width matches that have a "nextgroup" argument */ | |
1914 int keep_next_list; | |
1915 int zero_width_next_list = FALSE; | |
1916 garray_T zero_width_next_ga; | |
1917 | |
1918 /* | |
1919 * No character, no attributes! Past end of line? | |
1920 * Do try matching with an empty line (could be the start of a region). | |
1921 */ | |
1922 line = syn_getcurline(); | |
1923 if (line[current_col] == NUL && current_col != 0) | |
1924 { | |
1925 /* | |
1926 * If we found a match after the last column, use it. | |
1927 */ | |
1928 if (next_match_idx >= 0 && next_match_col >= (int)current_col | |
1929 && next_match_col != MAXCOL) | |
1930 (void)push_next_match(NULL); | |
1931 | |
1932 current_finished = TRUE; | |
1933 current_state_stored = FALSE; | |
1934 return 0; | |
1935 } | |
1936 | |
1937 /* if the current or next character is NUL, we will finish the line now */ | |
1938 if (line[current_col] == NUL || line[current_col + 1] == NUL) | |
1939 { | |
1940 current_finished = TRUE; | |
1941 current_state_stored = FALSE; | |
1942 } | |
1943 | |
1944 /* | |
1945 * When in the previous column there was a match but it could not be used | |
1946 * (empty match or already matched in this column) need to try again in | |
1947 * the next column. | |
1948 */ | |
1949 if (try_next_column) | |
1950 { | |
1951 next_match_idx = -1; | |
1952 try_next_column = FALSE; | |
1953 } | |
1954 | |
1955 /* Only check for keywords when not syncing and there are some. */ | |
1956 do_keywords = !syncing | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1957 && (syn_block->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1958 || syn_block->b_keywtab_ic.ht_used > 0); |
7 | 1959 |
1960 /* Init the list of zero-width matches with a nextlist. This is used to | |
1961 * avoid matching the same item in the same position twice. */ | |
1962 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10); | |
1963 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1964 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1965 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1966 |
7 | 1967 /* |
1968 * Repeat matching keywords and patterns, to find contained items at the | |
1969 * same column. This stops when there are no extra matches at the current | |
1970 * column. | |
1971 */ | |
1972 do | |
1973 { | |
1974 found_match = FALSE; | |
1975 keep_next_list = FALSE; | |
1976 syn_id = 0; | |
1977 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1978 |
7 | 1979 /* |
1980 * 1. Check for a current state. | |
1981 * Only when there is no current state, or if the current state may | |
1982 * contain other things, we need to check for keywords and patterns. | |
1983 * Always need to check for contained items if some item has the | |
1984 * "containedin" argument (takes extra time!). | |
1985 */ | |
1986 if (current_state.ga_len) | |
1987 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1988 else | |
1989 cur_si = NULL; | |
1990 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1991 if (syn_block->b_syn_containedin || cur_si == NULL |
7 | 1992 || cur_si->si_cont_list != NULL) |
1993 { | |
1994 /* | |
1995 * 2. Check for keywords, if on a keyword char after a non-keyword | |
1996 * char. Don't do this when syncing. | |
1997 */ | |
1998 if (do_keywords) | |
1999 { | |
2000 line = syn_getcurline(); | |
4043 | 2001 if (vim_iswordp_buf(line + current_col, syn_buf) |
7 | 2002 && (current_col == 0 |
4043 | 2003 || !vim_iswordp_buf(line + current_col - 1 |
7 | 2004 #ifdef FEAT_MBYTE |
2005 - (has_mbyte | |
2006 ? (*mb_head_off)(line, line + current_col - 1) | |
2007 : 0) | |
2008 #endif | |
2009 , syn_buf))) | |
2010 { | |
2011 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
|
2012 &endcol, &flags, &next_list, cur_si, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2013 &cchar); |
205 | 2014 if (syn_id != 0) |
7 | 2015 { |
2016 if (push_current_state(KEYWORD_IDX) == OK) | |
2017 { | |
2018 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2019 cur_si->si_m_startcol = current_col; | |
2020 cur_si->si_h_startpos.lnum = current_lnum; | |
2021 cur_si->si_h_startpos.col = 0; /* starts right away */ | |
2022 cur_si->si_m_endpos.lnum = current_lnum; | |
2023 cur_si->si_m_endpos.col = endcol; | |
2024 cur_si->si_h_endpos.lnum = current_lnum; | |
2025 cur_si->si_h_endpos.col = endcol; | |
2026 cur_si->si_ends = TRUE; | |
2027 cur_si->si_end_idx = 0; | |
2028 cur_si->si_flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2029 #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
|
2030 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
|
2031 cur_si->si_cchar = cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2032 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2033 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2034 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
|
2035 & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2036 #endif |
7 | 2037 cur_si->si_id = syn_id; |
2038 cur_si->si_trans_id = syn_id; | |
2039 if (flags & HL_TRANSP) | |
2040 { | |
2041 if (current_state.ga_len < 2) | |
2042 { | |
2043 cur_si->si_attr = 0; | |
2044 cur_si->si_trans_id = 0; | |
2045 } | |
2046 else | |
2047 { | |
2048 cur_si->si_attr = CUR_STATE( | |
2049 current_state.ga_len - 2).si_attr; | |
2050 cur_si->si_trans_id = CUR_STATE( | |
2051 current_state.ga_len - 2).si_trans_id; | |
2052 } | |
2053 } | |
2054 else | |
2055 cur_si->si_attr = syn_id2attr(syn_id); | |
2056 cur_si->si_cont_list = NULL; | |
2057 cur_si->si_next_list = next_list; | |
2058 check_keepend(); | |
2059 } | |
2060 else | |
2061 vim_free(next_list); | |
2062 } | |
2063 } | |
2064 } | |
2065 | |
2066 /* | |
205 | 2067 * 3. Check for patterns (only if no keyword found). |
7 | 2068 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2069 if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) |
7 | 2070 { |
2071 /* | |
2072 * If we didn't check for a match yet, or we are past it, check | |
2073 * for any match with a pattern. | |
2074 */ | |
2075 if (next_match_idx < 0 || next_match_col < (int)current_col) | |
2076 { | |
2077 /* | |
2078 * Check all relevant patterns for a match at this | |
2079 * position. This is complicated, because matching with a | |
2080 * pattern takes quite a bit of time, thus we want to | |
2081 * avoid doing it when it's not needed. | |
2082 */ | |
2083 next_match_idx = 0; /* no match in this line yet */ | |
2084 next_match_col = MAXCOL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2085 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
7 | 2086 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2087 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2088 if ( spp->sp_syncing == syncing |
2089 && (displaying || !(spp->sp_flags & HL_DISPLAY)) | |
2090 && (spp->sp_type == SPTYPE_MATCH | |
2091 || spp->sp_type == SPTYPE_START) | |
2092 && (current_next_list != NULL | |
2093 ? in_id_list(NULL, current_next_list, | |
2094 &spp->sp_syn, 0) | |
2095 : (cur_si == NULL | |
2096 ? !(spp->sp_flags & HL_CONTAINED) | |
2097 : in_id_list(cur_si, | |
2098 cur_si->si_cont_list, &spp->sp_syn, | |
2099 spp->sp_flags & HL_CONTAINED)))) | |
2100 { | |
6375 | 2101 int r; |
2102 | |
7 | 2103 /* If we already tried matching in this line, and |
2104 * there isn't a match before next_match_col, skip | |
2105 * this item. */ | |
2106 if (spp->sp_line_id == current_line_id | |
2107 && spp->sp_startcol >= next_match_col) | |
2108 continue; | |
2109 spp->sp_line_id = current_line_id; | |
2110 | |
2111 lc_col = current_col - spp->sp_offsets[SPO_LC_OFF]; | |
2112 if (lc_col < 0) | |
2113 lc_col = 0; | |
2114 | |
2115 regmatch.rmm_ic = spp->sp_ic; | |
2116 regmatch.regprog = spp->sp_prog; | |
6375 | 2117 r = syn_regexec(®match, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2118 current_lnum, |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2119 (colnr_T)lc_col, |
6375 | 2120 IF_SYN_TIME(&spp->sp_time)); |
2121 spp->sp_prog = regmatch.regprog; | |
2122 if (!r) | |
7 | 2123 { |
2124 /* no match in this line, try another one */ | |
2125 spp->sp_startcol = MAXCOL; | |
2126 continue; | |
2127 } | |
2128 | |
2129 /* | |
2130 * Compute the first column of the match. | |
2131 */ | |
2132 syn_add_start_off(&pos, ®match, | |
2133 spp, SPO_MS_OFF, -1); | |
2134 if (pos.lnum > current_lnum) | |
2135 { | |
2136 /* must have used end of match in a next line, | |
2137 * we can't handle that */ | |
2138 spp->sp_startcol = MAXCOL; | |
2139 continue; | |
2140 } | |
2141 startcol = pos.col; | |
2142 | |
2143 /* remember the next column where this pattern | |
2144 * matches in the current line */ | |
2145 spp->sp_startcol = startcol; | |
2146 | |
2147 /* | |
2148 * If a previously found match starts at a lower | |
2149 * column number, don't use this one. | |
2150 */ | |
2151 if (startcol >= next_match_col) | |
2152 continue; | |
2153 | |
2154 /* | |
2155 * If we matched this pattern at this position | |
2156 * before, skip it. Must retry in the next | |
2157 * column, because it may match from there. | |
2158 */ | |
2159 if (did_match_already(idx, &zero_width_next_ga)) | |
2160 { | |
2161 try_next_column = TRUE; | |
2162 continue; | |
2163 } | |
2164 | |
2165 endpos.lnum = regmatch.endpos[0].lnum; | |
2166 endpos.col = regmatch.endpos[0].col; | |
2167 | |
2168 /* Compute the highlight start. */ | |
2169 syn_add_start_off(&hl_startpos, ®match, | |
2170 spp, SPO_HS_OFF, -1); | |
2171 | |
2172 /* Compute the region start. */ | |
2173 /* Default is to use the end of the match. */ | |
2174 syn_add_end_off(&eos_pos, ®match, | |
2175 spp, SPO_RS_OFF, 0); | |
2176 | |
2177 /* | |
2178 * Grab the external submatches before they get | |
2179 * overwritten. Reference count doesn't change. | |
2180 */ | |
2181 unref_extmatch(cur_extmatch); | |
2182 cur_extmatch = re_extmatch_out; | |
2183 re_extmatch_out = NULL; | |
2184 | |
2185 flags = 0; | |
2186 eoe_pos.lnum = 0; /* avoid warning */ | |
2187 eoe_pos.col = 0; | |
2188 end_idx = 0; | |
2189 hl_endpos.lnum = 0; | |
2190 | |
2191 /* | |
2192 * For a "oneline" the end must be found in the | |
2193 * same line too. Search for it after the end of | |
2194 * the match with the start pattern. Set the | |
2195 * resulting end positions at the same time. | |
2196 */ | |
2197 if (spp->sp_type == SPTYPE_START | |
2198 && (spp->sp_flags & HL_ONELINE)) | |
2199 { | |
2200 lpos_T startpos; | |
2201 | |
2202 startpos = endpos; | |
2203 find_endpos(idx, &startpos, &endpos, &hl_endpos, | |
2204 &flags, &eoe_pos, &end_idx, cur_extmatch); | |
2205 if (endpos.lnum == 0) | |
2206 continue; /* not found */ | |
2207 } | |
2208 | |
2209 /* | |
2210 * For a "match" the size must be > 0 after the | |
2211 * end offset needs has been added. Except when | |
2212 * syncing. | |
2213 */ | |
2214 else if (spp->sp_type == SPTYPE_MATCH) | |
2215 { | |
2216 syn_add_end_off(&hl_endpos, ®match, spp, | |
2217 SPO_HE_OFF, 0); | |
2218 syn_add_end_off(&endpos, ®match, spp, | |
2219 SPO_ME_OFF, 0); | |
2220 if (endpos.lnum == current_lnum | |
2221 && (int)endpos.col + syncing < startcol) | |
2222 { | |
2223 /* | |
2224 * If an empty string is matched, may need | |
2225 * to try matching again at next column. | |
2226 */ | |
2227 if (regmatch.startpos[0].col | |
2228 == regmatch.endpos[0].col) | |
2229 try_next_column = TRUE; | |
2230 continue; | |
2231 } | |
2232 } | |
2233 | |
2234 /* | |
2235 * keep the best match so far in next_match_* | |
2236 */ | |
2237 /* Highlighting must start after startpos and end | |
2238 * before endpos. */ | |
2239 if (hl_startpos.lnum == current_lnum | |
2240 && (int)hl_startpos.col < startcol) | |
2241 hl_startpos.col = startcol; | |
2242 limit_pos_zero(&hl_endpos, &endpos); | |
2243 | |
2244 next_match_idx = idx; | |
2245 next_match_col = startcol; | |
2246 next_match_m_endpos = endpos; | |
2247 next_match_h_endpos = hl_endpos; | |
2248 next_match_h_startpos = hl_startpos; | |
2249 next_match_flags = flags; | |
2250 next_match_eos_pos = eos_pos; | |
2251 next_match_eoe_pos = eoe_pos; | |
2252 next_match_end_idx = end_idx; | |
2253 unref_extmatch(next_match_extmatch); | |
2254 next_match_extmatch = cur_extmatch; | |
2255 cur_extmatch = NULL; | |
2256 } | |
2257 } | |
2258 } | |
2259 | |
2260 /* | |
2261 * If we found a match at the current column, use it. | |
2262 */ | |
2263 if (next_match_idx >= 0 && next_match_col == (int)current_col) | |
2264 { | |
2265 synpat_T *lspp; | |
2266 | |
2267 /* When a zero-width item matched which has a nextgroup, | |
2268 * 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
|
2269 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2270 if (next_match_m_endpos.lnum == current_lnum |
2271 && next_match_m_endpos.col == current_col | |
2272 && lspp->sp_next_list != NULL) | |
2273 { | |
2274 current_next_list = lspp->sp_next_list; | |
2275 current_next_flags = lspp->sp_flags; | |
2276 keep_next_list = TRUE; | |
2277 zero_width_next_list = TRUE; | |
2278 | |
2279 /* Add the index to a list, so that we can check | |
2280 * later that we don't match it again (and cause an | |
2281 * endless loop). */ | |
2282 if (ga_grow(&zero_width_next_ga, 1) == OK) | |
2283 { | |
2284 ((int *)(zero_width_next_ga.ga_data)) | |
2285 [zero_width_next_ga.ga_len++] = next_match_idx; | |
2286 } | |
2287 next_match_idx = -1; | |
2288 } | |
2289 else | |
2290 cur_si = push_next_match(cur_si); | |
2291 found_match = TRUE; | |
2292 } | |
2293 } | |
2294 } | |
2295 | |
2296 /* | |
2297 * Handle searching for nextgroup match. | |
2298 */ | |
2299 if (current_next_list != NULL && !keep_next_list) | |
2300 { | |
2301 /* | |
2302 * If a nextgroup was not found, continue looking for one if: | |
2303 * - this is an empty line and the "skipempty" option was given | |
2304 * - we are on white space and the "skipwhite" option was given | |
2305 */ | |
2306 if (!found_match) | |
2307 { | |
2308 line = syn_getcurline(); | |
2309 if (((current_next_flags & HL_SKIPWHITE) | |
2310 && vim_iswhite(line[current_col])) | |
2311 || ((current_next_flags & HL_SKIPEMPTY) | |
2312 && *line == NUL)) | |
2313 break; | |
2314 } | |
2315 | |
2316 /* | |
2317 * If a nextgroup was found: Use it, and continue looking for | |
2318 * contained matches. | |
2319 * If a nextgroup was not found: Continue looking for a normal | |
2320 * match. | |
2321 * When did set current_next_list for a zero-width item and no | |
2322 * match was found don't loop (would get stuck). | |
2323 */ | |
2324 current_next_list = NULL; | |
2325 next_match_idx = -1; | |
2326 if (!zero_width_next_list) | |
2327 found_match = TRUE; | |
2328 } | |
2329 | |
2330 } while (found_match); | |
2331 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2332 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2333 |
7 | 2334 /* |
2335 * Use attributes from the current state, if within its highlighting. | |
2336 * If not, use attributes from the current-but-one state, etc. | |
2337 */ | |
2338 current_attr = 0; | |
2339 #ifdef FEAT_EVAL | |
2340 current_id = 0; | |
2341 current_trans_id = 0; | |
2342 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2343 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2344 current_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2345 #endif |
7 | 2346 if (cur_si != NULL) |
2347 { | |
221 | 2348 #ifndef FEAT_EVAL |
2349 int current_trans_id = 0; | |
2350 #endif | |
7 | 2351 for (idx = current_state.ga_len - 1; idx >= 0; --idx) |
2352 { | |
2353 sip = &CUR_STATE(idx); | |
2354 if ((current_lnum > sip->si_h_startpos.lnum | |
2355 || (current_lnum == sip->si_h_startpos.lnum | |
2356 && current_col >= sip->si_h_startpos.col)) | |
2357 && (sip->si_h_endpos.lnum == 0 | |
2358 || current_lnum < sip->si_h_endpos.lnum | |
2359 || (current_lnum == sip->si_h_endpos.lnum | |
2360 && current_col < sip->si_h_endpos.col))) | |
2361 { | |
2362 current_attr = sip->si_attr; | |
2363 #ifdef FEAT_EVAL | |
2364 current_id = sip->si_id; | |
221 | 2365 #endif |
7 | 2366 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
|
2367 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2368 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
|
2369 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
|
2370 current_sub_char = sip->si_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2371 #endif |
7 | 2372 break; |
2373 } | |
2374 } | |
2375 | |
221 | 2376 if (can_spell != NULL) |
2377 { | |
2378 struct sp_syn sps; | |
2379 | |
2380 /* | |
2381 * set "can_spell" to TRUE if spell checking is supposed to be | |
2382 * done in the current item. | |
2383 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2384 if (syn_block->b_spell_cluster_id == 0) |
227 | 2385 { |
320 | 2386 /* There is no @Spell cluster: Do spelling for items without |
2387 * @NoSpell cluster. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2388 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
|
2389 || current_trans_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2390 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); |
227 | 2391 else |
2392 { | |
2393 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2394 sps.id = syn_block->b_nospell_cluster_id; |
227 | 2395 sps.cont_in_list = NULL; |
2396 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2397 } | |
2398 } | |
221 | 2399 else |
2400 { | |
320 | 2401 /* The @Spell cluster is defined: Do spelling in items with |
419 | 2402 * the @Spell cluster. But not when @NoSpell is also there. |
2403 * At the toplevel only spell check when ":syn spell toplevel" | |
2404 * was used. */ | |
320 | 2405 if (current_trans_id == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2406 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); |
320 | 2407 else |
2408 { | |
2409 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2410 sps.id = syn_block->b_spell_cluster_id; |
320 | 2411 sps.cont_in_list = NULL; |
2412 *can_spell = in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2413 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2414 if (syn_block->b_nospell_cluster_id != 0) |
320 | 2415 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2416 sps.id = syn_block->b_nospell_cluster_id; |
320 | 2417 if (in_id_list(sip, sip->si_cont_list, &sps, 0)) |
2418 *can_spell = FALSE; | |
2419 } | |
2420 } | |
221 | 2421 } |
2422 } | |
2423 | |
2424 | |
7 | 2425 /* |
2426 * Check for end of current state (and the states before it) at the | |
2427 * next column. Don't do this for syncing, because we would miss a | |
2428 * single character match. | |
2429 * First check if the current state ends at the current column. It | |
2430 * may be for an empty match and a containing item might end in the | |
2431 * current column. | |
2432 */ | |
1504 | 2433 if (!syncing && !keep_state) |
7 | 2434 { |
2435 check_state_ends(); | |
442 | 2436 if (current_state.ga_len > 0 |
2437 && syn_getcurline()[current_col] != NUL) | |
7 | 2438 { |
2439 ++current_col; | |
2440 check_state_ends(); | |
2441 --current_col; | |
2442 } | |
2443 } | |
2444 } | |
221 | 2445 else if (can_spell != NULL) |
419 | 2446 /* Default: Only do spelling when there is no @Spell cluster or when |
2447 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2448 *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
|
2449 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2450 : (syn_block->b_syn_spell == SYNSPL_TOP); |
7 | 2451 |
2020 | 2452 /* nextgroup ends at end of line, unless "skipnl" or "skipempty" present */ |
7 | 2453 if (current_next_list != NULL |
2454 && syn_getcurline()[current_col + 1] == NUL | |
2455 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) | |
2456 current_next_list = NULL; | |
2457 | |
2458 if (zero_width_next_ga.ga_len > 0) | |
2459 ga_clear(&zero_width_next_ga); | |
2460 | |
2461 /* No longer need external matches. But keep next_match_extmatch. */ | |
2462 unref_extmatch(re_extmatch_out); | |
2463 re_extmatch_out = NULL; | |
2464 unref_extmatch(cur_extmatch); | |
2465 | |
2466 return current_attr; | |
2467 } | |
2468 | |
2469 | |
2470 /* | |
2471 * Check if we already matched pattern "idx" at the current column. | |
2472 */ | |
2473 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2474 did_match_already(int idx, garray_T *gap) |
7 | 2475 { |
2476 int i; | |
2477 | |
2478 for (i = current_state.ga_len; --i >= 0; ) | |
2479 if (CUR_STATE(i).si_m_startcol == (int)current_col | |
2480 && CUR_STATE(i).si_m_lnum == (int)current_lnum | |
2481 && CUR_STATE(i).si_idx == idx) | |
2482 return TRUE; | |
2483 | |
2484 /* Zero-width matches with a nextgroup argument are not put on the syntax | |
2485 * stack, and can only be matched once anyway. */ | |
2486 for (i = gap->ga_len; --i >= 0; ) | |
2487 if (((int *)(gap->ga_data))[i] == idx) | |
2488 return TRUE; | |
2489 | |
2490 return FALSE; | |
2491 } | |
2492 | |
2493 /* | |
2494 * Push the next match onto the stack. | |
2495 */ | |
2496 static stateitem_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2497 push_next_match(stateitem_T *cur_si) |
7 | 2498 { |
2499 synpat_T *spp; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2500 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2501 int save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2502 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2503 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2504 spp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2505 |
2506 /* | |
2507 * Push the item in current_state stack; | |
2508 */ | |
2509 if (push_current_state(next_match_idx) == OK) | |
2510 { | |
2511 /* | |
2512 * If it's a start-skip-end type that crosses lines, figure out how | |
2513 * much it continues in this line. Otherwise just fill in the length. | |
2514 */ | |
2515 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2516 cur_si->si_h_startpos = next_match_h_startpos; | |
2517 cur_si->si_m_startcol = current_col; | |
2518 cur_si->si_m_lnum = current_lnum; | |
2519 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
|
2520 #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
|
2521 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
|
2522 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
|
2523 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2524 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2525 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
|
2526 #endif |
7 | 2527 cur_si->si_next_list = spp->sp_next_list; |
2528 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); | |
2529 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) | |
2530 { | |
2531 /* Try to find the end pattern in the current line */ | |
2532 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); | |
2533 check_keepend(); | |
2534 } | |
2535 else | |
2536 { | |
2537 cur_si->si_m_endpos = next_match_m_endpos; | |
2538 cur_si->si_h_endpos = next_match_h_endpos; | |
2539 cur_si->si_ends = TRUE; | |
2540 cur_si->si_flags |= next_match_flags; | |
2541 cur_si->si_eoe_pos = next_match_eoe_pos; | |
2542 cur_si->si_end_idx = next_match_end_idx; | |
2543 } | |
2544 if (keepend_level < 0 && (cur_si->si_flags & HL_KEEPEND)) | |
2545 keepend_level = current_state.ga_len - 1; | |
2546 check_keepend(); | |
2547 update_si_attr(current_state.ga_len - 1); | |
2548 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2549 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2550 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
|
2551 #endif |
7 | 2552 /* |
2553 * If the start pattern has another highlight group, push another item | |
2554 * on the stack for the start pattern. | |
2555 */ | |
2556 if ( spp->sp_type == SPTYPE_START | |
2557 && spp->sp_syn_match_id != 0 | |
2558 && push_current_state(next_match_idx) == OK) | |
2559 { | |
2560 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2561 cur_si->si_h_startpos = next_match_h_startpos; | |
2562 cur_si->si_m_startcol = current_col; | |
2563 cur_si->si_m_lnum = current_lnum; | |
2564 cur_si->si_m_endpos = next_match_eos_pos; | |
2565 cur_si->si_h_endpos = next_match_eos_pos; | |
2566 cur_si->si_ends = TRUE; | |
2567 cur_si->si_end_idx = 0; | |
2568 cur_si->si_flags = HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2569 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2570 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2571 cur_si->si_flags |= save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2572 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2573 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2574 #endif |
7 | 2575 cur_si->si_next_list = NULL; |
2576 check_keepend(); | |
2577 update_si_attr(current_state.ga_len - 1); | |
2578 } | |
2579 } | |
2580 | |
2581 next_match_idx = -1; /* try other match next time */ | |
2582 | |
2583 return cur_si; | |
2584 } | |
2585 | |
2586 /* | |
2587 * Check for end of current state (and the states before it). | |
2588 */ | |
2589 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2590 check_state_ends(void) |
7 | 2591 { |
2592 stateitem_T *cur_si; | |
2863 | 2593 int had_extend; |
7 | 2594 |
2595 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2596 for (;;) | |
2597 { | |
2598 if (cur_si->si_ends | |
2599 && (cur_si->si_m_endpos.lnum < current_lnum | |
2600 || (cur_si->si_m_endpos.lnum == current_lnum | |
2601 && cur_si->si_m_endpos.col <= current_col))) | |
2602 { | |
2603 /* | |
2604 * If there is an end pattern group ID, highlight the end pattern | |
2605 * now. No need to pop the current item from the stack. | |
2606 * Only do this if the end pattern continues beyond the current | |
2607 * position. | |
2608 */ | |
2609 if (cur_si->si_end_idx | |
2610 && (cur_si->si_eoe_pos.lnum > current_lnum | |
2611 || (cur_si->si_eoe_pos.lnum == current_lnum | |
2612 && cur_si->si_eoe_pos.col > current_col))) | |
2613 { | |
2614 cur_si->si_idx = cur_si->si_end_idx; | |
2615 cur_si->si_end_idx = 0; | |
2616 cur_si->si_m_endpos = cur_si->si_eoe_pos; | |
2617 cur_si->si_h_endpos = cur_si->si_eoe_pos; | |
2618 cur_si->si_flags |= HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2619 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2620 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2621 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2622 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2623 #endif |
7 | 2624 update_si_attr(current_state.ga_len - 1); |
36 | 2625 |
2831 | 2626 /* nextgroup= should not match in the end pattern */ |
2627 current_next_list = NULL; | |
2628 | |
36 | 2629 /* what matches next may be different now, clear it */ |
2630 next_match_idx = 0; | |
2631 next_match_col = MAXCOL; | |
7 | 2632 break; |
2633 } | |
2634 else | |
2635 { | |
2636 /* handle next_list, unless at end of line and no "skipnl" or | |
2637 * "skipempty" */ | |
2638 current_next_list = cur_si->si_next_list; | |
2639 current_next_flags = cur_si->si_flags; | |
2640 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) | |
2641 && syn_getcurline()[current_col] == NUL) | |
2642 current_next_list = NULL; | |
2643 | |
2644 /* When the ended item has "extend", another item with | |
2645 * "keepend" now needs to check for its end. */ | |
2863 | 2646 had_extend = (cur_si->si_flags & HL_EXTEND); |
7 | 2647 |
2648 pop_current_state(); | |
2649 | |
2650 if (current_state.ga_len == 0) | |
2651 break; | |
2652 | |
1503 | 2653 if (had_extend && keepend_level >= 0) |
7 | 2654 { |
2655 syn_update_ends(FALSE); | |
2656 if (current_state.ga_len == 0) | |
2657 break; | |
2658 } | |
2659 | |
2660 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2661 | |
2662 /* | |
2663 * Only for a region the search for the end continues after | |
2664 * the end of the contained item. If the contained match | |
2665 * included the end-of-line, break here, the region continues. | |
2666 * Don't do this when: | |
2667 * - "keepend" is used for the contained item | |
2668 * - not at the end of the line (could be end="x$"me=e-1). | |
2669 * - "excludenl" is used (HL_HAS_EOL won't be set) | |
2670 */ | |
2671 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2672 && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type |
7 | 2673 == SPTYPE_START |
2674 && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) | |
2675 { | |
2676 update_si_end(cur_si, (int)current_col, TRUE); | |
2677 check_keepend(); | |
2678 if ((current_next_flags & HL_HAS_EOL) | |
2679 && keepend_level < 0 | |
2680 && syn_getcurline()[current_col] == NUL) | |
2681 break; | |
2682 } | |
2683 } | |
2684 } | |
2685 else | |
2686 break; | |
2687 } | |
2688 } | |
2689 | |
2690 /* | |
2691 * Update an entry in the current_state stack for a match or region. This | |
2692 * fills in si_attr, si_next_list and si_cont_list. | |
2693 */ | |
2694 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2695 update_si_attr(int idx) |
7 | 2696 { |
2697 stateitem_T *sip = &CUR_STATE(idx); | |
2698 synpat_T *spp; | |
2699 | |
1371 | 2700 /* This should not happen... */ |
2701 if (sip->si_idx < 0) | |
2702 return; | |
2703 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2704 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); |
7 | 2705 if (sip->si_flags & HL_MATCH) |
2706 sip->si_id = spp->sp_syn_match_id; | |
2707 else | |
2708 sip->si_id = spp->sp_syn.id; | |
2709 sip->si_attr = syn_id2attr(sip->si_id); | |
2710 sip->si_trans_id = sip->si_id; | |
2711 if (sip->si_flags & HL_MATCH) | |
2712 sip->si_cont_list = NULL; | |
2713 else | |
2714 sip->si_cont_list = spp->sp_cont_list; | |
2715 | |
2716 /* | |
2717 * For transparent items, take attr from outer item. | |
2718 * Also take cont_list, if there is none. | |
2719 * Don't do this for the matchgroup of a start or end pattern. | |
2720 */ | |
2721 if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) | |
2722 { | |
2723 if (idx == 0) | |
2724 { | |
2725 sip->si_attr = 0; | |
2726 sip->si_trans_id = 0; | |
2727 if (sip->si_cont_list == NULL) | |
2728 sip->si_cont_list = ID_LIST_ALL; | |
2729 } | |
2730 else | |
2731 { | |
2732 sip->si_attr = CUR_STATE(idx - 1).si_attr; | |
2733 sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; | |
36 | 2734 sip->si_h_startpos = CUR_STATE(idx - 1).si_h_startpos; |
2735 sip->si_h_endpos = CUR_STATE(idx - 1).si_h_endpos; | |
7 | 2736 if (sip->si_cont_list == NULL) |
2737 { | |
2738 sip->si_flags |= HL_TRANS_CONT; | |
2739 sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; | |
2740 } | |
2741 } | |
2742 } | |
2743 } | |
2744 | |
2745 /* | |
2746 * Check the current stack for patterns with "keepend" flag. | |
2747 * Propagate the match-end to contained items, until a "skipend" item is found. | |
2748 */ | |
2749 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2750 check_keepend(void) |
7 | 2751 { |
2752 int i; | |
2753 lpos_T maxpos; | |
991 | 2754 lpos_T maxpos_h; |
7 | 2755 stateitem_T *sip; |
2756 | |
2757 /* | |
2758 * This check can consume a lot of time; only do it from the level where | |
2759 * there really is a keepend. | |
2760 */ | |
2761 if (keepend_level < 0) | |
2762 return; | |
2763 | |
2764 /* | |
2765 * Find the last index of an "extend" item. "keepend" items before that | |
2766 * won't do anything. If there is no "extend" item "i" will be | |
2767 * "keepend_level" and all "keepend" items will work normally. | |
2768 */ | |
2769 for (i = current_state.ga_len - 1; i > keepend_level; --i) | |
2770 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
2771 break; | |
2772 | |
2773 maxpos.lnum = 0; | |
1702 | 2774 maxpos.col = 0; |
991 | 2775 maxpos_h.lnum = 0; |
1702 | 2776 maxpos_h.col = 0; |
7 | 2777 for ( ; i < current_state.ga_len; ++i) |
2778 { | |
2779 sip = &CUR_STATE(i); | |
2780 if (maxpos.lnum != 0) | |
2781 { | |
2782 limit_pos_zero(&sip->si_m_endpos, &maxpos); | |
991 | 2783 limit_pos_zero(&sip->si_h_endpos, &maxpos_h); |
7 | 2784 limit_pos_zero(&sip->si_eoe_pos, &maxpos); |
2785 sip->si_ends = TRUE; | |
2786 } | |
991 | 2787 if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) |
2788 { | |
2789 if (maxpos.lnum == 0 | |
7 | 2790 || maxpos.lnum > sip->si_m_endpos.lnum |
2791 || (maxpos.lnum == sip->si_m_endpos.lnum | |
991 | 2792 && maxpos.col > sip->si_m_endpos.col)) |
2793 maxpos = sip->si_m_endpos; | |
2794 if (maxpos_h.lnum == 0 | |
2795 || maxpos_h.lnum > sip->si_h_endpos.lnum | |
2796 || (maxpos_h.lnum == sip->si_h_endpos.lnum | |
2797 && maxpos_h.col > sip->si_h_endpos.col)) | |
2798 maxpos_h = sip->si_h_endpos; | |
2799 } | |
7 | 2800 } |
2801 } | |
2802 | |
2803 /* | |
2804 * Update an entry in the current_state stack for a start-skip-end pattern. | |
2805 * This finds the end of the current item, if it's in the current line. | |
2806 * | |
2807 * Return the flags for the matched END. | |
2808 */ | |
2809 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2810 update_si_end( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2811 stateitem_T *sip, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2812 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
|
2813 int force) /* when TRUE overrule a previous end */ |
7 | 2814 { |
2815 lpos_T startpos; | |
2816 lpos_T endpos; | |
2817 lpos_T hl_endpos; | |
2818 lpos_T end_endpos; | |
2819 int end_idx; | |
2820 | |
1371 | 2821 /* return quickly for a keyword */ |
2822 if (sip->si_idx < 0) | |
2823 return; | |
2824 | |
7 | 2825 /* Don't update when it's already done. Can be a match of an end pattern |
2826 * that started in a previous line. Watch out: can also be a "keepend" | |
2827 * from a containing item. */ | |
2828 if (!force && sip->si_m_endpos.lnum >= current_lnum) | |
2829 return; | |
2830 | |
2831 /* | |
2832 * We need to find the end of the region. It may continue in the next | |
2833 * line. | |
2834 */ | |
2835 end_idx = 0; | |
2836 startpos.lnum = current_lnum; | |
2837 startpos.col = startcol; | |
2838 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, | |
2839 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); | |
2840 | |
2841 if (endpos.lnum == 0) | |
2842 { | |
2843 /* No end pattern matched. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2844 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) |
7 | 2845 { |
2846 /* a "oneline" never continues in the next line */ | |
2847 sip->si_ends = TRUE; | |
2848 sip->si_m_endpos.lnum = current_lnum; | |
2849 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); | |
2850 } | |
2851 else | |
2852 { | |
2853 /* continues in the next line */ | |
2854 sip->si_ends = FALSE; | |
2855 sip->si_m_endpos.lnum = 0; | |
2856 } | |
2857 sip->si_h_endpos = sip->si_m_endpos; | |
2858 } | |
2859 else | |
2860 { | |
2861 /* match within this line */ | |
2862 sip->si_m_endpos = endpos; | |
2863 sip->si_h_endpos = hl_endpos; | |
2864 sip->si_eoe_pos = end_endpos; | |
2865 sip->si_ends = TRUE; | |
2866 sip->si_end_idx = end_idx; | |
2867 } | |
2868 } | |
2869 | |
2870 /* | |
2871 * Add a new state to the current state stack. | |
2872 * It is cleared and the index set to "idx". | |
2873 * Return FAIL if it's not possible (out of memory). | |
2874 */ | |
2875 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2876 push_current_state(int idx) |
7 | 2877 { |
2878 if (ga_grow(¤t_state, 1) == FAIL) | |
2879 return FAIL; | |
2880 vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T)); | |
2881 CUR_STATE(current_state.ga_len).si_idx = idx; | |
2882 ++current_state.ga_len; | |
2883 return OK; | |
2884 } | |
2885 | |
2886 /* | |
2887 * Remove a state from the current_state stack. | |
2888 */ | |
2889 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2890 pop_current_state(void) |
7 | 2891 { |
2892 if (current_state.ga_len) | |
2893 { | |
2894 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); | |
2895 --current_state.ga_len; | |
2896 } | |
2897 /* after the end of a pattern, try matching a keyword or pattern */ | |
2898 next_match_idx = -1; | |
2899 | |
2900 /* if first state with "keepend" is popped, reset keepend_level */ | |
2901 if (keepend_level >= current_state.ga_len) | |
2902 keepend_level = -1; | |
2903 } | |
2904 | |
2905 /* | |
2906 * Find the end of a start/skip/end syntax region after "startpos". | |
2907 * Only checks one line. | |
2908 * Also handles a match item that continued from a previous line. | |
2909 * If not found, the syntax item continues in the next line. m_endpos->lnum | |
2910 * will be 0. | |
2911 * If found, the end of the region and the end of the highlighting is | |
2912 * computed. | |
2913 */ | |
2914 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2915 find_endpos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2916 int idx, /* index of the pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2917 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
|
2918 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
|
2919 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
|
2920 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
|
2921 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
|
2922 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
|
2923 reg_extmatch_T *start_ext) /* submatches from the start pattern */ |
7 | 2924 { |
2925 colnr_T matchcol; | |
2926 synpat_T *spp, *spp_skip; | |
2927 int start_idx; | |
2928 int best_idx; | |
2929 regmmatch_T regmatch; | |
2930 regmmatch_T best_regmatch; /* startpos/endpos of best match */ | |
2931 lpos_T pos; | |
2932 char_u *line; | |
2933 int had_match = FALSE; | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2934 char_u buf_chartab[32]; /* chartab array for syn option iskyeyword */ |
7 | 2935 |
1371 | 2936 /* just in case we are invoked for a keyword */ |
2937 if (idx < 0) | |
2938 return; | |
2939 | |
7 | 2940 /* |
2941 * Check for being called with a START pattern. | |
2942 * Can happen with a match that continues to the next line, because it | |
2943 * contained a region. | |
2944 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2945 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2946 if (spp->sp_type != SPTYPE_START) |
2947 { | |
2948 *hl_endpos = *startpos; | |
2949 return; | |
2950 } | |
2951 | |
2952 /* | |
2953 * Find the SKIP or first END pattern after the last START pattern. | |
2954 */ | |
2955 for (;;) | |
2956 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2957 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2958 if (spp->sp_type != SPTYPE_START) |
2959 break; | |
2960 ++idx; | |
2961 } | |
2962 | |
2963 /* | |
2964 * Lookup the SKIP pattern (if present) | |
2965 */ | |
2966 if (spp->sp_type == SPTYPE_SKIP) | |
2967 { | |
2968 spp_skip = spp; | |
2969 ++idx; | |
2970 } | |
2971 else | |
2972 spp_skip = NULL; | |
2973 | |
2974 /* Setup external matches for syn_regexec(). */ | |
2975 unref_extmatch(re_extmatch_in); | |
2976 re_extmatch_in = ref_extmatch(start_ext); | |
2977 | |
2978 matchcol = startpos->col; /* start looking for a match at sstart */ | |
2979 start_idx = idx; /* remember the first END pattern. */ | |
2980 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
|
2981 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2982 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2983 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2984 |
7 | 2985 for (;;) |
2986 { | |
2987 /* | |
2988 * Find end pattern that matches first after "matchcol". | |
2989 */ | |
2990 best_idx = -1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2991 for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; ++idx) |
7 | 2992 { |
2993 int lc_col = matchcol; | |
6375 | 2994 int r; |
7 | 2995 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2996 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2997 if (spp->sp_type != SPTYPE_END) /* past last END pattern */ |
2998 break; | |
2999 lc_col -= spp->sp_offsets[SPO_LC_OFF]; | |
3000 if (lc_col < 0) | |
3001 lc_col = 0; | |
3002 | |
3003 regmatch.rmm_ic = spp->sp_ic; | |
3004 regmatch.regprog = spp->sp_prog; | |
6375 | 3005 r = syn_regexec(®match, startpos->lnum, lc_col, |
3006 IF_SYN_TIME(&spp->sp_time)); | |
3007 spp->sp_prog = regmatch.regprog; | |
3008 if (r) | |
7 | 3009 { |
3010 if (best_idx == -1 || regmatch.startpos[0].col | |
3011 < best_regmatch.startpos[0].col) | |
3012 { | |
3013 best_idx = idx; | |
3014 best_regmatch.startpos[0] = regmatch.startpos[0]; | |
3015 best_regmatch.endpos[0] = regmatch.endpos[0]; | |
3016 } | |
3017 } | |
3018 } | |
3019 | |
3020 /* | |
3021 * If all end patterns have been tried, and there is no match, the | |
3022 * item continues until end-of-line. | |
3023 */ | |
3024 if (best_idx == -1) | |
3025 break; | |
3026 | |
3027 /* | |
3028 * If the skip pattern matches before the end pattern, | |
3029 * continue searching after the skip pattern. | |
3030 */ | |
3031 if (spp_skip != NULL) | |
3032 { | |
3033 int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; | |
6375 | 3034 int r; |
7 | 3035 |
3036 if (lc_col < 0) | |
3037 lc_col = 0; | |
3038 regmatch.rmm_ic = spp_skip->sp_ic; | |
3039 regmatch.regprog = spp_skip->sp_prog; | |
6375 | 3040 r = syn_regexec(®match, startpos->lnum, lc_col, |
3041 IF_SYN_TIME(&spp_skip->sp_time)); | |
3042 spp_skip->sp_prog = regmatch.regprog; | |
3043 if (r && regmatch.startpos[0].col | |
7 | 3044 <= best_regmatch.startpos[0].col) |
3045 { | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3046 int line_len; |
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3047 |
7 | 3048 /* Add offset to skip pattern match */ |
3049 syn_add_end_off(&pos, ®match, spp_skip, SPO_ME_OFF, 1); | |
3050 | |
3051 /* If the skip pattern goes on to the next line, there is no | |
3052 * match with an end pattern in this line. */ | |
3053 if (pos.lnum > startpos->lnum) | |
3054 break; | |
3055 | |
3056 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
|
3057 line_len = (int)STRLEN(line); |
7 | 3058 |
3059 /* take care of an empty match or negative offset */ | |
3060 if (pos.col <= matchcol) | |
3061 ++matchcol; | |
3062 else if (pos.col <= regmatch.endpos[0].col) | |
3063 matchcol = pos.col; | |
3064 else | |
3065 /* Be careful not to jump over the NUL at the end-of-line */ | |
3066 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
|
3067 matchcol < line_len && matchcol < pos.col; |
7 | 3068 ++matchcol) |
3069 ; | |
3070 | |
3071 /* 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
|
3072 if (matchcol >= line_len) |
7 | 3073 break; |
3074 | |
3075 continue; /* start with first end pattern again */ | |
3076 } | |
3077 } | |
3078 | |
3079 /* | |
3080 * Match from start pattern to end pattern. | |
3081 * Correct for match and highlight offset of end pattern. | |
3082 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3083 spp = &(SYN_ITEMS(syn_block)[best_idx]); |
7 | 3084 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); |
3085 /* can't end before the start */ | |
3086 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) | |
3087 m_endpos->col = startpos->col; | |
3088 | |
3089 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); | |
3090 /* can't end before the start */ | |
3091 if (end_endpos->lnum == startpos->lnum | |
3092 && end_endpos->col < startpos->col) | |
3093 end_endpos->col = startpos->col; | |
3094 /* can't end after the match */ | |
3095 limit_pos(end_endpos, m_endpos); | |
3096 | |
3097 /* | |
3098 * If the end group is highlighted differently, adjust the pointers. | |
3099 */ | |
3100 if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) | |
3101 { | |
3102 *end_idx = best_idx; | |
3103 if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) | |
3104 { | |
3105 hl_endpos->lnum = best_regmatch.endpos[0].lnum; | |
3106 hl_endpos->col = best_regmatch.endpos[0].col; | |
3107 } | |
3108 else | |
3109 { | |
3110 hl_endpos->lnum = best_regmatch.startpos[0].lnum; | |
3111 hl_endpos->col = best_regmatch.startpos[0].col; | |
3112 } | |
3113 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; | |
3114 | |
3115 /* can't end before the start */ | |
3116 if (hl_endpos->lnum == startpos->lnum | |
3117 && hl_endpos->col < startpos->col) | |
3118 hl_endpos->col = startpos->col; | |
3119 limit_pos(hl_endpos, m_endpos); | |
3120 | |
3121 /* now the match ends where the highlighting ends, it is turned | |
3122 * into the matchgroup for the end */ | |
3123 *m_endpos = *hl_endpos; | |
3124 } | |
3125 else | |
3126 { | |
3127 *end_idx = 0; | |
3128 *hl_endpos = *end_endpos; | |
3129 } | |
3130 | |
3131 *flagsp = spp->sp_flags; | |
3132 | |
3133 had_match = TRUE; | |
3134 break; | |
3135 } | |
3136 | |
3137 /* no match for an END pattern in this line */ | |
3138 if (!had_match) | |
3139 m_endpos->lnum = 0; | |
3140 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3141 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3142 |
7 | 3143 /* Remove external matches. */ |
3144 unref_extmatch(re_extmatch_in); | |
3145 re_extmatch_in = NULL; | |
3146 } | |
3147 | |
3148 /* | |
3149 * Limit "pos" not to be after "limit". | |
3150 */ | |
3151 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3152 limit_pos(lpos_T *pos, lpos_T *limit) |
7 | 3153 { |
3154 if (pos->lnum > limit->lnum) | |
3155 *pos = *limit; | |
3156 else if (pos->lnum == limit->lnum && pos->col > limit->col) | |
3157 pos->col = limit->col; | |
3158 } | |
3159 | |
3160 /* | |
3161 * Limit "pos" not to be after "limit", unless pos->lnum is zero. | |
3162 */ | |
3163 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3164 limit_pos_zero( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3165 lpos_T *pos, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3166 lpos_T *limit) |
7 | 3167 { |
3168 if (pos->lnum == 0) | |
3169 *pos = *limit; | |
3170 else | |
3171 limit_pos(pos, limit); | |
3172 } | |
3173 | |
3174 /* | |
3175 * Add offset to matched text for end of match or highlight. | |
3176 */ | |
3177 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3178 syn_add_end_off( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3179 lpos_T *result, /* returned position */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3180 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
|
3181 synpat_T *spp, /* matched pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3182 int idx, /* index of offset */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3183 int extra) /* extra chars for offset to start */ |
7 | 3184 { |
3185 int col; | |
1624 | 3186 int off; |
3187 char_u *base; | |
3188 char_u *p; | |
7 | 3189 |
3190 if (spp->sp_off_flags & (1 << idx)) | |
3191 { | |
3192 result->lnum = regmatch->startpos[0].lnum; | |
1624 | 3193 col = regmatch->startpos[0].col; |
3194 off = spp->sp_offsets[idx] + extra; | |
7 | 3195 } |
3196 else | |
3197 { | |
3198 result->lnum = regmatch->endpos[0].lnum; | |
3199 col = regmatch->endpos[0].col; | |
1624 | 3200 off = spp->sp_offsets[idx]; |
3201 } | |
3202 /* Don't go past the end of the line. Matters for "rs=e+2" when there | |
3203 * is a matchgroup. Watch out for match with last NL in the buffer. */ | |
3204 if (result->lnum > syn_buf->b_ml.ml_line_count) | |
3205 col = 0; | |
3206 else if (off != 0) | |
3207 { | |
3208 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3209 p = base + col; | |
3210 if (off > 0) | |
3211 { | |
3212 while (off-- > 0 && *p != NUL) | |
3213 mb_ptr_adv(p); | |
3214 } | |
3215 else if (off < 0) | |
3216 { | |
3217 while (off++ < 0 && base < p) | |
3218 mb_ptr_back(base, p); | |
3219 } | |
3220 col = (int)(p - base); | |
3221 } | |
3222 result->col = col; | |
7 | 3223 } |
3224 | |
3225 /* | |
3226 * Add offset to matched text for start of match or highlight. | |
3227 * Avoid resulting column to become negative. | |
3228 */ | |
3229 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3230 syn_add_start_off( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3231 lpos_T *result, /* returned position */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3232 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
|
3233 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3234 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3235 int extra) /* extra chars for offset to end */ |
7 | 3236 { |
3237 int col; | |
1624 | 3238 int off; |
3239 char_u *base; | |
3240 char_u *p; | |
7 | 3241 |
3242 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) | |
3243 { | |
3244 result->lnum = regmatch->endpos[0].lnum; | |
1624 | 3245 col = regmatch->endpos[0].col; |
3246 off = spp->sp_offsets[idx] + extra; | |
7 | 3247 } |
3248 else | |
3249 { | |
3250 result->lnum = regmatch->startpos[0].lnum; | |
3251 col = regmatch->startpos[0].col; | |
1624 | 3252 off = spp->sp_offsets[idx]; |
3253 } | |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3254 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
|
3255 { |
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3256 /* 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
|
3257 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
|
3258 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
|
3259 } |
1624 | 3260 if (off != 0) |
3261 { | |
3262 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3263 p = base + col; | |
3264 if (off > 0) | |
3265 { | |
3266 while (off-- && *p != NUL) | |
3267 mb_ptr_adv(p); | |
3268 } | |
3269 else if (off < 0) | |
3270 { | |
3271 while (off++ && base < p) | |
3272 mb_ptr_back(base, p); | |
3273 } | |
3274 col = (int)(p - base); | |
3275 } | |
3276 result->col = col; | |
7 | 3277 } |
3278 | |
3279 /* | |
3280 * Get current line in syntax buffer. | |
3281 */ | |
3282 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3283 syn_getcurline(void) |
7 | 3284 { |
3285 return ml_get_buf(syn_buf, current_lnum, FALSE); | |
3286 } | |
3287 | |
3288 /* | |
410 | 3289 * Call vim_regexec() to find a match with "rmp" in "syn_buf". |
7 | 3290 * Returns TRUE when there is a match. |
3291 */ | |
3292 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3293 syn_regexec( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3294 regmmatch_T *rmp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3295 linenr_T lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3296 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3297 syn_time_T *st UNUSED) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3298 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3299 int r; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3300 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3301 proftime_T pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3302 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3303 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3304 profile_start(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3305 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3306 |
410 | 3307 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
|
3308 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
|
3309 |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3310 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3311 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3312 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3313 profile_end(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3314 profile_add(&st->total, &pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3315 if (profile_cmp(&pt, &st->slowest) < 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3316 st->slowest = pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3317 ++st->count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3318 if (r > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3319 ++st->match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3320 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3321 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3322 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3323 if (r > 0) |
7 | 3324 { |
3325 rmp->startpos[0].lnum += lnum; | |
3326 rmp->endpos[0].lnum += lnum; | |
3327 return TRUE; | |
3328 } | |
3329 return FALSE; | |
3330 } | |
3331 | |
3332 /* | |
3333 * Check one position in a line for a matching keyword. | |
3334 * The caller must check if a keyword can start at startcol. | |
3335 * Return it's ID if found, 0 otherwise. | |
3336 */ | |
3337 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3338 check_keyword_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3339 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3340 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
|
3341 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
|
3342 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
|
3343 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
|
3344 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
|
3345 int *ccharp UNUSED) /* conceal substitution char */ |
7 | 3346 { |
134 | 3347 keyentry_T *kp; |
3348 char_u *kwp; | |
7 | 3349 int round; |
134 | 3350 int kwlen; |
7 | 3351 char_u keyword[MAXKEYWLEN + 1]; /* assume max. keyword len is 80 */ |
134 | 3352 hashtab_T *ht; |
3353 hashitem_T *hi; | |
7 | 3354 |
3355 /* Find first character after the keyword. First character was already | |
3356 * checked. */ | |
134 | 3357 kwp = line + startcol; |
3358 kwlen = 0; | |
7 | 3359 do |
3360 { | |
3361 #ifdef FEAT_MBYTE | |
3362 if (has_mbyte) | |
474 | 3363 kwlen += (*mb_ptr2len)(kwp + kwlen); |
7 | 3364 else |
3365 #endif | |
134 | 3366 ++kwlen; |
3367 } | |
4043 | 3368 while (vim_iswordp_buf(kwp + kwlen, syn_buf)); |
134 | 3369 |
3370 if (kwlen > MAXKEYWLEN) | |
7 | 3371 return 0; |
3372 | |
3373 /* | |
3374 * Must make a copy of the keyword, so we can add a NUL and make it | |
3375 * lowercase. | |
3376 */ | |
419 | 3377 vim_strncpy(keyword, kwp, kwlen); |
7 | 3378 |
3379 /* | |
3380 * Try twice: | |
3381 * 1. matching case | |
3382 * 2. ignoring case | |
3383 */ | |
3384 for (round = 1; round <= 2; ++round) | |
3385 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3386 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; |
134 | 3387 if (ht->ht_used == 0) |
7 | 3388 continue; |
134 | 3389 if (round == 2) /* ignore case */ |
3390 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); | |
7 | 3391 |
3392 /* | |
134 | 3393 * Find keywords that match. There can be several with different |
3394 * attributes. | |
7 | 3395 * When current_next_list is non-zero accept only that group, otherwise: |
3396 * Accept a not-contained keyword at toplevel. | |
3397 * Accept a keyword at other levels only if it is in the contains list. | |
3398 */ | |
134 | 3399 hi = hash_find(ht, keyword); |
3400 if (!HASHITEM_EMPTY(hi)) | |
3401 for (kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) | |
7 | 3402 { |
134 | 3403 if (current_next_list != 0 |
3404 ? in_id_list(NULL, current_next_list, &kp->k_syn, 0) | |
3405 : (cur_si == NULL | |
3406 ? !(kp->flags & HL_CONTAINED) | |
3407 : in_id_list(cur_si, cur_si->si_cont_list, | |
3408 &kp->k_syn, kp->flags & HL_CONTAINED))) | |
3409 { | |
3410 *endcolp = startcol + kwlen; | |
3411 *flagsp = kp->flags; | |
3412 *next_listp = kp->next_list; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3413 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3414 *ccharp = kp->k_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3415 #endif |
134 | 3416 return kp->k_syn.id; |
3417 } | |
7 | 3418 } |
3419 } | |
3420 return 0; | |
3421 } | |
3422 | |
3423 /* | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3424 * Handle ":syntax conceal" command. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3425 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3426 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3427 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
|
3428 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3429 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3430 char_u *arg = eap->arg; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3431 char_u *next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3432 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3433 eap->nextcmd = find_nextcmd(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3434 if (eap->skip) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3435 return; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3436 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3437 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
|
3438 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
|
3439 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3440 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
|
3441 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
|
3442 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3443 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
|
3444 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3445 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
|
3446 curwin->w_s->b_syn_conceal = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3447 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
|
3448 curwin->w_s->b_syn_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3449 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3450 EMSG2(_("E390: Illegal argument: %s"), arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3451 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3452 } |
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 /* |
7 | 3455 * Handle ":syntax case" command. |
3456 */ | |
3457 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3458 syn_cmd_case(exarg_T *eap, int syncing UNUSED) |
7 | 3459 { |
3460 char_u *arg = eap->arg; | |
3461 char_u *next; | |
3462 | |
3463 eap->nextcmd = find_nextcmd(arg); | |
3464 if (eap->skip) | |
3465 return; | |
3466 | |
3467 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
|
3468 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
|
3469 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3470 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
|
3471 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
|
3472 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3473 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
|
3474 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3475 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
|
3476 curwin->w_s->b_syn_ic = FALSE; |
7 | 3477 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
|
3478 curwin->w_s->b_syn_ic = TRUE; |
7 | 3479 else |
3480 EMSG2(_("E390: Illegal argument: %s"), arg); | |
3481 } | |
3482 | |
3483 /* | |
419 | 3484 * Handle ":syntax spell" command. |
3485 */ | |
3486 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3487 syn_cmd_spell(exarg_T *eap, int syncing UNUSED) |
419 | 3488 { |
3489 char_u *arg = eap->arg; | |
3490 char_u *next; | |
3491 | |
3492 eap->nextcmd = find_nextcmd(arg); | |
3493 if (eap->skip) | |
3494 return; | |
3495 | |
3496 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
|
3497 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
|
3498 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3499 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
|
3500 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
|
3501 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
|
3502 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
|
3503 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3504 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
|
3505 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3506 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
|
3507 curwin->w_s->b_syn_spell = SYNSPL_TOP; |
419 | 3508 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
|
3509 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; |
1064 | 3510 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
|
3511 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; |
419 | 3512 else |
6880 | 3513 { |
419 | 3514 EMSG2(_("E390: Illegal argument: %s"), arg); |
6880 | 3515 return; |
3516 } | |
3517 | |
3518 /* assume spell checking changed, force a redraw */ | |
3519 redraw_win_later(curwin, NOT_VALID); | |
419 | 3520 } |
3521 | |
3522 /* | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3523 * Handle ":syntax iskeyword" command. |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3524 */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3525 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3526 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
|
3527 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3528 char_u *arg = eap->arg; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3529 char_u save_chartab[32]; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3530 char_u *save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3531 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3532 if (eap->skip) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3533 return; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3534 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3535 arg = skipwhite(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3536 if (*arg == NUL) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3537 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3538 MSG_PUTS("\n"); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3539 MSG_PUTS(_("syntax iskeyword ")); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3540 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
|
3541 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
|
3542 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3543 msg_outtrans((char_u *)"not set"); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3544 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3545 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3546 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3547 if (STRNICMP(arg, "clear", 5) == 0) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3548 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3549 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
|
3550 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3551 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
|
3552 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3553 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3554 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3555 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
|
3556 save_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3557 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
|
3558 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3559 buf_init_chartab(curbuf, FALSE); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3560 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
|
3561 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3562 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
|
3563 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
|
3564 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
|
3565 curbuf->b_p_isk = save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3566 } |
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 redraw_win_later(curwin, NOT_VALID); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3569 } |
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 /* |
7 | 3572 * Clear all syntax info for one buffer. |
3573 */ | |
3574 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3575 syntax_clear(synblock_T *block) |
7 | 3576 { |
3577 int i; | |
3578 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3579 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
|
3580 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
|
3581 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
|
3582 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
|
3583 #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
|
3584 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
|
3585 #endif |
7 | 3586 |
3587 /* free the keywords */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3588 clear_keywtab(&block->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3589 clear_keywtab(&block->b_keywtab_ic); |
7 | 3590 |
3591 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3592 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
|
3593 syn_clear_pattern(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3594 ga_clear(&block->b_syn_patterns); |
7 | 3595 |
3596 /* free the syntax clusters */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3597 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
|
3598 syn_clear_cluster(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3599 ga_clear(&block->b_syn_clusters); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3600 block->b_spell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3601 block->b_nospell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3602 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3603 block->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3604 block->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3605 block->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3606 block->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3607 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3608 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
|
3609 block->b_syn_linecont_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3610 vim_free(block->b_syn_linecont_pat); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3611 block->b_syn_linecont_pat = NULL; |
7 | 3612 #ifdef FEAT_FOLDING |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3613 block->b_syn_folditems = 0; |
7 | 3614 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3615 clear_string_option(&block->b_syn_isk); |
7 | 3616 |
3617 /* free the stored states */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3618 syn_stack_free_all(block); |
7 | 3619 invalidate_current_state(); |
2743 | 3620 |
3621 /* Reset the counter for ":syn include" */ | |
3622 running_syn_inc_tag = 0; | |
7 | 3623 } |
3624 | |
3625 /* | |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3626 * 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
|
3627 */ |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3628 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3629 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
|
3630 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3631 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
|
3632 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3633 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
|
3634 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
|
3635 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
|
3636 } |
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 /* |
7 | 3640 * Clear syncing info for one buffer. |
3641 */ | |
3642 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3643 syntax_sync_clear(void) |
7 | 3644 { |
3645 int i; | |
3646 | |
3647 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3648 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
|
3649 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
|
3650 syn_remove_pattern(curwin->w_s, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3651 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3652 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
|
3653 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
|
3654 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
|
3655 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
|
3656 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3657 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
|
3658 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
|
3659 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
|
3660 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
|
3661 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
|
3662 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3663 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3664 } |
3665 | |
3666 /* | |
3667 * Remove one pattern from the buffer's pattern list. | |
3668 */ | |
3669 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3670 syn_remove_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3671 synblock_T *block, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3672 int idx) |
7 | 3673 { |
3674 synpat_T *spp; | |
3675 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3676 spp = &(SYN_ITEMS(block)[idx]); |
7 | 3677 #ifdef FEAT_FOLDING |
3678 if (spp->sp_flags & HL_FOLD) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3679 --block->b_syn_folditems; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3680 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3681 syn_clear_pattern(block, idx); |
7 | 3682 mch_memmove(spp, spp + 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3683 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
|
3684 --block->b_syn_patterns.ga_len; |
7 | 3685 } |
3686 | |
3687 /* | |
3688 * Clear and free one syntax pattern. When clearing all, must be called from | |
3689 * last to first! | |
3690 */ | |
3691 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3692 syn_clear_pattern(synblock_T *block, int i) |
7 | 3693 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3694 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
|
3695 vim_regfree(SYN_ITEMS(block)[i].sp_prog); |
7 | 3696 /* 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
|
3697 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
|
3698 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3699 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
|
3700 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
|
3701 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); |
7 | 3702 } |
3703 } | |
3704 | |
3705 /* | |
3706 * Clear and free one syntax cluster. | |
3707 */ | |
3708 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3709 syn_clear_cluster(synblock_T *block, int i) |
7 | 3710 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3711 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
|
3712 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
|
3713 vim_free(SYN_CLSTR(block)[i].scl_list); |
7 | 3714 } |
3715 | |
3716 /* | |
3717 * Handle ":syntax clear" command. | |
3718 */ | |
3719 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3720 syn_cmd_clear(exarg_T *eap, int syncing) |
7 | 3721 { |
3722 char_u *arg = eap->arg; | |
3723 char_u *arg_end; | |
3724 int id; | |
3725 | |
3726 eap->nextcmd = find_nextcmd(arg); | |
3727 if (eap->skip) | |
3728 return; | |
3729 | |
3730 /* | |
3731 * We have to disable this within ":syn include @group filename", | |
3732 * because otherwise @group would get deleted. | |
3733 * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn | |
3734 * clear". | |
3735 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3736 if (curwin->w_s->b_syn_topgrp != 0) |
7 | 3737 return; |
3738 | |
3739 if (ends_excmd(*arg)) | |
3740 { | |
3741 /* | |
3742 * No argument: Clear all syntax items. | |
3743 */ | |
3744 if (syncing) | |
3745 syntax_sync_clear(); | |
3746 else | |
3747 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3748 syntax_clear(curwin->w_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3749 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
|
3750 do_unlet((char_u *)"b:current_syntax", TRUE); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
3751 do_unlet((char_u *)"w:current_syntax", TRUE); |
7 | 3752 } |
3753 } | |
3754 else | |
3755 { | |
3756 /* | |
3757 * Clear the group IDs that are in the argument. | |
3758 */ | |
3759 while (!ends_excmd(*arg)) | |
3760 { | |
3761 arg_end = skiptowhite(arg); | |
3762 if (*arg == '@') | |
3763 { | |
3764 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3765 if (id == 0) | |
3766 { | |
3767 EMSG2(_("E391: No such syntax cluster: %s"), arg); | |
3768 break; | |
3769 } | |
3770 else | |
3771 { | |
3772 /* | |
3773 * We can't physically delete a cluster without changing | |
3774 * the IDs of other clusters, so we do the next best thing | |
3775 * and make it empty. | |
3776 */ | |
3777 short scl_id = id - SYNID_CLUSTER; | |
3778 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3779 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
|
3780 SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; |
7 | 3781 } |
3782 } | |
3783 else | |
3784 { | |
3785 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3786 if (id == 0) | |
3787 { | |
3788 EMSG2(_(e_nogroup), arg); | |
3789 break; | |
3790 } | |
3791 else | |
3792 syn_clear_one(id, syncing); | |
3793 } | |
3794 arg = skipwhite(arg_end); | |
3795 } | |
3796 } | |
745 | 3797 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3798 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3799 } |
3800 | |
3801 /* | |
3802 * Clear one syntax group for the current buffer. | |
3803 */ | |
3804 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3805 syn_clear_one(int id, int syncing) |
7 | 3806 { |
3807 synpat_T *spp; | |
3808 int idx; | |
3809 | |
3810 /* Clear keywords only when not ":syn sync clear group-name" */ | |
3811 if (!syncing) | |
3812 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3813 (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
|
3814 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); |
7 | 3815 } |
3816 | |
3817 /* clear the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3818 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
|
3819 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3820 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3821 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3822 continue; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3823 syn_remove_pattern(curwin->w_s, idx); |
7 | 3824 } |
3825 } | |
3826 | |
3827 /* | |
3828 * Handle ":syntax on" command. | |
3829 */ | |
3830 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3831 syn_cmd_on(exarg_T *eap, int syncing UNUSED) |
7 | 3832 { |
3833 syn_cmd_onoff(eap, "syntax"); | |
3834 } | |
3835 | |
3836 /* | |
3837 * Handle ":syntax enable" command. | |
3838 */ | |
3839 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3840 syn_cmd_enable(exarg_T *eap, int syncing UNUSED) |
7 | 3841 { |
3842 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable"); | |
3843 syn_cmd_onoff(eap, "syntax"); | |
148 | 3844 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3845 } |
3846 | |
3847 /* | |
3848 * Handle ":syntax reset" command. | |
8815
50d9fb580ffe
commit https://github.com/vim/vim/commit/8bc189e81aa98ba4aebb03a9dc9527a210fce816
Christian Brabandt <cb@256bit.org>
parents:
8806
diff
changeset
|
3849 * It actually resets highlighting, not syntax. |
7 | 3850 */ |
3851 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3852 syn_cmd_reset(exarg_T *eap, int syncing UNUSED) |
7 | 3853 { |
3854 eap->nextcmd = check_nextcmd(eap->arg); | |
3855 if (!eap->skip) | |
3856 { | |
3857 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset"); | |
3858 do_cmdline_cmd((char_u *)"runtime! syntax/syncolor.vim"); | |
148 | 3859 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3860 } |
3861 } | |
3862 | |
3863 /* | |
3864 * Handle ":syntax manual" command. | |
3865 */ | |
3866 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3867 syn_cmd_manual(exarg_T *eap, int syncing UNUSED) |
7 | 3868 { |
3869 syn_cmd_onoff(eap, "manual"); | |
3870 } | |
3871 | |
3872 /* | |
3873 * Handle ":syntax off" command. | |
3874 */ | |
3875 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3876 syn_cmd_off(exarg_T *eap, int syncing UNUSED) |
7 | 3877 { |
3878 syn_cmd_onoff(eap, "nosyntax"); | |
3879 } | |
3880 | |
3881 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3882 syn_cmd_onoff(exarg_T *eap, char *name) |
7 | 3883 { |
3884 char_u buf[100]; | |
3885 | |
3886 eap->nextcmd = check_nextcmd(eap->arg); | |
3887 if (!eap->skip) | |
3888 { | |
3889 STRCPY(buf, "so "); | |
274 | 3890 vim_snprintf((char *)buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); |
7 | 3891 do_cmdline_cmd(buf); |
3892 } | |
3893 } | |
3894 | |
3895 /* | |
3896 * Handle ":syntax [list]" command: list current syntax words. | |
3897 */ | |
3898 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3899 syn_cmd_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3900 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3901 int syncing) /* when TRUE: list syncing items */ |
7 | 3902 { |
3903 char_u *arg = eap->arg; | |
3904 int id; | |
3905 char_u *arg_end; | |
3906 | |
3907 eap->nextcmd = find_nextcmd(arg); | |
3908 if (eap->skip) | |
3909 return; | |
3910 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3911 if (!syntax_present(curwin)) |
7 | 3912 { |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3913 MSG(_(msg_no_items)); |
7 | 3914 return; |
3915 } | |
3916 | |
3917 if (syncing) | |
3918 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3919 if (curwin->w_s->b_syn_sync_flags & SF_CCOMMENT) |
7 | 3920 { |
3921 MSG_PUTS(_("syncing on C-style comments")); | |
3922 syn_lines_msg(); | |
3923 syn_match_msg(); | |
3924 return; | |
3925 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3926 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
|
3927 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3928 if (curwin->w_s->b_syn_sync_minlines == 0) |
7 | 3929 MSG_PUTS(_("no syncing")); |
3930 else | |
3931 { | |
3932 MSG_PUTS(_("syncing starts ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3933 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
7 | 3934 MSG_PUTS(_(" lines before top line")); |
3935 syn_match_msg(); | |
3936 } | |
3937 return; | |
3938 } | |
3939 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
|
3940 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
|
3941 || 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
|
3942 || curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3943 { |
3944 MSG_PUTS(_("\nsyncing on items")); | |
3945 syn_lines_msg(); | |
3946 syn_match_msg(); | |
3947 } | |
3948 } | |
3949 else | |
3950 MSG_PUTS_TITLE(_("\n--- Syntax items ---")); | |
3951 if (ends_excmd(*arg)) | |
3952 { | |
3953 /* | |
3954 * No argument: List all group IDs and all syntax clusters. | |
3955 */ | |
3956 for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id) | |
3957 syn_list_one(id, syncing, FALSE); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3958 for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) |
7 | 3959 syn_list_cluster(id); |
3960 } | |
3961 else | |
3962 { | |
3963 /* | |
3964 * List the group IDs and syntax clusters that are in the argument. | |
3965 */ | |
3966 while (!ends_excmd(*arg) && !got_int) | |
3967 { | |
3968 arg_end = skiptowhite(arg); | |
3969 if (*arg == '@') | |
3970 { | |
3971 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3972 if (id == 0) | |
3973 EMSG2(_("E392: No such syntax cluster: %s"), arg); | |
3974 else | |
3975 syn_list_cluster(id - SYNID_CLUSTER); | |
3976 } | |
3977 else | |
3978 { | |
3979 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3980 if (id == 0) | |
3981 EMSG2(_(e_nogroup), arg); | |
3982 else | |
3983 syn_list_one(id, syncing, TRUE); | |
3984 } | |
3985 arg = skipwhite(arg_end); | |
3986 } | |
3987 } | |
3988 eap->nextcmd = check_nextcmd(arg); | |
3989 } | |
3990 | |
3991 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3992 syn_lines_msg(void) |
7 | 3993 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3994 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
|
3995 || curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3996 { |
3997 MSG_PUTS("; "); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3998 if (curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3999 { |
4000 MSG_PUTS(_("minimal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4001 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
|
4002 if (curwin->w_s->b_syn_sync_maxlines) |
7 | 4003 MSG_PUTS(", "); |
4004 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4005 if (curwin->w_s->b_syn_sync_maxlines > 0) |
7 | 4006 { |
4007 MSG_PUTS(_("maximal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4008 msg_outnum(curwin->w_s->b_syn_sync_maxlines); |
7 | 4009 } |
4010 MSG_PUTS(_(" lines before top line")); | |
4011 } | |
4012 } | |
4013 | |
4014 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4015 syn_match_msg(void) |
7 | 4016 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4017 if (curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 4018 { |
4019 MSG_PUTS(_("; match ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4020 msg_outnum(curwin->w_s->b_syn_sync_linebreaks); |
7 | 4021 MSG_PUTS(_(" line breaks")); |
4022 } | |
4023 } | |
4024 | |
4025 static int last_matchgroup; | |
4026 | |
4027 struct name_list | |
4028 { | |
4029 int flag; | |
4030 char *name; | |
4031 }; | |
4032 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
4033 static void syn_list_flags(struct name_list *nl, int flags, int attr); |
7 | 4034 |
4035 /* | |
4036 * List one syntax item, for ":syntax" or "syntax list syntax_name". | |
4037 */ | |
4038 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4039 syn_list_one( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4040 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4041 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
|
4042 int link_only) /* when TRUE; list link-only too */ |
7 | 4043 { |
4044 int attr; | |
4045 int idx; | |
4046 int did_header = FALSE; | |
4047 synpat_T *spp; | |
4048 static struct name_list namelist1[] = | |
4049 { | |
4050 {HL_DISPLAY, "display"}, | |
4051 {HL_CONTAINED, "contained"}, | |
4052 {HL_ONELINE, "oneline"}, | |
4053 {HL_KEEPEND, "keepend"}, | |
4054 {HL_EXTEND, "extend"}, | |
4055 {HL_EXCLUDENL, "excludenl"}, | |
4056 {HL_TRANSP, "transparent"}, | |
4057 {HL_FOLD, "fold"}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4058 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4059 {HL_CONCEAL, "conceal"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4060 {HL_CONCEALENDS, "concealends"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4061 #endif |
7 | 4062 {0, NULL} |
4063 }; | |
4064 static struct name_list namelist2[] = | |
4065 { | |
4066 {HL_SKIPWHITE, "skipwhite"}, | |
4067 {HL_SKIPNL, "skipnl"}, | |
4068 {HL_SKIPEMPTY, "skipempty"}, | |
4069 {0, NULL} | |
4070 }; | |
4071 | |
4072 attr = hl_attr(HLF_D); /* highlight like directories */ | |
4073 | |
4074 /* list the keywords for "id" */ | |
4075 if (!syncing) | |
4076 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4077 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
|
4078 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, |
7 | 4079 did_header, attr); |
4080 } | |
4081 | |
4082 /* list the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4083 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
|
4084 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4085 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 4086 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
4087 continue; | |
4088 | |
4089 (void)syn_list_header(did_header, 999, id); | |
4090 did_header = TRUE; | |
4091 last_matchgroup = 0; | |
4092 if (spp->sp_type == SPTYPE_MATCH) | |
4093 { | |
4094 put_pattern("match", ' ', spp, attr); | |
4095 msg_putchar(' '); | |
4096 } | |
4097 else if (spp->sp_type == SPTYPE_START) | |
4098 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4099 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
|
4100 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
|
4101 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
|
4102 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
|
4103 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
|
4104 && 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
|
4105 put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
7 | 4106 --idx; |
4107 msg_putchar(' '); | |
4108 } | |
4109 syn_list_flags(namelist1, spp->sp_flags, attr); | |
4110 | |
4111 if (spp->sp_cont_list != NULL) | |
4112 put_id_list((char_u *)"contains", spp->sp_cont_list, attr); | |
4113 | |
4114 if (spp->sp_syn.cont_in_list != NULL) | |
4115 put_id_list((char_u *)"containedin", | |
4116 spp->sp_syn.cont_in_list, attr); | |
4117 | |
4118 if (spp->sp_next_list != NULL) | |
4119 { | |
4120 put_id_list((char_u *)"nextgroup", spp->sp_next_list, attr); | |
4121 syn_list_flags(namelist2, spp->sp_flags, attr); | |
4122 } | |
4123 if (spp->sp_flags & (HL_SYNC_HERE|HL_SYNC_THERE)) | |
4124 { | |
4125 if (spp->sp_flags & HL_SYNC_HERE) | |
4126 msg_puts_attr((char_u *)"grouphere", attr); | |
4127 else | |
4128 msg_puts_attr((char_u *)"groupthere", attr); | |
4129 msg_putchar(' '); | |
4130 if (spp->sp_sync_idx >= 0) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4131 msg_outtrans(HL_TABLE()[SYN_ITEMS(curwin->w_s) |
7 | 4132 [spp->sp_sync_idx].sp_syn.id - 1].sg_name); |
4133 else | |
4134 MSG_PUTS("NONE"); | |
4135 msg_putchar(' '); | |
4136 } | |
4137 } | |
4138 | |
4139 /* list the link, if there is one */ | |
4140 if (HL_TABLE()[id - 1].sg_link && (did_header || link_only) && !got_int) | |
4141 { | |
4142 (void)syn_list_header(did_header, 999, id); | |
4143 msg_puts_attr((char_u *)"links to", attr); | |
4144 msg_putchar(' '); | |
4145 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
4146 } | |
4147 } | |
4148 | |
4149 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4150 syn_list_flags(struct name_list *nlist, int flags, int attr) |
7 | 4151 { |
4152 int i; | |
4153 | |
3263 | 4154 for (i = 0; nlist[i].flag != 0; ++i) |
4155 if (flags & nlist[i].flag) | |
4156 { | |
4157 msg_puts_attr((char_u *)nlist[i].name, attr); | |
7 | 4158 msg_putchar(' '); |
4159 } | |
4160 } | |
4161 | |
4162 /* | |
4163 * List one syntax cluster, for ":syntax" or "syntax list syntax_name". | |
4164 */ | |
4165 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4166 syn_list_cluster(int id) |
7 | 4167 { |
4168 int endcol = 15; | |
4169 | |
4170 /* slight hack: roughly duplicate the guts of syn_list_header() */ | |
4171 msg_putchar('\n'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4172 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); |
7 | 4173 |
4174 if (msg_col >= endcol) /* output at least one space */ | |
4175 endcol = msg_col + 1; | |
4176 if (Columns <= endcol) /* avoid hang for tiny window */ | |
4177 endcol = Columns - 1; | |
4178 | |
4179 msg_advance(endcol); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4180 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
|
4181 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4182 put_id_list((char_u *)"cluster", SYN_CLSTR(curwin->w_s)[id].scl_list, |
7 | 4183 hl_attr(HLF_D)); |
4184 } | |
4185 else | |
4186 { | |
4187 msg_puts_attr((char_u *)"cluster", hl_attr(HLF_D)); | |
4188 msg_puts((char_u *)"=NONE"); | |
4189 } | |
4190 } | |
4191 | |
4192 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4193 put_id_list(char_u *name, short *list, int attr) |
7 | 4194 { |
4195 short *p; | |
4196 | |
4197 msg_puts_attr(name, attr); | |
4198 msg_putchar('='); | |
4199 for (p = list; *p; ++p) | |
4200 { | |
4201 if (*p >= SYNID_ALLBUT && *p < SYNID_TOP) | |
4202 { | |
4203 if (p[1]) | |
4204 MSG_PUTS("ALLBUT"); | |
4205 else | |
4206 MSG_PUTS("ALL"); | |
4207 } | |
4208 else if (*p >= SYNID_TOP && *p < SYNID_CONTAINED) | |
4209 { | |
4210 MSG_PUTS("TOP"); | |
4211 } | |
4212 else if (*p >= SYNID_CONTAINED && *p < SYNID_CLUSTER) | |
4213 { | |
4214 MSG_PUTS("CONTAINED"); | |
4215 } | |
4216 else if (*p >= SYNID_CLUSTER) | |
4217 { | |
4218 short scl_id = *p - SYNID_CLUSTER; | |
4219 | |
4220 msg_putchar('@'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4221 msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); |
7 | 4222 } |
4223 else | |
4224 msg_outtrans(HL_TABLE()[*p - 1].sg_name); | |
4225 if (p[1]) | |
4226 msg_putchar(','); | |
4227 } | |
4228 msg_putchar(' '); | |
4229 } | |
4230 | |
4231 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4232 put_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4233 char *s, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4234 int c, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4235 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4236 int attr) |
7 | 4237 { |
4238 long n; | |
4239 int mask; | |
4240 int first; | |
4241 static char *sepchars = "/+=-#@\"|'^&"; | |
4242 int i; | |
4243 | |
4244 /* May have to write "matchgroup=group" */ | |
4245 if (last_matchgroup != spp->sp_syn_match_id) | |
4246 { | |
4247 last_matchgroup = spp->sp_syn_match_id; | |
4248 msg_puts_attr((char_u *)"matchgroup", attr); | |
4249 msg_putchar('='); | |
4250 if (last_matchgroup == 0) | |
4251 msg_outtrans((char_u *)"NONE"); | |
4252 else | |
4253 msg_outtrans(HL_TABLE()[last_matchgroup - 1].sg_name); | |
4254 msg_putchar(' '); | |
4255 } | |
4256 | |
4257 /* output the name of the pattern and an '=' or ' ' */ | |
4258 msg_puts_attr((char_u *)s, attr); | |
4259 msg_putchar(c); | |
4260 | |
4261 /* output the pattern, in between a char that is not in the pattern */ | |
4262 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) | |
4263 if (sepchars[++i] == NUL) | |
4264 { | |
4265 i = 0; /* no good char found, just use the first one */ | |
4266 break; | |
4267 } | |
4268 msg_putchar(sepchars[i]); | |
4269 msg_outtrans(spp->sp_pattern); | |
4270 msg_putchar(sepchars[i]); | |
4271 | |
4272 /* output any pattern options */ | |
4273 first = TRUE; | |
4274 for (i = 0; i < SPO_COUNT; ++i) | |
4275 { | |
4276 mask = (1 << i); | |
4277 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) | |
4278 { | |
4279 if (!first) | |
4280 msg_putchar(','); /* separate with commas */ | |
4281 msg_puts((char_u *)spo_name_tab[i]); | |
4282 n = spp->sp_offsets[i]; | |
4283 if (i != SPO_LC_OFF) | |
4284 { | |
4285 if (spp->sp_off_flags & mask) | |
4286 msg_putchar('s'); | |
4287 else | |
4288 msg_putchar('e'); | |
4289 if (n > 0) | |
4290 msg_putchar('+'); | |
4291 } | |
4292 if (n || i == SPO_LC_OFF) | |
4293 msg_outnum(n); | |
4294 first = FALSE; | |
4295 } | |
4296 } | |
4297 msg_putchar(' '); | |
4298 } | |
4299 | |
4300 /* | |
4301 * List or clear the keywords for one syntax group. | |
4302 * Return TRUE if the header has been printed. | |
4303 */ | |
4304 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4305 syn_list_keywords( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4306 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4307 hashtab_T *ht, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4308 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
|
4309 int attr) |
7 | 4310 { |
4311 int outlen; | |
134 | 4312 hashitem_T *hi; |
4313 keyentry_T *kp; | |
4314 int todo; | |
7 | 4315 int prev_contained = 0; |
4316 short *prev_next_list = NULL; | |
4317 short *prev_cont_in_list = NULL; | |
4318 int prev_skipnl = 0; | |
4319 int prev_skipwhite = 0; | |
4320 int prev_skipempty = 0; | |
4321 | |
4322 /* | |
4323 * Unfortunately, this list of keywords is not sorted on alphabet but on | |
4324 * hash value... | |
4325 */ | |
835 | 4326 todo = (int)ht->ht_used; |
134 | 4327 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
4328 { | |
4329 if (!HASHITEM_EMPTY(hi)) | |
4330 { | |
4331 --todo; | |
4332 for (kp = HI2KE(hi); kp != NULL && !got_int; kp = kp->ke_next) | |
7 | 4333 { |
134 | 4334 if (kp->k_syn.id == id) |
7 | 4335 { |
134 | 4336 if (prev_contained != (kp->flags & HL_CONTAINED) |
4337 || prev_skipnl != (kp->flags & HL_SKIPNL) | |
4338 || prev_skipwhite != (kp->flags & HL_SKIPWHITE) | |
4339 || prev_skipempty != (kp->flags & HL_SKIPEMPTY) | |
4340 || prev_cont_in_list != kp->k_syn.cont_in_list | |
4341 || prev_next_list != kp->next_list) | |
4342 outlen = 9999; | |
4343 else | |
4344 outlen = (int)STRLEN(kp->keyword); | |
4345 /* output "contained" and "nextgroup" on each line */ | |
4346 if (syn_list_header(did_header, outlen, id)) | |
4347 { | |
4348 prev_contained = 0; | |
4349 prev_next_list = NULL; | |
4350 prev_cont_in_list = NULL; | |
4351 prev_skipnl = 0; | |
4352 prev_skipwhite = 0; | |
4353 prev_skipempty = 0; | |
4354 } | |
4355 did_header = TRUE; | |
4356 if (prev_contained != (kp->flags & HL_CONTAINED)) | |
4357 { | |
4358 msg_puts_attr((char_u *)"contained", attr); | |
4359 msg_putchar(' '); | |
4360 prev_contained = (kp->flags & HL_CONTAINED); | |
4361 } | |
4362 if (kp->k_syn.cont_in_list != prev_cont_in_list) | |
4363 { | |
4364 put_id_list((char_u *)"containedin", | |
4365 kp->k_syn.cont_in_list, attr); | |
4366 msg_putchar(' '); | |
4367 prev_cont_in_list = kp->k_syn.cont_in_list; | |
4368 } | |
4369 if (kp->next_list != prev_next_list) | |
4370 { | |
4371 put_id_list((char_u *)"nextgroup", kp->next_list, attr); | |
4372 msg_putchar(' '); | |
4373 prev_next_list = kp->next_list; | |
4374 if (kp->flags & HL_SKIPNL) | |
4375 { | |
4376 msg_puts_attr((char_u *)"skipnl", attr); | |
4377 msg_putchar(' '); | |
4378 prev_skipnl = (kp->flags & HL_SKIPNL); | |
4379 } | |
4380 if (kp->flags & HL_SKIPWHITE) | |
4381 { | |
4382 msg_puts_attr((char_u *)"skipwhite", attr); | |
4383 msg_putchar(' '); | |
4384 prev_skipwhite = (kp->flags & HL_SKIPWHITE); | |
4385 } | |
4386 if (kp->flags & HL_SKIPEMPTY) | |
4387 { | |
4388 msg_puts_attr((char_u *)"skipempty", attr); | |
4389 msg_putchar(' '); | |
4390 prev_skipempty = (kp->flags & HL_SKIPEMPTY); | |
4391 } | |
4392 } | |
4393 msg_outtrans(kp->keyword); | |
7 | 4394 } |
4395 } | |
4396 } | |
4397 } | |
4398 | |
4399 return did_header; | |
4400 } | |
4401 | |
4402 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4403 syn_clear_keyword(int id, hashtab_T *ht) |
134 | 4404 { |
4405 hashitem_T *hi; | |
4406 keyentry_T *kp; | |
4407 keyentry_T *kp_prev; | |
4408 keyentry_T *kp_next; | |
4409 int todo; | |
4410 | |
4411 hash_lock(ht); | |
835 | 4412 todo = (int)ht->ht_used; |
134 | 4413 for (hi = ht->ht_array; todo > 0; ++hi) |
4414 { | |
4415 if (!HASHITEM_EMPTY(hi)) | |
4416 { | |
4417 --todo; | |
4418 kp_prev = NULL; | |
4419 for (kp = HI2KE(hi); kp != NULL; ) | |
7 | 4420 { |
134 | 4421 if (kp->k_syn.id == id) |
4422 { | |
4423 kp_next = kp->ke_next; | |
4424 if (kp_prev == NULL) | |
4425 { | |
4426 if (kp_next == NULL) | |
4427 hash_remove(ht, hi); | |
4428 else | |
4429 hi->hi_key = KE2HIKEY(kp_next); | |
4430 } | |
4431 else | |
4432 kp_prev->ke_next = kp_next; | |
4433 vim_free(kp->next_list); | |
4434 vim_free(kp->k_syn.cont_in_list); | |
4435 vim_free(kp); | |
4436 kp = kp_next; | |
4437 } | |
7 | 4438 else |
134 | 4439 { |
4440 kp_prev = kp; | |
4441 kp = kp->ke_next; | |
4442 } | |
7 | 4443 } |
134 | 4444 } |
4445 } | |
4446 hash_unlock(ht); | |
4447 } | |
4448 | |
4449 /* | |
4450 * Clear a whole keyword table. | |
7 | 4451 */ |
4452 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4453 clear_keywtab(hashtab_T *ht) |
134 | 4454 { |
4455 hashitem_T *hi; | |
4456 int todo; | |
4457 keyentry_T *kp; | |
4458 keyentry_T *kp_next; | |
4459 | |
835 | 4460 todo = (int)ht->ht_used; |
134 | 4461 for (hi = ht->ht_array; todo > 0; ++hi) |
4462 { | |
4463 if (!HASHITEM_EMPTY(hi)) | |
4464 { | |
4465 --todo; | |
4466 for (kp = HI2KE(hi); kp != NULL; kp = kp_next) | |
7 | 4467 { |
134 | 4468 kp_next = kp->ke_next; |
4469 vim_free(kp->next_list); | |
4470 vim_free(kp->k_syn.cont_in_list); | |
4471 vim_free(kp); | |
7 | 4472 } |
134 | 4473 } |
4474 } | |
4475 hash_clear(ht); | |
4476 hash_init(ht); | |
7 | 4477 } |
4478 | |
4479 /* | |
4480 * Add a keyword to the list of keywords. | |
4481 */ | |
4482 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4483 add_keyword( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4484 char_u *name, /* name of keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4485 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
|
4486 int flags, /* flags for this keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4487 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
|
4488 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
|
4489 int conceal_char) |
7 | 4490 { |
134 | 4491 keyentry_T *kp; |
4492 hashtab_T *ht; | |
4493 hashitem_T *hi; | |
154 | 4494 char_u *name_ic; |
134 | 4495 long_u hash; |
154 | 4496 char_u name_folded[MAXKEYWLEN + 1]; |
7 | 4497 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4498 if (curwin->w_s->b_syn_ic) |
154 | 4499 name_ic = str_foldcase(name, (int)STRLEN(name), |
4500 name_folded, MAXKEYWLEN + 1); | |
4501 else | |
4502 name_ic = name; | |
134 | 4503 kp = (keyentry_T *)alloc((int)(sizeof(keyentry_T) + STRLEN(name_ic))); |
4504 if (kp == NULL) | |
4505 return; | |
4506 STRCPY(kp->keyword, name_ic); | |
4507 kp->k_syn.id = id; | |
4508 kp->k_syn.inc_tag = current_syn_inc_tag; | |
4509 kp->flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4510 kp->k_char = conceal_char; |
134 | 4511 kp->k_syn.cont_in_list = copy_id_list(cont_in_list); |
4512 if (cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4513 curwin->w_s->b_syn_containedin = TRUE; |
134 | 4514 kp->next_list = copy_id_list(next_list); |
4515 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4516 if (curwin->w_s->b_syn_ic) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4517 ht = &curwin->w_s->b_keywtab_ic; |
7 | 4518 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4519 ht = &curwin->w_s->b_keywtab; |
134 | 4520 |
4521 hash = hash_hash(kp->keyword); | |
4522 hi = hash_lookup(ht, kp->keyword, hash); | |
4523 if (HASHITEM_EMPTY(hi)) | |
4524 { | |
4525 /* new keyword, add to hashtable */ | |
4526 kp->ke_next = NULL; | |
4527 hash_add_item(ht, hi, kp->keyword, hash); | |
4528 } | |
4529 else | |
4530 { | |
4531 /* keyword already exists, prepend to list */ | |
4532 kp->ke_next = HI2KE(hi); | |
4533 hi->hi_key = KE2HIKEY(kp); | |
4534 } | |
7 | 4535 } |
4536 | |
4537 /* | |
4538 * Get the start and end of the group name argument. | |
4539 * Return a pointer to the first argument. | |
4540 * Return NULL if the end of the command was found instead of further args. | |
4541 */ | |
4542 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4543 get_group_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4544 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
|
4545 char_u **name_end) /* pointer to end of the name */ |
7 | 4546 { |
4547 char_u *rest; | |
4548 | |
4549 *name_end = skiptowhite(arg); | |
4550 rest = skipwhite(*name_end); | |
4551 | |
4552 /* | |
4553 * Check if there are enough arguments. The first argument may be a | |
4554 * pattern, where '|' is allowed, so only check for NUL. | |
4555 */ | |
4556 if (ends_excmd(*arg) || *rest == NUL) | |
4557 return NULL; | |
4558 return rest; | |
4559 } | |
4560 | |
4561 /* | |
4562 * Check for syntax command option arguments. | |
4563 * This can be called at any place in the list of arguments, and just picks | |
4564 * out the arguments that are known. Can be called several times in a row to | |
4565 * collect all options in between other arguments. | |
4566 * Return a pointer to the next argument (which isn't an option). | |
4567 * Return NULL for any error; | |
4568 */ | |
4569 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4570 get_syn_options( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4571 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
|
4572 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
|
4573 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
|
4574 int skip) /* TRUE if skipping over command */ |
154 | 4575 { |
7 | 4576 char_u *gname_start, *gname; |
4577 int syn_id; | |
4578 int len; | |
154 | 4579 char *p; |
7 | 4580 int i; |
4581 int fidx; | |
4582 static struct flag | |
4583 { | |
4584 char *name; | |
154 | 4585 int argtype; |
4586 int flags; | |
4587 } flagtab[] = { {"cCoOnNtTaAiInNeEdD", 0, HL_CONTAINED}, | |
4588 {"oOnNeElLiInNeE", 0, HL_ONELINE}, | |
4589 {"kKeEeEpPeEnNdD", 0, HL_KEEPEND}, | |
4590 {"eExXtTeEnNdD", 0, HL_EXTEND}, | |
4591 {"eExXcClLuUdDeEnNlL", 0, HL_EXCLUDENL}, | |
4592 {"tTrRaAnNsSpPaArReEnNtT", 0, HL_TRANSP}, | |
4593 {"sSkKiIpPnNlL", 0, HL_SKIPNL}, | |
4594 {"sSkKiIpPwWhHiItTeE", 0, HL_SKIPWHITE}, | |
4595 {"sSkKiIpPeEmMpPtTyY", 0, HL_SKIPEMPTY}, | |
4596 {"gGrRoOuUpPhHeErReE", 0, HL_SYNC_HERE}, | |
4597 {"gGrRoOuUpPtThHeErReE", 0, HL_SYNC_THERE}, | |
4598 {"dDiIsSpPlLaAyY", 0, HL_DISPLAY}, | |
4599 {"fFoOlLdD", 0, HL_FOLD}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4600 {"cCoOnNcCeEaAlL", 0, HL_CONCEAL}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4601 {"cCoOnNcCeEaAlLeEnNdDsS", 0, HL_CONCEALENDS}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4602 {"cCcChHaArR", 11, 0}, |
154 | 4603 {"cCoOnNtTaAiInNsS", 1, 0}, |
4604 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, | |
4605 {"nNeExXtTgGrRoOuUpP", 3, 0}, | |
7 | 4606 }; |
154 | 4607 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; |
7 | 4608 |
4609 if (arg == NULL) /* already detected error */ | |
4610 return NULL; | |
4611 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4612 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4613 if (curwin->w_s->b_syn_conceal) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4614 opt->flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4615 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4616 |
7 | 4617 for (;;) |
4618 { | |
154 | 4619 /* |
4620 * This is used very often when a large number of keywords is defined. | |
4621 * Need to skip quickly when no option name is found. | |
4622 * Also avoid tolower(), it's slow. | |
4623 */ | |
4624 if (strchr(first_letters, *arg) == NULL) | |
4625 break; | |
7 | 4626 |
4627 for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; ) | |
4628 { | |
154 | 4629 p = flagtab[fidx].name; |
4630 for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) | |
4631 if (arg[len] != p[i] && arg[len] != p[i + 1]) | |
4632 break; | |
4633 if (p[i] == NUL && (vim_iswhite(arg[len]) | |
4634 || (flagtab[fidx].argtype > 0 | |
4635 ? arg[len] == '=' | |
4636 : ends_excmd(arg[len])))) | |
7 | 4637 { |
154 | 4638 if (opt->keyword |
4639 && (flagtab[fidx].flags == HL_DISPLAY | |
4640 || flagtab[fidx].flags == HL_FOLD | |
4641 || flagtab[fidx].flags == HL_EXTEND)) | |
7 | 4642 /* treat "display", "fold" and "extend" as a keyword */ |
4643 fidx = -1; | |
4644 break; | |
4645 } | |
4646 } | |
154 | 4647 if (fidx < 0) /* no match found */ |
4648 break; | |
4649 | |
4650 if (flagtab[fidx].argtype == 1) | |
4651 { | |
4652 if (!opt->has_cont_list) | |
7 | 4653 { |
4654 EMSG(_("E395: contains argument not accepted here")); | |
4655 return NULL; | |
4656 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4657 if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) |
7 | 4658 return NULL; |
4659 } | |
154 | 4660 else if (flagtab[fidx].argtype == 2) |
4661 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4662 if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL) |
7 | 4663 return NULL; |
4664 } | |
154 | 4665 else if (flagtab[fidx].argtype == 3) |
4666 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4667 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) |
7 | 4668 return NULL; |
4669 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4670 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
|
4671 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4672 #ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4673 /* cchar=? */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4674 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4675 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4676 # ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4677 *conceal_char = mb_ptr2char(arg + 6); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4678 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4679 arg += mb_ptr2len(arg + 6) - 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4680 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4681 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4682 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4683 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4684 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4685 *conceal_char = arg[6]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4686 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4687 ; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4688 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4689 } |
2686 | 4690 #ifdef FEAT_CONCEAL |
4691 if (!vim_isprintc_strict(*conceal_char)) | |
4692 { | |
4693 EMSG(_("E844: invalid cchar value")); | |
4694 return NULL; | |
4695 } | |
4696 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4697 arg = skipwhite(arg + 7); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4698 } |
7 | 4699 else |
154 | 4700 { |
4701 opt->flags |= flagtab[fidx].flags; | |
4702 arg = skipwhite(arg + len); | |
4703 | |
4704 if (flagtab[fidx].flags == HL_SYNC_HERE | |
4705 || flagtab[fidx].flags == HL_SYNC_THERE) | |
4706 { | |
4707 if (opt->sync_idx == NULL) | |
4708 { | |
4709 EMSG(_("E393: group[t]here not accepted here")); | |
4710 return NULL; | |
4711 } | |
4712 gname_start = arg; | |
4713 arg = skiptowhite(arg); | |
4714 if (gname_start == arg) | |
4715 return NULL; | |
4716 gname = vim_strnsave(gname_start, (int)(arg - gname_start)); | |
4717 if (gname == NULL) | |
4718 return NULL; | |
4719 if (STRCMP(gname, "NONE") == 0) | |
4720 *opt->sync_idx = NONE_IDX; | |
4721 else | |
4722 { | |
4723 syn_id = syn_name2id(gname); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4724 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
|
4725 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
|
4726 && SYN_ITEMS(curwin->w_s)[i].sp_type == SPTYPE_START) |
154 | 4727 { |
4728 *opt->sync_idx = i; | |
4729 break; | |
4730 } | |
4731 if (i < 0) | |
4732 { | |
4733 EMSG2(_("E394: Didn't find region item for %s"), gname); | |
4734 vim_free(gname); | |
4735 return NULL; | |
4736 } | |
4737 } | |
4738 | |
4739 vim_free(gname); | |
4740 arg = skipwhite(arg); | |
4741 } | |
4742 #ifdef FEAT_FOLDING | |
4743 else if (flagtab[fidx].flags == HL_FOLD | |
4744 && foldmethodIsSyntax(curwin)) | |
4745 /* Need to update folds later. */ | |
4746 foldUpdateAll(curwin); | |
4747 #endif | |
4748 } | |
4749 } | |
7 | 4750 |
4751 return arg; | |
4752 } | |
4753 | |
4754 /* | |
4755 * Adjustments to syntax item when declared in a ":syn include"'d file. | |
4756 * Set the contained flag, and if the item is not already contained, add it | |
4757 * to the specified top-level group, if any. | |
4758 */ | |
4759 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4760 syn_incl_toplevel(int id, int *flagsp) |
7 | 4761 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4762 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) |
7 | 4763 return; |
4764 *flagsp |= HL_CONTAINED; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4765 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
7 | 4766 { |
4767 /* We have to alloc this, because syn_combine_list() will free it. */ | |
4768 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
|
4769 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; |
7 | 4770 |
4771 if (grp_list != NULL) | |
4772 { | |
4773 grp_list[0] = id; | |
4774 grp_list[1] = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4775 syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, &grp_list, |
7 | 4776 CLUSTER_ADD); |
4777 } | |
4778 } | |
4779 } | |
4780 | |
4781 /* | |
4782 * Handle ":syntax include [@{group-name}] filename" command. | |
4783 */ | |
4784 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4785 syn_cmd_include(exarg_T *eap, int syncing UNUSED) |
7 | 4786 { |
4787 char_u *arg = eap->arg; | |
4788 int sgl_id = 1; | |
4789 char_u *group_name_end; | |
4790 char_u *rest; | |
4791 char_u *errormsg = NULL; | |
4792 int prev_toplvl_grp; | |
4793 int prev_syn_inc_tag; | |
4794 int source = FALSE; | |
4795 | |
4796 eap->nextcmd = find_nextcmd(arg); | |
4797 if (eap->skip) | |
4798 return; | |
4799 | |
4800 if (arg[0] == '@') | |
4801 { | |
4802 ++arg; | |
4803 rest = get_group_name(arg, &group_name_end); | |
4804 if (rest == NULL) | |
4805 { | |
4806 EMSG((char_u *)_("E397: Filename required")); | |
4807 return; | |
4808 } | |
4809 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
2743 | 4810 if (sgl_id == 0) |
4811 return; | |
7 | 4812 /* separate_nextcmd() and expand_filename() depend on this */ |
4813 eap->arg = rest; | |
4814 } | |
4815 | |
4816 /* | |
4817 * Everything that's left, up to the next command, should be the | |
4818 * filename to include. | |
4819 */ | |
4820 eap->argt |= (XFILE | NOSPC); | |
4821 separate_nextcmd(eap); | |
4822 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) | |
4823 { | |
4824 /* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the | |
4825 * file. Need to expand the file name first. In other cases | |
4826 * ":runtime!" is used. */ | |
4827 source = TRUE; | |
4828 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) | |
4829 { | |
4830 if (errormsg != NULL) | |
4831 EMSG(errormsg); | |
4832 return; | |
4833 } | |
4834 } | |
4835 | |
4836 /* | |
4837 * Save and restore the existing top-level grouplist id and ":syn | |
4838 * include" tag around the actual inclusion. | |
4839 */ | |
2743 | 4840 if (running_syn_inc_tag >= MAX_SYN_INC_TAG) |
4841 { | |
4842 EMSG((char_u *)_("E847: Too many syntax includes")); | |
4843 return; | |
4844 } | |
7 | 4845 prev_syn_inc_tag = current_syn_inc_tag; |
4846 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
|
4847 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
|
4848 curwin->w_s->b_syn_topgrp = sgl_id; |
1299 | 4849 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
|
4850 : source_runtime(eap->arg, DIP_ALL) == FAIL) |
7 | 4851 EMSG2(_(e_notopen), eap->arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4852 curwin->w_s->b_syn_topgrp = prev_toplvl_grp; |
7 | 4853 current_syn_inc_tag = prev_syn_inc_tag; |
4854 } | |
4855 | |
4856 /* | |
4857 * Handle ":syntax keyword {group-name} [{option}] keyword .." command. | |
4858 */ | |
4859 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4860 syn_cmd_keyword(exarg_T *eap, int syncing UNUSED) |
7 | 4861 { |
4862 char_u *arg = eap->arg; | |
4863 char_u *group_name_end; | |
4864 int syn_id; | |
4865 char_u *rest; | |
2743 | 4866 char_u *keyword_copy = NULL; |
7 | 4867 char_u *p; |
154 | 4868 char_u *kw; |
4869 syn_opt_arg_T syn_opt_arg; | |
4870 int cnt; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4871 int conceal_char = NUL; |
7 | 4872 |
4873 rest = get_group_name(arg, &group_name_end); | |
4874 | |
4875 if (rest != NULL) | |
4876 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4877 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
|
4878 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
|
4879 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4880 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); |
2743 | 4881 if (syn_id != 0) |
4882 /* allocate a buffer, for removing backslashes in the keyword */ | |
4883 keyword_copy = alloc((unsigned)STRLEN(rest) + 1); | |
7 | 4884 if (keyword_copy != NULL) |
4885 { | |
154 | 4886 syn_opt_arg.flags = 0; |
4887 syn_opt_arg.keyword = TRUE; | |
4888 syn_opt_arg.sync_idx = NULL; | |
4889 syn_opt_arg.has_cont_list = FALSE; | |
4890 syn_opt_arg.cont_in_list = NULL; | |
4891 syn_opt_arg.next_list = NULL; | |
4892 | |
7 | 4893 /* |
4894 * The options given apply to ALL keywords, so all options must be | |
4895 * found before keywords can be created. | |
154 | 4896 * 1: collect the options and copy the keywords to keyword_copy. |
7 | 4897 */ |
154 | 4898 cnt = 0; |
4899 p = keyword_copy; | |
4900 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) | |
7 | 4901 { |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4902 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
|
4903 eap->skip); |
154 | 4904 if (rest == NULL || ends_excmd(*rest)) |
4905 break; | |
4906 /* Copy the keyword, removing backslashes, and add a NUL. */ | |
4907 while (*rest != NUL && !vim_iswhite(*rest)) | |
4908 { | |
4909 if (*rest == '\\' && rest[1] != NUL) | |
4910 ++rest; | |
4911 *p++ = *rest++; | |
4912 } | |
4913 *p++ = NUL; | |
4914 ++cnt; | |
4915 } | |
4916 | |
4917 if (!eap->skip) | |
4918 { | |
4919 /* Adjust flags for use of ":syn include". */ | |
4920 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); | |
4921 | |
7 | 4922 /* |
154 | 4923 * 2: Add an entry for each keyword. |
7 | 4924 */ |
154 | 4925 for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) |
7 | 4926 { |
154 | 4927 for (p = vim_strchr(kw, '['); ; ) |
7 | 4928 { |
154 | 4929 if (p != NULL) |
4930 *p = NUL; | |
4931 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
|
4932 syn_opt_arg.cont_in_list, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4933 syn_opt_arg.next_list, conceal_char); |
168 | 4934 if (p == NULL) |
4935 break; | |
4936 if (p[1] == NUL) | |
4937 { | |
838 | 4938 EMSG2(_("E789: Missing ']': %s"), kw); |
7017 | 4939 goto error; |
168 | 4940 } |
4941 if (p[1] == ']') | |
4942 { | |
7017 | 4943 if (p[2] != NUL) |
4944 { | |
4945 EMSG3(_("E890: trailing char after ']': %s]%s"), | |
4946 kw, &p[2]); | |
4947 goto error; | |
4948 } | |
168 | 4949 kw = p + 1; /* skip over the "]" */ |
4950 break; | |
4951 } | |
154 | 4952 #ifdef FEAT_MBYTE |
4953 if (has_mbyte) | |
7 | 4954 { |
474 | 4955 int l = (*mb_ptr2len)(p + 1); |
154 | 4956 |
4957 mch_memmove(p, p + 1, l); | |
4958 p += l; | |
4959 } | |
4960 else | |
7 | 4961 #endif |
154 | 4962 { |
4963 p[0] = p[1]; | |
4964 ++p; | |
7 | 4965 } |
4966 } | |
4967 } | |
4968 } | |
7017 | 4969 error: |
7 | 4970 vim_free(keyword_copy); |
168 | 4971 vim_free(syn_opt_arg.cont_in_list); |
4972 vim_free(syn_opt_arg.next_list); | |
7 | 4973 } |
4974 } | |
4975 | |
4976 if (rest != NULL) | |
4977 eap->nextcmd = check_nextcmd(rest); | |
4978 else | |
4979 EMSG2(_(e_invarg2), arg); | |
4980 | |
745 | 4981 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4982 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 4983 } |
4984 | |
4985 /* | |
4986 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". | |
4987 * | |
4988 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." | |
4989 */ | |
4990 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4991 syn_cmd_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4992 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4993 int syncing) /* TRUE for ":syntax sync match .. " */ |
7 | 4994 { |
4995 char_u *arg = eap->arg; | |
4996 char_u *group_name_end; | |
4997 char_u *rest; | |
4998 synpat_T item; /* the item found in the line */ | |
4999 int syn_id; | |
5000 int idx; | |
154 | 5001 syn_opt_arg_T syn_opt_arg; |
7 | 5002 int sync_idx = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5003 int conceal_char = NUL; |
7 | 5004 |
5005 /* Isolate the group name, check for validity */ | |
5006 rest = get_group_name(arg, &group_name_end); | |
5007 | |
5008 /* Get options before the pattern */ | |
154 | 5009 syn_opt_arg.flags = 0; |
5010 syn_opt_arg.keyword = FALSE; | |
5011 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; | |
5012 syn_opt_arg.has_cont_list = TRUE; | |
5013 syn_opt_arg.cont_list = NULL; | |
5014 syn_opt_arg.cont_in_list = NULL; | |
5015 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
|
5016 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5017 |
5018 /* get the pattern. */ | |
5019 init_syn_patterns(); | |
5020 vim_memset(&item, 0, sizeof(item)); | |
5021 rest = get_syn_pattern(rest, &item); | |
154 | 5022 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
5023 syn_opt_arg.flags |= HL_HAS_EOL; | |
7 | 5024 |
5025 /* 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
|
5026 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5027 |
5028 if (rest != NULL) /* all arguments are valid */ | |
5029 { | |
5030 /* | |
5031 * Check for trailing command and illegal trailing arguments. | |
5032 */ | |
5033 eap->nextcmd = check_nextcmd(rest); | |
5034 if (!ends_excmd(*rest) || eap->skip) | |
5035 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5036 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL |
7 | 5037 && (syn_id = syn_check_group(arg, |
5038 (int)(group_name_end - arg))) != 0) | |
5039 { | |
154 | 5040 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5041 /* |
5042 * Store the pattern in the syn_items list | |
5043 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5044 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
|
5045 SYN_ITEMS(curwin->w_s)[idx] = item; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5046 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
|
5047 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
|
5048 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
|
5049 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
|
5050 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
|
5051 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
|
5052 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
|
5053 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5054 syn_opt_arg.cont_in_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5055 #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
|
5056 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
|
5057 #endif |
154 | 5058 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
|
5059 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5060 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
|
5061 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5062 |
5063 /* remember that we found a match for syncing on */ | |
154 | 5064 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
|
5065 curwin->w_s->b_syn_sync_flags |= SF_MATCH; |
7 | 5066 #ifdef FEAT_FOLDING |
154 | 5067 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
|
5068 ++curwin->w_s->b_syn_folditems; |
7 | 5069 #endif |
5070 | |
745 | 5071 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5072 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5073 return; /* don't free the progs and patterns now */ |
5074 } | |
5075 } | |
5076 | |
5077 /* | |
5078 * Something failed, free the allocated memory. | |
5079 */ | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5080 vim_regfree(item.sp_prog); |
7 | 5081 vim_free(item.sp_pattern); |
154 | 5082 vim_free(syn_opt_arg.cont_list); |
5083 vim_free(syn_opt_arg.cont_in_list); | |
5084 vim_free(syn_opt_arg.next_list); | |
7 | 5085 |
5086 if (rest == NULL) | |
5087 EMSG2(_(e_invarg2), arg); | |
5088 } | |
5089 | |
5090 /* | |
5091 * Handle ":syntax region {group-name} [matchgroup={group-name}] | |
5092 * start {start} .. [skip {skip}] end {end} .. [{options}]". | |
5093 */ | |
5094 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5095 syn_cmd_region( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5096 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5097 int syncing) /* TRUE for ":syntax sync region .." */ |
7 | 5098 { |
5099 char_u *arg = eap->arg; | |
5100 char_u *group_name_end; | |
5101 char_u *rest; /* next arg, NULL on error */ | |
5102 char_u *key_end; | |
5103 char_u *key = NULL; | |
5104 char_u *p; | |
5105 int item; | |
5106 #define ITEM_START 0 | |
5107 #define ITEM_SKIP 1 | |
5108 #define ITEM_END 2 | |
5109 #define ITEM_MATCHGROUP 3 | |
5110 struct pat_ptr | |
5111 { | |
5112 synpat_T *pp_synp; /* pointer to syn_pattern */ | |
5113 int pp_matchgroup_id; /* matchgroup ID */ | |
5114 struct pat_ptr *pp_next; /* pointer to next pat_ptr */ | |
5115 } *(pat_ptrs[3]); | |
5116 /* patterns found in the line */ | |
5117 struct pat_ptr *ppp; | |
5118 struct pat_ptr *ppp_next; | |
5119 int pat_count = 0; /* nr of syn_patterns found */ | |
5120 int syn_id; | |
5121 int matchgroup_id = 0; | |
5122 int not_enough = FALSE; /* not enough arguments */ | |
5123 int illegal = FALSE; /* illegal arguments */ | |
5124 int success = FALSE; | |
5125 int idx; | |
154 | 5126 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
|
5127 int conceal_char = NUL; |
7 | 5128 |
5129 /* Isolate the group name, check for validity */ | |
5130 rest = get_group_name(arg, &group_name_end); | |
5131 | |
5132 pat_ptrs[0] = NULL; | |
5133 pat_ptrs[1] = NULL; | |
5134 pat_ptrs[2] = NULL; | |
5135 | |
5136 init_syn_patterns(); | |
5137 | |
154 | 5138 syn_opt_arg.flags = 0; |
5139 syn_opt_arg.keyword = FALSE; | |
5140 syn_opt_arg.sync_idx = NULL; | |
5141 syn_opt_arg.has_cont_list = TRUE; | |
5142 syn_opt_arg.cont_list = NULL; | |
5143 syn_opt_arg.cont_in_list = NULL; | |
5144 syn_opt_arg.next_list = NULL; | |
5145 | |
7 | 5146 /* |
5147 * get the options, patterns and matchgroup. | |
5148 */ | |
5149 while (rest != NULL && !ends_excmd(*rest)) | |
5150 { | |
5151 /* 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
|
5152 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5153 if (rest == NULL || ends_excmd(*rest)) |
5154 break; | |
5155 | |
5156 /* must be a pattern or matchgroup then */ | |
5157 key_end = rest; | |
5158 while (*key_end && !vim_iswhite(*key_end) && *key_end != '=') | |
5159 ++key_end; | |
5160 vim_free(key); | |
5161 key = vim_strnsave_up(rest, (int)(key_end - rest)); | |
5162 if (key == NULL) /* out of memory */ | |
5163 { | |
5164 rest = NULL; | |
5165 break; | |
5166 } | |
5167 if (STRCMP(key, "MATCHGROUP") == 0) | |
5168 item = ITEM_MATCHGROUP; | |
5169 else if (STRCMP(key, "START") == 0) | |
5170 item = ITEM_START; | |
5171 else if (STRCMP(key, "END") == 0) | |
5172 item = ITEM_END; | |
5173 else if (STRCMP(key, "SKIP") == 0) | |
5174 { | |
5175 if (pat_ptrs[ITEM_SKIP] != NULL) /* one skip pattern allowed */ | |
5176 { | |
5177 illegal = TRUE; | |
5178 break; | |
5179 } | |
5180 item = ITEM_SKIP; | |
5181 } | |
5182 else | |
5183 break; | |
5184 rest = skipwhite(key_end); | |
5185 if (*rest != '=') | |
5186 { | |
5187 rest = NULL; | |
5188 EMSG2(_("E398: Missing '=': %s"), arg); | |
5189 break; | |
5190 } | |
5191 rest = skipwhite(rest + 1); | |
5192 if (*rest == NUL) | |
5193 { | |
5194 not_enough = TRUE; | |
5195 break; | |
5196 } | |
5197 | |
5198 if (item == ITEM_MATCHGROUP) | |
5199 { | |
5200 p = skiptowhite(rest); | |
5201 if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) | |
5202 matchgroup_id = 0; | |
5203 else | |
5204 { | |
5205 matchgroup_id = syn_check_group(rest, (int)(p - rest)); | |
5206 if (matchgroup_id == 0) | |
5207 { | |
5208 illegal = TRUE; | |
5209 break; | |
5210 } | |
5211 } | |
5212 rest = skipwhite(p); | |
5213 } | |
5214 else | |
5215 { | |
5216 /* | |
5217 * Allocate room for a syn_pattern, and link it in the list of | |
5218 * syn_patterns for this item, at the start (because the list is | |
5219 * used from end to start). | |
5220 */ | |
5221 ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr)); | |
5222 if (ppp == NULL) | |
5223 { | |
5224 rest = NULL; | |
5225 break; | |
5226 } | |
5227 ppp->pp_next = pat_ptrs[item]; | |
5228 pat_ptrs[item] = ppp; | |
5229 ppp->pp_synp = (synpat_T *)alloc_clear((unsigned)sizeof(synpat_T)); | |
5230 if (ppp->pp_synp == NULL) | |
5231 { | |
5232 rest = NULL; | |
5233 break; | |
5234 } | |
5235 | |
5236 /* | |
5237 * Get the syntax pattern and the following offset(s). | |
5238 */ | |
5239 /* Enable the appropriate \z specials. */ | |
5240 if (item == ITEM_START) | |
5241 reg_do_extmatch = REX_SET; | |
5242 else if (item == ITEM_SKIP || item == ITEM_END) | |
5243 reg_do_extmatch = REX_USE; | |
5244 rest = get_syn_pattern(rest, ppp->pp_synp); | |
5245 reg_do_extmatch = 0; | |
5246 if (item == ITEM_END && vim_regcomp_had_eol() | |
154 | 5247 && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
7 | 5248 ppp->pp_synp->sp_flags |= HL_HAS_EOL; |
5249 ppp->pp_matchgroup_id = matchgroup_id; | |
5250 ++pat_count; | |
5251 } | |
5252 } | |
5253 vim_free(key); | |
5254 if (illegal || not_enough) | |
5255 rest = NULL; | |
5256 | |
5257 /* | |
5258 * Must have a "start" and "end" pattern. | |
5259 */ | |
5260 if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || | |
5261 pat_ptrs[ITEM_END] == NULL)) | |
5262 { | |
5263 not_enough = TRUE; | |
5264 rest = NULL; | |
5265 } | |
5266 | |
5267 if (rest != NULL) | |
5268 { | |
5269 /* | |
5270 * Check for trailing garbage or command. | |
5271 * If OK, add the item. | |
5272 */ | |
5273 eap->nextcmd = check_nextcmd(rest); | |
5274 if (!ends_excmd(*rest) || eap->skip) | |
5275 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5276 else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL |
7 | 5277 && (syn_id = syn_check_group(arg, |
5278 (int)(group_name_end - arg))) != 0) | |
5279 { | |
154 | 5280 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5281 /* |
5282 * Store the start/skip/end in the syn_items list | |
5283 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5284 idx = curwin->w_s->b_syn_patterns.ga_len; |
7 | 5285 for (item = ITEM_START; item <= ITEM_END; ++item) |
5286 { | |
5287 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) | |
5288 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5289 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
|
5290 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
|
5291 SYN_ITEMS(curwin->w_s)[idx].sp_type = |
7 | 5292 (item == ITEM_START) ? SPTYPE_START : |
5293 (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
|
5294 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
|
5295 SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; |
2743 | 5296 SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = |
5297 current_syn_inc_tag; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5298 SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = |
7 | 5299 ppp->pp_matchgroup_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5300 #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
|
5301 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
|
5302 #endif |
7 | 5303 if (item == ITEM_START) |
5304 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5305 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = |
154 | 5306 syn_opt_arg.cont_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5307 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5308 syn_opt_arg.cont_in_list; |
5309 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
|
5310 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5311 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = |
154 | 5312 syn_opt_arg.next_list; |
7 | 5313 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5314 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5315 ++idx; |
5316 #ifdef FEAT_FOLDING | |
154 | 5317 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
|
5318 ++curwin->w_s->b_syn_folditems; |
7 | 5319 #endif |
5320 } | |
5321 } | |
5322 | |
745 | 5323 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5324 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5325 success = TRUE; /* don't free the progs and patterns now */ |
5326 } | |
5327 } | |
5328 | |
5329 /* | |
5330 * Free the allocated memory. | |
5331 */ | |
5332 for (item = ITEM_START; item <= ITEM_END; ++item) | |
5333 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) | |
5334 { | |
5335 if (!success) | |
5336 { | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5337 vim_regfree(ppp->pp_synp->sp_prog); |
7 | 5338 vim_free(ppp->pp_synp->sp_pattern); |
5339 } | |
5340 vim_free(ppp->pp_synp); | |
5341 ppp_next = ppp->pp_next; | |
5342 vim_free(ppp); | |
5343 } | |
5344 | |
5345 if (!success) | |
5346 { | |
154 | 5347 vim_free(syn_opt_arg.cont_list); |
5348 vim_free(syn_opt_arg.cont_in_list); | |
5349 vim_free(syn_opt_arg.next_list); | |
7 | 5350 if (not_enough) |
5351 EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); | |
5352 else if (illegal || rest == NULL) | |
5353 EMSG2(_(e_invarg2), arg); | |
5354 } | |
5355 } | |
5356 | |
5357 /* | |
5358 * A simple syntax group ID comparison function suitable for use in qsort() | |
5359 */ | |
5360 static int | |
5361 #ifdef __BORLANDC__ | |
5362 _RTLENTRYF | |
5363 #endif | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5364 syn_compare_stub(const void *v1, const void *v2) |
7 | 5365 { |
5366 const short *s1 = v1; | |
5367 const short *s2 = v2; | |
5368 | |
5369 return (*s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0); | |
5370 } | |
5371 | |
5372 /* | |
5373 * Combines lists of syntax clusters. | |
5374 * *clstr1 and *clstr2 must both be allocated memory; they will be consumed. | |
5375 */ | |
5376 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5377 syn_combine_list(short **clstr1, short **clstr2, int list_op) |
7 | 5378 { |
5379 int count1 = 0; | |
5380 int count2 = 0; | |
5381 short *g1; | |
5382 short *g2; | |
5383 short *clstr = NULL; | |
5384 int count; | |
5385 int round; | |
5386 | |
5387 /* | |
5388 * Handle degenerate cases. | |
5389 */ | |
5390 if (*clstr2 == NULL) | |
5391 return; | |
5392 if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) | |
5393 { | |
5394 if (list_op == CLUSTER_REPLACE) | |
5395 vim_free(*clstr1); | |
5396 if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) | |
5397 *clstr1 = *clstr2; | |
5398 else | |
5399 vim_free(*clstr2); | |
5400 return; | |
5401 } | |
5402 | |
5403 for (g1 = *clstr1; *g1; g1++) | |
5404 ++count1; | |
5405 for (g2 = *clstr2; *g2; g2++) | |
5406 ++count2; | |
5407 | |
5408 /* | |
5409 * For speed purposes, sort both lists. | |
5410 */ | |
5411 qsort(*clstr1, (size_t)count1, sizeof(short), syn_compare_stub); | |
5412 qsort(*clstr2, (size_t)count2, sizeof(short), syn_compare_stub); | |
5413 | |
5414 /* | |
5415 * We proceed in two passes; in round 1, we count the elements to place | |
5416 * in the new list, and in round 2, we allocate and populate the new | |
5417 * list. For speed, we use a mergesort-like method, adding the smaller | |
5418 * of the current elements in each list to the new list. | |
5419 */ | |
5420 for (round = 1; round <= 2; round++) | |
5421 { | |
5422 g1 = *clstr1; | |
5423 g2 = *clstr2; | |
5424 count = 0; | |
5425 | |
5426 /* | |
5427 * First, loop through the lists until one of them is empty. | |
5428 */ | |
5429 while (*g1 && *g2) | |
5430 { | |
5431 /* | |
5432 * We always want to add from the first list. | |
5433 */ | |
5434 if (*g1 < *g2) | |
5435 { | |
5436 if (round == 2) | |
5437 clstr[count] = *g1; | |
5438 count++; | |
5439 g1++; | |
5440 continue; | |
5441 } | |
5442 /* | |
5443 * We only want to add from the second list if we're adding the | |
5444 * lists. | |
5445 */ | |
5446 if (list_op == CLUSTER_ADD) | |
5447 { | |
5448 if (round == 2) | |
5449 clstr[count] = *g2; | |
5450 count++; | |
5451 } | |
5452 if (*g1 == *g2) | |
5453 g1++; | |
5454 g2++; | |
5455 } | |
5456 | |
5457 /* | |
5458 * Now add the leftovers from whichever list didn't get finished | |
5459 * first. As before, we only want to add from the second list if | |
5460 * we're adding the lists. | |
5461 */ | |
5462 for (; *g1; g1++, count++) | |
5463 if (round == 2) | |
5464 clstr[count] = *g1; | |
5465 if (list_op == CLUSTER_ADD) | |
5466 for (; *g2; g2++, count++) | |
5467 if (round == 2) | |
5468 clstr[count] = *g2; | |
5469 | |
5470 if (round == 1) | |
5471 { | |
5472 /* | |
5473 * If the group ended up empty, we don't need to allocate any | |
5474 * space for it. | |
5475 */ | |
5476 if (count == 0) | |
5477 { | |
5478 clstr = NULL; | |
5479 break; | |
5480 } | |
5481 clstr = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
5482 if (clstr == NULL) | |
5483 break; | |
5484 clstr[count] = 0; | |
5485 } | |
5486 } | |
5487 | |
5488 /* | |
5489 * Finally, put the new list in place. | |
5490 */ | |
5491 vim_free(*clstr1); | |
5492 vim_free(*clstr2); | |
5493 *clstr1 = clstr; | |
5494 } | |
5495 | |
5496 /* | |
5497 * Lookup a syntax cluster name and return it's ID. | |
5498 * If it is not found, 0 is returned. | |
5499 */ | |
5500 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5501 syn_scl_name2id(char_u *name) |
7 | 5502 { |
5503 int i; | |
5504 char_u *name_u; | |
5505 | |
5506 /* Avoid using stricmp() too much, it's slow on some systems */ | |
5507 name_u = vim_strsave_up(name); | |
5508 if (name_u == NULL) | |
5509 return 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5510 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
|
5511 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
|
5512 && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) |
7 | 5513 break; |
5514 vim_free(name_u); | |
5515 return (i < 0 ? 0 : i + SYNID_CLUSTER); | |
5516 } | |
5517 | |
5518 /* | |
5519 * Like syn_scl_name2id(), but take a pointer + length argument. | |
5520 */ | |
5521 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5522 syn_scl_namen2id(char_u *linep, int len) |
7 | 5523 { |
5524 char_u *name; | |
5525 int id = 0; | |
5526 | |
5527 name = vim_strnsave(linep, len); | |
5528 if (name != NULL) | |
5529 { | |
5530 id = syn_scl_name2id(name); | |
5531 vim_free(name); | |
5532 } | |
5533 return id; | |
5534 } | |
5535 | |
5536 /* | |
5537 * Find syntax cluster name in the table and return it's ID. | |
5538 * The argument is a pointer to the name and the length of the name. | |
5539 * If it doesn't exist yet, a new entry is created. | |
5540 * Return 0 for failure. | |
5541 */ | |
5542 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5543 syn_check_cluster(char_u *pp, int len) |
7 | 5544 { |
5545 int id; | |
5546 char_u *name; | |
5547 | |
5548 name = vim_strnsave(pp, len); | |
5549 if (name == NULL) | |
5550 return 0; | |
5551 | |
5552 id = syn_scl_name2id(name); | |
5553 if (id == 0) /* doesn't exist yet */ | |
5554 id = syn_add_cluster(name); | |
5555 else | |
5556 vim_free(name); | |
5557 return id; | |
5558 } | |
5559 | |
5560 /* | |
5561 * Add new syntax cluster and return it's ID. | |
5562 * "name" must be an allocated string, it will be consumed. | |
5563 * Return 0 for failure. | |
5564 */ | |
5565 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5566 syn_add_cluster(char_u *name) |
221 | 5567 { |
5568 int len; | |
7 | 5569 |
5570 /* | |
5571 * First call for this growarray: init growing array. | |
5572 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5573 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
|
5574 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5575 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
|
5576 curwin->w_s->b_syn_clusters.ga_growsize = 10; |
7 | 5577 } |
5578 | |
2743 | 5579 len = curwin->w_s->b_syn_clusters.ga_len; |
5580 if (len >= MAX_CLUSTER_ID) | |
5581 { | |
5582 EMSG((char_u *)_("E848: Too many syntax clusters")); | |
5583 vim_free(name); | |
5584 return 0; | |
5585 } | |
5586 | |
7 | 5587 /* |
5588 * Make room for at least one other cluster entry. | |
5589 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5590 if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) |
7 | 5591 { |
5592 vim_free(name); | |
5593 return 0; | |
5594 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5595 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5596 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
|
5597 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
|
5598 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
|
5599 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
|
5600 ++curwin->w_s->b_syn_clusters.ga_len; |
7 | 5601 |
221 | 5602 if (STRICMP(name, "Spell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5603 curwin->w_s->b_spell_cluster_id = len + SYNID_CLUSTER; |
227 | 5604 if (STRICMP(name, "NoSpell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5605 curwin->w_s->b_nospell_cluster_id = len + SYNID_CLUSTER; |
221 | 5606 |
7 | 5607 return len + SYNID_CLUSTER; |
5608 } | |
5609 | |
5610 /* | |
5611 * Handle ":syntax cluster {cluster-name} [contains={groupname},..] | |
5612 * [add={groupname},..] [remove={groupname},..]". | |
5613 */ | |
5614 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5615 syn_cmd_cluster(exarg_T *eap, int syncing UNUSED) |
7 | 5616 { |
5617 char_u *arg = eap->arg; | |
5618 char_u *group_name_end; | |
5619 char_u *rest; | |
5620 int scl_id; | |
5621 short *clstr_list; | |
5622 int got_clstr = FALSE; | |
5623 int opt_len; | |
5624 int list_op; | |
5625 | |
5626 eap->nextcmd = find_nextcmd(arg); | |
5627 if (eap->skip) | |
5628 return; | |
5629 | |
5630 rest = get_group_name(arg, &group_name_end); | |
5631 | |
5632 if (rest != NULL) | |
5633 { | |
2743 | 5634 scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); |
5635 if (scl_id == 0) | |
5636 return; | |
5637 scl_id -= SYNID_CLUSTER; | |
7 | 5638 |
5639 for (;;) | |
5640 { | |
5641 if (STRNICMP(rest, "add", 3) == 0 | |
5642 && (vim_iswhite(rest[3]) || rest[3] == '=')) | |
5643 { | |
5644 opt_len = 3; | |
5645 list_op = CLUSTER_ADD; | |
5646 } | |
5647 else if (STRNICMP(rest, "remove", 6) == 0 | |
5648 && (vim_iswhite(rest[6]) || rest[6] == '=')) | |
5649 { | |
5650 opt_len = 6; | |
5651 list_op = CLUSTER_SUBTRACT; | |
5652 } | |
5653 else if (STRNICMP(rest, "contains", 8) == 0 | |
5654 && (vim_iswhite(rest[8]) || rest[8] == '=')) | |
5655 { | |
5656 opt_len = 8; | |
5657 list_op = CLUSTER_REPLACE; | |
5658 } | |
5659 else | |
5660 break; | |
5661 | |
5662 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
|
5663 if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) |
7 | 5664 { |
5665 EMSG2(_(e_invarg2), rest); | |
5666 break; | |
5667 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5668 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
|
5669 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, |
7 | 5670 &clstr_list, list_op); |
5671 got_clstr = TRUE; | |
5672 } | |
5673 | |
5674 if (got_clstr) | |
5675 { | |
745 | 5676 redraw_curbuf_later(SOME_VALID); |
2743 | 5677 syn_stack_free_all(curwin->w_s); /* Need to recompute all. */ |
7 | 5678 } |
5679 } | |
5680 | |
5681 if (!got_clstr) | |
5682 EMSG(_("E400: No cluster specified")); | |
5683 if (rest == NULL || !ends_excmd(*rest)) | |
5684 EMSG2(_(e_invarg2), arg); | |
5685 } | |
5686 | |
5687 /* | |
5688 * On first call for current buffer: Init growing array. | |
5689 */ | |
5690 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5691 init_syn_patterns(void) |
7 | 5692 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5693 curwin->w_s->b_syn_patterns.ga_itemsize = sizeof(synpat_T); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5694 curwin->w_s->b_syn_patterns.ga_growsize = 10; |
7 | 5695 } |
5696 | |
5697 /* | |
5698 * Get one pattern for a ":syntax match" or ":syntax region" command. | |
5699 * Stores the pattern and program in a synpat_T. | |
5700 * Returns a pointer to the next argument, or NULL in case of an error. | |
5701 */ | |
5702 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5703 get_syn_pattern(char_u *arg, synpat_T *ci) |
7 | 5704 { |
5705 char_u *end; | |
5706 int *p; | |
5707 int idx; | |
5708 char_u *cpo_save; | |
5709 | |
5710 /* need at least three chars */ | |
6993 | 5711 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) |
7 | 5712 return NULL; |
5713 | |
5714 end = skip_regexp(arg + 1, *arg, TRUE, NULL); | |
5715 if (*end != *arg) /* end delimiter not found */ | |
5716 { | |
5717 EMSG2(_("E401: Pattern delimiter not found: %s"), arg); | |
5718 return NULL; | |
5719 } | |
5720 /* store the pattern and compiled regexp program */ | |
5721 if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL) | |
5722 return NULL; | |
5723 | |
5724 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5725 cpo_save = p_cpo; | |
5726 p_cpo = (char_u *)""; | |
5727 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); | |
5728 p_cpo = cpo_save; | |
5729 | |
5730 if (ci->sp_prog == NULL) | |
5731 return NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5732 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
|
5733 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5734 syn_clear_time(&ci->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5735 #endif |
7 | 5736 |
5737 /* | |
5738 * Check for a match, highlight or region offset. | |
5739 */ | |
5740 ++end; | |
5741 do | |
5742 { | |
5743 for (idx = SPO_COUNT; --idx >= 0; ) | |
5744 if (STRNCMP(end, spo_name_tab[idx], 3) == 0) | |
5745 break; | |
5746 if (idx >= 0) | |
5747 { | |
5748 p = &(ci->sp_offsets[idx]); | |
5749 if (idx != SPO_LC_OFF) | |
5750 switch (end[3]) | |
5751 { | |
5752 case 's': break; | |
5753 case 'b': break; | |
5754 case 'e': idx += SPO_COUNT; break; | |
5755 default: idx = -1; break; | |
5756 } | |
5757 if (idx >= 0) | |
5758 { | |
5759 ci->sp_off_flags |= (1 << idx); | |
5760 if (idx == SPO_LC_OFF) /* lc=99 */ | |
5761 { | |
5762 end += 3; | |
5763 *p = getdigits(&end); | |
5764 | |
5765 /* "lc=" offset automatically sets "ms=" offset */ | |
5766 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) | |
5767 { | |
5768 ci->sp_off_flags |= (1 << SPO_MS_OFF); | |
5769 ci->sp_offsets[SPO_MS_OFF] = *p; | |
5770 } | |
5771 } | |
5772 else /* yy=x+99 */ | |
5773 { | |
5774 end += 4; | |
5775 if (*end == '+') | |
5776 { | |
5777 ++end; | |
5778 *p = getdigits(&end); /* positive offset */ | |
5779 } | |
5780 else if (*end == '-') | |
5781 { | |
5782 ++end; | |
5783 *p = -getdigits(&end); /* negative offset */ | |
5784 } | |
5785 } | |
5786 if (*end != ',') | |
5787 break; | |
5788 ++end; | |
5789 } | |
5790 } | |
5791 } while (idx >= 0); | |
5792 | |
5793 if (!ends_excmd(*end) && !vim_iswhite(*end)) | |
5794 { | |
5795 EMSG2(_("E402: Garbage after pattern: %s"), arg); | |
5796 return NULL; | |
5797 } | |
5798 return skipwhite(end); | |
5799 } | |
5800 | |
5801 /* | |
5802 * Handle ":syntax sync .." command. | |
5803 */ | |
5804 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5805 syn_cmd_sync(exarg_T *eap, int syncing UNUSED) |
7 | 5806 { |
5807 char_u *arg_start = eap->arg; | |
5808 char_u *arg_end; | |
5809 char_u *key = NULL; | |
5810 char_u *next_arg; | |
5811 int illegal = FALSE; | |
5812 int finished = FALSE; | |
5813 long n; | |
5814 char_u *cpo_save; | |
5815 | |
5816 if (ends_excmd(*arg_start)) | |
5817 { | |
5818 syn_cmd_list(eap, TRUE); | |
5819 return; | |
5820 } | |
5821 | |
5822 while (!ends_excmd(*arg_start)) | |
5823 { | |
5824 arg_end = skiptowhite(arg_start); | |
5825 next_arg = skipwhite(arg_end); | |
5826 vim_free(key); | |
5827 key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); | |
5828 if (STRCMP(key, "CCOMMENT") == 0) | |
5829 { | |
5830 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5831 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; |
7 | 5832 if (!ends_excmd(*next_arg)) |
5833 { | |
5834 arg_end = skiptowhite(next_arg); | |
5835 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5836 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, |
7 | 5837 (int)(arg_end - next_arg)); |
5838 next_arg = skipwhite(arg_end); | |
5839 } | |
5840 else if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5841 curwin->w_s->b_syn_sync_id = syn_name2id((char_u *)"Comment"); |
7 | 5842 } |
5843 else if ( STRNCMP(key, "LINES", 5) == 0 | |
5844 || STRNCMP(key, "MINLINES", 8) == 0 | |
5845 || STRNCMP(key, "MAXLINES", 8) == 0 | |
5846 || STRNCMP(key, "LINEBREAKS", 10) == 0) | |
5847 { | |
5848 if (key[4] == 'S') | |
5849 arg_end = key + 6; | |
5850 else if (key[0] == 'L') | |
5851 arg_end = key + 11; | |
5852 else | |
5853 arg_end = key + 9; | |
5854 if (arg_end[-1] != '=' || !VIM_ISDIGIT(*arg_end)) | |
5855 { | |
5856 illegal = TRUE; | |
5857 break; | |
5858 } | |
5859 n = getdigits(&arg_end); | |
5860 if (!eap->skip) | |
5861 { | |
5862 if (key[4] == 'B') | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5863 curwin->w_s->b_syn_sync_linebreaks = n; |
7 | 5864 else if (key[1] == 'A') |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5865 curwin->w_s->b_syn_sync_maxlines = n; |
7 | 5866 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5867 curwin->w_s->b_syn_sync_minlines = n; |
7 | 5868 } |
5869 } | |
5870 else if (STRCMP(key, "FROMSTART") == 0) | |
5871 { | |
5872 if (!eap->skip) | |
5873 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5874 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
|
5875 curwin->w_s->b_syn_sync_maxlines = 0; |
7 | 5876 } |
5877 } | |
5878 else if (STRCMP(key, "LINECONT") == 0) | |
5879 { | |
7504
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5880 if (*next_arg == NUL) /* missing pattern */ |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5881 { |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5882 illegal = TRUE; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5883 break; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5884 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5885 if (curwin->w_s->b_syn_linecont_pat != NULL) |
7 | 5886 { |
5887 EMSG(_("E403: syntax sync: line continuations pattern specified twice")); | |
5888 finished = TRUE; | |
5889 break; | |
5890 } | |
5891 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE, NULL); | |
5892 if (*arg_end != *next_arg) /* end delimiter not found */ | |
5893 { | |
5894 illegal = TRUE; | |
5895 break; | |
5896 } | |
5897 | |
5898 if (!eap->skip) | |
5899 { | |
5900 /* 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
|
5901 if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1, |
7 | 5902 (int)(arg_end - next_arg - 1))) == NULL) |
5903 { | |
5904 finished = TRUE; | |
5905 break; | |
5906 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5907 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; |
7 | 5908 |
5909 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5910 cpo_save = p_cpo; | |
5911 p_cpo = (char_u *)""; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5912 curwin->w_s->b_syn_linecont_prog = |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5913 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); |
7 | 5914 p_cpo = cpo_save; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5915 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5916 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
|
5917 #endif |
7 | 5918 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5919 if (curwin->w_s->b_syn_linecont_prog == NULL) |
7 | 5920 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5921 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
|
5922 curwin->w_s->b_syn_linecont_pat = NULL; |
7 | 5923 finished = TRUE; |
5924 break; | |
5925 } | |
5926 } | |
5927 next_arg = skipwhite(arg_end + 1); | |
5928 } | |
5929 else | |
5930 { | |
5931 eap->arg = next_arg; | |
5932 if (STRCMP(key, "MATCH") == 0) | |
5933 syn_cmd_match(eap, TRUE); | |
5934 else if (STRCMP(key, "REGION") == 0) | |
5935 syn_cmd_region(eap, TRUE); | |
5936 else if (STRCMP(key, "CLEAR") == 0) | |
5937 syn_cmd_clear(eap, TRUE); | |
5938 else | |
5939 illegal = TRUE; | |
5940 finished = TRUE; | |
5941 break; | |
5942 } | |
5943 arg_start = next_arg; | |
5944 } | |
5945 vim_free(key); | |
5946 if (illegal) | |
5947 EMSG2(_("E404: Illegal arguments: %s"), arg_start); | |
5948 else if (!finished) | |
5949 { | |
5950 eap->nextcmd = check_nextcmd(arg_start); | |
745 | 5951 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5952 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5953 } |
5954 } | |
5955 | |
5956 /* | |
5957 * Convert a line of highlight group names into a list of group ID numbers. | |
5958 * "arg" should point to the "contains" or "nextgroup" keyword. | |
5959 * "arg" is advanced to after the last group name. | |
5960 * Careful: the argument is modified (NULs added). | |
5961 * returns FAIL for some error, OK for success. | |
5962 */ | |
5963 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5964 get_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5965 char_u **arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5966 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
|
5967 short **list, /* where to store the resulting list, if not |
7 | 5968 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
|
5969 int skip) |
7 | 5970 { |
5971 char_u *p = NULL; | |
5972 char_u *end; | |
5973 int round; | |
5974 int count; | |
5975 int total_count = 0; | |
5976 short *retval = NULL; | |
5977 char_u *name; | |
5978 regmatch_T regmatch; | |
5979 int id; | |
5980 int i; | |
5981 int failed = FALSE; | |
5982 | |
5983 /* | |
5984 * We parse the list twice: | |
5985 * round == 1: count the number of items, allocate the array. | |
5986 * round == 2: fill the array with the items. | |
5987 * In round 1 new groups may be added, causing the number of items to | |
5988 * grow when a regexp is used. In that case round 1 is done once again. | |
5989 */ | |
5990 for (round = 1; round <= 2; ++round) | |
5991 { | |
5992 /* | |
5993 * skip "contains" | |
5994 */ | |
5995 p = skipwhite(*arg + keylen); | |
5996 if (*p != '=') | |
5997 { | |
5998 EMSG2(_("E405: Missing equal sign: %s"), *arg); | |
5999 break; | |
6000 } | |
6001 p = skipwhite(p + 1); | |
6002 if (ends_excmd(*p)) | |
6003 { | |
6004 EMSG2(_("E406: Empty argument: %s"), *arg); | |
6005 break; | |
6006 } | |
6007 | |
6008 /* | |
6009 * parse the arguments after "contains" | |
6010 */ | |
6011 count = 0; | |
6012 while (!ends_excmd(*p)) | |
6013 { | |
6014 for (end = p; *end && !vim_iswhite(*end) && *end != ','; ++end) | |
6015 ; | |
6016 name = alloc((int)(end - p + 3)); /* leave room for "^$" */ | |
6017 if (name == NULL) | |
6018 { | |
6019 failed = TRUE; | |
6020 break; | |
6021 } | |
419 | 6022 vim_strncpy(name + 1, p, end - p); |
7 | 6023 if ( STRCMP(name + 1, "ALLBUT") == 0 |
6024 || STRCMP(name + 1, "ALL") == 0 | |
6025 || STRCMP(name + 1, "TOP") == 0 | |
6026 || STRCMP(name + 1, "CONTAINED") == 0) | |
6027 { | |
6028 if (TOUPPER_ASC(**arg) != 'C') | |
6029 { | |
6030 EMSG2(_("E407: %s not allowed here"), name + 1); | |
6031 failed = TRUE; | |
6032 vim_free(name); | |
6033 break; | |
6034 } | |
6035 if (count != 0) | |
6036 { | |
6037 EMSG2(_("E408: %s must be first in contains list"), name + 1); | |
6038 failed = TRUE; | |
6039 vim_free(name); | |
6040 break; | |
6041 } | |
6042 if (name[1] == 'A') | |
6043 id = SYNID_ALLBUT; | |
6044 else if (name[1] == 'T') | |
6045 id = SYNID_TOP; | |
6046 else | |
6047 id = SYNID_CONTAINED; | |
6048 id += current_syn_inc_tag; | |
6049 } | |
6050 else if (name[1] == '@') | |
6051 { | |
10629
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6052 if (skip) |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6053 id = -1; |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6054 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
|
6055 id = syn_check_cluster(name + 2, (int)(end - p - 1)); |
7 | 6056 } |
6057 else | |
6058 { | |
6059 /* | |
6060 * Handle full group name. | |
6061 */ | |
6062 if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) | |
6063 id = syn_check_group(name + 1, (int)(end - p)); | |
6064 else | |
6065 { | |
6066 /* | |
6067 * Handle match of regexp with group names. | |
6068 */ | |
6069 *name = '^'; | |
6070 STRCAT(name, "$"); | |
6071 regmatch.regprog = vim_regcomp(name, RE_MAGIC); | |
6072 if (regmatch.regprog == NULL) | |
6073 { | |
6074 failed = TRUE; | |
6075 vim_free(name); | |
6076 break; | |
6077 } | |
6078 | |
6079 regmatch.rm_ic = TRUE; | |
6080 id = 0; | |
6081 for (i = highlight_ga.ga_len; --i >= 0; ) | |
6082 { | |
6083 if (vim_regexec(®match, HL_TABLE()[i].sg_name, | |
6084 (colnr_T)0)) | |
6085 { | |
6086 if (round == 2) | |
6087 { | |
6088 /* Got more items than expected; can happen | |
6089 * when adding items that match: | |
6090 * "contains=a.*b,axb". | |
6091 * Go back to first round */ | |
6092 if (count >= total_count) | |
6093 { | |
6094 vim_free(retval); | |
6095 round = 1; | |
6096 } | |
6097 else | |
6098 retval[count] = i + 1; | |
6099 } | |
6100 ++count; | |
6101 id = -1; /* remember that we found one */ | |
6102 } | |
6103 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6104 vim_regfree(regmatch.regprog); |
7 | 6105 } |
6106 } | |
6107 vim_free(name); | |
6108 if (id == 0) | |
6109 { | |
6110 EMSG2(_("E409: Unknown group name: %s"), p); | |
6111 failed = TRUE; | |
6112 break; | |
6113 } | |
6114 if (id > 0) | |
6115 { | |
6116 if (round == 2) | |
6117 { | |
6118 /* Got more items than expected, go back to first round */ | |
6119 if (count >= total_count) | |
6120 { | |
6121 vim_free(retval); | |
6122 round = 1; | |
6123 } | |
6124 else | |
6125 retval[count] = id; | |
6126 } | |
6127 ++count; | |
6128 } | |
6129 p = skipwhite(end); | |
6130 if (*p != ',') | |
6131 break; | |
6132 p = skipwhite(p + 1); /* skip comma in between arguments */ | |
6133 } | |
6134 if (failed) | |
6135 break; | |
6136 if (round == 1) | |
6137 { | |
6138 retval = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
6139 if (retval == NULL) | |
6140 break; | |
6141 retval[count] = 0; /* zero means end of the list */ | |
6142 total_count = count; | |
6143 } | |
6144 } | |
6145 | |
6146 *arg = p; | |
6147 if (failed || retval == NULL) | |
6148 { | |
6149 vim_free(retval); | |
6150 return FAIL; | |
6151 } | |
6152 | |
6153 if (*list == NULL) | |
6154 *list = retval; | |
6155 else | |
6156 vim_free(retval); /* list already found, don't overwrite it */ | |
6157 | |
6158 return OK; | |
6159 } | |
6160 | |
6161 /* | |
6162 * Make a copy of an ID list. | |
6163 */ | |
6164 static short * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6165 copy_id_list(short *list) |
7 | 6166 { |
6167 int len; | |
6168 int count; | |
6169 short *retval; | |
6170 | |
6171 if (list == NULL) | |
6172 return NULL; | |
6173 | |
6174 for (count = 0; list[count]; ++count) | |
6175 ; | |
6176 len = (count + 1) * sizeof(short); | |
6177 retval = (short *)alloc((unsigned)len); | |
6178 if (retval != NULL) | |
6179 mch_memmove(retval, list, (size_t)len); | |
6180 | |
6181 return retval; | |
6182 } | |
6183 | |
6184 /* | |
6185 * Check if syntax group "ssp" is in the ID list "list" of "cur_si". | |
6186 * "cur_si" can be NULL if not checking the "containedin" list. | |
6187 * Used to check if a syntax item is in the "contains" or "nextgroup" list of | |
6188 * the current item. | |
6189 * This function is called very often, keep it fast!! | |
6190 */ | |
6191 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6192 in_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6193 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
|
6194 short *list, /* id list */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6195 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
|
6196 int contained) /* group id is contained */ |
7 | 6197 { |
6198 int retval; | |
6199 short *scl_list; | |
6200 short item; | |
6201 short id = ssp->id; | |
6202 static int depth = 0; | |
6203 int r; | |
6204 | |
4352 | 6205 /* If ssp has a "containedin" list and "cur_si" is in it, return TRUE. */ |
36 | 6206 if (cur_si != NULL && ssp->cont_in_list != NULL |
6207 && !(cur_si->si_flags & HL_MATCH)) | |
7 | 6208 { |
6209 /* Ignore transparent items without a contains argument. Double check | |
6210 * that we don't go back past the first one. */ | |
6211 while ((cur_si->si_flags & HL_TRANS_CONT) | |
6212 && cur_si > (stateitem_T *)(current_state.ga_data)) | |
6213 --cur_si; | |
6214 /* cur_si->si_idx is -1 for keywords, these never contain anything. */ | |
6215 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
|
6216 &(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
|
6217 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) |
7 | 6218 return TRUE; |
6219 } | |
6220 | |
6221 if (list == NULL) | |
6222 return FALSE; | |
6223 | |
6224 /* | |
6225 * If list is ID_LIST_ALL, we are in a transparent item that isn't | |
6226 * inside anything. Only allow not-contained groups. | |
6227 */ | |
6228 if (list == ID_LIST_ALL) | |
6229 return !contained; | |
6230 | |
6231 /* | |
6232 * If the first item is "ALLBUT", return TRUE if "id" is NOT in the | |
6233 * contains list. We also require that "id" is at the same ":syn include" | |
6234 * level as the list. | |
6235 */ | |
6236 item = *list; | |
6237 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) | |
6238 { | |
6239 if (item < SYNID_TOP) | |
6240 { | |
6241 /* ALL or ALLBUT: accept all groups in the same file */ | |
6242 if (item - SYNID_ALLBUT != ssp->inc_tag) | |
6243 return FALSE; | |
6244 } | |
6245 else if (item < SYNID_CONTAINED) | |
6246 { | |
6247 /* TOP: accept all not-contained groups in the same file */ | |
6248 if (item - SYNID_TOP != ssp->inc_tag || contained) | |
6249 return FALSE; | |
6250 } | |
6251 else | |
6252 { | |
6253 /* CONTAINED: accept all contained groups in the same file */ | |
6254 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) | |
6255 return FALSE; | |
6256 } | |
6257 item = *++list; | |
6258 retval = FALSE; | |
6259 } | |
6260 else | |
6261 retval = TRUE; | |
6262 | |
6263 /* | |
6264 * Return "retval" if id is in the contains list. | |
6265 */ | |
6266 while (item != 0) | |
6267 { | |
6268 if (item == id) | |
6269 return retval; | |
6270 if (item >= SYNID_CLUSTER) | |
6271 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6272 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; |
7 | 6273 /* restrict recursiveness to 30 to avoid an endless loop for a |
6274 * cluster that includes itself (indirectly) */ | |
6275 if (scl_list != NULL && depth < 30) | |
6276 { | |
6277 ++depth; | |
6278 r = in_id_list(NULL, scl_list, ssp, contained); | |
6279 --depth; | |
6280 if (r) | |
6281 return retval; | |
6282 } | |
6283 } | |
6284 item = *++list; | |
6285 } | |
6286 return !retval; | |
6287 } | |
6288 | |
6289 struct subcommand | |
6290 { | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6291 char *name; /* subcommand name */ |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6292 void (*func)(exarg_T *, int); /* function to call */ |
7 | 6293 }; |
6294 | |
6295 static struct subcommand subcommands[] = | |
6296 { | |
6297 {"case", syn_cmd_case}, | |
6298 {"clear", syn_cmd_clear}, | |
6299 {"cluster", syn_cmd_cluster}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6300 {"conceal", syn_cmd_conceal}, |
7 | 6301 {"enable", syn_cmd_enable}, |
6302 {"include", syn_cmd_include}, | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6303 {"iskeyword", syn_cmd_iskeyword}, |
7 | 6304 {"keyword", syn_cmd_keyword}, |
6305 {"list", syn_cmd_list}, | |
6306 {"manual", syn_cmd_manual}, | |
6307 {"match", syn_cmd_match}, | |
6308 {"on", syn_cmd_on}, | |
6309 {"off", syn_cmd_off}, | |
6310 {"region", syn_cmd_region}, | |
6311 {"reset", syn_cmd_reset}, | |
419 | 6312 {"spell", syn_cmd_spell}, |
7 | 6313 {"sync", syn_cmd_sync}, |
6314 {"", syn_cmd_list}, | |
6315 {NULL, NULL} | |
6316 }; | |
6317 | |
6318 /* | |
6319 * ":syntax". | |
6320 * This searches the subcommands[] table for the subcommand name, and calls a | |
6321 * syntax_subcommand() function to do the rest. | |
6322 */ | |
6323 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6324 ex_syntax(exarg_T *eap) |
7 | 6325 { |
6326 char_u *arg = eap->arg; | |
6327 char_u *subcmd_end; | |
6328 char_u *subcmd_name; | |
6329 int i; | |
6330 | |
6331 syn_cmdlinep = eap->cmdlinep; | |
6332 | |
6333 /* isolate subcommand name */ | |
6334 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) | |
6335 ; | |
6336 subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg)); | |
6337 if (subcmd_name != NULL) | |
6338 { | |
6339 if (eap->skip) /* skip error messages for all subcommands */ | |
6340 ++emsg_skip; | |
6341 for (i = 0; ; ++i) | |
6342 { | |
6343 if (subcommands[i].name == NULL) | |
6344 { | |
6345 EMSG2(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); | |
6346 break; | |
6347 } | |
6348 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) | |
6349 { | |
6350 eap->arg = skipwhite(subcmd_end); | |
6351 (subcommands[i].func)(eap, FALSE); | |
6352 break; | |
6353 } | |
6354 } | |
6355 vim_free(subcmd_name); | |
6356 if (eap->skip) | |
6357 --emsg_skip; | |
6358 } | |
6359 } | |
6360 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6361 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6362 ex_ownsyntax(exarg_T *eap) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6363 { |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6364 char_u *old_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6365 char_u *new_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6366 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6367 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
|
6368 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6369 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
|
6370 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
|
6371 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
|
6372 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
|
6373 #ifdef FEAT_SPELL |
6386 | 6374 /* 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
|
6375 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
|
6376 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
|
6377 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
|
6378 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
|
6379 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6380 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
|
6381 } |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6382 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6383 /* save value of b:current_syntax */ |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6384 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
|
6385 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6386 old_value = vim_strsave(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6387 |
8362
a541dd5cfd3a
commit https://github.com/vim/vim/commit/d1413d90983fc6c579ad66ba4d4611b057197f94
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
6388 #ifdef FEAT_AUTOCMD |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6389 /* 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
|
6390 * file. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6391 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
|
6392 #endif |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6393 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6394 /* 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
|
6395 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
|
6396 if (new_value != NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6397 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
|
6398 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6399 /* restore value of b:current_syntax */ |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6400 if (old_value == NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6401 do_unlet((char_u *)"b:current_syntax", TRUE); |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6402 else |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6403 { |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6404 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
|
6405 vim_free(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6406 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6407 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6408 |
7 | 6409 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6410 syntax_present(win_T *win) |
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 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
|
6413 || 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
|
6414 || 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
|
6415 || win->w_s->b_keywtab_ic.ht_used > 0); |
7 | 6416 } |
6417 | |
6418 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
6419 | |
6420 static enum | |
6421 { | |
6422 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
|
6423 EXP_CASE, /* expand ":syn case" arguments */ |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6424 EXP_SPELL, /* expand ":syn spell" arguments */ |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6425 EXP_SYNC /* expand ":syn sync" arguments */ |
7 | 6426 } expand_what; |
6427 | |
1322 | 6428 /* |
6429 * Reset include_link, include_default, include_none to 0. | |
6430 * Called when we are done expanding. | |
6431 */ | |
6432 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6433 reset_expand_highlight(void) |
1322 | 6434 { |
6435 include_link = include_default = include_none = 0; | |
6436 } | |
6437 | |
6438 /* | |
6439 * Handle command line completion for :match and :echohl command: Add "None" | |
6440 * as highlight group. | |
6441 */ | |
6442 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6443 set_context_in_echohl_cmd(expand_T *xp, char_u *arg) |
1322 | 6444 { |
6445 xp->xp_context = EXPAND_HIGHLIGHT; | |
6446 xp->xp_pattern = arg; | |
6447 include_none = 1; | |
6448 } | |
7 | 6449 |
6450 /* | |
6451 * Handle command line completion for :syntax command. | |
6452 */ | |
6453 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6454 set_context_in_syntax_cmd(expand_T *xp, char_u *arg) |
7 | 6455 { |
6456 char_u *p; | |
6457 | |
6458 /* Default: expand subcommands */ | |
6459 xp->xp_context = EXPAND_SYNTAX; | |
6460 expand_what = EXP_SUBCMD; | |
6461 xp->xp_pattern = arg; | |
1322 | 6462 include_link = 0; |
6463 include_default = 0; | |
7 | 6464 |
6465 /* (part of) subcommand already typed */ | |
6466 if (*arg != NUL) | |
6467 { | |
6468 p = skiptowhite(arg); | |
6469 if (*p != NUL) /* past first word */ | |
6470 { | |
6471 xp->xp_pattern = skipwhite(p); | |
6472 if (*skiptowhite(xp->xp_pattern) != NUL) | |
6473 xp->xp_context = EXPAND_NOTHING; | |
6474 else if (STRNICMP(arg, "case", p - arg) == 0) | |
6475 expand_what = EXP_CASE; | |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6476 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
|
6477 expand_what = EXP_SPELL; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6478 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
|
6479 expand_what = EXP_SYNC; |
7 | 6480 else if ( STRNICMP(arg, "keyword", p - arg) == 0 |
6481 || STRNICMP(arg, "region", p - arg) == 0 | |
6482 || STRNICMP(arg, "match", p - arg) == 0 | |
6483 || STRNICMP(arg, "list", p - arg) == 0) | |
6484 xp->xp_context = EXPAND_HIGHLIGHT; | |
6485 else | |
6486 xp->xp_context = EXPAND_NOTHING; | |
6487 } | |
6488 } | |
6489 } | |
6490 | |
6491 /* | |
6492 * Function given to ExpandGeneric() to obtain the list syntax names for | |
6493 * expansion. | |
6494 */ | |
6495 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6496 get_syntax_name(expand_T *xp UNUSED, int idx) |
7 | 6497 { |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6498 switch (expand_what) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6499 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6500 case EXP_SUBCMD: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6501 return (char_u *)subcommands[idx].name; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6502 case EXP_CASE: |
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 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
|
6505 return (char_u *)case_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6506 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6507 case EXP_SPELL: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6508 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6509 static char *spell_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6510 {"toplevel", "notoplevel", "default", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6511 return (char_u *)spell_args[idx]; |
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 case EXP_SYNC: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6514 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6515 static char *sync_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6516 {"ccomment", "clear", "fromstart", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6517 "linebreaks=", "linecont", "lines=", "match", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6518 "maxlines=", "minlines=", "region", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6519 return (char_u *)sync_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6520 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6521 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6522 return NULL; |
7 | 6523 } |
6524 | |
6525 #endif /* FEAT_CMDL_COMPL */ | |
6526 | |
6527 /* | |
6528 * Function called for expression evaluation: get syntax ID at file position. | |
6529 */ | |
6530 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6531 syn_get_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6532 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6533 long lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6534 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6535 int trans, /* remove transparency */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6536 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
|
6537 int keep_state) /* keep state of char at "col" */ |
7 | 6538 { |
6539 /* When the position is not after the current position and in the same | |
6540 * line of the same buffer, need to restart parsing. */ | |
499 | 6541 if (wp->w_buffer != syn_buf |
7 | 6542 || lnum != current_lnum |
253 | 6543 || col < current_col) |
499 | 6544 syntax_start(wp, lnum); |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6545 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
|
6546 && lnum == current_lnum |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6547 && col > current_col) |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6548 /* 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
|
6549 * "skip" expression in searchpair() */ |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6550 next_match_idx = -1; |
7 | 6551 |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6552 (void)get_syntax_attr(col, spellp, keep_state); |
7 | 6553 |
6554 return (trans ? current_trans_id : current_id); | |
6555 } | |
6556 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6557 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6558 /* |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6559 * 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
|
6560 * 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
|
6561 * 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
|
6562 * 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
|
6563 */ |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6564 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6565 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
|
6566 { |
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
|
6567 *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
|
6568 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
|
6569 } |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6570 |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6571 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6572 * Return conceal substitution character |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6573 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6574 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6575 syn_get_sub_char(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6576 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6577 return current_sub_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6578 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6579 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6580 |
1500 | 6581 #if defined(FEAT_EVAL) || defined(PROTO) |
6582 /* | |
6583 * Return the syntax ID at position "i" in the current stack. | |
6584 * The caller must have called syn_get_id() before to fill the stack. | |
6585 * Returns -1 when "i" is out of range. | |
6586 */ | |
6587 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6588 syn_get_stack_item(int i) |
1500 | 6589 { |
1504 | 6590 if (i >= current_state.ga_len) |
6591 { | |
6592 /* Need to invalidate the state, because we didn't properly finish it | |
6593 * for the last character, "keep_state" was TRUE. */ | |
6594 invalidate_current_state(); | |
6595 current_col = MAXCOL; | |
1500 | 6596 return -1; |
1504 | 6597 } |
1500 | 6598 return CUR_STATE(i).si_id; |
6599 } | |
6600 #endif | |
6601 | |
7 | 6602 #if defined(FEAT_FOLDING) || defined(PROTO) |
6603 /* | |
6604 * Function called to get folding level for line "lnum" in window "wp". | |
6605 */ | |
6606 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6607 syn_get_foldlevel(win_T *wp, long lnum) |
7 | 6608 { |
6609 int level = 0; | |
6610 int i; | |
6611 | |
6612 /* 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
|
6613 if (wp->w_s->b_syn_folditems != 0) |
7 | 6614 { |
6615 syntax_start(wp, lnum); | |
6616 | |
6617 for (i = 0; i < current_state.ga_len; ++i) | |
6618 if (CUR_STATE(i).si_flags & HL_FOLD) | |
6619 ++level; | |
6620 } | |
6621 if (level > wp->w_p_fdn) | |
1028 | 6622 { |
7 | 6623 level = wp->w_p_fdn; |
1028 | 6624 if (level < 0) |
6625 level = 0; | |
6626 } | |
7 | 6627 return level; |
6628 } | |
6629 #endif | |
6630 | |
6567 | 6631 #if defined(FEAT_PROFILE) || defined(PROTO) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6632 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6633 * ":syntime". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6634 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6635 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6636 ex_syntime(exarg_T *eap) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6637 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6638 if (STRCMP(eap->arg, "on") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6639 syn_time_on = TRUE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6640 else if (STRCMP(eap->arg, "off") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6641 syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6642 else if (STRCMP(eap->arg, "clear") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6643 syntime_clear(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6644 else if (STRCMP(eap->arg, "report") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6645 syntime_report(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6646 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6647 EMSG2(_(e_invarg2), eap->arg); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6648 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6649 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6650 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6651 syn_clear_time(syn_time_T *st) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6652 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6653 profile_zero(&st->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6654 profile_zero(&st->slowest); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6655 st->count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6656 st->match = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6657 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6658 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6659 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6660 * Clear the syntax timing for the current buffer. |
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 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6663 syntime_clear(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6664 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6665 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6666 synpat_T *spp; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6667 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6668 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6669 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6670 MSG(_(msg_no_items)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6671 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6672 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6673 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
|
6674 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6675 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6676 syn_clear_time(&spp->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6677 } |
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 |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6680 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6681 /* |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6682 * 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
|
6683 * ":syntime {on,off,clear,report}" command. |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6684 */ |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6685 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6686 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
|
6687 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6688 switch (idx) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6689 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6690 case 0: return (char_u *)"on"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6691 case 1: return (char_u *)"off"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6692 case 2: return (char_u *)"clear"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6693 case 3: return (char_u *)"report"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6694 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6695 return NULL; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6696 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6697 #endif |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6698 |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6699 typedef struct |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6700 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6701 proftime_T total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6702 int count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6703 int match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6704 proftime_T slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6705 proftime_T average; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6706 int id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6707 char_u *pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6708 } time_entry_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6709 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6710 static int |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6711 #ifdef __BORLANDC__ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6712 _RTLENTRYF |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6713 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6714 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
|
6715 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6716 const time_entry_T *s1 = v1; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6717 const time_entry_T *s2 = v2; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6718 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6719 return profile_cmp(&s1->total, &s2->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6720 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6721 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6722 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6723 * Clear the syntax timing for the current buffer. |
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 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6726 syntime_report(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6727 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6728 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6729 synpat_T *spp; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6730 # ifdef FEAT_FLOAT |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6731 proftime_T tm; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6732 # endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6733 int len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6734 proftime_T total_total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6735 int total_count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6736 garray_T ga; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6737 time_entry_T *p; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6738 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6739 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6740 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6741 MSG(_(msg_no_items)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6742 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6743 } |
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 ga_init2(&ga, sizeof(time_entry_T), 50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6746 profile_zero(&total_total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6747 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
|
6748 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6749 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6750 if (spp->sp_time.count > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6751 { |
7009 | 6752 (void)ga_grow(&ga, 1); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6753 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
|
6754 p->total = spp->sp_time.total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6755 profile_add(&total_total, &spp->sp_time.total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6756 p->count = spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6757 p->match = spp->sp_time.match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6758 total_count += spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6759 p->slowest = spp->sp_time.slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6760 # ifdef FEAT_FLOAT |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6761 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
|
6762 p->average = tm; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6763 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6764 p->id = spp->sp_syn.id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6765 p->pattern = spp->sp_pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6766 ++ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6767 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6768 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6769 |
10530
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6770 /* 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
|
6771 * pointer to qsort(). */ |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6772 if (ga.ga_len > 1) |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6773 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
|
6774 syn_compare_syntime); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6775 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6776 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
|
6777 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6778 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
|
6779 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6780 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6781 p = ((time_entry_T *)ga.ga_data) + idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6782 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6783 MSG_PUTS(profile_msg(&p->total)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6784 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
|
6785 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6786 msg_outnum(p->count); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6787 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6788 msg_advance(20); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6789 msg_outnum(p->match); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6790 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6791 msg_advance(26); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6792 MSG_PUTS(profile_msg(&p->slowest)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6793 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6794 msg_advance(38); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6795 # ifdef FEAT_FLOAT |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6796 MSG_PUTS(profile_msg(&p->average)); |
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 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6799 msg_advance(50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6800 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
|
6801 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6802 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6803 msg_advance(69); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6804 if (Columns < 80) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6805 len = 20; /* will wrap anyway */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6806 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6807 len = Columns - 70; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6808 if (len > (int)STRLEN(p->pattern)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6809 len = (int)STRLEN(p->pattern); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6810 msg_outtrans_len(p->pattern, len); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6811 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6812 } |
4791
65cef998f860
updated for version 7.3.1142
Bram Moolenaar <bram@vim.org>
parents:
4776
diff
changeset
|
6813 ga_clear(&ga); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6814 if (!got_int) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6815 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6816 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6817 MSG_PUTS(profile_msg(&total_total)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6818 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6819 msg_outnum(total_count); |
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 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6822 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6823 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6824 |
7 | 6825 #endif /* FEAT_SYN_HL */ |
6826 | |
6827 /************************************** | |
6828 * Highlighting stuff * | |
6829 **************************************/ | |
6830 | |
6831 /* | |
6832 * The default highlight groups. These are compiled-in for fast startup and | |
6833 * they still work when the runtime files can't be found. | |
6834 * When making changes here, also change runtime/colors/default.vim! | |
806 | 6835 * The #ifdefs are needed to reduce the amount of static data. Helps to make |
6836 * the 16 bit DOS (museum) version compile. | |
7 | 6837 */ |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
6838 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
809 | 6839 # define CENT(a, b) b |
6840 #else | |
6841 # define CENT(a, b) a | |
6842 #endif | |
7 | 6843 static char *(highlight_init_both[]) = |
6844 { | |
809 | 6845 CENT("ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", |
6846 "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), | |
6847 CENT("IncSearch term=reverse cterm=reverse", | |
6848 "IncSearch term=reverse cterm=reverse gui=reverse"), | |
6849 CENT("ModeMsg term=bold cterm=bold", | |
6850 "ModeMsg term=bold cterm=bold gui=bold"), | |
6851 CENT("NonText term=bold ctermfg=Blue", | |
6852 "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), | |
6853 CENT("StatusLine term=reverse,bold cterm=reverse,bold", | |
6854 "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), | |
6855 CENT("StatusLineNC term=reverse cterm=reverse", | |
6856 "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
|
6857 "default link EndOfBuffer NonText", |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
6858 #ifdef FEAT_WINDOWS |
809 | 6859 CENT("VertSplit term=reverse cterm=reverse", |
6860 "VertSplit term=reverse cterm=reverse gui=reverse"), | |
806 | 6861 #endif |
6862 #ifdef FEAT_CLIPBOARD | |
809 | 6863 CENT("VisualNOS term=underline,bold cterm=underline,bold", |
6864 "VisualNOS term=underline,bold cterm=underline,bold gui=underline,bold"), | |
806 | 6865 #endif |
6866 #ifdef FEAT_DIFF | |
809 | 6867 CENT("DiffText term=reverse cterm=bold ctermbg=Red", |
6868 "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), | |
806 | 6869 #endif |
6870 #ifdef FEAT_INS_EXPAND | |
809 | 6871 CENT("PmenuSbar ctermbg=Grey", |
6872 "PmenuSbar ctermbg=Grey guibg=Grey"), | |
806 | 6873 #endif |
6874 #ifdef FEAT_WINDOWS | |
809 | 6875 CENT("TabLineSel term=bold cterm=bold", |
6876 "TabLineSel term=bold cterm=bold gui=bold"), | |
6877 CENT("TabLineFill term=reverse cterm=reverse", | |
6878 "TabLineFill term=reverse cterm=reverse gui=reverse"), | |
806 | 6879 #endif |
7 | 6880 #ifdef FEAT_GUI |
6881 "Cursor guibg=fg guifg=bg", | |
809 | 6882 "lCursor guibg=fg guifg=bg", /* should be different, but what? */ |
7 | 6883 #endif |
6884 NULL | |
6885 }; | |
6886 | |
6887 static char *(highlight_init_light[]) = | |
6888 { | |
809 | 6889 CENT("Directory term=bold ctermfg=DarkBlue", |
6890 "Directory term=bold ctermfg=DarkBlue guifg=Blue"), | |
6891 CENT("LineNr term=underline ctermfg=Brown", | |
6892 "LineNr term=underline ctermfg=Brown guifg=Brown"), | |
3427 | 6893 CENT("CursorLineNr term=bold ctermfg=Brown", |
6894 "CursorLineNr term=bold ctermfg=Brown gui=bold guifg=Brown"), | |
809 | 6895 CENT("MoreMsg term=bold ctermfg=DarkGreen", |
6896 "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6897 CENT("Question term=standout ctermfg=DarkGreen", | |
6898 "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6899 CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", | |
6900 "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), | |
806 | 6901 #ifdef FEAT_SPELL |
809 | 6902 CENT("SpellBad term=reverse ctermbg=LightRed", |
6903 "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), | |
6904 CENT("SpellCap term=reverse ctermbg=LightBlue", | |
6905 "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), | |
6906 CENT("SpellRare term=reverse ctermbg=LightMagenta", | |
6907 "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), | |
6908 CENT("SpellLocal term=underline ctermbg=Cyan", | |
6909 "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), | |
806 | 6910 #endif |
6911 #ifdef FEAT_INS_EXPAND | |
3419 | 6912 CENT("PmenuThumb ctermbg=Black", |
6913 "PmenuThumb ctermbg=Black guibg=Black"), | |
6914 CENT("Pmenu ctermbg=LightMagenta ctermfg=Black", | |
6915 "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta"), | |
6916 CENT("PmenuSel ctermbg=LightGrey ctermfg=Black", | |
6917 "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey"), | |
806 | 6918 #endif |
809 | 6919 CENT("SpecialKey term=bold ctermfg=DarkBlue", |
6920 "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), | |
6921 CENT("Title term=bold ctermfg=DarkMagenta", | |
6922 "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), | |
6923 CENT("WarningMsg term=standout ctermfg=DarkRed", | |
6924 "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), | |
806 | 6925 #ifdef FEAT_WILDMENU |
809 | 6926 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
6927 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 6928 #endif |
6929 #ifdef FEAT_FOLDING | |
809 | 6930 CENT("Folded term=standout ctermbg=Grey ctermfg=DarkBlue", |
6931 "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), | |
6932 CENT("FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", | |
6933 "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6934 #endif |
6935 #ifdef FEAT_SIGNS | |
809 | 6936 CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", |
6937 "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6938 #endif |
836 | 6939 CENT("Visual term=reverse", |
6940 "Visual term=reverse guibg=LightGrey"), | |
806 | 6941 #ifdef FEAT_DIFF |
809 | 6942 CENT("DiffAdd term=bold ctermbg=LightBlue", |
6943 "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), | |
6944 CENT("DiffChange term=bold ctermbg=LightMagenta", | |
6945 "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), | |
6946 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", | |
6947 "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), | |
806 | 6948 #endif |
6949 #ifdef FEAT_WINDOWS | |
809 | 6950 CENT("TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", |
6951 "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), | |
806 | 6952 #endif |
6953 #ifdef FEAT_SYN_HL | |
809 | 6954 CENT("CursorColumn term=reverse ctermbg=LightGrey", |
818 | 6955 "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), |
809 | 6956 CENT("CursorLine term=underline cterm=underline", |
818 | 6957 "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
|
6958 CENT("ColorColumn term=reverse ctermbg=LightRed", |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
6959 "ColorColumn term=reverse ctermbg=LightRed guibg=LightRed"), |
806 | 6960 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6961 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6962 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6963 "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
|
6964 #endif |
834 | 6965 #ifdef FEAT_AUTOCMD |
6966 CENT("MatchParen term=reverse ctermbg=Cyan", | |
6967 "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), | |
6968 #endif | |
806 | 6969 #ifdef FEAT_GUI |
7 | 6970 "Normal gui=NONE", |
806 | 6971 #endif |
7 | 6972 NULL |
6973 }; | |
6974 | |
6975 static char *(highlight_init_dark[]) = | |
6976 { | |
809 | 6977 CENT("Directory term=bold ctermfg=LightCyan", |
6978 "Directory term=bold ctermfg=LightCyan guifg=Cyan"), | |
6979 CENT("LineNr term=underline ctermfg=Yellow", | |
6980 "LineNr term=underline ctermfg=Yellow guifg=Yellow"), | |
3427 | 6981 CENT("CursorLineNr term=bold ctermfg=Yellow", |
6982 "CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow"), | |
809 | 6983 CENT("MoreMsg term=bold ctermfg=LightGreen", |
6984 "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), | |
6985 CENT("Question term=standout ctermfg=LightGreen", | |
6986 "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), | |
6987 CENT("Search term=reverse ctermbg=Yellow ctermfg=Black", | |
6988 "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
6989 CENT("SpecialKey term=bold ctermfg=LightBlue", | |
6990 "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), | |
806 | 6991 #ifdef FEAT_SPELL |
809 | 6992 CENT("SpellBad term=reverse ctermbg=Red", |
6993 "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), | |
6994 CENT("SpellCap term=reverse ctermbg=Blue", | |
6995 "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), | |
6996 CENT("SpellRare term=reverse ctermbg=Magenta", | |
6997 "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), | |
6998 CENT("SpellLocal term=underline ctermbg=Cyan", | |
6999 "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), | |
806 | 7000 #endif |
7001 #ifdef FEAT_INS_EXPAND | |
3419 | 7002 CENT("PmenuThumb ctermbg=White", |
7003 "PmenuThumb ctermbg=White guibg=White"), | |
7004 CENT("Pmenu ctermbg=Magenta ctermfg=Black", | |
7005 "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta"), | |
3695 | 7006 CENT("PmenuSel ctermbg=Black ctermfg=DarkGrey", |
7007 "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey"), | |
806 | 7008 #endif |
809 | 7009 CENT("Title term=bold ctermfg=LightMagenta", |
7010 "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), | |
7011 CENT("WarningMsg term=standout ctermfg=LightRed", | |
7012 "WarningMsg term=standout ctermfg=LightRed guifg=Red"), | |
806 | 7013 #ifdef FEAT_WILDMENU |
809 | 7014 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
7015 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 7016 #endif |
7017 #ifdef FEAT_FOLDING | |
809 | 7018 CENT("Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", |
7019 "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), | |
7020 CENT("FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", | |
7021 "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 7022 #endif |
7023 #ifdef FEAT_SIGNS | |
809 | 7024 CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", |
7025 "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 7026 #endif |
836 | 7027 CENT("Visual term=reverse", |
7028 "Visual term=reverse guibg=DarkGrey"), | |
806 | 7029 #ifdef FEAT_DIFF |
809 | 7030 CENT("DiffAdd term=bold ctermbg=DarkBlue", |
7031 "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), | |
7032 CENT("DiffChange term=bold ctermbg=DarkMagenta", | |
7033 "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), | |
7034 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", | |
7035 "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), | |
806 | 7036 #endif |
7037 #ifdef FEAT_WINDOWS | |
809 | 7038 CENT("TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", |
7039 "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), | |
806 | 7040 #endif |
7041 #ifdef FEAT_SYN_HL | |
809 | 7042 CENT("CursorColumn term=reverse ctermbg=DarkGrey", |
834 | 7043 "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), |
809 | 7044 CENT("CursorLine term=underline cterm=underline", |
834 | 7045 "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
|
7046 CENT("ColorColumn term=reverse ctermbg=DarkRed", |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
7047 "ColorColumn term=reverse ctermbg=DarkRed guibg=DarkRed"), |
834 | 7048 #endif |
7049 #ifdef FEAT_AUTOCMD | |
7050 CENT("MatchParen term=reverse ctermbg=DarkCyan", | |
7051 "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), | |
806 | 7052 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7053 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7054 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7055 "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
|
7056 #endif |
806 | 7057 #ifdef FEAT_GUI |
7 | 7058 "Normal gui=NONE", |
806 | 7059 #endif |
7 | 7060 NULL |
7061 }; | |
7062 | |
7063 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7064 init_highlight( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7065 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
|
7066 int reset) /* clear group first */ |
7 | 7067 { |
7068 int i; | |
7069 char **pp; | |
7070 static int had_both = FALSE; | |
7071 #ifdef FEAT_EVAL | |
7072 char_u *p; | |
7073 | |
7074 /* | |
7075 * Try finding the color scheme file. Used when a color file was loaded | |
7076 * and 'background' or 't_Co' is changed. | |
7077 */ | |
7078 p = get_var_value((char_u *)"g:colors_name"); | |
6671 | 7079 if (p != NULL) |
7080 { | |
7081 /* The value of g:colors_name could be freed when sourcing the script, | |
7082 * making "p" invalid, so copy it. */ | |
7083 char_u *copy_p = vim_strsave(p); | |
7084 int r; | |
7085 | |
7086 if (copy_p != NULL) | |
7087 { | |
7088 r = load_colors(copy_p); | |
7089 vim_free(copy_p); | |
7090 if (r == OK) | |
7091 return; | |
7092 } | |
7093 } | |
7094 | |
7 | 7095 #endif |
7096 | |
7097 /* | |
7098 * Didn't use a color file, use the compiled-in colors. | |
7099 */ | |
7100 if (both) | |
7101 { | |
7102 had_both = TRUE; | |
7103 pp = highlight_init_both; | |
7104 for (i = 0; pp[i] != NULL; ++i) | |
7105 do_highlight((char_u *)pp[i], reset, TRUE); | |
7106 } | |
7107 else if (!had_both) | |
7108 /* Don't do anything before the call with both == TRUE from main(). | |
7109 * Not everything has been setup then, and that call will overrule | |
7110 * everything anyway. */ | |
7111 return; | |
7112 | |
7113 if (*p_bg == 'l') | |
7114 pp = highlight_init_light; | |
7115 else | |
7116 pp = highlight_init_dark; | |
7117 for (i = 0; pp[i] != NULL; ++i) | |
7118 do_highlight((char_u *)pp[i], reset, TRUE); | |
7119 | |
836 | 7120 /* Reverse looks ugly, but grey may not work for 8 colors. Thus let it |
844 | 7121 * depend on the number of colors available. |
7122 * With 8 colors brown is equal to yellow, need to use black for Search fg | |
1697 | 7123 * to avoid Statement highlighted text disappears. |
7124 * Clear the attributes, needed when changing the t_Co value. */ | |
527 | 7125 if (t_colors > 8) |
1697 | 7126 do_highlight((char_u *)(*p_bg == 'l' |
7127 ? "Visual cterm=NONE ctermbg=LightGrey" | |
7128 : "Visual cterm=NONE ctermbg=DarkGrey"), FALSE, TRUE); | |
836 | 7129 else |
844 | 7130 { |
1697 | 7131 do_highlight((char_u *)"Visual cterm=reverse ctermbg=NONE", |
7132 FALSE, TRUE); | |
844 | 7133 if (*p_bg == 'l') |
7134 do_highlight((char_u *)"Search ctermfg=black", FALSE, TRUE); | |
7135 } | |
527 | 7136 |
7 | 7137 #ifdef FEAT_SYN_HL |
7138 /* | |
7139 * If syntax highlighting is enabled load the highlighting for it. | |
7140 */ | |
7141 if (get_var_value((char_u *)"g:syntax_on") != NULL) | |
24 | 7142 { |
7143 static int recursive = 0; | |
7144 | |
7145 if (recursive >= 5) | |
7146 EMSG(_("E679: recursive loop loading syncolor.vim")); | |
7147 else | |
7148 { | |
7149 ++recursive; | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
7150 (void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL); |
24 | 7151 --recursive; |
7152 } | |
7153 } | |
7 | 7154 #endif |
7155 } | |
7156 | |
7157 /* | |
12 | 7158 * Load color file "name". |
7 | 7159 * Return OK for success, FAIL for failure. |
7160 */ | |
7161 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7162 load_colors(char_u *name) |
7 | 7163 { |
7164 char_u *buf; | |
7165 int retval = FAIL; | |
7166 static int recursive = FALSE; | |
7167 | |
7168 /* When being called recursively, this is probably because setting | |
7169 * 'background' caused the highlighting to be reloaded. This means it is | |
7170 * working, thus we should return OK. */ | |
7171 if (recursive) | |
7172 return OK; | |
7173 | |
7174 recursive = TRUE; | |
12 | 7175 buf = alloc((unsigned)(STRLEN(name) + 12)); |
7 | 7176 if (buf != NULL) |
7177 { | |
12 | 7178 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
|
7179 retval = source_runtime(buf, DIP_START + DIP_OPT); |
7 | 7180 vim_free(buf); |
12 | 7181 #ifdef FEAT_AUTOCMD |
5521 | 7182 apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); |
12 | 7183 #endif |
7 | 7184 } |
7185 recursive = FALSE; | |
7186 | |
7187 return retval; | |
7188 } | |
7189 | |
7190 /* | |
7191 * Handle the ":highlight .." command. | |
7192 * When using ":hi clear" this is called recursively for each group with | |
7193 * "forceit" and "init" both TRUE. | |
7194 */ | |
7195 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7196 do_highlight( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7197 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7198 int forceit, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7199 int init) /* TRUE when called for initializing */ |
7 | 7200 { |
7201 char_u *name_end; | |
7202 char_u *p; | |
7203 char_u *linep; | |
7204 char_u *key_start; | |
7205 char_u *arg_start; | |
7206 char_u *key = NULL, *arg = NULL; | |
7207 long i; | |
7208 int off; | |
7209 int len; | |
7210 int attr; | |
7211 int id; | |
7212 int idx; | |
7213 int dodefault = FALSE; | |
7214 int doclear = FALSE; | |
7215 int dolink = FALSE; | |
7216 int error = FALSE; | |
7217 int color; | |
7218 int is_normal_group = FALSE; /* "Normal" group */ | |
7219 #ifdef FEAT_GUI_X11 | |
7220 int is_menu_group = FALSE; /* "Menu" group */ | |
7221 int is_scrollbar_group = FALSE; /* "Scrollbar" group */ | |
7222 int is_tooltip_group = FALSE; /* "Tooltip" group */ | |
7223 int do_colors = FALSE; /* need to update colors? */ | |
7224 #else | |
7225 # define is_menu_group 0 | |
7226 # define is_tooltip_group 0 | |
7227 #endif | |
7228 | |
7229 /* | |
7230 * If no argument, list current highlighting. | |
7231 */ | |
7232 if (ends_excmd(*line)) | |
7233 { | |
7234 for (i = 1; i <= highlight_ga.ga_len && !got_int; ++i) | |
7235 /* TODO: only call when the group has attributes set */ | |
7236 highlight_list_one((int)i); | |
7237 return; | |
7238 } | |
7239 | |
7240 /* | |
7241 * Isolate the name. | |
7242 */ | |
7243 name_end = skiptowhite(line); | |
7244 linep = skipwhite(name_end); | |
7245 | |
7246 /* | |
7247 * Check for "default" argument. | |
7248 */ | |
7249 if (STRNCMP(line, "default", name_end - line) == 0) | |
7250 { | |
7251 dodefault = TRUE; | |
7252 line = linep; | |
7253 name_end = skiptowhite(line); | |
7254 linep = skipwhite(name_end); | |
7255 } | |
7256 | |
7257 /* | |
7258 * Check for "clear" or "link" argument. | |
7259 */ | |
7260 if (STRNCMP(line, "clear", name_end - line) == 0) | |
7261 doclear = TRUE; | |
7262 if (STRNCMP(line, "link", name_end - line) == 0) | |
7263 dolink = TRUE; | |
7264 | |
7265 /* | |
7266 * ":highlight {group-name}": list highlighting for one group. | |
7267 */ | |
7268 if (!doclear && !dolink && ends_excmd(*linep)) | |
7269 { | |
7270 id = syn_namen2id(line, (int)(name_end - line)); | |
7271 if (id == 0) | |
7272 EMSG2(_("E411: highlight group not found: %s"), line); | |
7273 else | |
7274 highlight_list_one(id); | |
7275 return; | |
7276 } | |
7277 | |
7278 /* | |
7279 * Handle ":highlight link {from} {to}" command. | |
7280 */ | |
7281 if (dolink) | |
7282 { | |
7283 char_u *from_start = linep; | |
7284 char_u *from_end; | |
7285 char_u *to_start; | |
7286 char_u *to_end; | |
7287 int from_id; | |
7288 int to_id; | |
7289 | |
7290 from_end = skiptowhite(from_start); | |
7291 to_start = skipwhite(from_end); | |
7292 to_end = skiptowhite(to_start); | |
7293 | |
7294 if (ends_excmd(*from_start) || ends_excmd(*to_start)) | |
7295 { | |
7296 EMSG2(_("E412: Not enough arguments: \":highlight link %s\""), | |
7297 from_start); | |
7298 return; | |
7299 } | |
7300 | |
7301 if (!ends_excmd(*skipwhite(to_end))) | |
7302 { | |
7303 EMSG2(_("E413: Too many arguments: \":highlight link %s\""), from_start); | |
7304 return; | |
7305 } | |
7306 | |
7307 from_id = syn_check_group(from_start, (int)(from_end - from_start)); | |
7308 if (STRNCMP(to_start, "NONE", 4) == 0) | |
7309 to_id = 0; | |
7310 else | |
7311 to_id = syn_check_group(to_start, (int)(to_end - to_start)); | |
7312 | |
7313 if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0)) | |
7314 { | |
7315 /* | |
7316 * Don't allow a link when there already is some highlighting | |
7317 * for the group, unless '!' is used | |
7318 */ | |
7319 if (to_id > 0 && !forceit && !init | |
7320 && hl_has_settings(from_id - 1, dodefault)) | |
7321 { | |
7322 if (sourcing_name == NULL && !dodefault) | |
7323 EMSG(_("E414: group has settings, highlight link ignored")); | |
7324 } | |
7325 else | |
7326 { | |
7327 if (!init) | |
7328 HL_TABLE()[from_id - 1].sg_set |= SG_LINK; | |
7329 HL_TABLE()[from_id - 1].sg_link = to_id; | |
448 | 7330 #ifdef FEAT_EVAL |
7331 HL_TABLE()[from_id - 1].sg_scriptID = current_SID; | |
7332 #endif | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
7333 HL_TABLE()[from_id - 1].sg_cleared = FALSE; |
745 | 7334 redraw_all_later(SOME_VALID); |
7 | 7335 } |
7336 } | |
7337 | |
7338 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
7339 need_highlight_changed = TRUE; | |
7340 | |
7341 return; | |
7342 } | |
7343 | |
7344 if (doclear) | |
7345 { | |
7346 /* | |
7347 * ":highlight clear [group]" command. | |
7348 */ | |
7349 line = linep; | |
7350 if (ends_excmd(*line)) | |
7351 { | |
7352 #ifdef FEAT_GUI | |
7353 /* First, we do not destroy the old values, but allocate the new | |
7354 * ones and update the display. THEN we destroy the old values. | |
7355 * If we destroy the old values first, then the old values | |
7356 * (such as GuiFont's or GuiFontset's) will still be displayed but | |
7357 * invalid because they were free'd. | |
7358 */ | |
7359 if (gui.in_use) | |
7360 { | |
7361 # ifdef FEAT_BEVAL_TIP | |
7362 gui_init_tooltip_font(); | |
7363 # endif | |
7364 # if defined(FEAT_MENU) && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF)) | |
7365 gui_init_menu_font(); | |
7366 # endif | |
7367 } | |
7368 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_X11) | |
7369 gui_mch_def_colors(); | |
7370 # endif | |
7371 # ifdef FEAT_GUI_X11 | |
7372 # ifdef FEAT_MENU | |
7373 | |
7374 /* This only needs to be done when there is no Menu highlight | |
7375 * group defined by default, which IS currently the case. | |
7376 */ | |
7377 gui_mch_new_menu_colors(); | |
7378 # endif | |
7379 if (gui.in_use) | |
7380 { | |
7381 gui_new_scrollbar_colors(); | |
7382 # ifdef FEAT_BEVAL | |
7383 gui_mch_new_tooltip_colors(); | |
7384 # endif | |
7385 # ifdef FEAT_MENU | |
7386 gui_mch_new_menu_font(); | |
7387 # endif | |
7388 } | |
7389 # endif | |
7390 | |
7391 /* Ok, we're done allocating the new default graphics items. | |
7392 * The screen should already be refreshed at this point. | |
7393 * It is now Ok to clear out the old data. | |
7394 */ | |
7395 #endif | |
7396 #ifdef FEAT_EVAL | |
148 | 7397 do_unlet((char_u *)"colors_name", TRUE); |
7 | 7398 #endif |
7399 restore_cterm_colors(); | |
7400 | |
7401 /* | |
7402 * Clear all default highlight groups and load the defaults. | |
7403 */ | |
7404 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
7405 highlight_clear(idx); | |
7406 init_highlight(TRUE, TRUE); | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7407 #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
|
7408 if (USE_24BIT) |
7 | 7409 highlight_gui_started(); |
7410 #endif | |
7411 highlight_changed(); | |
7412 redraw_later_clear(); | |
7413 return; | |
7414 } | |
7415 name_end = skiptowhite(line); | |
7416 linep = skipwhite(name_end); | |
7417 } | |
7418 | |
7419 /* | |
7420 * Find the group name in the table. If it does not exist yet, add it. | |
7421 */ | |
7422 id = syn_check_group(line, (int)(name_end - line)); | |
7423 if (id == 0) /* failed (out of memory) */ | |
7424 return; | |
7425 idx = id - 1; /* index is ID minus one */ | |
7426 | |
7427 /* Return if "default" was used and the group already has settings. */ | |
7428 if (dodefault && hl_has_settings(idx, TRUE)) | |
7429 return; | |
7430 | |
7431 if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0) | |
7432 is_normal_group = TRUE; | |
7433 #ifdef FEAT_GUI_X11 | |
7434 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0) | |
7435 is_menu_group = TRUE; | |
7436 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "SCROLLBAR") == 0) | |
7437 is_scrollbar_group = TRUE; | |
7438 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "TOOLTIP") == 0) | |
7439 is_tooltip_group = TRUE; | |
7440 #endif | |
7441 | |
7442 /* Clear the highlighting for ":hi clear {group}" and ":hi clear". */ | |
7443 if (doclear || (forceit && init)) | |
7444 { | |
7445 highlight_clear(idx); | |
7446 if (!doclear) | |
7447 HL_TABLE()[idx].sg_set = 0; | |
7448 } | |
7449 | |
7450 if (!doclear) | |
7451 while (!ends_excmd(*linep)) | |
7452 { | |
7453 key_start = linep; | |
7454 if (*linep == '=') | |
7455 { | |
7456 EMSG2(_("E415: unexpected equal sign: %s"), key_start); | |
7457 error = TRUE; | |
7458 break; | |
7459 } | |
7460 | |
7461 /* | |
7462 * Isolate the key ("term", "ctermfg", "ctermbg", "font", "guifg" or | |
7463 * "guibg"). | |
7464 */ | |
7465 while (*linep && !vim_iswhite(*linep) && *linep != '=') | |
7466 ++linep; | |
7467 vim_free(key); | |
7468 key = vim_strnsave_up(key_start, (int)(linep - key_start)); | |
7469 if (key == NULL) | |
7470 { | |
7471 error = TRUE; | |
7472 break; | |
7473 } | |
7474 linep = skipwhite(linep); | |
7475 | |
7476 if (STRCMP(key, "NONE") == 0) | |
7477 { | |
7478 if (!init || HL_TABLE()[idx].sg_set == 0) | |
7479 { | |
7480 if (!init) | |
7481 HL_TABLE()[idx].sg_set |= SG_TERM+SG_CTERM+SG_GUI; | |
7482 highlight_clear(idx); | |
7483 } | |
7484 continue; | |
7485 } | |
7486 | |
7487 /* | |
7488 * Check for the equal sign. | |
7489 */ | |
7490 if (*linep != '=') | |
7491 { | |
7492 EMSG2(_("E416: missing equal sign: %s"), key_start); | |
7493 error = TRUE; | |
7494 break; | |
7495 } | |
7496 ++linep; | |
7497 | |
7498 /* | |
7499 * Isolate the argument. | |
7500 */ | |
7501 linep = skipwhite(linep); | |
7502 if (*linep == '\'') /* guifg='color name' */ | |
7503 { | |
7504 arg_start = ++linep; | |
7505 linep = vim_strchr(linep, '\''); | |
7506 if (linep == NULL) | |
7507 { | |
7508 EMSG2(_(e_invarg2), key_start); | |
7509 error = TRUE; | |
7510 break; | |
7511 } | |
7512 } | |
7513 else | |
7514 { | |
7515 arg_start = linep; | |
7516 linep = skiptowhite(linep); | |
7517 } | |
7518 if (linep == arg_start) | |
7519 { | |
7520 EMSG2(_("E417: missing argument: %s"), key_start); | |
7521 error = TRUE; | |
7522 break; | |
7523 } | |
7524 vim_free(arg); | |
7525 arg = vim_strnsave(arg_start, (int)(linep - arg_start)); | |
7526 if (arg == NULL) | |
7527 { | |
7528 error = TRUE; | |
7529 break; | |
7530 } | |
7531 if (*linep == '\'') | |
7532 ++linep; | |
7533 | |
7534 /* | |
7535 * Store the argument. | |
7536 */ | |
7537 if ( STRCMP(key, "TERM") == 0 | |
7538 || STRCMP(key, "CTERM") == 0 | |
7539 || STRCMP(key, "GUI") == 0) | |
7540 { | |
7541 attr = 0; | |
7542 off = 0; | |
7543 while (arg[off] != NUL) | |
7544 { | |
7545 for (i = sizeof(hl_attr_table) / sizeof(int); --i >= 0; ) | |
7546 { | |
7547 len = (int)STRLEN(hl_name_table[i]); | |
7548 if (STRNICMP(arg + off, hl_name_table[i], len) == 0) | |
7549 { | |
7550 attr |= hl_attr_table[i]; | |
7551 off += len; | |
7552 break; | |
7553 } | |
7554 } | |
7555 if (i < 0) | |
7556 { | |
7557 EMSG2(_("E418: Illegal value: %s"), arg); | |
7558 error = TRUE; | |
7559 break; | |
7560 } | |
7561 if (arg[off] == ',') /* another one follows */ | |
7562 ++off; | |
7563 } | |
7564 if (error) | |
7565 break; | |
7566 if (*key == 'T') | |
7567 { | |
7568 if (!init || !(HL_TABLE()[idx].sg_set & SG_TERM)) | |
7569 { | |
7570 if (!init) | |
7571 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7572 HL_TABLE()[idx].sg_term = attr; | |
7573 } | |
7574 } | |
7575 else if (*key == 'C') | |
7576 { | |
7577 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7578 { | |
7579 if (!init) | |
7580 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7581 HL_TABLE()[idx].sg_cterm = attr; | |
7582 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7583 } | |
7584 } | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7585 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 7586 else |
7587 { | |
7588 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) | |
7589 { | |
7590 if (!init) | |
7591 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7592 HL_TABLE()[idx].sg_gui = attr; | |
7593 } | |
7594 } | |
7595 #endif | |
7596 } | |
7597 else if (STRCMP(key, "FONT") == 0) | |
7598 { | |
7599 /* in non-GUI fonts are simply ignored */ | |
7600 #ifdef FEAT_GUI | |
7601 if (!gui.shell_created) | |
7602 { | |
7603 /* GUI not started yet, always accept the name. */ | |
7604 vim_free(HL_TABLE()[idx].sg_font_name); | |
7605 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7606 } | |
7607 else | |
7608 { | |
7609 GuiFont temp_sg_font = HL_TABLE()[idx].sg_font; | |
7610 # ifdef FEAT_XFONTSET | |
7611 GuiFontset temp_sg_fontset = HL_TABLE()[idx].sg_fontset; | |
7612 # endif | |
7613 /* First, save the current font/fontset. | |
7614 * Then try to allocate the font/fontset. | |
7615 * If the allocation fails, HL_TABLE()[idx].sg_font OR | |
7616 * sg_fontset will be set to NOFONT or NOFONTSET respectively. | |
7617 */ | |
7618 | |
7619 HL_TABLE()[idx].sg_font = NOFONT; | |
7620 # ifdef FEAT_XFONTSET | |
7621 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
7622 # endif | |
7623 hl_do_font(idx, arg, is_normal_group, is_menu_group, | |
3881 | 7624 is_tooltip_group, FALSE); |
7 | 7625 |
7626 # ifdef FEAT_XFONTSET | |
7627 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) | |
7628 { | |
3881 | 7629 /* New fontset was accepted. Free the old one, if there |
7630 * was one. */ | |
7 | 7631 gui_mch_free_fontset(temp_sg_fontset); |
7632 vim_free(HL_TABLE()[idx].sg_font_name); | |
7633 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7634 } | |
7635 else | |
7636 HL_TABLE()[idx].sg_fontset = temp_sg_fontset; | |
7637 # endif | |
7638 if (HL_TABLE()[idx].sg_font != NOFONT) | |
7639 { | |
7640 /* New font was accepted. Free the old one, if there was | |
3881 | 7641 * one. */ |
7 | 7642 gui_mch_free_font(temp_sg_font); |
7643 vim_free(HL_TABLE()[idx].sg_font_name); | |
7644 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7645 } | |
7646 else | |
7647 HL_TABLE()[idx].sg_font = temp_sg_font; | |
7648 } | |
7649 #endif | |
7650 } | |
7651 else if (STRCMP(key, "CTERMFG") == 0 || STRCMP(key, "CTERMBG") == 0) | |
7652 { | |
7653 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7654 { | |
7655 if (!init) | |
7656 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7657 | |
7658 /* When setting the foreground color, and previously the "bold" | |
7659 * flag was set for a light color, reset it now */ | |
7660 if (key[5] == 'F' && HL_TABLE()[idx].sg_cterm_bold) | |
7661 { | |
7662 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7663 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7664 } | |
7665 | |
7666 if (VIM_ISDIGIT(*arg)) | |
7667 color = atoi((char *)arg); | |
7668 else if (STRICMP(arg, "fg") == 0) | |
7669 { | |
7670 if (cterm_normal_fg_color) | |
7671 color = cterm_normal_fg_color - 1; | |
7672 else | |
7673 { | |
7674 EMSG(_("E419: FG color unknown")); | |
7675 error = TRUE; | |
7676 break; | |
7677 } | |
7678 } | |
7679 else if (STRICMP(arg, "bg") == 0) | |
7680 { | |
7681 if (cterm_normal_bg_color > 0) | |
7682 color = cterm_normal_bg_color - 1; | |
7683 else | |
7684 { | |
7685 EMSG(_("E420: BG color unknown")); | |
7686 error = TRUE; | |
7687 break; | |
7688 } | |
7689 } | |
7690 else | |
7691 { | |
7692 static char *(color_names[28]) = { | |
7693 "Black", "DarkBlue", "DarkGreen", "DarkCyan", | |
7694 "DarkRed", "DarkMagenta", "Brown", "DarkYellow", | |
7695 "Gray", "Grey", | |
7696 "LightGray", "LightGrey", "DarkGray", "DarkGrey", | |
7697 "Blue", "LightBlue", "Green", "LightGreen", | |
7698 "Cyan", "LightCyan", "Red", "LightRed", "Magenta", | |
7699 "LightMagenta", "Yellow", "LightYellow", "White", "NONE"}; | |
7700 static int color_numbers_16[28] = {0, 1, 2, 3, | |
7701 4, 5, 6, 6, | |
7702 7, 7, | |
7703 7, 7, 8, 8, | |
7704 9, 9, 10, 10, | |
7705 11, 11, 12, 12, 13, | |
7706 13, 14, 14, 15, -1}; | |
7707 /* for xterm with 88 colors... */ | |
7708 static int color_numbers_88[28] = {0, 4, 2, 6, | |
7709 1, 5, 32, 72, | |
7710 84, 84, | |
7711 7, 7, 82, 82, | |
7712 12, 43, 10, 61, | |
7713 14, 63, 9, 74, 13, | |
7714 75, 11, 78, 15, -1}; | |
7715 /* for xterm with 256 colors... */ | |
7716 static int color_numbers_256[28] = {0, 4, 2, 6, | |
7717 1, 5, 130, 130, | |
7718 248, 248, | |
7719 7, 7, 242, 242, | |
7720 12, 81, 10, 121, | |
7721 14, 159, 9, 224, 13, | |
7722 225, 11, 229, 15, -1}; | |
7723 /* for terminals with less than 16 colors... */ | |
7724 static int color_numbers_8[28] = {0, 4, 2, 6, | |
7725 1, 5, 3, 3, | |
7726 7, 7, | |
7727 7, 7, 0+8, 0+8, | |
7728 4+8, 4+8, 2+8, 2+8, | |
7729 6+8, 6+8, 1+8, 1+8, 5+8, | |
7730 5+8, 3+8, 3+8, 7+8, -1}; | |
7731 #if defined(__QNXNTO__) | |
7732 static int *color_numbers_8_qansi = color_numbers_8; | |
7733 /* On qnx, the 8 & 16 color arrays are the same */ | |
7734 if (STRNCMP(T_NAME, "qansi", 5) == 0) | |
7735 color_numbers_8_qansi = color_numbers_16; | |
7736 #endif | |
7737 | |
7738 /* reduce calls to STRICMP a bit, it can be slow */ | |
7739 off = TOUPPER_ASC(*arg); | |
7740 for (i = (sizeof(color_names) / sizeof(char *)); --i >= 0; ) | |
7741 if (off == color_names[i][0] | |
7742 && STRICMP(arg + 1, color_names[i] + 1) == 0) | |
7743 break; | |
7744 if (i < 0) | |
7745 { | |
7746 EMSG2(_("E421: Color name or number not recognized: %s"), key_start); | |
7747 error = TRUE; | |
7748 break; | |
7749 } | |
7750 | |
7751 /* Use the _16 table to check if its a valid color name. */ | |
7752 color = color_numbers_16[i]; | |
7753 if (color >= 0) | |
7754 { | |
7755 if (t_colors == 8) | |
7756 { | |
7757 /* t_Co is 8: use the 8 colors table */ | |
7758 #if defined(__QNXNTO__) | |
7759 color = color_numbers_8_qansi[i]; | |
7760 #else | |
7761 color = color_numbers_8[i]; | |
7762 #endif | |
7763 if (key[5] == 'F') | |
7764 { | |
7765 /* set/reset bold attribute to get light foreground | |
7766 * colors (on some terminals, e.g. "linux") */ | |
7767 if (color & 8) | |
7768 { | |
7769 HL_TABLE()[idx].sg_cterm |= HL_BOLD; | |
7770 HL_TABLE()[idx].sg_cterm_bold = TRUE; | |
7771 } | |
7772 else | |
7773 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7774 } | |
7775 color &= 7; /* truncate to 8 colors */ | |
7776 } | |
7777 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
|
7778 || t_colors >= 256) |
7 | 7779 { |
7780 /* | |
7781 * Guess: if the termcap entry ends in 'm', it is | |
7782 * probably an xterm-like terminal. Use the changed | |
7783 * order for colors. | |
7784 */ | |
7785 if (*T_CAF != NUL) | |
7786 p = T_CAF; | |
7787 else | |
7788 p = T_CSF; | |
7467
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7789 if (*p != NUL && (t_colors > 256 |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7790 || *(p + STRLEN(p) - 1) == 'm')) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7791 { |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7792 if (t_colors == 88) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7793 color = color_numbers_88[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7794 else if (t_colors >= 256) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7795 color = color_numbers_256[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7796 else |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7797 color = color_numbers_8[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7798 } |
7 | 7799 } |
7800 } | |
7801 } | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7802 /* 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
|
7803 * "NONE", then "color" is -1. */ |
7 | 7804 if (key[5] == 'F') |
7805 { | |
7806 HL_TABLE()[idx].sg_cterm_fg = color + 1; | |
7807 if (is_normal_group) | |
7808 { | |
7809 cterm_normal_fg_color = color + 1; | |
7810 cterm_normal_fg_bold = (HL_TABLE()[idx].sg_cterm & HL_BOLD); | |
7811 #ifdef FEAT_GUI | |
7812 /* Don't do this if the GUI is used. */ | |
7813 if (!gui.in_use && !gui.starting) | |
7814 #endif | |
7815 { | |
7816 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7817 if (termcap_active && color >= 0) |
7 | 7818 term_fg_color(color); |
7819 } | |
7820 } | |
7821 } | |
7822 else | |
7823 { | |
7824 HL_TABLE()[idx].sg_cterm_bg = color + 1; | |
7825 if (is_normal_group) | |
7826 { | |
7827 cterm_normal_bg_color = color + 1; | |
7828 #ifdef FEAT_GUI | |
7829 /* Don't mess with 'background' if the GUI is used. */ | |
7830 if (!gui.in_use && !gui.starting) | |
7831 #endif | |
7832 { | |
7833 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7834 if (color >= 0) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7835 { |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7836 if (termcap_active) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7837 term_bg_color(color); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7838 if (t_colors < 16) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7839 i = (color == 0 || color == 4); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7840 else |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7841 i = (color < 7 || color == 8); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7842 /* Set the 'background' option if the value is |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7843 * wrong. */ |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7844 if (i != (*p_bg == 'd')) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7845 set_option_value((char_u *)"bg", 0L, |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7846 i ? (char_u *)"dark" |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7847 : (char_u *)"light", 0); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7848 } |
7 | 7849 } |
7850 } | |
7851 } | |
7852 } | |
7853 } | |
7854 else if (STRCMP(key, "GUIFG") == 0) | |
7855 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7856 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7857 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7858 { |
205 | 7859 if (!init) |
7860 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7861 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7862 # 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
|
7863 /* In GUI guifg colors are only used when recognized */ |
205 | 7864 i = color_name2handle(arg); |
9029
f06767547415
commit https://github.com/vim/vim/commit/631225627d448b591e529a5d3e7ac74ef44b8459
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
7865 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) |
205 | 7866 { |
7867 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
|
7868 # endif |
205 | 7869 vim_free(HL_TABLE()[idx].sg_gui_fg_name); |
7870 if (STRCMP(arg, "NONE")) | |
7871 HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg); | |
7872 else | |
7873 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
|
7874 # 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
|
7875 # ifdef FEAT_GUI_X11 |
205 | 7876 if (is_menu_group) |
7877 gui.menu_fg_pixel = i; | |
7878 if (is_scrollbar_group) | |
7879 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
|
7880 # ifdef FEAT_BEVAL |
205 | 7881 if (is_tooltip_group) |
7882 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
|
7883 # endif |
205 | 7884 do_colors = TRUE; |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7885 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7886 } |
7 | 7887 # endif |
7888 } | |
7889 #endif | |
7890 } | |
7891 else if (STRCMP(key, "GUIBG") == 0) | |
7892 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7893 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7894 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7895 { |
205 | 7896 if (!init) |
7897 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7898 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7899 # 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
|
7900 /* In GUI guifg colors are only used when recognized */ |
205 | 7901 i = color_name2handle(arg); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
7902 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) |
205 | 7903 { |
7904 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
|
7905 # endif |
205 | 7906 vim_free(HL_TABLE()[idx].sg_gui_bg_name); |
7907 if (STRCMP(arg, "NONE") != 0) | |
7908 HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg); | |
7909 else | |
7910 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
|
7911 # 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
|
7912 # ifdef FEAT_GUI_X11 |
205 | 7913 if (is_menu_group) |
7914 gui.menu_bg_pixel = i; | |
7915 if (is_scrollbar_group) | |
7916 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
|
7917 # ifdef FEAT_BEVAL |
205 | 7918 if (is_tooltip_group) |
7919 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
|
7920 # endif |
205 | 7921 do_colors = TRUE; |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7922 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7923 } |
7 | 7924 # endif |
7925 } | |
205 | 7926 #endif |
7927 } | |
7928 else if (STRCMP(key, "GUISP") == 0) | |
7929 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7930 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7931 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7932 { | |
7933 if (!init) | |
7934 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7935 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7936 # ifdef FEAT_GUI |
205 | 7937 i = color_name2handle(arg); |
7938 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) | |
7939 { | |
7940 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
|
7941 # endif |
205 | 7942 vim_free(HL_TABLE()[idx].sg_gui_sp_name); |
7943 if (STRCMP(arg, "NONE") != 0) | |
7944 HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg); | |
7945 else | |
7946 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
|
7947 # ifdef FEAT_GUI |
205 | 7948 } |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7949 # endif |
205 | 7950 } |
7 | 7951 #endif |
7952 } | |
7953 else if (STRCMP(key, "START") == 0 || STRCMP(key, "STOP") == 0) | |
7954 { | |
7955 char_u buf[100]; | |
7956 char_u *tname; | |
7957 | |
7958 if (!init) | |
7959 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7960 | |
7961 /* | |
7962 * The "start" and "stop" arguments can be a literal escape | |
1222 | 7963 * sequence, or a comma separated list of terminal codes. |
7 | 7964 */ |
7965 if (STRNCMP(arg, "t_", 2) == 0) | |
7966 { | |
7967 off = 0; | |
7968 buf[0] = 0; | |
7969 while (arg[off] != NUL) | |
7970 { | |
7971 /* Isolate one termcap name */ | |
7972 for (len = 0; arg[off + len] && | |
7973 arg[off + len] != ','; ++len) | |
7974 ; | |
7975 tname = vim_strnsave(arg + off, len); | |
7976 if (tname == NULL) /* out of memory */ | |
7977 { | |
7978 error = TRUE; | |
7979 break; | |
7980 } | |
7981 /* lookup the escape sequence for the item */ | |
7982 p = get_term_code(tname); | |
7983 vim_free(tname); | |
7984 if (p == NULL) /* ignore non-existing things */ | |
7985 p = (char_u *)""; | |
7986 | |
7987 /* Append it to the already found stuff */ | |
7988 if ((int)(STRLEN(buf) + STRLEN(p)) >= 99) | |
7989 { | |
7990 EMSG2(_("E422: terminal code too long: %s"), arg); | |
7991 error = TRUE; | |
7992 break; | |
7993 } | |
7994 STRCAT(buf, p); | |
7995 | |
7996 /* Advance to the next item */ | |
7997 off += len; | |
7998 if (arg[off] == ',') /* another one follows */ | |
7999 ++off; | |
8000 } | |
8001 } | |
8002 else | |
8003 { | |
8004 /* | |
8005 * Copy characters from arg[] to buf[], translating <> codes. | |
8006 */ | |
2593 | 8007 for (p = arg, off = 0; off < 100 - 6 && *p; ) |
7 | 8008 { |
9869
989d44d35a66
commit https://github.com/vim/vim/commit/35a4cfa200917dd171b1fff3cd5b6cee9add673d
Christian Brabandt <cb@256bit.org>
parents:
9141
diff
changeset
|
8009 len = trans_special(&p, buf + off, FALSE, FALSE); |
2593 | 8010 if (len > 0) /* recognized special char */ |
7 | 8011 off += len; |
8012 else /* copy as normal char */ | |
8013 buf[off++] = *p++; | |
8014 } | |
8015 buf[off] = NUL; | |
8016 } | |
8017 if (error) | |
8018 break; | |
8019 | |
8020 if (STRCMP(buf, "NONE") == 0) /* resetting the value */ | |
8021 p = NULL; | |
8022 else | |
8023 p = vim_strsave(buf); | |
8024 if (key[2] == 'A') | |
8025 { | |
8026 vim_free(HL_TABLE()[idx].sg_start); | |
8027 HL_TABLE()[idx].sg_start = p; | |
8028 } | |
8029 else | |
8030 { | |
8031 vim_free(HL_TABLE()[idx].sg_stop); | |
8032 HL_TABLE()[idx].sg_stop = p; | |
8033 } | |
8034 } | |
8035 else | |
8036 { | |
8037 EMSG2(_("E423: Illegal argument: %s"), key_start); | |
8038 error = TRUE; | |
8039 break; | |
8040 } | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8041 HL_TABLE()[idx].sg_cleared = FALSE; |
7 | 8042 |
8043 /* | |
8044 * When highlighting has been given for a group, don't link it. | |
8045 */ | |
8046 if (!init || !(HL_TABLE()[idx].sg_set & SG_LINK)) | |
8047 HL_TABLE()[idx].sg_link = 0; | |
8048 | |
8049 /* | |
8050 * Continue with next argument. | |
8051 */ | |
8052 linep = skipwhite(linep); | |
8053 } | |
8054 | |
8055 /* | |
8056 * If there is an error, and it's a new entry, remove it from the table. | |
8057 */ | |
8058 if (error && idx == highlight_ga.ga_len) | |
8059 syn_unadd_group(); | |
8060 else | |
8061 { | |
8062 if (is_normal_group) | |
8063 { | |
8064 HL_TABLE()[idx].sg_term_attr = 0; | |
8065 HL_TABLE()[idx].sg_cterm_attr = 0; | |
8066 #ifdef FEAT_GUI | |
8067 HL_TABLE()[idx].sg_gui_attr = 0; | |
8068 /* | |
8069 * Need to update all groups, because they might be using "bg" | |
8070 * and/or "fg", which have been changed now. | |
8071 */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8072 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8073 #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
|
8074 if (USE_24BIT) |
7 | 8075 highlight_gui_started(); |
8076 #endif | |
8077 } | |
8078 #ifdef FEAT_GUI_X11 | |
8079 # ifdef FEAT_MENU | |
8080 else if (is_menu_group) | |
8081 { | |
8082 if (gui.in_use && do_colors) | |
8083 gui_mch_new_menu_colors(); | |
8084 } | |
8085 # endif | |
8086 else if (is_scrollbar_group) | |
8087 { | |
8088 if (gui.in_use && do_colors) | |
8089 gui_new_scrollbar_colors(); | |
8090 } | |
8091 # ifdef FEAT_BEVAL | |
8092 else if (is_tooltip_group) | |
8093 { | |
8094 if (gui.in_use && do_colors) | |
8095 gui_mch_new_tooltip_colors(); | |
8096 } | |
8097 # endif | |
8098 #endif | |
8099 else | |
8100 set_hl_attr(idx); | |
448 | 8101 #ifdef FEAT_EVAL |
8102 HL_TABLE()[idx].sg_scriptID = current_SID; | |
8103 #endif | |
819 | 8104 redraw_all_later(NOT_VALID); |
7 | 8105 } |
8106 vim_free(key); | |
8107 vim_free(arg); | |
8108 | |
8109 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
8110 need_highlight_changed = TRUE; | |
8111 } | |
8112 | |
356 | 8113 #if defined(EXITFREE) || defined(PROTO) |
8114 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8115 free_highlight(void) |
356 | 8116 { |
8117 int i; | |
8118 | |
8119 for (i = 0; i < highlight_ga.ga_len; ++i) | |
359 | 8120 { |
356 | 8121 highlight_clear(i); |
359 | 8122 vim_free(HL_TABLE()[i].sg_name); |
8123 vim_free(HL_TABLE()[i].sg_name_u); | |
8124 } | |
356 | 8125 ga_clear(&highlight_ga); |
8126 } | |
8127 #endif | |
8128 | |
7 | 8129 /* |
8130 * Reset the cterm colors to what they were before Vim was started, if | |
8131 * possible. Otherwise reset them to zero. | |
8132 */ | |
8133 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8134 restore_cterm_colors(void) |
7 | 8135 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
8136 #if defined(WIN3264) && !defined(FEAT_GUI_W32) |
7 | 8137 /* Since t_me has been set, this probably means that the user |
8138 * wants to use this as default colors. Need to reset default | |
8139 * background/foreground colors. */ | |
8140 mch_set_normal_colors(); | |
8141 #else | |
8142 cterm_normal_fg_color = 0; | |
8143 cterm_normal_fg_bold = 0; | |
8144 cterm_normal_bg_color = 0; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8145 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8146 cterm_normal_fg_gui_color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8147 cterm_normal_bg_gui_color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8148 # endif |
7 | 8149 #endif |
8150 } | |
8151 | |
8152 /* | |
8153 * Return TRUE if highlight group "idx" has any settings. | |
8154 * When "check_link" is TRUE also check for an existing link. | |
8155 */ | |
8156 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8157 hl_has_settings(int idx, int check_link) |
7 | 8158 { |
8159 return ( HL_TABLE()[idx].sg_term_attr != 0 | |
8160 || HL_TABLE()[idx].sg_cterm_attr != 0 | |
5954 | 8161 || HL_TABLE()[idx].sg_cterm_fg != 0 |
8162 || HL_TABLE()[idx].sg_cterm_bg != 0 | |
7 | 8163 #ifdef FEAT_GUI |
8164 || HL_TABLE()[idx].sg_gui_attr != 0 | |
5954 | 8165 || HL_TABLE()[idx].sg_gui_fg_name != NULL |
8166 || HL_TABLE()[idx].sg_gui_bg_name != NULL | |
8167 || HL_TABLE()[idx].sg_gui_sp_name != NULL | |
8168 || HL_TABLE()[idx].sg_font_name != NUL | |
7 | 8169 #endif |
8170 || (check_link && (HL_TABLE()[idx].sg_set & SG_LINK))); | |
8171 } | |
8172 | |
8173 /* | |
8174 * Clear highlighting for one group. | |
8175 */ | |
8176 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8177 highlight_clear(int idx) |
7 | 8178 { |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8179 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
|
8180 |
7 | 8181 HL_TABLE()[idx].sg_term = 0; |
8182 vim_free(HL_TABLE()[idx].sg_start); | |
8183 HL_TABLE()[idx].sg_start = NULL; | |
8184 vim_free(HL_TABLE()[idx].sg_stop); | |
8185 HL_TABLE()[idx].sg_stop = NULL; | |
8186 HL_TABLE()[idx].sg_term_attr = 0; | |
8187 HL_TABLE()[idx].sg_cterm = 0; | |
8188 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
8189 HL_TABLE()[idx].sg_cterm_fg = 0; | |
8190 HL_TABLE()[idx].sg_cterm_bg = 0; | |
8191 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
|
8192 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 8193 HL_TABLE()[idx].sg_gui = 0; |
8194 vim_free(HL_TABLE()[idx].sg_gui_fg_name); | |
8195 HL_TABLE()[idx].sg_gui_fg_name = NULL; | |
8196 vim_free(HL_TABLE()[idx].sg_gui_bg_name); | |
8197 HL_TABLE()[idx].sg_gui_bg_name = NULL; | |
205 | 8198 vim_free(HL_TABLE()[idx].sg_gui_sp_name); |
8199 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
|
8200 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8201 #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
|
8202 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
|
8203 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
|
8204 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8205 #ifdef FEAT_GUI |
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_sp = INVALCOLOR; |
7 | 8207 gui_mch_free_font(HL_TABLE()[idx].sg_font); |
8208 HL_TABLE()[idx].sg_font = NOFONT; | |
8209 # ifdef FEAT_XFONTSET | |
8210 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
8211 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
8212 # endif | |
8213 vim_free(HL_TABLE()[idx].sg_font_name); | |
8214 HL_TABLE()[idx].sg_font_name = NULL; | |
8215 HL_TABLE()[idx].sg_gui_attr = 0; | |
8216 #endif | |
448 | 8217 #ifdef FEAT_EVAL |
8218 /* Clear the script ID only when there is no link, since that is not | |
8219 * cleared. */ | |
8220 if (HL_TABLE()[idx].sg_link == 0) | |
8221 HL_TABLE()[idx].sg_scriptID = 0; | |
8222 #endif | |
7 | 8223 } |
8224 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8225 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
7 | 8226 /* |
8227 * Set the normal foreground and background colors according to the "Normal" | |
2020 | 8228 * highlighting group. For X11 also set "Menu", "Scrollbar", and |
7 | 8229 * "Tooltip" colors. |
8230 */ | |
8231 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8232 set_normal_colors(void) |
7 | 8233 { |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8234 #ifdef FEAT_GUI |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8235 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8236 if (gui.in_use) |
7 | 8237 # endif |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8238 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8239 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
|
8240 &gui.norm_pixel, &gui.back_pixel, |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8241 FALSE, TRUE, FALSE)) |
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 gui_mch_new_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8244 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8245 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8246 # ifdef FEAT_GUI_X11 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8247 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
|
8248 &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
|
8249 TRUE, FALSE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8250 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8251 # ifdef FEAT_MENU |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8252 gui_mch_new_menu_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8253 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8254 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8255 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8256 # ifdef FEAT_BEVAL |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8257 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
|
8258 &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
|
8259 FALSE, FALSE, TRUE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8260 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8261 # ifdef FEAT_TOOLBAR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8262 gui_mch_new_tooltip_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8263 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8264 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8265 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8266 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8267 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
|
8268 &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
|
8269 FALSE, FALSE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8270 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8271 gui_new_scrollbar_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8272 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8273 } |
7 | 8274 # endif |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8275 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8276 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8277 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8278 # ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8279 else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8280 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8281 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8282 int idx; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8283 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8284 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
|
8285 if (idx >= 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8286 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8287 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
|
8288 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8289 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
|
8290 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8291 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
|
8292 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8293 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8294 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
|
8295 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8296 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
|
8297 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8298 } |
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 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8301 #endif |
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 #endif |
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 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 8306 /* |
8307 * Set the colors for "Normal", "Menu", "Tooltip" or "Scrollbar". | |
8308 */ | |
8309 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8310 set_group_colors( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8311 char_u *name, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8312 guicolor_T *fgp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8313 guicolor_T *bgp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8314 int do_menu, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8315 int use_norm, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8316 int do_tooltip) |
7 | 8317 { |
8318 int idx; | |
8319 | |
8320 idx = syn_name2id(name) - 1; | |
8321 if (idx >= 0) | |
8322 { | |
8323 gui_do_one_color(idx, do_menu, do_tooltip); | |
8324 | |
8325 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR) | |
8326 *fgp = HL_TABLE()[idx].sg_gui_fg; | |
8327 else if (use_norm) | |
8328 *fgp = gui.def_norm_pixel; | |
8329 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR) | |
8330 *bgp = HL_TABLE()[idx].sg_gui_bg; | |
8331 else if (use_norm) | |
8332 *bgp = gui.def_back_pixel; | |
8333 return TRUE; | |
8334 } | |
8335 return FALSE; | |
8336 } | |
8337 | |
8338 /* | |
8339 * Get the font of the "Normal" group. | |
8340 * Returns "" when it's not found or not set. | |
8341 */ | |
8342 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8343 hl_get_font_name(void) |
7 | 8344 { |
8345 int id; | |
8346 char_u *s; | |
8347 | |
8348 id = syn_name2id((char_u *)"Normal"); | |
8349 if (id > 0) | |
8350 { | |
8351 s = HL_TABLE()[id - 1].sg_font_name; | |
8352 if (s != NULL) | |
8353 return s; | |
8354 } | |
8355 return (char_u *)""; | |
8356 } | |
8357 | |
8358 /* | |
8359 * Set font for "Normal" group. Called by gui_mch_init_font() when a font has | |
8360 * actually chosen to be used. | |
8361 */ | |
8362 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8363 hl_set_font_name(char_u *font_name) |
7 | 8364 { |
8365 int id; | |
8366 | |
8367 id = syn_name2id((char_u *)"Normal"); | |
8368 if (id > 0) | |
8369 { | |
8370 vim_free(HL_TABLE()[id - 1].sg_font_name); | |
8371 HL_TABLE()[id - 1].sg_font_name = vim_strsave(font_name); | |
8372 } | |
8373 } | |
8374 | |
8375 /* | |
8376 * Set background color for "Normal" group. Called by gui_set_bg_color() | |
8377 * when the color is known. | |
8378 */ | |
8379 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8380 hl_set_bg_color_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8381 char_u *name) /* must have been allocated */ |
7 | 8382 { |
8383 int id; | |
8384 | |
8385 if (name != NULL) | |
8386 { | |
8387 id = syn_name2id((char_u *)"Normal"); | |
8388 if (id > 0) | |
8389 { | |
8390 vim_free(HL_TABLE()[id - 1].sg_gui_bg_name); | |
8391 HL_TABLE()[id - 1].sg_gui_bg_name = name; | |
8392 } | |
8393 } | |
8394 } | |
8395 | |
8396 /* | |
8397 * Set foreground color for "Normal" group. Called by gui_set_fg_color() | |
8398 * when the color is known. | |
8399 */ | |
8400 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8401 hl_set_fg_color_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8402 char_u *name) /* must have been allocated */ |
7 | 8403 { |
8404 int id; | |
8405 | |
8406 if (name != NULL) | |
8407 { | |
8408 id = syn_name2id((char_u *)"Normal"); | |
8409 if (id > 0) | |
8410 { | |
8411 vim_free(HL_TABLE()[id - 1].sg_gui_fg_name); | |
8412 HL_TABLE()[id - 1].sg_gui_fg_name = name; | |
8413 } | |
8414 } | |
8415 } | |
8416 | |
8417 /* | |
8418 * Return the handle for a font name. | |
8419 * Returns NOFONT when failed. | |
8420 */ | |
8421 static GuiFont | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8422 font_name2handle(char_u *name) |
7 | 8423 { |
8424 if (STRCMP(name, "NONE") == 0) | |
8425 return NOFONT; | |
8426 | |
8427 return gui_mch_get_font(name, TRUE); | |
8428 } | |
8429 | |
8430 # ifdef FEAT_XFONTSET | |
8431 /* | |
8432 * Return the handle for a fontset name. | |
8433 * Returns NOFONTSET when failed. | |
8434 */ | |
8435 static GuiFontset | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8436 fontset_name2handle(char_u *name, int fixed_width) |
7 | 8437 { |
8438 if (STRCMP(name, "NONE") == 0) | |
8439 return NOFONTSET; | |
8440 | |
8441 return gui_mch_get_fontset(name, TRUE, fixed_width); | |
8442 } | |
8443 # endif | |
8444 | |
8445 /* | |
8446 * Get the font or fontset for one highlight group. | |
8447 */ | |
8448 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8449 hl_do_font( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8450 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8451 char_u *arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8452 int do_normal, /* set normal font */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8453 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
|
8454 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
|
8455 int free_font) /* free current font/fontset */ |
7 | 8456 { |
8457 # ifdef FEAT_XFONTSET | |
8458 /* If 'guifontset' is not empty, first try using the name as a | |
8459 * fontset. If that doesn't work, use it as a font name. */ | |
8460 if (*p_guifontset != NUL | |
8461 # ifdef FONTSET_ALWAYS | |
8462 || do_menu | |
8463 # endif | |
8464 # ifdef FEAT_BEVAL_TIP | |
8465 /* In Athena & Motif, the Tooltip highlight group is always a fontset */ | |
8466 || do_tooltip | |
8467 # endif | |
8468 ) | |
4344 | 8469 { |
3900 | 8470 if (free_font) |
3881 | 8471 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); |
7 | 8472 HL_TABLE()[idx].sg_fontset = fontset_name2handle(arg, 0 |
8473 # ifdef FONTSET_ALWAYS | |
8474 || do_menu | |
8475 # endif | |
8476 # ifdef FEAT_BEVAL_TIP | |
8477 || do_tooltip | |
8478 # endif | |
8479 ); | |
4344 | 8480 } |
7 | 8481 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) |
8482 { | |
3881 | 8483 /* If it worked and it's the Normal group, use it as the normal |
8484 * fontset. Same for the Menu group. */ | |
7 | 8485 if (do_normal) |
8486 gui_init_font(arg, TRUE); | |
8487 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8488 if (do_menu) | |
8489 { | |
8490 # ifdef FONTSET_ALWAYS | |
8491 gui.menu_fontset = HL_TABLE()[idx].sg_fontset; | |
8492 # else | |
8493 /* YIKES! This is a bug waiting to crash the program */ | |
8494 gui.menu_font = HL_TABLE()[idx].sg_fontset; | |
8495 # endif | |
8496 gui_mch_new_menu_font(); | |
8497 } | |
8498 # ifdef FEAT_BEVAL | |
8499 if (do_tooltip) | |
8500 { | |
8501 /* The Athena widget set cannot currently handle switching between | |
8502 * displaying a single font and a fontset. | |
8503 * If the XtNinternational resource is set to True at widget | |
1222 | 8504 * creation, then a fontset is always used, otherwise an |
7 | 8505 * XFontStruct is used. |
8506 */ | |
8507 gui.tooltip_fontset = (XFontSet)HL_TABLE()[idx].sg_fontset; | |
8508 gui_mch_new_tooltip_font(); | |
8509 } | |
8510 # endif | |
8511 # endif | |
8512 } | |
8513 else | |
8514 # endif | |
8515 { | |
3881 | 8516 if (free_font) |
8517 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
7 | 8518 HL_TABLE()[idx].sg_font = font_name2handle(arg); |
8519 /* If it worked and it's the Normal group, use it as the | |
8520 * normal font. Same for the Menu group. */ | |
8521 if (HL_TABLE()[idx].sg_font != NOFONT) | |
8522 { | |
8523 if (do_normal) | |
8524 gui_init_font(arg, FALSE); | |
8525 #ifndef FONTSET_ALWAYS | |
8526 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8527 if (do_menu) | |
8528 { | |
8529 gui.menu_font = HL_TABLE()[idx].sg_font; | |
8530 gui_mch_new_menu_font(); | |
8531 } | |
8532 # endif | |
8533 #endif | |
8534 } | |
8535 } | |
8536 } | |
8537 | |
8538 #endif /* FEAT_GUI */ | |
8539 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8540 #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
|
8541 /* |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8542 * 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
|
8543 * Returns INVALCOLOR when failed. |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8544 */ |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8545 static guicolor_T |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8546 color_name2handle(char_u *name) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8547 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8548 if (STRCMP(name, "NONE") == 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8549 return INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8550 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8551 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
|
8552 { |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8553 #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
|
8554 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8555 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8556 #ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8557 return gui.norm_pixel; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8558 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8559 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8560 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
|
8561 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
|
8562 /* 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
|
8563 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
|
8564 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8565 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8566 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
|
8567 { |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8568 #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
|
8569 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8570 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8571 #ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8572 return gui.back_pixel; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8573 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8574 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8575 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
|
8576 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
|
8577 /* 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
|
8578 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
|
8579 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8580 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8581 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8582 return GUI_GET_COLOR(name); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8583 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8584 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8585 |
7 | 8586 /* |
8587 * Table with the specifications for an attribute number. | |
8588 * Note that this table is used by ALL buffers. This is required because the | |
8589 * GUI can redraw at any time for any buffer. | |
8590 */ | |
298 | 8591 static garray_T term_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8592 |
8593 #define TERM_ATTR_ENTRY(idx) ((attrentry_T *)term_attr_table.ga_data)[idx] | |
8594 | |
298 | 8595 static garray_T cterm_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8596 |
8597 #define CTERM_ATTR_ENTRY(idx) ((attrentry_T *)cterm_attr_table.ga_data)[idx] | |
8598 | |
8599 #ifdef FEAT_GUI | |
298 | 8600 static garray_T gui_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8601 |
8602 #define GUI_ATTR_ENTRY(idx) ((attrentry_T *)gui_attr_table.ga_data)[idx] | |
8603 #endif | |
8604 | |
8605 /* | |
8606 * Return the attr number for a set of colors and font. | |
8607 * Add a new entry to the term_attr_table, cterm_attr_table or gui_attr_table | |
8608 * if the combination is new. | |
8609 * Return 0 for error (no more room). | |
8610 */ | |
8611 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8612 get_attr_entry(garray_T *table, attrentry_T *aep) |
7 | 8613 { |
8614 int i; | |
359 | 8615 attrentry_T *taep; |
7 | 8616 static int recursive = FALSE; |
8617 | |
8618 /* | |
8619 * Init the table, in case it wasn't done yet. | |
8620 */ | |
8621 table->ga_itemsize = sizeof(attrentry_T); | |
8622 table->ga_growsize = 7; | |
8623 | |
8624 /* | |
8625 * Try to find an entry with the same specifications. | |
8626 */ | |
8627 for (i = 0; i < table->ga_len; ++i) | |
8628 { | |
359 | 8629 taep = &(((attrentry_T *)table->ga_data)[i]); |
8630 if ( aep->ae_attr == taep->ae_attr | |
7 | 8631 && ( |
8632 #ifdef FEAT_GUI | |
8633 (table == &gui_attr_table | |
359 | 8634 && (aep->ae_u.gui.fg_color == taep->ae_u.gui.fg_color |
8635 && aep->ae_u.gui.bg_color | |
8636 == taep->ae_u.gui.bg_color | |
8637 && aep->ae_u.gui.sp_color | |
8638 == taep->ae_u.gui.sp_color | |
8639 && aep->ae_u.gui.font == taep->ae_u.gui.font | |
7 | 8640 # ifdef FEAT_XFONTSET |
359 | 8641 && aep->ae_u.gui.fontset == taep->ae_u.gui.fontset |
7 | 8642 # endif |
8643 )) | |
8644 || | |
8645 #endif | |
8646 (table == &term_attr_table | |
359 | 8647 && (aep->ae_u.term.start == NULL) |
8648 == (taep->ae_u.term.start == NULL) | |
7 | 8649 && (aep->ae_u.term.start == NULL |
8650 || STRCMP(aep->ae_u.term.start, | |
359 | 8651 taep->ae_u.term.start) == 0) |
8652 && (aep->ae_u.term.stop == NULL) | |
8653 == (taep->ae_u.term.stop == NULL) | |
7 | 8654 && (aep->ae_u.term.stop == NULL |
8655 || STRCMP(aep->ae_u.term.stop, | |
359 | 8656 taep->ae_u.term.stop) == 0)) |
7 | 8657 || (table == &cterm_attr_table |
359 | 8658 && aep->ae_u.cterm.fg_color |
8659 == taep->ae_u.cterm.fg_color | |
8660 && 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
|
8661 == 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
|
8662 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8663 && aep->ae_u.cterm.fg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8664 == taep->ae_u.cterm.fg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8665 && aep->ae_u.cterm.bg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8666 == taep->ae_u.cterm.bg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8667 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8668 ))) |
7 | 8669 |
8670 return i + ATTR_OFF; | |
8671 } | |
8672 | |
271 | 8673 if (table->ga_len + ATTR_OFF > MAX_TYPENR) |
7 | 8674 { |
8675 /* | |
8676 * Running out of attribute entries! remove all attributes, and | |
8677 * compute new ones for all groups. | |
8678 * When called recursively, we are really out of numbers. | |
8679 */ | |
8680 if (recursive) | |
8681 { | |
8682 EMSG(_("E424: Too many different highlighting attributes in use")); | |
8683 return 0; | |
8684 } | |
8685 recursive = TRUE; | |
8686 | |
359 | 8687 clear_hl_tables(); |
8688 | |
7 | 8689 must_redraw = CLEAR; |
8690 | |
8691 for (i = 0; i < highlight_ga.ga_len; ++i) | |
8692 set_hl_attr(i); | |
8693 | |
8694 recursive = FALSE; | |
8695 } | |
8696 | |
8697 /* | |
8698 * This is a new combination of colors and font, add an entry. | |
8699 */ | |
8700 if (ga_grow(table, 1) == FAIL) | |
8701 return 0; | |
8702 | |
359 | 8703 taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); |
8704 vim_memset(taep, 0, sizeof(attrentry_T)); | |
8705 taep->ae_attr = aep->ae_attr; | |
7 | 8706 #ifdef FEAT_GUI |
8707 if (table == &gui_attr_table) | |
8708 { | |
359 | 8709 taep->ae_u.gui.fg_color = aep->ae_u.gui.fg_color; |
8710 taep->ae_u.gui.bg_color = aep->ae_u.gui.bg_color; | |
8711 taep->ae_u.gui.sp_color = aep->ae_u.gui.sp_color; | |
8712 taep->ae_u.gui.font = aep->ae_u.gui.font; | |
7 | 8713 # ifdef FEAT_XFONTSET |
359 | 8714 taep->ae_u.gui.fontset = aep->ae_u.gui.fontset; |
7 | 8715 # endif |
8716 } | |
8717 #endif | |
8718 if (table == &term_attr_table) | |
8719 { | |
8720 if (aep->ae_u.term.start == NULL) | |
359 | 8721 taep->ae_u.term.start = NULL; |
7 | 8722 else |
359 | 8723 taep->ae_u.term.start = vim_strsave(aep->ae_u.term.start); |
7 | 8724 if (aep->ae_u.term.stop == NULL) |
359 | 8725 taep->ae_u.term.stop = NULL; |
7 | 8726 else |
359 | 8727 taep->ae_u.term.stop = vim_strsave(aep->ae_u.term.stop); |
7 | 8728 } |
8729 else if (table == &cterm_attr_table) | |
8730 { | |
359 | 8731 taep->ae_u.cterm.fg_color = aep->ae_u.cterm.fg_color; |
8732 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
|
8733 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8734 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
|
8735 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
|
8736 #endif |
7 | 8737 } |
8738 ++table->ga_len; | |
8739 return (table->ga_len - 1 + ATTR_OFF); | |
8740 } | |
8741 | |
359 | 8742 /* |
8743 * Clear all highlight tables. | |
8744 */ | |
8745 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8746 clear_hl_tables(void) |
359 | 8747 { |
8748 int i; | |
8749 attrentry_T *taep; | |
8750 | |
8751 #ifdef FEAT_GUI | |
8752 ga_clear(&gui_attr_table); | |
8753 #endif | |
8754 for (i = 0; i < term_attr_table.ga_len; ++i) | |
8755 { | |
8756 taep = &(((attrentry_T *)term_attr_table.ga_data)[i]); | |
8757 vim_free(taep->ae_u.term.start); | |
8758 vim_free(taep->ae_u.term.stop); | |
8759 } | |
8760 ga_clear(&term_attr_table); | |
8761 ga_clear(&cterm_attr_table); | |
8762 } | |
8763 | |
745 | 8764 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL) || defined(PROTO) |
221 | 8765 /* |
348 | 8766 * Combine special attributes (e.g., for spelling) with other attributes |
8767 * (e.g., for syntax highlighting). | |
8768 * "prim_attr" overrules "char_attr". | |
221 | 8769 * This creates a new group when required. |
8770 * Since we expect there to be few spelling mistakes we don't cache the | |
8771 * result. | |
8772 * Return the resulting attributes. | |
8773 */ | |
8774 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8775 hl_combine_attr(int char_attr, int prim_attr) |
221 | 8776 { |
8777 attrentry_T *char_aep = NULL; | |
8778 attrentry_T *spell_aep; | |
8779 attrentry_T new_en; | |
8780 | |
8781 if (char_attr == 0) | |
348 | 8782 return prim_attr; |
8783 if (char_attr <= HL_ALL && prim_attr <= HL_ALL) | |
8784 return char_attr | prim_attr; | |
221 | 8785 #ifdef FEAT_GUI |
8786 if (gui.in_use) | |
8787 { | |
8788 if (char_attr > HL_ALL) | |
8789 char_aep = syn_gui_attr2entry(char_attr); | |
8790 if (char_aep != NULL) | |
8791 new_en = *char_aep; | |
8792 else | |
8793 { | |
8794 vim_memset(&new_en, 0, sizeof(new_en)); | |
548 | 8795 new_en.ae_u.gui.fg_color = INVALCOLOR; |
8796 new_en.ae_u.gui.bg_color = INVALCOLOR; | |
8797 new_en.ae_u.gui.sp_color = INVALCOLOR; | |
221 | 8798 if (char_attr <= HL_ALL) |
8799 new_en.ae_attr = char_attr; | |
8800 } | |
8801 | |
348 | 8802 if (prim_attr <= HL_ALL) |
8803 new_en.ae_attr |= prim_attr; | |
221 | 8804 else |
8805 { | |
348 | 8806 spell_aep = syn_gui_attr2entry(prim_attr); |
221 | 8807 if (spell_aep != NULL) |
8808 { | |
8809 new_en.ae_attr |= spell_aep->ae_attr; | |
8810 if (spell_aep->ae_u.gui.fg_color != INVALCOLOR) | |
8811 new_en.ae_u.gui.fg_color = spell_aep->ae_u.gui.fg_color; | |
8812 if (spell_aep->ae_u.gui.bg_color != INVALCOLOR) | |
8813 new_en.ae_u.gui.bg_color = spell_aep->ae_u.gui.bg_color; | |
8814 if (spell_aep->ae_u.gui.sp_color != INVALCOLOR) | |
8815 new_en.ae_u.gui.sp_color = spell_aep->ae_u.gui.sp_color; | |
8816 if (spell_aep->ae_u.gui.font != NOFONT) | |
8817 new_en.ae_u.gui.font = spell_aep->ae_u.gui.font; | |
8818 # ifdef FEAT_XFONTSET | |
8819 if (spell_aep->ae_u.gui.fontset != NOFONTSET) | |
8820 new_en.ae_u.gui.fontset = spell_aep->ae_u.gui.fontset; | |
8821 # endif | |
8822 } | |
8823 } | |
8824 return get_attr_entry(&gui_attr_table, &new_en); | |
8825 } | |
8826 #endif | |
8827 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8828 if (IS_CTERM) |
221 | 8829 { |
8830 if (char_attr > HL_ALL) | |
8831 char_aep = syn_cterm_attr2entry(char_attr); | |
8832 if (char_aep != NULL) | |
8833 new_en = *char_aep; | |
8834 else | |
8835 { | |
8836 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
|
8837 #ifdef FEAT_TERMGUICOLORS |
e88ffb09ff38
commit https://github.com/vim/vim/commit/0cdb72aa38c4a0140c94d56bf8bc17cb30260ebf
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
8838 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
|
8839 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
|
8840 #endif |
221 | 8841 if (char_attr <= HL_ALL) |
8842 new_en.ae_attr = char_attr; | |
8843 } | |
8844 | |
348 | 8845 if (prim_attr <= HL_ALL) |
8846 new_en.ae_attr |= prim_attr; | |
221 | 8847 else |
8848 { | |
348 | 8849 spell_aep = syn_cterm_attr2entry(prim_attr); |
221 | 8850 if (spell_aep != NULL) |
8851 { | |
8852 new_en.ae_attr |= spell_aep->ae_attr; | |
8853 if (spell_aep->ae_u.cterm.fg_color > 0) | |
8854 new_en.ae_u.cterm.fg_color = spell_aep->ae_u.cterm.fg_color; | |
8855 if (spell_aep->ae_u.cterm.bg_color > 0) | |
8856 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
|
8857 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8858 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
|
8859 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
|
8860 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
|
8861 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
|
8862 #endif |
221 | 8863 } |
8864 } | |
8865 return get_attr_entry(&cterm_attr_table, &new_en); | |
8866 } | |
8867 | |
8868 if (char_attr > HL_ALL) | |
8869 char_aep = syn_term_attr2entry(char_attr); | |
8870 if (char_aep != NULL) | |
8871 new_en = *char_aep; | |
8872 else | |
8873 { | |
8874 vim_memset(&new_en, 0, sizeof(new_en)); | |
8875 if (char_attr <= HL_ALL) | |
8876 new_en.ae_attr = char_attr; | |
8877 } | |
8878 | |
348 | 8879 if (prim_attr <= HL_ALL) |
8880 new_en.ae_attr |= prim_attr; | |
221 | 8881 else |
8882 { | |
607 | 8883 spell_aep = syn_term_attr2entry(prim_attr); |
221 | 8884 if (spell_aep != NULL) |
8885 { | |
8886 new_en.ae_attr |= spell_aep->ae_attr; | |
8887 if (spell_aep->ae_u.term.start != NULL) | |
8888 { | |
8889 new_en.ae_u.term.start = spell_aep->ae_u.term.start; | |
8890 new_en.ae_u.term.stop = spell_aep->ae_u.term.stop; | |
8891 } | |
8892 } | |
8893 } | |
8894 return get_attr_entry(&term_attr_table, &new_en); | |
8895 } | |
8896 #endif | |
8897 | |
7 | 8898 #ifdef FEAT_GUI |
8899 | |
8900 attrentry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8901 syn_gui_attr2entry(int attr) |
7 | 8902 { |
8903 attr -= ATTR_OFF; | |
8904 if (attr >= gui_attr_table.ga_len) /* did ":syntax clear" */ | |
8905 return NULL; | |
8906 return &(GUI_ATTR_ENTRY(attr)); | |
8907 } | |
8908 #endif /* FEAT_GUI */ | |
8909 | |
745 | 8910 /* |
8911 * Get the highlight attributes (HL_BOLD etc.) from an attribute nr. | |
8912 * Only to be used when "attr" > HL_ALL. | |
8913 */ | |
8914 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8915 syn_attr2attr(int attr) |
745 | 8916 { |
8917 attrentry_T *aep; | |
8918 | |
8919 #ifdef FEAT_GUI | |
8920 if (gui.in_use) | |
8921 aep = syn_gui_attr2entry(attr); | |
8922 else | |
8923 #endif | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8924 if (IS_CTERM) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8925 aep = syn_cterm_attr2entry(attr); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8926 else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8927 aep = syn_term_attr2entry(attr); |
745 | 8928 |
8929 if (aep == NULL) /* highlighting not set */ | |
8930 return 0; | |
8931 return aep->ae_attr; | |
8932 } | |
8933 | |
8934 | |
7 | 8935 attrentry_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8936 syn_term_attr2entry(int attr) |
7 | 8937 { |
8938 attr -= ATTR_OFF; | |
8939 if (attr >= term_attr_table.ga_len) /* did ":syntax clear" */ | |
8940 return NULL; | |
8941 return &(TERM_ATTR_ENTRY(attr)); | |
8942 } | |
8943 | |
8944 attrentry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8945 syn_cterm_attr2entry(int attr) |
7 | 8946 { |
8947 attr -= ATTR_OFF; | |
8948 if (attr >= cterm_attr_table.ga_len) /* did ":syntax clear" */ | |
8949 return NULL; | |
8950 return &(CTERM_ATTR_ENTRY(attr)); | |
8951 } | |
8952 | |
8953 #define LIST_ATTR 1 | |
8954 #define LIST_STRING 2 | |
8955 #define LIST_INT 3 | |
8956 | |
8957 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8958 highlight_list_one(int id) |
7 | 8959 { |
8960 struct hl_group *sgp; | |
8961 int didh = FALSE; | |
8962 | |
8963 sgp = &HL_TABLE()[id - 1]; /* index is ID minus one */ | |
8964 | |
8965 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8966 sgp->sg_term, NULL, "term"); | |
8967 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8968 0, sgp->sg_start, "start"); | |
8969 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8970 0, sgp->sg_stop, "stop"); | |
8971 | |
8972 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
8973 sgp->sg_cterm, NULL, "cterm"); | |
8974 didh = highlight_list_arg(id, didh, LIST_INT, | |
8975 sgp->sg_cterm_fg, NULL, "ctermfg"); | |
8976 didh = highlight_list_arg(id, didh, LIST_INT, | |
8977 sgp->sg_cterm_bg, NULL, "ctermbg"); | |
8978 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8979 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 8980 didh = highlight_list_arg(id, didh, LIST_ATTR, |
8981 sgp->sg_gui, NULL, "gui"); | |
8982 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8983 0, sgp->sg_gui_fg_name, "guifg"); | |
8984 didh = highlight_list_arg(id, didh, LIST_STRING, | |
8985 0, sgp->sg_gui_bg_name, "guibg"); | |
8986 didh = highlight_list_arg(id, didh, LIST_STRING, | |
301 | 8987 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
|
8988 #endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8989 #ifdef FEAT_GUI |
301 | 8990 didh = highlight_list_arg(id, didh, LIST_STRING, |
7 | 8991 0, sgp->sg_font_name, "font"); |
8992 #endif | |
8993 | |
448 | 8994 if (sgp->sg_link && !got_int) |
7 | 8995 { |
8996 (void)syn_list_header(didh, 9999, id); | |
448 | 8997 didh = TRUE; |
7 | 8998 msg_puts_attr((char_u *)"links to", hl_attr(HLF_D)); |
8999 msg_putchar(' '); | |
9000 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
9001 } | |
448 | 9002 |
694 | 9003 if (!didh) |
9004 highlight_list_arg(id, didh, LIST_STRING, 0, (char_u *)"cleared", ""); | |
448 | 9005 #ifdef FEAT_EVAL |
694 | 9006 if (p_verbose > 0) |
448 | 9007 last_set_msg(sgp->sg_scriptID); |
9008 #endif | |
7 | 9009 } |
9010 | |
9011 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9012 highlight_list_arg( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9013 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9014 int didh, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9015 int type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9016 int iarg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9017 char_u *sarg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9018 char *name) |
7 | 9019 { |
9020 char_u buf[100]; | |
9021 char_u *ts; | |
9022 int i; | |
9023 | |
448 | 9024 if (got_int) |
9025 return FALSE; | |
7 | 9026 if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) |
9027 { | |
9028 ts = buf; | |
9029 if (type == LIST_INT) | |
9030 sprintf((char *)buf, "%d", iarg - 1); | |
9031 else if (type == LIST_STRING) | |
9032 ts = sarg; | |
9033 else /* type == LIST_ATTR */ | |
9034 { | |
9035 buf[0] = NUL; | |
9036 for (i = 0; hl_attr_table[i] != 0; ++i) | |
9037 { | |
9038 if (iarg & hl_attr_table[i]) | |
9039 { | |
9040 if (buf[0] != NUL) | |
2768 | 9041 vim_strcat(buf, (char_u *)",", 100); |
9042 vim_strcat(buf, (char_u *)hl_name_table[i], 100); | |
7 | 9043 iarg &= ~hl_attr_table[i]; /* don't want "inverse" */ |
9044 } | |
9045 } | |
9046 } | |
9047 | |
9048 (void)syn_list_header(didh, | |
9049 (int)(vim_strsize(ts) + STRLEN(name) + 1), id); | |
9050 didh = TRUE; | |
448 | 9051 if (!got_int) |
9052 { | |
694 | 9053 if (*name != NUL) |
9054 { | |
9055 MSG_PUTS_ATTR(name, hl_attr(HLF_D)); | |
9056 MSG_PUTS_ATTR("=", hl_attr(HLF_D)); | |
9057 } | |
448 | 9058 msg_outtrans(ts); |
9059 } | |
7 | 9060 } |
9061 return didh; | |
9062 } | |
9063 | |
9064 #if (((defined(FEAT_EVAL) || defined(FEAT_PRINTER))) && defined(FEAT_SYN_HL)) || defined(PROTO) | |
9065 /* | |
9066 * Return "1" if highlight group "id" has attribute "flag". | |
9067 * Return NULL otherwise. | |
9068 */ | |
9069 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9070 highlight_has_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9071 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9072 int flag, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9073 int modec) /* 'g' for GUI, 'c' for cterm, 't' for term */ |
7 | 9074 { |
9075 int attr; | |
9076 | |
9077 if (id <= 0 || id > highlight_ga.ga_len) | |
9078 return NULL; | |
9079 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9080 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9081 if (modec == 'g') |
9082 attr = HL_TABLE()[id - 1].sg_gui; | |
9083 else | |
9084 #endif | |
9085 if (modec == 'c') | |
9086 attr = HL_TABLE()[id - 1].sg_cterm; | |
9087 else | |
9088 attr = HL_TABLE()[id - 1].sg_term; | |
9089 | |
9090 if (attr & flag) | |
9091 return (char_u *)"1"; | |
9092 return NULL; | |
9093 } | |
9094 #endif | |
9095 | |
9096 #if (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) || defined(PROTO) | |
9097 /* | |
9098 * Return color name of highlight group "id". | |
9099 */ | |
9100 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9101 highlight_color( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9102 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9103 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
|
9104 int modec) /* 'g' for GUI, 'c' for cterm, 't' for term */ |
7 | 9105 { |
9106 static char_u name[20]; | |
9107 int n; | |
205 | 9108 int fg = FALSE; |
9109 int sp = FALSE; | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9110 int font = FALSE; |
7 | 9111 |
9112 if (id <= 0 || id > highlight_ga.ga_len) | |
9113 return NULL; | |
9114 | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9115 if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g') |
7 | 9116 fg = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9117 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
|
9118 && 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
|
9119 font = TRUE; |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9120 else if (TOLOWER_ASC(what[0]) == 's' && TOLOWER_ASC(what[1]) == 'p') |
205 | 9121 sp = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9122 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
|
9123 return NULL; |
7 | 9124 if (modec == 'g') |
9125 { | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9126 # 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
|
9127 # ifdef FEAT_GUI |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9128 /* return font name */ |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9129 if (font) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9130 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
|
9131 # endif |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9132 |
7 | 9133 /* 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
|
9134 if ((USE_24BIT) && what[2] == '#') |
7 | 9135 { |
9136 guicolor_T color; | |
9137 long_u rgb; | |
9138 static char_u buf[10]; | |
9139 | |
9140 if (fg) | |
9141 color = HL_TABLE()[id - 1].sg_gui_fg; | |
205 | 9142 else if (sp) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9143 # ifdef FEAT_GUI |
205 | 9144 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
|
9145 # else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9146 color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9147 # endif |
7 | 9148 else |
9149 color = HL_TABLE()[id - 1].sg_gui_bg; | |
9150 if (color == INVALCOLOR) | |
9151 return NULL; | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
9152 rgb = (long_u)GUI_MCH_GET_RGB(color); |
7 | 9153 sprintf((char *)buf, "#%02x%02x%02x", |
9154 (unsigned)(rgb >> 16), | |
9155 (unsigned)(rgb >> 8) & 255, | |
9156 (unsigned)rgb & 255); | |
9157 return buf; | |
9158 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9159 # endif |
7 | 9160 if (fg) |
9161 return (HL_TABLE()[id - 1].sg_gui_fg_name); | |
205 | 9162 if (sp) |
9163 return (HL_TABLE()[id - 1].sg_gui_sp_name); | |
7 | 9164 return (HL_TABLE()[id - 1].sg_gui_bg_name); |
9165 } | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9166 if (font || sp) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9167 return NULL; |
7 | 9168 if (modec == 'c') |
9169 { | |
9170 if (fg) | |
9171 n = HL_TABLE()[id - 1].sg_cterm_fg - 1; | |
9172 else | |
9173 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
|
9174 if (n < 0) |
260d01c1cd17
commit https://github.com/vim/vim/commit/385111bd86e0b38667879c3e89506ca1ae98e1df
Christian Brabandt <cb@256bit.org>
parents:
8362
diff
changeset
|
9175 return NULL; |
7 | 9176 sprintf((char *)name, "%d", n); |
9177 return name; | |
9178 } | |
9179 /* term doesn't have color */ | |
9180 return NULL; | |
9181 } | |
9182 #endif | |
9183 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9184 #if (defined(FEAT_SYN_HL) \ |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9185 && (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
|
9186 && defined(FEAT_PRINTER)) || defined(PROTO) |
7 | 9187 /* |
9188 * Return color name of highlight group "id" as RGB value. | |
9189 */ | |
9190 long_u | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9191 highlight_gui_color_rgb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9192 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9193 int fg) /* TRUE = fg, FALSE = bg */ |
7 | 9194 { |
9195 guicolor_T color; | |
9196 | |
9197 if (id <= 0 || id > highlight_ga.ga_len) | |
9198 return 0L; | |
9199 | |
9200 if (fg) | |
9201 color = HL_TABLE()[id - 1].sg_gui_fg; | |
9202 else | |
9203 color = HL_TABLE()[id - 1].sg_gui_bg; | |
9204 | |
9205 if (color == INVALCOLOR) | |
9206 return 0L; | |
9207 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9208 return GUI_MCH_GET_RGB(color); |
7 | 9209 } |
9210 #endif | |
9211 | |
9212 /* | |
9213 * Output the syntax list header. | |
9214 * Return TRUE when started a new line. | |
9215 */ | |
9216 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9217 syn_list_header( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9218 int did_header, /* did header already */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9219 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
|
9220 int id) /* highlight group id */ |
7 | 9221 { |
9222 int endcol = 19; | |
9223 int newline = TRUE; | |
9224 | |
9225 if (!did_header) | |
9226 { | |
9227 msg_putchar('\n'); | |
448 | 9228 if (got_int) |
9229 return TRUE; | |
7 | 9230 msg_outtrans(HL_TABLE()[id - 1].sg_name); |
9231 endcol = 15; | |
9232 } | |
9233 else if (msg_col + outlen + 1 >= Columns) | |
448 | 9234 { |
7 | 9235 msg_putchar('\n'); |
448 | 9236 if (got_int) |
9237 return TRUE; | |
9238 } | |
7 | 9239 else |
9240 { | |
9241 if (msg_col >= endcol) /* wrap around is like starting a new line */ | |
9242 newline = FALSE; | |
9243 } | |
9244 | |
9245 if (msg_col >= endcol) /* output at least one space */ | |
9246 endcol = msg_col + 1; | |
9247 if (Columns <= endcol) /* avoid hang for tiny window */ | |
9248 endcol = Columns - 1; | |
9249 | |
9250 msg_advance(endcol); | |
9251 | |
9252 /* Show "xxx" with the attributes. */ | |
9253 if (!did_header) | |
9254 { | |
9255 msg_puts_attr((char_u *)"xxx", syn_id2attr(id)); | |
9256 msg_putchar(' '); | |
9257 } | |
9258 | |
9259 return newline; | |
9260 } | |
9261 | |
9262 /* | |
9263 * Set the attribute numbers for a highlight group. | |
9264 * Called after one of the attributes has changed. | |
9265 */ | |
9266 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9267 set_hl_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9268 int idx) /* index in array */ |
7 | 9269 { |
9270 attrentry_T at_en; | |
9271 struct hl_group *sgp = HL_TABLE() + idx; | |
9272 | |
9273 /* The "Normal" group doesn't need an attribute number */ | |
9274 if (sgp->sg_name_u != NULL && STRCMP(sgp->sg_name_u, "NORMAL") == 0) | |
9275 return; | |
9276 | |
9277 #ifdef FEAT_GUI | |
9278 /* | |
9279 * For the GUI mode: If there are other than "normal" highlighting | |
9280 * attributes, need to allocate an attr number. | |
9281 */ | |
9282 if (sgp->sg_gui_fg == INVALCOLOR | |
9283 && sgp->sg_gui_bg == INVALCOLOR | |
205 | 9284 && sgp->sg_gui_sp == INVALCOLOR |
7 | 9285 && sgp->sg_font == NOFONT |
9286 # ifdef FEAT_XFONTSET | |
9287 && sgp->sg_fontset == NOFONTSET | |
9288 # endif | |
9289 ) | |
9290 { | |
9291 sgp->sg_gui_attr = sgp->sg_gui; | |
9292 } | |
9293 else | |
9294 { | |
9295 at_en.ae_attr = sgp->sg_gui; | |
9296 at_en.ae_u.gui.fg_color = sgp->sg_gui_fg; | |
9297 at_en.ae_u.gui.bg_color = sgp->sg_gui_bg; | |
205 | 9298 at_en.ae_u.gui.sp_color = sgp->sg_gui_sp; |
7 | 9299 at_en.ae_u.gui.font = sgp->sg_font; |
9300 # ifdef FEAT_XFONTSET | |
9301 at_en.ae_u.gui.fontset = sgp->sg_fontset; | |
9302 # endif | |
9303 sgp->sg_gui_attr = get_attr_entry(&gui_attr_table, &at_en); | |
9304 } | |
9305 #endif | |
9306 /* | |
9307 * For the term mode: If there are other than "normal" highlighting | |
9308 * attributes, need to allocate an attr number. | |
9309 */ | |
9310 if (sgp->sg_start == NULL && sgp->sg_stop == NULL) | |
9311 sgp->sg_term_attr = sgp->sg_term; | |
9312 else | |
9313 { | |
9314 at_en.ae_attr = sgp->sg_term; | |
9315 at_en.ae_u.term.start = sgp->sg_start; | |
9316 at_en.ae_u.term.stop = sgp->sg_stop; | |
9317 sgp->sg_term_attr = get_attr_entry(&term_attr_table, &at_en); | |
9318 } | |
9319 | |
9320 /* | |
9321 * For the color term mode: If there are other than "normal" | |
9322 * highlighting attributes, need to allocate an attr number. | |
9323 */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9324 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
|
9325 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9326 && sgp->sg_gui_fg == INVALCOLOR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9327 && sgp->sg_gui_bg == INVALCOLOR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9328 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9329 ) |
7 | 9330 sgp->sg_cterm_attr = sgp->sg_cterm; |
9331 else | |
9332 { | |
9333 at_en.ae_attr = sgp->sg_cterm; | |
9334 at_en.ae_u.cterm.fg_color = sgp->sg_cterm_fg; | |
9335 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
|
9336 # ifdef FEAT_TERMGUICOLORS |
9054
f129fd3ebd98
commit https://github.com/vim/vim/commit/187147aedd588070d0676664d5076d046644094e
Christian Brabandt <cb@256bit.org>
parents:
9029
diff
changeset
|
9337 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
|
9338 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
|
9339 # endif |
7 | 9340 sgp->sg_cterm_attr = get_attr_entry(&cterm_attr_table, &at_en); |
9341 } | |
9342 } | |
9343 | |
9344 /* | |
9345 * Lookup a highlight group name and return it's ID. | |
9346 * If it is not found, 0 is returned. | |
9347 */ | |
9348 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9349 syn_name2id(char_u *name) |
7 | 9350 { |
9351 int i; | |
9352 char_u name_u[200]; | |
9353 | |
9354 /* Avoid using stricmp() too much, it's slow on some systems */ | |
9355 /* Avoid alloc()/free(), these are slow too. ID names over 200 chars | |
9356 * don't deserve to be found! */ | |
419 | 9357 vim_strncpy(name_u, name, 199); |
7 | 9358 vim_strup(name_u); |
9359 for (i = highlight_ga.ga_len; --i >= 0; ) | |
9360 if (HL_TABLE()[i].sg_name_u != NULL | |
9361 && STRCMP(name_u, HL_TABLE()[i].sg_name_u) == 0) | |
9362 break; | |
9363 return i + 1; | |
9364 } | |
9365 | |
9366 #if defined(FEAT_EVAL) || defined(PROTO) | |
9367 /* | |
9368 * Return TRUE if highlight group "name" exists. | |
9369 */ | |
9370 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9371 highlight_exists(char_u *name) |
7 | 9372 { |
9373 return (syn_name2id(name) > 0); | |
9374 } | |
819 | 9375 |
9376 # if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) | |
9377 /* | |
9378 * Return the name of highlight group "id". | |
9379 * When not a valid ID return an empty string. | |
9380 */ | |
9381 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9382 syn_id2name(int id) |
819 | 9383 { |
1326 | 9384 if (id <= 0 || id > highlight_ga.ga_len) |
819 | 9385 return (char_u *)""; |
9386 return HL_TABLE()[id - 1].sg_name; | |
9387 } | |
9388 # endif | |
7 | 9389 #endif |
9390 | |
9391 /* | |
9392 * Like syn_name2id(), but take a pointer + length argument. | |
9393 */ | |
9394 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9395 syn_namen2id(char_u *linep, int len) |
7 | 9396 { |
9397 char_u *name; | |
9398 int id = 0; | |
9399 | |
9400 name = vim_strnsave(linep, len); | |
9401 if (name != NULL) | |
9402 { | |
9403 id = syn_name2id(name); | |
9404 vim_free(name); | |
9405 } | |
9406 return id; | |
9407 } | |
9408 | |
9409 /* | |
9410 * Find highlight group name in the table and return it's ID. | |
9411 * The argument is a pointer to the name and the length of the name. | |
9412 * If it doesn't exist yet, a new entry is created. | |
9413 * Return 0 for failure. | |
9414 */ | |
9415 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9416 syn_check_group(char_u *pp, int len) |
7 | 9417 { |
9418 int id; | |
9419 char_u *name; | |
9420 | |
9421 name = vim_strnsave(pp, len); | |
9422 if (name == NULL) | |
9423 return 0; | |
9424 | |
9425 id = syn_name2id(name); | |
9426 if (id == 0) /* doesn't exist yet */ | |
9427 id = syn_add_group(name); | |
9428 else | |
9429 vim_free(name); | |
9430 return id; | |
9431 } | |
9432 | |
9433 /* | |
9434 * Add new highlight group and return it's ID. | |
9435 * "name" must be an allocated string, it will be consumed. | |
9436 * Return 0 for failure. | |
9437 */ | |
9438 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9439 syn_add_group(char_u *name) |
7 | 9440 { |
9441 char_u *p; | |
9442 | |
9443 /* Check that the name is ASCII letters, digits and underscore. */ | |
9444 for (p = name; *p != NUL; ++p) | |
9445 { | |
9446 if (!vim_isprintc(*p)) | |
9447 { | |
9448 EMSG(_("E669: Unprintable character in group name")); | |
2020 | 9449 vim_free(name); |
7 | 9450 return 0; |
9451 } | |
9452 else if (!ASCII_ISALNUM(*p) && *p != '_') | |
9453 { | |
9454 /* This is an error, but since there previously was no check only | |
9455 * give a warning. */ | |
16 | 9456 msg_source(hl_attr(HLF_W)); |
7 | 9457 MSG(_("W18: Invalid character in group name")); |
9458 break; | |
9459 } | |
9460 } | |
9461 | |
9462 /* | |
9463 * First call for this growarray: init growing array. | |
9464 */ | |
9465 if (highlight_ga.ga_data == NULL) | |
9466 { | |
9467 highlight_ga.ga_itemsize = sizeof(struct hl_group); | |
9468 highlight_ga.ga_growsize = 10; | |
9469 } | |
9470 | |
2756 | 9471 if (highlight_ga.ga_len >= MAX_HL_ID) |
9472 { | |
9473 EMSG(_("E849: Too many highlight and syntax groups")); | |
2743 | 9474 vim_free(name); |
9475 return 0; | |
9476 } | |
9477 | |
7 | 9478 /* |
9479 * Make room for at least one other syntax_highlight entry. | |
9480 */ | |
9481 if (ga_grow(&highlight_ga, 1) == FAIL) | |
9482 { | |
9483 vim_free(name); | |
9484 return 0; | |
9485 } | |
9486 | |
9487 vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(struct hl_group)); | |
9488 HL_TABLE()[highlight_ga.ga_len].sg_name = name; | |
9489 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
|
9490 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 9491 HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR; |
9492 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
|
9493 # ifdef FEAT_GUI |
205 | 9494 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
|
9495 # endif |
7 | 9496 #endif |
9497 ++highlight_ga.ga_len; | |
9498 | |
9499 return highlight_ga.ga_len; /* ID is index plus one */ | |
9500 } | |
9501 | |
9502 /* | |
9503 * When, just after calling syn_add_group(), an error is discovered, this | |
9504 * function deletes the new name. | |
9505 */ | |
9506 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9507 syn_unadd_group(void) |
7 | 9508 { |
9509 --highlight_ga.ga_len; | |
9510 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name); | |
9511 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); | |
9512 } | |
9513 | |
9514 /* | |
9515 * Translate a group ID to highlight attributes. | |
9516 */ | |
9517 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9518 syn_id2attr(int hl_id) |
7 | 9519 { |
9520 int attr; | |
9521 struct hl_group *sgp; | |
9522 | |
9523 hl_id = syn_get_final_id(hl_id); | |
9524 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9525 | |
9526 #ifdef FEAT_GUI | |
9527 /* | |
9528 * Only use GUI attr when the GUI is being used. | |
9529 */ | |
9530 if (gui.in_use) | |
9531 attr = sgp->sg_gui_attr; | |
9532 else | |
9533 #endif | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9534 if (IS_CTERM) |
7 | 9535 attr = sgp->sg_cterm_attr; |
9536 else | |
9537 attr = sgp->sg_term_attr; | |
9538 | |
9539 return attr; | |
9540 } | |
9541 | |
9542 #ifdef FEAT_GUI | |
9543 /* | |
9544 * Get the GUI colors and attributes for a group ID. | |
9545 * NOTE: the colors will be INVALCOLOR when not set, the color otherwise. | |
9546 */ | |
9547 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9548 syn_id2colors(int hl_id, guicolor_T *fgp, guicolor_T *bgp) |
7 | 9549 { |
9550 struct hl_group *sgp; | |
9551 | |
9552 hl_id = syn_get_final_id(hl_id); | |
9553 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9554 | |
9555 *fgp = sgp->sg_gui_fg; | |
9556 *bgp = sgp->sg_gui_bg; | |
9557 return sgp->sg_gui; | |
9558 } | |
9559 #endif | |
9560 | |
9561 /* | |
9562 * Translate a group ID to the final group ID (following links). | |
9563 */ | |
9564 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9565 syn_get_final_id(int hl_id) |
7 | 9566 { |
9567 int count; | |
9568 struct hl_group *sgp; | |
9569 | |
9570 if (hl_id > highlight_ga.ga_len || hl_id < 1) | |
9571 return 0; /* Can be called from eval!! */ | |
9572 | |
9573 /* | |
9574 * Follow links until there is no more. | |
9575 * Look out for loops! Break after 100 links. | |
9576 */ | |
9577 for (count = 100; --count >= 0; ) | |
9578 { | |
9579 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9580 if (sgp->sg_link == 0 || sgp->sg_link > highlight_ga.ga_len) | |
9581 break; | |
9582 hl_id = sgp->sg_link; | |
9583 } | |
9584 | |
9585 return hl_id; | |
9586 } | |
9587 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9588 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 9589 /* |
9590 * Call this function just after the GUI has started. | |
9591 * It finds the font and color handles for the highlighting groups. | |
9592 */ | |
9593 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9594 highlight_gui_started(void) |
7 | 9595 { |
9596 int idx; | |
9597 | |
9598 /* 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
|
9599 # 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
|
9600 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9601 if (USE_24BIT) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9602 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9603 set_normal_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9604 # endif |
7 | 9605 |
9606 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9607 gui_do_one_color(idx, FALSE, FALSE); | |
9608 | |
9609 highlight_changed(); | |
9610 } | |
9611 | |
9612 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9613 gui_do_one_color( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9614 int idx, |
8975
9c097bfad637
commit https://github.com/vim/vim/commit/380130f1e18da92a44372728fe044f56db58585b
Christian Brabandt <cb@256bit.org>
parents:
8969
diff
changeset
|
9615 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
|
9616 int do_tooltip UNUSED) /* TRUE: might set the tooltip font */ |
7 | 9617 { |
9618 int didit = FALSE; | |
9619 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9620 # ifdef FEAT_GUI |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9621 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9622 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9623 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9624 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
|
9625 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9626 hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu, |
3881 | 9627 do_tooltip, TRUE); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9628 didit = TRUE; |
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 # endif |
7 | 9631 if (HL_TABLE()[idx].sg_gui_fg_name != NULL) |
9632 { | |
9633 HL_TABLE()[idx].sg_gui_fg = | |
9634 color_name2handle(HL_TABLE()[idx].sg_gui_fg_name); | |
9635 didit = TRUE; | |
9636 } | |
9637 if (HL_TABLE()[idx].sg_gui_bg_name != NULL) | |
9638 { | |
9639 HL_TABLE()[idx].sg_gui_bg = | |
9640 color_name2handle(HL_TABLE()[idx].sg_gui_bg_name); | |
9641 didit = TRUE; | |
9642 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9643 # ifdef FEAT_GUI |
205 | 9644 if (HL_TABLE()[idx].sg_gui_sp_name != NULL) |
9645 { | |
9646 HL_TABLE()[idx].sg_gui_sp = | |
9647 color_name2handle(HL_TABLE()[idx].sg_gui_sp_name); | |
9648 didit = TRUE; | |
9649 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9650 # endif |
7 | 9651 if (didit) /* need to get a new attr number */ |
9652 set_hl_attr(idx); | |
9653 } | |
9654 #endif | |
9655 | |
9656 /* | |
9657 * Translate the 'highlight' option into attributes in highlight_attr[] and | |
9658 * set up the user highlights User1..9. If FEAT_STL_OPT is in use, a set of | |
9659 * corresponding highlights to use on top of HLF_SNC is computed. | |
9660 * Called only when the 'highlight' option has been changed and upon first | |
9661 * screen redraw after any :highlight command. | |
9662 * Return FAIL when an invalid flag is found in 'highlight'. OK otherwise. | |
9663 */ | |
9664 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9665 highlight_changed(void) |
7 | 9666 { |
9667 int hlf; | |
9668 int i; | |
9669 char_u *p; | |
9670 int attr; | |
9671 char_u *end; | |
9672 int id; | |
9673 #ifdef USER_HIGHLIGHT | |
9674 char_u userhl[10]; | |
9675 # ifdef FEAT_STL_OPT | |
9676 int id_SNC = -1; | |
9677 int id_S = -1; | |
9678 int hlcnt; | |
9679 # endif | |
9680 #endif | |
9681 static int hl_flags[HLF_COUNT] = HL_FLAGS; | |
9682 | |
9683 need_highlight_changed = FALSE; | |
9684 | |
9685 /* | |
9686 * Clear all attributes. | |
9687 */ | |
9688 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9689 highlight_attr[hlf] = 0; | |
9690 | |
9691 /* | |
9692 * First set all attributes to their default value. | |
9693 * Then use the attributes from the 'highlight' option. | |
9694 */ | |
9695 for (i = 0; i < 2; ++i) | |
9696 { | |
9697 if (i) | |
9698 p = p_hl; | |
9699 else | |
9700 p = get_highlight_default(); | |
9701 if (p == NULL) /* just in case */ | |
9702 continue; | |
9703 | |
9704 while (*p) | |
9705 { | |
9706 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9707 if (hl_flags[hlf] == *p) | |
9708 break; | |
9709 ++p; | |
9710 if (hlf == (int)HLF_COUNT || *p == NUL) | |
9711 return FAIL; | |
9712 | |
9713 /* | |
9714 * Allow several hl_flags to be combined, like "bu" for | |
9715 * bold-underlined. | |
9716 */ | |
9717 attr = 0; | |
9718 for ( ; *p && *p != ','; ++p) /* parse upto comma */ | |
9719 { | |
9720 if (vim_iswhite(*p)) /* ignore white space */ | |
9721 continue; | |
9722 | |
9723 if (attr > HL_ALL) /* Combination with ':' is not allowed. */ | |
9724 return FAIL; | |
9725 | |
9726 switch (*p) | |
9727 { | |
9728 case 'b': attr |= HL_BOLD; | |
9729 break; | |
9730 case 'i': attr |= HL_ITALIC; | |
9731 break; | |
9732 case '-': | |
9733 case 'n': /* no highlighting */ | |
9734 break; | |
9735 case 'r': attr |= HL_INVERSE; | |
9736 break; | |
9737 case 's': attr |= HL_STANDOUT; | |
9738 break; | |
9739 case 'u': attr |= HL_UNDERLINE; | |
9740 break; | |
205 | 9741 case 'c': attr |= HL_UNDERCURL; |
9742 break; | |
7 | 9743 case ':': ++p; /* highlight group name */ |
9744 if (attr || *p == NUL) /* no combinations */ | |
9745 return FAIL; | |
9746 end = vim_strchr(p, ','); | |
9747 if (end == NULL) | |
9748 end = p + STRLEN(p); | |
9749 id = syn_check_group(p, (int)(end - p)); | |
9750 if (id == 0) | |
9751 return FAIL; | |
9752 attr = syn_id2attr(id); | |
9753 p = end - 1; | |
9754 #if defined(FEAT_STL_OPT) && defined(USER_HIGHLIGHT) | |
9755 if (hlf == (int)HLF_SNC) | |
9756 id_SNC = syn_get_final_id(id); | |
9757 else if (hlf == (int)HLF_S) | |
9758 id_S = syn_get_final_id(id); | |
9759 #endif | |
9760 break; | |
9761 default: return FAIL; | |
9762 } | |
9763 } | |
9764 highlight_attr[hlf] = attr; | |
9765 | |
9766 p = skip_to_option_part(p); /* skip comma and spaces */ | |
9767 } | |
9768 } | |
9769 | |
9770 #ifdef USER_HIGHLIGHT | |
9771 /* Setup the user highlights | |
9772 * | |
9773 * Temporarily utilize 10 more hl entries. Have to be in there | |
9774 * simultaneously in case of table overflows in get_attr_entry() | |
9775 */ | |
9776 # ifdef FEAT_STL_OPT | |
9777 if (ga_grow(&highlight_ga, 10) == FAIL) | |
9778 return FAIL; | |
9779 hlcnt = highlight_ga.ga_len; | |
9780 if (id_S == 0) | |
9781 { /* 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
|
9782 vim_memset(&HL_TABLE()[hlcnt + 9], 0, sizeof(struct hl_group)); |
7 | 9783 HL_TABLE()[hlcnt + 9].sg_term = highlight_attr[HLF_S]; |
9784 id_S = hlcnt + 10; | |
9785 } | |
9786 # endif | |
9787 for (i = 0; i < 9; i++) | |
9788 { | |
9789 sprintf((char *)userhl, "User%d", i + 1); | |
9790 id = syn_name2id(userhl); | |
9791 if (id == 0) | |
9792 { | |
9793 highlight_user[i] = 0; | |
9794 # ifdef FEAT_STL_OPT | |
9795 highlight_stlnc[i] = 0; | |
9796 # endif | |
9797 } | |
9798 else | |
9799 { | |
9800 # ifdef FEAT_STL_OPT | |
9801 struct hl_group *hlt = HL_TABLE(); | |
9802 # endif | |
9803 | |
9804 highlight_user[i] = syn_id2attr(id); | |
9805 # ifdef FEAT_STL_OPT | |
9806 if (id_SNC == 0) | |
9807 { | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2136
diff
changeset
|
9808 vim_memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group)); |
7 | 9809 hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC]; |
9810 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
|
9811 # if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9812 hlt[hlcnt + i].sg_gui = highlight_attr[HLF_SNC]; |
9813 # endif | |
9814 } | |
9815 else | |
9816 mch_memmove(&hlt[hlcnt + i], | |
9817 &hlt[id_SNC - 1], | |
9818 sizeof(struct hl_group)); | |
9819 hlt[hlcnt + i].sg_link = 0; | |
9820 | |
9821 /* Apply difference between UserX and HLF_S to HLF_SNC */ | |
9822 hlt[hlcnt + i].sg_term ^= | |
9823 hlt[id - 1].sg_term ^ hlt[id_S - 1].sg_term; | |
9824 if (hlt[id - 1].sg_start != hlt[id_S - 1].sg_start) | |
9825 hlt[hlcnt + i].sg_start = hlt[id - 1].sg_start; | |
9826 if (hlt[id - 1].sg_stop != hlt[id_S - 1].sg_stop) | |
9827 hlt[hlcnt + i].sg_stop = hlt[id - 1].sg_stop; | |
9828 hlt[hlcnt + i].sg_cterm ^= | |
9829 hlt[id - 1].sg_cterm ^ hlt[id_S - 1].sg_cterm; | |
9830 if (hlt[id - 1].sg_cterm_fg != hlt[id_S - 1].sg_cterm_fg) | |
9831 hlt[hlcnt + i].sg_cterm_fg = hlt[id - 1].sg_cterm_fg; | |
9832 if (hlt[id - 1].sg_cterm_bg != hlt[id_S - 1].sg_cterm_bg) | |
9833 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
|
9834 # if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9835 hlt[hlcnt + i].sg_gui ^= |
9836 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
|
9837 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9838 # ifdef FEAT_GUI |
7 | 9839 if (hlt[id - 1].sg_gui_fg != hlt[id_S - 1].sg_gui_fg) |
9840 hlt[hlcnt + i].sg_gui_fg = hlt[id - 1].sg_gui_fg; | |
9841 if (hlt[id - 1].sg_gui_bg != hlt[id_S - 1].sg_gui_bg) | |
9842 hlt[hlcnt + i].sg_gui_bg = hlt[id - 1].sg_gui_bg; | |
205 | 9843 if (hlt[id - 1].sg_gui_sp != hlt[id_S - 1].sg_gui_sp) |
9844 hlt[hlcnt + i].sg_gui_sp = hlt[id - 1].sg_gui_sp; | |
7 | 9845 if (hlt[id - 1].sg_font != hlt[id_S - 1].sg_font) |
9846 hlt[hlcnt + i].sg_font = hlt[id - 1].sg_font; | |
9847 # ifdef FEAT_XFONTSET | |
9848 if (hlt[id - 1].sg_fontset != hlt[id_S - 1].sg_fontset) | |
9849 hlt[hlcnt + i].sg_fontset = hlt[id - 1].sg_fontset; | |
9850 # endif | |
9851 # endif | |
9852 highlight_ga.ga_len = hlcnt + i + 1; | |
9853 set_hl_attr(hlcnt + i); /* At long last we can apply */ | |
9854 highlight_stlnc[i] = syn_id2attr(hlcnt + i + 1); | |
9855 # endif | |
9856 } | |
9857 } | |
9858 # ifdef FEAT_STL_OPT | |
9859 highlight_ga.ga_len = hlcnt; | |
9860 # endif | |
9861 | |
9862 #endif /* USER_HIGHLIGHT */ | |
9863 | |
9864 return OK; | |
9865 } | |
9866 | |
1322 | 9867 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
7 | 9868 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
9869 static void highlight_list(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
9870 static void highlight_list_two(int cnt, int attr); |
7 | 9871 |
9872 /* | |
9873 * Handle command line completion for :highlight command. | |
9874 */ | |
9875 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9876 set_context_in_highlight_cmd(expand_T *xp, char_u *arg) |
7 | 9877 { |
9878 char_u *p; | |
9879 | |
9880 /* Default: expand group names */ | |
9881 xp->xp_context = EXPAND_HIGHLIGHT; | |
9882 xp->xp_pattern = arg; | |
1322 | 9883 include_link = 2; |
9884 include_default = 1; | |
7 | 9885 |
9886 /* (part of) subcommand already typed */ | |
9887 if (*arg != NUL) | |
9888 { | |
9889 p = skiptowhite(arg); | |
9890 if (*p != NUL) /* past "default" or group name */ | |
9891 { | |
1322 | 9892 include_default = 0; |
7 | 9893 if (STRNCMP("default", arg, p - arg) == 0) |
9894 { | |
9895 arg = skipwhite(p); | |
9896 xp->xp_pattern = arg; | |
9897 p = skiptowhite(arg); | |
9898 } | |
9899 if (*p != NUL) /* past group name */ | |
9900 { | |
1322 | 9901 include_link = 0; |
7 | 9902 if (arg[1] == 'i' && arg[0] == 'N') |
9903 highlight_list(); | |
9904 if (STRNCMP("link", arg, p - arg) == 0 | |
9905 || STRNCMP("clear", arg, p - arg) == 0) | |
9906 { | |
9907 xp->xp_pattern = skipwhite(p); | |
9908 p = skiptowhite(xp->xp_pattern); | |
9909 if (*p != NUL) /* past first group name */ | |
9910 { | |
9911 xp->xp_pattern = skipwhite(p); | |
9912 p = skiptowhite(xp->xp_pattern); | |
9913 } | |
9914 } | |
9915 if (*p != NUL) /* past group name(s) */ | |
9916 xp->xp_context = EXPAND_NOTHING; | |
9917 } | |
9918 } | |
9919 } | |
9920 } | |
9921 | |
9922 /* | |
9923 * List highlighting matches in a nice way. | |
9924 */ | |
9925 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9926 highlight_list(void) |
7 | 9927 { |
9928 int i; | |
9929 | |
9930 for (i = 10; --i >= 0; ) | |
9931 highlight_list_two(i, hl_attr(HLF_D)); | |
9932 for (i = 40; --i >= 0; ) | |
9933 highlight_list_two(99, 0); | |
9934 } | |
9935 | |
9936 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9937 highlight_list_two(int cnt, int attr) |
7 | 9938 { |
3543 | 9939 msg_puts_attr((char_u *)&("N \bI \b! \b"[cnt / 11]), attr); |
7 | 9940 msg_clr_eos(); |
9941 out_flush(); | |
9942 ui_delay(cnt == 99 ? 40L : (long)cnt * 50L, FALSE); | |
9943 } | |
9944 | |
9945 #endif /* FEAT_CMDL_COMPL */ | |
9946 | |
9947 #if defined(FEAT_CMDL_COMPL) || (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) \ | |
9948 || defined(FEAT_SIGNS) || defined(PROTO) | |
9949 /* | |
9950 * Function given to ExpandGeneric() to obtain the list of group names. | |
9951 * Also used for synIDattr() function. | |
9952 */ | |
9953 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9954 get_highlight_name(expand_T *xp UNUSED, int idx) |
7 | 9955 { |
9956 #ifdef FEAT_CMDL_COMPL | |
1322 | 9957 if (idx == highlight_ga.ga_len && include_none != 0) |
9958 return (char_u *)"none"; | |
9959 if (idx == highlight_ga.ga_len + include_none && include_default != 0) | |
9960 return (char_u *)"default"; | |
9961 if (idx == highlight_ga.ga_len + include_none + include_default | |
9962 && include_link != 0) | |
7 | 9963 return (char_u *)"link"; |
1322 | 9964 if (idx == highlight_ga.ga_len + include_none + include_default + 1 |
9965 && include_link != 0) | |
7 | 9966 return (char_u *)"clear"; |
9967 #endif | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9968 if (idx < 0) |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9969 return NULL; |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9970 /* Items are never removed from the table, skip the ones that were cleared. |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9971 */ |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9972 while (idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared) |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9973 ++idx; |
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
9974 if (idx >= highlight_ga.ga_len) |
7 | 9975 return NULL; |
9976 return HL_TABLE()[idx].sg_name; | |
9977 } | |
9978 #endif | |
9979 | |
1322 | 9980 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 9981 /* |
9982 * Free all the highlight group fonts. | |
9983 * Used when quitting for systems which need it. | |
9984 */ | |
9985 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9986 free_highlight_fonts(void) |
7 | 9987 { |
9988 int idx; | |
9989 | |
9990 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9991 { | |
9992 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
9993 HL_TABLE()[idx].sg_font = NOFONT; | |
9994 # ifdef FEAT_XFONTSET | |
9995 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
9996 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
9997 # endif | |
9998 } | |
9999 | |
10000 gui_mch_free_font(gui.norm_font); | |
10001 # ifdef FEAT_XFONTSET | |
10002 gui_mch_free_fontset(gui.fontset); | |
10003 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2256
diff
changeset
|
10004 # ifndef FEAT_GUI_GTK |
7 | 10005 gui_mch_free_font(gui.bold_font); |
10006 gui_mch_free_font(gui.ital_font); | |
10007 gui_mch_free_font(gui.boldital_font); | |
10008 # endif | |
10009 } | |
10010 #endif | |
10011 | |
10012 /************************************** | |
10013 * End of Highlighting stuff * | |
10014 **************************************/ |