Mercurial > vim
annotate src/syntax.c @ 11541:3bc4fb330d07 v8.0.0653
patch 8.0.0653: the default highlight for QuickFixLine is not good
commit https://github.com/vim/vim/commit/c768a208ca8e0e0fec900c18d5d9a593357ad793
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 22 16:04:27 2017 +0200
patch 8.0.0653: the default highlight for QuickFixLine is not good
Problem: The default highlight for QuickFixLine does not work for several
color schemes. (Manas Thakur)
Solution: Make the default use the old color. (closes #1780)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 22 Jun 2017 16:15:03 +0200 |
parents | 998d2cf59caa |
children | 52e3a77c097b |
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 */ |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
370 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
371 static proftime_T *syn_tm; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
372 #endif |
7 | 373 static linenr_T current_lnum = 0; /* lnum of current state */ |
374 static colnr_T current_col = 0; /* column of current state */ | |
375 static int current_state_stored = 0; /* TRUE if stored current state | |
376 * after setting current_finished */ | |
377 static int current_finished = 0; /* current line has been finished */ | |
378 static garray_T current_state /* current stack of state_items */ | |
379 = {0, 0, 0, 0, NULL}; | |
380 static short *current_next_list = NULL; /* when non-zero, nextgroup list */ | |
381 static int current_next_flags = 0; /* flags for current_next_list */ | |
382 static int current_line_id = 0; /* unique number for current line */ | |
383 | |
384 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] | |
385 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 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
|
390 static void syn_start_line(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
391 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
|
392 static void syn_stack_alloc(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
393 static int syn_stack_cleanup(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
394 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
|
395 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
|
396 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
|
397 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
|
398 static void invalidate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
399 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
|
400 static void validate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 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
|
405 static void check_state_ends(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
406 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
|
407 static void check_keepend(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
408 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
|
409 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
|
410 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
|
411 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
|
412 static void pop_current_state(void); |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
413 #ifdef FEAT_PROFILE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
414 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
|
415 static void syntime_clear(void); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
416 #ifdef __BORLANDC__ |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
417 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
|
418 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
419 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
|
420 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
421 static void syntime_report(void); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
422 static int syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
423 # define IF_SYN_TIME(p) (p) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
424 #else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
425 # define IF_SYN_TIME(p) NULL |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
426 typedef int syn_time_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
427 #endif |
7 | 428 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
429 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
|
430 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
|
431 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
|
432 static void clear_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
433 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 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
|
438 static char_u *syn_getcurline(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 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
|
443 static void syntax_sync_clear(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 static void syn_lines_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
458 static void syn_match_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 static void syn_cmd_region(exarg_T *eap, int syncing); |
7 | 475 #ifdef __BORLANDC__ |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
476 static int _RTLENTRYF syn_compare_stub(const void *v1, const void *v2); |
7 | 477 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
478 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
|
479 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 static void init_syn_patterns(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
486 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
|
487 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
|
488 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
|
489 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
|
490 static void syn_incl_toplevel(int id, int *flagsp); |
7 | 491 |
492 /* | |
493 * Start the syntax recognition for a line. This function is normally called | |
494 * from the screen updating, once for each displayed line. | |
495 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get | |
496 * it. Careful: curbuf and curwin are likely to point to another buffer and | |
497 * window. | |
498 */ | |
499 void | |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
500 syntax_start(win_T *wp, linenr_T lnum, proftime_T *syntax_tm UNUSED) |
7 | 501 { |
502 synstate_T *p; | |
503 synstate_T *last_valid = NULL; | |
504 synstate_T *last_min_valid = NULL; | |
1512 | 505 synstate_T *sp, *prev = NULL; |
7 | 506 linenr_T parsed_lnum; |
507 linenr_T first_stored; | |
508 int dist; | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10660
diff
changeset
|
509 static varnumber_T changedtick = 0; /* remember the last change ID */ |
7 | 510 |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
511 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
512 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
|
513 #endif |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
514 |
7 | 515 /* |
516 * After switching buffers, invalidate current_state. | |
26 | 517 * Also do this when a change was made, the current state may be invalid |
518 * then. | |
7 | 519 */ |
8806
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
520 if (syn_block != wp->w_s |
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
521 || syn_buf != wp->w_buffer |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
522 || changedtick != CHANGEDTICK(syn_buf)) |
7 | 523 { |
524 invalidate_current_state(); | |
525 syn_buf = wp->w_buffer; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
526 syn_block = wp->w_s; |
7 | 527 } |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
528 changedtick = CHANGEDTICK(syn_buf); |
7 | 529 syn_win = wp; |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
530 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
531 syn_tm = syntax_tm; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
532 #endif |
7 | 533 |
534 /* | |
535 * Allocate syntax stack when needed. | |
536 */ | |
537 syn_stack_alloc(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
538 if (syn_block->b_sst_array == NULL) |
410 | 539 return; /* out of memory */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
540 syn_block->b_sst_lasttick = display_tick; |
7 | 541 |
542 /* | |
543 * If the state of the end of the previous line is useful, store it. | |
544 */ | |
545 if (VALID_STATE(¤t_state) | |
546 && current_lnum < lnum | |
547 && current_lnum < syn_buf->b_ml.ml_line_count) | |
548 { | |
549 (void)syn_finish_line(FALSE); | |
550 if (!current_state_stored) | |
551 { | |
552 ++current_lnum; | |
1512 | 553 (void)store_current_state(); |
7 | 554 } |
555 | |
556 /* | |
557 * If the current_lnum is now the same as "lnum", keep the current | |
558 * state (this happens very often!). Otherwise invalidate | |
559 * current_state and figure it out below. | |
560 */ | |
561 if (current_lnum != lnum) | |
562 invalidate_current_state(); | |
563 } | |
564 else | |
565 invalidate_current_state(); | |
566 | |
567 /* | |
568 * Try to synchronize from a saved state in b_sst_array[]. | |
569 * Only do this if lnum is not before and not to far beyond a saved state. | |
570 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
571 if (INVALID_STATE(¤t_state) && syn_block->b_sst_array != NULL) |
7 | 572 { |
573 /* 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
|
574 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 575 { |
576 if (p->sst_lnum > lnum) | |
577 break; | |
578 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0) | |
579 { | |
580 last_valid = p; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
581 if (p->sst_lnum >= lnum - syn_block->b_syn_sync_minlines) |
7 | 582 last_min_valid = p; |
583 } | |
584 } | |
585 if (last_min_valid != NULL) | |
586 load_current_state(last_min_valid); | |
587 } | |
588 | |
589 /* | |
590 * If "lnum" is before or far beyond a line with a saved state, need to | |
591 * re-synchronize. | |
592 */ | |
593 if (INVALID_STATE(¤t_state)) | |
594 { | |
595 syn_sync(wp, lnum, last_valid); | |
2906 | 596 if (current_lnum == 1) |
597 /* First line is always valid, no matter "minlines". */ | |
598 first_stored = 1; | |
599 else | |
600 /* Need to parse "minlines" lines before state can be considered | |
601 * valid to store. */ | |
602 first_stored = current_lnum + syn_block->b_syn_sync_minlines; | |
7 | 603 } |
604 else | |
605 first_stored = current_lnum; | |
606 | |
607 /* | |
608 * Advance from the sync point or saved state until the current line. | |
609 * Save some entries for syncing with later on. | |
610 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
611 if (syn_block->b_sst_len <= Rows) |
819 | 612 dist = 999999; |
613 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
614 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 615 while (current_lnum < lnum) |
616 { | |
617 syn_start_line(); | |
618 (void)syn_finish_line(FALSE); | |
619 ++current_lnum; | |
620 | |
621 /* If we parsed at least "minlines" lines or started at a valid | |
622 * state, the current state is considered valid. */ | |
623 if (current_lnum >= first_stored) | |
624 { | |
625 /* Check if the saved state entry is for the current line and is | |
626 * equal to the current state. If so, then validate all saved | |
627 * states that depended on a change before the parsed line. */ | |
628 if (prev == NULL) | |
1512 | 629 prev = syn_stack_find_entry(current_lnum - 1); |
630 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
631 sp = syn_block->b_sst_first; |
7 | 632 else |
1512 | 633 sp = prev; |
634 while (sp != NULL && sp->sst_lnum < current_lnum) | |
635 sp = sp->sst_next; | |
7 | 636 if (sp != NULL |
637 && sp->sst_lnum == current_lnum | |
638 && syn_stack_equal(sp)) | |
639 { | |
640 parsed_lnum = current_lnum; | |
641 prev = sp; | |
642 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) | |
643 { | |
644 if (sp->sst_lnum <= lnum) | |
645 /* valid state before desired line, use this one */ | |
646 prev = sp; | |
647 else if (sp->sst_change_lnum == 0) | |
648 /* past saved states depending on change, break here. */ | |
649 break; | |
650 sp->sst_change_lnum = 0; | |
651 sp = sp->sst_next; | |
652 } | |
653 load_current_state(prev); | |
654 } | |
655 /* Store the state at this line when it's the first one, the line | |
656 * where we start parsing, or some distance from the previously | |
657 * saved state. But only when parsed at least 'minlines'. */ | |
658 else if (prev == NULL | |
659 || current_lnum == lnum | |
660 || current_lnum >= prev->sst_lnum + dist) | |
1512 | 661 prev = store_current_state(); |
7 | 662 } |
663 | |
664 /* This can take a long time: break when CTRL-C pressed. The current | |
665 * state will be wrong then. */ | |
666 line_breakcheck(); | |
667 if (got_int) | |
668 { | |
669 current_lnum = lnum; | |
670 break; | |
671 } | |
672 } | |
673 | |
674 syn_start_line(); | |
675 } | |
676 | |
677 /* | |
678 * We cannot simply discard growarrays full of state_items or buf_states; we | |
679 * have to manually release their extmatch pointers first. | |
680 */ | |
681 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
682 clear_syn_state(synstate_T *p) |
7 | 683 { |
684 int i; | |
685 garray_T *gap; | |
686 | |
687 if (p->sst_stacksize > SST_FIX_STATES) | |
688 { | |
689 gap = &(p->sst_union.sst_ga); | |
690 for (i = 0; i < gap->ga_len; i++) | |
691 unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch); | |
692 ga_clear(gap); | |
693 } | |
694 else | |
695 { | |
696 for (i = 0; i < p->sst_stacksize; i++) | |
697 unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch); | |
698 } | |
699 } | |
700 | |
701 /* | |
702 * Cleanup the current_state stack. | |
703 */ | |
704 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
705 clear_current_state(void) |
7 | 706 { |
707 int i; | |
708 stateitem_T *sip; | |
709 | |
710 sip = (stateitem_T *)(current_state.ga_data); | |
711 for (i = 0; i < current_state.ga_len; i++) | |
712 unref_extmatch(sip[i].si_extmatch); | |
713 ga_clear(¤t_state); | |
714 } | |
715 | |
716 /* | |
717 * Try to find a synchronisation point for line "lnum". | |
718 * | |
719 * This sets current_lnum and the current state. One of three methods is | |
720 * used: | |
721 * 1. Search backwards for the end of a C-comment. | |
722 * 2. Search backwards for given sync patterns. | |
723 * 3. Simply start on a given number of lines above "lnum". | |
724 */ | |
725 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
726 syn_sync( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
727 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
728 linenr_T start_lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
729 synstate_T *last_valid) |
7 | 730 { |
731 buf_T *curbuf_save; | |
732 win_T *curwin_save; | |
733 pos_T cursor_save; | |
734 int idx; | |
735 linenr_T lnum; | |
736 linenr_T end_lnum; | |
737 linenr_T break_lnum; | |
738 int had_sync_point; | |
739 stateitem_T *cur_si; | |
740 synpat_T *spp; | |
741 char_u *line; | |
742 int found_flags = 0; | |
743 int found_match_idx = 0; | |
744 linenr_T found_current_lnum = 0; | |
745 int found_current_col= 0; | |
746 lpos_T found_m_endpos; | |
442 | 747 colnr_T prev_current_col; |
7 | 748 |
749 /* | |
750 * Clear any current state that might be hanging around. | |
751 */ | |
752 invalidate_current_state(); | |
753 | |
754 /* | |
755 * Start at least "minlines" back. Default starting point for parsing is | |
756 * there. | |
757 * Start further back, to avoid that scrolling backwards will result in | |
758 * resyncing for every line. Now it resyncs only one out of N lines, | |
759 * where N is minlines * 1.5, or minlines * 2 if minlines is small. | |
760 * Watch out for overflow when minlines is MAXLNUM. | |
761 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
762 if (syn_block->b_syn_sync_minlines > start_lnum) |
7 | 763 start_lnum = 1; |
764 else | |
765 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
766 if (syn_block->b_syn_sync_minlines == 1) |
7 | 767 lnum = 1; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
768 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
|
769 lnum = syn_block->b_syn_sync_minlines * 2; |
7 | 770 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
771 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
|
772 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
|
773 && lnum > syn_block->b_syn_sync_maxlines) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
774 lnum = syn_block->b_syn_sync_maxlines; |
7 | 775 if (lnum >= start_lnum) |
776 start_lnum = 1; | |
777 else | |
778 start_lnum -= lnum; | |
779 } | |
780 current_lnum = start_lnum; | |
781 | |
782 /* | |
783 * 1. Search backwards for the end of a C-style comment. | |
784 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
785 if (syn_block->b_syn_sync_flags & SF_CCOMMENT) |
7 | 786 { |
787 /* Need to make syn_buf the current buffer for a moment, to be able to | |
788 * use find_start_comment(). */ | |
789 curwin_save = curwin; | |
790 curwin = wp; | |
791 curbuf_save = curbuf; | |
792 curbuf = syn_buf; | |
793 | |
794 /* | |
795 * Skip lines that end in a backslash. | |
796 */ | |
797 for ( ; start_lnum > 1; --start_lnum) | |
798 { | |
799 line = ml_get(start_lnum - 1); | |
800 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') | |
801 break; | |
802 } | |
803 current_lnum = start_lnum; | |
804 | |
805 /* set cursor to start of search */ | |
806 cursor_save = wp->w_cursor; | |
807 wp->w_cursor.lnum = start_lnum; | |
808 wp->w_cursor.col = 0; | |
809 | |
810 /* | |
811 * If the line is inside a comment, need to find the syntax item that | |
812 * defines the comment. | |
813 * Restrict the search for the end of a comment to b_syn_sync_maxlines. | |
814 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
815 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
|
816 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
817 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
|
818 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
|
819 == syn_block->b_syn_sync_id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
820 && SYN_ITEMS(syn_block)[idx].sp_type == SPTYPE_START) |
7 | 821 { |
822 validate_current_state(); | |
823 if (push_current_state(idx) == OK) | |
824 update_si_attr(current_state.ga_len - 1); | |
825 break; | |
826 } | |
827 } | |
828 | |
829 /* restore cursor and buffer */ | |
830 wp->w_cursor = cursor_save; | |
831 curwin = curwin_save; | |
832 curbuf = curbuf_save; | |
833 } | |
834 | |
835 /* | |
836 * 2. Search backwards for given sync patterns. | |
837 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
838 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
|
839 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
840 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
|
841 && 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
|
842 break_lnum = start_lnum - syn_block->b_syn_sync_maxlines; |
7 | 843 else |
844 break_lnum = 0; | |
845 | |
699 | 846 found_m_endpos.lnum = 0; |
847 found_m_endpos.col = 0; | |
7 | 848 end_lnum = start_lnum; |
849 lnum = start_lnum; | |
850 while (--lnum > break_lnum) | |
851 { | |
852 /* This can take a long time: break when CTRL-C pressed. */ | |
853 line_breakcheck(); | |
854 if (got_int) | |
855 { | |
856 invalidate_current_state(); | |
857 current_lnum = start_lnum; | |
858 break; | |
859 } | |
860 | |
861 /* Check if we have run into a valid saved state stack now. */ | |
862 if (last_valid != NULL && lnum == last_valid->sst_lnum) | |
863 { | |
864 load_current_state(last_valid); | |
865 break; | |
866 } | |
867 | |
868 /* | |
869 * Check if the previous line has the line-continuation pattern. | |
870 */ | |
871 if (lnum > 1 && syn_match_linecont(lnum - 1)) | |
872 continue; | |
873 | |
874 /* | |
875 * Start with nothing on the state stack | |
876 */ | |
877 validate_current_state(); | |
878 | |
879 for (current_lnum = lnum; current_lnum < end_lnum; ++current_lnum) | |
880 { | |
881 syn_start_line(); | |
882 for (;;) | |
883 { | |
884 had_sync_point = syn_finish_line(TRUE); | |
885 /* | |
886 * When a sync point has been found, remember where, and | |
887 * continue to look for another one, further on in the line. | |
888 */ | |
889 if (had_sync_point && current_state.ga_len) | |
890 { | |
891 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
892 if (cur_si->si_m_endpos.lnum > start_lnum) | |
893 { | |
894 /* ignore match that goes to after where started */ | |
895 current_lnum = end_lnum; | |
896 break; | |
897 } | |
1371 | 898 if (cur_si->si_idx < 0) |
899 { | |
900 /* Cannot happen? */ | |
901 found_flags = 0; | |
902 found_match_idx = KEYWORD_IDX; | |
903 } | |
904 else | |
905 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
906 spp = &(SYN_ITEMS(syn_block)[cur_si->si_idx]); |
1371 | 907 found_flags = spp->sp_flags; |
908 found_match_idx = spp->sp_sync_idx; | |
909 } | |
7 | 910 found_current_lnum = current_lnum; |
911 found_current_col = current_col; | |
912 found_m_endpos = cur_si->si_m_endpos; | |
913 /* | |
914 * Continue after the match (be aware of a zero-length | |
915 * match). | |
916 */ | |
917 if (found_m_endpos.lnum > current_lnum) | |
918 { | |
919 current_lnum = found_m_endpos.lnum; | |
920 current_col = found_m_endpos.col; | |
921 if (current_lnum >= end_lnum) | |
922 break; | |
923 } | |
924 else if (found_m_endpos.col > current_col) | |
925 current_col = found_m_endpos.col; | |
926 else | |
927 ++current_col; | |
928 | |
929 /* syn_current_attr() will have skipped the check for | |
442 | 930 * an item that ends here, need to do that now. Be |
931 * careful not to go past the NUL. */ | |
932 prev_current_col = current_col; | |
933 if (syn_getcurline()[current_col] != NUL) | |
934 ++current_col; | |
7 | 935 check_state_ends(); |
442 | 936 current_col = prev_current_col; |
7 | 937 } |
938 else | |
939 break; | |
940 } | |
941 } | |
942 | |
943 /* | |
944 * If a sync point was encountered, break here. | |
945 */ | |
946 if (found_flags) | |
947 { | |
948 /* | |
949 * Put the item that was specified by the sync point on the | |
950 * state stack. If there was no item specified, make the | |
951 * state stack empty. | |
952 */ | |
953 clear_current_state(); | |
954 if (found_match_idx >= 0 | |
955 && push_current_state(found_match_idx) == OK) | |
956 update_si_attr(current_state.ga_len - 1); | |
957 | |
958 /* | |
959 * When using "grouphere", continue from the sync point | |
960 * match, until the end of the line. Parsing starts at | |
961 * the next line. | |
962 * For "groupthere" the parsing starts at start_lnum. | |
963 */ | |
964 if (found_flags & HL_SYNC_HERE) | |
965 { | |
966 if (current_state.ga_len) | |
967 { | |
968 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
969 cur_si->si_h_startpos.lnum = found_current_lnum; | |
970 cur_si->si_h_startpos.col = found_current_col; | |
971 update_si_end(cur_si, (int)current_col, TRUE); | |
972 check_keepend(); | |
973 } | |
974 current_col = found_m_endpos.col; | |
975 current_lnum = found_m_endpos.lnum; | |
976 (void)syn_finish_line(FALSE); | |
977 ++current_lnum; | |
978 } | |
979 else | |
980 current_lnum = start_lnum; | |
981 | |
982 break; | |
983 } | |
984 | |
985 end_lnum = lnum; | |
986 invalidate_current_state(); | |
987 } | |
988 | |
989 /* Ran into start of the file or exceeded maximum number of lines */ | |
990 if (lnum <= break_lnum) | |
991 { | |
992 invalidate_current_state(); | |
993 current_lnum = break_lnum + 1; | |
994 } | |
995 } | |
996 | |
997 validate_current_state(); | |
998 } | |
999 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1000 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1001 save_chartab(char_u *chartab) |
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 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
|
1004 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1005 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
|
1006 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
|
1007 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1008 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1009 } |
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 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1012 restore_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1013 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1014 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
|
1015 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
|
1016 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1017 |
7 | 1018 /* |
1019 * Return TRUE if the line-continuation pattern matches in line "lnum". | |
1020 */ | |
1021 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1022 syn_match_linecont(linenr_T lnum) |
7 | 1023 { |
1024 regmmatch_T regmatch; | |
6375 | 1025 int r; |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1026 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ |
7 | 1027 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1028 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
|
1029 { |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1030 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1031 save_chartab(buf_chartab); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1032 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
|
1033 regmatch.regprog = syn_block->b_syn_linecont_prog; |
6375 | 1034 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
|
1035 IF_SYN_TIME(&syn_block->b_syn_linecont_time)); |
6375 | 1036 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
|
1037 restore_chartab(buf_chartab); |
6375 | 1038 return r; |
7 | 1039 } |
1040 return FALSE; | |
1041 } | |
1042 | |
1043 /* | |
1044 * Prepare the current state for the start of a line. | |
1045 */ | |
1046 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1047 syn_start_line(void) |
7 | 1048 { |
1049 current_finished = FALSE; | |
1050 current_col = 0; | |
1051 | |
1052 /* | |
1053 * Need to update the end of a start/skip/end that continues from the | |
1054 * previous line and regions that have "keepend". | |
1055 */ | |
1056 if (current_state.ga_len > 0) | |
2863 | 1057 { |
7 | 1058 syn_update_ends(TRUE); |
2863 | 1059 check_state_ends(); |
1060 } | |
7 | 1061 |
1062 next_match_idx = -1; | |
1063 ++current_line_id; | |
1064 } | |
1065 | |
1066 /* | |
1067 * Check for items in the stack that need their end updated. | |
1068 * When "startofline" is TRUE the last item is always updated. | |
1069 * When "startofline" is FALSE the item with "keepend" is forcefully updated. | |
1070 */ | |
1071 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1072 syn_update_ends(int startofline) |
7 | 1073 { |
1074 stateitem_T *cur_si; | |
1075 int i; | |
991 | 1076 int seen_keepend; |
7 | 1077 |
1078 if (startofline) | |
1079 { | |
1080 /* Check for a match carried over from a previous line with a | |
1081 * contained region. The match ends as soon as the region ends. */ | |
1082 for (i = 0; i < current_state.ga_len; ++i) | |
1083 { | |
1084 cur_si = &CUR_STATE(i); | |
1085 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1086 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type |
7 | 1087 == SPTYPE_MATCH |
1088 && cur_si->si_m_endpos.lnum < current_lnum) | |
1089 { | |
1090 cur_si->si_flags |= HL_MATCHCONT; | |
1091 cur_si->si_m_endpos.lnum = 0; | |
1092 cur_si->si_m_endpos.col = 0; | |
1093 cur_si->si_h_endpos = cur_si->si_m_endpos; | |
1094 cur_si->si_ends = TRUE; | |
1095 } | |
1096 } | |
1097 } | |
1098 | |
1099 /* | |
1100 * Need to update the end of a start/skip/end that continues from the | |
1101 * previous line. And regions that have "keepend", because they may | |
991 | 1102 * influence contained items. If we've just removed "extend" |
1103 * (startofline == 0) then we should update ends of normal regions | |
1104 * contained inside "keepend" because "extend" could have extended | |
1105 * these "keepend" regions as well as contained normal regions. | |
7 | 1106 * Then check for items ending in column 0. |
1107 */ | |
1108 i = current_state.ga_len - 1; | |
1109 if (keepend_level >= 0) | |
1110 for ( ; i > keepend_level; --i) | |
1111 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
1112 break; | |
991 | 1113 |
1114 seen_keepend = FALSE; | |
7 | 1115 for ( ; i < current_state.ga_len; ++i) |
1116 { | |
1117 cur_si = &CUR_STATE(i); | |
1118 if ((cur_si->si_flags & HL_KEEPEND) | |
991 | 1119 || (seen_keepend && !startofline) |
7 | 1120 || (i == current_state.ga_len - 1 && startofline)) |
1121 { | |
1122 cur_si->si_h_startpos.col = 0; /* start highl. in col 0 */ | |
1123 cur_si->si_h_startpos.lnum = current_lnum; | |
1124 | |
1125 if (!(cur_si->si_flags & HL_MATCHCONT)) | |
1126 update_si_end(cur_si, (int)current_col, !startofline); | |
991 | 1127 |
1128 if (!startofline && (cur_si->si_flags & HL_KEEPEND)) | |
1129 seen_keepend = TRUE; | |
7 | 1130 } |
1131 } | |
1132 check_keepend(); | |
1133 } | |
1134 | |
1135 /**************************************** | |
1136 * Handling of the state stack cache. | |
1137 */ | |
1138 | |
1139 /* | |
1140 * EXPLANATION OF THE SYNTAX STATE STACK CACHE | |
1141 * | |
1142 * To speed up syntax highlighting, the state stack for the start of some | |
1143 * lines is cached. These entries can be used to start parsing at that point. | |
1144 * | |
1145 * The stack is kept in b_sst_array[] for each buffer. There is a list of | |
1146 * valid entries. b_sst_first points to the first one, then follow sst_next. | |
1147 * The entries are sorted on line number. The first entry is often for line 2 | |
1148 * (line 1 always starts with an empty stack). | |
1149 * There is also a list for free entries. This construction is used to avoid | |
1150 * having to allocate and free memory blocks too often. | |
1151 * | |
1152 * When making changes to the buffer, this is logged in b_mod_*. When calling | |
1153 * update_screen() to update the display, it will call | |
1154 * syn_stack_apply_changes() for each displayed buffer to adjust the cached | |
1155 * entries. The entries which are inside the changed area are removed, | |
1156 * because they must be recomputed. Entries below the changed have their line | |
1157 * number adjusted for deleted/inserted lines, and have their sst_change_lnum | |
1158 * set to indicate that a check must be made if the changed lines would change | |
1159 * the cached entry. | |
1160 * | |
1161 * When later displaying lines, an entry is stored for each line. Displayed | |
1162 * lines are likely to be displayed again, in which case the state at the | |
1163 * start of the line is needed. | |
1164 * For not displayed lines, an entry is stored for every so many lines. These | |
1165 * entries will be used e.g., when scrolling backwards. The distance between | |
1166 * entries depends on the number of lines in the buffer. For small buffers | |
1167 * the distance is fixed at SST_DIST, for large buffers there is a fixed | |
1168 * number of entries SST_MAX_ENTRIES, and the distance is computed. | |
1169 */ | |
1170 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1171 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1172 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
|
1173 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1174 synstate_T *p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1175 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1176 if (block->b_sst_array != NULL) |
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 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
|
1179 clear_syn_state(p); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1180 vim_free(block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1181 block->b_sst_array = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1182 block->b_sst_len = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1183 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1184 } |
7 | 1185 /* |
1186 * Free b_sst_array[] for buffer "buf". | |
1187 * Used when syntax items changed to force resyncing everywhere. | |
1188 */ | |
1189 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1190 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
|
1191 { |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1192 #ifdef FEAT_FOLDING |
7 | 1193 win_T *wp; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1194 #endif |
7 | 1195 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1196 syn_stack_free_block(block); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1197 |
7 | 1198 #ifdef FEAT_FOLDING |
1199 /* When using "syntax" fold method, must update all folds. */ | |
1200 FOR_ALL_WINDOWS(wp) | |
1201 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1202 if (wp->w_s == block && foldmethodIsSyntax(wp)) |
7 | 1203 foldUpdateAll(wp); |
1204 } | |
1205 #endif | |
1206 } | |
1207 | |
1208 /* | |
1209 * Allocate the syntax state stack for syn_buf when needed. | |
1210 * If the number of entries in b_sst_array[] is much too big or a bit too | |
1211 * small, reallocate it. | |
1212 * Also used to allocate b_sst_array[] for the first time. | |
1213 */ | |
1214 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1215 syn_stack_alloc(void) |
7 | 1216 { |
1217 long len; | |
1218 synstate_T *to, *from; | |
1219 synstate_T *sstp; | |
1220 | |
1221 len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; | |
1222 if (len < SST_MIN_ENTRIES) | |
1223 len = SST_MIN_ENTRIES; | |
1224 else if (len > SST_MAX_ENTRIES) | |
1225 len = SST_MAX_ENTRIES; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1226 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) |
7 | 1227 { |
1228 /* Allocate 50% too much, to avoid reallocating too often. */ | |
1229 len = syn_buf->b_ml.ml_line_count; | |
1230 len = (len + len / 2) / SST_DIST + Rows * 2; | |
1231 if (len < SST_MIN_ENTRIES) | |
1232 len = SST_MIN_ENTRIES; | |
1233 else if (len > SST_MAX_ENTRIES) | |
1234 len = SST_MAX_ENTRIES; | |
1235 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1236 if (syn_block->b_sst_array != NULL) |
7 | 1237 { |
1238 /* When shrinking the array, cleanup the existing stack. | |
1239 * 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
|
1240 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len |
7 | 1241 && syn_stack_cleanup()) |
1242 ; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1243 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
|
1244 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; |
7 | 1245 } |
1246 | |
1247 sstp = (synstate_T *)alloc_clear((unsigned)(len * sizeof(synstate_T))); | |
1248 if (sstp == NULL) /* out of memory! */ | |
1249 return; | |
1250 | |
1251 to = sstp - 1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1252 if (syn_block->b_sst_array != NULL) |
7 | 1253 { |
1254 /* 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
|
1255 for (from = syn_block->b_sst_first; from != NULL; |
7 | 1256 from = from->sst_next) |
1257 { | |
1258 ++to; | |
1259 *to = *from; | |
1260 to->sst_next = to + 1; | |
1261 } | |
1262 } | |
1263 if (to != sstp - 1) | |
1264 { | |
1265 to->sst_next = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1266 syn_block->b_sst_first = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1267 syn_block->b_sst_freecount = len - (int)(to - sstp) - 1; |
7 | 1268 } |
1269 else | |
1270 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1271 syn_block->b_sst_first = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1272 syn_block->b_sst_freecount = len; |
7 | 1273 } |
1274 | |
1275 /* Create the list of free entries. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1276 syn_block->b_sst_firstfree = to + 1; |
7 | 1277 while (++to < sstp + len) |
1278 to->sst_next = to + 1; | |
1279 (sstp + len - 1)->sst_next = NULL; | |
1280 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1281 vim_free(syn_block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1282 syn_block->b_sst_array = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1283 syn_block->b_sst_len = len; |
7 | 1284 } |
1285 } | |
1286 | |
1287 /* | |
1288 * Check for changes in a buffer to affect stored syntax states. Uses the | |
1289 * b_mod_* fields. | |
1290 * Called from update_screen(), before screen is being updated, once for each | |
1291 * displayed buffer. | |
1292 */ | |
1293 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1294 syn_stack_apply_changes(buf_T *buf) |
7 | 1295 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1296 win_T *wp; |
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 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
|
1299 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1300 FOR_ALL_WINDOWS(wp) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1301 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1302 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
|
1303 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
|
1304 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1305 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1306 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1307 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1308 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
|
1309 { |
7 | 1310 synstate_T *p, *prev, *np; |
1311 linenr_T n; | |
1312 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1313 if (block->b_sst_array == NULL) /* nothing to do */ |
7 | 1314 return; |
1315 | |
1316 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1317 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
|
1318 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1319 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) |
7 | 1320 { |
1321 n = p->sst_lnum + buf->b_mod_xlines; | |
1322 if (n <= buf->b_mod_bot) | |
1323 { | |
1324 /* this state is inside the changed area, remove it */ | |
1325 np = p->sst_next; | |
1326 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1327 block->b_sst_first = np; |
7 | 1328 else |
1329 prev->sst_next = np; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1330 syn_stack_free_entry(block, p); |
7 | 1331 p = np; |
1332 continue; | |
1333 } | |
1334 /* This state is below the changed area. Remember the line | |
1335 * that needs to be parsed before this entry can be made valid | |
1336 * again. */ | |
1337 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) | |
1338 { | |
1339 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) | |
1340 p->sst_change_lnum += buf->b_mod_xlines; | |
1341 else | |
1342 p->sst_change_lnum = buf->b_mod_top; | |
1343 } | |
1344 if (p->sst_change_lnum == 0 | |
1345 || p->sst_change_lnum < buf->b_mod_bot) | |
1346 p->sst_change_lnum = buf->b_mod_bot; | |
1347 | |
1348 p->sst_lnum = n; | |
1349 } | |
1350 prev = p; | |
1351 p = p->sst_next; | |
1352 } | |
1353 } | |
1354 | |
1355 /* | |
1356 * Reduce the number of entries in the state stack for syn_buf. | |
1357 * Returns TRUE if at least one entry was freed. | |
1358 */ | |
1359 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1360 syn_stack_cleanup(void) |
7 | 1361 { |
1362 synstate_T *p, *prev; | |
1363 disptick_T tick; | |
1364 int above; | |
1365 int dist; | |
1366 int retval = FALSE; | |
1367 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1368 if (syn_block->b_sst_array == NULL || syn_block->b_sst_first == NULL) |
7 | 1369 return retval; |
1370 | |
1371 /* 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
|
1372 if (syn_block->b_sst_len <= Rows) |
819 | 1373 dist = 999999; |
1374 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1375 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 1376 |
1377 /* | |
2020 | 1378 * Go through the list to find the "tick" for the oldest entry that can |
7 | 1379 * be removed. Set "above" when the "tick" for the oldest entry is above |
1380 * "b_sst_lasttick" (the display tick wraps around). | |
1381 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1382 tick = syn_block->b_sst_lasttick; |
7 | 1383 above = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1384 prev = syn_block->b_sst_first; |
7 | 1385 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1386 { | |
1387 if (prev->sst_lnum + dist > p->sst_lnum) | |
1388 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1389 if (p->sst_tick > syn_block->b_sst_lasttick) |
7 | 1390 { |
1391 if (!above || p->sst_tick < tick) | |
1392 tick = p->sst_tick; | |
1393 above = TRUE; | |
1394 } | |
1395 else if (!above && p->sst_tick < tick) | |
1396 tick = p->sst_tick; | |
1397 } | |
1398 } | |
1399 | |
1400 /* | |
1401 * Go through the list to make the entries for the oldest tick at an | |
1402 * interval of several lines. | |
1403 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1404 prev = syn_block->b_sst_first; |
7 | 1405 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1406 { | |
1407 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) | |
1408 { | |
1409 /* Move this entry from used list to free list */ | |
1410 prev->sst_next = p->sst_next; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1411 syn_stack_free_entry(syn_block, p); |
7 | 1412 p = prev; |
1413 retval = TRUE; | |
1414 } | |
1415 } | |
1416 return retval; | |
1417 } | |
1418 | |
1419 /* | |
1420 * Free the allocated memory for a syn_state item. | |
1421 * Move the entry into the free list. | |
1422 */ | |
1423 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1424 syn_stack_free_entry(synblock_T *block, synstate_T *p) |
7 | 1425 { |
1426 clear_syn_state(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1427 p->sst_next = block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1428 block->b_sst_firstfree = p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1429 ++block->b_sst_freecount; |
7 | 1430 } |
1431 | |
1432 /* | |
1433 * Find an entry in the list of state stacks at or before "lnum". | |
1434 * Returns NULL when there is no entry or the first entry is after "lnum". | |
1435 */ | |
1436 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1437 syn_stack_find_entry(linenr_T lnum) |
7 | 1438 { |
1439 synstate_T *p, *prev; | |
1440 | |
1441 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1442 for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) |
7 | 1443 { |
1444 if (p->sst_lnum == lnum) | |
1445 return p; | |
1446 if (p->sst_lnum > lnum) | |
1447 break; | |
1448 } | |
1449 return prev; | |
1450 } | |
1451 | |
1452 /* | |
1453 * Try saving the current state in b_sst_array[]. | |
1454 * The current state must be valid for the start of the current_lnum line! | |
1455 */ | |
1456 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1457 store_current_state(void) |
7 | 1458 { |
1459 int i; | |
1460 synstate_T *p; | |
1461 bufstate_T *bp; | |
1462 stateitem_T *cur_si; | |
1512 | 1463 synstate_T *sp = syn_stack_find_entry(current_lnum); |
7 | 1464 |
1465 /* | |
1466 * If the current state contains a start or end pattern that continues | |
1467 * from the previous line, we can't use it. Don't store it then. | |
1468 */ | |
1469 for (i = current_state.ga_len - 1; i >= 0; --i) | |
1470 { | |
1471 cur_si = &CUR_STATE(i); | |
1472 if (cur_si->si_h_startpos.lnum >= current_lnum | |
1473 || cur_si->si_m_endpos.lnum >= current_lnum | |
1474 || cur_si->si_h_endpos.lnum >= current_lnum | |
1475 || (cur_si->si_end_idx | |
1476 && cur_si->si_eoe_pos.lnum >= current_lnum)) | |
1477 break; | |
1478 } | |
1479 if (i >= 0) | |
1480 { | |
1481 if (sp != NULL) | |
1482 { | |
1483 /* 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
|
1484 if (syn_block->b_sst_first == sp) |
7 | 1485 /* it's the first entry */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1486 syn_block->b_sst_first = sp->sst_next; |
7 | 1487 else |
1488 { | |
1489 /* 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
|
1490 for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) |
7 | 1491 if (p->sst_next == sp) |
1492 break; | |
840 | 1493 if (p != NULL) /* just in case */ |
1494 p->sst_next = sp->sst_next; | |
7 | 1495 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1496 syn_stack_free_entry(syn_block, sp); |
7 | 1497 sp = NULL; |
1498 } | |
1499 } | |
1500 else if (sp == NULL || sp->sst_lnum != current_lnum) | |
1501 { | |
1502 /* | |
1503 * Add a new entry | |
1504 */ | |
1505 /* 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
|
1506 if (syn_block->b_sst_freecount == 0) |
7 | 1507 { |
1508 (void)syn_stack_cleanup(); | |
1509 /* "sp" may have been moved to the freelist now */ | |
1510 sp = syn_stack_find_entry(current_lnum); | |
1511 } | |
1512 /* 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
|
1513 if (syn_block->b_sst_freecount == 0) |
7 | 1514 sp = NULL; |
1515 else | |
1516 { | |
1517 /* Take the first item from the free list and put it in the used | |
1518 * list, after *sp */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1519 p = syn_block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1520 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
|
1521 --syn_block->b_sst_freecount; |
7 | 1522 if (sp == NULL) |
1523 { | |
1524 /* Insert in front of the list */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1525 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
|
1526 syn_block->b_sst_first = p; |
7 | 1527 } |
1528 else | |
1529 { | |
1530 /* insert in list after *sp */ | |
1531 p->sst_next = sp->sst_next; | |
1532 sp->sst_next = p; | |
1533 } | |
1534 sp = p; | |
1535 sp->sst_stacksize = 0; | |
1536 sp->sst_lnum = current_lnum; | |
1537 } | |
1538 } | |
1539 if (sp != NULL) | |
1540 { | |
1541 /* When overwriting an existing state stack, clear it first */ | |
1542 clear_syn_state(sp); | |
1543 sp->sst_stacksize = current_state.ga_len; | |
1544 if (current_state.ga_len > SST_FIX_STATES) | |
1545 { | |
1546 /* Need to clear it, might be something remaining from when the | |
1547 * length was less than SST_FIX_STATES. */ | |
1548 ga_init2(&sp->sst_union.sst_ga, (int)sizeof(bufstate_T), 1); | |
1549 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) | |
1550 sp->sst_stacksize = 0; | |
1551 else | |
1552 sp->sst_union.sst_ga.ga_len = current_state.ga_len; | |
1553 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1554 } | |
1555 else | |
1556 bp = sp->sst_union.sst_stack; | |
1557 for (i = 0; i < sp->sst_stacksize; ++i) | |
1558 { | |
1559 bp[i].bs_idx = CUR_STATE(i).si_idx; | |
1560 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
|
1561 #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
|
1562 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
|
1563 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
|
1564 #endif |
7 | 1565 bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); |
1566 } | |
1567 sp->sst_next_flags = current_next_flags; | |
1568 sp->sst_next_list = current_next_list; | |
1569 sp->sst_tick = display_tick; | |
1570 sp->sst_change_lnum = 0; | |
1571 } | |
1572 current_state_stored = TRUE; | |
1573 return sp; | |
1574 } | |
1575 | |
1576 /* | |
1577 * Copy a state stack from "from" in b_sst_array[] to current_state; | |
1578 */ | |
1579 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1580 load_current_state(synstate_T *from) |
7 | 1581 { |
1582 int i; | |
1583 bufstate_T *bp; | |
1584 | |
1585 clear_current_state(); | |
1586 validate_current_state(); | |
1587 keepend_level = -1; | |
1588 if (from->sst_stacksize | |
1589 && ga_grow(¤t_state, from->sst_stacksize) != FAIL) | |
1590 { | |
1591 if (from->sst_stacksize > SST_FIX_STATES) | |
1592 bp = SYN_STATE_P(&(from->sst_union.sst_ga)); | |
1593 else | |
1594 bp = from->sst_union.sst_stack; | |
1595 for (i = 0; i < from->sst_stacksize; ++i) | |
1596 { | |
1597 CUR_STATE(i).si_idx = bp[i].bs_idx; | |
1598 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
|
1599 #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
|
1600 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
|
1601 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
|
1602 #endif |
7 | 1603 CUR_STATE(i).si_extmatch = ref_extmatch(bp[i].bs_extmatch); |
1604 if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) | |
1605 keepend_level = i; | |
1606 CUR_STATE(i).si_ends = FALSE; | |
1607 CUR_STATE(i).si_m_lnum = 0; | |
1608 if (CUR_STATE(i).si_idx >= 0) | |
1609 CUR_STATE(i).si_next_list = | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1610 (SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_next_list; |
7 | 1611 else |
1612 CUR_STATE(i).si_next_list = NULL; | |
1613 update_si_attr(i); | |
1614 } | |
1615 current_state.ga_len = from->sst_stacksize; | |
1616 } | |
1617 current_next_list = from->sst_next_list; | |
1618 current_next_flags = from->sst_next_flags; | |
1619 current_lnum = from->sst_lnum; | |
1620 } | |
1621 | |
1622 /* | |
1623 * Compare saved state stack "*sp" with the current state. | |
1624 * Return TRUE when they are equal. | |
1625 */ | |
1626 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1627 syn_stack_equal(synstate_T *sp) |
7 | 1628 { |
1629 int i, j; | |
1630 bufstate_T *bp; | |
1631 reg_extmatch_T *six, *bsx; | |
1632 | |
1633 /* First a quick check if the stacks have the same size end nextlist. */ | |
1634 if (sp->sst_stacksize == current_state.ga_len | |
1635 && sp->sst_next_list == current_next_list) | |
1636 { | |
1637 /* Need to compare all states on both stacks. */ | |
1638 if (sp->sst_stacksize > SST_FIX_STATES) | |
1639 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1640 else | |
1641 bp = sp->sst_union.sst_stack; | |
1642 | |
1643 for (i = current_state.ga_len; --i >= 0; ) | |
1644 { | |
1645 /* If the item has another index the state is different. */ | |
1646 if (bp[i].bs_idx != CUR_STATE(i).si_idx) | |
1647 break; | |
1648 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) | |
1649 { | |
1650 /* When the extmatch pointers are different, the strings in | |
1651 * them can still be the same. Check if the extmatch | |
1652 * references are equal. */ | |
1653 bsx = bp[i].bs_extmatch; | |
1654 six = CUR_STATE(i).si_extmatch; | |
1655 /* If one of the extmatch pointers is NULL the states are | |
1656 * different. */ | |
1657 if (bsx == NULL || six == NULL) | |
1658 break; | |
1659 for (j = 0; j < NSUBEXP; ++j) | |
1660 { | |
1661 /* Check each referenced match string. They must all be | |
1662 * equal. */ | |
1663 if (bsx->matches[j] != six->matches[j]) | |
1664 { | |
1665 /* If the pointer is different it can still be the | |
1666 * same text. Compare the strings, ignore case when | |
1667 * the start item has the sp_ic flag set. */ | |
1668 if (bsx->matches[j] == NULL | |
1669 || six->matches[j] == NULL) | |
1670 break; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1671 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic |
7 | 1672 ? MB_STRICMP(bsx->matches[j], |
1673 six->matches[j]) != 0 | |
1674 : STRCMP(bsx->matches[j], six->matches[j]) != 0) | |
1675 break; | |
1676 } | |
1677 } | |
1678 if (j != NSUBEXP) | |
1679 break; | |
1680 } | |
1681 } | |
1682 if (i < 0) | |
1683 return TRUE; | |
1684 } | |
1685 return FALSE; | |
1686 } | |
1687 | |
1688 /* | |
1689 * We stop parsing syntax above line "lnum". If the stored state at or below | |
1690 * this line depended on a change before it, it now depends on the line below | |
1691 * the last parsed line. | |
1692 * The window looks like this: | |
1693 * line which changed | |
1694 * displayed line | |
1695 * displayed line | |
1696 * lnum -> line below window | |
1697 */ | |
1698 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1699 syntax_end_parsing(linenr_T lnum) |
7 | 1700 { |
1701 synstate_T *sp; | |
1702 | |
1703 sp = syn_stack_find_entry(lnum); | |
1704 if (sp != NULL && sp->sst_lnum < lnum) | |
1705 sp = sp->sst_next; | |
1706 | |
1707 if (sp != NULL && sp->sst_change_lnum != 0) | |
1708 sp->sst_change_lnum = lnum; | |
1709 } | |
1710 | |
1711 /* | |
1712 * End of handling of the state stack. | |
1713 ****************************************/ | |
1714 | |
1715 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1716 invalidate_current_state(void) |
7 | 1717 { |
1718 clear_current_state(); | |
1719 current_state.ga_itemsize = 0; /* mark current_state invalid */ | |
1720 current_next_list = NULL; | |
1721 keepend_level = -1; | |
1722 } | |
1723 | |
1724 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1725 validate_current_state(void) |
7 | 1726 { |
1727 current_state.ga_itemsize = sizeof(stateitem_T); | |
1728 current_state.ga_growsize = 3; | |
1729 } | |
1730 | |
1731 /* | |
1732 * Return TRUE if the syntax at start of lnum changed since last time. | |
1733 * This will only be called just after get_syntax_attr() for the previous | |
1734 * line, to check if the next line needs to be redrawn too. | |
1735 */ | |
1736 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1737 syntax_check_changed(linenr_T lnum) |
7 | 1738 { |
1739 int retval = TRUE; | |
1740 synstate_T *sp; | |
1741 | |
1742 /* | |
1743 * Check the state stack when: | |
1744 * - lnum is just below the previously syntaxed line. | |
1745 * - lnum is not before the lines with saved states. | |
1746 * - lnum is not past the lines with saved states. | |
1747 * - lnum is at or before the last changed line. | |
1748 */ | |
1749 if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) | |
1750 { | |
1751 sp = syn_stack_find_entry(lnum); | |
1752 if (sp != NULL && sp->sst_lnum == lnum) | |
1753 { | |
1754 /* | |
1755 * finish the previous line (needed when not all of the line was | |
1756 * drawn) | |
1757 */ | |
1758 (void)syn_finish_line(FALSE); | |
1759 | |
1760 /* | |
1761 * Compare the current state with the previously saved state of | |
1762 * the line. | |
1763 */ | |
1764 if (syn_stack_equal(sp)) | |
1765 retval = FALSE; | |
1766 | |
1767 /* | |
1768 * Store the current state in b_sst_array[] for later use. | |
1769 */ | |
1770 ++current_lnum; | |
1512 | 1771 (void)store_current_state(); |
7 | 1772 } |
1773 } | |
1774 | |
1775 return retval; | |
1776 } | |
1777 | |
1778 /* | |
1779 * Finish the current line. | |
1780 * This doesn't return any attributes, it only gets the state at the end of | |
1781 * the line. It can start anywhere in the line, as long as the current state | |
1782 * is valid. | |
1783 */ | |
1784 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1785 syn_finish_line( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1786 int syncing) /* called for syncing */ |
7 | 1787 { |
1788 stateitem_T *cur_si; | |
442 | 1789 colnr_T prev_current_col; |
7 | 1790 |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1791 while (!current_finished) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1792 { |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1793 (void)syn_current_attr(syncing, FALSE, NULL, FALSE); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1794 /* |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1795 * When syncing, and found some item, need to check the item. |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1796 */ |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1797 if (syncing && current_state.ga_len) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1798 { |
7 | 1799 /* |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1800 * Check for match with sync item. |
7 | 1801 */ |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1802 cur_si = &CUR_STATE(current_state.ga_len - 1); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1803 if (cur_si->si_idx >= 0 |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1804 && (SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1805 & (HL_SYNC_HERE|HL_SYNC_THERE))) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1806 return TRUE; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1807 |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1808 /* syn_current_attr() will have skipped the check for an item |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1809 * that ends here, need to do that now. Be careful not to go |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1810 * past the NUL. */ |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1811 prev_current_col = current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1812 if (syn_getcurline()[current_col] != NUL) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1813 ++current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1814 check_state_ends(); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1815 current_col = prev_current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1816 } |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1817 ++current_col; |
7 | 1818 } |
1819 return FALSE; | |
1820 } | |
1821 | |
1822 /* | |
1823 * Return highlight attributes for next character. | |
1824 * Must first call syntax_start() once for the line. | |
1825 * "col" is normally 0 for the first use in a line, and increments by one each | |
1826 * time. It's allowed to skip characters and to stop before the end of the | |
1827 * line. But only a "col" after a previously used column is allowed. | |
221 | 1828 * When "can_spell" is not NULL set it to TRUE when spell-checking should be |
1829 * done. | |
7 | 1830 */ |
1831 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1832 get_syntax_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1833 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1834 int *can_spell, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1835 int keep_state) /* keep state of char at "col" */ |
7 | 1836 { |
1837 int attr = 0; | |
1838 | |
1363 | 1839 if (can_spell != NULL) |
1840 /* Default: Only do spelling when there is no @Spell cluster or when | |
1841 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1842 *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
|
1843 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1844 : (syn_block->b_syn_spell == SYNSPL_TOP); |
1363 | 1845 |
7 | 1846 /* check for out of memory situation */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1847 if (syn_block->b_sst_array == NULL) |
7 | 1848 return 0; |
1849 | |
419 | 1850 /* After 'synmaxcol' the attribute is always zero. */ |
431 | 1851 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) |
419 | 1852 { |
1853 clear_current_state(); | |
1854 #ifdef FEAT_EVAL | |
1855 current_id = 0; | |
1856 current_trans_id = 0; | |
1857 #endif | |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1858 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1859 current_flags = 0; |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1860 #endif |
419 | 1861 return 0; |
1862 } | |
1863 | |
7 | 1864 /* Make sure current_state is valid */ |
1865 if (INVALID_STATE(¤t_state)) | |
1866 validate_current_state(); | |
1867 | |
1868 /* | |
1869 * Skip from the current column to "col", get the attributes for "col". | |
1870 */ | |
1871 while (current_col <= col) | |
1872 { | |
1504 | 1873 attr = syn_current_attr(FALSE, TRUE, can_spell, |
1874 current_col == col ? keep_state : FALSE); | |
7 | 1875 ++current_col; |
1876 } | |
1877 | |
1878 return attr; | |
1879 } | |
1880 | |
1881 /* | |
1882 * Get syntax attributes for current_lnum, current_col. | |
1883 */ | |
1884 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1885 syn_current_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1886 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
|
1887 int displaying, /* result will be displayed */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1888 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
|
1889 int keep_state) /* keep syntax stack afterwards */ |
7 | 1890 { |
1891 int syn_id; | |
1892 lpos_T endpos; /* was: char_u *endp; */ | |
1893 lpos_T hl_startpos; /* was: int hl_startcol; */ | |
1894 lpos_T hl_endpos; | |
1895 lpos_T eos_pos; /* end-of-start match (start region) */ | |
1896 lpos_T eoe_pos; /* end-of-end pattern */ | |
1897 int end_idx; /* group ID for end pattern */ | |
1898 int idx; | |
1899 synpat_T *spp; | |
221 | 1900 stateitem_T *cur_si, *sip = NULL; |
7 | 1901 int startcol; |
1902 int endcol; | |
1903 long flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1904 int cchar; |
7 | 1905 short *next_list; |
1906 int found_match; /* found usable match */ | |
1907 static int try_next_column = FALSE; /* must try in next col */ | |
1908 int do_keywords; | |
1909 regmmatch_T regmatch; | |
1910 lpos_T pos; | |
1911 int lc_col; | |
1912 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
|
1913 char_u buf_chartab[32]; /* chartab array for syn iskyeyword */ |
7 | 1914 char_u *line; /* current line. NOTE: becomes invalid after |
1915 looking for a pattern match! */ | |
1916 | |
1917 /* variables for zero-width matches that have a "nextgroup" argument */ | |
1918 int keep_next_list; | |
1919 int zero_width_next_list = FALSE; | |
1920 garray_T zero_width_next_ga; | |
1921 | |
1922 /* | |
1923 * No character, no attributes! Past end of line? | |
1924 * Do try matching with an empty line (could be the start of a region). | |
1925 */ | |
1926 line = syn_getcurline(); | |
1927 if (line[current_col] == NUL && current_col != 0) | |
1928 { | |
1929 /* | |
1930 * If we found a match after the last column, use it. | |
1931 */ | |
1932 if (next_match_idx >= 0 && next_match_col >= (int)current_col | |
1933 && next_match_col != MAXCOL) | |
1934 (void)push_next_match(NULL); | |
1935 | |
1936 current_finished = TRUE; | |
1937 current_state_stored = FALSE; | |
1938 return 0; | |
1939 } | |
1940 | |
1941 /* if the current or next character is NUL, we will finish the line now */ | |
1942 if (line[current_col] == NUL || line[current_col + 1] == NUL) | |
1943 { | |
1944 current_finished = TRUE; | |
1945 current_state_stored = FALSE; | |
1946 } | |
1947 | |
1948 /* | |
1949 * When in the previous column there was a match but it could not be used | |
1950 * (empty match or already matched in this column) need to try again in | |
1951 * the next column. | |
1952 */ | |
1953 if (try_next_column) | |
1954 { | |
1955 next_match_idx = -1; | |
1956 try_next_column = FALSE; | |
1957 } | |
1958 | |
1959 /* Only check for keywords when not syncing and there are some. */ | |
1960 do_keywords = !syncing | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1961 && (syn_block->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1962 || syn_block->b_keywtab_ic.ht_used > 0); |
7 | 1963 |
1964 /* Init the list of zero-width matches with a nextlist. This is used to | |
1965 * avoid matching the same item in the same position twice. */ | |
1966 ga_init2(&zero_width_next_ga, (int)sizeof(int), 10); | |
1967 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1968 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1969 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1970 |
7 | 1971 /* |
1972 * Repeat matching keywords and patterns, to find contained items at the | |
1973 * same column. This stops when there are no extra matches at the current | |
1974 * column. | |
1975 */ | |
1976 do | |
1977 { | |
1978 found_match = FALSE; | |
1979 keep_next_list = FALSE; | |
1980 syn_id = 0; | |
1981 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1982 |
7 | 1983 /* |
1984 * 1. Check for a current state. | |
1985 * Only when there is no current state, or if the current state may | |
1986 * contain other things, we need to check for keywords and patterns. | |
1987 * Always need to check for contained items if some item has the | |
1988 * "containedin" argument (takes extra time!). | |
1989 */ | |
1990 if (current_state.ga_len) | |
1991 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1992 else | |
1993 cur_si = NULL; | |
1994 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1995 if (syn_block->b_syn_containedin || cur_si == NULL |
7 | 1996 || cur_si->si_cont_list != NULL) |
1997 { | |
1998 /* | |
1999 * 2. Check for keywords, if on a keyword char after a non-keyword | |
2000 * char. Don't do this when syncing. | |
2001 */ | |
2002 if (do_keywords) | |
2003 { | |
2004 line = syn_getcurline(); | |
4043 | 2005 if (vim_iswordp_buf(line + current_col, syn_buf) |
7 | 2006 && (current_col == 0 |
4043 | 2007 || !vim_iswordp_buf(line + current_col - 1 |
7 | 2008 #ifdef FEAT_MBYTE |
2009 - (has_mbyte | |
2010 ? (*mb_head_off)(line, line + current_col - 1) | |
2011 : 0) | |
2012 #endif | |
2013 , syn_buf))) | |
2014 { | |
2015 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
|
2016 &endcol, &flags, &next_list, cur_si, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2017 &cchar); |
205 | 2018 if (syn_id != 0) |
7 | 2019 { |
2020 if (push_current_state(KEYWORD_IDX) == OK) | |
2021 { | |
2022 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2023 cur_si->si_m_startcol = current_col; | |
2024 cur_si->si_h_startpos.lnum = current_lnum; | |
2025 cur_si->si_h_startpos.col = 0; /* starts right away */ | |
2026 cur_si->si_m_endpos.lnum = current_lnum; | |
2027 cur_si->si_m_endpos.col = endcol; | |
2028 cur_si->si_h_endpos.lnum = current_lnum; | |
2029 cur_si->si_h_endpos.col = endcol; | |
2030 cur_si->si_ends = TRUE; | |
2031 cur_si->si_end_idx = 0; | |
2032 cur_si->si_flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2033 #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
|
2034 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
|
2035 cur_si->si_cchar = cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2036 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2037 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2038 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
|
2039 & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2040 #endif |
7 | 2041 cur_si->si_id = syn_id; |
2042 cur_si->si_trans_id = syn_id; | |
2043 if (flags & HL_TRANSP) | |
2044 { | |
2045 if (current_state.ga_len < 2) | |
2046 { | |
2047 cur_si->si_attr = 0; | |
2048 cur_si->si_trans_id = 0; | |
2049 } | |
2050 else | |
2051 { | |
2052 cur_si->si_attr = CUR_STATE( | |
2053 current_state.ga_len - 2).si_attr; | |
2054 cur_si->si_trans_id = CUR_STATE( | |
2055 current_state.ga_len - 2).si_trans_id; | |
2056 } | |
2057 } | |
2058 else | |
2059 cur_si->si_attr = syn_id2attr(syn_id); | |
2060 cur_si->si_cont_list = NULL; | |
2061 cur_si->si_next_list = next_list; | |
2062 check_keepend(); | |
2063 } | |
2064 else | |
2065 vim_free(next_list); | |
2066 } | |
2067 } | |
2068 } | |
2069 | |
2070 /* | |
205 | 2071 * 3. Check for patterns (only if no keyword found). |
7 | 2072 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2073 if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) |
7 | 2074 { |
2075 /* | |
2076 * If we didn't check for a match yet, or we are past it, check | |
2077 * for any match with a pattern. | |
2078 */ | |
2079 if (next_match_idx < 0 || next_match_col < (int)current_col) | |
2080 { | |
2081 /* | |
2082 * Check all relevant patterns for a match at this | |
2083 * position. This is complicated, because matching with a | |
2084 * pattern takes quite a bit of time, thus we want to | |
2085 * avoid doing it when it's not needed. | |
2086 */ | |
2087 next_match_idx = 0; /* no match in this line yet */ | |
2088 next_match_col = MAXCOL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2089 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
7 | 2090 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2091 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2092 if ( spp->sp_syncing == syncing |
2093 && (displaying || !(spp->sp_flags & HL_DISPLAY)) | |
2094 && (spp->sp_type == SPTYPE_MATCH | |
2095 || spp->sp_type == SPTYPE_START) | |
2096 && (current_next_list != NULL | |
2097 ? in_id_list(NULL, current_next_list, | |
2098 &spp->sp_syn, 0) | |
2099 : (cur_si == NULL | |
2100 ? !(spp->sp_flags & HL_CONTAINED) | |
2101 : in_id_list(cur_si, | |
2102 cur_si->si_cont_list, &spp->sp_syn, | |
2103 spp->sp_flags & HL_CONTAINED)))) | |
2104 { | |
6375 | 2105 int r; |
2106 | |
7 | 2107 /* If we already tried matching in this line, and |
2108 * there isn't a match before next_match_col, skip | |
2109 * this item. */ | |
2110 if (spp->sp_line_id == current_line_id | |
2111 && spp->sp_startcol >= next_match_col) | |
2112 continue; | |
2113 spp->sp_line_id = current_line_id; | |
2114 | |
2115 lc_col = current_col - spp->sp_offsets[SPO_LC_OFF]; | |
2116 if (lc_col < 0) | |
2117 lc_col = 0; | |
2118 | |
2119 regmatch.rmm_ic = spp->sp_ic; | |
2120 regmatch.regprog = spp->sp_prog; | |
6375 | 2121 r = syn_regexec(®match, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2122 current_lnum, |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
2123 (colnr_T)lc_col, |
6375 | 2124 IF_SYN_TIME(&spp->sp_time)); |
2125 spp->sp_prog = regmatch.regprog; | |
2126 if (!r) | |
7 | 2127 { |
2128 /* no match in this line, try another one */ | |
2129 spp->sp_startcol = MAXCOL; | |
2130 continue; | |
2131 } | |
2132 | |
2133 /* | |
2134 * Compute the first column of the match. | |
2135 */ | |
2136 syn_add_start_off(&pos, ®match, | |
2137 spp, SPO_MS_OFF, -1); | |
2138 if (pos.lnum > current_lnum) | |
2139 { | |
2140 /* must have used end of match in a next line, | |
2141 * we can't handle that */ | |
2142 spp->sp_startcol = MAXCOL; | |
2143 continue; | |
2144 } | |
2145 startcol = pos.col; | |
2146 | |
2147 /* remember the next column where this pattern | |
2148 * matches in the current line */ | |
2149 spp->sp_startcol = startcol; | |
2150 | |
2151 /* | |
2152 * If a previously found match starts at a lower | |
2153 * column number, don't use this one. | |
2154 */ | |
2155 if (startcol >= next_match_col) | |
2156 continue; | |
2157 | |
2158 /* | |
2159 * If we matched this pattern at this position | |
2160 * before, skip it. Must retry in the next | |
2161 * column, because it may match from there. | |
2162 */ | |
2163 if (did_match_already(idx, &zero_width_next_ga)) | |
2164 { | |
2165 try_next_column = TRUE; | |
2166 continue; | |
2167 } | |
2168 | |
2169 endpos.lnum = regmatch.endpos[0].lnum; | |
2170 endpos.col = regmatch.endpos[0].col; | |
2171 | |
2172 /* Compute the highlight start. */ | |
2173 syn_add_start_off(&hl_startpos, ®match, | |
2174 spp, SPO_HS_OFF, -1); | |
2175 | |
2176 /* Compute the region start. */ | |
2177 /* Default is to use the end of the match. */ | |
2178 syn_add_end_off(&eos_pos, ®match, | |
2179 spp, SPO_RS_OFF, 0); | |
2180 | |
2181 /* | |
2182 * Grab the external submatches before they get | |
2183 * overwritten. Reference count doesn't change. | |
2184 */ | |
2185 unref_extmatch(cur_extmatch); | |
2186 cur_extmatch = re_extmatch_out; | |
2187 re_extmatch_out = NULL; | |
2188 | |
2189 flags = 0; | |
2190 eoe_pos.lnum = 0; /* avoid warning */ | |
2191 eoe_pos.col = 0; | |
2192 end_idx = 0; | |
2193 hl_endpos.lnum = 0; | |
2194 | |
2195 /* | |
2196 * For a "oneline" the end must be found in the | |
2197 * same line too. Search for it after the end of | |
2198 * the match with the start pattern. Set the | |
2199 * resulting end positions at the same time. | |
2200 */ | |
2201 if (spp->sp_type == SPTYPE_START | |
2202 && (spp->sp_flags & HL_ONELINE)) | |
2203 { | |
2204 lpos_T startpos; | |
2205 | |
2206 startpos = endpos; | |
2207 find_endpos(idx, &startpos, &endpos, &hl_endpos, | |
2208 &flags, &eoe_pos, &end_idx, cur_extmatch); | |
2209 if (endpos.lnum == 0) | |
2210 continue; /* not found */ | |
2211 } | |
2212 | |
2213 /* | |
2214 * For a "match" the size must be > 0 after the | |
2215 * end offset needs has been added. Except when | |
2216 * syncing. | |
2217 */ | |
2218 else if (spp->sp_type == SPTYPE_MATCH) | |
2219 { | |
2220 syn_add_end_off(&hl_endpos, ®match, spp, | |
2221 SPO_HE_OFF, 0); | |
2222 syn_add_end_off(&endpos, ®match, spp, | |
2223 SPO_ME_OFF, 0); | |
2224 if (endpos.lnum == current_lnum | |
2225 && (int)endpos.col + syncing < startcol) | |
2226 { | |
2227 /* | |
2228 * If an empty string is matched, may need | |
2229 * to try matching again at next column. | |
2230 */ | |
2231 if (regmatch.startpos[0].col | |
2232 == regmatch.endpos[0].col) | |
2233 try_next_column = TRUE; | |
2234 continue; | |
2235 } | |
2236 } | |
2237 | |
2238 /* | |
2239 * keep the best match so far in next_match_* | |
2240 */ | |
2241 /* Highlighting must start after startpos and end | |
2242 * before endpos. */ | |
2243 if (hl_startpos.lnum == current_lnum | |
2244 && (int)hl_startpos.col < startcol) | |
2245 hl_startpos.col = startcol; | |
2246 limit_pos_zero(&hl_endpos, &endpos); | |
2247 | |
2248 next_match_idx = idx; | |
2249 next_match_col = startcol; | |
2250 next_match_m_endpos = endpos; | |
2251 next_match_h_endpos = hl_endpos; | |
2252 next_match_h_startpos = hl_startpos; | |
2253 next_match_flags = flags; | |
2254 next_match_eos_pos = eos_pos; | |
2255 next_match_eoe_pos = eoe_pos; | |
2256 next_match_end_idx = end_idx; | |
2257 unref_extmatch(next_match_extmatch); | |
2258 next_match_extmatch = cur_extmatch; | |
2259 cur_extmatch = NULL; | |
2260 } | |
2261 } | |
2262 } | |
2263 | |
2264 /* | |
2265 * If we found a match at the current column, use it. | |
2266 */ | |
2267 if (next_match_idx >= 0 && next_match_col == (int)current_col) | |
2268 { | |
2269 synpat_T *lspp; | |
2270 | |
2271 /* When a zero-width item matched which has a nextgroup, | |
2272 * 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
|
2273 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2274 if (next_match_m_endpos.lnum == current_lnum |
2275 && next_match_m_endpos.col == current_col | |
2276 && lspp->sp_next_list != NULL) | |
2277 { | |
2278 current_next_list = lspp->sp_next_list; | |
2279 current_next_flags = lspp->sp_flags; | |
2280 keep_next_list = TRUE; | |
2281 zero_width_next_list = TRUE; | |
2282 | |
2283 /* Add the index to a list, so that we can check | |
2284 * later that we don't match it again (and cause an | |
2285 * endless loop). */ | |
2286 if (ga_grow(&zero_width_next_ga, 1) == OK) | |
2287 { | |
2288 ((int *)(zero_width_next_ga.ga_data)) | |
2289 [zero_width_next_ga.ga_len++] = next_match_idx; | |
2290 } | |
2291 next_match_idx = -1; | |
2292 } | |
2293 else | |
2294 cur_si = push_next_match(cur_si); | |
2295 found_match = TRUE; | |
2296 } | |
2297 } | |
2298 } | |
2299 | |
2300 /* | |
2301 * Handle searching for nextgroup match. | |
2302 */ | |
2303 if (current_next_list != NULL && !keep_next_list) | |
2304 { | |
2305 /* | |
2306 * If a nextgroup was not found, continue looking for one if: | |
2307 * - this is an empty line and the "skipempty" option was given | |
2308 * - we are on white space and the "skipwhite" option was given | |
2309 */ | |
2310 if (!found_match) | |
2311 { | |
2312 line = syn_getcurline(); | |
2313 if (((current_next_flags & HL_SKIPWHITE) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2314 && VIM_ISWHITE(line[current_col])) |
7 | 2315 || ((current_next_flags & HL_SKIPEMPTY) |
2316 && *line == NUL)) | |
2317 break; | |
2318 } | |
2319 | |
2320 /* | |
2321 * If a nextgroup was found: Use it, and continue looking for | |
2322 * contained matches. | |
2323 * If a nextgroup was not found: Continue looking for a normal | |
2324 * match. | |
2325 * When did set current_next_list for a zero-width item and no | |
2326 * match was found don't loop (would get stuck). | |
2327 */ | |
2328 current_next_list = NULL; | |
2329 next_match_idx = -1; | |
2330 if (!zero_width_next_list) | |
2331 found_match = TRUE; | |
2332 } | |
2333 | |
2334 } while (found_match); | |
2335 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2336 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2337 |
7 | 2338 /* |
2339 * Use attributes from the current state, if within its highlighting. | |
2340 * If not, use attributes from the current-but-one state, etc. | |
2341 */ | |
2342 current_attr = 0; | |
2343 #ifdef FEAT_EVAL | |
2344 current_id = 0; | |
2345 current_trans_id = 0; | |
2346 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2347 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2348 current_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2349 #endif |
7 | 2350 if (cur_si != NULL) |
2351 { | |
221 | 2352 #ifndef FEAT_EVAL |
2353 int current_trans_id = 0; | |
2354 #endif | |
7 | 2355 for (idx = current_state.ga_len - 1; idx >= 0; --idx) |
2356 { | |
2357 sip = &CUR_STATE(idx); | |
2358 if ((current_lnum > sip->si_h_startpos.lnum | |
2359 || (current_lnum == sip->si_h_startpos.lnum | |
2360 && current_col >= sip->si_h_startpos.col)) | |
2361 && (sip->si_h_endpos.lnum == 0 | |
2362 || current_lnum < sip->si_h_endpos.lnum | |
2363 || (current_lnum == sip->si_h_endpos.lnum | |
2364 && current_col < sip->si_h_endpos.col))) | |
2365 { | |
2366 current_attr = sip->si_attr; | |
2367 #ifdef FEAT_EVAL | |
2368 current_id = sip->si_id; | |
221 | 2369 #endif |
7 | 2370 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
|
2371 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2372 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
|
2373 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
|
2374 current_sub_char = sip->si_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2375 #endif |
7 | 2376 break; |
2377 } | |
2378 } | |
2379 | |
221 | 2380 if (can_spell != NULL) |
2381 { | |
2382 struct sp_syn sps; | |
2383 | |
2384 /* | |
2385 * set "can_spell" to TRUE if spell checking is supposed to be | |
2386 * done in the current item. | |
2387 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2388 if (syn_block->b_spell_cluster_id == 0) |
227 | 2389 { |
320 | 2390 /* There is no @Spell cluster: Do spelling for items without |
2391 * @NoSpell cluster. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2392 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
|
2393 || current_trans_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2394 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); |
227 | 2395 else |
2396 { | |
2397 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2398 sps.id = syn_block->b_nospell_cluster_id; |
227 | 2399 sps.cont_in_list = NULL; |
2400 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2401 } | |
2402 } | |
221 | 2403 else |
2404 { | |
320 | 2405 /* The @Spell cluster is defined: Do spelling in items with |
419 | 2406 * the @Spell cluster. But not when @NoSpell is also there. |
2407 * At the toplevel only spell check when ":syn spell toplevel" | |
2408 * was used. */ | |
320 | 2409 if (current_trans_id == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2410 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); |
320 | 2411 else |
2412 { | |
2413 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2414 sps.id = syn_block->b_spell_cluster_id; |
320 | 2415 sps.cont_in_list = NULL; |
2416 *can_spell = in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2417 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2418 if (syn_block->b_nospell_cluster_id != 0) |
320 | 2419 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2420 sps.id = syn_block->b_nospell_cluster_id; |
320 | 2421 if (in_id_list(sip, sip->si_cont_list, &sps, 0)) |
2422 *can_spell = FALSE; | |
2423 } | |
2424 } | |
221 | 2425 } |
2426 } | |
2427 | |
2428 | |
7 | 2429 /* |
2430 * Check for end of current state (and the states before it) at the | |
2431 * next column. Don't do this for syncing, because we would miss a | |
2432 * single character match. | |
2433 * First check if the current state ends at the current column. It | |
2434 * may be for an empty match and a containing item might end in the | |
2435 * current column. | |
2436 */ | |
1504 | 2437 if (!syncing && !keep_state) |
7 | 2438 { |
2439 check_state_ends(); | |
442 | 2440 if (current_state.ga_len > 0 |
2441 && syn_getcurline()[current_col] != NUL) | |
7 | 2442 { |
2443 ++current_col; | |
2444 check_state_ends(); | |
2445 --current_col; | |
2446 } | |
2447 } | |
2448 } | |
221 | 2449 else if (can_spell != NULL) |
419 | 2450 /* Default: Only do spelling when there is no @Spell cluster or when |
2451 * ":syn spell toplevel" was used. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2452 *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
|
2453 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2454 : (syn_block->b_syn_spell == SYNSPL_TOP); |
7 | 2455 |
2020 | 2456 /* nextgroup ends at end of line, unless "skipnl" or "skipempty" present */ |
7 | 2457 if (current_next_list != NULL |
2458 && syn_getcurline()[current_col + 1] == NUL | |
2459 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) | |
2460 current_next_list = NULL; | |
2461 | |
2462 if (zero_width_next_ga.ga_len > 0) | |
2463 ga_clear(&zero_width_next_ga); | |
2464 | |
2465 /* No longer need external matches. But keep next_match_extmatch. */ | |
2466 unref_extmatch(re_extmatch_out); | |
2467 re_extmatch_out = NULL; | |
2468 unref_extmatch(cur_extmatch); | |
2469 | |
2470 return current_attr; | |
2471 } | |
2472 | |
2473 | |
2474 /* | |
2475 * Check if we already matched pattern "idx" at the current column. | |
2476 */ | |
2477 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2478 did_match_already(int idx, garray_T *gap) |
7 | 2479 { |
2480 int i; | |
2481 | |
2482 for (i = current_state.ga_len; --i >= 0; ) | |
2483 if (CUR_STATE(i).si_m_startcol == (int)current_col | |
2484 && CUR_STATE(i).si_m_lnum == (int)current_lnum | |
2485 && CUR_STATE(i).si_idx == idx) | |
2486 return TRUE; | |
2487 | |
2488 /* Zero-width matches with a nextgroup argument are not put on the syntax | |
2489 * stack, and can only be matched once anyway. */ | |
2490 for (i = gap->ga_len; --i >= 0; ) | |
2491 if (((int *)(gap->ga_data))[i] == idx) | |
2492 return TRUE; | |
2493 | |
2494 return FALSE; | |
2495 } | |
2496 | |
2497 /* | |
2498 * Push the next match onto the stack. | |
2499 */ | |
2500 static stateitem_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2501 push_next_match(stateitem_T *cur_si) |
7 | 2502 { |
2503 synpat_T *spp; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2504 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2505 int save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2506 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2507 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2508 spp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2509 |
2510 /* | |
2511 * Push the item in current_state stack; | |
2512 */ | |
2513 if (push_current_state(next_match_idx) == OK) | |
2514 { | |
2515 /* | |
2516 * If it's a start-skip-end type that crosses lines, figure out how | |
2517 * much it continues in this line. Otherwise just fill in the length. | |
2518 */ | |
2519 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2520 cur_si->si_h_startpos = next_match_h_startpos; | |
2521 cur_si->si_m_startcol = current_col; | |
2522 cur_si->si_m_lnum = current_lnum; | |
2523 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
|
2524 #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
|
2525 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
|
2526 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
|
2527 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2528 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2529 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
|
2530 #endif |
7 | 2531 cur_si->si_next_list = spp->sp_next_list; |
2532 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); | |
2533 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) | |
2534 { | |
2535 /* Try to find the end pattern in the current line */ | |
2536 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); | |
2537 check_keepend(); | |
2538 } | |
2539 else | |
2540 { | |
2541 cur_si->si_m_endpos = next_match_m_endpos; | |
2542 cur_si->si_h_endpos = next_match_h_endpos; | |
2543 cur_si->si_ends = TRUE; | |
2544 cur_si->si_flags |= next_match_flags; | |
2545 cur_si->si_eoe_pos = next_match_eoe_pos; | |
2546 cur_si->si_end_idx = next_match_end_idx; | |
2547 } | |
2548 if (keepend_level < 0 && (cur_si->si_flags & HL_KEEPEND)) | |
2549 keepend_level = current_state.ga_len - 1; | |
2550 check_keepend(); | |
2551 update_si_attr(current_state.ga_len - 1); | |
2552 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2553 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2554 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
|
2555 #endif |
7 | 2556 /* |
2557 * If the start pattern has another highlight group, push another item | |
2558 * on the stack for the start pattern. | |
2559 */ | |
2560 if ( spp->sp_type == SPTYPE_START | |
2561 && spp->sp_syn_match_id != 0 | |
2562 && push_current_state(next_match_idx) == OK) | |
2563 { | |
2564 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2565 cur_si->si_h_startpos = next_match_h_startpos; | |
2566 cur_si->si_m_startcol = current_col; | |
2567 cur_si->si_m_lnum = current_lnum; | |
2568 cur_si->si_m_endpos = next_match_eos_pos; | |
2569 cur_si->si_h_endpos = next_match_eos_pos; | |
2570 cur_si->si_ends = TRUE; | |
2571 cur_si->si_end_idx = 0; | |
2572 cur_si->si_flags = HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2573 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2574 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2575 cur_si->si_flags |= save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2576 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2577 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2578 #endif |
7 | 2579 cur_si->si_next_list = NULL; |
2580 check_keepend(); | |
2581 update_si_attr(current_state.ga_len - 1); | |
2582 } | |
2583 } | |
2584 | |
2585 next_match_idx = -1; /* try other match next time */ | |
2586 | |
2587 return cur_si; | |
2588 } | |
2589 | |
2590 /* | |
2591 * Check for end of current state (and the states before it). | |
2592 */ | |
2593 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2594 check_state_ends(void) |
7 | 2595 { |
2596 stateitem_T *cur_si; | |
2863 | 2597 int had_extend; |
7 | 2598 |
2599 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2600 for (;;) | |
2601 { | |
2602 if (cur_si->si_ends | |
2603 && (cur_si->si_m_endpos.lnum < current_lnum | |
2604 || (cur_si->si_m_endpos.lnum == current_lnum | |
2605 && cur_si->si_m_endpos.col <= current_col))) | |
2606 { | |
2607 /* | |
2608 * If there is an end pattern group ID, highlight the end pattern | |
2609 * now. No need to pop the current item from the stack. | |
2610 * Only do this if the end pattern continues beyond the current | |
2611 * position. | |
2612 */ | |
2613 if (cur_si->si_end_idx | |
2614 && (cur_si->si_eoe_pos.lnum > current_lnum | |
2615 || (cur_si->si_eoe_pos.lnum == current_lnum | |
2616 && cur_si->si_eoe_pos.col > current_col))) | |
2617 { | |
2618 cur_si->si_idx = cur_si->si_end_idx; | |
2619 cur_si->si_end_idx = 0; | |
2620 cur_si->si_m_endpos = cur_si->si_eoe_pos; | |
2621 cur_si->si_h_endpos = cur_si->si_eoe_pos; | |
2622 cur_si->si_flags |= HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2623 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2624 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2625 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2626 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2627 #endif |
7 | 2628 update_si_attr(current_state.ga_len - 1); |
36 | 2629 |
2831 | 2630 /* nextgroup= should not match in the end pattern */ |
2631 current_next_list = NULL; | |
2632 | |
36 | 2633 /* what matches next may be different now, clear it */ |
2634 next_match_idx = 0; | |
2635 next_match_col = MAXCOL; | |
7 | 2636 break; |
2637 } | |
2638 else | |
2639 { | |
2640 /* handle next_list, unless at end of line and no "skipnl" or | |
2641 * "skipempty" */ | |
2642 current_next_list = cur_si->si_next_list; | |
2643 current_next_flags = cur_si->si_flags; | |
2644 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) | |
2645 && syn_getcurline()[current_col] == NUL) | |
2646 current_next_list = NULL; | |
2647 | |
2648 /* When the ended item has "extend", another item with | |
2649 * "keepend" now needs to check for its end. */ | |
2863 | 2650 had_extend = (cur_si->si_flags & HL_EXTEND); |
7 | 2651 |
2652 pop_current_state(); | |
2653 | |
2654 if (current_state.ga_len == 0) | |
2655 break; | |
2656 | |
1503 | 2657 if (had_extend && keepend_level >= 0) |
7 | 2658 { |
2659 syn_update_ends(FALSE); | |
2660 if (current_state.ga_len == 0) | |
2661 break; | |
2662 } | |
2663 | |
2664 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2665 | |
2666 /* | |
2667 * Only for a region the search for the end continues after | |
2668 * the end of the contained item. If the contained match | |
2669 * included the end-of-line, break here, the region continues. | |
2670 * Don't do this when: | |
2671 * - "keepend" is used for the contained item | |
2672 * - not at the end of the line (could be end="x$"me=e-1). | |
2673 * - "excludenl" is used (HL_HAS_EOL won't be set) | |
2674 */ | |
2675 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2676 && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type |
7 | 2677 == SPTYPE_START |
2678 && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) | |
2679 { | |
2680 update_si_end(cur_si, (int)current_col, TRUE); | |
2681 check_keepend(); | |
2682 if ((current_next_flags & HL_HAS_EOL) | |
2683 && keepend_level < 0 | |
2684 && syn_getcurline()[current_col] == NUL) | |
2685 break; | |
2686 } | |
2687 } | |
2688 } | |
2689 else | |
2690 break; | |
2691 } | |
2692 } | |
2693 | |
2694 /* | |
2695 * Update an entry in the current_state stack for a match or region. This | |
2696 * fills in si_attr, si_next_list and si_cont_list. | |
2697 */ | |
2698 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2699 update_si_attr(int idx) |
7 | 2700 { |
2701 stateitem_T *sip = &CUR_STATE(idx); | |
2702 synpat_T *spp; | |
2703 | |
1371 | 2704 /* This should not happen... */ |
2705 if (sip->si_idx < 0) | |
2706 return; | |
2707 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2708 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); |
7 | 2709 if (sip->si_flags & HL_MATCH) |
2710 sip->si_id = spp->sp_syn_match_id; | |
2711 else | |
2712 sip->si_id = spp->sp_syn.id; | |
2713 sip->si_attr = syn_id2attr(sip->si_id); | |
2714 sip->si_trans_id = sip->si_id; | |
2715 if (sip->si_flags & HL_MATCH) | |
2716 sip->si_cont_list = NULL; | |
2717 else | |
2718 sip->si_cont_list = spp->sp_cont_list; | |
2719 | |
2720 /* | |
2721 * For transparent items, take attr from outer item. | |
2722 * Also take cont_list, if there is none. | |
2723 * Don't do this for the matchgroup of a start or end pattern. | |
2724 */ | |
2725 if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) | |
2726 { | |
2727 if (idx == 0) | |
2728 { | |
2729 sip->si_attr = 0; | |
2730 sip->si_trans_id = 0; | |
2731 if (sip->si_cont_list == NULL) | |
2732 sip->si_cont_list = ID_LIST_ALL; | |
2733 } | |
2734 else | |
2735 { | |
2736 sip->si_attr = CUR_STATE(idx - 1).si_attr; | |
2737 sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; | |
36 | 2738 sip->si_h_startpos = CUR_STATE(idx - 1).si_h_startpos; |
2739 sip->si_h_endpos = CUR_STATE(idx - 1).si_h_endpos; | |
7 | 2740 if (sip->si_cont_list == NULL) |
2741 { | |
2742 sip->si_flags |= HL_TRANS_CONT; | |
2743 sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; | |
2744 } | |
2745 } | |
2746 } | |
2747 } | |
2748 | |
2749 /* | |
2750 * Check the current stack for patterns with "keepend" flag. | |
2751 * Propagate the match-end to contained items, until a "skipend" item is found. | |
2752 */ | |
2753 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2754 check_keepend(void) |
7 | 2755 { |
2756 int i; | |
2757 lpos_T maxpos; | |
991 | 2758 lpos_T maxpos_h; |
7 | 2759 stateitem_T *sip; |
2760 | |
2761 /* | |
2762 * This check can consume a lot of time; only do it from the level where | |
2763 * there really is a keepend. | |
2764 */ | |
2765 if (keepend_level < 0) | |
2766 return; | |
2767 | |
2768 /* | |
2769 * Find the last index of an "extend" item. "keepend" items before that | |
2770 * won't do anything. If there is no "extend" item "i" will be | |
2771 * "keepend_level" and all "keepend" items will work normally. | |
2772 */ | |
2773 for (i = current_state.ga_len - 1; i > keepend_level; --i) | |
2774 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
2775 break; | |
2776 | |
2777 maxpos.lnum = 0; | |
1702 | 2778 maxpos.col = 0; |
991 | 2779 maxpos_h.lnum = 0; |
1702 | 2780 maxpos_h.col = 0; |
7 | 2781 for ( ; i < current_state.ga_len; ++i) |
2782 { | |
2783 sip = &CUR_STATE(i); | |
2784 if (maxpos.lnum != 0) | |
2785 { | |
2786 limit_pos_zero(&sip->si_m_endpos, &maxpos); | |
991 | 2787 limit_pos_zero(&sip->si_h_endpos, &maxpos_h); |
7 | 2788 limit_pos_zero(&sip->si_eoe_pos, &maxpos); |
2789 sip->si_ends = TRUE; | |
2790 } | |
991 | 2791 if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) |
2792 { | |
2793 if (maxpos.lnum == 0 | |
7 | 2794 || maxpos.lnum > sip->si_m_endpos.lnum |
2795 || (maxpos.lnum == sip->si_m_endpos.lnum | |
991 | 2796 && maxpos.col > sip->si_m_endpos.col)) |
2797 maxpos = sip->si_m_endpos; | |
2798 if (maxpos_h.lnum == 0 | |
2799 || maxpos_h.lnum > sip->si_h_endpos.lnum | |
2800 || (maxpos_h.lnum == sip->si_h_endpos.lnum | |
2801 && maxpos_h.col > sip->si_h_endpos.col)) | |
2802 maxpos_h = sip->si_h_endpos; | |
2803 } | |
7 | 2804 } |
2805 } | |
2806 | |
2807 /* | |
2808 * Update an entry in the current_state stack for a start-skip-end pattern. | |
2809 * This finds the end of the current item, if it's in the current line. | |
2810 * | |
2811 * Return the flags for the matched END. | |
2812 */ | |
2813 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2814 update_si_end( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2815 stateitem_T *sip, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2816 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
|
2817 int force) /* when TRUE overrule a previous end */ |
7 | 2818 { |
2819 lpos_T startpos; | |
2820 lpos_T endpos; | |
2821 lpos_T hl_endpos; | |
2822 lpos_T end_endpos; | |
2823 int end_idx; | |
2824 | |
1371 | 2825 /* return quickly for a keyword */ |
2826 if (sip->si_idx < 0) | |
2827 return; | |
2828 | |
7 | 2829 /* Don't update when it's already done. Can be a match of an end pattern |
2830 * that started in a previous line. Watch out: can also be a "keepend" | |
2831 * from a containing item. */ | |
2832 if (!force && sip->si_m_endpos.lnum >= current_lnum) | |
2833 return; | |
2834 | |
2835 /* | |
2836 * We need to find the end of the region. It may continue in the next | |
2837 * line. | |
2838 */ | |
2839 end_idx = 0; | |
2840 startpos.lnum = current_lnum; | |
2841 startpos.col = startcol; | |
2842 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, | |
2843 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); | |
2844 | |
2845 if (endpos.lnum == 0) | |
2846 { | |
2847 /* No end pattern matched. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2848 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) |
7 | 2849 { |
2850 /* a "oneline" never continues in the next line */ | |
2851 sip->si_ends = TRUE; | |
2852 sip->si_m_endpos.lnum = current_lnum; | |
2853 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); | |
2854 } | |
2855 else | |
2856 { | |
2857 /* continues in the next line */ | |
2858 sip->si_ends = FALSE; | |
2859 sip->si_m_endpos.lnum = 0; | |
2860 } | |
2861 sip->si_h_endpos = sip->si_m_endpos; | |
2862 } | |
2863 else | |
2864 { | |
2865 /* match within this line */ | |
2866 sip->si_m_endpos = endpos; | |
2867 sip->si_h_endpos = hl_endpos; | |
2868 sip->si_eoe_pos = end_endpos; | |
2869 sip->si_ends = TRUE; | |
2870 sip->si_end_idx = end_idx; | |
2871 } | |
2872 } | |
2873 | |
2874 /* | |
2875 * Add a new state to the current state stack. | |
2876 * It is cleared and the index set to "idx". | |
2877 * Return FAIL if it's not possible (out of memory). | |
2878 */ | |
2879 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2880 push_current_state(int idx) |
7 | 2881 { |
2882 if (ga_grow(¤t_state, 1) == FAIL) | |
2883 return FAIL; | |
2884 vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T)); | |
2885 CUR_STATE(current_state.ga_len).si_idx = idx; | |
2886 ++current_state.ga_len; | |
2887 return OK; | |
2888 } | |
2889 | |
2890 /* | |
2891 * Remove a state from the current_state stack. | |
2892 */ | |
2893 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2894 pop_current_state(void) |
7 | 2895 { |
2896 if (current_state.ga_len) | |
2897 { | |
2898 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); | |
2899 --current_state.ga_len; | |
2900 } | |
2901 /* after the end of a pattern, try matching a keyword or pattern */ | |
2902 next_match_idx = -1; | |
2903 | |
2904 /* if first state with "keepend" is popped, reset keepend_level */ | |
2905 if (keepend_level >= current_state.ga_len) | |
2906 keepend_level = -1; | |
2907 } | |
2908 | |
2909 /* | |
2910 * Find the end of a start/skip/end syntax region after "startpos". | |
2911 * Only checks one line. | |
2912 * Also handles a match item that continued from a previous line. | |
2913 * If not found, the syntax item continues in the next line. m_endpos->lnum | |
2914 * will be 0. | |
2915 * If found, the end of the region and the end of the highlighting is | |
2916 * computed. | |
2917 */ | |
2918 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2919 find_endpos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2920 int idx, /* index of the pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2921 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
|
2922 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
|
2923 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
|
2924 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
|
2925 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
|
2926 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
|
2927 reg_extmatch_T *start_ext) /* submatches from the start pattern */ |
7 | 2928 { |
2929 colnr_T matchcol; | |
2930 synpat_T *spp, *spp_skip; | |
2931 int start_idx; | |
2932 int best_idx; | |
2933 regmmatch_T regmatch; | |
2934 regmmatch_T best_regmatch; /* startpos/endpos of best match */ | |
2935 lpos_T pos; | |
2936 char_u *line; | |
2937 int had_match = FALSE; | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2938 char_u buf_chartab[32]; /* chartab array for syn option iskyeyword */ |
7 | 2939 |
1371 | 2940 /* just in case we are invoked for a keyword */ |
2941 if (idx < 0) | |
2942 return; | |
2943 | |
7 | 2944 /* |
2945 * Check for being called with a START pattern. | |
2946 * Can happen with a match that continues to the next line, because it | |
2947 * contained a region. | |
2948 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2949 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2950 if (spp->sp_type != SPTYPE_START) |
2951 { | |
2952 *hl_endpos = *startpos; | |
2953 return; | |
2954 } | |
2955 | |
2956 /* | |
2957 * Find the SKIP or first END pattern after the last START pattern. | |
2958 */ | |
2959 for (;;) | |
2960 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2961 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2962 if (spp->sp_type != SPTYPE_START) |
2963 break; | |
2964 ++idx; | |
2965 } | |
2966 | |
2967 /* | |
2968 * Lookup the SKIP pattern (if present) | |
2969 */ | |
2970 if (spp->sp_type == SPTYPE_SKIP) | |
2971 { | |
2972 spp_skip = spp; | |
2973 ++idx; | |
2974 } | |
2975 else | |
2976 spp_skip = NULL; | |
2977 | |
2978 /* Setup external matches for syn_regexec(). */ | |
2979 unref_extmatch(re_extmatch_in); | |
2980 re_extmatch_in = ref_extmatch(start_ext); | |
2981 | |
2982 matchcol = startpos->col; /* start looking for a match at sstart */ | |
2983 start_idx = idx; /* remember the first END pattern. */ | |
2984 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
|
2985 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2986 /* use syntax iskeyword option */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2987 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2988 |
7 | 2989 for (;;) |
2990 { | |
2991 /* | |
2992 * Find end pattern that matches first after "matchcol". | |
2993 */ | |
2994 best_idx = -1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2995 for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; ++idx) |
7 | 2996 { |
2997 int lc_col = matchcol; | |
6375 | 2998 int r; |
7 | 2999 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3000 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 3001 if (spp->sp_type != SPTYPE_END) /* past last END pattern */ |
3002 break; | |
3003 lc_col -= spp->sp_offsets[SPO_LC_OFF]; | |
3004 if (lc_col < 0) | |
3005 lc_col = 0; | |
3006 | |
3007 regmatch.rmm_ic = spp->sp_ic; | |
3008 regmatch.regprog = spp->sp_prog; | |
6375 | 3009 r = syn_regexec(®match, startpos->lnum, lc_col, |
3010 IF_SYN_TIME(&spp->sp_time)); | |
3011 spp->sp_prog = regmatch.regprog; | |
3012 if (r) | |
7 | 3013 { |
3014 if (best_idx == -1 || regmatch.startpos[0].col | |
3015 < best_regmatch.startpos[0].col) | |
3016 { | |
3017 best_idx = idx; | |
3018 best_regmatch.startpos[0] = regmatch.startpos[0]; | |
3019 best_regmatch.endpos[0] = regmatch.endpos[0]; | |
3020 } | |
3021 } | |
3022 } | |
3023 | |
3024 /* | |
3025 * If all end patterns have been tried, and there is no match, the | |
3026 * item continues until end-of-line. | |
3027 */ | |
3028 if (best_idx == -1) | |
3029 break; | |
3030 | |
3031 /* | |
3032 * If the skip pattern matches before the end pattern, | |
3033 * continue searching after the skip pattern. | |
3034 */ | |
3035 if (spp_skip != NULL) | |
3036 { | |
3037 int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; | |
6375 | 3038 int r; |
7 | 3039 |
3040 if (lc_col < 0) | |
3041 lc_col = 0; | |
3042 regmatch.rmm_ic = spp_skip->sp_ic; | |
3043 regmatch.regprog = spp_skip->sp_prog; | |
6375 | 3044 r = syn_regexec(®match, startpos->lnum, lc_col, |
3045 IF_SYN_TIME(&spp_skip->sp_time)); | |
3046 spp_skip->sp_prog = regmatch.regprog; | |
3047 if (r && regmatch.startpos[0].col | |
7 | 3048 <= best_regmatch.startpos[0].col) |
3049 { | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3050 int line_len; |
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
3051 |
7 | 3052 /* Add offset to skip pattern match */ |
3053 syn_add_end_off(&pos, ®match, spp_skip, SPO_ME_OFF, 1); | |
3054 | |
3055 /* If the skip pattern goes on to the next line, there is no | |
3056 * match with an end pattern in this line. */ | |
3057 if (pos.lnum > startpos->lnum) | |
3058 break; | |
3059 | |
3060 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
|
3061 line_len = (int)STRLEN(line); |
7 | 3062 |
3063 /* take care of an empty match or negative offset */ | |
3064 if (pos.col <= matchcol) | |
3065 ++matchcol; | |
3066 else if (pos.col <= regmatch.endpos[0].col) | |
3067 matchcol = pos.col; | |
3068 else | |
3069 /* Be careful not to jump over the NUL at the end-of-line */ | |
3070 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
|
3071 matchcol < line_len && matchcol < pos.col; |
7 | 3072 ++matchcol) |
3073 ; | |
3074 | |
3075 /* 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
|
3076 if (matchcol >= line_len) |
7 | 3077 break; |
3078 | |
3079 continue; /* start with first end pattern again */ | |
3080 } | |
3081 } | |
3082 | |
3083 /* | |
3084 * Match from start pattern to end pattern. | |
3085 * Correct for match and highlight offset of end pattern. | |
3086 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3087 spp = &(SYN_ITEMS(syn_block)[best_idx]); |
7 | 3088 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); |
3089 /* can't end before the start */ | |
3090 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) | |
3091 m_endpos->col = startpos->col; | |
3092 | |
3093 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); | |
3094 /* can't end before the start */ | |
3095 if (end_endpos->lnum == startpos->lnum | |
3096 && end_endpos->col < startpos->col) | |
3097 end_endpos->col = startpos->col; | |
3098 /* can't end after the match */ | |
3099 limit_pos(end_endpos, m_endpos); | |
3100 | |
3101 /* | |
3102 * If the end group is highlighted differently, adjust the pointers. | |
3103 */ | |
3104 if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) | |
3105 { | |
3106 *end_idx = best_idx; | |
3107 if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) | |
3108 { | |
3109 hl_endpos->lnum = best_regmatch.endpos[0].lnum; | |
3110 hl_endpos->col = best_regmatch.endpos[0].col; | |
3111 } | |
3112 else | |
3113 { | |
3114 hl_endpos->lnum = best_regmatch.startpos[0].lnum; | |
3115 hl_endpos->col = best_regmatch.startpos[0].col; | |
3116 } | |
3117 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; | |
3118 | |
3119 /* can't end before the start */ | |
3120 if (hl_endpos->lnum == startpos->lnum | |
3121 && hl_endpos->col < startpos->col) | |
3122 hl_endpos->col = startpos->col; | |
3123 limit_pos(hl_endpos, m_endpos); | |
3124 | |
3125 /* now the match ends where the highlighting ends, it is turned | |
3126 * into the matchgroup for the end */ | |
3127 *m_endpos = *hl_endpos; | |
3128 } | |
3129 else | |
3130 { | |
3131 *end_idx = 0; | |
3132 *hl_endpos = *end_endpos; | |
3133 } | |
3134 | |
3135 *flagsp = spp->sp_flags; | |
3136 | |
3137 had_match = TRUE; | |
3138 break; | |
3139 } | |
3140 | |
3141 /* no match for an END pattern in this line */ | |
3142 if (!had_match) | |
3143 m_endpos->lnum = 0; | |
3144 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3145 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3146 |
7 | 3147 /* Remove external matches. */ |
3148 unref_extmatch(re_extmatch_in); | |
3149 re_extmatch_in = NULL; | |
3150 } | |
3151 | |
3152 /* | |
3153 * Limit "pos" not to be after "limit". | |
3154 */ | |
3155 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3156 limit_pos(lpos_T *pos, lpos_T *limit) |
7 | 3157 { |
3158 if (pos->lnum > limit->lnum) | |
3159 *pos = *limit; | |
3160 else if (pos->lnum == limit->lnum && pos->col > limit->col) | |
3161 pos->col = limit->col; | |
3162 } | |
3163 | |
3164 /* | |
3165 * Limit "pos" not to be after "limit", unless pos->lnum is zero. | |
3166 */ | |
3167 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3168 limit_pos_zero( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3169 lpos_T *pos, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3170 lpos_T *limit) |
7 | 3171 { |
3172 if (pos->lnum == 0) | |
3173 *pos = *limit; | |
3174 else | |
3175 limit_pos(pos, limit); | |
3176 } | |
3177 | |
3178 /* | |
3179 * Add offset to matched text for end of match or highlight. | |
3180 */ | |
3181 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3182 syn_add_end_off( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3183 lpos_T *result, /* returned position */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3184 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
|
3185 synpat_T *spp, /* matched pattern */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3186 int idx, /* index of offset */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3187 int extra) /* extra chars for offset to start */ |
7 | 3188 { |
3189 int col; | |
1624 | 3190 int off; |
3191 char_u *base; | |
3192 char_u *p; | |
7 | 3193 |
3194 if (spp->sp_off_flags & (1 << idx)) | |
3195 { | |
3196 result->lnum = regmatch->startpos[0].lnum; | |
1624 | 3197 col = regmatch->startpos[0].col; |
3198 off = spp->sp_offsets[idx] + extra; | |
7 | 3199 } |
3200 else | |
3201 { | |
3202 result->lnum = regmatch->endpos[0].lnum; | |
3203 col = regmatch->endpos[0].col; | |
1624 | 3204 off = spp->sp_offsets[idx]; |
3205 } | |
3206 /* Don't go past the end of the line. Matters for "rs=e+2" when there | |
3207 * is a matchgroup. Watch out for match with last NL in the buffer. */ | |
3208 if (result->lnum > syn_buf->b_ml.ml_line_count) | |
3209 col = 0; | |
3210 else if (off != 0) | |
3211 { | |
3212 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3213 p = base + col; | |
3214 if (off > 0) | |
3215 { | |
3216 while (off-- > 0 && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3217 MB_PTR_ADV(p); |
1624 | 3218 } |
3219 else if (off < 0) | |
3220 { | |
3221 while (off++ < 0 && base < p) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3222 MB_PTR_BACK(base, p); |
1624 | 3223 } |
3224 col = (int)(p - base); | |
3225 } | |
3226 result->col = col; | |
7 | 3227 } |
3228 | |
3229 /* | |
3230 * Add offset to matched text for start of match or highlight. | |
3231 * Avoid resulting column to become negative. | |
3232 */ | |
3233 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3234 syn_add_start_off( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3235 lpos_T *result, /* returned position */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3236 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
|
3237 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3238 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3239 int extra) /* extra chars for offset to end */ |
7 | 3240 { |
3241 int col; | |
1624 | 3242 int off; |
3243 char_u *base; | |
3244 char_u *p; | |
7 | 3245 |
3246 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) | |
3247 { | |
3248 result->lnum = regmatch->endpos[0].lnum; | |
1624 | 3249 col = regmatch->endpos[0].col; |
3250 off = spp->sp_offsets[idx] + extra; | |
7 | 3251 } |
3252 else | |
3253 { | |
3254 result->lnum = regmatch->startpos[0].lnum; | |
3255 col = regmatch->startpos[0].col; | |
1624 | 3256 off = spp->sp_offsets[idx]; |
3257 } | |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3258 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
|
3259 { |
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3260 /* 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
|
3261 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
|
3262 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
|
3263 } |
1624 | 3264 if (off != 0) |
3265 { | |
3266 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3267 p = base + col; | |
3268 if (off > 0) | |
3269 { | |
3270 while (off-- && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3271 MB_PTR_ADV(p); |
1624 | 3272 } |
3273 else if (off < 0) | |
3274 { | |
3275 while (off++ && base < p) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11119
diff
changeset
|
3276 MB_PTR_BACK(base, p); |
1624 | 3277 } |
3278 col = (int)(p - base); | |
3279 } | |
3280 result->col = col; | |
7 | 3281 } |
3282 | |
3283 /* | |
3284 * Get current line in syntax buffer. | |
3285 */ | |
3286 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3287 syn_getcurline(void) |
7 | 3288 { |
3289 return ml_get_buf(syn_buf, current_lnum, FALSE); | |
3290 } | |
3291 | |
3292 /* | |
410 | 3293 * Call vim_regexec() to find a match with "rmp" in "syn_buf". |
7 | 3294 * Returns TRUE when there is a match. |
3295 */ | |
3296 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3297 syn_regexec( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3298 regmmatch_T *rmp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3299 linenr_T lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3300 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3301 syn_time_T *st UNUSED) |
4764
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 int r; |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3304 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3305 int timed_out = FALSE; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3306 #endif |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3307 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3308 proftime_T pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3309 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3310 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3311 profile_start(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3312 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3313 |
410 | 3314 rmp->rmm_maxcol = syn_buf->b_p_smc; |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3315 r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3316 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3317 syn_tm, &timed_out |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3318 #else |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3319 NULL, NULL |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3320 #endif |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3321 ); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3322 |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3323 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3324 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3325 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3326 profile_end(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3327 profile_add(&st->total, &pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3328 if (profile_cmp(&pt, &st->slowest) < 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3329 st->slowest = pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3330 ++st->count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3331 if (r > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3332 ++st->match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3333 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3334 #endif |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3335 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3336 if (timed_out) |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3337 syn_win->w_s->b_syn_slow = TRUE; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3338 #endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3339 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3340 if (r > 0) |
7 | 3341 { |
3342 rmp->startpos[0].lnum += lnum; | |
3343 rmp->endpos[0].lnum += lnum; | |
3344 return TRUE; | |
3345 } | |
3346 return FALSE; | |
3347 } | |
3348 | |
3349 /* | |
3350 * Check one position in a line for a matching keyword. | |
3351 * The caller must check if a keyword can start at startcol. | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3352 * Return its ID if found, 0 otherwise. |
7 | 3353 */ |
3354 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3355 check_keyword_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3356 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3357 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
|
3358 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
|
3359 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
|
3360 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
|
3361 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
|
3362 int *ccharp UNUSED) /* conceal substitution char */ |
7 | 3363 { |
134 | 3364 keyentry_T *kp; |
3365 char_u *kwp; | |
7 | 3366 int round; |
134 | 3367 int kwlen; |
7 | 3368 char_u keyword[MAXKEYWLEN + 1]; /* assume max. keyword len is 80 */ |
134 | 3369 hashtab_T *ht; |
3370 hashitem_T *hi; | |
7 | 3371 |
3372 /* Find first character after the keyword. First character was already | |
3373 * checked. */ | |
134 | 3374 kwp = line + startcol; |
3375 kwlen = 0; | |
7 | 3376 do |
3377 { | |
3378 #ifdef FEAT_MBYTE | |
3379 if (has_mbyte) | |
474 | 3380 kwlen += (*mb_ptr2len)(kwp + kwlen); |
7 | 3381 else |
3382 #endif | |
134 | 3383 ++kwlen; |
3384 } | |
4043 | 3385 while (vim_iswordp_buf(kwp + kwlen, syn_buf)); |
134 | 3386 |
3387 if (kwlen > MAXKEYWLEN) | |
7 | 3388 return 0; |
3389 | |
3390 /* | |
3391 * Must make a copy of the keyword, so we can add a NUL and make it | |
3392 * lowercase. | |
3393 */ | |
419 | 3394 vim_strncpy(keyword, kwp, kwlen); |
7 | 3395 |
3396 /* | |
3397 * Try twice: | |
3398 * 1. matching case | |
3399 * 2. ignoring case | |
3400 */ | |
3401 for (round = 1; round <= 2; ++round) | |
3402 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3403 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; |
134 | 3404 if (ht->ht_used == 0) |
7 | 3405 continue; |
134 | 3406 if (round == 2) /* ignore case */ |
3407 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); | |
7 | 3408 |
3409 /* | |
134 | 3410 * Find keywords that match. There can be several with different |
3411 * attributes. | |
7 | 3412 * When current_next_list is non-zero accept only that group, otherwise: |
3413 * Accept a not-contained keyword at toplevel. | |
3414 * Accept a keyword at other levels only if it is in the contains list. | |
3415 */ | |
134 | 3416 hi = hash_find(ht, keyword); |
3417 if (!HASHITEM_EMPTY(hi)) | |
3418 for (kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) | |
7 | 3419 { |
134 | 3420 if (current_next_list != 0 |
3421 ? in_id_list(NULL, current_next_list, &kp->k_syn, 0) | |
3422 : (cur_si == NULL | |
3423 ? !(kp->flags & HL_CONTAINED) | |
3424 : in_id_list(cur_si, cur_si->si_cont_list, | |
3425 &kp->k_syn, kp->flags & HL_CONTAINED))) | |
3426 { | |
3427 *endcolp = startcol + kwlen; | |
3428 *flagsp = kp->flags; | |
3429 *next_listp = kp->next_list; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3430 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3431 *ccharp = kp->k_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3432 #endif |
134 | 3433 return kp->k_syn.id; |
3434 } | |
7 | 3435 } |
3436 } | |
3437 return 0; | |
3438 } | |
3439 | |
3440 /* | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3441 * Handle ":syntax conceal" command. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3442 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3443 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3444 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
|
3445 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3446 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3447 char_u *arg = eap->arg; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3448 char_u *next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3449 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3450 eap->nextcmd = find_nextcmd(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3451 if (eap->skip) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3452 return; |
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 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
|
3455 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
|
3456 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3457 if (curwin->w_s->b_syn_conceal) |
11514
7c42cf66d5be
patch 8.0.0640: mismatch between help and actual message
Christian Brabandt <cb@256bit.org>
parents:
11465
diff
changeset
|
3458 MSG(_("syntax conceal on")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3459 else |
11514
7c42cf66d5be
patch 8.0.0640: mismatch between help and actual message
Christian Brabandt <cb@256bit.org>
parents:
11465
diff
changeset
|
3460 MSG(_("syntax conceal off")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3461 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3462 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
|
3463 curwin->w_s->b_syn_conceal = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3464 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
|
3465 curwin->w_s->b_syn_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3466 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3467 EMSG2(_("E390: Illegal argument: %s"), arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3468 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3469 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3470 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3471 /* |
7 | 3472 * Handle ":syntax case" command. |
3473 */ | |
3474 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3475 syn_cmd_case(exarg_T *eap, int syncing UNUSED) |
7 | 3476 { |
3477 char_u *arg = eap->arg; | |
3478 char_u *next; | |
3479 | |
3480 eap->nextcmd = find_nextcmd(arg); | |
3481 if (eap->skip) | |
3482 return; | |
3483 | |
3484 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
|
3485 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
|
3486 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3487 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
|
3488 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
|
3489 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3490 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
|
3491 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3492 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
|
3493 curwin->w_s->b_syn_ic = FALSE; |
7 | 3494 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
|
3495 curwin->w_s->b_syn_ic = TRUE; |
7 | 3496 else |
3497 EMSG2(_("E390: Illegal argument: %s"), arg); | |
3498 } | |
3499 | |
3500 /* | |
419 | 3501 * Handle ":syntax spell" command. |
3502 */ | |
3503 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3504 syn_cmd_spell(exarg_T *eap, int syncing UNUSED) |
419 | 3505 { |
3506 char_u *arg = eap->arg; | |
3507 char_u *next; | |
3508 | |
3509 eap->nextcmd = find_nextcmd(arg); | |
3510 if (eap->skip) | |
3511 return; | |
3512 | |
3513 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
|
3514 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
|
3515 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3516 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
|
3517 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
|
3518 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
|
3519 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
|
3520 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3521 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
|
3522 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3523 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
|
3524 curwin->w_s->b_syn_spell = SYNSPL_TOP; |
419 | 3525 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
|
3526 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; |
1064 | 3527 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
|
3528 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; |
419 | 3529 else |
6880 | 3530 { |
419 | 3531 EMSG2(_("E390: Illegal argument: %s"), arg); |
6880 | 3532 return; |
3533 } | |
3534 | |
3535 /* assume spell checking changed, force a redraw */ | |
3536 redraw_win_later(curwin, NOT_VALID); | |
419 | 3537 } |
3538 | |
3539 /* | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3540 * Handle ":syntax iskeyword" command. |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3541 */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3542 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3543 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
|
3544 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3545 char_u *arg = eap->arg; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3546 char_u save_chartab[32]; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3547 char_u *save_isk; |
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 if (eap->skip) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3550 return; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3551 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3552 arg = skipwhite(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3553 if (*arg == NUL) |
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 MSG_PUTS("\n"); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3556 MSG_PUTS(_("syntax iskeyword ")); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3557 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
|
3558 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
|
3559 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3560 msg_outtrans((char_u *)"not set"); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3561 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3562 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3563 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3564 if (STRNICMP(arg, "clear", 5) == 0) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3565 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3566 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
|
3567 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3568 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
|
3569 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3570 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3571 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3572 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
|
3573 save_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3574 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
|
3575 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3576 buf_init_chartab(curbuf, FALSE); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3577 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
|
3578 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3579 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
|
3580 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
|
3581 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
|
3582 curbuf->b_p_isk = save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3583 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3584 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3585 redraw_win_later(curwin, NOT_VALID); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3586 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3587 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3588 /* |
7 | 3589 * Clear all syntax info for one buffer. |
3590 */ | |
3591 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3592 syntax_clear(synblock_T *block) |
7 | 3593 { |
3594 int i; | |
3595 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3596 block->b_syn_error = FALSE; /* clear previous error */ |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3597 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3598 block->b_syn_slow = FALSE; /* clear previous timeout */ |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3599 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3600 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
|
3601 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
|
3602 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
|
3603 #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
|
3604 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
|
3605 #endif |
7 | 3606 |
3607 /* free the keywords */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3608 clear_keywtab(&block->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3609 clear_keywtab(&block->b_keywtab_ic); |
7 | 3610 |
3611 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3612 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
|
3613 syn_clear_pattern(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3614 ga_clear(&block->b_syn_patterns); |
7 | 3615 |
3616 /* free the syntax clusters */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3617 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
|
3618 syn_clear_cluster(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3619 ga_clear(&block->b_syn_clusters); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3620 block->b_spell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3621 block->b_nospell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3622 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3623 block->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3624 block->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3625 block->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3626 block->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3627 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3628 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
|
3629 block->b_syn_linecont_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3630 vim_free(block->b_syn_linecont_pat); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3631 block->b_syn_linecont_pat = NULL; |
7 | 3632 #ifdef FEAT_FOLDING |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3633 block->b_syn_folditems = 0; |
7 | 3634 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3635 clear_string_option(&block->b_syn_isk); |
7 | 3636 |
3637 /* free the stored states */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3638 syn_stack_free_all(block); |
7 | 3639 invalidate_current_state(); |
2743 | 3640 |
3641 /* Reset the counter for ":syn include" */ | |
3642 running_syn_inc_tag = 0; | |
7 | 3643 } |
3644 | |
3645 /* | |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3646 * 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
|
3647 */ |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3648 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3649 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
|
3650 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3651 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
|
3652 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3653 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
|
3654 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
|
3655 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
|
3656 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3657 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3658 |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3659 /* |
7 | 3660 * Clear syncing info for one buffer. |
3661 */ | |
3662 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3663 syntax_sync_clear(void) |
7 | 3664 { |
3665 int i; | |
3666 | |
3667 /* free the syntax patterns */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3668 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
|
3669 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
|
3670 syn_remove_pattern(curwin->w_s, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3671 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3672 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
|
3673 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
|
3674 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
|
3675 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
|
3676 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3677 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
|
3678 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
|
3679 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
|
3680 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
|
3681 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
|
3682 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3683 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3684 } |
3685 | |
3686 /* | |
3687 * Remove one pattern from the buffer's pattern list. | |
3688 */ | |
3689 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3690 syn_remove_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3691 synblock_T *block, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3692 int idx) |
7 | 3693 { |
3694 synpat_T *spp; | |
3695 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3696 spp = &(SYN_ITEMS(block)[idx]); |
7 | 3697 #ifdef FEAT_FOLDING |
3698 if (spp->sp_flags & HL_FOLD) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3699 --block->b_syn_folditems; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3700 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3701 syn_clear_pattern(block, idx); |
7 | 3702 mch_memmove(spp, spp + 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3703 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
|
3704 --block->b_syn_patterns.ga_len; |
7 | 3705 } |
3706 | |
3707 /* | |
3708 * Clear and free one syntax pattern. When clearing all, must be called from | |
3709 * last to first! | |
3710 */ | |
3711 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3712 syn_clear_pattern(synblock_T *block, int i) |
7 | 3713 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3714 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
|
3715 vim_regfree(SYN_ITEMS(block)[i].sp_prog); |
7 | 3716 /* 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
|
3717 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
|
3718 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3719 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
|
3720 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
|
3721 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); |
7 | 3722 } |
3723 } | |
3724 | |
3725 /* | |
3726 * Clear and free one syntax cluster. | |
3727 */ | |
3728 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3729 syn_clear_cluster(synblock_T *block, int i) |
7 | 3730 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3731 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
|
3732 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
|
3733 vim_free(SYN_CLSTR(block)[i].scl_list); |
7 | 3734 } |
3735 | |
3736 /* | |
3737 * Handle ":syntax clear" command. | |
3738 */ | |
3739 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3740 syn_cmd_clear(exarg_T *eap, int syncing) |
7 | 3741 { |
3742 char_u *arg = eap->arg; | |
3743 char_u *arg_end; | |
3744 int id; | |
3745 | |
3746 eap->nextcmd = find_nextcmd(arg); | |
3747 if (eap->skip) | |
3748 return; | |
3749 | |
3750 /* | |
3751 * We have to disable this within ":syn include @group filename", | |
3752 * because otherwise @group would get deleted. | |
3753 * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn | |
3754 * clear". | |
3755 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3756 if (curwin->w_s->b_syn_topgrp != 0) |
7 | 3757 return; |
3758 | |
3759 if (ends_excmd(*arg)) | |
3760 { | |
3761 /* | |
3762 * No argument: Clear all syntax items. | |
3763 */ | |
3764 if (syncing) | |
3765 syntax_sync_clear(); | |
3766 else | |
3767 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3768 syntax_clear(curwin->w_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3769 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
|
3770 do_unlet((char_u *)"b:current_syntax", TRUE); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
3771 do_unlet((char_u *)"w:current_syntax", TRUE); |
7 | 3772 } |
3773 } | |
3774 else | |
3775 { | |
3776 /* | |
3777 * Clear the group IDs that are in the argument. | |
3778 */ | |
3779 while (!ends_excmd(*arg)) | |
3780 { | |
3781 arg_end = skiptowhite(arg); | |
3782 if (*arg == '@') | |
3783 { | |
3784 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3785 if (id == 0) | |
3786 { | |
3787 EMSG2(_("E391: No such syntax cluster: %s"), arg); | |
3788 break; | |
3789 } | |
3790 else | |
3791 { | |
3792 /* | |
3793 * We can't physically delete a cluster without changing | |
3794 * the IDs of other clusters, so we do the next best thing | |
3795 * and make it empty. | |
3796 */ | |
3797 short scl_id = id - SYNID_CLUSTER; | |
3798 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3799 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
|
3800 SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; |
7 | 3801 } |
3802 } | |
3803 else | |
3804 { | |
3805 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3806 if (id == 0) | |
3807 { | |
3808 EMSG2(_(e_nogroup), arg); | |
3809 break; | |
3810 } | |
3811 else | |
3812 syn_clear_one(id, syncing); | |
3813 } | |
3814 arg = skipwhite(arg_end); | |
3815 } | |
3816 } | |
745 | 3817 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3818 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 3819 } |
3820 | |
3821 /* | |
3822 * Clear one syntax group for the current buffer. | |
3823 */ | |
3824 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3825 syn_clear_one(int id, int syncing) |
7 | 3826 { |
3827 synpat_T *spp; | |
3828 int idx; | |
3829 | |
3830 /* Clear keywords only when not ":syn sync clear group-name" */ | |
3831 if (!syncing) | |
3832 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3833 (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
|
3834 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); |
7 | 3835 } |
3836 | |
3837 /* clear the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3838 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
|
3839 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3840 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3841 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3842 continue; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3843 syn_remove_pattern(curwin->w_s, idx); |
7 | 3844 } |
3845 } | |
3846 | |
3847 /* | |
3848 * Handle ":syntax on" command. | |
3849 */ | |
3850 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3851 syn_cmd_on(exarg_T *eap, int syncing UNUSED) |
7 | 3852 { |
3853 syn_cmd_onoff(eap, "syntax"); | |
3854 } | |
3855 | |
3856 /* | |
3857 * Handle ":syntax enable" command. | |
3858 */ | |
3859 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3860 syn_cmd_enable(exarg_T *eap, int syncing UNUSED) |
7 | 3861 { |
3862 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"enable"); | |
3863 syn_cmd_onoff(eap, "syntax"); | |
148 | 3864 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3865 } |
3866 | |
3867 /* | |
3868 * Handle ":syntax reset" command. | |
8815
50d9fb580ffe
commit https://github.com/vim/vim/commit/8bc189e81aa98ba4aebb03a9dc9527a210fce816
Christian Brabandt <cb@256bit.org>
parents:
8806
diff
changeset
|
3869 * It actually resets highlighting, not syntax. |
7 | 3870 */ |
3871 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3872 syn_cmd_reset(exarg_T *eap, int syncing UNUSED) |
7 | 3873 { |
3874 eap->nextcmd = check_nextcmd(eap->arg); | |
3875 if (!eap->skip) | |
3876 { | |
3877 set_internal_string_var((char_u *)"syntax_cmd", (char_u *)"reset"); | |
3878 do_cmdline_cmd((char_u *)"runtime! syntax/syncolor.vim"); | |
148 | 3879 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3880 } |
3881 } | |
3882 | |
3883 /* | |
3884 * Handle ":syntax manual" command. | |
3885 */ | |
3886 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3887 syn_cmd_manual(exarg_T *eap, int syncing UNUSED) |
7 | 3888 { |
3889 syn_cmd_onoff(eap, "manual"); | |
3890 } | |
3891 | |
3892 /* | |
3893 * Handle ":syntax off" command. | |
3894 */ | |
3895 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3896 syn_cmd_off(exarg_T *eap, int syncing UNUSED) |
7 | 3897 { |
3898 syn_cmd_onoff(eap, "nosyntax"); | |
3899 } | |
3900 | |
3901 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3902 syn_cmd_onoff(exarg_T *eap, char *name) |
7 | 3903 { |
3904 char_u buf[100]; | |
3905 | |
3906 eap->nextcmd = check_nextcmd(eap->arg); | |
3907 if (!eap->skip) | |
3908 { | |
3909 STRCPY(buf, "so "); | |
274 | 3910 vim_snprintf((char *)buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); |
7 | 3911 do_cmdline_cmd(buf); |
3912 } | |
3913 } | |
3914 | |
3915 /* | |
3916 * Handle ":syntax [list]" command: list current syntax words. | |
3917 */ | |
3918 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3919 syn_cmd_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3920 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3921 int syncing) /* when TRUE: list syncing items */ |
7 | 3922 { |
3923 char_u *arg = eap->arg; | |
3924 int id; | |
3925 char_u *arg_end; | |
3926 | |
3927 eap->nextcmd = find_nextcmd(arg); | |
3928 if (eap->skip) | |
3929 return; | |
3930 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3931 if (!syntax_present(curwin)) |
7 | 3932 { |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3933 MSG(_(msg_no_items)); |
7 | 3934 return; |
3935 } | |
3936 | |
3937 if (syncing) | |
3938 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3939 if (curwin->w_s->b_syn_sync_flags & SF_CCOMMENT) |
7 | 3940 { |
3941 MSG_PUTS(_("syncing on C-style comments")); | |
3942 syn_lines_msg(); | |
3943 syn_match_msg(); | |
3944 return; | |
3945 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3946 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
|
3947 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3948 if (curwin->w_s->b_syn_sync_minlines == 0) |
7 | 3949 MSG_PUTS(_("no syncing")); |
3950 else | |
3951 { | |
3952 MSG_PUTS(_("syncing starts ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3953 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
7 | 3954 MSG_PUTS(_(" lines before top line")); |
3955 syn_match_msg(); | |
3956 } | |
3957 return; | |
3958 } | |
3959 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
|
3960 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
|
3961 || 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
|
3962 || curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3963 { |
3964 MSG_PUTS(_("\nsyncing on items")); | |
3965 syn_lines_msg(); | |
3966 syn_match_msg(); | |
3967 } | |
3968 } | |
3969 else | |
3970 MSG_PUTS_TITLE(_("\n--- Syntax items ---")); | |
3971 if (ends_excmd(*arg)) | |
3972 { | |
3973 /* | |
3974 * No argument: List all group IDs and all syntax clusters. | |
3975 */ | |
3976 for (id = 1; id <= highlight_ga.ga_len && !got_int; ++id) | |
3977 syn_list_one(id, syncing, FALSE); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3978 for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) |
7 | 3979 syn_list_cluster(id); |
3980 } | |
3981 else | |
3982 { | |
3983 /* | |
3984 * List the group IDs and syntax clusters that are in the argument. | |
3985 */ | |
3986 while (!ends_excmd(*arg) && !got_int) | |
3987 { | |
3988 arg_end = skiptowhite(arg); | |
3989 if (*arg == '@') | |
3990 { | |
3991 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3992 if (id == 0) | |
3993 EMSG2(_("E392: No such syntax cluster: %s"), arg); | |
3994 else | |
3995 syn_list_cluster(id - SYNID_CLUSTER); | |
3996 } | |
3997 else | |
3998 { | |
3999 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
4000 if (id == 0) | |
4001 EMSG2(_(e_nogroup), arg); | |
4002 else | |
4003 syn_list_one(id, syncing, TRUE); | |
4004 } | |
4005 arg = skipwhite(arg_end); | |
4006 } | |
4007 } | |
4008 eap->nextcmd = check_nextcmd(arg); | |
4009 } | |
4010 | |
4011 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4012 syn_lines_msg(void) |
7 | 4013 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4014 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
|
4015 || curwin->w_s->b_syn_sync_minlines > 0) |
7 | 4016 { |
4017 MSG_PUTS("; "); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4018 if (curwin->w_s->b_syn_sync_minlines > 0) |
7 | 4019 { |
4020 MSG_PUTS(_("minimal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4021 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4022 if (curwin->w_s->b_syn_sync_maxlines) |
7 | 4023 MSG_PUTS(", "); |
4024 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4025 if (curwin->w_s->b_syn_sync_maxlines > 0) |
7 | 4026 { |
4027 MSG_PUTS(_("maximal ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4028 msg_outnum(curwin->w_s->b_syn_sync_maxlines); |
7 | 4029 } |
4030 MSG_PUTS(_(" lines before top line")); | |
4031 } | |
4032 } | |
4033 | |
4034 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4035 syn_match_msg(void) |
7 | 4036 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4037 if (curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 4038 { |
4039 MSG_PUTS(_("; match ")); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4040 msg_outnum(curwin->w_s->b_syn_sync_linebreaks); |
7 | 4041 MSG_PUTS(_(" line breaks")); |
4042 } | |
4043 } | |
4044 | |
4045 static int last_matchgroup; | |
4046 | |
4047 struct name_list | |
4048 { | |
4049 int flag; | |
4050 char *name; | |
4051 }; | |
4052 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
4053 static void syn_list_flags(struct name_list *nl, int flags, int attr); |
7 | 4054 |
4055 /* | |
4056 * List one syntax item, for ":syntax" or "syntax list syntax_name". | |
4057 */ | |
4058 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4059 syn_list_one( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4060 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4061 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
|
4062 int link_only) /* when TRUE; list link-only too */ |
7 | 4063 { |
4064 int attr; | |
4065 int idx; | |
4066 int did_header = FALSE; | |
4067 synpat_T *spp; | |
4068 static struct name_list namelist1[] = | |
4069 { | |
4070 {HL_DISPLAY, "display"}, | |
4071 {HL_CONTAINED, "contained"}, | |
4072 {HL_ONELINE, "oneline"}, | |
4073 {HL_KEEPEND, "keepend"}, | |
4074 {HL_EXTEND, "extend"}, | |
4075 {HL_EXCLUDENL, "excludenl"}, | |
4076 {HL_TRANSP, "transparent"}, | |
4077 {HL_FOLD, "fold"}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4078 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4079 {HL_CONCEAL, "conceal"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4080 {HL_CONCEALENDS, "concealends"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4081 #endif |
7 | 4082 {0, NULL} |
4083 }; | |
4084 static struct name_list namelist2[] = | |
4085 { | |
4086 {HL_SKIPWHITE, "skipwhite"}, | |
4087 {HL_SKIPNL, "skipnl"}, | |
4088 {HL_SKIPEMPTY, "skipempty"}, | |
4089 {0, NULL} | |
4090 }; | |
4091 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4092 attr = HL_ATTR(HLF_D); /* highlight like directories */ |
7 | 4093 |
4094 /* list the keywords for "id" */ | |
4095 if (!syncing) | |
4096 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4097 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
|
4098 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, |
7 | 4099 did_header, attr); |
4100 } | |
4101 | |
4102 /* list the patterns for "id" */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4103 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
|
4104 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4105 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 4106 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
4107 continue; | |
4108 | |
4109 (void)syn_list_header(did_header, 999, id); | |
4110 did_header = TRUE; | |
4111 last_matchgroup = 0; | |
4112 if (spp->sp_type == SPTYPE_MATCH) | |
4113 { | |
4114 put_pattern("match", ' ', spp, attr); | |
4115 msg_putchar(' '); | |
4116 } | |
4117 else if (spp->sp_type == SPTYPE_START) | |
4118 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4119 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
|
4120 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
|
4121 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
|
4122 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
|
4123 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
|
4124 && 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
|
4125 put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
7 | 4126 --idx; |
4127 msg_putchar(' '); | |
4128 } | |
4129 syn_list_flags(namelist1, spp->sp_flags, attr); | |
4130 | |
4131 if (spp->sp_cont_list != NULL) | |
4132 put_id_list((char_u *)"contains", spp->sp_cont_list, attr); | |
4133 | |
4134 if (spp->sp_syn.cont_in_list != NULL) | |
4135 put_id_list((char_u *)"containedin", | |
4136 spp->sp_syn.cont_in_list, attr); | |
4137 | |
4138 if (spp->sp_next_list != NULL) | |
4139 { | |
4140 put_id_list((char_u *)"nextgroup", spp->sp_next_list, attr); | |
4141 syn_list_flags(namelist2, spp->sp_flags, attr); | |
4142 } | |
4143 if (spp->sp_flags & (HL_SYNC_HERE|HL_SYNC_THERE)) | |
4144 { | |
4145 if (spp->sp_flags & HL_SYNC_HERE) | |
4146 msg_puts_attr((char_u *)"grouphere", attr); | |
4147 else | |
4148 msg_puts_attr((char_u *)"groupthere", attr); | |
4149 msg_putchar(' '); | |
4150 if (spp->sp_sync_idx >= 0) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4151 msg_outtrans(HL_TABLE()[SYN_ITEMS(curwin->w_s) |
7 | 4152 [spp->sp_sync_idx].sp_syn.id - 1].sg_name); |
4153 else | |
4154 MSG_PUTS("NONE"); | |
4155 msg_putchar(' '); | |
4156 } | |
4157 } | |
4158 | |
4159 /* list the link, if there is one */ | |
4160 if (HL_TABLE()[id - 1].sg_link && (did_header || link_only) && !got_int) | |
4161 { | |
4162 (void)syn_list_header(did_header, 999, id); | |
4163 msg_puts_attr((char_u *)"links to", attr); | |
4164 msg_putchar(' '); | |
4165 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
4166 } | |
4167 } | |
4168 | |
4169 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4170 syn_list_flags(struct name_list *nlist, int flags, int attr) |
7 | 4171 { |
4172 int i; | |
4173 | |
3263 | 4174 for (i = 0; nlist[i].flag != 0; ++i) |
4175 if (flags & nlist[i].flag) | |
4176 { | |
4177 msg_puts_attr((char_u *)nlist[i].name, attr); | |
7 | 4178 msg_putchar(' '); |
4179 } | |
4180 } | |
4181 | |
4182 /* | |
4183 * List one syntax cluster, for ":syntax" or "syntax list syntax_name". | |
4184 */ | |
4185 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4186 syn_list_cluster(int id) |
7 | 4187 { |
4188 int endcol = 15; | |
4189 | |
4190 /* slight hack: roughly duplicate the guts of syn_list_header() */ | |
4191 msg_putchar('\n'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4192 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); |
7 | 4193 |
4194 if (msg_col >= endcol) /* output at least one space */ | |
4195 endcol = msg_col + 1; | |
4196 if (Columns <= endcol) /* avoid hang for tiny window */ | |
4197 endcol = Columns - 1; | |
4198 | |
4199 msg_advance(endcol); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4200 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
|
4201 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4202 put_id_list((char_u *)"cluster", SYN_CLSTR(curwin->w_s)[id].scl_list, |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4203 HL_ATTR(HLF_D)); |
7 | 4204 } |
4205 else | |
4206 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4207 msg_puts_attr((char_u *)"cluster", HL_ATTR(HLF_D)); |
7 | 4208 msg_puts((char_u *)"=NONE"); |
4209 } | |
4210 } | |
4211 | |
4212 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4213 put_id_list(char_u *name, short *list, int attr) |
7 | 4214 { |
4215 short *p; | |
4216 | |
4217 msg_puts_attr(name, attr); | |
4218 msg_putchar('='); | |
4219 for (p = list; *p; ++p) | |
4220 { | |
4221 if (*p >= SYNID_ALLBUT && *p < SYNID_TOP) | |
4222 { | |
4223 if (p[1]) | |
4224 MSG_PUTS("ALLBUT"); | |
4225 else | |
4226 MSG_PUTS("ALL"); | |
4227 } | |
4228 else if (*p >= SYNID_TOP && *p < SYNID_CONTAINED) | |
4229 { | |
4230 MSG_PUTS("TOP"); | |
4231 } | |
4232 else if (*p >= SYNID_CONTAINED && *p < SYNID_CLUSTER) | |
4233 { | |
4234 MSG_PUTS("CONTAINED"); | |
4235 } | |
4236 else if (*p >= SYNID_CLUSTER) | |
4237 { | |
4238 short scl_id = *p - SYNID_CLUSTER; | |
4239 | |
4240 msg_putchar('@'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4241 msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); |
7 | 4242 } |
4243 else | |
4244 msg_outtrans(HL_TABLE()[*p - 1].sg_name); | |
4245 if (p[1]) | |
4246 msg_putchar(','); | |
4247 } | |
4248 msg_putchar(' '); | |
4249 } | |
4250 | |
4251 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4252 put_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4253 char *s, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4254 int c, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4255 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4256 int attr) |
7 | 4257 { |
4258 long n; | |
4259 int mask; | |
4260 int first; | |
4261 static char *sepchars = "/+=-#@\"|'^&"; | |
4262 int i; | |
4263 | |
4264 /* May have to write "matchgroup=group" */ | |
4265 if (last_matchgroup != spp->sp_syn_match_id) | |
4266 { | |
4267 last_matchgroup = spp->sp_syn_match_id; | |
4268 msg_puts_attr((char_u *)"matchgroup", attr); | |
4269 msg_putchar('='); | |
4270 if (last_matchgroup == 0) | |
4271 msg_outtrans((char_u *)"NONE"); | |
4272 else | |
4273 msg_outtrans(HL_TABLE()[last_matchgroup - 1].sg_name); | |
4274 msg_putchar(' '); | |
4275 } | |
4276 | |
4277 /* output the name of the pattern and an '=' or ' ' */ | |
4278 msg_puts_attr((char_u *)s, attr); | |
4279 msg_putchar(c); | |
4280 | |
4281 /* output the pattern, in between a char that is not in the pattern */ | |
4282 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) | |
4283 if (sepchars[++i] == NUL) | |
4284 { | |
4285 i = 0; /* no good char found, just use the first one */ | |
4286 break; | |
4287 } | |
4288 msg_putchar(sepchars[i]); | |
4289 msg_outtrans(spp->sp_pattern); | |
4290 msg_putchar(sepchars[i]); | |
4291 | |
4292 /* output any pattern options */ | |
4293 first = TRUE; | |
4294 for (i = 0; i < SPO_COUNT; ++i) | |
4295 { | |
4296 mask = (1 << i); | |
4297 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) | |
4298 { | |
4299 if (!first) | |
4300 msg_putchar(','); /* separate with commas */ | |
4301 msg_puts((char_u *)spo_name_tab[i]); | |
4302 n = spp->sp_offsets[i]; | |
4303 if (i != SPO_LC_OFF) | |
4304 { | |
4305 if (spp->sp_off_flags & mask) | |
4306 msg_putchar('s'); | |
4307 else | |
4308 msg_putchar('e'); | |
4309 if (n > 0) | |
4310 msg_putchar('+'); | |
4311 } | |
4312 if (n || i == SPO_LC_OFF) | |
4313 msg_outnum(n); | |
4314 first = FALSE; | |
4315 } | |
4316 } | |
4317 msg_putchar(' '); | |
4318 } | |
4319 | |
4320 /* | |
4321 * List or clear the keywords for one syntax group. | |
4322 * Return TRUE if the header has been printed. | |
4323 */ | |
4324 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4325 syn_list_keywords( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4326 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4327 hashtab_T *ht, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4328 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
|
4329 int attr) |
7 | 4330 { |
4331 int outlen; | |
134 | 4332 hashitem_T *hi; |
4333 keyentry_T *kp; | |
4334 int todo; | |
7 | 4335 int prev_contained = 0; |
4336 short *prev_next_list = NULL; | |
4337 short *prev_cont_in_list = NULL; | |
4338 int prev_skipnl = 0; | |
4339 int prev_skipwhite = 0; | |
4340 int prev_skipempty = 0; | |
4341 | |
4342 /* | |
4343 * Unfortunately, this list of keywords is not sorted on alphabet but on | |
4344 * hash value... | |
4345 */ | |
835 | 4346 todo = (int)ht->ht_used; |
134 | 4347 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
4348 { | |
4349 if (!HASHITEM_EMPTY(hi)) | |
4350 { | |
4351 --todo; | |
4352 for (kp = HI2KE(hi); kp != NULL && !got_int; kp = kp->ke_next) | |
7 | 4353 { |
134 | 4354 if (kp->k_syn.id == id) |
7 | 4355 { |
134 | 4356 if (prev_contained != (kp->flags & HL_CONTAINED) |
4357 || prev_skipnl != (kp->flags & HL_SKIPNL) | |
4358 || prev_skipwhite != (kp->flags & HL_SKIPWHITE) | |
4359 || prev_skipempty != (kp->flags & HL_SKIPEMPTY) | |
4360 || prev_cont_in_list != kp->k_syn.cont_in_list | |
4361 || prev_next_list != kp->next_list) | |
4362 outlen = 9999; | |
4363 else | |
4364 outlen = (int)STRLEN(kp->keyword); | |
4365 /* output "contained" and "nextgroup" on each line */ | |
4366 if (syn_list_header(did_header, outlen, id)) | |
4367 { | |
4368 prev_contained = 0; | |
4369 prev_next_list = NULL; | |
4370 prev_cont_in_list = NULL; | |
4371 prev_skipnl = 0; | |
4372 prev_skipwhite = 0; | |
4373 prev_skipempty = 0; | |
4374 } | |
4375 did_header = TRUE; | |
4376 if (prev_contained != (kp->flags & HL_CONTAINED)) | |
4377 { | |
4378 msg_puts_attr((char_u *)"contained", attr); | |
4379 msg_putchar(' '); | |
4380 prev_contained = (kp->flags & HL_CONTAINED); | |
4381 } | |
4382 if (kp->k_syn.cont_in_list != prev_cont_in_list) | |
4383 { | |
4384 put_id_list((char_u *)"containedin", | |
4385 kp->k_syn.cont_in_list, attr); | |
4386 msg_putchar(' '); | |
4387 prev_cont_in_list = kp->k_syn.cont_in_list; | |
4388 } | |
4389 if (kp->next_list != prev_next_list) | |
4390 { | |
4391 put_id_list((char_u *)"nextgroup", kp->next_list, attr); | |
4392 msg_putchar(' '); | |
4393 prev_next_list = kp->next_list; | |
4394 if (kp->flags & HL_SKIPNL) | |
4395 { | |
4396 msg_puts_attr((char_u *)"skipnl", attr); | |
4397 msg_putchar(' '); | |
4398 prev_skipnl = (kp->flags & HL_SKIPNL); | |
4399 } | |
4400 if (kp->flags & HL_SKIPWHITE) | |
4401 { | |
4402 msg_puts_attr((char_u *)"skipwhite", attr); | |
4403 msg_putchar(' '); | |
4404 prev_skipwhite = (kp->flags & HL_SKIPWHITE); | |
4405 } | |
4406 if (kp->flags & HL_SKIPEMPTY) | |
4407 { | |
4408 msg_puts_attr((char_u *)"skipempty", attr); | |
4409 msg_putchar(' '); | |
4410 prev_skipempty = (kp->flags & HL_SKIPEMPTY); | |
4411 } | |
4412 } | |
4413 msg_outtrans(kp->keyword); | |
7 | 4414 } |
4415 } | |
4416 } | |
4417 } | |
4418 | |
4419 return did_header; | |
4420 } | |
4421 | |
4422 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4423 syn_clear_keyword(int id, hashtab_T *ht) |
134 | 4424 { |
4425 hashitem_T *hi; | |
4426 keyentry_T *kp; | |
4427 keyentry_T *kp_prev; | |
4428 keyentry_T *kp_next; | |
4429 int todo; | |
4430 | |
4431 hash_lock(ht); | |
835 | 4432 todo = (int)ht->ht_used; |
134 | 4433 for (hi = ht->ht_array; todo > 0; ++hi) |
4434 { | |
4435 if (!HASHITEM_EMPTY(hi)) | |
4436 { | |
4437 --todo; | |
4438 kp_prev = NULL; | |
4439 for (kp = HI2KE(hi); kp != NULL; ) | |
7 | 4440 { |
134 | 4441 if (kp->k_syn.id == id) |
4442 { | |
4443 kp_next = kp->ke_next; | |
4444 if (kp_prev == NULL) | |
4445 { | |
4446 if (kp_next == NULL) | |
4447 hash_remove(ht, hi); | |
4448 else | |
4449 hi->hi_key = KE2HIKEY(kp_next); | |
4450 } | |
4451 else | |
4452 kp_prev->ke_next = kp_next; | |
4453 vim_free(kp->next_list); | |
4454 vim_free(kp->k_syn.cont_in_list); | |
4455 vim_free(kp); | |
4456 kp = kp_next; | |
4457 } | |
7 | 4458 else |
134 | 4459 { |
4460 kp_prev = kp; | |
4461 kp = kp->ke_next; | |
4462 } | |
7 | 4463 } |
134 | 4464 } |
4465 } | |
4466 hash_unlock(ht); | |
4467 } | |
4468 | |
4469 /* | |
4470 * Clear a whole keyword table. | |
7 | 4471 */ |
4472 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4473 clear_keywtab(hashtab_T *ht) |
134 | 4474 { |
4475 hashitem_T *hi; | |
4476 int todo; | |
4477 keyentry_T *kp; | |
4478 keyentry_T *kp_next; | |
4479 | |
835 | 4480 todo = (int)ht->ht_used; |
134 | 4481 for (hi = ht->ht_array; todo > 0; ++hi) |
4482 { | |
4483 if (!HASHITEM_EMPTY(hi)) | |
4484 { | |
4485 --todo; | |
4486 for (kp = HI2KE(hi); kp != NULL; kp = kp_next) | |
7 | 4487 { |
134 | 4488 kp_next = kp->ke_next; |
4489 vim_free(kp->next_list); | |
4490 vim_free(kp->k_syn.cont_in_list); | |
4491 vim_free(kp); | |
7 | 4492 } |
134 | 4493 } |
4494 } | |
4495 hash_clear(ht); | |
4496 hash_init(ht); | |
7 | 4497 } |
4498 | |
4499 /* | |
4500 * Add a keyword to the list of keywords. | |
4501 */ | |
4502 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4503 add_keyword( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4504 char_u *name, /* name of keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4505 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
|
4506 int flags, /* flags for this keyword */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4507 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
|
4508 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
|
4509 int conceal_char) |
7 | 4510 { |
134 | 4511 keyentry_T *kp; |
4512 hashtab_T *ht; | |
4513 hashitem_T *hi; | |
154 | 4514 char_u *name_ic; |
134 | 4515 long_u hash; |
154 | 4516 char_u name_folded[MAXKEYWLEN + 1]; |
7 | 4517 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4518 if (curwin->w_s->b_syn_ic) |
154 | 4519 name_ic = str_foldcase(name, (int)STRLEN(name), |
4520 name_folded, MAXKEYWLEN + 1); | |
4521 else | |
4522 name_ic = name; | |
134 | 4523 kp = (keyentry_T *)alloc((int)(sizeof(keyentry_T) + STRLEN(name_ic))); |
4524 if (kp == NULL) | |
4525 return; | |
4526 STRCPY(kp->keyword, name_ic); | |
4527 kp->k_syn.id = id; | |
4528 kp->k_syn.inc_tag = current_syn_inc_tag; | |
4529 kp->flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4530 kp->k_char = conceal_char; |
134 | 4531 kp->k_syn.cont_in_list = copy_id_list(cont_in_list); |
4532 if (cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4533 curwin->w_s->b_syn_containedin = TRUE; |
134 | 4534 kp->next_list = copy_id_list(next_list); |
4535 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4536 if (curwin->w_s->b_syn_ic) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4537 ht = &curwin->w_s->b_keywtab_ic; |
7 | 4538 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4539 ht = &curwin->w_s->b_keywtab; |
134 | 4540 |
4541 hash = hash_hash(kp->keyword); | |
4542 hi = hash_lookup(ht, kp->keyword, hash); | |
4543 if (HASHITEM_EMPTY(hi)) | |
4544 { | |
4545 /* new keyword, add to hashtable */ | |
4546 kp->ke_next = NULL; | |
4547 hash_add_item(ht, hi, kp->keyword, hash); | |
4548 } | |
4549 else | |
4550 { | |
4551 /* keyword already exists, prepend to list */ | |
4552 kp->ke_next = HI2KE(hi); | |
4553 hi->hi_key = KE2HIKEY(kp); | |
4554 } | |
7 | 4555 } |
4556 | |
4557 /* | |
4558 * Get the start and end of the group name argument. | |
4559 * Return a pointer to the first argument. | |
4560 * Return NULL if the end of the command was found instead of further args. | |
4561 */ | |
4562 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4563 get_group_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4564 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
|
4565 char_u **name_end) /* pointer to end of the name */ |
7 | 4566 { |
4567 char_u *rest; | |
4568 | |
4569 *name_end = skiptowhite(arg); | |
4570 rest = skipwhite(*name_end); | |
4571 | |
4572 /* | |
4573 * Check if there are enough arguments. The first argument may be a | |
4574 * pattern, where '|' is allowed, so only check for NUL. | |
4575 */ | |
4576 if (ends_excmd(*arg) || *rest == NUL) | |
4577 return NULL; | |
4578 return rest; | |
4579 } | |
4580 | |
4581 /* | |
4582 * Check for syntax command option arguments. | |
4583 * This can be called at any place in the list of arguments, and just picks | |
4584 * out the arguments that are known. Can be called several times in a row to | |
4585 * collect all options in between other arguments. | |
4586 * Return a pointer to the next argument (which isn't an option). | |
4587 * Return NULL for any error; | |
4588 */ | |
4589 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4590 get_syn_options( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4591 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
|
4592 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
|
4593 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
|
4594 int skip) /* TRUE if skipping over command */ |
154 | 4595 { |
7 | 4596 char_u *gname_start, *gname; |
4597 int syn_id; | |
4598 int len; | |
154 | 4599 char *p; |
7 | 4600 int i; |
4601 int fidx; | |
4602 static struct flag | |
4603 { | |
4604 char *name; | |
154 | 4605 int argtype; |
4606 int flags; | |
4607 } flagtab[] = { {"cCoOnNtTaAiInNeEdD", 0, HL_CONTAINED}, | |
4608 {"oOnNeElLiInNeE", 0, HL_ONELINE}, | |
4609 {"kKeEeEpPeEnNdD", 0, HL_KEEPEND}, | |
4610 {"eExXtTeEnNdD", 0, HL_EXTEND}, | |
4611 {"eExXcClLuUdDeEnNlL", 0, HL_EXCLUDENL}, | |
4612 {"tTrRaAnNsSpPaArReEnNtT", 0, HL_TRANSP}, | |
4613 {"sSkKiIpPnNlL", 0, HL_SKIPNL}, | |
4614 {"sSkKiIpPwWhHiItTeE", 0, HL_SKIPWHITE}, | |
4615 {"sSkKiIpPeEmMpPtTyY", 0, HL_SKIPEMPTY}, | |
4616 {"gGrRoOuUpPhHeErReE", 0, HL_SYNC_HERE}, | |
4617 {"gGrRoOuUpPtThHeErReE", 0, HL_SYNC_THERE}, | |
4618 {"dDiIsSpPlLaAyY", 0, HL_DISPLAY}, | |
4619 {"fFoOlLdD", 0, HL_FOLD}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4620 {"cCoOnNcCeEaAlL", 0, HL_CONCEAL}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4621 {"cCoOnNcCeEaAlLeEnNdDsS", 0, HL_CONCEALENDS}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4622 {"cCcChHaArR", 11, 0}, |
154 | 4623 {"cCoOnNtTaAiInNsS", 1, 0}, |
4624 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, | |
4625 {"nNeExXtTgGrRoOuUpP", 3, 0}, | |
7 | 4626 }; |
154 | 4627 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; |
7 | 4628 |
4629 if (arg == NULL) /* already detected error */ | |
4630 return NULL; | |
4631 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4632 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4633 if (curwin->w_s->b_syn_conceal) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4634 opt->flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4635 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4636 |
7 | 4637 for (;;) |
4638 { | |
154 | 4639 /* |
4640 * This is used very often when a large number of keywords is defined. | |
4641 * Need to skip quickly when no option name is found. | |
4642 * Also avoid tolower(), it's slow. | |
4643 */ | |
4644 if (strchr(first_letters, *arg) == NULL) | |
4645 break; | |
7 | 4646 |
4647 for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; ) | |
4648 { | |
154 | 4649 p = flagtab[fidx].name; |
4650 for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) | |
4651 if (arg[len] != p[i] && arg[len] != p[i + 1]) | |
4652 break; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4653 if (p[i] == NUL && (VIM_ISWHITE(arg[len]) |
154 | 4654 || (flagtab[fidx].argtype > 0 |
4655 ? arg[len] == '=' | |
4656 : ends_excmd(arg[len])))) | |
7 | 4657 { |
154 | 4658 if (opt->keyword |
4659 && (flagtab[fidx].flags == HL_DISPLAY | |
4660 || flagtab[fidx].flags == HL_FOLD | |
4661 || flagtab[fidx].flags == HL_EXTEND)) | |
7 | 4662 /* treat "display", "fold" and "extend" as a keyword */ |
4663 fidx = -1; | |
4664 break; | |
4665 } | |
4666 } | |
154 | 4667 if (fidx < 0) /* no match found */ |
4668 break; | |
4669 | |
4670 if (flagtab[fidx].argtype == 1) | |
4671 { | |
4672 if (!opt->has_cont_list) | |
7 | 4673 { |
4674 EMSG(_("E395: contains argument not accepted here")); | |
4675 return NULL; | |
4676 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4677 if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) |
7 | 4678 return NULL; |
4679 } | |
154 | 4680 else if (flagtab[fidx].argtype == 2) |
4681 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4682 if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL) |
7 | 4683 return NULL; |
4684 } | |
154 | 4685 else if (flagtab[fidx].argtype == 3) |
4686 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4687 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) |
7 | 4688 return NULL; |
4689 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4690 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
|
4691 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4692 #ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4693 /* cchar=? */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4694 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4695 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4696 # ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4697 *conceal_char = mb_ptr2char(arg + 6); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4698 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4699 arg += mb_ptr2len(arg + 6) - 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4700 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4701 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4702 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4703 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4704 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4705 *conceal_char = arg[6]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4706 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4707 ; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4708 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4709 } |
2686 | 4710 #ifdef FEAT_CONCEAL |
4711 if (!vim_isprintc_strict(*conceal_char)) | |
4712 { | |
4713 EMSG(_("E844: invalid cchar value")); | |
4714 return NULL; | |
4715 } | |
4716 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4717 arg = skipwhite(arg + 7); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4718 } |
7 | 4719 else |
154 | 4720 { |
4721 opt->flags |= flagtab[fidx].flags; | |
4722 arg = skipwhite(arg + len); | |
4723 | |
4724 if (flagtab[fidx].flags == HL_SYNC_HERE | |
4725 || flagtab[fidx].flags == HL_SYNC_THERE) | |
4726 { | |
4727 if (opt->sync_idx == NULL) | |
4728 { | |
4729 EMSG(_("E393: group[t]here not accepted here")); | |
4730 return NULL; | |
4731 } | |
4732 gname_start = arg; | |
4733 arg = skiptowhite(arg); | |
4734 if (gname_start == arg) | |
4735 return NULL; | |
4736 gname = vim_strnsave(gname_start, (int)(arg - gname_start)); | |
4737 if (gname == NULL) | |
4738 return NULL; | |
4739 if (STRCMP(gname, "NONE") == 0) | |
4740 *opt->sync_idx = NONE_IDX; | |
4741 else | |
4742 { | |
4743 syn_id = syn_name2id(gname); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4744 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
|
4745 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
|
4746 && SYN_ITEMS(curwin->w_s)[i].sp_type == SPTYPE_START) |
154 | 4747 { |
4748 *opt->sync_idx = i; | |
4749 break; | |
4750 } | |
4751 if (i < 0) | |
4752 { | |
4753 EMSG2(_("E394: Didn't find region item for %s"), gname); | |
4754 vim_free(gname); | |
4755 return NULL; | |
4756 } | |
4757 } | |
4758 | |
4759 vim_free(gname); | |
4760 arg = skipwhite(arg); | |
4761 } | |
4762 #ifdef FEAT_FOLDING | |
4763 else if (flagtab[fidx].flags == HL_FOLD | |
4764 && foldmethodIsSyntax(curwin)) | |
4765 /* Need to update folds later. */ | |
4766 foldUpdateAll(curwin); | |
4767 #endif | |
4768 } | |
4769 } | |
7 | 4770 |
4771 return arg; | |
4772 } | |
4773 | |
4774 /* | |
4775 * Adjustments to syntax item when declared in a ":syn include"'d file. | |
4776 * Set the contained flag, and if the item is not already contained, add it | |
4777 * to the specified top-level group, if any. | |
4778 */ | |
4779 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4780 syn_incl_toplevel(int id, int *flagsp) |
7 | 4781 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4782 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) |
7 | 4783 return; |
4784 *flagsp |= HL_CONTAINED; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4785 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
7 | 4786 { |
4787 /* We have to alloc this, because syn_combine_list() will free it. */ | |
4788 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
|
4789 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; |
7 | 4790 |
4791 if (grp_list != NULL) | |
4792 { | |
4793 grp_list[0] = id; | |
4794 grp_list[1] = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4795 syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, &grp_list, |
7 | 4796 CLUSTER_ADD); |
4797 } | |
4798 } | |
4799 } | |
4800 | |
4801 /* | |
4802 * Handle ":syntax include [@{group-name}] filename" command. | |
4803 */ | |
4804 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4805 syn_cmd_include(exarg_T *eap, int syncing UNUSED) |
7 | 4806 { |
4807 char_u *arg = eap->arg; | |
4808 int sgl_id = 1; | |
4809 char_u *group_name_end; | |
4810 char_u *rest; | |
4811 char_u *errormsg = NULL; | |
4812 int prev_toplvl_grp; | |
4813 int prev_syn_inc_tag; | |
4814 int source = FALSE; | |
4815 | |
4816 eap->nextcmd = find_nextcmd(arg); | |
4817 if (eap->skip) | |
4818 return; | |
4819 | |
4820 if (arg[0] == '@') | |
4821 { | |
4822 ++arg; | |
4823 rest = get_group_name(arg, &group_name_end); | |
4824 if (rest == NULL) | |
4825 { | |
4826 EMSG((char_u *)_("E397: Filename required")); | |
4827 return; | |
4828 } | |
4829 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
2743 | 4830 if (sgl_id == 0) |
4831 return; | |
7 | 4832 /* separate_nextcmd() and expand_filename() depend on this */ |
4833 eap->arg = rest; | |
4834 } | |
4835 | |
4836 /* | |
4837 * Everything that's left, up to the next command, should be the | |
4838 * filename to include. | |
4839 */ | |
4840 eap->argt |= (XFILE | NOSPC); | |
4841 separate_nextcmd(eap); | |
4842 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) | |
4843 { | |
4844 /* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the | |
4845 * file. Need to expand the file name first. In other cases | |
4846 * ":runtime!" is used. */ | |
4847 source = TRUE; | |
4848 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) | |
4849 { | |
4850 if (errormsg != NULL) | |
4851 EMSG(errormsg); | |
4852 return; | |
4853 } | |
4854 } | |
4855 | |
4856 /* | |
4857 * Save and restore the existing top-level grouplist id and ":syn | |
4858 * include" tag around the actual inclusion. | |
4859 */ | |
2743 | 4860 if (running_syn_inc_tag >= MAX_SYN_INC_TAG) |
4861 { | |
4862 EMSG((char_u *)_("E847: Too many syntax includes")); | |
4863 return; | |
4864 } | |
7 | 4865 prev_syn_inc_tag = current_syn_inc_tag; |
4866 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
|
4867 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
|
4868 curwin->w_s->b_syn_topgrp = sgl_id; |
1299 | 4869 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
|
4870 : source_runtime(eap->arg, DIP_ALL) == FAIL) |
7 | 4871 EMSG2(_(e_notopen), eap->arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4872 curwin->w_s->b_syn_topgrp = prev_toplvl_grp; |
7 | 4873 current_syn_inc_tag = prev_syn_inc_tag; |
4874 } | |
4875 | |
4876 /* | |
4877 * Handle ":syntax keyword {group-name} [{option}] keyword .." command. | |
4878 */ | |
4879 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4880 syn_cmd_keyword(exarg_T *eap, int syncing UNUSED) |
7 | 4881 { |
4882 char_u *arg = eap->arg; | |
4883 char_u *group_name_end; | |
4884 int syn_id; | |
4885 char_u *rest; | |
2743 | 4886 char_u *keyword_copy = NULL; |
7 | 4887 char_u *p; |
154 | 4888 char_u *kw; |
4889 syn_opt_arg_T syn_opt_arg; | |
4890 int cnt; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4891 int conceal_char = NUL; |
7 | 4892 |
4893 rest = get_group_name(arg, &group_name_end); | |
4894 | |
4895 if (rest != NULL) | |
4896 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4897 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
|
4898 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
|
4899 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4900 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); |
2743 | 4901 if (syn_id != 0) |
4902 /* allocate a buffer, for removing backslashes in the keyword */ | |
4903 keyword_copy = alloc((unsigned)STRLEN(rest) + 1); | |
7 | 4904 if (keyword_copy != NULL) |
4905 { | |
154 | 4906 syn_opt_arg.flags = 0; |
4907 syn_opt_arg.keyword = TRUE; | |
4908 syn_opt_arg.sync_idx = NULL; | |
4909 syn_opt_arg.has_cont_list = FALSE; | |
4910 syn_opt_arg.cont_in_list = NULL; | |
4911 syn_opt_arg.next_list = NULL; | |
4912 | |
7 | 4913 /* |
4914 * The options given apply to ALL keywords, so all options must be | |
4915 * found before keywords can be created. | |
154 | 4916 * 1: collect the options and copy the keywords to keyword_copy. |
7 | 4917 */ |
154 | 4918 cnt = 0; |
4919 p = keyword_copy; | |
4920 for ( ; rest != NULL && !ends_excmd(*rest); rest = skipwhite(rest)) | |
7 | 4921 { |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4922 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
|
4923 eap->skip); |
154 | 4924 if (rest == NULL || ends_excmd(*rest)) |
4925 break; | |
4926 /* Copy the keyword, removing backslashes, and add a NUL. */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4927 while (*rest != NUL && !VIM_ISWHITE(*rest)) |
154 | 4928 { |
4929 if (*rest == '\\' && rest[1] != NUL) | |
4930 ++rest; | |
4931 *p++ = *rest++; | |
4932 } | |
4933 *p++ = NUL; | |
4934 ++cnt; | |
4935 } | |
4936 | |
4937 if (!eap->skip) | |
4938 { | |
4939 /* Adjust flags for use of ":syn include". */ | |
4940 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); | |
4941 | |
7 | 4942 /* |
154 | 4943 * 2: Add an entry for each keyword. |
7 | 4944 */ |
154 | 4945 for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) |
7 | 4946 { |
154 | 4947 for (p = vim_strchr(kw, '['); ; ) |
7 | 4948 { |
154 | 4949 if (p != NULL) |
4950 *p = NUL; | |
4951 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
|
4952 syn_opt_arg.cont_in_list, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4953 syn_opt_arg.next_list, conceal_char); |
168 | 4954 if (p == NULL) |
4955 break; | |
4956 if (p[1] == NUL) | |
4957 { | |
838 | 4958 EMSG2(_("E789: Missing ']': %s"), kw); |
7017 | 4959 goto error; |
168 | 4960 } |
4961 if (p[1] == ']') | |
4962 { | |
7017 | 4963 if (p[2] != NUL) |
4964 { | |
4965 EMSG3(_("E890: trailing char after ']': %s]%s"), | |
4966 kw, &p[2]); | |
4967 goto error; | |
4968 } | |
168 | 4969 kw = p + 1; /* skip over the "]" */ |
4970 break; | |
4971 } | |
154 | 4972 #ifdef FEAT_MBYTE |
4973 if (has_mbyte) | |
7 | 4974 { |
474 | 4975 int l = (*mb_ptr2len)(p + 1); |
154 | 4976 |
4977 mch_memmove(p, p + 1, l); | |
4978 p += l; | |
4979 } | |
4980 else | |
7 | 4981 #endif |
154 | 4982 { |
4983 p[0] = p[1]; | |
4984 ++p; | |
7 | 4985 } |
4986 } | |
4987 } | |
4988 } | |
7017 | 4989 error: |
7 | 4990 vim_free(keyword_copy); |
168 | 4991 vim_free(syn_opt_arg.cont_in_list); |
4992 vim_free(syn_opt_arg.next_list); | |
7 | 4993 } |
4994 } | |
4995 | |
4996 if (rest != NULL) | |
4997 eap->nextcmd = check_nextcmd(rest); | |
4998 else | |
4999 EMSG2(_(e_invarg2), arg); | |
5000 | |
745 | 5001 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5002 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5003 } |
5004 | |
5005 /* | |
5006 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". | |
5007 * | |
5008 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." | |
5009 */ | |
5010 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5011 syn_cmd_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5012 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5013 int syncing) /* TRUE for ":syntax sync match .. " */ |
7 | 5014 { |
5015 char_u *arg = eap->arg; | |
5016 char_u *group_name_end; | |
5017 char_u *rest; | |
5018 synpat_T item; /* the item found in the line */ | |
5019 int syn_id; | |
5020 int idx; | |
154 | 5021 syn_opt_arg_T syn_opt_arg; |
7 | 5022 int sync_idx = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5023 int conceal_char = NUL; |
7 | 5024 |
5025 /* Isolate the group name, check for validity */ | |
5026 rest = get_group_name(arg, &group_name_end); | |
5027 | |
5028 /* Get options before the pattern */ | |
154 | 5029 syn_opt_arg.flags = 0; |
5030 syn_opt_arg.keyword = FALSE; | |
5031 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; | |
5032 syn_opt_arg.has_cont_list = TRUE; | |
5033 syn_opt_arg.cont_list = NULL; | |
5034 syn_opt_arg.cont_in_list = NULL; | |
5035 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
|
5036 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5037 |
5038 /* get the pattern. */ | |
5039 init_syn_patterns(); | |
5040 vim_memset(&item, 0, sizeof(item)); | |
5041 rest = get_syn_pattern(rest, &item); | |
154 | 5042 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
5043 syn_opt_arg.flags |= HL_HAS_EOL; | |
7 | 5044 |
5045 /* 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
|
5046 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5047 |
5048 if (rest != NULL) /* all arguments are valid */ | |
5049 { | |
5050 /* | |
5051 * Check for trailing command and illegal trailing arguments. | |
5052 */ | |
5053 eap->nextcmd = check_nextcmd(rest); | |
5054 if (!ends_excmd(*rest) || eap->skip) | |
5055 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5056 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL |
7 | 5057 && (syn_id = syn_check_group(arg, |
5058 (int)(group_name_end - arg))) != 0) | |
5059 { | |
154 | 5060 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5061 /* |
5062 * Store the pattern in the syn_items list | |
5063 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5064 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
|
5065 SYN_ITEMS(curwin->w_s)[idx] = item; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5066 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
|
5067 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
|
5068 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
|
5069 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
|
5070 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
|
5071 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
|
5072 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
|
5073 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5074 syn_opt_arg.cont_in_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5075 #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
|
5076 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
|
5077 #endif |
154 | 5078 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
|
5079 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5080 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
|
5081 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5082 |
5083 /* remember that we found a match for syncing on */ | |
154 | 5084 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
|
5085 curwin->w_s->b_syn_sync_flags |= SF_MATCH; |
7 | 5086 #ifdef FEAT_FOLDING |
154 | 5087 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
|
5088 ++curwin->w_s->b_syn_folditems; |
7 | 5089 #endif |
5090 | |
745 | 5091 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5092 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5093 return; /* don't free the progs and patterns now */ |
5094 } | |
5095 } | |
5096 | |
5097 /* | |
5098 * Something failed, free the allocated memory. | |
5099 */ | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5100 vim_regfree(item.sp_prog); |
7 | 5101 vim_free(item.sp_pattern); |
154 | 5102 vim_free(syn_opt_arg.cont_list); |
5103 vim_free(syn_opt_arg.cont_in_list); | |
5104 vim_free(syn_opt_arg.next_list); | |
7 | 5105 |
5106 if (rest == NULL) | |
5107 EMSG2(_(e_invarg2), arg); | |
5108 } | |
5109 | |
5110 /* | |
5111 * Handle ":syntax region {group-name} [matchgroup={group-name}] | |
5112 * start {start} .. [skip {skip}] end {end} .. [{options}]". | |
5113 */ | |
5114 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5115 syn_cmd_region( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5116 exarg_T *eap, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5117 int syncing) /* TRUE for ":syntax sync region .." */ |
7 | 5118 { |
5119 char_u *arg = eap->arg; | |
5120 char_u *group_name_end; | |
5121 char_u *rest; /* next arg, NULL on error */ | |
5122 char_u *key_end; | |
5123 char_u *key = NULL; | |
5124 char_u *p; | |
5125 int item; | |
5126 #define ITEM_START 0 | |
5127 #define ITEM_SKIP 1 | |
5128 #define ITEM_END 2 | |
5129 #define ITEM_MATCHGROUP 3 | |
5130 struct pat_ptr | |
5131 { | |
5132 synpat_T *pp_synp; /* pointer to syn_pattern */ | |
5133 int pp_matchgroup_id; /* matchgroup ID */ | |
5134 struct pat_ptr *pp_next; /* pointer to next pat_ptr */ | |
5135 } *(pat_ptrs[3]); | |
5136 /* patterns found in the line */ | |
5137 struct pat_ptr *ppp; | |
5138 struct pat_ptr *ppp_next; | |
5139 int pat_count = 0; /* nr of syn_patterns found */ | |
5140 int syn_id; | |
5141 int matchgroup_id = 0; | |
5142 int not_enough = FALSE; /* not enough arguments */ | |
5143 int illegal = FALSE; /* illegal arguments */ | |
5144 int success = FALSE; | |
5145 int idx; | |
154 | 5146 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
|
5147 int conceal_char = NUL; |
7 | 5148 |
5149 /* Isolate the group name, check for validity */ | |
5150 rest = get_group_name(arg, &group_name_end); | |
5151 | |
5152 pat_ptrs[0] = NULL; | |
5153 pat_ptrs[1] = NULL; | |
5154 pat_ptrs[2] = NULL; | |
5155 | |
5156 init_syn_patterns(); | |
5157 | |
154 | 5158 syn_opt_arg.flags = 0; |
5159 syn_opt_arg.keyword = FALSE; | |
5160 syn_opt_arg.sync_idx = NULL; | |
5161 syn_opt_arg.has_cont_list = TRUE; | |
5162 syn_opt_arg.cont_list = NULL; | |
5163 syn_opt_arg.cont_in_list = NULL; | |
5164 syn_opt_arg.next_list = NULL; | |
5165 | |
7 | 5166 /* |
5167 * get the options, patterns and matchgroup. | |
5168 */ | |
5169 while (rest != NULL && !ends_excmd(*rest)) | |
5170 { | |
5171 /* 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
|
5172 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 5173 if (rest == NULL || ends_excmd(*rest)) |
5174 break; | |
5175 | |
5176 /* must be a pattern or matchgroup then */ | |
5177 key_end = rest; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5178 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') |
7 | 5179 ++key_end; |
5180 vim_free(key); | |
5181 key = vim_strnsave_up(rest, (int)(key_end - rest)); | |
5182 if (key == NULL) /* out of memory */ | |
5183 { | |
5184 rest = NULL; | |
5185 break; | |
5186 } | |
5187 if (STRCMP(key, "MATCHGROUP") == 0) | |
5188 item = ITEM_MATCHGROUP; | |
5189 else if (STRCMP(key, "START") == 0) | |
5190 item = ITEM_START; | |
5191 else if (STRCMP(key, "END") == 0) | |
5192 item = ITEM_END; | |
5193 else if (STRCMP(key, "SKIP") == 0) | |
5194 { | |
5195 if (pat_ptrs[ITEM_SKIP] != NULL) /* one skip pattern allowed */ | |
5196 { | |
5197 illegal = TRUE; | |
5198 break; | |
5199 } | |
5200 item = ITEM_SKIP; | |
5201 } | |
5202 else | |
5203 break; | |
5204 rest = skipwhite(key_end); | |
5205 if (*rest != '=') | |
5206 { | |
5207 rest = NULL; | |
5208 EMSG2(_("E398: Missing '=': %s"), arg); | |
5209 break; | |
5210 } | |
5211 rest = skipwhite(rest + 1); | |
5212 if (*rest == NUL) | |
5213 { | |
5214 not_enough = TRUE; | |
5215 break; | |
5216 } | |
5217 | |
5218 if (item == ITEM_MATCHGROUP) | |
5219 { | |
5220 p = skiptowhite(rest); | |
5221 if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) | |
5222 matchgroup_id = 0; | |
5223 else | |
5224 { | |
5225 matchgroup_id = syn_check_group(rest, (int)(p - rest)); | |
5226 if (matchgroup_id == 0) | |
5227 { | |
5228 illegal = TRUE; | |
5229 break; | |
5230 } | |
5231 } | |
5232 rest = skipwhite(p); | |
5233 } | |
5234 else | |
5235 { | |
5236 /* | |
5237 * Allocate room for a syn_pattern, and link it in the list of | |
5238 * syn_patterns for this item, at the start (because the list is | |
5239 * used from end to start). | |
5240 */ | |
5241 ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr)); | |
5242 if (ppp == NULL) | |
5243 { | |
5244 rest = NULL; | |
5245 break; | |
5246 } | |
5247 ppp->pp_next = pat_ptrs[item]; | |
5248 pat_ptrs[item] = ppp; | |
5249 ppp->pp_synp = (synpat_T *)alloc_clear((unsigned)sizeof(synpat_T)); | |
5250 if (ppp->pp_synp == NULL) | |
5251 { | |
5252 rest = NULL; | |
5253 break; | |
5254 } | |
5255 | |
5256 /* | |
5257 * Get the syntax pattern and the following offset(s). | |
5258 */ | |
5259 /* Enable the appropriate \z specials. */ | |
5260 if (item == ITEM_START) | |
5261 reg_do_extmatch = REX_SET; | |
5262 else if (item == ITEM_SKIP || item == ITEM_END) | |
5263 reg_do_extmatch = REX_USE; | |
5264 rest = get_syn_pattern(rest, ppp->pp_synp); | |
5265 reg_do_extmatch = 0; | |
5266 if (item == ITEM_END && vim_regcomp_had_eol() | |
154 | 5267 && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
7 | 5268 ppp->pp_synp->sp_flags |= HL_HAS_EOL; |
5269 ppp->pp_matchgroup_id = matchgroup_id; | |
5270 ++pat_count; | |
5271 } | |
5272 } | |
5273 vim_free(key); | |
5274 if (illegal || not_enough) | |
5275 rest = NULL; | |
5276 | |
5277 /* | |
5278 * Must have a "start" and "end" pattern. | |
5279 */ | |
5280 if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || | |
5281 pat_ptrs[ITEM_END] == NULL)) | |
5282 { | |
5283 not_enough = TRUE; | |
5284 rest = NULL; | |
5285 } | |
5286 | |
5287 if (rest != NULL) | |
5288 { | |
5289 /* | |
5290 * Check for trailing garbage or command. | |
5291 * If OK, add the item. | |
5292 */ | |
5293 eap->nextcmd = check_nextcmd(rest); | |
5294 if (!ends_excmd(*rest) || eap->skip) | |
5295 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5296 else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL |
7 | 5297 && (syn_id = syn_check_group(arg, |
5298 (int)(group_name_end - arg))) != 0) | |
5299 { | |
154 | 5300 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5301 /* |
5302 * Store the start/skip/end in the syn_items list | |
5303 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5304 idx = curwin->w_s->b_syn_patterns.ga_len; |
7 | 5305 for (item = ITEM_START; item <= ITEM_END; ++item) |
5306 { | |
5307 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) | |
5308 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5309 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
|
5310 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
|
5311 SYN_ITEMS(curwin->w_s)[idx].sp_type = |
7 | 5312 (item == ITEM_START) ? SPTYPE_START : |
5313 (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
|
5314 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
|
5315 SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; |
2743 | 5316 SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = |
5317 current_syn_inc_tag; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5318 SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = |
7 | 5319 ppp->pp_matchgroup_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5320 #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
|
5321 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
|
5322 #endif |
7 | 5323 if (item == ITEM_START) |
5324 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5325 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = |
154 | 5326 syn_opt_arg.cont_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5327 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5328 syn_opt_arg.cont_in_list; |
5329 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
|
5330 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5331 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = |
154 | 5332 syn_opt_arg.next_list; |
7 | 5333 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5334 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5335 ++idx; |
5336 #ifdef FEAT_FOLDING | |
154 | 5337 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
|
5338 ++curwin->w_s->b_syn_folditems; |
7 | 5339 #endif |
5340 } | |
5341 } | |
5342 | |
745 | 5343 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5344 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5345 success = TRUE; /* don't free the progs and patterns now */ |
5346 } | |
5347 } | |
5348 | |
5349 /* | |
5350 * Free the allocated memory. | |
5351 */ | |
5352 for (item = ITEM_START; item <= ITEM_END; ++item) | |
5353 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) | |
5354 { | |
5355 if (!success) | |
5356 { | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5357 vim_regfree(ppp->pp_synp->sp_prog); |
7 | 5358 vim_free(ppp->pp_synp->sp_pattern); |
5359 } | |
5360 vim_free(ppp->pp_synp); | |
5361 ppp_next = ppp->pp_next; | |
5362 vim_free(ppp); | |
5363 } | |
5364 | |
5365 if (!success) | |
5366 { | |
154 | 5367 vim_free(syn_opt_arg.cont_list); |
5368 vim_free(syn_opt_arg.cont_in_list); | |
5369 vim_free(syn_opt_arg.next_list); | |
7 | 5370 if (not_enough) |
5371 EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); | |
5372 else if (illegal || rest == NULL) | |
5373 EMSG2(_(e_invarg2), arg); | |
5374 } | |
5375 } | |
5376 | |
5377 /* | |
5378 * A simple syntax group ID comparison function suitable for use in qsort() | |
5379 */ | |
5380 static int | |
5381 #ifdef __BORLANDC__ | |
5382 _RTLENTRYF | |
5383 #endif | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5384 syn_compare_stub(const void *v1, const void *v2) |
7 | 5385 { |
5386 const short *s1 = v1; | |
5387 const short *s2 = v2; | |
5388 | |
5389 return (*s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0); | |
5390 } | |
5391 | |
5392 /* | |
5393 * Combines lists of syntax clusters. | |
5394 * *clstr1 and *clstr2 must both be allocated memory; they will be consumed. | |
5395 */ | |
5396 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5397 syn_combine_list(short **clstr1, short **clstr2, int list_op) |
7 | 5398 { |
5399 int count1 = 0; | |
5400 int count2 = 0; | |
5401 short *g1; | |
5402 short *g2; | |
5403 short *clstr = NULL; | |
5404 int count; | |
5405 int round; | |
5406 | |
5407 /* | |
5408 * Handle degenerate cases. | |
5409 */ | |
5410 if (*clstr2 == NULL) | |
5411 return; | |
5412 if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) | |
5413 { | |
5414 if (list_op == CLUSTER_REPLACE) | |
5415 vim_free(*clstr1); | |
5416 if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) | |
5417 *clstr1 = *clstr2; | |
5418 else | |
5419 vim_free(*clstr2); | |
5420 return; | |
5421 } | |
5422 | |
5423 for (g1 = *clstr1; *g1; g1++) | |
5424 ++count1; | |
5425 for (g2 = *clstr2; *g2; g2++) | |
5426 ++count2; | |
5427 | |
5428 /* | |
5429 * For speed purposes, sort both lists. | |
5430 */ | |
5431 qsort(*clstr1, (size_t)count1, sizeof(short), syn_compare_stub); | |
5432 qsort(*clstr2, (size_t)count2, sizeof(short), syn_compare_stub); | |
5433 | |
5434 /* | |
5435 * We proceed in two passes; in round 1, we count the elements to place | |
5436 * in the new list, and in round 2, we allocate and populate the new | |
5437 * list. For speed, we use a mergesort-like method, adding the smaller | |
5438 * of the current elements in each list to the new list. | |
5439 */ | |
5440 for (round = 1; round <= 2; round++) | |
5441 { | |
5442 g1 = *clstr1; | |
5443 g2 = *clstr2; | |
5444 count = 0; | |
5445 | |
5446 /* | |
5447 * First, loop through the lists until one of them is empty. | |
5448 */ | |
5449 while (*g1 && *g2) | |
5450 { | |
5451 /* | |
5452 * We always want to add from the first list. | |
5453 */ | |
5454 if (*g1 < *g2) | |
5455 { | |
5456 if (round == 2) | |
5457 clstr[count] = *g1; | |
5458 count++; | |
5459 g1++; | |
5460 continue; | |
5461 } | |
5462 /* | |
5463 * We only want to add from the second list if we're adding the | |
5464 * lists. | |
5465 */ | |
5466 if (list_op == CLUSTER_ADD) | |
5467 { | |
5468 if (round == 2) | |
5469 clstr[count] = *g2; | |
5470 count++; | |
5471 } | |
5472 if (*g1 == *g2) | |
5473 g1++; | |
5474 g2++; | |
5475 } | |
5476 | |
5477 /* | |
5478 * Now add the leftovers from whichever list didn't get finished | |
5479 * first. As before, we only want to add from the second list if | |
5480 * we're adding the lists. | |
5481 */ | |
5482 for (; *g1; g1++, count++) | |
5483 if (round == 2) | |
5484 clstr[count] = *g1; | |
5485 if (list_op == CLUSTER_ADD) | |
5486 for (; *g2; g2++, count++) | |
5487 if (round == 2) | |
5488 clstr[count] = *g2; | |
5489 | |
5490 if (round == 1) | |
5491 { | |
5492 /* | |
5493 * If the group ended up empty, we don't need to allocate any | |
5494 * space for it. | |
5495 */ | |
5496 if (count == 0) | |
5497 { | |
5498 clstr = NULL; | |
5499 break; | |
5500 } | |
5501 clstr = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
5502 if (clstr == NULL) | |
5503 break; | |
5504 clstr[count] = 0; | |
5505 } | |
5506 } | |
5507 | |
5508 /* | |
5509 * Finally, put the new list in place. | |
5510 */ | |
5511 vim_free(*clstr1); | |
5512 vim_free(*clstr2); | |
5513 *clstr1 = clstr; | |
5514 } | |
5515 | |
5516 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5517 * Lookup a syntax cluster name and return its ID. |
7 | 5518 * If it is not found, 0 is returned. |
5519 */ | |
5520 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5521 syn_scl_name2id(char_u *name) |
7 | 5522 { |
5523 int i; | |
5524 char_u *name_u; | |
5525 | |
5526 /* Avoid using stricmp() too much, it's slow on some systems */ | |
5527 name_u = vim_strsave_up(name); | |
5528 if (name_u == NULL) | |
5529 return 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5530 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
|
5531 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
|
5532 && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) |
7 | 5533 break; |
5534 vim_free(name_u); | |
5535 return (i < 0 ? 0 : i + SYNID_CLUSTER); | |
5536 } | |
5537 | |
5538 /* | |
5539 * Like syn_scl_name2id(), but take a pointer + length argument. | |
5540 */ | |
5541 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5542 syn_scl_namen2id(char_u *linep, int len) |
7 | 5543 { |
5544 char_u *name; | |
5545 int id = 0; | |
5546 | |
5547 name = vim_strnsave(linep, len); | |
5548 if (name != NULL) | |
5549 { | |
5550 id = syn_scl_name2id(name); | |
5551 vim_free(name); | |
5552 } | |
5553 return id; | |
5554 } | |
5555 | |
5556 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5557 * Find syntax cluster name in the table and return its ID. |
7 | 5558 * The argument is a pointer to the name and the length of the name. |
5559 * If it doesn't exist yet, a new entry is created. | |
5560 * Return 0 for failure. | |
5561 */ | |
5562 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5563 syn_check_cluster(char_u *pp, int len) |
7 | 5564 { |
5565 int id; | |
5566 char_u *name; | |
5567 | |
5568 name = vim_strnsave(pp, len); | |
5569 if (name == NULL) | |
5570 return 0; | |
5571 | |
5572 id = syn_scl_name2id(name); | |
5573 if (id == 0) /* doesn't exist yet */ | |
5574 id = syn_add_cluster(name); | |
5575 else | |
5576 vim_free(name); | |
5577 return id; | |
5578 } | |
5579 | |
5580 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5581 * Add new syntax cluster and return its ID. |
7 | 5582 * "name" must be an allocated string, it will be consumed. |
5583 * Return 0 for failure. | |
5584 */ | |
5585 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5586 syn_add_cluster(char_u *name) |
221 | 5587 { |
5588 int len; | |
7 | 5589 |
5590 /* | |
5591 * First call for this growarray: init growing array. | |
5592 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5593 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
|
5594 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5595 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
|
5596 curwin->w_s->b_syn_clusters.ga_growsize = 10; |
7 | 5597 } |
5598 | |
2743 | 5599 len = curwin->w_s->b_syn_clusters.ga_len; |
5600 if (len >= MAX_CLUSTER_ID) | |
5601 { | |
5602 EMSG((char_u *)_("E848: Too many syntax clusters")); | |
5603 vim_free(name); | |
5604 return 0; | |
5605 } | |
5606 | |
7 | 5607 /* |
5608 * Make room for at least one other cluster entry. | |
5609 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5610 if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) |
7 | 5611 { |
5612 vim_free(name); | |
5613 return 0; | |
5614 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5615 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5616 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
|
5617 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
|
5618 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
|
5619 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
|
5620 ++curwin->w_s->b_syn_clusters.ga_len; |
7 | 5621 |
221 | 5622 if (STRICMP(name, "Spell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5623 curwin->w_s->b_spell_cluster_id = len + SYNID_CLUSTER; |
227 | 5624 if (STRICMP(name, "NoSpell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5625 curwin->w_s->b_nospell_cluster_id = len + SYNID_CLUSTER; |
221 | 5626 |
7 | 5627 return len + SYNID_CLUSTER; |
5628 } | |
5629 | |
5630 /* | |
5631 * Handle ":syntax cluster {cluster-name} [contains={groupname},..] | |
5632 * [add={groupname},..] [remove={groupname},..]". | |
5633 */ | |
5634 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5635 syn_cmd_cluster(exarg_T *eap, int syncing UNUSED) |
7 | 5636 { |
5637 char_u *arg = eap->arg; | |
5638 char_u *group_name_end; | |
5639 char_u *rest; | |
5640 int scl_id; | |
5641 short *clstr_list; | |
5642 int got_clstr = FALSE; | |
5643 int opt_len; | |
5644 int list_op; | |
5645 | |
5646 eap->nextcmd = find_nextcmd(arg); | |
5647 if (eap->skip) | |
5648 return; | |
5649 | |
5650 rest = get_group_name(arg, &group_name_end); | |
5651 | |
5652 if (rest != NULL) | |
5653 { | |
2743 | 5654 scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); |
5655 if (scl_id == 0) | |
5656 return; | |
5657 scl_id -= SYNID_CLUSTER; | |
7 | 5658 |
5659 for (;;) | |
5660 { | |
5661 if (STRNICMP(rest, "add", 3) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5662 && (VIM_ISWHITE(rest[3]) || rest[3] == '=')) |
7 | 5663 { |
5664 opt_len = 3; | |
5665 list_op = CLUSTER_ADD; | |
5666 } | |
5667 else if (STRNICMP(rest, "remove", 6) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5668 && (VIM_ISWHITE(rest[6]) || rest[6] == '=')) |
7 | 5669 { |
5670 opt_len = 6; | |
5671 list_op = CLUSTER_SUBTRACT; | |
5672 } | |
5673 else if (STRNICMP(rest, "contains", 8) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5674 && (VIM_ISWHITE(rest[8]) || rest[8] == '=')) |
7 | 5675 { |
5676 opt_len = 8; | |
5677 list_op = CLUSTER_REPLACE; | |
5678 } | |
5679 else | |
5680 break; | |
5681 | |
5682 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
|
5683 if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) |
7 | 5684 { |
5685 EMSG2(_(e_invarg2), rest); | |
5686 break; | |
5687 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5688 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
|
5689 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, |
7 | 5690 &clstr_list, list_op); |
10648
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5691 else |
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5692 vim_free(clstr_list); |
7 | 5693 got_clstr = TRUE; |
5694 } | |
5695 | |
5696 if (got_clstr) | |
5697 { | |
745 | 5698 redraw_curbuf_later(SOME_VALID); |
2743 | 5699 syn_stack_free_all(curwin->w_s); /* Need to recompute all. */ |
7 | 5700 } |
5701 } | |
5702 | |
5703 if (!got_clstr) | |
5704 EMSG(_("E400: No cluster specified")); | |
5705 if (rest == NULL || !ends_excmd(*rest)) | |
5706 EMSG2(_(e_invarg2), arg); | |
5707 } | |
5708 | |
5709 /* | |
5710 * On first call for current buffer: Init growing array. | |
5711 */ | |
5712 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5713 init_syn_patterns(void) |
7 | 5714 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5715 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
|
5716 curwin->w_s->b_syn_patterns.ga_growsize = 10; |
7 | 5717 } |
5718 | |
5719 /* | |
5720 * Get one pattern for a ":syntax match" or ":syntax region" command. | |
5721 * Stores the pattern and program in a synpat_T. | |
5722 * Returns a pointer to the next argument, or NULL in case of an error. | |
5723 */ | |
5724 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5725 get_syn_pattern(char_u *arg, synpat_T *ci) |
7 | 5726 { |
5727 char_u *end; | |
5728 int *p; | |
5729 int idx; | |
5730 char_u *cpo_save; | |
5731 | |
5732 /* need at least three chars */ | |
6993 | 5733 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) |
7 | 5734 return NULL; |
5735 | |
5736 end = skip_regexp(arg + 1, *arg, TRUE, NULL); | |
5737 if (*end != *arg) /* end delimiter not found */ | |
5738 { | |
5739 EMSG2(_("E401: Pattern delimiter not found: %s"), arg); | |
5740 return NULL; | |
5741 } | |
5742 /* store the pattern and compiled regexp program */ | |
5743 if ((ci->sp_pattern = vim_strnsave(arg + 1, (int)(end - arg - 1))) == NULL) | |
5744 return NULL; | |
5745 | |
5746 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5747 cpo_save = p_cpo; | |
5748 p_cpo = (char_u *)""; | |
5749 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); | |
5750 p_cpo = cpo_save; | |
5751 | |
5752 if (ci->sp_prog == NULL) | |
5753 return NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5754 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
|
5755 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5756 syn_clear_time(&ci->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5757 #endif |
7 | 5758 |
5759 /* | |
5760 * Check for a match, highlight or region offset. | |
5761 */ | |
5762 ++end; | |
5763 do | |
5764 { | |
5765 for (idx = SPO_COUNT; --idx >= 0; ) | |
5766 if (STRNCMP(end, spo_name_tab[idx], 3) == 0) | |
5767 break; | |
5768 if (idx >= 0) | |
5769 { | |
5770 p = &(ci->sp_offsets[idx]); | |
5771 if (idx != SPO_LC_OFF) | |
5772 switch (end[3]) | |
5773 { | |
5774 case 's': break; | |
5775 case 'b': break; | |
5776 case 'e': idx += SPO_COUNT; break; | |
5777 default: idx = -1; break; | |
5778 } | |
5779 if (idx >= 0) | |
5780 { | |
5781 ci->sp_off_flags |= (1 << idx); | |
5782 if (idx == SPO_LC_OFF) /* lc=99 */ | |
5783 { | |
5784 end += 3; | |
5785 *p = getdigits(&end); | |
5786 | |
5787 /* "lc=" offset automatically sets "ms=" offset */ | |
5788 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) | |
5789 { | |
5790 ci->sp_off_flags |= (1 << SPO_MS_OFF); | |
5791 ci->sp_offsets[SPO_MS_OFF] = *p; | |
5792 } | |
5793 } | |
5794 else /* yy=x+99 */ | |
5795 { | |
5796 end += 4; | |
5797 if (*end == '+') | |
5798 { | |
5799 ++end; | |
5800 *p = getdigits(&end); /* positive offset */ | |
5801 } | |
5802 else if (*end == '-') | |
5803 { | |
5804 ++end; | |
5805 *p = -getdigits(&end); /* negative offset */ | |
5806 } | |
5807 } | |
5808 if (*end != ',') | |
5809 break; | |
5810 ++end; | |
5811 } | |
5812 } | |
5813 } while (idx >= 0); | |
5814 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5815 if (!ends_excmd(*end) && !VIM_ISWHITE(*end)) |
7 | 5816 { |
5817 EMSG2(_("E402: Garbage after pattern: %s"), arg); | |
5818 return NULL; | |
5819 } | |
5820 return skipwhite(end); | |
5821 } | |
5822 | |
5823 /* | |
5824 * Handle ":syntax sync .." command. | |
5825 */ | |
5826 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5827 syn_cmd_sync(exarg_T *eap, int syncing UNUSED) |
7 | 5828 { |
5829 char_u *arg_start = eap->arg; | |
5830 char_u *arg_end; | |
5831 char_u *key = NULL; | |
5832 char_u *next_arg; | |
5833 int illegal = FALSE; | |
5834 int finished = FALSE; | |
5835 long n; | |
5836 char_u *cpo_save; | |
5837 | |
5838 if (ends_excmd(*arg_start)) | |
5839 { | |
5840 syn_cmd_list(eap, TRUE); | |
5841 return; | |
5842 } | |
5843 | |
5844 while (!ends_excmd(*arg_start)) | |
5845 { | |
5846 arg_end = skiptowhite(arg_start); | |
5847 next_arg = skipwhite(arg_end); | |
5848 vim_free(key); | |
5849 key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); | |
5850 if (STRCMP(key, "CCOMMENT") == 0) | |
5851 { | |
5852 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5853 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; |
7 | 5854 if (!ends_excmd(*next_arg)) |
5855 { | |
5856 arg_end = skiptowhite(next_arg); | |
5857 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5858 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, |
7 | 5859 (int)(arg_end - next_arg)); |
5860 next_arg = skipwhite(arg_end); | |
5861 } | |
5862 else if (!eap->skip) | |
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_id = syn_name2id((char_u *)"Comment"); |
7 | 5864 } |
5865 else if ( STRNCMP(key, "LINES", 5) == 0 | |
5866 || STRNCMP(key, "MINLINES", 8) == 0 | |
5867 || STRNCMP(key, "MAXLINES", 8) == 0 | |
5868 || STRNCMP(key, "LINEBREAKS", 10) == 0) | |
5869 { | |
5870 if (key[4] == 'S') | |
5871 arg_end = key + 6; | |
5872 else if (key[0] == 'L') | |
5873 arg_end = key + 11; | |
5874 else | |
5875 arg_end = key + 9; | |
5876 if (arg_end[-1] != '=' || !VIM_ISDIGIT(*arg_end)) | |
5877 { | |
5878 illegal = TRUE; | |
5879 break; | |
5880 } | |
5881 n = getdigits(&arg_end); | |
5882 if (!eap->skip) | |
5883 { | |
5884 if (key[4] == 'B') | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5885 curwin->w_s->b_syn_sync_linebreaks = n; |
7 | 5886 else if (key[1] == 'A') |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5887 curwin->w_s->b_syn_sync_maxlines = n; |
7 | 5888 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5889 curwin->w_s->b_syn_sync_minlines = n; |
7 | 5890 } |
5891 } | |
5892 else if (STRCMP(key, "FROMSTART") == 0) | |
5893 { | |
5894 if (!eap->skip) | |
5895 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5896 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
|
5897 curwin->w_s->b_syn_sync_maxlines = 0; |
7 | 5898 } |
5899 } | |
5900 else if (STRCMP(key, "LINECONT") == 0) | |
5901 { | |
7504
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5902 if (*next_arg == NUL) /* missing pattern */ |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5903 { |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5904 illegal = TRUE; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5905 break; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5906 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5907 if (curwin->w_s->b_syn_linecont_pat != NULL) |
7 | 5908 { |
5909 EMSG(_("E403: syntax sync: line continuations pattern specified twice")); | |
5910 finished = TRUE; | |
5911 break; | |
5912 } | |
5913 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE, NULL); | |
5914 if (*arg_end != *next_arg) /* end delimiter not found */ | |
5915 { | |
5916 illegal = TRUE; | |
5917 break; | |
5918 } | |
5919 | |
5920 if (!eap->skip) | |
5921 { | |
5922 /* 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
|
5923 if ((curwin->w_s->b_syn_linecont_pat = vim_strnsave(next_arg + 1, |
7 | 5924 (int)(arg_end - next_arg - 1))) == NULL) |
5925 { | |
5926 finished = TRUE; | |
5927 break; | |
5928 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5929 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; |
7 | 5930 |
5931 /* Make 'cpoptions' empty, to avoid the 'l' flag */ | |
5932 cpo_save = p_cpo; | |
5933 p_cpo = (char_u *)""; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5934 curwin->w_s->b_syn_linecont_prog = |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5935 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); |
7 | 5936 p_cpo = cpo_save; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5937 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5938 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
|
5939 #endif |
7 | 5940 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5941 if (curwin->w_s->b_syn_linecont_prog == NULL) |
7 | 5942 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5943 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
|
5944 curwin->w_s->b_syn_linecont_pat = NULL; |
7 | 5945 finished = TRUE; |
5946 break; | |
5947 } | |
5948 } | |
5949 next_arg = skipwhite(arg_end + 1); | |
5950 } | |
5951 else | |
5952 { | |
5953 eap->arg = next_arg; | |
5954 if (STRCMP(key, "MATCH") == 0) | |
5955 syn_cmd_match(eap, TRUE); | |
5956 else if (STRCMP(key, "REGION") == 0) | |
5957 syn_cmd_region(eap, TRUE); | |
5958 else if (STRCMP(key, "CLEAR") == 0) | |
5959 syn_cmd_clear(eap, TRUE); | |
5960 else | |
5961 illegal = TRUE; | |
5962 finished = TRUE; | |
5963 break; | |
5964 } | |
5965 arg_start = next_arg; | |
5966 } | |
5967 vim_free(key); | |
5968 if (illegal) | |
5969 EMSG2(_("E404: Illegal arguments: %s"), arg_start); | |
5970 else if (!finished) | |
5971 { | |
5972 eap->nextcmd = check_nextcmd(arg_start); | |
745 | 5973 redraw_curbuf_later(SOME_VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5974 syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ |
7 | 5975 } |
5976 } | |
5977 | |
5978 /* | |
5979 * Convert a line of highlight group names into a list of group ID numbers. | |
5980 * "arg" should point to the "contains" or "nextgroup" keyword. | |
5981 * "arg" is advanced to after the last group name. | |
5982 * Careful: the argument is modified (NULs added). | |
5983 * returns FAIL for some error, OK for success. | |
5984 */ | |
5985 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5986 get_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5987 char_u **arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5988 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
|
5989 short **list, /* where to store the resulting list, if not |
7 | 5990 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
|
5991 int skip) |
7 | 5992 { |
5993 char_u *p = NULL; | |
5994 char_u *end; | |
5995 int round; | |
5996 int count; | |
5997 int total_count = 0; | |
5998 short *retval = NULL; | |
5999 char_u *name; | |
6000 regmatch_T regmatch; | |
6001 int id; | |
6002 int i; | |
6003 int failed = FALSE; | |
6004 | |
6005 /* | |
6006 * We parse the list twice: | |
6007 * round == 1: count the number of items, allocate the array. | |
6008 * round == 2: fill the array with the items. | |
6009 * In round 1 new groups may be added, causing the number of items to | |
6010 * grow when a regexp is used. In that case round 1 is done once again. | |
6011 */ | |
6012 for (round = 1; round <= 2; ++round) | |
6013 { | |
6014 /* | |
6015 * skip "contains" | |
6016 */ | |
6017 p = skipwhite(*arg + keylen); | |
6018 if (*p != '=') | |
6019 { | |
6020 EMSG2(_("E405: Missing equal sign: %s"), *arg); | |
6021 break; | |
6022 } | |
6023 p = skipwhite(p + 1); | |
6024 if (ends_excmd(*p)) | |
6025 { | |
6026 EMSG2(_("E406: Empty argument: %s"), *arg); | |
6027 break; | |
6028 } | |
6029 | |
6030 /* | |
6031 * parse the arguments after "contains" | |
6032 */ | |
6033 count = 0; | |
6034 while (!ends_excmd(*p)) | |
6035 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6036 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) |
7 | 6037 ; |
6038 name = alloc((int)(end - p + 3)); /* leave room for "^$" */ | |
6039 if (name == NULL) | |
6040 { | |
6041 failed = TRUE; | |
6042 break; | |
6043 } | |
419 | 6044 vim_strncpy(name + 1, p, end - p); |
7 | 6045 if ( STRCMP(name + 1, "ALLBUT") == 0 |
6046 || STRCMP(name + 1, "ALL") == 0 | |
6047 || STRCMP(name + 1, "TOP") == 0 | |
6048 || STRCMP(name + 1, "CONTAINED") == 0) | |
6049 { | |
6050 if (TOUPPER_ASC(**arg) != 'C') | |
6051 { | |
6052 EMSG2(_("E407: %s not allowed here"), name + 1); | |
6053 failed = TRUE; | |
6054 vim_free(name); | |
6055 break; | |
6056 } | |
6057 if (count != 0) | |
6058 { | |
10648
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
6059 EMSG2(_("E408: %s must be first in contains list"), |
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
6060 name + 1); |
7 | 6061 failed = TRUE; |
6062 vim_free(name); | |
6063 break; | |
6064 } | |
6065 if (name[1] == 'A') | |
6066 id = SYNID_ALLBUT; | |
6067 else if (name[1] == 'T') | |
6068 id = SYNID_TOP; | |
6069 else | |
6070 id = SYNID_CONTAINED; | |
6071 id += current_syn_inc_tag; | |
6072 } | |
6073 else if (name[1] == '@') | |
6074 { | |
10629
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6075 if (skip) |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6076 id = -1; |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6077 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
|
6078 id = syn_check_cluster(name + 2, (int)(end - p - 1)); |
7 | 6079 } |
6080 else | |
6081 { | |
6082 /* | |
6083 * Handle full group name. | |
6084 */ | |
6085 if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) | |
6086 id = syn_check_group(name + 1, (int)(end - p)); | |
6087 else | |
6088 { | |
6089 /* | |
6090 * Handle match of regexp with group names. | |
6091 */ | |
6092 *name = '^'; | |
6093 STRCAT(name, "$"); | |
6094 regmatch.regprog = vim_regcomp(name, RE_MAGIC); | |
6095 if (regmatch.regprog == NULL) | |
6096 { | |
6097 failed = TRUE; | |
6098 vim_free(name); | |
6099 break; | |
6100 } | |
6101 | |
6102 regmatch.rm_ic = TRUE; | |
6103 id = 0; | |
6104 for (i = highlight_ga.ga_len; --i >= 0; ) | |
6105 { | |
6106 if (vim_regexec(®match, HL_TABLE()[i].sg_name, | |
6107 (colnr_T)0)) | |
6108 { | |
6109 if (round == 2) | |
6110 { | |
6111 /* Got more items than expected; can happen | |
6112 * when adding items that match: | |
6113 * "contains=a.*b,axb". | |
6114 * Go back to first round */ | |
6115 if (count >= total_count) | |
6116 { | |
6117 vim_free(retval); | |
6118 round = 1; | |
6119 } | |
6120 else | |
6121 retval[count] = i + 1; | |
6122 } | |
6123 ++count; | |
6124 id = -1; /* remember that we found one */ | |
6125 } | |
6126 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6127 vim_regfree(regmatch.regprog); |
7 | 6128 } |
6129 } | |
6130 vim_free(name); | |
6131 if (id == 0) | |
6132 { | |
6133 EMSG2(_("E409: Unknown group name: %s"), p); | |
6134 failed = TRUE; | |
6135 break; | |
6136 } | |
6137 if (id > 0) | |
6138 { | |
6139 if (round == 2) | |
6140 { | |
6141 /* Got more items than expected, go back to first round */ | |
6142 if (count >= total_count) | |
6143 { | |
6144 vim_free(retval); | |
6145 round = 1; | |
6146 } | |
6147 else | |
6148 retval[count] = id; | |
6149 } | |
6150 ++count; | |
6151 } | |
6152 p = skipwhite(end); | |
6153 if (*p != ',') | |
6154 break; | |
6155 p = skipwhite(p + 1); /* skip comma in between arguments */ | |
6156 } | |
6157 if (failed) | |
6158 break; | |
6159 if (round == 1) | |
6160 { | |
6161 retval = (short *)alloc((unsigned)((count + 1) * sizeof(short))); | |
6162 if (retval == NULL) | |
6163 break; | |
6164 retval[count] = 0; /* zero means end of the list */ | |
6165 total_count = count; | |
6166 } | |
6167 } | |
6168 | |
6169 *arg = p; | |
6170 if (failed || retval == NULL) | |
6171 { | |
6172 vim_free(retval); | |
6173 return FAIL; | |
6174 } | |
6175 | |
6176 if (*list == NULL) | |
6177 *list = retval; | |
6178 else | |
6179 vim_free(retval); /* list already found, don't overwrite it */ | |
6180 | |
6181 return OK; | |
6182 } | |
6183 | |
6184 /* | |
6185 * Make a copy of an ID list. | |
6186 */ | |
6187 static short * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6188 copy_id_list(short *list) |
7 | 6189 { |
6190 int len; | |
6191 int count; | |
6192 short *retval; | |
6193 | |
6194 if (list == NULL) | |
6195 return NULL; | |
6196 | |
6197 for (count = 0; list[count]; ++count) | |
6198 ; | |
6199 len = (count + 1) * sizeof(short); | |
6200 retval = (short *)alloc((unsigned)len); | |
6201 if (retval != NULL) | |
6202 mch_memmove(retval, list, (size_t)len); | |
6203 | |
6204 return retval; | |
6205 } | |
6206 | |
6207 /* | |
6208 * Check if syntax group "ssp" is in the ID list "list" of "cur_si". | |
6209 * "cur_si" can be NULL if not checking the "containedin" list. | |
6210 * Used to check if a syntax item is in the "contains" or "nextgroup" list of | |
6211 * the current item. | |
6212 * This function is called very often, keep it fast!! | |
6213 */ | |
6214 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6215 in_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6216 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
|
6217 short *list, /* id list */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6218 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
|
6219 int contained) /* group id is contained */ |
7 | 6220 { |
6221 int retval; | |
6222 short *scl_list; | |
6223 short item; | |
6224 short id = ssp->id; | |
6225 static int depth = 0; | |
6226 int r; | |
6227 | |
4352 | 6228 /* If ssp has a "containedin" list and "cur_si" is in it, return TRUE. */ |
36 | 6229 if (cur_si != NULL && ssp->cont_in_list != NULL |
6230 && !(cur_si->si_flags & HL_MATCH)) | |
7 | 6231 { |
6232 /* Ignore transparent items without a contains argument. Double check | |
6233 * that we don't go back past the first one. */ | |
6234 while ((cur_si->si_flags & HL_TRANS_CONT) | |
6235 && cur_si > (stateitem_T *)(current_state.ga_data)) | |
6236 --cur_si; | |
6237 /* cur_si->si_idx is -1 for keywords, these never contain anything. */ | |
6238 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
|
6239 &(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
|
6240 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) |
7 | 6241 return TRUE; |
6242 } | |
6243 | |
6244 if (list == NULL) | |
6245 return FALSE; | |
6246 | |
6247 /* | |
6248 * If list is ID_LIST_ALL, we are in a transparent item that isn't | |
6249 * inside anything. Only allow not-contained groups. | |
6250 */ | |
6251 if (list == ID_LIST_ALL) | |
6252 return !contained; | |
6253 | |
6254 /* | |
6255 * If the first item is "ALLBUT", return TRUE if "id" is NOT in the | |
6256 * contains list. We also require that "id" is at the same ":syn include" | |
6257 * level as the list. | |
6258 */ | |
6259 item = *list; | |
6260 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) | |
6261 { | |
6262 if (item < SYNID_TOP) | |
6263 { | |
6264 /* ALL or ALLBUT: accept all groups in the same file */ | |
6265 if (item - SYNID_ALLBUT != ssp->inc_tag) | |
6266 return FALSE; | |
6267 } | |
6268 else if (item < SYNID_CONTAINED) | |
6269 { | |
6270 /* TOP: accept all not-contained groups in the same file */ | |
6271 if (item - SYNID_TOP != ssp->inc_tag || contained) | |
6272 return FALSE; | |
6273 } | |
6274 else | |
6275 { | |
6276 /* CONTAINED: accept all contained groups in the same file */ | |
6277 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) | |
6278 return FALSE; | |
6279 } | |
6280 item = *++list; | |
6281 retval = FALSE; | |
6282 } | |
6283 else | |
6284 retval = TRUE; | |
6285 | |
6286 /* | |
6287 * Return "retval" if id is in the contains list. | |
6288 */ | |
6289 while (item != 0) | |
6290 { | |
6291 if (item == id) | |
6292 return retval; | |
6293 if (item >= SYNID_CLUSTER) | |
6294 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6295 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; |
7 | 6296 /* restrict recursiveness to 30 to avoid an endless loop for a |
6297 * cluster that includes itself (indirectly) */ | |
6298 if (scl_list != NULL && depth < 30) | |
6299 { | |
6300 ++depth; | |
6301 r = in_id_list(NULL, scl_list, ssp, contained); | |
6302 --depth; | |
6303 if (r) | |
6304 return retval; | |
6305 } | |
6306 } | |
6307 item = *++list; | |
6308 } | |
6309 return !retval; | |
6310 } | |
6311 | |
6312 struct subcommand | |
6313 { | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6314 char *name; /* subcommand name */ |
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6315 void (*func)(exarg_T *, int); /* function to call */ |
7 | 6316 }; |
6317 | |
6318 static struct subcommand subcommands[] = | |
6319 { | |
6320 {"case", syn_cmd_case}, | |
6321 {"clear", syn_cmd_clear}, | |
6322 {"cluster", syn_cmd_cluster}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6323 {"conceal", syn_cmd_conceal}, |
7 | 6324 {"enable", syn_cmd_enable}, |
6325 {"include", syn_cmd_include}, | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6326 {"iskeyword", syn_cmd_iskeyword}, |
7 | 6327 {"keyword", syn_cmd_keyword}, |
6328 {"list", syn_cmd_list}, | |
6329 {"manual", syn_cmd_manual}, | |
6330 {"match", syn_cmd_match}, | |
6331 {"on", syn_cmd_on}, | |
6332 {"off", syn_cmd_off}, | |
6333 {"region", syn_cmd_region}, | |
6334 {"reset", syn_cmd_reset}, | |
419 | 6335 {"spell", syn_cmd_spell}, |
7 | 6336 {"sync", syn_cmd_sync}, |
6337 {"", syn_cmd_list}, | |
6338 {NULL, NULL} | |
6339 }; | |
6340 | |
6341 /* | |
6342 * ":syntax". | |
6343 * This searches the subcommands[] table for the subcommand name, and calls a | |
6344 * syntax_subcommand() function to do the rest. | |
6345 */ | |
6346 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6347 ex_syntax(exarg_T *eap) |
7 | 6348 { |
6349 char_u *arg = eap->arg; | |
6350 char_u *subcmd_end; | |
6351 char_u *subcmd_name; | |
6352 int i; | |
6353 | |
6354 syn_cmdlinep = eap->cmdlinep; | |
6355 | |
6356 /* isolate subcommand name */ | |
6357 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) | |
6358 ; | |
6359 subcmd_name = vim_strnsave(arg, (int)(subcmd_end - arg)); | |
6360 if (subcmd_name != NULL) | |
6361 { | |
6362 if (eap->skip) /* skip error messages for all subcommands */ | |
6363 ++emsg_skip; | |
6364 for (i = 0; ; ++i) | |
6365 { | |
6366 if (subcommands[i].name == NULL) | |
6367 { | |
6368 EMSG2(_("E410: Invalid :syntax subcommand: %s"), subcmd_name); | |
6369 break; | |
6370 } | |
6371 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) | |
6372 { | |
6373 eap->arg = skipwhite(subcmd_end); | |
6374 (subcommands[i].func)(eap, FALSE); | |
6375 break; | |
6376 } | |
6377 } | |
6378 vim_free(subcmd_name); | |
6379 if (eap->skip) | |
6380 --emsg_skip; | |
6381 } | |
6382 } | |
6383 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6384 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6385 ex_ownsyntax(exarg_T *eap) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6386 { |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6387 char_u *old_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6388 char_u *new_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6389 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6390 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
|
6391 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6392 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
|
6393 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
|
6394 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
|
6395 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
|
6396 #ifdef FEAT_SPELL |
6386 | 6397 /* 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
|
6398 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
|
6399 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
|
6400 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
|
6401 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
|
6402 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6403 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
|
6404 } |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6405 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6406 /* save value of b:current_syntax */ |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6407 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
|
6408 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6409 old_value = vim_strsave(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6410 |
8362
a541dd5cfd3a
commit https://github.com/vim/vim/commit/d1413d90983fc6c579ad66ba4d4611b057197f94
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
6411 #ifdef FEAT_AUTOCMD |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6412 /* 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
|
6413 * file. */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6414 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
|
6415 #endif |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6416 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6417 /* 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
|
6418 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
|
6419 if (new_value != NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6420 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
|
6421 |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6422 /* restore value of b:current_syntax */ |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6423 if (old_value == NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6424 do_unlet((char_u *)"b:current_syntax", TRUE); |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6425 else |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6426 { |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6427 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
|
6428 vim_free(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6429 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6430 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6431 |
7 | 6432 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6433 syntax_present(win_T *win) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6434 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6435 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
|
6436 || 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
|
6437 || 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
|
6438 || win->w_s->b_keywtab_ic.ht_used > 0); |
7 | 6439 } |
6440 | |
6441 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
6442 | |
6443 static enum | |
6444 { | |
6445 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
|
6446 EXP_CASE, /* expand ":syn case" arguments */ |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6447 EXP_SPELL, /* expand ":syn spell" arguments */ |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6448 EXP_SYNC /* expand ":syn sync" arguments */ |
7 | 6449 } expand_what; |
6450 | |
1322 | 6451 /* |
6452 * Reset include_link, include_default, include_none to 0. | |
6453 * Called when we are done expanding. | |
6454 */ | |
6455 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6456 reset_expand_highlight(void) |
1322 | 6457 { |
6458 include_link = include_default = include_none = 0; | |
6459 } | |
6460 | |
6461 /* | |
6462 * Handle command line completion for :match and :echohl command: Add "None" | |
6463 * as highlight group. | |
6464 */ | |
6465 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6466 set_context_in_echohl_cmd(expand_T *xp, char_u *arg) |
1322 | 6467 { |
6468 xp->xp_context = EXPAND_HIGHLIGHT; | |
6469 xp->xp_pattern = arg; | |
6470 include_none = 1; | |
6471 } | |
7 | 6472 |
6473 /* | |
6474 * Handle command line completion for :syntax command. | |
6475 */ | |
6476 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6477 set_context_in_syntax_cmd(expand_T *xp, char_u *arg) |
7 | 6478 { |
6479 char_u *p; | |
6480 | |
6481 /* Default: expand subcommands */ | |
6482 xp->xp_context = EXPAND_SYNTAX; | |
6483 expand_what = EXP_SUBCMD; | |
6484 xp->xp_pattern = arg; | |
1322 | 6485 include_link = 0; |
6486 include_default = 0; | |
7 | 6487 |
6488 /* (part of) subcommand already typed */ | |
6489 if (*arg != NUL) | |
6490 { | |
6491 p = skiptowhite(arg); | |
6492 if (*p != NUL) /* past first word */ | |
6493 { | |
6494 xp->xp_pattern = skipwhite(p); | |
6495 if (*skiptowhite(xp->xp_pattern) != NUL) | |
6496 xp->xp_context = EXPAND_NOTHING; | |
6497 else if (STRNICMP(arg, "case", p - arg) == 0) | |
6498 expand_what = EXP_CASE; | |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6499 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
|
6500 expand_what = EXP_SPELL; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6501 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
|
6502 expand_what = EXP_SYNC; |
7 | 6503 else if ( STRNICMP(arg, "keyword", p - arg) == 0 |
6504 || STRNICMP(arg, "region", p - arg) == 0 | |
6505 || STRNICMP(arg, "match", p - arg) == 0 | |
6506 || STRNICMP(arg, "list", p - arg) == 0) | |
6507 xp->xp_context = EXPAND_HIGHLIGHT; | |
6508 else | |
6509 xp->xp_context = EXPAND_NOTHING; | |
6510 } | |
6511 } | |
6512 } | |
6513 | |
6514 /* | |
6515 * Function given to ExpandGeneric() to obtain the list syntax names for | |
6516 * expansion. | |
6517 */ | |
6518 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6519 get_syntax_name(expand_T *xp UNUSED, int idx) |
7 | 6520 { |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6521 switch (expand_what) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6522 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6523 case EXP_SUBCMD: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6524 return (char_u *)subcommands[idx].name; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6525 case EXP_CASE: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6526 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6527 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
|
6528 return (char_u *)case_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6529 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6530 case EXP_SPELL: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6531 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6532 static char *spell_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6533 {"toplevel", "notoplevel", "default", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6534 return (char_u *)spell_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6535 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6536 case EXP_SYNC: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6537 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6538 static char *sync_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6539 {"ccomment", "clear", "fromstart", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6540 "linebreaks=", "linecont", "lines=", "match", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6541 "maxlines=", "minlines=", "region", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6542 return (char_u *)sync_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6543 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6544 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6545 return NULL; |
7 | 6546 } |
6547 | |
6548 #endif /* FEAT_CMDL_COMPL */ | |
6549 | |
6550 /* | |
6551 * Function called for expression evaluation: get syntax ID at file position. | |
6552 */ | |
6553 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6554 syn_get_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6555 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6556 long lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6557 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6558 int trans, /* remove transparency */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6559 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
|
6560 int keep_state) /* keep state of char at "col" */ |
7 | 6561 { |
6562 /* When the position is not after the current position and in the same | |
6563 * line of the same buffer, need to restart parsing. */ | |
499 | 6564 if (wp->w_buffer != syn_buf |
7 | 6565 || lnum != current_lnum |
253 | 6566 || col < current_col) |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6567 syntax_start(wp, lnum, NULL); |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6568 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
|
6569 && lnum == current_lnum |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6570 && col > current_col) |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6571 /* 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
|
6572 * "skip" expression in searchpair() */ |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6573 next_match_idx = -1; |
7 | 6574 |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6575 (void)get_syntax_attr(col, spellp, keep_state); |
7 | 6576 |
6577 return (trans ? current_trans_id : current_id); | |
6578 } | |
6579 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6580 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6581 /* |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6582 * 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
|
6583 * 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
|
6584 * 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
|
6585 * 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
|
6586 */ |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6587 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6588 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
|
6589 { |
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
|
6590 *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
|
6591 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
|
6592 } |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6593 |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6594 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6595 * Return conceal substitution character |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6596 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6597 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6598 syn_get_sub_char(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6599 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6600 return current_sub_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6601 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6602 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6603 |
1500 | 6604 #if defined(FEAT_EVAL) || defined(PROTO) |
6605 /* | |
6606 * Return the syntax ID at position "i" in the current stack. | |
6607 * The caller must have called syn_get_id() before to fill the stack. | |
6608 * Returns -1 when "i" is out of range. | |
6609 */ | |
6610 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6611 syn_get_stack_item(int i) |
1500 | 6612 { |
1504 | 6613 if (i >= current_state.ga_len) |
6614 { | |
6615 /* Need to invalidate the state, because we didn't properly finish it | |
6616 * for the last character, "keep_state" was TRUE. */ | |
6617 invalidate_current_state(); | |
6618 current_col = MAXCOL; | |
1500 | 6619 return -1; |
1504 | 6620 } |
1500 | 6621 return CUR_STATE(i).si_id; |
6622 } | |
6623 #endif | |
6624 | |
7 | 6625 #if defined(FEAT_FOLDING) || defined(PROTO) |
6626 /* | |
6627 * Function called to get folding level for line "lnum" in window "wp". | |
6628 */ | |
6629 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6630 syn_get_foldlevel(win_T *wp, long lnum) |
7 | 6631 { |
6632 int level = 0; | |
6633 int i; | |
6634 | |
6635 /* Return quickly when there are no fold items at all. */ | |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6636 if (wp->w_s->b_syn_folditems != 0 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6637 && !wp->w_s->b_syn_error |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6638 # ifdef SYN_TIME_LIMIT |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6639 && !wp->w_s->b_syn_slow |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6640 # endif |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6641 ) |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6642 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6643 syntax_start(wp, lnum, NULL); |
7 | 6644 |
6645 for (i = 0; i < current_state.ga_len; ++i) | |
6646 if (CUR_STATE(i).si_flags & HL_FOLD) | |
6647 ++level; | |
6648 } | |
6649 if (level > wp->w_p_fdn) | |
1028 | 6650 { |
7 | 6651 level = wp->w_p_fdn; |
1028 | 6652 if (level < 0) |
6653 level = 0; | |
6654 } | |
7 | 6655 return level; |
6656 } | |
6657 #endif | |
6658 | |
6567 | 6659 #if defined(FEAT_PROFILE) || defined(PROTO) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6660 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6661 * ":syntime". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6662 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6663 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6664 ex_syntime(exarg_T *eap) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6665 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6666 if (STRCMP(eap->arg, "on") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6667 syn_time_on = TRUE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6668 else if (STRCMP(eap->arg, "off") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6669 syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6670 else if (STRCMP(eap->arg, "clear") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6671 syntime_clear(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6672 else if (STRCMP(eap->arg, "report") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6673 syntime_report(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6674 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6675 EMSG2(_(e_invarg2), eap->arg); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6676 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6677 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6678 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6679 syn_clear_time(syn_time_T *st) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6680 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6681 profile_zero(&st->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6682 profile_zero(&st->slowest); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6683 st->count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6684 st->match = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6685 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6686 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6687 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6688 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6689 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6690 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6691 syntime_clear(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6692 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6693 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6694 synpat_T *spp; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6695 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6696 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6697 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6698 MSG(_(msg_no_items)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6699 return; |
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 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
|
6702 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6703 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6704 syn_clear_time(&spp->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6705 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6706 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6707 |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6708 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6709 /* |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6710 * 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
|
6711 * ":syntime {on,off,clear,report}" command. |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6712 */ |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6713 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6714 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
|
6715 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6716 switch (idx) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6717 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6718 case 0: return (char_u *)"on"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6719 case 1: return (char_u *)"off"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6720 case 2: return (char_u *)"clear"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6721 case 3: return (char_u *)"report"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6722 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6723 return NULL; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6724 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6725 #endif |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6726 |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6727 typedef struct |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6728 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6729 proftime_T total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6730 int count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6731 int match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6732 proftime_T slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6733 proftime_T average; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6734 int id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6735 char_u *pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6736 } time_entry_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6737 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6738 static int |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6739 #ifdef __BORLANDC__ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6740 _RTLENTRYF |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6741 #endif |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6742 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
|
6743 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6744 const time_entry_T *s1 = v1; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6745 const time_entry_T *s2 = v2; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6746 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6747 return profile_cmp(&s1->total, &s2->total); |
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 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6750 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6751 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6752 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6753 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6754 syntime_report(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6755 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6756 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6757 synpat_T *spp; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6758 # ifdef FEAT_FLOAT |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6759 proftime_T tm; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6760 # endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6761 int len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6762 proftime_T total_total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6763 int total_count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6764 garray_T ga; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6765 time_entry_T *p; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6766 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6767 if (!syntax_present(curwin)) |
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 MSG(_(msg_no_items)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6770 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6771 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6772 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6773 ga_init2(&ga, sizeof(time_entry_T), 50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6774 profile_zero(&total_total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6775 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
|
6776 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6777 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6778 if (spp->sp_time.count > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6779 { |
7009 | 6780 (void)ga_grow(&ga, 1); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6781 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
|
6782 p->total = spp->sp_time.total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6783 profile_add(&total_total, &spp->sp_time.total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6784 p->count = spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6785 p->match = spp->sp_time.match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6786 total_count += spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6787 p->slowest = spp->sp_time.slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6788 # ifdef FEAT_FLOAT |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6789 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
|
6790 p->average = tm; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6791 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6792 p->id = spp->sp_syn.id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6793 p->pattern = spp->sp_pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6794 ++ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6795 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6796 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6797 |
10530
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6798 /* 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
|
6799 * pointer to qsort(). */ |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6800 if (ga.ga_len > 1) |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6801 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
|
6802 syn_compare_syntime); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6803 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6804 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
|
6805 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6806 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
|
6807 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6808 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6809 p = ((time_entry_T *)ga.ga_data) + idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6810 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6811 MSG_PUTS(profile_msg(&p->total)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6812 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
|
6813 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6814 msg_outnum(p->count); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6815 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6816 msg_advance(20); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6817 msg_outnum(p->match); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6818 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6819 msg_advance(26); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6820 MSG_PUTS(profile_msg(&p->slowest)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6821 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6822 msg_advance(38); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6823 # ifdef FEAT_FLOAT |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6824 MSG_PUTS(profile_msg(&p->average)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6825 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6826 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6827 msg_advance(50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6828 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
|
6829 MSG_PUTS(" "); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6830 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6831 msg_advance(69); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6832 if (Columns < 80) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6833 len = 20; /* will wrap anyway */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6834 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6835 len = Columns - 70; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6836 if (len > (int)STRLEN(p->pattern)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6837 len = (int)STRLEN(p->pattern); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6838 msg_outtrans_len(p->pattern, len); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6839 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6840 } |
4791
65cef998f860
updated for version 7.3.1142
Bram Moolenaar <bram@vim.org>
parents:
4776
diff
changeset
|
6841 ga_clear(&ga); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6842 if (!got_int) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6843 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6844 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6845 MSG_PUTS(profile_msg(&total_total)); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6846 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6847 msg_outnum(total_count); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6848 MSG_PUTS("\n"); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6849 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6850 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6851 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6852 |
7 | 6853 #endif /* FEAT_SYN_HL */ |
6854 | |
6855 /************************************** | |
6856 * Highlighting stuff * | |
6857 **************************************/ | |
6858 | |
6859 /* | |
6860 * The default highlight groups. These are compiled-in for fast startup and | |
6861 * they still work when the runtime files can't be found. | |
6862 * When making changes here, also change runtime/colors/default.vim! | |
806 | 6863 * The #ifdefs are needed to reduce the amount of static data. Helps to make |
6864 * the 16 bit DOS (museum) version compile. | |
7 | 6865 */ |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
6866 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
809 | 6867 # define CENT(a, b) b |
6868 #else | |
6869 # define CENT(a, b) a | |
6870 #endif | |
7 | 6871 static char *(highlight_init_both[]) = |
6872 { | |
809 | 6873 CENT("ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", |
6874 "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), | |
6875 CENT("IncSearch term=reverse cterm=reverse", | |
6876 "IncSearch term=reverse cterm=reverse gui=reverse"), | |
6877 CENT("ModeMsg term=bold cterm=bold", | |
6878 "ModeMsg term=bold cterm=bold gui=bold"), | |
6879 CENT("NonText term=bold ctermfg=Blue", | |
6880 "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), | |
6881 CENT("StatusLine term=reverse,bold cterm=reverse,bold", | |
6882 "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), | |
6883 CENT("StatusLineNC term=reverse cterm=reverse", | |
6884 "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
|
6885 "default link EndOfBuffer NonText", |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
6886 #ifdef FEAT_WINDOWS |
809 | 6887 CENT("VertSplit term=reverse cterm=reverse", |
6888 "VertSplit term=reverse cterm=reverse gui=reverse"), | |
806 | 6889 #endif |
6890 #ifdef FEAT_CLIPBOARD | |
809 | 6891 CENT("VisualNOS term=underline,bold cterm=underline,bold", |
6892 "VisualNOS term=underline,bold cterm=underline,bold gui=underline,bold"), | |
806 | 6893 #endif |
6894 #ifdef FEAT_DIFF | |
809 | 6895 CENT("DiffText term=reverse cterm=bold ctermbg=Red", |
6896 "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), | |
806 | 6897 #endif |
6898 #ifdef FEAT_INS_EXPAND | |
809 | 6899 CENT("PmenuSbar ctermbg=Grey", |
6900 "PmenuSbar ctermbg=Grey guibg=Grey"), | |
806 | 6901 #endif |
6902 #ifdef FEAT_WINDOWS | |
809 | 6903 CENT("TabLineSel term=bold cterm=bold", |
6904 "TabLineSel term=bold cterm=bold gui=bold"), | |
6905 CENT("TabLineFill term=reverse cterm=reverse", | |
6906 "TabLineFill term=reverse cterm=reverse gui=reverse"), | |
806 | 6907 #endif |
7 | 6908 #ifdef FEAT_GUI |
6909 "Cursor guibg=fg guifg=bg", | |
809 | 6910 "lCursor guibg=fg guifg=bg", /* should be different, but what? */ |
7 | 6911 #endif |
11541
3bc4fb330d07
patch 8.0.0653: the default highlight for QuickFixLine is not good
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
6912 "default link QuickFixLine Search", |
7 | 6913 NULL |
6914 }; | |
6915 | |
6916 static char *(highlight_init_light[]) = | |
6917 { | |
809 | 6918 CENT("Directory term=bold ctermfg=DarkBlue", |
6919 "Directory term=bold ctermfg=DarkBlue guifg=Blue"), | |
6920 CENT("LineNr term=underline ctermfg=Brown", | |
6921 "LineNr term=underline ctermfg=Brown guifg=Brown"), | |
3427 | 6922 CENT("CursorLineNr term=bold ctermfg=Brown", |
6923 "CursorLineNr term=bold ctermfg=Brown gui=bold guifg=Brown"), | |
809 | 6924 CENT("MoreMsg term=bold ctermfg=DarkGreen", |
6925 "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6926 CENT("Question term=standout ctermfg=DarkGreen", | |
6927 "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), | |
6928 CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", | |
6929 "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), | |
806 | 6930 #ifdef FEAT_SPELL |
809 | 6931 CENT("SpellBad term=reverse ctermbg=LightRed", |
6932 "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), | |
6933 CENT("SpellCap term=reverse ctermbg=LightBlue", | |
6934 "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), | |
6935 CENT("SpellRare term=reverse ctermbg=LightMagenta", | |
6936 "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), | |
6937 CENT("SpellLocal term=underline ctermbg=Cyan", | |
6938 "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), | |
806 | 6939 #endif |
6940 #ifdef FEAT_INS_EXPAND | |
3419 | 6941 CENT("PmenuThumb ctermbg=Black", |
6942 "PmenuThumb ctermbg=Black guibg=Black"), | |
6943 CENT("Pmenu ctermbg=LightMagenta ctermfg=Black", | |
6944 "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta"), | |
6945 CENT("PmenuSel ctermbg=LightGrey ctermfg=Black", | |
6946 "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey"), | |
806 | 6947 #endif |
809 | 6948 CENT("SpecialKey term=bold ctermfg=DarkBlue", |
6949 "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), | |
6950 CENT("Title term=bold ctermfg=DarkMagenta", | |
6951 "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), | |
6952 CENT("WarningMsg term=standout ctermfg=DarkRed", | |
6953 "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), | |
806 | 6954 #ifdef FEAT_WILDMENU |
809 | 6955 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
6956 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 6957 #endif |
6958 #ifdef FEAT_FOLDING | |
809 | 6959 CENT("Folded term=standout ctermbg=Grey ctermfg=DarkBlue", |
6960 "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), | |
6961 CENT("FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", | |
6962 "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6963 #endif |
6964 #ifdef FEAT_SIGNS | |
809 | 6965 CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", |
6966 "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), | |
806 | 6967 #endif |
836 | 6968 CENT("Visual term=reverse", |
6969 "Visual term=reverse guibg=LightGrey"), | |
806 | 6970 #ifdef FEAT_DIFF |
809 | 6971 CENT("DiffAdd term=bold ctermbg=LightBlue", |
6972 "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), | |
6973 CENT("DiffChange term=bold ctermbg=LightMagenta", | |
6974 "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), | |
6975 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", | |
6976 "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), | |
806 | 6977 #endif |
6978 #ifdef FEAT_WINDOWS | |
809 | 6979 CENT("TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", |
6980 "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), | |
806 | 6981 #endif |
6982 #ifdef FEAT_SYN_HL | |
809 | 6983 CENT("CursorColumn term=reverse ctermbg=LightGrey", |
818 | 6984 "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), |
809 | 6985 CENT("CursorLine term=underline cterm=underline", |
818 | 6986 "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
|
6987 CENT("ColorColumn term=reverse ctermbg=LightRed", |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
6988 "ColorColumn term=reverse ctermbg=LightRed guibg=LightRed"), |
806 | 6989 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6990 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6991 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6992 "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
|
6993 #endif |
834 | 6994 #ifdef FEAT_AUTOCMD |
6995 CENT("MatchParen term=reverse ctermbg=Cyan", | |
6996 "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), | |
6997 #endif | |
806 | 6998 #ifdef FEAT_GUI |
7 | 6999 "Normal gui=NONE", |
806 | 7000 #endif |
7 | 7001 NULL |
7002 }; | |
7003 | |
7004 static char *(highlight_init_dark[]) = | |
7005 { | |
809 | 7006 CENT("Directory term=bold ctermfg=LightCyan", |
7007 "Directory term=bold ctermfg=LightCyan guifg=Cyan"), | |
7008 CENT("LineNr term=underline ctermfg=Yellow", | |
7009 "LineNr term=underline ctermfg=Yellow guifg=Yellow"), | |
3427 | 7010 CENT("CursorLineNr term=bold ctermfg=Yellow", |
7011 "CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow"), | |
809 | 7012 CENT("MoreMsg term=bold ctermfg=LightGreen", |
7013 "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), | |
7014 CENT("Question term=standout ctermfg=LightGreen", | |
7015 "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), | |
7016 CENT("Search term=reverse ctermbg=Yellow ctermfg=Black", | |
7017 "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
7018 CENT("SpecialKey term=bold ctermfg=LightBlue", | |
7019 "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), | |
806 | 7020 #ifdef FEAT_SPELL |
809 | 7021 CENT("SpellBad term=reverse ctermbg=Red", |
7022 "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), | |
7023 CENT("SpellCap term=reverse ctermbg=Blue", | |
7024 "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), | |
7025 CENT("SpellRare term=reverse ctermbg=Magenta", | |
7026 "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), | |
7027 CENT("SpellLocal term=underline ctermbg=Cyan", | |
7028 "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), | |
806 | 7029 #endif |
7030 #ifdef FEAT_INS_EXPAND | |
3419 | 7031 CENT("PmenuThumb ctermbg=White", |
7032 "PmenuThumb ctermbg=White guibg=White"), | |
7033 CENT("Pmenu ctermbg=Magenta ctermfg=Black", | |
7034 "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta"), | |
3695 | 7035 CENT("PmenuSel ctermbg=Black ctermfg=DarkGrey", |
7036 "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey"), | |
806 | 7037 #endif |
809 | 7038 CENT("Title term=bold ctermfg=LightMagenta", |
7039 "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), | |
7040 CENT("WarningMsg term=standout ctermfg=LightRed", | |
7041 "WarningMsg term=standout ctermfg=LightRed guifg=Red"), | |
806 | 7042 #ifdef FEAT_WILDMENU |
809 | 7043 CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", |
7044 "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), | |
806 | 7045 #endif |
7046 #ifdef FEAT_FOLDING | |
809 | 7047 CENT("Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", |
7048 "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), | |
7049 CENT("FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", | |
7050 "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 7051 #endif |
7052 #ifdef FEAT_SIGNS | |
809 | 7053 CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", |
7054 "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), | |
806 | 7055 #endif |
836 | 7056 CENT("Visual term=reverse", |
7057 "Visual term=reverse guibg=DarkGrey"), | |
806 | 7058 #ifdef FEAT_DIFF |
809 | 7059 CENT("DiffAdd term=bold ctermbg=DarkBlue", |
7060 "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), | |
7061 CENT("DiffChange term=bold ctermbg=DarkMagenta", | |
7062 "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), | |
7063 CENT("DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", | |
7064 "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), | |
806 | 7065 #endif |
7066 #ifdef FEAT_WINDOWS | |
809 | 7067 CENT("TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", |
7068 "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), | |
806 | 7069 #endif |
7070 #ifdef FEAT_SYN_HL | |
809 | 7071 CENT("CursorColumn term=reverse ctermbg=DarkGrey", |
834 | 7072 "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), |
809 | 7073 CENT("CursorLine term=underline cterm=underline", |
834 | 7074 "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
|
7075 CENT("ColorColumn term=reverse ctermbg=DarkRed", |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
7076 "ColorColumn term=reverse ctermbg=DarkRed guibg=DarkRed"), |
834 | 7077 #endif |
7078 #ifdef FEAT_AUTOCMD | |
7079 CENT("MatchParen term=reverse ctermbg=DarkCyan", | |
7080 "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), | |
806 | 7081 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7082 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7083 CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
7084 "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
|
7085 #endif |
806 | 7086 #ifdef FEAT_GUI |
7 | 7087 "Normal gui=NONE", |
806 | 7088 #endif |
7 | 7089 NULL |
7090 }; | |
7091 | |
7092 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7093 init_highlight( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7094 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
|
7095 int reset) /* clear group first */ |
7 | 7096 { |
7097 int i; | |
7098 char **pp; | |
7099 static int had_both = FALSE; | |
7100 #ifdef FEAT_EVAL | |
7101 char_u *p; | |
7102 | |
7103 /* | |
7104 * Try finding the color scheme file. Used when a color file was loaded | |
7105 * and 'background' or 't_Co' is changed. | |
7106 */ | |
7107 p = get_var_value((char_u *)"g:colors_name"); | |
6671 | 7108 if (p != NULL) |
7109 { | |
7110 /* The value of g:colors_name could be freed when sourcing the script, | |
7111 * making "p" invalid, so copy it. */ | |
7112 char_u *copy_p = vim_strsave(p); | |
7113 int r; | |
7114 | |
7115 if (copy_p != NULL) | |
7116 { | |
7117 r = load_colors(copy_p); | |
7118 vim_free(copy_p); | |
7119 if (r == OK) | |
7120 return; | |
7121 } | |
7122 } | |
7123 | |
7 | 7124 #endif |
7125 | |
7126 /* | |
7127 * Didn't use a color file, use the compiled-in colors. | |
7128 */ | |
7129 if (both) | |
7130 { | |
7131 had_both = TRUE; | |
7132 pp = highlight_init_both; | |
7133 for (i = 0; pp[i] != NULL; ++i) | |
7134 do_highlight((char_u *)pp[i], reset, TRUE); | |
7135 } | |
7136 else if (!had_both) | |
7137 /* Don't do anything before the call with both == TRUE from main(). | |
7138 * Not everything has been setup then, and that call will overrule | |
7139 * everything anyway. */ | |
7140 return; | |
7141 | |
7142 if (*p_bg == 'l') | |
7143 pp = highlight_init_light; | |
7144 else | |
7145 pp = highlight_init_dark; | |
7146 for (i = 0; pp[i] != NULL; ++i) | |
7147 do_highlight((char_u *)pp[i], reset, TRUE); | |
7148 | |
836 | 7149 /* Reverse looks ugly, but grey may not work for 8 colors. Thus let it |
844 | 7150 * depend on the number of colors available. |
7151 * With 8 colors brown is equal to yellow, need to use black for Search fg | |
1697 | 7152 * to avoid Statement highlighted text disappears. |
7153 * Clear the attributes, needed when changing the t_Co value. */ | |
527 | 7154 if (t_colors > 8) |
1697 | 7155 do_highlight((char_u *)(*p_bg == 'l' |
7156 ? "Visual cterm=NONE ctermbg=LightGrey" | |
7157 : "Visual cterm=NONE ctermbg=DarkGrey"), FALSE, TRUE); | |
836 | 7158 else |
844 | 7159 { |
1697 | 7160 do_highlight((char_u *)"Visual cterm=reverse ctermbg=NONE", |
7161 FALSE, TRUE); | |
844 | 7162 if (*p_bg == 'l') |
7163 do_highlight((char_u *)"Search ctermfg=black", FALSE, TRUE); | |
7164 } | |
527 | 7165 |
7 | 7166 #ifdef FEAT_SYN_HL |
7167 /* | |
7168 * If syntax highlighting is enabled load the highlighting for it. | |
7169 */ | |
7170 if (get_var_value((char_u *)"g:syntax_on") != NULL) | |
24 | 7171 { |
7172 static int recursive = 0; | |
7173 | |
7174 if (recursive >= 5) | |
7175 EMSG(_("E679: recursive loop loading syncolor.vim")); | |
7176 else | |
7177 { | |
7178 ++recursive; | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
7179 (void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL); |
24 | 7180 --recursive; |
7181 } | |
7182 } | |
7 | 7183 #endif |
7184 } | |
7185 | |
7186 /* | |
12 | 7187 * Load color file "name". |
7 | 7188 * Return OK for success, FAIL for failure. |
7189 */ | |
7190 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7191 load_colors(char_u *name) |
7 | 7192 { |
7193 char_u *buf; | |
7194 int retval = FAIL; | |
7195 static int recursive = FALSE; | |
7196 | |
7197 /* When being called recursively, this is probably because setting | |
7198 * 'background' caused the highlighting to be reloaded. This means it is | |
7199 * working, thus we should return OK. */ | |
7200 if (recursive) | |
7201 return OK; | |
7202 | |
7203 recursive = TRUE; | |
12 | 7204 buf = alloc((unsigned)(STRLEN(name) + 12)); |
7 | 7205 if (buf != NULL) |
7206 { | |
12 | 7207 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
|
7208 retval = source_runtime(buf, DIP_START + DIP_OPT); |
7 | 7209 vim_free(buf); |
12 | 7210 #ifdef FEAT_AUTOCMD |
5521 | 7211 apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); |
12 | 7212 #endif |
7 | 7213 } |
7214 recursive = FALSE; | |
7215 | |
7216 return retval; | |
7217 } | |
7218 | |
7219 /* | |
7220 * Handle the ":highlight .." command. | |
7221 * When using ":hi clear" this is called recursively for each group with | |
7222 * "forceit" and "init" both TRUE. | |
7223 */ | |
7224 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7225 do_highlight( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7226 char_u *line, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7227 int forceit, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
7228 int init) /* TRUE when called for initializing */ |
7 | 7229 { |
7230 char_u *name_end; | |
7231 char_u *p; | |
7232 char_u *linep; | |
7233 char_u *key_start; | |
7234 char_u *arg_start; | |
7235 char_u *key = NULL, *arg = NULL; | |
7236 long i; | |
7237 int off; | |
7238 int len; | |
7239 int attr; | |
7240 int id; | |
7241 int idx; | |
7242 int dodefault = FALSE; | |
7243 int doclear = FALSE; | |
7244 int dolink = FALSE; | |
7245 int error = FALSE; | |
7246 int color; | |
7247 int is_normal_group = FALSE; /* "Normal" group */ | |
7248 #ifdef FEAT_GUI_X11 | |
7249 int is_menu_group = FALSE; /* "Menu" group */ | |
7250 int is_scrollbar_group = FALSE; /* "Scrollbar" group */ | |
7251 int is_tooltip_group = FALSE; /* "Tooltip" group */ | |
7252 int do_colors = FALSE; /* need to update colors? */ | |
7253 #else | |
7254 # define is_menu_group 0 | |
7255 # define is_tooltip_group 0 | |
7256 #endif | |
7257 | |
7258 /* | |
7259 * If no argument, list current highlighting. | |
7260 */ | |
7261 if (ends_excmd(*line)) | |
7262 { | |
7263 for (i = 1; i <= highlight_ga.ga_len && !got_int; ++i) | |
7264 /* TODO: only call when the group has attributes set */ | |
7265 highlight_list_one((int)i); | |
7266 return; | |
7267 } | |
7268 | |
7269 /* | |
7270 * Isolate the name. | |
7271 */ | |
7272 name_end = skiptowhite(line); | |
7273 linep = skipwhite(name_end); | |
7274 | |
7275 /* | |
7276 * Check for "default" argument. | |
7277 */ | |
7278 if (STRNCMP(line, "default", name_end - line) == 0) | |
7279 { | |
7280 dodefault = TRUE; | |
7281 line = linep; | |
7282 name_end = skiptowhite(line); | |
7283 linep = skipwhite(name_end); | |
7284 } | |
7285 | |
7286 /* | |
7287 * Check for "clear" or "link" argument. | |
7288 */ | |
7289 if (STRNCMP(line, "clear", name_end - line) == 0) | |
7290 doclear = TRUE; | |
7291 if (STRNCMP(line, "link", name_end - line) == 0) | |
7292 dolink = TRUE; | |
7293 | |
7294 /* | |
7295 * ":highlight {group-name}": list highlighting for one group. | |
7296 */ | |
7297 if (!doclear && !dolink && ends_excmd(*linep)) | |
7298 { | |
7299 id = syn_namen2id(line, (int)(name_end - line)); | |
7300 if (id == 0) | |
7301 EMSG2(_("E411: highlight group not found: %s"), line); | |
7302 else | |
7303 highlight_list_one(id); | |
7304 return; | |
7305 } | |
7306 | |
7307 /* | |
7308 * Handle ":highlight link {from} {to}" command. | |
7309 */ | |
7310 if (dolink) | |
7311 { | |
7312 char_u *from_start = linep; | |
7313 char_u *from_end; | |
7314 char_u *to_start; | |
7315 char_u *to_end; | |
7316 int from_id; | |
7317 int to_id; | |
7318 | |
7319 from_end = skiptowhite(from_start); | |
7320 to_start = skipwhite(from_end); | |
7321 to_end = skiptowhite(to_start); | |
7322 | |
7323 if (ends_excmd(*from_start) || ends_excmd(*to_start)) | |
7324 { | |
7325 EMSG2(_("E412: Not enough arguments: \":highlight link %s\""), | |
7326 from_start); | |
7327 return; | |
7328 } | |
7329 | |
7330 if (!ends_excmd(*skipwhite(to_end))) | |
7331 { | |
7332 EMSG2(_("E413: Too many arguments: \":highlight link %s\""), from_start); | |
7333 return; | |
7334 } | |
7335 | |
7336 from_id = syn_check_group(from_start, (int)(from_end - from_start)); | |
7337 if (STRNCMP(to_start, "NONE", 4) == 0) | |
7338 to_id = 0; | |
7339 else | |
7340 to_id = syn_check_group(to_start, (int)(to_end - to_start)); | |
7341 | |
7342 if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0)) | |
7343 { | |
7344 /* | |
7345 * Don't allow a link when there already is some highlighting | |
7346 * for the group, unless '!' is used | |
7347 */ | |
7348 if (to_id > 0 && !forceit && !init | |
7349 && hl_has_settings(from_id - 1, dodefault)) | |
7350 { | |
7351 if (sourcing_name == NULL && !dodefault) | |
7352 EMSG(_("E414: group has settings, highlight link ignored")); | |
7353 } | |
7354 else | |
7355 { | |
7356 if (!init) | |
7357 HL_TABLE()[from_id - 1].sg_set |= SG_LINK; | |
7358 HL_TABLE()[from_id - 1].sg_link = to_id; | |
448 | 7359 #ifdef FEAT_EVAL |
7360 HL_TABLE()[from_id - 1].sg_scriptID = current_SID; | |
7361 #endif | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
7362 HL_TABLE()[from_id - 1].sg_cleared = FALSE; |
745 | 7363 redraw_all_later(SOME_VALID); |
7 | 7364 } |
7365 } | |
7366 | |
7367 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
7368 need_highlight_changed = TRUE; | |
7369 | |
7370 return; | |
7371 } | |
7372 | |
7373 if (doclear) | |
7374 { | |
7375 /* | |
7376 * ":highlight clear [group]" command. | |
7377 */ | |
7378 line = linep; | |
7379 if (ends_excmd(*line)) | |
7380 { | |
7381 #ifdef FEAT_GUI | |
7382 /* First, we do not destroy the old values, but allocate the new | |
7383 * ones and update the display. THEN we destroy the old values. | |
7384 * If we destroy the old values first, then the old values | |
7385 * (such as GuiFont's or GuiFontset's) will still be displayed but | |
7386 * invalid because they were free'd. | |
7387 */ | |
7388 if (gui.in_use) | |
7389 { | |
7390 # ifdef FEAT_BEVAL_TIP | |
7391 gui_init_tooltip_font(); | |
7392 # endif | |
7393 # if defined(FEAT_MENU) && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF)) | |
7394 gui_init_menu_font(); | |
7395 # endif | |
7396 } | |
7397 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_X11) | |
7398 gui_mch_def_colors(); | |
7399 # endif | |
7400 # ifdef FEAT_GUI_X11 | |
7401 # ifdef FEAT_MENU | |
7402 | |
7403 /* This only needs to be done when there is no Menu highlight | |
7404 * group defined by default, which IS currently the case. | |
7405 */ | |
7406 gui_mch_new_menu_colors(); | |
7407 # endif | |
7408 if (gui.in_use) | |
7409 { | |
7410 gui_new_scrollbar_colors(); | |
7411 # ifdef FEAT_BEVAL | |
7412 gui_mch_new_tooltip_colors(); | |
7413 # endif | |
7414 # ifdef FEAT_MENU | |
7415 gui_mch_new_menu_font(); | |
7416 # endif | |
7417 } | |
7418 # endif | |
7419 | |
7420 /* Ok, we're done allocating the new default graphics items. | |
7421 * The screen should already be refreshed at this point. | |
7422 * It is now Ok to clear out the old data. | |
7423 */ | |
7424 #endif | |
7425 #ifdef FEAT_EVAL | |
148 | 7426 do_unlet((char_u *)"colors_name", TRUE); |
7 | 7427 #endif |
7428 restore_cterm_colors(); | |
7429 | |
7430 /* | |
7431 * Clear all default highlight groups and load the defaults. | |
7432 */ | |
7433 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
7434 highlight_clear(idx); | |
7435 init_highlight(TRUE, TRUE); | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7436 #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
|
7437 if (USE_24BIT) |
7 | 7438 highlight_gui_started(); |
7439 #endif | |
7440 highlight_changed(); | |
7441 redraw_later_clear(); | |
7442 return; | |
7443 } | |
7444 name_end = skiptowhite(line); | |
7445 linep = skipwhite(name_end); | |
7446 } | |
7447 | |
7448 /* | |
7449 * Find the group name in the table. If it does not exist yet, add it. | |
7450 */ | |
7451 id = syn_check_group(line, (int)(name_end - line)); | |
7452 if (id == 0) /* failed (out of memory) */ | |
7453 return; | |
7454 idx = id - 1; /* index is ID minus one */ | |
7455 | |
7456 /* Return if "default" was used and the group already has settings. */ | |
7457 if (dodefault && hl_has_settings(idx, TRUE)) | |
7458 return; | |
7459 | |
7460 if (STRCMP(HL_TABLE()[idx].sg_name_u, "NORMAL") == 0) | |
7461 is_normal_group = TRUE; | |
7462 #ifdef FEAT_GUI_X11 | |
7463 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "MENU") == 0) | |
7464 is_menu_group = TRUE; | |
7465 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "SCROLLBAR") == 0) | |
7466 is_scrollbar_group = TRUE; | |
7467 else if (STRCMP(HL_TABLE()[idx].sg_name_u, "TOOLTIP") == 0) | |
7468 is_tooltip_group = TRUE; | |
7469 #endif | |
7470 | |
7471 /* Clear the highlighting for ":hi clear {group}" and ":hi clear". */ | |
7472 if (doclear || (forceit && init)) | |
7473 { | |
7474 highlight_clear(idx); | |
7475 if (!doclear) | |
7476 HL_TABLE()[idx].sg_set = 0; | |
7477 } | |
7478 | |
7479 if (!doclear) | |
7480 while (!ends_excmd(*linep)) | |
7481 { | |
7482 key_start = linep; | |
7483 if (*linep == '=') | |
7484 { | |
7485 EMSG2(_("E415: unexpected equal sign: %s"), key_start); | |
7486 error = TRUE; | |
7487 break; | |
7488 } | |
7489 | |
7490 /* | |
7491 * Isolate the key ("term", "ctermfg", "ctermbg", "font", "guifg" or | |
7492 * "guibg"). | |
7493 */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
7494 while (*linep && !VIM_ISWHITE(*linep) && *linep != '=') |
7 | 7495 ++linep; |
7496 vim_free(key); | |
7497 key = vim_strnsave_up(key_start, (int)(linep - key_start)); | |
7498 if (key == NULL) | |
7499 { | |
7500 error = TRUE; | |
7501 break; | |
7502 } | |
7503 linep = skipwhite(linep); | |
7504 | |
7505 if (STRCMP(key, "NONE") == 0) | |
7506 { | |
7507 if (!init || HL_TABLE()[idx].sg_set == 0) | |
7508 { | |
7509 if (!init) | |
7510 HL_TABLE()[idx].sg_set |= SG_TERM+SG_CTERM+SG_GUI; | |
7511 highlight_clear(idx); | |
7512 } | |
7513 continue; | |
7514 } | |
7515 | |
7516 /* | |
7517 * Check for the equal sign. | |
7518 */ | |
7519 if (*linep != '=') | |
7520 { | |
7521 EMSG2(_("E416: missing equal sign: %s"), key_start); | |
7522 error = TRUE; | |
7523 break; | |
7524 } | |
7525 ++linep; | |
7526 | |
7527 /* | |
7528 * Isolate the argument. | |
7529 */ | |
7530 linep = skipwhite(linep); | |
7531 if (*linep == '\'') /* guifg='color name' */ | |
7532 { | |
7533 arg_start = ++linep; | |
7534 linep = vim_strchr(linep, '\''); | |
7535 if (linep == NULL) | |
7536 { | |
7537 EMSG2(_(e_invarg2), key_start); | |
7538 error = TRUE; | |
7539 break; | |
7540 } | |
7541 } | |
7542 else | |
7543 { | |
7544 arg_start = linep; | |
7545 linep = skiptowhite(linep); | |
7546 } | |
7547 if (linep == arg_start) | |
7548 { | |
7549 EMSG2(_("E417: missing argument: %s"), key_start); | |
7550 error = TRUE; | |
7551 break; | |
7552 } | |
7553 vim_free(arg); | |
7554 arg = vim_strnsave(arg_start, (int)(linep - arg_start)); | |
7555 if (arg == NULL) | |
7556 { | |
7557 error = TRUE; | |
7558 break; | |
7559 } | |
7560 if (*linep == '\'') | |
7561 ++linep; | |
7562 | |
7563 /* | |
7564 * Store the argument. | |
7565 */ | |
7566 if ( STRCMP(key, "TERM") == 0 | |
7567 || STRCMP(key, "CTERM") == 0 | |
7568 || STRCMP(key, "GUI") == 0) | |
7569 { | |
7570 attr = 0; | |
7571 off = 0; | |
7572 while (arg[off] != NUL) | |
7573 { | |
7574 for (i = sizeof(hl_attr_table) / sizeof(int); --i >= 0; ) | |
7575 { | |
7576 len = (int)STRLEN(hl_name_table[i]); | |
7577 if (STRNICMP(arg + off, hl_name_table[i], len) == 0) | |
7578 { | |
7579 attr |= hl_attr_table[i]; | |
7580 off += len; | |
7581 break; | |
7582 } | |
7583 } | |
7584 if (i < 0) | |
7585 { | |
7586 EMSG2(_("E418: Illegal value: %s"), arg); | |
7587 error = TRUE; | |
7588 break; | |
7589 } | |
7590 if (arg[off] == ',') /* another one follows */ | |
7591 ++off; | |
7592 } | |
7593 if (error) | |
7594 break; | |
7595 if (*key == 'T') | |
7596 { | |
7597 if (!init || !(HL_TABLE()[idx].sg_set & SG_TERM)) | |
7598 { | |
7599 if (!init) | |
7600 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7601 HL_TABLE()[idx].sg_term = attr; | |
7602 } | |
7603 } | |
7604 else if (*key == 'C') | |
7605 { | |
7606 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7607 { | |
7608 if (!init) | |
7609 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7610 HL_TABLE()[idx].sg_cterm = attr; | |
7611 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7612 } | |
7613 } | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7614 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 7615 else |
7616 { | |
7617 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) | |
7618 { | |
7619 if (!init) | |
7620 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7621 HL_TABLE()[idx].sg_gui = attr; | |
7622 } | |
7623 } | |
7624 #endif | |
7625 } | |
7626 else if (STRCMP(key, "FONT") == 0) | |
7627 { | |
7628 /* in non-GUI fonts are simply ignored */ | |
7629 #ifdef FEAT_GUI | |
7630 if (!gui.shell_created) | |
7631 { | |
7632 /* GUI not started yet, always accept the name. */ | |
7633 vim_free(HL_TABLE()[idx].sg_font_name); | |
7634 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7635 } | |
7636 else | |
7637 { | |
7638 GuiFont temp_sg_font = HL_TABLE()[idx].sg_font; | |
7639 # ifdef FEAT_XFONTSET | |
7640 GuiFontset temp_sg_fontset = HL_TABLE()[idx].sg_fontset; | |
7641 # endif | |
7642 /* First, save the current font/fontset. | |
7643 * Then try to allocate the font/fontset. | |
7644 * If the allocation fails, HL_TABLE()[idx].sg_font OR | |
7645 * sg_fontset will be set to NOFONT or NOFONTSET respectively. | |
7646 */ | |
7647 | |
7648 HL_TABLE()[idx].sg_font = NOFONT; | |
7649 # ifdef FEAT_XFONTSET | |
7650 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
7651 # endif | |
7652 hl_do_font(idx, arg, is_normal_group, is_menu_group, | |
3881 | 7653 is_tooltip_group, FALSE); |
7 | 7654 |
7655 # ifdef FEAT_XFONTSET | |
7656 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) | |
7657 { | |
3881 | 7658 /* New fontset was accepted. Free the old one, if there |
7659 * was one. */ | |
7 | 7660 gui_mch_free_fontset(temp_sg_fontset); |
7661 vim_free(HL_TABLE()[idx].sg_font_name); | |
7662 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7663 } | |
7664 else | |
7665 HL_TABLE()[idx].sg_fontset = temp_sg_fontset; | |
7666 # endif | |
7667 if (HL_TABLE()[idx].sg_font != NOFONT) | |
7668 { | |
7669 /* New font was accepted. Free the old one, if there was | |
3881 | 7670 * one. */ |
7 | 7671 gui_mch_free_font(temp_sg_font); |
7672 vim_free(HL_TABLE()[idx].sg_font_name); | |
7673 HL_TABLE()[idx].sg_font_name = vim_strsave(arg); | |
7674 } | |
7675 else | |
7676 HL_TABLE()[idx].sg_font = temp_sg_font; | |
7677 } | |
7678 #endif | |
7679 } | |
7680 else if (STRCMP(key, "CTERMFG") == 0 || STRCMP(key, "CTERMBG") == 0) | |
7681 { | |
7682 if (!init || !(HL_TABLE()[idx].sg_set & SG_CTERM)) | |
7683 { | |
7684 if (!init) | |
7685 HL_TABLE()[idx].sg_set |= SG_CTERM; | |
7686 | |
7687 /* When setting the foreground color, and previously the "bold" | |
7688 * flag was set for a light color, reset it now */ | |
7689 if (key[5] == 'F' && HL_TABLE()[idx].sg_cterm_bold) | |
7690 { | |
7691 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7692 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
7693 } | |
7694 | |
7695 if (VIM_ISDIGIT(*arg)) | |
7696 color = atoi((char *)arg); | |
7697 else if (STRICMP(arg, "fg") == 0) | |
7698 { | |
7699 if (cterm_normal_fg_color) | |
7700 color = cterm_normal_fg_color - 1; | |
7701 else | |
7702 { | |
7703 EMSG(_("E419: FG color unknown")); | |
7704 error = TRUE; | |
7705 break; | |
7706 } | |
7707 } | |
7708 else if (STRICMP(arg, "bg") == 0) | |
7709 { | |
7710 if (cterm_normal_bg_color > 0) | |
7711 color = cterm_normal_bg_color - 1; | |
7712 else | |
7713 { | |
7714 EMSG(_("E420: BG color unknown")); | |
7715 error = TRUE; | |
7716 break; | |
7717 } | |
7718 } | |
7719 else | |
7720 { | |
7721 static char *(color_names[28]) = { | |
7722 "Black", "DarkBlue", "DarkGreen", "DarkCyan", | |
7723 "DarkRed", "DarkMagenta", "Brown", "DarkYellow", | |
7724 "Gray", "Grey", | |
7725 "LightGray", "LightGrey", "DarkGray", "DarkGrey", | |
7726 "Blue", "LightBlue", "Green", "LightGreen", | |
7727 "Cyan", "LightCyan", "Red", "LightRed", "Magenta", | |
7728 "LightMagenta", "Yellow", "LightYellow", "White", "NONE"}; | |
7729 static int color_numbers_16[28] = {0, 1, 2, 3, | |
7730 4, 5, 6, 6, | |
7731 7, 7, | |
7732 7, 7, 8, 8, | |
7733 9, 9, 10, 10, | |
7734 11, 11, 12, 12, 13, | |
7735 13, 14, 14, 15, -1}; | |
7736 /* for xterm with 88 colors... */ | |
7737 static int color_numbers_88[28] = {0, 4, 2, 6, | |
7738 1, 5, 32, 72, | |
7739 84, 84, | |
7740 7, 7, 82, 82, | |
7741 12, 43, 10, 61, | |
7742 14, 63, 9, 74, 13, | |
7743 75, 11, 78, 15, -1}; | |
7744 /* for xterm with 256 colors... */ | |
7745 static int color_numbers_256[28] = {0, 4, 2, 6, | |
7746 1, 5, 130, 130, | |
7747 248, 248, | |
7748 7, 7, 242, 242, | |
7749 12, 81, 10, 121, | |
7750 14, 159, 9, 224, 13, | |
7751 225, 11, 229, 15, -1}; | |
7752 /* for terminals with less than 16 colors... */ | |
7753 static int color_numbers_8[28] = {0, 4, 2, 6, | |
7754 1, 5, 3, 3, | |
7755 7, 7, | |
7756 7, 7, 0+8, 0+8, | |
7757 4+8, 4+8, 2+8, 2+8, | |
7758 6+8, 6+8, 1+8, 1+8, 5+8, | |
7759 5+8, 3+8, 3+8, 7+8, -1}; | |
7760 #if defined(__QNXNTO__) | |
7761 static int *color_numbers_8_qansi = color_numbers_8; | |
7762 /* On qnx, the 8 & 16 color arrays are the same */ | |
7763 if (STRNCMP(T_NAME, "qansi", 5) == 0) | |
7764 color_numbers_8_qansi = color_numbers_16; | |
7765 #endif | |
7766 | |
7767 /* reduce calls to STRICMP a bit, it can be slow */ | |
7768 off = TOUPPER_ASC(*arg); | |
7769 for (i = (sizeof(color_names) / sizeof(char *)); --i >= 0; ) | |
7770 if (off == color_names[i][0] | |
7771 && STRICMP(arg + 1, color_names[i] + 1) == 0) | |
7772 break; | |
7773 if (i < 0) | |
7774 { | |
7775 EMSG2(_("E421: Color name or number not recognized: %s"), key_start); | |
7776 error = TRUE; | |
7777 break; | |
7778 } | |
7779 | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
7780 /* Use the _16 table to check if it's a valid color name. */ |
7 | 7781 color = color_numbers_16[i]; |
7782 if (color >= 0) | |
7783 { | |
7784 if (t_colors == 8) | |
7785 { | |
7786 /* t_Co is 8: use the 8 colors table */ | |
7787 #if defined(__QNXNTO__) | |
7788 color = color_numbers_8_qansi[i]; | |
7789 #else | |
7790 color = color_numbers_8[i]; | |
7791 #endif | |
7792 if (key[5] == 'F') | |
7793 { | |
7794 /* set/reset bold attribute to get light foreground | |
7795 * colors (on some terminals, e.g. "linux") */ | |
7796 if (color & 8) | |
7797 { | |
7798 HL_TABLE()[idx].sg_cterm |= HL_BOLD; | |
7799 HL_TABLE()[idx].sg_cterm_bold = TRUE; | |
7800 } | |
7801 else | |
7802 HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; | |
7803 } | |
7804 color &= 7; /* truncate to 8 colors */ | |
7805 } | |
7806 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
|
7807 || t_colors >= 256) |
7 | 7808 { |
7809 /* | |
7810 * Guess: if the termcap entry ends in 'm', it is | |
7811 * probably an xterm-like terminal. Use the changed | |
7812 * order for colors. | |
7813 */ | |
7814 if (*T_CAF != NUL) | |
7815 p = T_CAF; | |
7816 else | |
7817 p = T_CSF; | |
7467
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7818 if (*p != NUL && (t_colors > 256 |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7819 || *(p + STRLEN(p) - 1) == 'm')) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7820 { |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7821 if (t_colors == 88) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7822 color = color_numbers_88[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7823 else if (t_colors >= 256) |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7824 color = color_numbers_256[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7825 else |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7826 color = color_numbers_8[i]; |
765110dd332c
commit https://github.com/vim/vim/commit/fa03fd6c4a9fe05274d62ddefd645cb5801d2023
Christian Brabandt <cb@256bit.org>
parents:
7030
diff
changeset
|
7827 } |
7 | 7828 } |
7829 } | |
7830 } | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7831 /* 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
|
7832 * "NONE", then "color" is -1. */ |
7 | 7833 if (key[5] == 'F') |
7834 { | |
7835 HL_TABLE()[idx].sg_cterm_fg = color + 1; | |
7836 if (is_normal_group) | |
7837 { | |
7838 cterm_normal_fg_color = color + 1; | |
7839 cterm_normal_fg_bold = (HL_TABLE()[idx].sg_cterm & HL_BOLD); | |
7840 #ifdef FEAT_GUI | |
7841 /* Don't do this if the GUI is used. */ | |
7842 if (!gui.in_use && !gui.starting) | |
7843 #endif | |
7844 { | |
7845 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7846 if (termcap_active && color >= 0) |
7 | 7847 term_fg_color(color); |
7848 } | |
7849 } | |
7850 } | |
7851 else | |
7852 { | |
7853 HL_TABLE()[idx].sg_cterm_bg = color + 1; | |
7854 if (is_normal_group) | |
7855 { | |
7856 cterm_normal_bg_color = color + 1; | |
7857 #ifdef FEAT_GUI | |
7858 /* Don't mess with 'background' if the GUI is used. */ | |
7859 if (!gui.in_use && !gui.starting) | |
7860 #endif | |
7861 { | |
7862 must_redraw = CLEAR; | |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7863 if (color >= 0) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7864 { |
11465
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7865 int dark = -1; |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7866 |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7867 if (termcap_active) |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7868 term_bg_color(color); |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7869 if (t_colors < 16) |
11465
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7870 dark = (color == 0 || color == 4); |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7871 /* Limit the heuristic to the standard 16 colors */ |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7872 else if (color < 16) |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7873 dark = (color < 7 || color == 8); |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7874 /* Set the 'background' option if the value is |
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7875 * wrong. */ |
11465
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7876 if (dark != -1 |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7877 && dark != (*p_bg == 'd') |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7878 && !option_was_set((char_u *)"bg")) |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7879 { |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7880 set_option_value((char_u *)"bg", 0L, |
11465
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7881 (char_u *)(dark ? "dark" : "light"), 0); |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7882 reset_option_was_set((char_u *)"bg"); |
7cbcba782c4e
patch 8.0.0616: not always setting 'background' correctly after :hi Normal
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
7883 } |
2136
431ebc9412a8
updated for version 7.2.418
Bram Moolenaar <bram@zimbu.org>
parents:
2123
diff
changeset
|
7884 } |
7 | 7885 } |
7886 } | |
7887 } | |
7888 } | |
7889 } | |
7890 else if (STRCMP(key, "GUIFG") == 0) | |
7891 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7892 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7893 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7894 { |
205 | 7895 if (!init) |
7896 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7897 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7898 # 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
|
7899 /* In GUI guifg colors are only used when recognized */ |
205 | 7900 i = color_name2handle(arg); |
9029
f06767547415
commit https://github.com/vim/vim/commit/631225627d448b591e529a5d3e7ac74ef44b8459
Christian Brabandt <cb@256bit.org>
parents:
9027
diff
changeset
|
7901 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) |
205 | 7902 { |
7903 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
|
7904 # endif |
205 | 7905 vim_free(HL_TABLE()[idx].sg_gui_fg_name); |
7906 if (STRCMP(arg, "NONE")) | |
7907 HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg); | |
7908 else | |
7909 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
|
7910 # 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
|
7911 # ifdef FEAT_GUI_X11 |
205 | 7912 if (is_menu_group) |
7913 gui.menu_fg_pixel = i; | |
7914 if (is_scrollbar_group) | |
7915 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
|
7916 # ifdef FEAT_BEVAL |
205 | 7917 if (is_tooltip_group) |
7918 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
|
7919 # endif |
205 | 7920 do_colors = TRUE; |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7921 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7922 } |
7 | 7923 # endif |
7924 } | |
7925 #endif | |
7926 } | |
7927 else if (STRCMP(key, "GUIBG") == 0) | |
7928 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7929 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7930 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7 | 7931 { |
205 | 7932 if (!init) |
7933 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7934 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
7935 # 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
|
7936 /* In GUI guifg colors are only used when recognized */ |
205 | 7937 i = color_name2handle(arg); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
7938 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !USE_24BIT) |
205 | 7939 { |
7940 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
|
7941 # endif |
205 | 7942 vim_free(HL_TABLE()[idx].sg_gui_bg_name); |
7943 if (STRCMP(arg, "NONE") != 0) | |
7944 HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg); | |
7945 else | |
7946 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
|
7947 # 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
|
7948 # ifdef FEAT_GUI_X11 |
205 | 7949 if (is_menu_group) |
7950 gui.menu_bg_pixel = i; | |
7951 if (is_scrollbar_group) | |
7952 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
|
7953 # ifdef FEAT_BEVAL |
205 | 7954 if (is_tooltip_group) |
7955 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
|
7956 # endif |
205 | 7957 do_colors = TRUE; |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7958 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7959 } |
7 | 7960 # endif |
7961 } | |
205 | 7962 #endif |
7963 } | |
7964 else if (STRCMP(key, "GUISP") == 0) | |
7965 { | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7966 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
205 | 7967 if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) |
7968 { | |
7969 if (!init) | |
7970 HL_TABLE()[idx].sg_set |= SG_GUI; | |
7971 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7972 # ifdef FEAT_GUI |
205 | 7973 i = color_name2handle(arg); |
7974 if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) | |
7975 { | |
7976 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
|
7977 # endif |
205 | 7978 vim_free(HL_TABLE()[idx].sg_gui_sp_name); |
7979 if (STRCMP(arg, "NONE") != 0) | |
7980 HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg); | |
7981 else | |
7982 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
|
7983 # ifdef FEAT_GUI |
205 | 7984 } |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
7985 # endif |
205 | 7986 } |
7 | 7987 #endif |
7988 } | |
7989 else if (STRCMP(key, "START") == 0 || STRCMP(key, "STOP") == 0) | |
7990 { | |
7991 char_u buf[100]; | |
7992 char_u *tname; | |
7993 | |
7994 if (!init) | |
7995 HL_TABLE()[idx].sg_set |= SG_TERM; | |
7996 | |
7997 /* | |
7998 * The "start" and "stop" arguments can be a literal escape | |
1222 | 7999 * sequence, or a comma separated list of terminal codes. |
7 | 8000 */ |
8001 if (STRNCMP(arg, "t_", 2) == 0) | |
8002 { | |
8003 off = 0; | |
8004 buf[0] = 0; | |
8005 while (arg[off] != NUL) | |
8006 { | |
8007 /* Isolate one termcap name */ | |
8008 for (len = 0; arg[off + len] && | |
8009 arg[off + len] != ','; ++len) | |
8010 ; | |
8011 tname = vim_strnsave(arg + off, len); | |
8012 if (tname == NULL) /* out of memory */ | |
8013 { | |
8014 error = TRUE; | |
8015 break; | |
8016 } | |
8017 /* lookup the escape sequence for the item */ | |
8018 p = get_term_code(tname); | |
8019 vim_free(tname); | |
8020 if (p == NULL) /* ignore non-existing things */ | |
8021 p = (char_u *)""; | |
8022 | |
8023 /* Append it to the already found stuff */ | |
8024 if ((int)(STRLEN(buf) + STRLEN(p)) >= 99) | |
8025 { | |
8026 EMSG2(_("E422: terminal code too long: %s"), arg); | |
8027 error = TRUE; | |
8028 break; | |
8029 } | |
8030 STRCAT(buf, p); | |
8031 | |
8032 /* Advance to the next item */ | |
8033 off += len; | |
8034 if (arg[off] == ',') /* another one follows */ | |
8035 ++off; | |
8036 } | |
8037 } | |
8038 else | |
8039 { | |
8040 /* | |
8041 * Copy characters from arg[] to buf[], translating <> codes. | |
8042 */ | |
2593 | 8043 for (p = arg, off = 0; off < 100 - 6 && *p; ) |
7 | 8044 { |
9869
989d44d35a66
commit https://github.com/vim/vim/commit/35a4cfa200917dd171b1fff3cd5b6cee9add673d
Christian Brabandt <cb@256bit.org>
parents:
9141
diff
changeset
|
8045 len = trans_special(&p, buf + off, FALSE, FALSE); |
2593 | 8046 if (len > 0) /* recognized special char */ |
7 | 8047 off += len; |
8048 else /* copy as normal char */ | |
8049 buf[off++] = *p++; | |
8050 } | |
8051 buf[off] = NUL; | |
8052 } | |
8053 if (error) | |
8054 break; | |
8055 | |
8056 if (STRCMP(buf, "NONE") == 0) /* resetting the value */ | |
8057 p = NULL; | |
8058 else | |
8059 p = vim_strsave(buf); | |
8060 if (key[2] == 'A') | |
8061 { | |
8062 vim_free(HL_TABLE()[idx].sg_start); | |
8063 HL_TABLE()[idx].sg_start = p; | |
8064 } | |
8065 else | |
8066 { | |
8067 vim_free(HL_TABLE()[idx].sg_stop); | |
8068 HL_TABLE()[idx].sg_stop = p; | |
8069 } | |
8070 } | |
8071 else | |
8072 { | |
8073 EMSG2(_("E423: Illegal argument: %s"), key_start); | |
8074 error = TRUE; | |
8075 break; | |
8076 } | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8077 HL_TABLE()[idx].sg_cleared = FALSE; |
7 | 8078 |
8079 /* | |
8080 * When highlighting has been given for a group, don't link it. | |
8081 */ | |
8082 if (!init || !(HL_TABLE()[idx].sg_set & SG_LINK)) | |
8083 HL_TABLE()[idx].sg_link = 0; | |
8084 | |
8085 /* | |
8086 * Continue with next argument. | |
8087 */ | |
8088 linep = skipwhite(linep); | |
8089 } | |
8090 | |
8091 /* | |
8092 * If there is an error, and it's a new entry, remove it from the table. | |
8093 */ | |
8094 if (error && idx == highlight_ga.ga_len) | |
8095 syn_unadd_group(); | |
8096 else | |
8097 { | |
8098 if (is_normal_group) | |
8099 { | |
8100 HL_TABLE()[idx].sg_term_attr = 0; | |
8101 HL_TABLE()[idx].sg_cterm_attr = 0; | |
8102 #ifdef FEAT_GUI | |
8103 HL_TABLE()[idx].sg_gui_attr = 0; | |
8104 /* | |
8105 * Need to update all groups, because they might be using "bg" | |
8106 * and/or "fg", which have been changed now. | |
8107 */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8108 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8109 #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
|
8110 if (USE_24BIT) |
7 | 8111 highlight_gui_started(); |
8112 #endif | |
8113 } | |
8114 #ifdef FEAT_GUI_X11 | |
8115 # ifdef FEAT_MENU | |
8116 else if (is_menu_group) | |
8117 { | |
8118 if (gui.in_use && do_colors) | |
8119 gui_mch_new_menu_colors(); | |
8120 } | |
8121 # endif | |
8122 else if (is_scrollbar_group) | |
8123 { | |
8124 if (gui.in_use && do_colors) | |
8125 gui_new_scrollbar_colors(); | |
8126 } | |
8127 # ifdef FEAT_BEVAL | |
8128 else if (is_tooltip_group) | |
8129 { | |
8130 if (gui.in_use && do_colors) | |
8131 gui_mch_new_tooltip_colors(); | |
8132 } | |
8133 # endif | |
8134 #endif | |
8135 else | |
8136 set_hl_attr(idx); | |
448 | 8137 #ifdef FEAT_EVAL |
8138 HL_TABLE()[idx].sg_scriptID = current_SID; | |
8139 #endif | |
819 | 8140 redraw_all_later(NOT_VALID); |
7 | 8141 } |
8142 vim_free(key); | |
8143 vim_free(arg); | |
8144 | |
8145 /* Only call highlight_changed() once, after sourcing a syntax file */ | |
8146 need_highlight_changed = TRUE; | |
8147 } | |
8148 | |
356 | 8149 #if defined(EXITFREE) || defined(PROTO) |
8150 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8151 free_highlight(void) |
356 | 8152 { |
8153 int i; | |
8154 | |
8155 for (i = 0; i < highlight_ga.ga_len; ++i) | |
359 | 8156 { |
356 | 8157 highlight_clear(i); |
359 | 8158 vim_free(HL_TABLE()[i].sg_name); |
8159 vim_free(HL_TABLE()[i].sg_name_u); | |
8160 } | |
356 | 8161 ga_clear(&highlight_ga); |
8162 } | |
8163 #endif | |
8164 | |
7 | 8165 /* |
8166 * Reset the cterm colors to what they were before Vim was started, if | |
8167 * possible. Otherwise reset them to zero. | |
8168 */ | |
8169 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8170 restore_cterm_colors(void) |
7 | 8171 { |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
8172 #if defined(WIN3264) && !defined(FEAT_GUI_W32) |
7 | 8173 /* Since t_me has been set, this probably means that the user |
8174 * wants to use this as default colors. Need to reset default | |
8175 * background/foreground colors. */ | |
8176 mch_set_normal_colors(); | |
8177 #else | |
8178 cterm_normal_fg_color = 0; | |
8179 cterm_normal_fg_bold = 0; | |
8180 cterm_normal_bg_color = 0; | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8181 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8182 cterm_normal_fg_gui_color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8183 cterm_normal_bg_gui_color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8184 # endif |
7 | 8185 #endif |
8186 } | |
8187 | |
8188 /* | |
8189 * Return TRUE if highlight group "idx" has any settings. | |
8190 * When "check_link" is TRUE also check for an existing link. | |
8191 */ | |
8192 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8193 hl_has_settings(int idx, int check_link) |
7 | 8194 { |
8195 return ( HL_TABLE()[idx].sg_term_attr != 0 | |
8196 || HL_TABLE()[idx].sg_cterm_attr != 0 | |
5954 | 8197 || HL_TABLE()[idx].sg_cterm_fg != 0 |
8198 || HL_TABLE()[idx].sg_cterm_bg != 0 | |
7 | 8199 #ifdef FEAT_GUI |
8200 || HL_TABLE()[idx].sg_gui_attr != 0 | |
5954 | 8201 || HL_TABLE()[idx].sg_gui_fg_name != NULL |
8202 || HL_TABLE()[idx].sg_gui_bg_name != NULL | |
8203 || HL_TABLE()[idx].sg_gui_sp_name != NULL | |
11119
d8a550329a97
patch 8.0.0447: getting font name does not work on X11
Christian Brabandt <cb@256bit.org>
parents:
11073
diff
changeset
|
8204 || HL_TABLE()[idx].sg_font_name != NULL |
7 | 8205 #endif |
8206 || (check_link && (HL_TABLE()[idx].sg_set & SG_LINK))); | |
8207 } | |
8208 | |
8209 /* | |
8210 * Clear highlighting for one group. | |
8211 */ | |
8212 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8213 highlight_clear(int idx) |
7 | 8214 { |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
8215 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
|
8216 |
7 | 8217 HL_TABLE()[idx].sg_term = 0; |
8218 vim_free(HL_TABLE()[idx].sg_start); | |
8219 HL_TABLE()[idx].sg_start = NULL; | |
8220 vim_free(HL_TABLE()[idx].sg_stop); | |
8221 HL_TABLE()[idx].sg_stop = NULL; | |
8222 HL_TABLE()[idx].sg_term_attr = 0; | |
8223 HL_TABLE()[idx].sg_cterm = 0; | |
8224 HL_TABLE()[idx].sg_cterm_bold = FALSE; | |
8225 HL_TABLE()[idx].sg_cterm_fg = 0; | |
8226 HL_TABLE()[idx].sg_cterm_bg = 0; | |
8227 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
|
8228 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 8229 HL_TABLE()[idx].sg_gui = 0; |
8230 vim_free(HL_TABLE()[idx].sg_gui_fg_name); | |
8231 HL_TABLE()[idx].sg_gui_fg_name = NULL; | |
8232 vim_free(HL_TABLE()[idx].sg_gui_bg_name); | |
8233 HL_TABLE()[idx].sg_gui_bg_name = NULL; | |
205 | 8234 vim_free(HL_TABLE()[idx].sg_gui_sp_name); |
8235 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
|
8236 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8237 #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
|
8238 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
|
8239 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
|
8240 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8241 #ifdef FEAT_GUI |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
8242 HL_TABLE()[idx].sg_gui_sp = INVALCOLOR; |
7 | 8243 gui_mch_free_font(HL_TABLE()[idx].sg_font); |
8244 HL_TABLE()[idx].sg_font = NOFONT; | |
8245 # ifdef FEAT_XFONTSET | |
8246 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
8247 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
8248 # endif | |
8249 vim_free(HL_TABLE()[idx].sg_font_name); | |
8250 HL_TABLE()[idx].sg_font_name = NULL; | |
8251 HL_TABLE()[idx].sg_gui_attr = 0; | |
8252 #endif | |
448 | 8253 #ifdef FEAT_EVAL |
8254 /* Clear the script ID only when there is no link, since that is not | |
8255 * cleared. */ | |
8256 if (HL_TABLE()[idx].sg_link == 0) | |
8257 HL_TABLE()[idx].sg_scriptID = 0; | |
8258 #endif | |
7 | 8259 } |
8260 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8261 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
7 | 8262 /* |
8263 * Set the normal foreground and background colors according to the "Normal" | |
2020 | 8264 * highlighting group. For X11 also set "Menu", "Scrollbar", and |
7 | 8265 * "Tooltip" colors. |
8266 */ | |
8267 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8268 set_normal_colors(void) |
7 | 8269 { |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8270 #ifdef FEAT_GUI |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8271 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8272 if (gui.in_use) |
7 | 8273 # endif |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8274 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8275 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
|
8276 &gui.norm_pixel, &gui.back_pixel, |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8277 FALSE, TRUE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8278 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8279 gui_mch_new_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8280 must_redraw = CLEAR; |
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 # ifdef FEAT_GUI_X11 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8283 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
|
8284 &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
|
8285 TRUE, FALSE, FALSE)) |
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 # ifdef FEAT_MENU |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8288 gui_mch_new_menu_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8289 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8290 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8291 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8292 # ifdef FEAT_BEVAL |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8293 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
|
8294 &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
|
8295 FALSE, FALSE, TRUE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8296 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8297 # ifdef FEAT_TOOLBAR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8298 gui_mch_new_tooltip_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8299 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8300 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8301 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8302 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8303 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
|
8304 &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
|
8305 FALSE, FALSE, FALSE)) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8306 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8307 gui_new_scrollbar_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8308 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8309 } |
7 | 8310 # endif |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8311 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8312 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8313 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8314 # ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8315 else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8316 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8317 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8318 int idx; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8319 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8320 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
|
8321 if (idx >= 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8322 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8323 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
|
8324 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8325 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
|
8326 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8327 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
|
8328 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8329 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8330 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
|
8331 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8332 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
|
8333 must_redraw = CLEAR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8334 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8335 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8336 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8337 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8338 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8339 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8340 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8341 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 8342 /* |
8343 * Set the colors for "Normal", "Menu", "Tooltip" or "Scrollbar". | |
8344 */ | |
8345 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8346 set_group_colors( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8347 char_u *name, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8348 guicolor_T *fgp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8349 guicolor_T *bgp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8350 int do_menu, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8351 int use_norm, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8352 int do_tooltip) |
7 | 8353 { |
8354 int idx; | |
8355 | |
8356 idx = syn_name2id(name) - 1; | |
8357 if (idx >= 0) | |
8358 { | |
8359 gui_do_one_color(idx, do_menu, do_tooltip); | |
8360 | |
8361 if (HL_TABLE()[idx].sg_gui_fg != INVALCOLOR) | |
8362 *fgp = HL_TABLE()[idx].sg_gui_fg; | |
8363 else if (use_norm) | |
8364 *fgp = gui.def_norm_pixel; | |
8365 if (HL_TABLE()[idx].sg_gui_bg != INVALCOLOR) | |
8366 *bgp = HL_TABLE()[idx].sg_gui_bg; | |
8367 else if (use_norm) | |
8368 *bgp = gui.def_back_pixel; | |
8369 return TRUE; | |
8370 } | |
8371 return FALSE; | |
8372 } | |
8373 | |
8374 /* | |
8375 * Get the font of the "Normal" group. | |
8376 * Returns "" when it's not found or not set. | |
8377 */ | |
8378 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8379 hl_get_font_name(void) |
7 | 8380 { |
8381 int id; | |
8382 char_u *s; | |
8383 | |
8384 id = syn_name2id((char_u *)"Normal"); | |
8385 if (id > 0) | |
8386 { | |
8387 s = HL_TABLE()[id - 1].sg_font_name; | |
8388 if (s != NULL) | |
8389 return s; | |
8390 } | |
8391 return (char_u *)""; | |
8392 } | |
8393 | |
8394 /* | |
8395 * Set font for "Normal" group. Called by gui_mch_init_font() when a font has | |
8396 * actually chosen to be used. | |
8397 */ | |
8398 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8399 hl_set_font_name(char_u *font_name) |
7 | 8400 { |
8401 int id; | |
8402 | |
8403 id = syn_name2id((char_u *)"Normal"); | |
8404 if (id > 0) | |
8405 { | |
8406 vim_free(HL_TABLE()[id - 1].sg_font_name); | |
8407 HL_TABLE()[id - 1].sg_font_name = vim_strsave(font_name); | |
8408 } | |
8409 } | |
8410 | |
8411 /* | |
8412 * Set background color for "Normal" group. Called by gui_set_bg_color() | |
8413 * when the color is known. | |
8414 */ | |
8415 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8416 hl_set_bg_color_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8417 char_u *name) /* must have been allocated */ |
7 | 8418 { |
8419 int id; | |
8420 | |
8421 if (name != NULL) | |
8422 { | |
8423 id = syn_name2id((char_u *)"Normal"); | |
8424 if (id > 0) | |
8425 { | |
8426 vim_free(HL_TABLE()[id - 1].sg_gui_bg_name); | |
8427 HL_TABLE()[id - 1].sg_gui_bg_name = name; | |
8428 } | |
8429 } | |
8430 } | |
8431 | |
8432 /* | |
8433 * Set foreground color for "Normal" group. Called by gui_set_fg_color() | |
8434 * when the color is known. | |
8435 */ | |
8436 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8437 hl_set_fg_color_name( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8438 char_u *name) /* must have been allocated */ |
7 | 8439 { |
8440 int id; | |
8441 | |
8442 if (name != NULL) | |
8443 { | |
8444 id = syn_name2id((char_u *)"Normal"); | |
8445 if (id > 0) | |
8446 { | |
8447 vim_free(HL_TABLE()[id - 1].sg_gui_fg_name); | |
8448 HL_TABLE()[id - 1].sg_gui_fg_name = name; | |
8449 } | |
8450 } | |
8451 } | |
8452 | |
8453 /* | |
8454 * Return the handle for a font name. | |
8455 * Returns NOFONT when failed. | |
8456 */ | |
8457 static GuiFont | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8458 font_name2handle(char_u *name) |
7 | 8459 { |
8460 if (STRCMP(name, "NONE") == 0) | |
8461 return NOFONT; | |
8462 | |
8463 return gui_mch_get_font(name, TRUE); | |
8464 } | |
8465 | |
8466 # ifdef FEAT_XFONTSET | |
8467 /* | |
8468 * Return the handle for a fontset name. | |
8469 * Returns NOFONTSET when failed. | |
8470 */ | |
8471 static GuiFontset | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8472 fontset_name2handle(char_u *name, int fixed_width) |
7 | 8473 { |
8474 if (STRCMP(name, "NONE") == 0) | |
8475 return NOFONTSET; | |
8476 | |
8477 return gui_mch_get_fontset(name, TRUE, fixed_width); | |
8478 } | |
8479 # endif | |
8480 | |
8481 /* | |
8482 * Get the font or fontset for one highlight group. | |
8483 */ | |
8484 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8485 hl_do_font( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8486 int idx, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8487 char_u *arg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8488 int do_normal, /* set normal font */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8489 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
|
8490 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
|
8491 int free_font) /* free current font/fontset */ |
7 | 8492 { |
8493 # ifdef FEAT_XFONTSET | |
8494 /* If 'guifontset' is not empty, first try using the name as a | |
8495 * fontset. If that doesn't work, use it as a font name. */ | |
8496 if (*p_guifontset != NUL | |
8497 # ifdef FONTSET_ALWAYS | |
8498 || do_menu | |
8499 # endif | |
8500 # ifdef FEAT_BEVAL_TIP | |
8501 /* In Athena & Motif, the Tooltip highlight group is always a fontset */ | |
8502 || do_tooltip | |
8503 # endif | |
8504 ) | |
4344 | 8505 { |
3900 | 8506 if (free_font) |
3881 | 8507 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); |
7 | 8508 HL_TABLE()[idx].sg_fontset = fontset_name2handle(arg, 0 |
8509 # ifdef FONTSET_ALWAYS | |
8510 || do_menu | |
8511 # endif | |
8512 # ifdef FEAT_BEVAL_TIP | |
8513 || do_tooltip | |
8514 # endif | |
8515 ); | |
4344 | 8516 } |
7 | 8517 if (HL_TABLE()[idx].sg_fontset != NOFONTSET) |
8518 { | |
3881 | 8519 /* If it worked and it's the Normal group, use it as the normal |
8520 * fontset. Same for the Menu group. */ | |
7 | 8521 if (do_normal) |
8522 gui_init_font(arg, TRUE); | |
8523 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8524 if (do_menu) | |
8525 { | |
8526 # ifdef FONTSET_ALWAYS | |
8527 gui.menu_fontset = HL_TABLE()[idx].sg_fontset; | |
8528 # else | |
8529 /* YIKES! This is a bug waiting to crash the program */ | |
8530 gui.menu_font = HL_TABLE()[idx].sg_fontset; | |
8531 # endif | |
8532 gui_mch_new_menu_font(); | |
8533 } | |
8534 # ifdef FEAT_BEVAL | |
8535 if (do_tooltip) | |
8536 { | |
8537 /* The Athena widget set cannot currently handle switching between | |
8538 * displaying a single font and a fontset. | |
8539 * If the XtNinternational resource is set to True at widget | |
1222 | 8540 * creation, then a fontset is always used, otherwise an |
7 | 8541 * XFontStruct is used. |
8542 */ | |
8543 gui.tooltip_fontset = (XFontSet)HL_TABLE()[idx].sg_fontset; | |
8544 gui_mch_new_tooltip_font(); | |
8545 } | |
8546 # endif | |
8547 # endif | |
8548 } | |
8549 else | |
8550 # endif | |
8551 { | |
3881 | 8552 if (free_font) |
8553 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
7 | 8554 HL_TABLE()[idx].sg_font = font_name2handle(arg); |
8555 /* If it worked and it's the Normal group, use it as the | |
8556 * normal font. Same for the Menu group. */ | |
8557 if (HL_TABLE()[idx].sg_font != NOFONT) | |
8558 { | |
8559 if (do_normal) | |
8560 gui_init_font(arg, FALSE); | |
8561 #ifndef FONTSET_ALWAYS | |
8562 # if (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) && defined(FEAT_MENU) | |
8563 if (do_menu) | |
8564 { | |
8565 gui.menu_font = HL_TABLE()[idx].sg_font; | |
8566 gui_mch_new_menu_font(); | |
8567 } | |
8568 # endif | |
8569 #endif | |
8570 } | |
8571 } | |
8572 } | |
8573 | |
8574 #endif /* FEAT_GUI */ | |
8575 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8576 #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
|
8577 /* |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8578 * 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
|
8579 * Returns INVALCOLOR when failed. |
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 static guicolor_T |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8582 color_name2handle(char_u *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 if (STRCMP(name, "NONE") == 0) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8585 return INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8586 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8587 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
|
8588 { |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8589 #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
|
8590 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8591 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8592 #ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8593 return gui.norm_pixel; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8594 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8595 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8596 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
|
8597 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
|
8598 /* 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
|
8599 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
|
8600 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8601 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8602 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
|
8603 { |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8604 #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
|
8605 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8606 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8607 #ifdef FEAT_GUI |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8608 return gui.back_pixel; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8609 #endif |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
8610 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8611 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
|
8612 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
|
8613 /* 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
|
8614 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
|
8615 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8616 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8617 |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8618 return GUI_GET_COLOR(name); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8619 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8620 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8621 |
7 | 8622 /* |
8623 * Table with the specifications for an attribute number. | |
8624 * Note that this table is used by ALL buffers. This is required because the | |
8625 * GUI can redraw at any time for any buffer. | |
8626 */ | |
298 | 8627 static garray_T term_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8628 |
8629 #define TERM_ATTR_ENTRY(idx) ((attrentry_T *)term_attr_table.ga_data)[idx] | |
8630 | |
298 | 8631 static garray_T cterm_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8632 |
8633 #define CTERM_ATTR_ENTRY(idx) ((attrentry_T *)cterm_attr_table.ga_data)[idx] | |
8634 | |
8635 #ifdef FEAT_GUI | |
298 | 8636 static garray_T gui_attr_table = {0, 0, 0, 0, NULL}; |
7 | 8637 |
8638 #define GUI_ATTR_ENTRY(idx) ((attrentry_T *)gui_attr_table.ga_data)[idx] | |
8639 #endif | |
8640 | |
8641 /* | |
8642 * Return the attr number for a set of colors and font. | |
8643 * Add a new entry to the term_attr_table, cterm_attr_table or gui_attr_table | |
8644 * if the combination is new. | |
8645 * Return 0 for error (no more room). | |
8646 */ | |
8647 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8648 get_attr_entry(garray_T *table, attrentry_T *aep) |
7 | 8649 { |
8650 int i; | |
359 | 8651 attrentry_T *taep; |
7 | 8652 static int recursive = FALSE; |
8653 | |
8654 /* | |
8655 * Init the table, in case it wasn't done yet. | |
8656 */ | |
8657 table->ga_itemsize = sizeof(attrentry_T); | |
8658 table->ga_growsize = 7; | |
8659 | |
8660 /* | |
8661 * Try to find an entry with the same specifications. | |
8662 */ | |
8663 for (i = 0; i < table->ga_len; ++i) | |
8664 { | |
359 | 8665 taep = &(((attrentry_T *)table->ga_data)[i]); |
8666 if ( aep->ae_attr == taep->ae_attr | |
7 | 8667 && ( |
8668 #ifdef FEAT_GUI | |
8669 (table == &gui_attr_table | |
359 | 8670 && (aep->ae_u.gui.fg_color == taep->ae_u.gui.fg_color |
8671 && aep->ae_u.gui.bg_color | |
8672 == taep->ae_u.gui.bg_color | |
8673 && aep->ae_u.gui.sp_color | |
8674 == taep->ae_u.gui.sp_color | |
8675 && aep->ae_u.gui.font == taep->ae_u.gui.font | |
7 | 8676 # ifdef FEAT_XFONTSET |
359 | 8677 && aep->ae_u.gui.fontset == taep->ae_u.gui.fontset |
7 | 8678 # endif |
8679 )) | |
8680 || | |
8681 #endif | |
8682 (table == &term_attr_table | |
359 | 8683 && (aep->ae_u.term.start == NULL) |
8684 == (taep->ae_u.term.start == NULL) | |
7 | 8685 && (aep->ae_u.term.start == NULL |
8686 || STRCMP(aep->ae_u.term.start, | |
359 | 8687 taep->ae_u.term.start) == 0) |
8688 && (aep->ae_u.term.stop == NULL) | |
8689 == (taep->ae_u.term.stop == NULL) | |
7 | 8690 && (aep->ae_u.term.stop == NULL |
8691 || STRCMP(aep->ae_u.term.stop, | |
359 | 8692 taep->ae_u.term.stop) == 0)) |
7 | 8693 || (table == &cterm_attr_table |
359 | 8694 && aep->ae_u.cterm.fg_color |
8695 == taep->ae_u.cterm.fg_color | |
8696 && 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
|
8697 == 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
|
8698 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8699 && aep->ae_u.cterm.fg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8700 == taep->ae_u.cterm.fg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8701 && aep->ae_u.cterm.bg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8702 == taep->ae_u.cterm.bg_rgb |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8703 #endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8704 ))) |
7 | 8705 |
8706 return i + ATTR_OFF; | |
8707 } | |
8708 | |
271 | 8709 if (table->ga_len + ATTR_OFF > MAX_TYPENR) |
7 | 8710 { |
8711 /* | |
8712 * Running out of attribute entries! remove all attributes, and | |
8713 * compute new ones for all groups. | |
8714 * When called recursively, we are really out of numbers. | |
8715 */ | |
8716 if (recursive) | |
8717 { | |
8718 EMSG(_("E424: Too many different highlighting attributes in use")); | |
8719 return 0; | |
8720 } | |
8721 recursive = TRUE; | |
8722 | |
359 | 8723 clear_hl_tables(); |
8724 | |
7 | 8725 must_redraw = CLEAR; |
8726 | |
8727 for (i = 0; i < highlight_ga.ga_len; ++i) | |
8728 set_hl_attr(i); | |
8729 | |
8730 recursive = FALSE; | |
8731 } | |
8732 | |
8733 /* | |
8734 * This is a new combination of colors and font, add an entry. | |
8735 */ | |
8736 if (ga_grow(table, 1) == FAIL) | |
8737 return 0; | |
8738 | |
359 | 8739 taep = &(((attrentry_T *)table->ga_data)[table->ga_len]); |
8740 vim_memset(taep, 0, sizeof(attrentry_T)); | |
8741 taep->ae_attr = aep->ae_attr; | |
7 | 8742 #ifdef FEAT_GUI |
8743 if (table == &gui_attr_table) | |
8744 { | |
359 | 8745 taep->ae_u.gui.fg_color = aep->ae_u.gui.fg_color; |
8746 taep->ae_u.gui.bg_color = aep->ae_u.gui.bg_color; | |
8747 taep->ae_u.gui.sp_color = aep->ae_u.gui.sp_color; | |
8748 taep->ae_u.gui.font = aep->ae_u.gui.font; | |
7 | 8749 # ifdef FEAT_XFONTSET |
359 | 8750 taep->ae_u.gui.fontset = aep->ae_u.gui.fontset; |
7 | 8751 # endif |
8752 } | |
8753 #endif | |
8754 if (table == &term_attr_table) | |
8755 { | |
8756 if (aep->ae_u.term.start == NULL) | |
359 | 8757 taep->ae_u.term.start = NULL; |
7 | 8758 else |
359 | 8759 taep->ae_u.term.start = vim_strsave(aep->ae_u.term.start); |
7 | 8760 if (aep->ae_u.term.stop == NULL) |
359 | 8761 taep->ae_u.term.stop = NULL; |
7 | 8762 else |
359 | 8763 taep->ae_u.term.stop = vim_strsave(aep->ae_u.term.stop); |
7 | 8764 } |
8765 else if (table == &cterm_attr_table) | |
8766 { | |
359 | 8767 taep->ae_u.cterm.fg_color = aep->ae_u.cterm.fg_color; |
8768 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
|
8769 #ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8770 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
|
8771 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
|
8772 #endif |
7 | 8773 } |
8774 ++table->ga_len; | |
8775 return (table->ga_len - 1 + ATTR_OFF); | |
8776 } | |
8777 | |
359 | 8778 /* |
8779 * Clear all highlight tables. | |
8780 */ | |
8781 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8782 clear_hl_tables(void) |
359 | 8783 { |
8784 int i; | |
8785 attrentry_T *taep; | |
8786 | |
8787 #ifdef FEAT_GUI | |
8788 ga_clear(&gui_attr_table); | |
8789 #endif | |
8790 for (i = 0; i < term_attr_table.ga_len; ++i) | |
8791 { | |
8792 taep = &(((attrentry_T *)term_attr_table.ga_data)[i]); | |
8793 vim_free(taep->ae_u.term.start); | |
8794 vim_free(taep->ae_u.term.stop); | |
8795 } | |
8796 ga_clear(&term_attr_table); | |
8797 ga_clear(&cterm_attr_table); | |
8798 } | |
8799 | |
745 | 8800 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL) || defined(PROTO) |
221 | 8801 /* |
348 | 8802 * Combine special attributes (e.g., for spelling) with other attributes |
8803 * (e.g., for syntax highlighting). | |
8804 * "prim_attr" overrules "char_attr". | |
221 | 8805 * This creates a new group when required. |
8806 * Since we expect there to be few spelling mistakes we don't cache the | |
8807 * result. | |
8808 * Return the resulting attributes. | |
8809 */ | |
8810 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8811 hl_combine_attr(int char_attr, int prim_attr) |
221 | 8812 { |
8813 attrentry_T *char_aep = NULL; | |
8814 attrentry_T *spell_aep; | |
8815 attrentry_T new_en; | |
8816 | |
8817 if (char_attr == 0) | |
348 | 8818 return prim_attr; |
8819 if (char_attr <= HL_ALL && prim_attr <= HL_ALL) | |
8820 return char_attr | prim_attr; | |
221 | 8821 #ifdef FEAT_GUI |
8822 if (gui.in_use) | |
8823 { | |
8824 if (char_attr > HL_ALL) | |
8825 char_aep = syn_gui_attr2entry(char_attr); | |
8826 if (char_aep != NULL) | |
8827 new_en = *char_aep; | |
8828 else | |
8829 { | |
8830 vim_memset(&new_en, 0, sizeof(new_en)); | |
548 | 8831 new_en.ae_u.gui.fg_color = INVALCOLOR; |
8832 new_en.ae_u.gui.bg_color = INVALCOLOR; | |
8833 new_en.ae_u.gui.sp_color = INVALCOLOR; | |
221 | 8834 if (char_attr <= HL_ALL) |
8835 new_en.ae_attr = char_attr; | |
8836 } | |
8837 | |
348 | 8838 if (prim_attr <= HL_ALL) |
8839 new_en.ae_attr |= prim_attr; | |
221 | 8840 else |
8841 { | |
348 | 8842 spell_aep = syn_gui_attr2entry(prim_attr); |
221 | 8843 if (spell_aep != NULL) |
8844 { | |
8845 new_en.ae_attr |= spell_aep->ae_attr; | |
8846 if (spell_aep->ae_u.gui.fg_color != INVALCOLOR) | |
8847 new_en.ae_u.gui.fg_color = spell_aep->ae_u.gui.fg_color; | |
8848 if (spell_aep->ae_u.gui.bg_color != INVALCOLOR) | |
8849 new_en.ae_u.gui.bg_color = spell_aep->ae_u.gui.bg_color; | |
8850 if (spell_aep->ae_u.gui.sp_color != INVALCOLOR) | |
8851 new_en.ae_u.gui.sp_color = spell_aep->ae_u.gui.sp_color; | |
8852 if (spell_aep->ae_u.gui.font != NOFONT) | |
8853 new_en.ae_u.gui.font = spell_aep->ae_u.gui.font; | |
8854 # ifdef FEAT_XFONTSET | |
8855 if (spell_aep->ae_u.gui.fontset != NOFONTSET) | |
8856 new_en.ae_u.gui.fontset = spell_aep->ae_u.gui.fontset; | |
8857 # endif | |
8858 } | |
8859 } | |
8860 return get_attr_entry(&gui_attr_table, &new_en); | |
8861 } | |
8862 #endif | |
8863 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8864 if (IS_CTERM) |
221 | 8865 { |
8866 if (char_attr > HL_ALL) | |
8867 char_aep = syn_cterm_attr2entry(char_attr); | |
8868 if (char_aep != NULL) | |
8869 new_en = *char_aep; | |
8870 else | |
8871 { | |
8872 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
|
8873 #ifdef FEAT_TERMGUICOLORS |
e88ffb09ff38
commit https://github.com/vim/vim/commit/0cdb72aa38c4a0140c94d56bf8bc17cb30260ebf
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
8874 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
|
8875 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
|
8876 #endif |
221 | 8877 if (char_attr <= HL_ALL) |
8878 new_en.ae_attr = char_attr; | |
8879 } | |
8880 | |
348 | 8881 if (prim_attr <= HL_ALL) |
8882 new_en.ae_attr |= prim_attr; | |
221 | 8883 else |
8884 { | |
348 | 8885 spell_aep = syn_cterm_attr2entry(prim_attr); |
221 | 8886 if (spell_aep != NULL) |
8887 { | |
8888 new_en.ae_attr |= spell_aep->ae_attr; | |
8889 if (spell_aep->ae_u.cterm.fg_color > 0) | |
8890 new_en.ae_u.cterm.fg_color = spell_aep->ae_u.cterm.fg_color; | |
8891 if (spell_aep->ae_u.cterm.bg_color > 0) | |
8892 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
|
8893 #ifdef FEAT_TERMGUICOLORS |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
8894 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
|
8895 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
|
8896 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
|
8897 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
|
8898 #endif |
221 | 8899 } |
8900 } | |
8901 return get_attr_entry(&cterm_attr_table, &new_en); | |
8902 } | |
8903 | |
8904 if (char_attr > HL_ALL) | |
8905 char_aep = syn_term_attr2entry(char_attr); | |
8906 if (char_aep != NULL) | |
8907 new_en = *char_aep; | |
8908 else | |
8909 { | |
8910 vim_memset(&new_en, 0, sizeof(new_en)); | |
8911 if (char_attr <= HL_ALL) | |
8912 new_en.ae_attr = char_attr; | |
8913 } | |
8914 | |
348 | 8915 if (prim_attr <= HL_ALL) |
8916 new_en.ae_attr |= prim_attr; | |
221 | 8917 else |
8918 { | |
607 | 8919 spell_aep = syn_term_attr2entry(prim_attr); |
221 | 8920 if (spell_aep != NULL) |
8921 { | |
8922 new_en.ae_attr |= spell_aep->ae_attr; | |
8923 if (spell_aep->ae_u.term.start != NULL) | |
8924 { | |
8925 new_en.ae_u.term.start = spell_aep->ae_u.term.start; | |
8926 new_en.ae_u.term.stop = spell_aep->ae_u.term.stop; | |
8927 } | |
8928 } | |
8929 } | |
8930 return get_attr_entry(&term_attr_table, &new_en); | |
8931 } | |
8932 #endif | |
8933 | |
7 | 8934 #ifdef FEAT_GUI |
8935 | |
8936 attrentry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8937 syn_gui_attr2entry(int attr) |
7 | 8938 { |
8939 attr -= ATTR_OFF; | |
8940 if (attr >= gui_attr_table.ga_len) /* did ":syntax clear" */ | |
8941 return NULL; | |
8942 return &(GUI_ATTR_ENTRY(attr)); | |
8943 } | |
8944 #endif /* FEAT_GUI */ | |
8945 | |
745 | 8946 /* |
8947 * Get the highlight attributes (HL_BOLD etc.) from an attribute nr. | |
8948 * Only to be used when "attr" > HL_ALL. | |
8949 */ | |
8950 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8951 syn_attr2attr(int attr) |
745 | 8952 { |
8953 attrentry_T *aep; | |
8954 | |
8955 #ifdef FEAT_GUI | |
8956 if (gui.in_use) | |
8957 aep = syn_gui_attr2entry(attr); | |
8958 else | |
8959 #endif | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8960 if (IS_CTERM) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8961 aep = syn_cterm_attr2entry(attr); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8962 else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
8963 aep = syn_term_attr2entry(attr); |
745 | 8964 |
8965 if (aep == NULL) /* highlighting not set */ | |
8966 return 0; | |
8967 return aep->ae_attr; | |
8968 } | |
8969 | |
8970 | |
7 | 8971 attrentry_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8972 syn_term_attr2entry(int attr) |
7 | 8973 { |
8974 attr -= ATTR_OFF; | |
8975 if (attr >= term_attr_table.ga_len) /* did ":syntax clear" */ | |
8976 return NULL; | |
8977 return &(TERM_ATTR_ENTRY(attr)); | |
8978 } | |
8979 | |
8980 attrentry_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8981 syn_cterm_attr2entry(int attr) |
7 | 8982 { |
8983 attr -= ATTR_OFF; | |
8984 if (attr >= cterm_attr_table.ga_len) /* did ":syntax clear" */ | |
8985 return NULL; | |
8986 return &(CTERM_ATTR_ENTRY(attr)); | |
8987 } | |
8988 | |
8989 #define LIST_ATTR 1 | |
8990 #define LIST_STRING 2 | |
8991 #define LIST_INT 3 | |
8992 | |
8993 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
8994 highlight_list_one(int id) |
7 | 8995 { |
8996 struct hl_group *sgp; | |
8997 int didh = FALSE; | |
8998 | |
8999 sgp = &HL_TABLE()[id - 1]; /* index is ID minus one */ | |
9000 | |
9001 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
9002 sgp->sg_term, NULL, "term"); | |
9003 didh = highlight_list_arg(id, didh, LIST_STRING, | |
9004 0, sgp->sg_start, "start"); | |
9005 didh = highlight_list_arg(id, didh, LIST_STRING, | |
9006 0, sgp->sg_stop, "stop"); | |
9007 | |
9008 didh = highlight_list_arg(id, didh, LIST_ATTR, | |
9009 sgp->sg_cterm, NULL, "cterm"); | |
9010 didh = highlight_list_arg(id, didh, LIST_INT, | |
9011 sgp->sg_cterm_fg, NULL, "ctermfg"); | |
9012 didh = highlight_list_arg(id, didh, LIST_INT, | |
9013 sgp->sg_cterm_bg, NULL, "ctermbg"); | |
9014 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9015 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9016 didh = highlight_list_arg(id, didh, LIST_ATTR, |
9017 sgp->sg_gui, NULL, "gui"); | |
9018 didh = highlight_list_arg(id, didh, LIST_STRING, | |
9019 0, sgp->sg_gui_fg_name, "guifg"); | |
9020 didh = highlight_list_arg(id, didh, LIST_STRING, | |
9021 0, sgp->sg_gui_bg_name, "guibg"); | |
9022 didh = highlight_list_arg(id, didh, LIST_STRING, | |
301 | 9023 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
|
9024 #endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9025 #ifdef FEAT_GUI |
301 | 9026 didh = highlight_list_arg(id, didh, LIST_STRING, |
7 | 9027 0, sgp->sg_font_name, "font"); |
9028 #endif | |
9029 | |
448 | 9030 if (sgp->sg_link && !got_int) |
7 | 9031 { |
9032 (void)syn_list_header(didh, 9999, id); | |
448 | 9033 didh = TRUE; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
9034 msg_puts_attr((char_u *)"links to", HL_ATTR(HLF_D)); |
7 | 9035 msg_putchar(' '); |
9036 msg_outtrans(HL_TABLE()[HL_TABLE()[id - 1].sg_link - 1].sg_name); | |
9037 } | |
448 | 9038 |
694 | 9039 if (!didh) |
9040 highlight_list_arg(id, didh, LIST_STRING, 0, (char_u *)"cleared", ""); | |
448 | 9041 #ifdef FEAT_EVAL |
694 | 9042 if (p_verbose > 0) |
448 | 9043 last_set_msg(sgp->sg_scriptID); |
9044 #endif | |
7 | 9045 } |
9046 | |
9047 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9048 highlight_list_arg( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9049 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9050 int didh, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9051 int type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9052 int iarg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9053 char_u *sarg, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9054 char *name) |
7 | 9055 { |
9056 char_u buf[100]; | |
9057 char_u *ts; | |
9058 int i; | |
9059 | |
448 | 9060 if (got_int) |
9061 return FALSE; | |
7 | 9062 if (type == LIST_STRING ? (sarg != NULL) : (iarg != 0)) |
9063 { | |
9064 ts = buf; | |
9065 if (type == LIST_INT) | |
9066 sprintf((char *)buf, "%d", iarg - 1); | |
9067 else if (type == LIST_STRING) | |
9068 ts = sarg; | |
9069 else /* type == LIST_ATTR */ | |
9070 { | |
9071 buf[0] = NUL; | |
9072 for (i = 0; hl_attr_table[i] != 0; ++i) | |
9073 { | |
9074 if (iarg & hl_attr_table[i]) | |
9075 { | |
9076 if (buf[0] != NUL) | |
2768 | 9077 vim_strcat(buf, (char_u *)",", 100); |
9078 vim_strcat(buf, (char_u *)hl_name_table[i], 100); | |
7 | 9079 iarg &= ~hl_attr_table[i]; /* don't want "inverse" */ |
9080 } | |
9081 } | |
9082 } | |
9083 | |
9084 (void)syn_list_header(didh, | |
9085 (int)(vim_strsize(ts) + STRLEN(name) + 1), id); | |
9086 didh = TRUE; | |
448 | 9087 if (!got_int) |
9088 { | |
694 | 9089 if (*name != NUL) |
9090 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
9091 MSG_PUTS_ATTR(name, HL_ATTR(HLF_D)); |
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
9092 MSG_PUTS_ATTR("=", HL_ATTR(HLF_D)); |
694 | 9093 } |
448 | 9094 msg_outtrans(ts); |
9095 } | |
7 | 9096 } |
9097 return didh; | |
9098 } | |
9099 | |
9100 #if (((defined(FEAT_EVAL) || defined(FEAT_PRINTER))) && defined(FEAT_SYN_HL)) || defined(PROTO) | |
9101 /* | |
9102 * Return "1" if highlight group "id" has attribute "flag". | |
9103 * Return NULL otherwise. | |
9104 */ | |
9105 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9106 highlight_has_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9107 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9108 int flag, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9109 int modec) /* 'g' for GUI, 'c' for cterm, 't' for term */ |
7 | 9110 { |
9111 int attr; | |
9112 | |
9113 if (id <= 0 || id > highlight_ga.ga_len) | |
9114 return NULL; | |
9115 | |
2318
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9116 #if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9117 if (modec == 'g') |
9118 attr = HL_TABLE()[id - 1].sg_gui; | |
9119 else | |
9120 #endif | |
9121 if (modec == 'c') | |
9122 attr = HL_TABLE()[id - 1].sg_cterm; | |
9123 else | |
9124 attr = HL_TABLE()[id - 1].sg_term; | |
9125 | |
9126 if (attr & flag) | |
9127 return (char_u *)"1"; | |
9128 return NULL; | |
9129 } | |
9130 #endif | |
9131 | |
9132 #if (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) || defined(PROTO) | |
9133 /* | |
9134 * Return color name of highlight group "id". | |
9135 */ | |
9136 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9137 highlight_color( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9138 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9139 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
|
9140 int modec) /* 'g' for GUI, 'c' for cterm, 't' for term */ |
7 | 9141 { |
9142 static char_u name[20]; | |
9143 int n; | |
205 | 9144 int fg = FALSE; |
9145 int sp = FALSE; | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9146 int font = FALSE; |
7 | 9147 |
9148 if (id <= 0 || id > highlight_ga.ga_len) | |
9149 return NULL; | |
9150 | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9151 if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g') |
7 | 9152 fg = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9153 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
|
9154 && 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
|
9155 font = TRUE; |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9156 else if (TOLOWER_ASC(what[0]) == 's' && TOLOWER_ASC(what[1]) == 'p') |
205 | 9157 sp = TRUE; |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9158 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
|
9159 return NULL; |
7 | 9160 if (modec == 'g') |
9161 { | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9162 # 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
|
9163 # ifdef FEAT_GUI |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9164 /* return font name */ |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9165 if (font) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9166 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
|
9167 # endif |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9168 |
7 | 9169 /* 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
|
9170 if ((USE_24BIT) && what[2] == '#') |
7 | 9171 { |
9172 guicolor_T color; | |
9173 long_u rgb; | |
9174 static char_u buf[10]; | |
9175 | |
9176 if (fg) | |
9177 color = HL_TABLE()[id - 1].sg_gui_fg; | |
205 | 9178 else if (sp) |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9179 # ifdef FEAT_GUI |
205 | 9180 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
|
9181 # else |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9182 color = INVALCOLOR; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9183 # endif |
7 | 9184 else |
9185 color = HL_TABLE()[id - 1].sg_gui_bg; | |
9186 if (color == INVALCOLOR) | |
9187 return NULL; | |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9877
diff
changeset
|
9188 rgb = (long_u)GUI_MCH_GET_RGB(color); |
7 | 9189 sprintf((char *)buf, "#%02x%02x%02x", |
9190 (unsigned)(rgb >> 16), | |
9191 (unsigned)(rgb >> 8) & 255, | |
9192 (unsigned)rgb & 255); | |
9193 return buf; | |
9194 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9195 # endif |
7 | 9196 if (fg) |
9197 return (HL_TABLE()[id - 1].sg_gui_fg_name); | |
205 | 9198 if (sp) |
9199 return (HL_TABLE()[id - 1].sg_gui_sp_name); | |
7 | 9200 return (HL_TABLE()[id - 1].sg_gui_bg_name); |
9201 } | |
2106
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9202 if (font || sp) |
15674e198164
updated for version 7.2.389
Bram Moolenaar <bram@zimbu.org>
parents:
2100
diff
changeset
|
9203 return NULL; |
7 | 9204 if (modec == 'c') |
9205 { | |
9206 if (fg) | |
9207 n = HL_TABLE()[id - 1].sg_cterm_fg - 1; | |
9208 else | |
9209 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
|
9210 if (n < 0) |
260d01c1cd17
commit https://github.com/vim/vim/commit/385111bd86e0b38667879c3e89506ca1ae98e1df
Christian Brabandt <cb@256bit.org>
parents:
8362
diff
changeset
|
9211 return NULL; |
7 | 9212 sprintf((char *)name, "%d", n); |
9213 return name; | |
9214 } | |
9215 /* term doesn't have color */ | |
9216 return NULL; | |
9217 } | |
9218 #endif | |
9219 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9220 #if (defined(FEAT_SYN_HL) \ |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9221 && (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
|
9222 && defined(FEAT_PRINTER)) || defined(PROTO) |
7 | 9223 /* |
9224 * Return color name of highlight group "id" as RGB value. | |
9225 */ | |
9226 long_u | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9227 highlight_gui_color_rgb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9228 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9229 int fg) /* TRUE = fg, FALSE = bg */ |
7 | 9230 { |
9231 guicolor_T color; | |
9232 | |
9233 if (id <= 0 || id > highlight_ga.ga_len) | |
9234 return 0L; | |
9235 | |
9236 if (fg) | |
9237 color = HL_TABLE()[id - 1].sg_gui_fg; | |
9238 else | |
9239 color = HL_TABLE()[id - 1].sg_gui_bg; | |
9240 | |
9241 if (color == INVALCOLOR) | |
9242 return 0L; | |
9243 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9244 return GUI_MCH_GET_RGB(color); |
7 | 9245 } |
9246 #endif | |
9247 | |
9248 /* | |
9249 * Output the syntax list header. | |
9250 * Return TRUE when started a new line. | |
9251 */ | |
9252 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9253 syn_list_header( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9254 int did_header, /* did header already */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9255 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
|
9256 int id) /* highlight group id */ |
7 | 9257 { |
9258 int endcol = 19; | |
9259 int newline = TRUE; | |
9260 | |
9261 if (!did_header) | |
9262 { | |
9263 msg_putchar('\n'); | |
448 | 9264 if (got_int) |
9265 return TRUE; | |
7 | 9266 msg_outtrans(HL_TABLE()[id - 1].sg_name); |
9267 endcol = 15; | |
9268 } | |
9269 else if (msg_col + outlen + 1 >= Columns) | |
448 | 9270 { |
7 | 9271 msg_putchar('\n'); |
448 | 9272 if (got_int) |
9273 return TRUE; | |
9274 } | |
7 | 9275 else |
9276 { | |
9277 if (msg_col >= endcol) /* wrap around is like starting a new line */ | |
9278 newline = FALSE; | |
9279 } | |
9280 | |
9281 if (msg_col >= endcol) /* output at least one space */ | |
9282 endcol = msg_col + 1; | |
9283 if (Columns <= endcol) /* avoid hang for tiny window */ | |
9284 endcol = Columns - 1; | |
9285 | |
9286 msg_advance(endcol); | |
9287 | |
9288 /* Show "xxx" with the attributes. */ | |
9289 if (!did_header) | |
9290 { | |
9291 msg_puts_attr((char_u *)"xxx", syn_id2attr(id)); | |
9292 msg_putchar(' '); | |
9293 } | |
9294 | |
9295 return newline; | |
9296 } | |
9297 | |
9298 /* | |
9299 * Set the attribute numbers for a highlight group. | |
9300 * Called after one of the attributes has changed. | |
9301 */ | |
9302 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9303 set_hl_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9304 int idx) /* index in array */ |
7 | 9305 { |
9306 attrentry_T at_en; | |
9307 struct hl_group *sgp = HL_TABLE() + idx; | |
9308 | |
9309 /* The "Normal" group doesn't need an attribute number */ | |
9310 if (sgp->sg_name_u != NULL && STRCMP(sgp->sg_name_u, "NORMAL") == 0) | |
9311 return; | |
9312 | |
9313 #ifdef FEAT_GUI | |
9314 /* | |
9315 * For the GUI mode: If there are other than "normal" highlighting | |
9316 * attributes, need to allocate an attr number. | |
9317 */ | |
9318 if (sgp->sg_gui_fg == INVALCOLOR | |
9319 && sgp->sg_gui_bg == INVALCOLOR | |
205 | 9320 && sgp->sg_gui_sp == INVALCOLOR |
7 | 9321 && sgp->sg_font == NOFONT |
9322 # ifdef FEAT_XFONTSET | |
9323 && sgp->sg_fontset == NOFONTSET | |
9324 # endif | |
9325 ) | |
9326 { | |
9327 sgp->sg_gui_attr = sgp->sg_gui; | |
9328 } | |
9329 else | |
9330 { | |
9331 at_en.ae_attr = sgp->sg_gui; | |
9332 at_en.ae_u.gui.fg_color = sgp->sg_gui_fg; | |
9333 at_en.ae_u.gui.bg_color = sgp->sg_gui_bg; | |
205 | 9334 at_en.ae_u.gui.sp_color = sgp->sg_gui_sp; |
7 | 9335 at_en.ae_u.gui.font = sgp->sg_font; |
9336 # ifdef FEAT_XFONTSET | |
9337 at_en.ae_u.gui.fontset = sgp->sg_fontset; | |
9338 # endif | |
9339 sgp->sg_gui_attr = get_attr_entry(&gui_attr_table, &at_en); | |
9340 } | |
9341 #endif | |
9342 /* | |
9343 * For the term mode: If there are other than "normal" highlighting | |
9344 * attributes, need to allocate an attr number. | |
9345 */ | |
9346 if (sgp->sg_start == NULL && sgp->sg_stop == NULL) | |
9347 sgp->sg_term_attr = sgp->sg_term; | |
9348 else | |
9349 { | |
9350 at_en.ae_attr = sgp->sg_term; | |
9351 at_en.ae_u.term.start = sgp->sg_start; | |
9352 at_en.ae_u.term.stop = sgp->sg_stop; | |
9353 sgp->sg_term_attr = get_attr_entry(&term_attr_table, &at_en); | |
9354 } | |
9355 | |
9356 /* | |
9357 * For the color term mode: If there are other than "normal" | |
9358 * highlighting attributes, need to allocate an attr number. | |
9359 */ | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9360 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
|
9361 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9362 && sgp->sg_gui_fg == INVALCOLOR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9363 && sgp->sg_gui_bg == INVALCOLOR |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9364 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9365 ) |
7 | 9366 sgp->sg_cterm_attr = sgp->sg_cterm; |
9367 else | |
9368 { | |
9369 at_en.ae_attr = sgp->sg_cterm; | |
9370 at_en.ae_u.cterm.fg_color = sgp->sg_cterm_fg; | |
9371 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
|
9372 # ifdef FEAT_TERMGUICOLORS |
9054
f129fd3ebd98
commit https://github.com/vim/vim/commit/187147aedd588070d0676664d5076d046644094e
Christian Brabandt <cb@256bit.org>
parents:
9029
diff
changeset
|
9373 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
|
9374 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
|
9375 # endif |
7 | 9376 sgp->sg_cterm_attr = get_attr_entry(&cterm_attr_table, &at_en); |
9377 } | |
9378 } | |
9379 | |
9380 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
9381 * Lookup a highlight group name and return its ID. |
7 | 9382 * If it is not found, 0 is returned. |
9383 */ | |
9384 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9385 syn_name2id(char_u *name) |
7 | 9386 { |
9387 int i; | |
9388 char_u name_u[200]; | |
9389 | |
9390 /* Avoid using stricmp() too much, it's slow on some systems */ | |
9391 /* Avoid alloc()/free(), these are slow too. ID names over 200 chars | |
9392 * don't deserve to be found! */ | |
419 | 9393 vim_strncpy(name_u, name, 199); |
7 | 9394 vim_strup(name_u); |
9395 for (i = highlight_ga.ga_len; --i >= 0; ) | |
9396 if (HL_TABLE()[i].sg_name_u != NULL | |
9397 && STRCMP(name_u, HL_TABLE()[i].sg_name_u) == 0) | |
9398 break; | |
9399 return i + 1; | |
9400 } | |
9401 | |
9402 #if defined(FEAT_EVAL) || defined(PROTO) | |
9403 /* | |
9404 * Return TRUE if highlight group "name" exists. | |
9405 */ | |
9406 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9407 highlight_exists(char_u *name) |
7 | 9408 { |
9409 return (syn_name2id(name) > 0); | |
9410 } | |
819 | 9411 |
9412 # if defined(FEAT_SEARCH_EXTRA) || defined(PROTO) | |
9413 /* | |
9414 * Return the name of highlight group "id". | |
9415 * When not a valid ID return an empty string. | |
9416 */ | |
9417 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9418 syn_id2name(int id) |
819 | 9419 { |
1326 | 9420 if (id <= 0 || id > highlight_ga.ga_len) |
819 | 9421 return (char_u *)""; |
9422 return HL_TABLE()[id - 1].sg_name; | |
9423 } | |
9424 # endif | |
7 | 9425 #endif |
9426 | |
9427 /* | |
9428 * Like syn_name2id(), but take a pointer + length argument. | |
9429 */ | |
9430 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9431 syn_namen2id(char_u *linep, int len) |
7 | 9432 { |
9433 char_u *name; | |
9434 int id = 0; | |
9435 | |
9436 name = vim_strnsave(linep, len); | |
9437 if (name != NULL) | |
9438 { | |
9439 id = syn_name2id(name); | |
9440 vim_free(name); | |
9441 } | |
9442 return id; | |
9443 } | |
9444 | |
9445 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
9446 * Find highlight group name in the table and return its ID. |
7 | 9447 * The argument is a pointer to the name and the length of the name. |
9448 * If it doesn't exist yet, a new entry is created. | |
9449 * Return 0 for failure. | |
9450 */ | |
9451 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9452 syn_check_group(char_u *pp, int len) |
7 | 9453 { |
9454 int id; | |
9455 char_u *name; | |
9456 | |
9457 name = vim_strnsave(pp, len); | |
9458 if (name == NULL) | |
9459 return 0; | |
9460 | |
9461 id = syn_name2id(name); | |
9462 if (id == 0) /* doesn't exist yet */ | |
9463 id = syn_add_group(name); | |
9464 else | |
9465 vim_free(name); | |
9466 return id; | |
9467 } | |
9468 | |
9469 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
9470 * Add new highlight group and return its ID. |
7 | 9471 * "name" must be an allocated string, it will be consumed. |
9472 * Return 0 for failure. | |
9473 */ | |
9474 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9475 syn_add_group(char_u *name) |
7 | 9476 { |
9477 char_u *p; | |
9478 | |
9479 /* Check that the name is ASCII letters, digits and underscore. */ | |
9480 for (p = name; *p != NUL; ++p) | |
9481 { | |
9482 if (!vim_isprintc(*p)) | |
9483 { | |
9484 EMSG(_("E669: Unprintable character in group name")); | |
2020 | 9485 vim_free(name); |
7 | 9486 return 0; |
9487 } | |
9488 else if (!ASCII_ISALNUM(*p) && *p != '_') | |
9489 { | |
9490 /* This is an error, but since there previously was no check only | |
9491 * give a warning. */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
9492 msg_source(HL_ATTR(HLF_W)); |
7 | 9493 MSG(_("W18: Invalid character in group name")); |
9494 break; | |
9495 } | |
9496 } | |
9497 | |
9498 /* | |
9499 * First call for this growarray: init growing array. | |
9500 */ | |
9501 if (highlight_ga.ga_data == NULL) | |
9502 { | |
9503 highlight_ga.ga_itemsize = sizeof(struct hl_group); | |
9504 highlight_ga.ga_growsize = 10; | |
9505 } | |
9506 | |
2756 | 9507 if (highlight_ga.ga_len >= MAX_HL_ID) |
9508 { | |
9509 EMSG(_("E849: Too many highlight and syntax groups")); | |
2743 | 9510 vim_free(name); |
9511 return 0; | |
9512 } | |
9513 | |
7 | 9514 /* |
9515 * Make room for at least one other syntax_highlight entry. | |
9516 */ | |
9517 if (ga_grow(&highlight_ga, 1) == FAIL) | |
9518 { | |
9519 vim_free(name); | |
9520 return 0; | |
9521 } | |
9522 | |
9523 vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(struct hl_group)); | |
9524 HL_TABLE()[highlight_ga.ga_len].sg_name = name; | |
9525 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
|
9526 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 9527 HL_TABLE()[highlight_ga.ga_len].sg_gui_bg = INVALCOLOR; |
9528 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
|
9529 # ifdef FEAT_GUI |
205 | 9530 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
|
9531 # endif |
7 | 9532 #endif |
9533 ++highlight_ga.ga_len; | |
9534 | |
9535 return highlight_ga.ga_len; /* ID is index plus one */ | |
9536 } | |
9537 | |
9538 /* | |
9539 * When, just after calling syn_add_group(), an error is discovered, this | |
9540 * function deletes the new name. | |
9541 */ | |
9542 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9543 syn_unadd_group(void) |
7 | 9544 { |
9545 --highlight_ga.ga_len; | |
9546 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name); | |
9547 vim_free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); | |
9548 } | |
9549 | |
9550 /* | |
9551 * Translate a group ID to highlight attributes. | |
9552 */ | |
9553 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9554 syn_id2attr(int hl_id) |
7 | 9555 { |
9556 int attr; | |
9557 struct hl_group *sgp; | |
9558 | |
9559 hl_id = syn_get_final_id(hl_id); | |
9560 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9561 | |
9562 #ifdef FEAT_GUI | |
9563 /* | |
9564 * Only use GUI attr when the GUI is being used. | |
9565 */ | |
9566 if (gui.in_use) | |
9567 attr = sgp->sg_gui_attr; | |
9568 else | |
9569 #endif | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9570 if (IS_CTERM) |
7 | 9571 attr = sgp->sg_cterm_attr; |
9572 else | |
9573 attr = sgp->sg_term_attr; | |
9574 | |
9575 return attr; | |
9576 } | |
9577 | |
9578 #ifdef FEAT_GUI | |
9579 /* | |
9580 * Get the GUI colors and attributes for a group ID. | |
9581 * NOTE: the colors will be INVALCOLOR when not set, the color otherwise. | |
9582 */ | |
9583 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9584 syn_id2colors(int hl_id, guicolor_T *fgp, guicolor_T *bgp) |
7 | 9585 { |
9586 struct hl_group *sgp; | |
9587 | |
9588 hl_id = syn_get_final_id(hl_id); | |
9589 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9590 | |
9591 *fgp = sgp->sg_gui_fg; | |
9592 *bgp = sgp->sg_gui_bg; | |
9593 return sgp->sg_gui; | |
9594 } | |
9595 #endif | |
9596 | |
9597 /* | |
9598 * Translate a group ID to the final group ID (following links). | |
9599 */ | |
9600 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9601 syn_get_final_id(int hl_id) |
7 | 9602 { |
9603 int count; | |
9604 struct hl_group *sgp; | |
9605 | |
9606 if (hl_id > highlight_ga.ga_len || hl_id < 1) | |
9607 return 0; /* Can be called from eval!! */ | |
9608 | |
9609 /* | |
9610 * Follow links until there is no more. | |
9611 * Look out for loops! Break after 100 links. | |
9612 */ | |
9613 for (count = 100; --count >= 0; ) | |
9614 { | |
9615 sgp = &HL_TABLE()[hl_id - 1]; /* index is ID minus one */ | |
9616 if (sgp->sg_link == 0 || sgp->sg_link > highlight_ga.ga_len) | |
9617 break; | |
9618 hl_id = sgp->sg_link; | |
9619 } | |
9620 | |
9621 return hl_id; | |
9622 } | |
9623 | |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9624 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
7 | 9625 /* |
9626 * Call this function just after the GUI has started. | |
9627 * It finds the font and color handles for the highlighting groups. | |
9628 */ | |
9629 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9630 highlight_gui_started(void) |
7 | 9631 { |
9632 int idx; | |
9633 | |
9634 /* 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
|
9635 # 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
|
9636 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9637 if (USE_24BIT) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9638 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9639 set_normal_colors(); |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9640 # endif |
7 | 9641 |
9642 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
9643 gui_do_one_color(idx, FALSE, FALSE); | |
9644 | |
9645 highlight_changed(); | |
9646 } | |
9647 | |
9648 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9649 gui_do_one_color( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9650 int idx, |
8975
9c097bfad637
commit https://github.com/vim/vim/commit/380130f1e18da92a44372728fe044f56db58585b
Christian Brabandt <cb@256bit.org>
parents:
8969
diff
changeset
|
9651 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
|
9652 int do_tooltip UNUSED) /* TRUE: might set the tooltip font */ |
7 | 9653 { |
9654 int didit = FALSE; | |
9655 | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9656 # ifdef FEAT_GUI |
9027
773d627cac0b
commit https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
Christian Brabandt <cb@256bit.org>
parents:
8977
diff
changeset
|
9657 # ifdef FEAT_TERMGUICOLORS |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9658 if (gui.in_use) |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9659 # endif |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9660 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
|
9661 { |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9662 hl_do_font(idx, HL_TABLE()[idx].sg_font_name, FALSE, do_menu, |
3881 | 9663 do_tooltip, TRUE); |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9664 didit = TRUE; |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9665 } |
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9666 # endif |
7 | 9667 if (HL_TABLE()[idx].sg_gui_fg_name != NULL) |
9668 { | |
9669 HL_TABLE()[idx].sg_gui_fg = | |
9670 color_name2handle(HL_TABLE()[idx].sg_gui_fg_name); | |
9671 didit = TRUE; | |
9672 } | |
9673 if (HL_TABLE()[idx].sg_gui_bg_name != NULL) | |
9674 { | |
9675 HL_TABLE()[idx].sg_gui_bg = | |
9676 color_name2handle(HL_TABLE()[idx].sg_gui_bg_name); | |
9677 didit = TRUE; | |
9678 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9679 # ifdef FEAT_GUI |
205 | 9680 if (HL_TABLE()[idx].sg_gui_sp_name != NULL) |
9681 { | |
9682 HL_TABLE()[idx].sg_gui_sp = | |
9683 color_name2handle(HL_TABLE()[idx].sg_gui_sp_name); | |
9684 didit = TRUE; | |
9685 } | |
8969
c83e2c1e7f2b
commit https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
Christian Brabandt <cb@256bit.org>
parents:
8815
diff
changeset
|
9686 # endif |
7 | 9687 if (didit) /* need to get a new attr number */ |
9688 set_hl_attr(idx); | |
9689 } | |
9690 #endif | |
9691 | |
9692 /* | |
9693 * Translate the 'highlight' option into attributes in highlight_attr[] and | |
9694 * set up the user highlights User1..9. If FEAT_STL_OPT is in use, a set of | |
9695 * corresponding highlights to use on top of HLF_SNC is computed. | |
9696 * Called only when the 'highlight' option has been changed and upon first | |
9697 * screen redraw after any :highlight command. | |
9698 * Return FAIL when an invalid flag is found in 'highlight'. OK otherwise. | |
9699 */ | |
9700 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9701 highlight_changed(void) |
7 | 9702 { |
9703 int hlf; | |
9704 int i; | |
9705 char_u *p; | |
9706 int attr; | |
9707 char_u *end; | |
9708 int id; | |
9709 #ifdef USER_HIGHLIGHT | |
9710 char_u userhl[10]; | |
9711 # ifdef FEAT_STL_OPT | |
9712 int id_SNC = -1; | |
9713 int id_S = -1; | |
9714 int hlcnt; | |
9715 # endif | |
9716 #endif | |
9717 static int hl_flags[HLF_COUNT] = HL_FLAGS; | |
9718 | |
9719 need_highlight_changed = FALSE; | |
9720 | |
9721 /* | |
9722 * Clear all attributes. | |
9723 */ | |
9724 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9725 highlight_attr[hlf] = 0; | |
9726 | |
9727 /* | |
9728 * First set all attributes to their default value. | |
9729 * Then use the attributes from the 'highlight' option. | |
9730 */ | |
9731 for (i = 0; i < 2; ++i) | |
9732 { | |
9733 if (i) | |
9734 p = p_hl; | |
9735 else | |
9736 p = get_highlight_default(); | |
9737 if (p == NULL) /* just in case */ | |
9738 continue; | |
9739 | |
9740 while (*p) | |
9741 { | |
9742 for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) | |
9743 if (hl_flags[hlf] == *p) | |
9744 break; | |
9745 ++p; | |
9746 if (hlf == (int)HLF_COUNT || *p == NUL) | |
9747 return FAIL; | |
9748 | |
9749 /* | |
9750 * Allow several hl_flags to be combined, like "bu" for | |
9751 * bold-underlined. | |
9752 */ | |
9753 attr = 0; | |
9754 for ( ; *p && *p != ','; ++p) /* parse upto comma */ | |
9755 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
9756 if (VIM_ISWHITE(*p)) /* ignore white space */ |
7 | 9757 continue; |
9758 | |
9759 if (attr > HL_ALL) /* Combination with ':' is not allowed. */ | |
9760 return FAIL; | |
9761 | |
9762 switch (*p) | |
9763 { | |
9764 case 'b': attr |= HL_BOLD; | |
9765 break; | |
9766 case 'i': attr |= HL_ITALIC; | |
9767 break; | |
9768 case '-': | |
9769 case 'n': /* no highlighting */ | |
9770 break; | |
9771 case 'r': attr |= HL_INVERSE; | |
9772 break; | |
9773 case 's': attr |= HL_STANDOUT; | |
9774 break; | |
9775 case 'u': attr |= HL_UNDERLINE; | |
9776 break; | |
205 | 9777 case 'c': attr |= HL_UNDERCURL; |
9778 break; | |
7 | 9779 case ':': ++p; /* highlight group name */ |
9780 if (attr || *p == NUL) /* no combinations */ | |
9781 return FAIL; | |
9782 end = vim_strchr(p, ','); | |
9783 if (end == NULL) | |
9784 end = p + STRLEN(p); | |
9785 id = syn_check_group(p, (int)(end - p)); | |
9786 if (id == 0) | |
9787 return FAIL; | |
9788 attr = syn_id2attr(id); | |
9789 p = end - 1; | |
9790 #if defined(FEAT_STL_OPT) && defined(USER_HIGHLIGHT) | |
9791 if (hlf == (int)HLF_SNC) | |
9792 id_SNC = syn_get_final_id(id); | |
9793 else if (hlf == (int)HLF_S) | |
9794 id_S = syn_get_final_id(id); | |
9795 #endif | |
9796 break; | |
9797 default: return FAIL; | |
9798 } | |
9799 } | |
9800 highlight_attr[hlf] = attr; | |
9801 | |
9802 p = skip_to_option_part(p); /* skip comma and spaces */ | |
9803 } | |
9804 } | |
9805 | |
9806 #ifdef USER_HIGHLIGHT | |
9807 /* Setup the user highlights | |
9808 * | |
9809 * Temporarily utilize 10 more hl entries. Have to be in there | |
9810 * simultaneously in case of table overflows in get_attr_entry() | |
9811 */ | |
9812 # ifdef FEAT_STL_OPT | |
9813 if (ga_grow(&highlight_ga, 10) == FAIL) | |
9814 return FAIL; | |
9815 hlcnt = highlight_ga.ga_len; | |
9816 if (id_S == 0) | |
9817 { /* 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
|
9818 vim_memset(&HL_TABLE()[hlcnt + 9], 0, sizeof(struct hl_group)); |
7 | 9819 HL_TABLE()[hlcnt + 9].sg_term = highlight_attr[HLF_S]; |
9820 id_S = hlcnt + 10; | |
9821 } | |
9822 # endif | |
9823 for (i = 0; i < 9; i++) | |
9824 { | |
9825 sprintf((char *)userhl, "User%d", i + 1); | |
9826 id = syn_name2id(userhl); | |
9827 if (id == 0) | |
9828 { | |
9829 highlight_user[i] = 0; | |
9830 # ifdef FEAT_STL_OPT | |
9831 highlight_stlnc[i] = 0; | |
9832 # endif | |
9833 } | |
9834 else | |
9835 { | |
9836 # ifdef FEAT_STL_OPT | |
9837 struct hl_group *hlt = HL_TABLE(); | |
9838 # endif | |
9839 | |
9840 highlight_user[i] = syn_id2attr(id); | |
9841 # ifdef FEAT_STL_OPT | |
9842 if (id_SNC == 0) | |
9843 { | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2136
diff
changeset
|
9844 vim_memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group)); |
7 | 9845 hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC]; |
9846 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
|
9847 # if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9848 hlt[hlcnt + i].sg_gui = highlight_attr[HLF_SNC]; |
9849 # endif | |
9850 } | |
9851 else | |
9852 mch_memmove(&hlt[hlcnt + i], | |
9853 &hlt[id_SNC - 1], | |
9854 sizeof(struct hl_group)); | |
9855 hlt[hlcnt + i].sg_link = 0; | |
9856 | |
9857 /* Apply difference between UserX and HLF_S to HLF_SNC */ | |
9858 hlt[hlcnt + i].sg_term ^= | |
9859 hlt[id - 1].sg_term ^ hlt[id_S - 1].sg_term; | |
9860 if (hlt[id - 1].sg_start != hlt[id_S - 1].sg_start) | |
9861 hlt[hlcnt + i].sg_start = hlt[id - 1].sg_start; | |
9862 if (hlt[id - 1].sg_stop != hlt[id_S - 1].sg_stop) | |
9863 hlt[hlcnt + i].sg_stop = hlt[id - 1].sg_stop; | |
9864 hlt[hlcnt + i].sg_cterm ^= | |
9865 hlt[id - 1].sg_cterm ^ hlt[id_S - 1].sg_cterm; | |
9866 if (hlt[id - 1].sg_cterm_fg != hlt[id_S - 1].sg_cterm_fg) | |
9867 hlt[hlcnt + i].sg_cterm_fg = hlt[id - 1].sg_cterm_fg; | |
9868 if (hlt[id - 1].sg_cterm_bg != hlt[id_S - 1].sg_cterm_bg) | |
9869 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
|
9870 # if defined(FEAT_GUI) || defined(FEAT_EVAL) |
7 | 9871 hlt[hlcnt + i].sg_gui ^= |
9872 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
|
9873 # endif |
9cf111138fb9
Allow synIDattr() getting GUI attributes when build without GUI.
Bram Moolenaar <bram@vim.org>
parents:
2314
diff
changeset
|
9874 # ifdef FEAT_GUI |
7 | 9875 if (hlt[id - 1].sg_gui_fg != hlt[id_S - 1].sg_gui_fg) |
9876 hlt[hlcnt + i].sg_gui_fg = hlt[id - 1].sg_gui_fg; | |
9877 if (hlt[id - 1].sg_gui_bg != hlt[id_S - 1].sg_gui_bg) | |
9878 hlt[hlcnt + i].sg_gui_bg = hlt[id - 1].sg_gui_bg; | |
205 | 9879 if (hlt[id - 1].sg_gui_sp != hlt[id_S - 1].sg_gui_sp) |
9880 hlt[hlcnt + i].sg_gui_sp = hlt[id - 1].sg_gui_sp; | |
7 | 9881 if (hlt[id - 1].sg_font != hlt[id_S - 1].sg_font) |
9882 hlt[hlcnt + i].sg_font = hlt[id - 1].sg_font; | |
9883 # ifdef FEAT_XFONTSET | |
9884 if (hlt[id - 1].sg_fontset != hlt[id_S - 1].sg_fontset) | |
9885 hlt[hlcnt + i].sg_fontset = hlt[id - 1].sg_fontset; | |
9886 # endif | |
9887 # endif | |
9888 highlight_ga.ga_len = hlcnt + i + 1; | |
9889 set_hl_attr(hlcnt + i); /* At long last we can apply */ | |
9890 highlight_stlnc[i] = syn_id2attr(hlcnt + i + 1); | |
9891 # endif | |
9892 } | |
9893 } | |
9894 # ifdef FEAT_STL_OPT | |
9895 highlight_ga.ga_len = hlcnt; | |
9896 # endif | |
9897 | |
9898 #endif /* USER_HIGHLIGHT */ | |
9899 | |
9900 return OK; | |
9901 } | |
9902 | |
1322 | 9903 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
7 | 9904 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
9905 static void highlight_list(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
9906 static void highlight_list_two(int cnt, int attr); |
7 | 9907 |
9908 /* | |
9909 * Handle command line completion for :highlight command. | |
9910 */ | |
9911 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9912 set_context_in_highlight_cmd(expand_T *xp, char_u *arg) |
7 | 9913 { |
9914 char_u *p; | |
9915 | |
9916 /* Default: expand group names */ | |
9917 xp->xp_context = EXPAND_HIGHLIGHT; | |
9918 xp->xp_pattern = arg; | |
1322 | 9919 include_link = 2; |
9920 include_default = 1; | |
7 | 9921 |
9922 /* (part of) subcommand already typed */ | |
9923 if (*arg != NUL) | |
9924 { | |
9925 p = skiptowhite(arg); | |
9926 if (*p != NUL) /* past "default" or group name */ | |
9927 { | |
1322 | 9928 include_default = 0; |
7 | 9929 if (STRNCMP("default", arg, p - arg) == 0) |
9930 { | |
9931 arg = skipwhite(p); | |
9932 xp->xp_pattern = arg; | |
9933 p = skiptowhite(arg); | |
9934 } | |
9935 if (*p != NUL) /* past group name */ | |
9936 { | |
1322 | 9937 include_link = 0; |
7 | 9938 if (arg[1] == 'i' && arg[0] == 'N') |
9939 highlight_list(); | |
9940 if (STRNCMP("link", arg, p - arg) == 0 | |
9941 || STRNCMP("clear", arg, p - arg) == 0) | |
9942 { | |
9943 xp->xp_pattern = skipwhite(p); | |
9944 p = skiptowhite(xp->xp_pattern); | |
9945 if (*p != NUL) /* past first group name */ | |
9946 { | |
9947 xp->xp_pattern = skipwhite(p); | |
9948 p = skiptowhite(xp->xp_pattern); | |
9949 } | |
9950 } | |
9951 if (*p != NUL) /* past group name(s) */ | |
9952 xp->xp_context = EXPAND_NOTHING; | |
9953 } | |
9954 } | |
9955 } | |
9956 } | |
9957 | |
9958 /* | |
9959 * List highlighting matches in a nice way. | |
9960 */ | |
9961 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9962 highlight_list(void) |
7 | 9963 { |
9964 int i; | |
9965 | |
9966 for (i = 10; --i >= 0; ) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
9967 highlight_list_two(i, HL_ATTR(HLF_D)); |
7 | 9968 for (i = 40; --i >= 0; ) |
9969 highlight_list_two(99, 0); | |
9970 } | |
9971 | |
9972 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9973 highlight_list_two(int cnt, int attr) |
7 | 9974 { |
3543 | 9975 msg_puts_attr((char_u *)&("N \bI \b! \b"[cnt / 11]), attr); |
7 | 9976 msg_clr_eos(); |
9977 out_flush(); | |
9978 ui_delay(cnt == 99 ? 40L : (long)cnt * 50L, FALSE); | |
9979 } | |
9980 | |
9981 #endif /* FEAT_CMDL_COMPL */ | |
9982 | |
9983 #if defined(FEAT_CMDL_COMPL) || (defined(FEAT_SYN_HL) && defined(FEAT_EVAL)) \ | |
9984 || defined(FEAT_SIGNS) || defined(PROTO) | |
9985 /* | |
9986 * Function given to ExpandGeneric() to obtain the list of group names. | |
9987 */ | |
9988 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
9989 get_highlight_name(expand_T *xp UNUSED, int idx) |
7 | 9990 { |
11254
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9991 return get_highlight_name_ext(xp, idx, TRUE); |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9992 } |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9993 |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9994 /* |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9995 * Obtain a highlight group name. |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9996 * When "skip_cleared" is TRUE don't return a cleared entry. |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9997 */ |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9998 char_u * |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
9999 get_highlight_name_ext(expand_T *xp UNUSED, int idx, int skip_cleared) |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
10000 { |
10660
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
10001 if (idx < 0) |
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
10002 return NULL; |
11254
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
10003 |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
10004 /* Items are never removed from the table, skip the ones that were |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
10005 * cleared. */ |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
10006 if (skip_cleared && idx < highlight_ga.ga_len && HL_TABLE()[idx].sg_cleared) |
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11189
diff
changeset
|
10007 return (char_u *)""; |
10660
715836a72361
patch 8.0.0220: completion of highlight names misses a few values
Christian Brabandt <cb@256bit.org>
parents:
10648
diff
changeset
|
10008 |
7 | 10009 #ifdef FEAT_CMDL_COMPL |
1322 | 10010 if (idx == highlight_ga.ga_len && include_none != 0) |
10011 return (char_u *)"none"; | |
10012 if (idx == highlight_ga.ga_len + include_none && include_default != 0) | |
10013 return (char_u *)"default"; | |
10014 if (idx == highlight_ga.ga_len + include_none + include_default | |
10015 && include_link != 0) | |
7 | 10016 return (char_u *)"link"; |
1322 | 10017 if (idx == highlight_ga.ga_len + include_none + include_default + 1 |
10018 && include_link != 0) | |
7 | 10019 return (char_u *)"clear"; |
10020 #endif | |
10624
5ac9d7920f11
patch 8.0.0201: completion of highlight groups includes cleared names
Christian Brabandt <cb@256bit.org>
parents:
10618
diff
changeset
|
10021 if (idx >= highlight_ga.ga_len) |
7 | 10022 return NULL; |
10023 return HL_TABLE()[idx].sg_name; | |
10024 } | |
10025 #endif | |
10026 | |
1322 | 10027 #if defined(FEAT_GUI) || defined(PROTO) |
7 | 10028 /* |
10029 * Free all the highlight group fonts. | |
10030 * Used when quitting for systems which need it. | |
10031 */ | |
10032 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
10033 free_highlight_fonts(void) |
7 | 10034 { |
10035 int idx; | |
10036 | |
10037 for (idx = 0; idx < highlight_ga.ga_len; ++idx) | |
10038 { | |
10039 gui_mch_free_font(HL_TABLE()[idx].sg_font); | |
10040 HL_TABLE()[idx].sg_font = NOFONT; | |
10041 # ifdef FEAT_XFONTSET | |
10042 gui_mch_free_fontset(HL_TABLE()[idx].sg_fontset); | |
10043 HL_TABLE()[idx].sg_fontset = NOFONTSET; | |
10044 # endif | |
10045 } | |
10046 | |
10047 gui_mch_free_font(gui.norm_font); | |
10048 # ifdef FEAT_XFONTSET | |
10049 gui_mch_free_fontset(gui.fontset); | |
10050 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2256
diff
changeset
|
10051 # ifndef FEAT_GUI_GTK |
7 | 10052 gui_mch_free_font(gui.bold_font); |
10053 gui_mch_free_font(gui.ital_font); | |
10054 gui_mch_free_font(gui.boldital_font); | |
10055 # endif | |
10056 } | |
10057 #endif | |
10058 | |
10059 /************************************** | |
10060 * End of Highlighting stuff * | |
10061 **************************************/ |