Mercurial > vim
annotate src/syntax.c @ 27488:07da466dcf6d v8.2.4272
patch 8.2.4272: Vim9 expr test fails without the channel feature
Commit: https://github.com/vim/vim/commit/eb6c2765959c91ddbb527f96f91ba5be199b8d41
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 31 13:36:36 2022 +0000
patch 8.2.4272: Vim9 expr test fails without the channel feature
Problem: Vim9 expr test fails without the channel feature. (Dominique
Pell?)
Solution: Remove "g:" before "CheckFeature". (closes #9671)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 31 Jan 2022 14:45:04 +0100 |
parents | c9474ae175f4 |
children | 0ea5147a95f7 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * syntax.c: code for syntax highlighting | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
17 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
18 #define SYN_NAMELEN 50 // maximum length of a syntax name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
19 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
20 // different types of offsets that are possible |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
21 #define SPO_MS_OFF 0 // match start offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
22 #define SPO_ME_OFF 1 // match end offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
23 #define SPO_HS_OFF 2 // highl. start offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
24 #define SPO_HE_OFF 3 // highl. end offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
25 #define SPO_RS_OFF 4 // region start offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
26 #define SPO_RE_OFF 5 // region end offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
27 #define SPO_LC_OFF 6 // leading context offset |
7 | 28 #define SPO_COUNT 7 |
29 | |
30 static char *(spo_name_tab[SPO_COUNT]) = | |
31 {"ms=", "me=", "hs=", "he=", "rs=", "re=", "lc="}; | |
32 | |
33 /* | |
34 * The patterns that are being searched for are stored in a syn_pattern. | |
35 * A match item consists of one pattern. | |
36 * A start/end item consists of n start patterns and m end patterns. | |
37 * A start/skip/end item consists of n start patterns, one skip pattern and m | |
38 * end patterns. | |
39 * For the latter two, the patterns are always consecutive: start-skip-end. | |
40 * | |
41 * A character offset can be given for the matched text (_m_start and _m_end) | |
42 * and for the actually highlighted text (_h_start and _h_end). | |
13333
b4e7082de11d
patch 8.0.1541: synpat_T is taking too much memory
Christian Brabandt <cb@256bit.org>
parents:
13314
diff
changeset
|
43 * |
b4e7082de11d
patch 8.0.1541: synpat_T is taking too much memory
Christian Brabandt <cb@256bit.org>
parents:
13314
diff
changeset
|
44 * Note that ordering of members is optimized to reduce padding. |
7 | 45 */ |
46 typedef struct syn_pattern | |
47 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
48 char sp_type; // see SPTYPE_ defines below |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
49 char sp_syncing; // this item used for syncing |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
50 short sp_syn_match_id; // highlight group ID of pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
51 short sp_off_flags; // see below |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
52 int sp_offsets[SPO_COUNT]; // offsets |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
53 int sp_flags; // see HL_ defines below |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
54 #ifdef FEAT_CONCEAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
55 int sp_cchar; // conceal substitute character |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
56 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
57 int sp_ic; // ignore-case flag for sp_prog |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
58 int sp_sync_idx; // sync item index (syncing only) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
59 int sp_line_id; // ID of last line where tried |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
60 int sp_startcol; // next match in sp_line_id line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
61 short *sp_cont_list; // cont. group IDs, if non-zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
62 short *sp_next_list; // next group IDs, if non-zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
63 struct sp_syn sp_syn; // struct passed to in_id_list() |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
64 char_u *sp_pattern; // regexp to match, pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
65 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
|
66 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
67 syn_time_T sp_time; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
68 #endif |
7 | 69 } synpat_T; |
70 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
71 // The sp_off_flags are computed like this: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
72 // offset from the start of the matched text: (1 << SPO_XX_OFF) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
73 // offset from the end of the matched text: (1 << (SPO_XX_OFF + SPO_COUNT)) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
74 // When both are present, only one is used. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
75 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
76 #define SPTYPE_MATCH 1 // match keyword with this group ID |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
77 #define SPTYPE_START 2 // match a regexp, start of item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
78 #define SPTYPE_END 3 // match a regexp, end of item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
79 #define SPTYPE_SKIP 4 // match a regexp, skip within item |
7 | 80 |
81 | |
82 #define SYN_ITEMS(buf) ((synpat_T *)((buf)->b_syn_patterns.ga_data)) | |
83 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
84 #define NONE_IDX -2 // value of sp_sync_idx for "NONE" |
7 | 85 |
86 /* | |
87 * Flags for b_syn_sync_flags: | |
88 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
89 #define SF_CCOMMENT 0x01 // sync on a C-style comment |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
90 #define SF_MATCH 0x02 // sync by matching a pattern |
7 | 91 |
92 #define SYN_STATE_P(ssp) ((bufstate_T *)((ssp)->ga_data)) | |
93 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
94 #define MAXKEYWLEN 80 // maximum length of a keyword |
7 | 95 |
96 /* | |
97 * The attributes of the syntax item that has been recognized. | |
98 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
99 static int current_attr = 0; // attr of current syntax word |
7 | 100 #ifdef FEAT_EVAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
101 static int current_id = 0; // ID of current char for syn_get_id() |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
102 static int current_trans_id = 0; // idem, transparency removed |
7 | 103 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
104 #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
|
105 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
|
106 static int current_seqnr = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
107 static int current_sub_char = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
108 #endif |
7 | 109 |
221 | 110 typedef struct syn_cluster_S |
7 | 111 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
112 char_u *scl_name; // syntax cluster name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
113 char_u *scl_name_u; // uppercase of scl_name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
114 short *scl_list; // IDs in this syntax cluster |
221 | 115 } syn_cluster_T; |
7 | 116 |
117 /* | |
118 * Methods of combining two clusters | |
119 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
120 #define CLUSTER_REPLACE 1 // replace first list with second |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
121 #define CLUSTER_ADD 2 // add second list to first |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
122 #define CLUSTER_SUBTRACT 3 // subtract second list from first |
7 | 123 |
221 | 124 #define SYN_CLSTR(buf) ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data)) |
7 | 125 |
126 /* | |
127 * Syntax group IDs have different types: | |
2743 | 128 * 0 - 19999 normal syntax groups |
129 * 20000 - 20999 ALLBUT indicator (current_syn_inc_tag added) | |
130 * 21000 - 21999 TOP indicator (current_syn_inc_tag added) | |
131 * 22000 - 22999 CONTAINED indicator (current_syn_inc_tag added) | |
132 * 23000 - 32767 cluster IDs (subtract SYNID_CLUSTER for the cluster ID) | |
133 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
134 #define SYNID_ALLBUT MAX_HL_ID // syntax group ID for contains=ALLBUT |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
135 #define SYNID_TOP 21000 // syntax group ID for contains=TOP |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
136 #define SYNID_CONTAINED 22000 // syntax group ID for contains=CONTAINED |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
137 #define SYNID_CLUSTER 23000 // first syntax group ID for clusters |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
138 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
139 #define MAX_SYN_INC_TAG 999 // maximum before the above overflow |
2743 | 140 #define MAX_CLUSTER_ID (32767 - SYNID_CLUSTER) |
7 | 141 |
142 /* | |
143 * Annoying Hack(TM): ":syn include" needs this pointer to pass to | |
144 * expand_filename(). Most of the other syntax commands don't need it, so | |
145 * instead of passing it to them, we stow it here. | |
146 */ | |
147 static char_u **syn_cmdlinep; | |
148 | |
149 /* | |
150 * 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
|
151 * files from leaking into ALLBUT lists, we assign a unique ID to the |
7 | 152 * rules in each ":syn include"'d file. |
153 */ | |
154 static int current_syn_inc_tag = 0; | |
155 static int running_syn_inc_tag = 0; | |
156 | |
157 /* | |
134 | 158 * In a hashtable item "hi_key" points to "keyword" in a keyentry. |
159 * This avoids adding a pointer to the hashtable item. | |
160 * KE2HIKEY() converts a var pointer to a hashitem key pointer. | |
161 * HIKEY2KE() converts a hashitem key pointer to a var pointer. | |
162 * HI2KE() converts a hashitem pointer to a var pointer. | |
163 */ | |
164 static keyentry_T dumkey; | |
165 #define KE2HIKEY(kp) ((kp)->keyword) | |
166 #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey))) | |
167 #define HI2KE(hi) HIKEY2KE((hi)->hi_key) | |
168 | |
169 /* | |
7 | 170 * To reduce the time spent in keepend(), remember at which level in the state |
171 * stack the first item with "keepend" is present. When "-1", there is no | |
172 * "keepend" on the stack. | |
173 */ | |
174 static int keepend_level = -1; | |
175 | |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
176 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
|
177 |
7 | 178 /* |
179 * For the current state we need to remember more than just the idx. | |
180 * When si_m_endpos.lnum is 0, the items other than si_idx are unknown. | |
181 * (The end positions have the column number of the next char) | |
182 */ | |
183 typedef struct state_item | |
184 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
185 int si_idx; // index of syntax pattern or |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
186 // KEYWORD_IDX |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
187 int si_id; // highlight group ID for keywords |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
188 int si_trans_id; // idem, transparency removed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
189 int si_m_lnum; // lnum of the match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
190 int si_m_startcol; // starting column of the match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
191 lpos_T si_m_endpos; // just after end posn of the match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
192 lpos_T si_h_startpos; // start position of the highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
193 lpos_T si_h_endpos; // end position of the highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
194 lpos_T si_eoe_pos; // end position of end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
195 int si_end_idx; // group ID for end pattern or zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
196 int si_ends; // if match ends before si_m_endpos |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
197 int si_attr; // attributes in this state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
198 long si_flags; // HL_HAS_EOL flag in this state, and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
199 // HL_SKIP* for si_next_list |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
200 #ifdef FEAT_CONCEAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
201 int si_seqnr; // sequence number |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
202 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
|
203 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
204 short *si_cont_list; // list of contained groups |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
205 short *si_next_list; // nextgroup IDs after this item ends |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
206 reg_extmatch_T *si_extmatch; // \z(...\) matches from start |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
207 // pattern |
7 | 208 } stateitem_T; |
209 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
210 #define KEYWORD_IDX -1 // value of si_idx for keywords |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
211 #define ID_LIST_ALL (short *)-1 // valid of si_cont_list for containing all |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
212 // but contained groups |
7 | 213 |
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
|
214 #ifdef FEAT_CONCEAL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
215 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
|
216 #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
|
217 |
7 | 218 /* |
154 | 219 * Struct to reduce the number of arguments to get_syn_options(), it's used |
220 * very often. | |
221 */ | |
222 typedef struct | |
223 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
224 int flags; // flags for contained and transparent |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
225 int keyword; // TRUE for ":syn keyword" |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
226 int *sync_idx; // syntax item for "grouphere" argument, NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
227 // if not allowed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
228 char has_cont_list; // TRUE if "cont_list" can be used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
229 short *cont_list; // group IDs for "contains" argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
230 short *cont_in_list; // group IDs for "containedin" argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
231 short *next_list; // group IDs for "nextgroup" argument |
154 | 232 } syn_opt_arg_T; |
233 | |
234 /* | |
7 | 235 * The next possible match in the current line for any pattern is remembered, |
236 * to avoid having to try for a match in each column. | |
237 * If next_match_idx == -1, not tried (in this line) yet. | |
238 * If next_match_col == MAXCOL, no match found in this line. | |
239 * (All end positions have the column of the char after the end) | |
240 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
241 static int next_match_col; // column for start of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
242 static lpos_T next_match_m_endpos; // position for end of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
243 static lpos_T next_match_h_startpos; // pos. for highl. start of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
244 static lpos_T next_match_h_endpos; // pos. for highl. end of next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
245 static int next_match_idx; // index of matched item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
246 static long next_match_flags; // flags for next match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
247 static lpos_T next_match_eos_pos; // end of start pattn (start region) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
248 static lpos_T next_match_eoe_pos; // pos. for end of end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
249 static int next_match_end_idx; // ID of group for end pattn or zero |
7 | 250 static reg_extmatch_T *next_match_extmatch = NULL; |
251 | |
252 /* | |
253 * A state stack is an array of integers or stateitem_T, stored in a | |
14968
c5ec5ddbe814
patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
254 * garray_T. A state stack is invalid if its itemsize entry is zero. |
7 | 255 */ |
256 #define INVALID_STATE(ssp) ((ssp)->ga_itemsize == 0) | |
257 #define VALID_STATE(ssp) ((ssp)->ga_itemsize != 0) | |
258 | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
259 #define FOR_ALL_SYNSTATES(sb, sst) \ |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
260 for ((sst) = (sb)->b_sst_first; (sst) != NULL; (sst) = (sst)->sst_next) |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
261 |
7 | 262 /* |
263 * The current state (within the line) of the recognition engine. | |
264 * When current_state.ga_itemsize is 0 the current state is invalid. | |
265 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
266 static win_T *syn_win; // current window for highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
267 static buf_T *syn_buf; // current buffer for highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
268 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
|
269 #ifdef FEAT_RELTIME |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
270 static proftime_T *syn_tm; // timeout limit |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
271 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
272 static linenr_T current_lnum = 0; // lnum of current state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
273 static colnr_T current_col = 0; // column of current state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
274 static int current_state_stored = 0; // TRUE if stored current state |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
275 // after setting current_finished |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
276 static int current_finished = 0; // current line has been finished |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
277 static garray_T current_state // current stack of state_items |
7 | 278 = {0, 0, 0, 0, NULL}; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
279 static short *current_next_list = NULL; // when non-zero, nextgroup list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
280 static int current_next_flags = 0; // flags for current_next_list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
281 static int current_line_id = 0; // unique number for current line |
7 | 282 |
283 #define CUR_STATE(idx) ((stateitem_T *)(current_state.ga_data))[idx] | |
284 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
285 static void syn_sync(win_T *wp, linenr_T lnum, synstate_T *last_valid); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
286 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
|
287 static void syn_start_line(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
288 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
|
289 static void syn_stack_alloc(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
290 static int syn_stack_cleanup(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 static void invalidate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
296 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
|
297 static void validate_current_state(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
298 static int syn_finish_line(int syncing); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 static void check_state_ends(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
303 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
|
304 static void check_keepend(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
305 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
|
306 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
|
307 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
|
308 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
|
309 static void pop_current_state(void); |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
310 #ifdef FEAT_PROFILE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
311 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
|
312 static void syntime_clear(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
313 static void syntime_report(void); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
314 static int syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
315 # define IF_SYN_TIME(p) (p) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
316 #else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
317 # define IF_SYN_TIME(p) NULL |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
318 typedef int syn_time_T; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
319 #endif |
7 | 320 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
321 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
|
322 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
|
323 |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 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
|
328 static char_u *syn_getcurline(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 static void syn_lines_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
337 static void syn_match_msg(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 static void init_syn_patterns(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
349 static char_u *get_syn_pattern(char_u *arg, synpat_T *ci); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
350 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
|
351 static void syn_combine_list(short **clstr1, short **clstr2, int list_op); |
7 | 352 |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
353 #if defined(FEAT_RELTIME) || defined(PROTO) |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
354 /* |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
355 * Set the timeout used for syntax highlighting. |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
356 * Use NULL to reset, no timeout. |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
357 */ |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
358 void |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
359 syn_set_timeout(proftime_T *tm) |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
360 { |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
361 syn_tm = tm; |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
362 } |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
363 #endif |
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
364 |
7 | 365 /* |
366 * Start the syntax recognition for a line. This function is normally called | |
367 * from the screen updating, once for each displayed line. | |
368 * The buffer is remembered in syn_buf, because get_syntax_attr() doesn't get | |
369 * it. Careful: curbuf and curwin are likely to point to another buffer and | |
370 * window. | |
371 */ | |
372 void | |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
373 syntax_start(win_T *wp, linenr_T lnum) |
7 | 374 { |
375 synstate_T *p; | |
376 synstate_T *last_valid = NULL; | |
377 synstate_T *last_min_valid = NULL; | |
1512 | 378 synstate_T *sp, *prev = NULL; |
7 | 379 linenr_T parsed_lnum; |
380 linenr_T first_stored; | |
381 int dist; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
382 static varnumber_T changedtick = 0; // remember the last change ID |
7 | 383 |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
384 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
385 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
|
386 #endif |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
387 |
7 | 388 /* |
389 * After switching buffers, invalidate current_state. | |
26 | 390 * Also do this when a change was made, the current state may be invalid |
391 * then. | |
7 | 392 */ |
8806
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
393 if (syn_block != wp->w_s |
8fff73f17ff1
commit https://github.com/vim/vim/commit/b681be175b6991cdc2b8ddd49b0e97e3fe2b201e
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
394 || 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
|
395 || changedtick != CHANGEDTICK(syn_buf)) |
7 | 396 { |
397 invalidate_current_state(); | |
398 syn_buf = wp->w_buffer; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
399 syn_block = wp->w_s; |
7 | 400 } |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10889
diff
changeset
|
401 changedtick = CHANGEDTICK(syn_buf); |
7 | 402 syn_win = wp; |
403 | |
404 /* | |
405 * Allocate syntax stack when needed. | |
406 */ | |
407 syn_stack_alloc(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
408 if (syn_block->b_sst_array == NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
409 return; // out of memory |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
410 syn_block->b_sst_lasttick = display_tick; |
7 | 411 |
412 /* | |
413 * If the state of the end of the previous line is useful, store it. | |
414 */ | |
415 if (VALID_STATE(¤t_state) | |
416 && current_lnum < lnum | |
417 && current_lnum < syn_buf->b_ml.ml_line_count) | |
418 { | |
419 (void)syn_finish_line(FALSE); | |
420 if (!current_state_stored) | |
421 { | |
422 ++current_lnum; | |
1512 | 423 (void)store_current_state(); |
7 | 424 } |
425 | |
426 /* | |
427 * If the current_lnum is now the same as "lnum", keep the current | |
428 * state (this happens very often!). Otherwise invalidate | |
429 * current_state and figure it out below. | |
430 */ | |
431 if (current_lnum != lnum) | |
432 invalidate_current_state(); | |
433 } | |
434 else | |
435 invalidate_current_state(); | |
436 | |
437 /* | |
438 * Try to synchronize from a saved state in b_sst_array[]. | |
439 * Only do this if lnum is not before and not to far beyond a saved state. | |
440 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
441 if (INVALID_STATE(¤t_state) && syn_block->b_sst_array != NULL) |
7 | 442 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
443 // Find last valid saved state before start_lnum. |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
444 FOR_ALL_SYNSTATES(syn_block, p) |
7 | 445 { |
446 if (p->sst_lnum > lnum) | |
447 break; | |
448 if (p->sst_lnum <= lnum && p->sst_change_lnum == 0) | |
449 { | |
450 last_valid = p; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
451 if (p->sst_lnum >= lnum - syn_block->b_syn_sync_minlines) |
7 | 452 last_min_valid = p; |
453 } | |
454 } | |
455 if (last_min_valid != NULL) | |
456 load_current_state(last_min_valid); | |
457 } | |
458 | |
459 /* | |
460 * If "lnum" is before or far beyond a line with a saved state, need to | |
461 * re-synchronize. | |
462 */ | |
463 if (INVALID_STATE(¤t_state)) | |
464 { | |
465 syn_sync(wp, lnum, last_valid); | |
2906 | 466 if (current_lnum == 1) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
467 // First line is always valid, no matter "minlines". |
2906 | 468 first_stored = 1; |
469 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
470 // Need to parse "minlines" lines before state can be considered |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
471 // valid to store. |
2906 | 472 first_stored = current_lnum + syn_block->b_syn_sync_minlines; |
7 | 473 } |
474 else | |
475 first_stored = current_lnum; | |
476 | |
477 /* | |
478 * Advance from the sync point or saved state until the current line. | |
479 * Save some entries for syncing with later on. | |
480 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
481 if (syn_block->b_sst_len <= Rows) |
819 | 482 dist = 999999; |
483 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
484 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 485 while (current_lnum < lnum) |
486 { | |
487 syn_start_line(); | |
488 (void)syn_finish_line(FALSE); | |
489 ++current_lnum; | |
490 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
491 // If we parsed at least "minlines" lines or started at a valid |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
492 // state, the current state is considered valid. |
7 | 493 if (current_lnum >= first_stored) |
494 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
495 // Check if the saved state entry is for the current line and is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
496 // equal to the current state. If so, then validate all saved |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
497 // states that depended on a change before the parsed line. |
7 | 498 if (prev == NULL) |
1512 | 499 prev = syn_stack_find_entry(current_lnum - 1); |
500 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
501 sp = syn_block->b_sst_first; |
7 | 502 else |
1512 | 503 sp = prev; |
504 while (sp != NULL && sp->sst_lnum < current_lnum) | |
505 sp = sp->sst_next; | |
7 | 506 if (sp != NULL |
507 && sp->sst_lnum == current_lnum | |
508 && syn_stack_equal(sp)) | |
509 { | |
510 parsed_lnum = current_lnum; | |
511 prev = sp; | |
512 while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) | |
513 { | |
514 if (sp->sst_lnum <= lnum) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
515 // valid state before desired line, use this one |
7 | 516 prev = sp; |
517 else if (sp->sst_change_lnum == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
518 // past saved states depending on change, break here. |
7 | 519 break; |
520 sp->sst_change_lnum = 0; | |
521 sp = sp->sst_next; | |
522 } | |
523 load_current_state(prev); | |
524 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
525 // Store the state at this line when it's the first one, the line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
526 // where we start parsing, or some distance from the previously |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
527 // saved state. But only when parsed at least 'minlines'. |
7 | 528 else if (prev == NULL |
529 || current_lnum == lnum | |
530 || current_lnum >= prev->sst_lnum + dist) | |
1512 | 531 prev = store_current_state(); |
7 | 532 } |
533 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
534 // This can take a long time: break when CTRL-C pressed. The current |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
535 // state will be wrong then. |
7 | 536 line_breakcheck(); |
537 if (got_int) | |
538 { | |
539 current_lnum = lnum; | |
540 break; | |
541 } | |
542 } | |
543 | |
544 syn_start_line(); | |
545 } | |
546 | |
547 /* | |
548 * We cannot simply discard growarrays full of state_items or buf_states; we | |
549 * have to manually release their extmatch pointers first. | |
550 */ | |
551 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
552 clear_syn_state(synstate_T *p) |
7 | 553 { |
554 int i; | |
555 garray_T *gap; | |
556 | |
557 if (p->sst_stacksize > SST_FIX_STATES) | |
558 { | |
559 gap = &(p->sst_union.sst_ga); | |
560 for (i = 0; i < gap->ga_len; i++) | |
561 unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch); | |
562 ga_clear(gap); | |
563 } | |
564 else | |
565 { | |
566 for (i = 0; i < p->sst_stacksize; i++) | |
567 unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch); | |
568 } | |
569 } | |
570 | |
571 /* | |
572 * Cleanup the current_state stack. | |
573 */ | |
574 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
575 clear_current_state(void) |
7 | 576 { |
577 int i; | |
578 stateitem_T *sip; | |
579 | |
580 sip = (stateitem_T *)(current_state.ga_data); | |
581 for (i = 0; i < current_state.ga_len; i++) | |
582 unref_extmatch(sip[i].si_extmatch); | |
583 ga_clear(¤t_state); | |
584 } | |
585 | |
586 /* | |
587 * Try to find a synchronisation point for line "lnum". | |
588 * | |
589 * This sets current_lnum and the current state. One of three methods is | |
590 * used: | |
591 * 1. Search backwards for the end of a C-comment. | |
592 * 2. Search backwards for given sync patterns. | |
593 * 3. Simply start on a given number of lines above "lnum". | |
594 */ | |
595 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
596 syn_sync( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
597 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
598 linenr_T start_lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
599 synstate_T *last_valid) |
7 | 600 { |
601 buf_T *curbuf_save; | |
602 win_T *curwin_save; | |
603 pos_T cursor_save; | |
604 int idx; | |
605 linenr_T lnum; | |
606 linenr_T end_lnum; | |
607 linenr_T break_lnum; | |
608 int had_sync_point; | |
609 stateitem_T *cur_si; | |
610 synpat_T *spp; | |
611 char_u *line; | |
612 int found_flags = 0; | |
613 int found_match_idx = 0; | |
614 linenr_T found_current_lnum = 0; | |
615 int found_current_col= 0; | |
616 lpos_T found_m_endpos; | |
442 | 617 colnr_T prev_current_col; |
7 | 618 |
619 /* | |
620 * Clear any current state that might be hanging around. | |
621 */ | |
622 invalidate_current_state(); | |
623 | |
624 /* | |
625 * Start at least "minlines" back. Default starting point for parsing is | |
626 * there. | |
627 * Start further back, to avoid that scrolling backwards will result in | |
628 * resyncing for every line. Now it resyncs only one out of N lines, | |
629 * where N is minlines * 1.5, or minlines * 2 if minlines is small. | |
630 * Watch out for overflow when minlines is MAXLNUM. | |
631 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
632 if (syn_block->b_syn_sync_minlines > start_lnum) |
7 | 633 start_lnum = 1; |
634 else | |
635 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
636 if (syn_block->b_syn_sync_minlines == 1) |
7 | 637 lnum = 1; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
638 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
|
639 lnum = syn_block->b_syn_sync_minlines * 2; |
7 | 640 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
641 lnum = syn_block->b_syn_sync_minlines * 3 / 2; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
642 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
|
643 && lnum > syn_block->b_syn_sync_maxlines) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
644 lnum = syn_block->b_syn_sync_maxlines; |
7 | 645 if (lnum >= start_lnum) |
646 start_lnum = 1; | |
647 else | |
648 start_lnum -= lnum; | |
649 } | |
650 current_lnum = start_lnum; | |
651 | |
652 /* | |
653 * 1. Search backwards for the end of a C-style comment. | |
654 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
655 if (syn_block->b_syn_sync_flags & SF_CCOMMENT) |
7 | 656 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
657 // Need to make syn_buf the current buffer for a moment, to be able to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
658 // use find_start_comment(). |
7 | 659 curwin_save = curwin; |
660 curwin = wp; | |
661 curbuf_save = curbuf; | |
662 curbuf = syn_buf; | |
663 | |
664 /* | |
665 * Skip lines that end in a backslash. | |
666 */ | |
667 for ( ; start_lnum > 1; --start_lnum) | |
668 { | |
669 line = ml_get(start_lnum - 1); | |
670 if (*line == NUL || *(line + STRLEN(line) - 1) != '\\') | |
671 break; | |
672 } | |
673 current_lnum = start_lnum; | |
674 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
675 // set cursor to start of search |
7 | 676 cursor_save = wp->w_cursor; |
677 wp->w_cursor.lnum = start_lnum; | |
678 wp->w_cursor.col = 0; | |
679 | |
680 /* | |
681 * If the line is inside a comment, need to find the syntax item that | |
682 * defines the comment. | |
683 * Restrict the search for the end of a comment to b_syn_sync_maxlines. | |
684 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
685 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
|
686 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
687 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
|
688 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
|
689 == syn_block->b_syn_sync_id |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
690 && SYN_ITEMS(syn_block)[idx].sp_type == SPTYPE_START) |
7 | 691 { |
692 validate_current_state(); | |
693 if (push_current_state(idx) == OK) | |
694 update_si_attr(current_state.ga_len - 1); | |
695 break; | |
696 } | |
697 } | |
698 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
699 // restore cursor and buffer |
7 | 700 wp->w_cursor = cursor_save; |
701 curwin = curwin_save; | |
702 curbuf = curbuf_save; | |
703 } | |
704 | |
705 /* | |
706 * 2. Search backwards for given sync patterns. | |
707 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
708 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
|
709 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
710 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
|
711 && 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
|
712 break_lnum = start_lnum - syn_block->b_syn_sync_maxlines; |
7 | 713 else |
714 break_lnum = 0; | |
715 | |
699 | 716 found_m_endpos.lnum = 0; |
717 found_m_endpos.col = 0; | |
7 | 718 end_lnum = start_lnum; |
719 lnum = start_lnum; | |
720 while (--lnum > break_lnum) | |
721 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
722 // This can take a long time: break when CTRL-C pressed. |
7 | 723 line_breakcheck(); |
724 if (got_int) | |
725 { | |
726 invalidate_current_state(); | |
727 current_lnum = start_lnum; | |
728 break; | |
729 } | |
730 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
731 // Check if we have run into a valid saved state stack now. |
7 | 732 if (last_valid != NULL && lnum == last_valid->sst_lnum) |
733 { | |
734 load_current_state(last_valid); | |
735 break; | |
736 } | |
737 | |
738 /* | |
739 * Check if the previous line has the line-continuation pattern. | |
740 */ | |
741 if (lnum > 1 && syn_match_linecont(lnum - 1)) | |
742 continue; | |
743 | |
744 /* | |
745 * Start with nothing on the state stack | |
746 */ | |
747 validate_current_state(); | |
748 | |
749 for (current_lnum = lnum; current_lnum < end_lnum; ++current_lnum) | |
750 { | |
751 syn_start_line(); | |
752 for (;;) | |
753 { | |
754 had_sync_point = syn_finish_line(TRUE); | |
755 /* | |
756 * When a sync point has been found, remember where, and | |
757 * continue to look for another one, further on in the line. | |
758 */ | |
759 if (had_sync_point && current_state.ga_len) | |
760 { | |
761 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
762 if (cur_si->si_m_endpos.lnum > start_lnum) | |
763 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
764 // ignore match that goes to after where started |
7 | 765 current_lnum = end_lnum; |
766 break; | |
767 } | |
1371 | 768 if (cur_si->si_idx < 0) |
769 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
770 // Cannot happen? |
1371 | 771 found_flags = 0; |
772 found_match_idx = KEYWORD_IDX; | |
773 } | |
774 else | |
775 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
776 spp = &(SYN_ITEMS(syn_block)[cur_si->si_idx]); |
1371 | 777 found_flags = spp->sp_flags; |
778 found_match_idx = spp->sp_sync_idx; | |
779 } | |
7 | 780 found_current_lnum = current_lnum; |
781 found_current_col = current_col; | |
782 found_m_endpos = cur_si->si_m_endpos; | |
783 /* | |
784 * Continue after the match (be aware of a zero-length | |
785 * match). | |
786 */ | |
787 if (found_m_endpos.lnum > current_lnum) | |
788 { | |
789 current_lnum = found_m_endpos.lnum; | |
790 current_col = found_m_endpos.col; | |
791 if (current_lnum >= end_lnum) | |
792 break; | |
793 } | |
794 else if (found_m_endpos.col > current_col) | |
795 current_col = found_m_endpos.col; | |
796 else | |
797 ++current_col; | |
798 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
799 // syn_current_attr() will have skipped the check for |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
800 // an item that ends here, need to do that now. Be |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
801 // careful not to go past the NUL. |
442 | 802 prev_current_col = current_col; |
803 if (syn_getcurline()[current_col] != NUL) | |
804 ++current_col; | |
7 | 805 check_state_ends(); |
442 | 806 current_col = prev_current_col; |
7 | 807 } |
808 else | |
809 break; | |
810 } | |
811 } | |
812 | |
813 /* | |
814 * If a sync point was encountered, break here. | |
815 */ | |
816 if (found_flags) | |
817 { | |
818 /* | |
819 * Put the item that was specified by the sync point on the | |
820 * state stack. If there was no item specified, make the | |
821 * state stack empty. | |
822 */ | |
823 clear_current_state(); | |
824 if (found_match_idx >= 0 | |
825 && push_current_state(found_match_idx) == OK) | |
826 update_si_attr(current_state.ga_len - 1); | |
827 | |
828 /* | |
829 * When using "grouphere", continue from the sync point | |
830 * match, until the end of the line. Parsing starts at | |
831 * the next line. | |
832 * For "groupthere" the parsing starts at start_lnum. | |
833 */ | |
834 if (found_flags & HL_SYNC_HERE) | |
835 { | |
836 if (current_state.ga_len) | |
837 { | |
838 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
839 cur_si->si_h_startpos.lnum = found_current_lnum; | |
840 cur_si->si_h_startpos.col = found_current_col; | |
841 update_si_end(cur_si, (int)current_col, TRUE); | |
842 check_keepend(); | |
843 } | |
844 current_col = found_m_endpos.col; | |
845 current_lnum = found_m_endpos.lnum; | |
846 (void)syn_finish_line(FALSE); | |
847 ++current_lnum; | |
848 } | |
849 else | |
850 current_lnum = start_lnum; | |
851 | |
852 break; | |
853 } | |
854 | |
855 end_lnum = lnum; | |
856 invalidate_current_state(); | |
857 } | |
858 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
859 // Ran into start of the file or exceeded maximum number of lines |
7 | 860 if (lnum <= break_lnum) |
861 { | |
862 invalidate_current_state(); | |
863 current_lnum = break_lnum + 1; | |
864 } | |
865 } | |
866 | |
867 validate_current_state(); | |
868 } | |
869 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
870 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
871 save_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
872 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
873 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
|
874 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
875 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
|
876 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
|
877 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
878 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
879 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
880 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
881 static void |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
882 restore_chartab(char_u *chartab) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
883 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
884 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
|
885 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
|
886 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
887 |
7 | 888 /* |
889 * Return TRUE if the line-continuation pattern matches in line "lnum". | |
890 */ | |
891 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
892 syn_match_linecont(linenr_T lnum) |
7 | 893 { |
894 regmmatch_T regmatch; | |
6375 | 895 int r; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
896 char_u buf_chartab[32]; // chartab array for syn iskyeyword |
7 | 897 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
898 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
|
899 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
900 // use syntax iskeyword option |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
901 save_chartab(buf_chartab); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
902 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
|
903 regmatch.regprog = syn_block->b_syn_linecont_prog; |
6375 | 904 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
|
905 IF_SYN_TIME(&syn_block->b_syn_linecont_time)); |
6375 | 906 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
|
907 restore_chartab(buf_chartab); |
6375 | 908 return r; |
7 | 909 } |
910 return FALSE; | |
911 } | |
912 | |
913 /* | |
914 * Prepare the current state for the start of a line. | |
915 */ | |
916 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
917 syn_start_line(void) |
7 | 918 { |
919 current_finished = FALSE; | |
920 current_col = 0; | |
921 | |
922 /* | |
923 * Need to update the end of a start/skip/end that continues from the | |
924 * previous line and regions that have "keepend". | |
925 */ | |
926 if (current_state.ga_len > 0) | |
2863 | 927 { |
7 | 928 syn_update_ends(TRUE); |
2863 | 929 check_state_ends(); |
930 } | |
7 | 931 |
932 next_match_idx = -1; | |
933 ++current_line_id; | |
11581
2298fda621d3
patch 8.0.0673: build failure without conceal feature
Christian Brabandt <cb@256bit.org>
parents:
11579
diff
changeset
|
934 #ifdef FEAT_CONCEAL |
11579
52e3a77c097b
patch 8.0.0672: third item of synconcealed() changes too often
Christian Brabandt <cb@256bit.org>
parents:
11541
diff
changeset
|
935 next_seqnr = 1; |
11581
2298fda621d3
patch 8.0.0673: build failure without conceal feature
Christian Brabandt <cb@256bit.org>
parents:
11579
diff
changeset
|
936 #endif |
7 | 937 } |
938 | |
939 /* | |
940 * Check for items in the stack that need their end updated. | |
941 * When "startofline" is TRUE the last item is always updated. | |
942 * When "startofline" is FALSE the item with "keepend" is forcefully updated. | |
943 */ | |
944 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
945 syn_update_ends(int startofline) |
7 | 946 { |
947 stateitem_T *cur_si; | |
948 int i; | |
991 | 949 int seen_keepend; |
7 | 950 |
951 if (startofline) | |
952 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
953 // Check for a match carried over from a previous line with a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
954 // contained region. The match ends as soon as the region ends. |
7 | 955 for (i = 0; i < current_state.ga_len; ++i) |
956 { | |
957 cur_si = &CUR_STATE(i); | |
958 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
959 && (SYN_ITEMS(syn_block)[cur_si->si_idx]).sp_type |
7 | 960 == SPTYPE_MATCH |
961 && cur_si->si_m_endpos.lnum < current_lnum) | |
962 { | |
963 cur_si->si_flags |= HL_MATCHCONT; | |
964 cur_si->si_m_endpos.lnum = 0; | |
965 cur_si->si_m_endpos.col = 0; | |
966 cur_si->si_h_endpos = cur_si->si_m_endpos; | |
967 cur_si->si_ends = TRUE; | |
968 } | |
969 } | |
970 } | |
971 | |
972 /* | |
973 * Need to update the end of a start/skip/end that continues from the | |
974 * previous line. And regions that have "keepend", because they may | |
991 | 975 * influence contained items. If we've just removed "extend" |
976 * (startofline == 0) then we should update ends of normal regions | |
977 * contained inside "keepend" because "extend" could have extended | |
978 * these "keepend" regions as well as contained normal regions. | |
7 | 979 * Then check for items ending in column 0. |
980 */ | |
981 i = current_state.ga_len - 1; | |
982 if (keepend_level >= 0) | |
983 for ( ; i > keepend_level; --i) | |
984 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
985 break; | |
991 | 986 |
987 seen_keepend = FALSE; | |
7 | 988 for ( ; i < current_state.ga_len; ++i) |
989 { | |
990 cur_si = &CUR_STATE(i); | |
991 if ((cur_si->si_flags & HL_KEEPEND) | |
991 | 992 || (seen_keepend && !startofline) |
7 | 993 || (i == current_state.ga_len - 1 && startofline)) |
994 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
995 cur_si->si_h_startpos.col = 0; // start highl. in col 0 |
7 | 996 cur_si->si_h_startpos.lnum = current_lnum; |
997 | |
998 if (!(cur_si->si_flags & HL_MATCHCONT)) | |
999 update_si_end(cur_si, (int)current_col, !startofline); | |
991 | 1000 |
1001 if (!startofline && (cur_si->si_flags & HL_KEEPEND)) | |
1002 seen_keepend = TRUE; | |
7 | 1003 } |
1004 } | |
1005 check_keepend(); | |
1006 } | |
1007 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1008 ///////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1009 // Handling of the state stack cache. |
7 | 1010 |
1011 /* | |
1012 * EXPLANATION OF THE SYNTAX STATE STACK CACHE | |
1013 * | |
1014 * To speed up syntax highlighting, the state stack for the start of some | |
1015 * lines is cached. These entries can be used to start parsing at that point. | |
1016 * | |
1017 * The stack is kept in b_sst_array[] for each buffer. There is a list of | |
1018 * valid entries. b_sst_first points to the first one, then follow sst_next. | |
1019 * The entries are sorted on line number. The first entry is often for line 2 | |
1020 * (line 1 always starts with an empty stack). | |
1021 * There is also a list for free entries. This construction is used to avoid | |
1022 * having to allocate and free memory blocks too often. | |
1023 * | |
1024 * When making changes to the buffer, this is logged in b_mod_*. When calling | |
1025 * update_screen() to update the display, it will call | |
1026 * syn_stack_apply_changes() for each displayed buffer to adjust the cached | |
1027 * entries. The entries which are inside the changed area are removed, | |
1028 * because they must be recomputed. Entries below the changed have their line | |
1029 * number adjusted for deleted/inserted lines, and have their sst_change_lnum | |
1030 * set to indicate that a check must be made if the changed lines would change | |
1031 * the cached entry. | |
1032 * | |
1033 * When later displaying lines, an entry is stored for each line. Displayed | |
1034 * lines are likely to be displayed again, in which case the state at the | |
1035 * start of the line is needed. | |
1036 * For not displayed lines, an entry is stored for every so many lines. These | |
1037 * entries will be used e.g., when scrolling backwards. The distance between | |
1038 * entries depends on the number of lines in the buffer. For small buffers | |
1039 * the distance is fixed at SST_DIST, for large buffers there is a fixed | |
1040 * number of entries SST_MAX_ENTRIES, and the distance is computed. | |
1041 */ | |
1042 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1043 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1044 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
|
1045 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1046 synstate_T *p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1047 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1048 if (block->b_sst_array != NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1049 { |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
1050 FOR_ALL_SYNSTATES(block, p) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1051 clear_syn_state(p); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1052 VIM_CLEAR(block->b_sst_array); |
14850
85ef79b16181
patch 8.1.0437: may access freed memory when syntax HL times out
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
1053 block->b_sst_first = NULL; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1054 block->b_sst_len = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1055 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1056 } |
7 | 1057 /* |
1058 * Free b_sst_array[] for buffer "buf". | |
1059 * Used when syntax items changed to force resyncing everywhere. | |
1060 */ | |
1061 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1062 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
|
1063 { |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1064 #ifdef FEAT_FOLDING |
7 | 1065 win_T *wp; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
1066 #endif |
7 | 1067 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1068 syn_stack_free_block(block); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1069 |
7 | 1070 #ifdef FEAT_FOLDING |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1071 // When using "syntax" fold method, must update all folds. |
7 | 1072 FOR_ALL_WINDOWS(wp) |
1073 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1074 if (wp->w_s == block && foldmethodIsSyntax(wp)) |
7 | 1075 foldUpdateAll(wp); |
1076 } | |
1077 #endif | |
1078 } | |
1079 | |
1080 /* | |
1081 * Allocate the syntax state stack for syn_buf when needed. | |
1082 * If the number of entries in b_sst_array[] is much too big or a bit too | |
1083 * small, reallocate it. | |
1084 * Also used to allocate b_sst_array[] for the first time. | |
1085 */ | |
1086 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1087 syn_stack_alloc(void) |
7 | 1088 { |
1089 long len; | |
1090 synstate_T *to, *from; | |
1091 synstate_T *sstp; | |
1092 | |
1093 len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; | |
1094 if (len < SST_MIN_ENTRIES) | |
1095 len = SST_MIN_ENTRIES; | |
1096 else if (len > SST_MAX_ENTRIES) | |
1097 len = SST_MAX_ENTRIES; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1098 if (syn_block->b_sst_len > len * 2 || syn_block->b_sst_len < len) |
7 | 1099 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1100 // Allocate 50% too much, to avoid reallocating too often. |
7 | 1101 len = syn_buf->b_ml.ml_line_count; |
1102 len = (len + len / 2) / SST_DIST + Rows * 2; | |
1103 if (len < SST_MIN_ENTRIES) | |
1104 len = SST_MIN_ENTRIES; | |
1105 else if (len > SST_MAX_ENTRIES) | |
1106 len = SST_MAX_ENTRIES; | |
1107 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1108 if (syn_block->b_sst_array != NULL) |
7 | 1109 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1110 // When shrinking the array, cleanup the existing stack. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1111 // 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
|
1112 while (syn_block->b_sst_len - syn_block->b_sst_freecount + 2 > len |
7 | 1113 && syn_stack_cleanup()) |
1114 ; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1115 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
|
1116 len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2; |
7 | 1117 } |
1118 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
1119 sstp = ALLOC_CLEAR_MULT(synstate_T, len); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1120 if (sstp == NULL) // out of memory! |
7 | 1121 return; |
1122 | |
1123 to = sstp - 1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1124 if (syn_block->b_sst_array != NULL) |
7 | 1125 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1126 // 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
|
1127 for (from = syn_block->b_sst_first; from != NULL; |
7 | 1128 from = from->sst_next) |
1129 { | |
1130 ++to; | |
1131 *to = *from; | |
1132 to->sst_next = to + 1; | |
1133 } | |
1134 } | |
1135 if (to != sstp - 1) | |
1136 { | |
1137 to->sst_next = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1138 syn_block->b_sst_first = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1139 syn_block->b_sst_freecount = len - (int)(to - sstp) - 1; |
7 | 1140 } |
1141 else | |
1142 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1143 syn_block->b_sst_first = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1144 syn_block->b_sst_freecount = len; |
7 | 1145 } |
1146 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1147 // Create the list of free entries. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1148 syn_block->b_sst_firstfree = to + 1; |
7 | 1149 while (++to < sstp + len) |
1150 to->sst_next = to + 1; | |
1151 (sstp + len - 1)->sst_next = NULL; | |
1152 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1153 vim_free(syn_block->b_sst_array); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1154 syn_block->b_sst_array = sstp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1155 syn_block->b_sst_len = len; |
7 | 1156 } |
1157 } | |
1158 | |
1159 /* | |
1160 * Check for changes in a buffer to affect stored syntax states. Uses the | |
1161 * b_mod_* fields. | |
1162 * Called from update_screen(), before screen is being updated, once for each | |
1163 * displayed buffer. | |
1164 */ | |
1165 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1166 syn_stack_apply_changes(buf_T *buf) |
7 | 1167 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1168 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1169 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1170 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
|
1171 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1172 FOR_ALL_WINDOWS(wp) |
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 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
|
1175 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
|
1176 } |
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 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1179 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1180 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
|
1181 { |
7 | 1182 synstate_T *p, *prev, *np; |
1183 linenr_T n; | |
1184 | |
1185 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1186 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
|
1187 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1188 if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) |
7 | 1189 { |
1190 n = p->sst_lnum + buf->b_mod_xlines; | |
1191 if (n <= buf->b_mod_bot) | |
1192 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1193 // this state is inside the changed area, remove it |
7 | 1194 np = p->sst_next; |
1195 if (prev == NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1196 block->b_sst_first = np; |
7 | 1197 else |
1198 prev->sst_next = np; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1199 syn_stack_free_entry(block, p); |
7 | 1200 p = np; |
1201 continue; | |
1202 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1203 // This state is below the changed area. Remember the line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1204 // that needs to be parsed before this entry can be made valid |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1205 // again. |
7 | 1206 if (p->sst_change_lnum != 0 && p->sst_change_lnum > buf->b_mod_top) |
1207 { | |
1208 if (p->sst_change_lnum + buf->b_mod_xlines > buf->b_mod_top) | |
1209 p->sst_change_lnum += buf->b_mod_xlines; | |
1210 else | |
1211 p->sst_change_lnum = buf->b_mod_top; | |
1212 } | |
1213 if (p->sst_change_lnum == 0 | |
1214 || p->sst_change_lnum < buf->b_mod_bot) | |
1215 p->sst_change_lnum = buf->b_mod_bot; | |
1216 | |
1217 p->sst_lnum = n; | |
1218 } | |
1219 prev = p; | |
1220 p = p->sst_next; | |
1221 } | |
1222 } | |
1223 | |
1224 /* | |
1225 * Reduce the number of entries in the state stack for syn_buf. | |
1226 * Returns TRUE if at least one entry was freed. | |
1227 */ | |
1228 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1229 syn_stack_cleanup(void) |
7 | 1230 { |
1231 synstate_T *p, *prev; | |
1232 disptick_T tick; | |
1233 int above; | |
1234 int dist; | |
1235 int retval = FALSE; | |
1236 | |
14850
85ef79b16181
patch 8.1.0437: may access freed memory when syntax HL times out
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
1237 if (syn_block->b_sst_first == NULL) |
7 | 1238 return retval; |
1239 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1240 // 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
|
1241 if (syn_block->b_sst_len <= Rows) |
819 | 1242 dist = 999999; |
1243 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1244 dist = syn_buf->b_ml.ml_line_count / (syn_block->b_sst_len - Rows) + 1; |
7 | 1245 |
1246 /* | |
2020 | 1247 * Go through the list to find the "tick" for the oldest entry that can |
7 | 1248 * be removed. Set "above" when the "tick" for the oldest entry is above |
1249 * "b_sst_lasttick" (the display tick wraps around). | |
1250 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1251 tick = syn_block->b_sst_lasttick; |
7 | 1252 above = FALSE; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1253 prev = syn_block->b_sst_first; |
7 | 1254 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1255 { | |
1256 if (prev->sst_lnum + dist > p->sst_lnum) | |
1257 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1258 if (p->sst_tick > syn_block->b_sst_lasttick) |
7 | 1259 { |
1260 if (!above || p->sst_tick < tick) | |
1261 tick = p->sst_tick; | |
1262 above = TRUE; | |
1263 } | |
1264 else if (!above && p->sst_tick < tick) | |
1265 tick = p->sst_tick; | |
1266 } | |
1267 } | |
1268 | |
1269 /* | |
1270 * Go through the list to make the entries for the oldest tick at an | |
1271 * interval of several lines. | |
1272 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1273 prev = syn_block->b_sst_first; |
7 | 1274 for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) |
1275 { | |
1276 if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) | |
1277 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1278 // Move this entry from used list to free list |
7 | 1279 prev->sst_next = p->sst_next; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1280 syn_stack_free_entry(syn_block, p); |
7 | 1281 p = prev; |
1282 retval = TRUE; | |
1283 } | |
1284 } | |
1285 return retval; | |
1286 } | |
1287 | |
1288 /* | |
1289 * Free the allocated memory for a syn_state item. | |
1290 * Move the entry into the free list. | |
1291 */ | |
1292 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1293 syn_stack_free_entry(synblock_T *block, synstate_T *p) |
7 | 1294 { |
1295 clear_syn_state(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1296 p->sst_next = block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1297 block->b_sst_firstfree = p; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1298 ++block->b_sst_freecount; |
7 | 1299 } |
1300 | |
1301 /* | |
1302 * Find an entry in the list of state stacks at or before "lnum". | |
1303 * Returns NULL when there is no entry or the first entry is after "lnum". | |
1304 */ | |
1305 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1306 syn_stack_find_entry(linenr_T lnum) |
7 | 1307 { |
1308 synstate_T *p, *prev; | |
1309 | |
1310 prev = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1311 for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) |
7 | 1312 { |
1313 if (p->sst_lnum == lnum) | |
1314 return p; | |
1315 if (p->sst_lnum > lnum) | |
1316 break; | |
1317 } | |
1318 return prev; | |
1319 } | |
1320 | |
1321 /* | |
1322 * Try saving the current state in b_sst_array[]. | |
1323 * The current state must be valid for the start of the current_lnum line! | |
1324 */ | |
1325 static synstate_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1326 store_current_state(void) |
7 | 1327 { |
1328 int i; | |
1329 synstate_T *p; | |
1330 bufstate_T *bp; | |
1331 stateitem_T *cur_si; | |
1512 | 1332 synstate_T *sp = syn_stack_find_entry(current_lnum); |
7 | 1333 |
1334 /* | |
1335 * If the current state contains a start or end pattern that continues | |
1336 * from the previous line, we can't use it. Don't store it then. | |
1337 */ | |
1338 for (i = current_state.ga_len - 1; i >= 0; --i) | |
1339 { | |
1340 cur_si = &CUR_STATE(i); | |
1341 if (cur_si->si_h_startpos.lnum >= current_lnum | |
1342 || cur_si->si_m_endpos.lnum >= current_lnum | |
1343 || cur_si->si_h_endpos.lnum >= current_lnum | |
1344 || (cur_si->si_end_idx | |
1345 && cur_si->si_eoe_pos.lnum >= current_lnum)) | |
1346 break; | |
1347 } | |
1348 if (i >= 0) | |
1349 { | |
1350 if (sp != NULL) | |
1351 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1352 // 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
|
1353 if (syn_block->b_sst_first == sp) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1354 // it's the first entry |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1355 syn_block->b_sst_first = sp->sst_next; |
7 | 1356 else |
1357 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1358 // find the entry just before this one to adjust sst_next |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19892
diff
changeset
|
1359 FOR_ALL_SYNSTATES(syn_block, p) |
7 | 1360 if (p->sst_next == sp) |
1361 break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1362 if (p != NULL) // just in case |
840 | 1363 p->sst_next = sp->sst_next; |
7 | 1364 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1365 syn_stack_free_entry(syn_block, sp); |
7 | 1366 sp = NULL; |
1367 } | |
1368 } | |
1369 else if (sp == NULL || sp->sst_lnum != current_lnum) | |
1370 { | |
1371 /* | |
1372 * Add a new entry | |
1373 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1374 // 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
|
1375 if (syn_block->b_sst_freecount == 0) |
7 | 1376 { |
1377 (void)syn_stack_cleanup(); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1378 // "sp" may have been moved to the freelist now |
7 | 1379 sp = syn_stack_find_entry(current_lnum); |
1380 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1381 // 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
|
1382 if (syn_block->b_sst_freecount == 0) |
7 | 1383 sp = NULL; |
1384 else | |
1385 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1386 // Take the first item from the free list and put it in the used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1387 // list, after *sp |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1388 p = syn_block->b_sst_firstfree; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1389 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
|
1390 --syn_block->b_sst_freecount; |
7 | 1391 if (sp == NULL) |
1392 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1393 // Insert in front of the list |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1394 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
|
1395 syn_block->b_sst_first = p; |
7 | 1396 } |
1397 else | |
1398 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1399 // insert in list after *sp |
7 | 1400 p->sst_next = sp->sst_next; |
1401 sp->sst_next = p; | |
1402 } | |
1403 sp = p; | |
1404 sp->sst_stacksize = 0; | |
1405 sp->sst_lnum = current_lnum; | |
1406 } | |
1407 } | |
1408 if (sp != NULL) | |
1409 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1410 // When overwriting an existing state stack, clear it first |
7 | 1411 clear_syn_state(sp); |
1412 sp->sst_stacksize = current_state.ga_len; | |
1413 if (current_state.ga_len > SST_FIX_STATES) | |
1414 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1415 // Need to clear it, might be something remaining from when the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1416 // length was less than SST_FIX_STATES. |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1417 ga_init2(&sp->sst_union.sst_ga, sizeof(bufstate_T), 1); |
7 | 1418 if (ga_grow(&sp->sst_union.sst_ga, current_state.ga_len) == FAIL) |
1419 sp->sst_stacksize = 0; | |
1420 else | |
1421 sp->sst_union.sst_ga.ga_len = current_state.ga_len; | |
1422 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1423 } | |
1424 else | |
1425 bp = sp->sst_union.sst_stack; | |
1426 for (i = 0; i < sp->sst_stacksize; ++i) | |
1427 { | |
1428 bp[i].bs_idx = CUR_STATE(i).si_idx; | |
1429 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
|
1430 #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
|
1431 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
|
1432 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
|
1433 #endif |
7 | 1434 bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); |
1435 } | |
1436 sp->sst_next_flags = current_next_flags; | |
1437 sp->sst_next_list = current_next_list; | |
1438 sp->sst_tick = display_tick; | |
1439 sp->sst_change_lnum = 0; | |
1440 } | |
1441 current_state_stored = TRUE; | |
1442 return sp; | |
1443 } | |
1444 | |
1445 /* | |
1446 * Copy a state stack from "from" in b_sst_array[] to current_state; | |
1447 */ | |
1448 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1449 load_current_state(synstate_T *from) |
7 | 1450 { |
1451 int i; | |
1452 bufstate_T *bp; | |
1453 | |
1454 clear_current_state(); | |
1455 validate_current_state(); | |
1456 keepend_level = -1; | |
1457 if (from->sst_stacksize | |
1458 && ga_grow(¤t_state, from->sst_stacksize) != FAIL) | |
1459 { | |
1460 if (from->sst_stacksize > SST_FIX_STATES) | |
1461 bp = SYN_STATE_P(&(from->sst_union.sst_ga)); | |
1462 else | |
1463 bp = from->sst_union.sst_stack; | |
1464 for (i = 0; i < from->sst_stacksize; ++i) | |
1465 { | |
1466 CUR_STATE(i).si_idx = bp[i].bs_idx; | |
1467 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
|
1468 #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
|
1469 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
|
1470 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
|
1471 #endif |
7 | 1472 CUR_STATE(i).si_extmatch = ref_extmatch(bp[i].bs_extmatch); |
1473 if (keepend_level < 0 && (CUR_STATE(i).si_flags & HL_KEEPEND)) | |
1474 keepend_level = i; | |
1475 CUR_STATE(i).si_ends = FALSE; | |
1476 CUR_STATE(i).si_m_lnum = 0; | |
1477 if (CUR_STATE(i).si_idx >= 0) | |
1478 CUR_STATE(i).si_next_list = | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1479 (SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_next_list; |
7 | 1480 else |
1481 CUR_STATE(i).si_next_list = NULL; | |
1482 update_si_attr(i); | |
1483 } | |
1484 current_state.ga_len = from->sst_stacksize; | |
1485 } | |
1486 current_next_list = from->sst_next_list; | |
1487 current_next_flags = from->sst_next_flags; | |
1488 current_lnum = from->sst_lnum; | |
1489 } | |
1490 | |
1491 /* | |
1492 * Compare saved state stack "*sp" with the current state. | |
1493 * Return TRUE when they are equal. | |
1494 */ | |
1495 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1496 syn_stack_equal(synstate_T *sp) |
7 | 1497 { |
1498 int i, j; | |
1499 bufstate_T *bp; | |
1500 reg_extmatch_T *six, *bsx; | |
1501 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1502 // First a quick check if the stacks have the same size end nextlist. |
7 | 1503 if (sp->sst_stacksize == current_state.ga_len |
1504 && sp->sst_next_list == current_next_list) | |
1505 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1506 // Need to compare all states on both stacks. |
7 | 1507 if (sp->sst_stacksize > SST_FIX_STATES) |
1508 bp = SYN_STATE_P(&(sp->sst_union.sst_ga)); | |
1509 else | |
1510 bp = sp->sst_union.sst_stack; | |
1511 | |
1512 for (i = current_state.ga_len; --i >= 0; ) | |
1513 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1514 // If the item has another index the state is different. |
7 | 1515 if (bp[i].bs_idx != CUR_STATE(i).si_idx) |
1516 break; | |
1517 if (bp[i].bs_extmatch != CUR_STATE(i).si_extmatch) | |
1518 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1519 // When the extmatch pointers are different, the strings in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1520 // them can still be the same. Check if the extmatch |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1521 // references are equal. |
7 | 1522 bsx = bp[i].bs_extmatch; |
1523 six = CUR_STATE(i).si_extmatch; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1524 // If one of the extmatch pointers is NULL the states are |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1525 // different. |
7 | 1526 if (bsx == NULL || six == NULL) |
1527 break; | |
1528 for (j = 0; j < NSUBEXP; ++j) | |
1529 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1530 // Check each referenced match string. They must all be |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1531 // equal. |
7 | 1532 if (bsx->matches[j] != six->matches[j]) |
1533 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1534 // If the pointer is different it can still be the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1535 // same text. Compare the strings, ignore case when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1536 // the start item has the sp_ic flag set. |
7 | 1537 if (bsx->matches[j] == NULL |
1538 || six->matches[j] == NULL) | |
1539 break; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1540 if ((SYN_ITEMS(syn_block)[CUR_STATE(i).si_idx]).sp_ic |
7 | 1541 ? MB_STRICMP(bsx->matches[j], |
1542 six->matches[j]) != 0 | |
1543 : STRCMP(bsx->matches[j], six->matches[j]) != 0) | |
1544 break; | |
1545 } | |
1546 } | |
1547 if (j != NSUBEXP) | |
1548 break; | |
1549 } | |
1550 } | |
1551 if (i < 0) | |
1552 return TRUE; | |
1553 } | |
1554 return FALSE; | |
1555 } | |
1556 | |
1557 /* | |
1558 * We stop parsing syntax above line "lnum". If the stored state at or below | |
1559 * this line depended on a change before it, it now depends on the line below | |
1560 * the last parsed line. | |
1561 * The window looks like this: | |
1562 * line which changed | |
1563 * displayed line | |
1564 * displayed line | |
1565 * lnum -> line below window | |
1566 */ | |
1567 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1568 syntax_end_parsing(linenr_T lnum) |
7 | 1569 { |
1570 synstate_T *sp; | |
1571 | |
1572 sp = syn_stack_find_entry(lnum); | |
1573 if (sp != NULL && sp->sst_lnum < lnum) | |
1574 sp = sp->sst_next; | |
1575 | |
1576 if (sp != NULL && sp->sst_change_lnum != 0) | |
1577 sp->sst_change_lnum = lnum; | |
1578 } | |
1579 | |
1580 /* | |
1581 * End of handling of the state stack. | |
1582 ****************************************/ | |
1583 | |
1584 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1585 invalidate_current_state(void) |
7 | 1586 { |
1587 clear_current_state(); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1588 current_state.ga_itemsize = 0; // mark current_state invalid |
7 | 1589 current_next_list = NULL; |
1590 keepend_level = -1; | |
1591 } | |
1592 | |
1593 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1594 validate_current_state(void) |
7 | 1595 { |
1596 current_state.ga_itemsize = sizeof(stateitem_T); | |
1597 current_state.ga_growsize = 3; | |
1598 } | |
1599 | |
1600 /* | |
1601 * Return TRUE if the syntax at start of lnum changed since last time. | |
1602 * This will only be called just after get_syntax_attr() for the previous | |
1603 * line, to check if the next line needs to be redrawn too. | |
1604 */ | |
1605 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1606 syntax_check_changed(linenr_T lnum) |
7 | 1607 { |
1608 int retval = TRUE; | |
1609 synstate_T *sp; | |
1610 | |
1611 /* | |
1612 * Check the state stack when: | |
1613 * - lnum is just below the previously syntaxed line. | |
1614 * - lnum is not before the lines with saved states. | |
1615 * - lnum is not past the lines with saved states. | |
1616 * - lnum is at or before the last changed line. | |
1617 */ | |
1618 if (VALID_STATE(¤t_state) && lnum == current_lnum + 1) | |
1619 { | |
1620 sp = syn_stack_find_entry(lnum); | |
1621 if (sp != NULL && sp->sst_lnum == lnum) | |
1622 { | |
1623 /* | |
1624 * finish the previous line (needed when not all of the line was | |
1625 * drawn) | |
1626 */ | |
1627 (void)syn_finish_line(FALSE); | |
1628 | |
1629 /* | |
1630 * Compare the current state with the previously saved state of | |
1631 * the line. | |
1632 */ | |
1633 if (syn_stack_equal(sp)) | |
1634 retval = FALSE; | |
1635 | |
1636 /* | |
1637 * Store the current state in b_sst_array[] for later use. | |
1638 */ | |
1639 ++current_lnum; | |
1512 | 1640 (void)store_current_state(); |
7 | 1641 } |
1642 } | |
1643 | |
1644 return retval; | |
1645 } | |
1646 | |
1647 /* | |
1648 * Finish the current line. | |
1649 * This doesn't return any attributes, it only gets the state at the end of | |
1650 * the line. It can start anywhere in the line, as long as the current state | |
1651 * is valid. | |
1652 */ | |
1653 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1654 syn_finish_line( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1655 int syncing) // called for syncing |
7 | 1656 { |
1657 stateitem_T *cur_si; | |
442 | 1658 colnr_T prev_current_col; |
7 | 1659 |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1660 while (!current_finished) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1661 { |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1662 (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
|
1663 /* |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1664 * 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
|
1665 */ |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1666 if (syncing && current_state.ga_len) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1667 { |
7 | 1668 /* |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1669 * Check for match with sync item. |
7 | 1670 */ |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1671 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
|
1672 if (cur_si->si_idx >= 0 |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1673 && (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
|
1674 & (HL_SYNC_HERE|HL_SYNC_THERE))) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1675 return TRUE; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1676 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1677 // syn_current_attr() will have skipped the check for an item |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1678 // that ends here, need to do that now. Be careful not to go |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1679 // past the NUL. |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1680 prev_current_col = current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1681 if (syn_getcurline()[current_col] != NUL) |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1682 ++current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1683 check_state_ends(); |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1684 current_col = prev_current_col; |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1685 } |
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1686 ++current_col; |
7 | 1687 } |
1688 return FALSE; | |
1689 } | |
1690 | |
1691 /* | |
1692 * Return highlight attributes for next character. | |
1693 * Must first call syntax_start() once for the line. | |
1694 * "col" is normally 0 for the first use in a line, and increments by one each | |
1695 * time. It's allowed to skip characters and to stop before the end of the | |
1696 * line. But only a "col" after a previously used column is allowed. | |
221 | 1697 * When "can_spell" is not NULL set it to TRUE when spell-checking should be |
1698 * done. | |
7 | 1699 */ |
1700 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1701 get_syntax_attr( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1702 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1703 int *can_spell, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1704 int keep_state) // keep state of char at "col" |
7 | 1705 { |
1706 int attr = 0; | |
1707 | |
1363 | 1708 if (can_spell != NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1709 // Default: Only do spelling when there is no @Spell cluster or when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1710 // ":syn spell toplevel" was used. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1711 *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
|
1712 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1713 : (syn_block->b_syn_spell == SYNSPL_TOP); |
1363 | 1714 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1715 // check for out of memory situation |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1716 if (syn_block->b_sst_array == NULL) |
7 | 1717 return 0; |
1718 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1719 // After 'synmaxcol' the attribute is always zero. |
431 | 1720 if (syn_buf->b_p_smc > 0 && col >= (colnr_T)syn_buf->b_p_smc) |
419 | 1721 { |
1722 clear_current_state(); | |
1723 #ifdef FEAT_EVAL | |
1724 current_id = 0; | |
1725 current_trans_id = 0; | |
1726 #endif | |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1727 #ifdef FEAT_CONCEAL |
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1728 current_flags = 0; |
11579
52e3a77c097b
patch 8.0.0672: third item of synconcealed() changes too often
Christian Brabandt <cb@256bit.org>
parents:
11541
diff
changeset
|
1729 current_seqnr = 0; |
2401
e7751177126b
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2392
diff
changeset
|
1730 #endif |
419 | 1731 return 0; |
1732 } | |
1733 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1734 // Make sure current_state is valid |
7 | 1735 if (INVALID_STATE(¤t_state)) |
1736 validate_current_state(); | |
1737 | |
1738 /* | |
1739 * Skip from the current column to "col", get the attributes for "col". | |
1740 */ | |
1741 while (current_col <= col) | |
1742 { | |
1504 | 1743 attr = syn_current_attr(FALSE, TRUE, can_spell, |
1744 current_col == col ? keep_state : FALSE); | |
7 | 1745 ++current_col; |
1746 } | |
1747 | |
1748 return attr; | |
1749 } | |
1750 | |
1751 /* | |
1752 * Get syntax attributes for current_lnum, current_col. | |
1753 */ | |
1754 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
1755 syn_current_attr( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1756 int syncing, // When 1: called for syncing |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1757 int displaying, // result will be displayed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1758 int *can_spell, // return: do spell checking |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1759 int keep_state) // keep syntax stack afterwards |
7 | 1760 { |
1761 int syn_id; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1762 lpos_T endpos; // was: char_u *endp; |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1763 lpos_T hl_startpos; // was: int hl_startcol; |
7 | 1764 lpos_T hl_endpos; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1765 lpos_T eos_pos; // end-of-start match (start region) |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1766 lpos_T eoe_pos; // end-of-end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1767 int end_idx; // group ID for end pattern |
7 | 1768 int idx; |
1769 synpat_T *spp; | |
221 | 1770 stateitem_T *cur_si, *sip = NULL; |
7 | 1771 int startcol; |
1772 int endcol; | |
1773 long flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1774 int cchar; |
7 | 1775 short *next_list; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1776 int found_match; // found usable match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1777 static int try_next_column = FALSE; // must try in next col |
7 | 1778 int do_keywords; |
1779 regmmatch_T regmatch; | |
1780 lpos_T pos; | |
1781 int lc_col; | |
1782 reg_extmatch_T *cur_extmatch = NULL; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1783 char_u buf_chartab[32]; // chartab array for syn iskyeyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1784 char_u *line; // current line. NOTE: becomes invalid after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1785 // looking for a pattern match! |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1786 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1787 // variables for zero-width matches that have a "nextgroup" argument |
7 | 1788 int keep_next_list; |
1789 int zero_width_next_list = FALSE; | |
1790 garray_T zero_width_next_ga; | |
1791 | |
1792 /* | |
1793 * No character, no attributes! Past end of line? | |
1794 * Do try matching with an empty line (could be the start of a region). | |
1795 */ | |
1796 line = syn_getcurline(); | |
1797 if (line[current_col] == NUL && current_col != 0) | |
1798 { | |
1799 /* | |
1800 * If we found a match after the last column, use it. | |
1801 */ | |
1802 if (next_match_idx >= 0 && next_match_col >= (int)current_col | |
1803 && next_match_col != MAXCOL) | |
1804 (void)push_next_match(NULL); | |
1805 | |
1806 current_finished = TRUE; | |
1807 current_state_stored = FALSE; | |
1808 return 0; | |
1809 } | |
1810 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1811 // if the current or next character is NUL, we will finish the line now |
7 | 1812 if (line[current_col] == NUL || line[current_col + 1] == NUL) |
1813 { | |
1814 current_finished = TRUE; | |
1815 current_state_stored = FALSE; | |
1816 } | |
1817 | |
1818 /* | |
1819 * When in the previous column there was a match but it could not be used | |
1820 * (empty match or already matched in this column) need to try again in | |
1821 * the next column. | |
1822 */ | |
1823 if (try_next_column) | |
1824 { | |
1825 next_match_idx = -1; | |
1826 try_next_column = FALSE; | |
1827 } | |
1828 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1829 // Only check for keywords when not syncing and there are some. |
7 | 1830 do_keywords = !syncing |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1831 && (syn_block->b_keywtab.ht_used > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1832 || syn_block->b_keywtab_ic.ht_used > 0); |
7 | 1833 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1834 // Init the list of zero-width matches with a nextlist. This is used to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1835 // avoid matching the same item in the same position twice. |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1836 ga_init2(&zero_width_next_ga, sizeof(int), 10); |
7 | 1837 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1838 // use syntax iskeyword option |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1839 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1840 |
7 | 1841 /* |
1842 * Repeat matching keywords and patterns, to find contained items at the | |
1843 * same column. This stops when there are no extra matches at the current | |
1844 * column. | |
1845 */ | |
1846 do | |
1847 { | |
1848 found_match = FALSE; | |
1849 keep_next_list = FALSE; | |
1850 syn_id = 0; | |
1851 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
1852 |
7 | 1853 /* |
1854 * 1. Check for a current state. | |
1855 * Only when there is no current state, or if the current state may | |
1856 * contain other things, we need to check for keywords and patterns. | |
1857 * Always need to check for contained items if some item has the | |
1858 * "containedin" argument (takes extra time!). | |
1859 */ | |
1860 if (current_state.ga_len) | |
1861 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1862 else | |
1863 cur_si = NULL; | |
1864 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1865 if (syn_block->b_syn_containedin || cur_si == NULL |
7 | 1866 || cur_si->si_cont_list != NULL) |
1867 { | |
1868 /* | |
1869 * 2. Check for keywords, if on a keyword char after a non-keyword | |
1870 * char. Don't do this when syncing. | |
1871 */ | |
1872 if (do_keywords) | |
1873 { | |
1874 line = syn_getcurline(); | |
4043 | 1875 if (vim_iswordp_buf(line + current_col, syn_buf) |
7 | 1876 && (current_col == 0 |
4043 | 1877 || !vim_iswordp_buf(line + current_col - 1 |
7 | 1878 - (has_mbyte |
1879 ? (*mb_head_off)(line, line + current_col - 1) | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1880 : 0) , syn_buf))) |
7 | 1881 { |
1882 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
|
1883 &endcol, &flags, &next_list, cur_si, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1884 &cchar); |
205 | 1885 if (syn_id != 0) |
7 | 1886 { |
1887 if (push_current_state(KEYWORD_IDX) == OK) | |
1888 { | |
1889 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
1890 cur_si->si_m_startcol = current_col; | |
1891 cur_si->si_h_startpos.lnum = current_lnum; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1892 cur_si->si_h_startpos.col = 0; // starts right away |
7 | 1893 cur_si->si_m_endpos.lnum = current_lnum; |
1894 cur_si->si_m_endpos.col = endcol; | |
1895 cur_si->si_h_endpos.lnum = current_lnum; | |
1896 cur_si->si_h_endpos.col = endcol; | |
1897 cur_si->si_ends = TRUE; | |
1898 cur_si->si_end_idx = 0; | |
1899 cur_si->si_flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1900 #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
|
1901 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
|
1902 cur_si->si_cchar = cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1903 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1904 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1905 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
|
1906 & HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1907 #endif |
7 | 1908 cur_si->si_id = syn_id; |
1909 cur_si->si_trans_id = syn_id; | |
1910 if (flags & HL_TRANSP) | |
1911 { | |
1912 if (current_state.ga_len < 2) | |
1913 { | |
1914 cur_si->si_attr = 0; | |
1915 cur_si->si_trans_id = 0; | |
1916 } | |
1917 else | |
1918 { | |
1919 cur_si->si_attr = CUR_STATE( | |
1920 current_state.ga_len - 2).si_attr; | |
1921 cur_si->si_trans_id = CUR_STATE( | |
1922 current_state.ga_len - 2).si_trans_id; | |
1923 } | |
1924 } | |
1925 else | |
1926 cur_si->si_attr = syn_id2attr(syn_id); | |
1927 cur_si->si_cont_list = NULL; | |
1928 cur_si->si_next_list = next_list; | |
1929 check_keepend(); | |
1930 } | |
1931 else | |
1932 vim_free(next_list); | |
1933 } | |
1934 } | |
1935 } | |
1936 | |
1937 /* | |
205 | 1938 * 3. Check for patterns (only if no keyword found). |
7 | 1939 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1940 if (syn_id == 0 && syn_block->b_syn_patterns.ga_len) |
7 | 1941 { |
1942 /* | |
1943 * If we didn't check for a match yet, or we are past it, check | |
1944 * for any match with a pattern. | |
1945 */ | |
1946 if (next_match_idx < 0 || next_match_col < (int)current_col) | |
1947 { | |
1948 /* | |
1949 * Check all relevant patterns for a match at this | |
1950 * position. This is complicated, because matching with a | |
1951 * pattern takes quite a bit of time, thus we want to | |
1952 * avoid doing it when it's not needed. | |
1953 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1954 next_match_idx = 0; // no match in this line yet |
7 | 1955 next_match_col = MAXCOL; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1956 for (idx = syn_block->b_syn_patterns.ga_len; --idx >= 0; ) |
7 | 1957 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1958 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 1959 if ( spp->sp_syncing == syncing |
1960 && (displaying || !(spp->sp_flags & HL_DISPLAY)) | |
1961 && (spp->sp_type == SPTYPE_MATCH | |
1962 || spp->sp_type == SPTYPE_START) | |
1963 && (current_next_list != NULL | |
1964 ? in_id_list(NULL, current_next_list, | |
1965 &spp->sp_syn, 0) | |
1966 : (cur_si == NULL | |
1967 ? !(spp->sp_flags & HL_CONTAINED) | |
1968 : in_id_list(cur_si, | |
1969 cur_si->si_cont_list, &spp->sp_syn, | |
1970 spp->sp_flags & HL_CONTAINED)))) | |
1971 { | |
6375 | 1972 int r; |
1973 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1974 // If we already tried matching in this line, and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1975 // there isn't a match before next_match_col, skip |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1976 // this item. |
7 | 1977 if (spp->sp_line_id == current_line_id |
1978 && spp->sp_startcol >= next_match_col) | |
1979 continue; | |
1980 spp->sp_line_id = current_line_id; | |
1981 | |
1982 lc_col = current_col - spp->sp_offsets[SPO_LC_OFF]; | |
1983 if (lc_col < 0) | |
1984 lc_col = 0; | |
1985 | |
1986 regmatch.rmm_ic = spp->sp_ic; | |
1987 regmatch.regprog = spp->sp_prog; | |
6375 | 1988 r = syn_regexec(®match, |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1989 current_lnum, |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1990 (colnr_T)lc_col, |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1991 IF_SYN_TIME(&spp->sp_time)); |
6375 | 1992 spp->sp_prog = regmatch.regprog; |
1993 if (!r) | |
7 | 1994 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
1995 // no match in this line, try another one |
7 | 1996 spp->sp_startcol = MAXCOL; |
1997 continue; | |
1998 } | |
1999 | |
2000 /* | |
2001 * Compute the first column of the match. | |
2002 */ | |
2003 syn_add_start_off(&pos, ®match, | |
2004 spp, SPO_MS_OFF, -1); | |
2005 if (pos.lnum > current_lnum) | |
2006 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2007 // must have used end of match in a next line, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2008 // we can't handle that |
7 | 2009 spp->sp_startcol = MAXCOL; |
2010 continue; | |
2011 } | |
2012 startcol = pos.col; | |
2013 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2014 // remember the next column where this pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2015 // matches in the current line |
7 | 2016 spp->sp_startcol = startcol; |
2017 | |
2018 /* | |
2019 * If a previously found match starts at a lower | |
2020 * column number, don't use this one. | |
2021 */ | |
2022 if (startcol >= next_match_col) | |
2023 continue; | |
2024 | |
2025 /* | |
2026 * If we matched this pattern at this position | |
2027 * before, skip it. Must retry in the next | |
2028 * column, because it may match from there. | |
2029 */ | |
2030 if (did_match_already(idx, &zero_width_next_ga)) | |
2031 { | |
2032 try_next_column = TRUE; | |
2033 continue; | |
2034 } | |
2035 | |
2036 endpos.lnum = regmatch.endpos[0].lnum; | |
2037 endpos.col = regmatch.endpos[0].col; | |
2038 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2039 // Compute the highlight start. |
7 | 2040 syn_add_start_off(&hl_startpos, ®match, |
2041 spp, SPO_HS_OFF, -1); | |
2042 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2043 // Compute the region start. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2044 // Default is to use the end of the match. |
7 | 2045 syn_add_end_off(&eos_pos, ®match, |
2046 spp, SPO_RS_OFF, 0); | |
2047 | |
2048 /* | |
2049 * Grab the external submatches before they get | |
2050 * overwritten. Reference count doesn't change. | |
2051 */ | |
2052 unref_extmatch(cur_extmatch); | |
2053 cur_extmatch = re_extmatch_out; | |
2054 re_extmatch_out = NULL; | |
2055 | |
2056 flags = 0; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2057 eoe_pos.lnum = 0; // avoid warning |
7 | 2058 eoe_pos.col = 0; |
2059 end_idx = 0; | |
2060 hl_endpos.lnum = 0; | |
2061 | |
2062 /* | |
2063 * For a "oneline" the end must be found in the | |
2064 * same line too. Search for it after the end of | |
2065 * the match with the start pattern. Set the | |
2066 * resulting end positions at the same time. | |
2067 */ | |
2068 if (spp->sp_type == SPTYPE_START | |
2069 && (spp->sp_flags & HL_ONELINE)) | |
2070 { | |
2071 lpos_T startpos; | |
2072 | |
2073 startpos = endpos; | |
2074 find_endpos(idx, &startpos, &endpos, &hl_endpos, | |
2075 &flags, &eoe_pos, &end_idx, cur_extmatch); | |
2076 if (endpos.lnum == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2077 continue; // not found |
7 | 2078 } |
2079 | |
2080 /* | |
2081 * For a "match" the size must be > 0 after the | |
2082 * end offset needs has been added. Except when | |
2083 * syncing. | |
2084 */ | |
2085 else if (spp->sp_type == SPTYPE_MATCH) | |
2086 { | |
2087 syn_add_end_off(&hl_endpos, ®match, spp, | |
2088 SPO_HE_OFF, 0); | |
2089 syn_add_end_off(&endpos, ®match, spp, | |
2090 SPO_ME_OFF, 0); | |
2091 if (endpos.lnum == current_lnum | |
2092 && (int)endpos.col + syncing < startcol) | |
2093 { | |
2094 /* | |
2095 * If an empty string is matched, may need | |
2096 * to try matching again at next column. | |
2097 */ | |
2098 if (regmatch.startpos[0].col | |
2099 == regmatch.endpos[0].col) | |
2100 try_next_column = TRUE; | |
2101 continue; | |
2102 } | |
2103 } | |
2104 | |
2105 /* | |
2106 * keep the best match so far in next_match_* | |
2107 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2108 // Highlighting must start after startpos and end |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2109 // before endpos. |
7 | 2110 if (hl_startpos.lnum == current_lnum |
2111 && (int)hl_startpos.col < startcol) | |
2112 hl_startpos.col = startcol; | |
2113 limit_pos_zero(&hl_endpos, &endpos); | |
2114 | |
2115 next_match_idx = idx; | |
2116 next_match_col = startcol; | |
2117 next_match_m_endpos = endpos; | |
2118 next_match_h_endpos = hl_endpos; | |
2119 next_match_h_startpos = hl_startpos; | |
2120 next_match_flags = flags; | |
2121 next_match_eos_pos = eos_pos; | |
2122 next_match_eoe_pos = eoe_pos; | |
2123 next_match_end_idx = end_idx; | |
2124 unref_extmatch(next_match_extmatch); | |
2125 next_match_extmatch = cur_extmatch; | |
2126 cur_extmatch = NULL; | |
2127 } | |
2128 } | |
2129 } | |
2130 | |
2131 /* | |
2132 * If we found a match at the current column, use it. | |
2133 */ | |
2134 if (next_match_idx >= 0 && next_match_col == (int)current_col) | |
2135 { | |
2136 synpat_T *lspp; | |
2137 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2138 // When a zero-width item matched which has a nextgroup, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2139 // 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
|
2140 lspp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2141 if (next_match_m_endpos.lnum == current_lnum |
2142 && next_match_m_endpos.col == current_col | |
2143 && lspp->sp_next_list != NULL) | |
2144 { | |
2145 current_next_list = lspp->sp_next_list; | |
2146 current_next_flags = lspp->sp_flags; | |
2147 keep_next_list = TRUE; | |
2148 zero_width_next_list = TRUE; | |
2149 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2150 // Add the index to a list, so that we can check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2151 // later that we don't match it again (and cause an |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2152 // endless loop). |
7 | 2153 if (ga_grow(&zero_width_next_ga, 1) == OK) |
2154 { | |
2155 ((int *)(zero_width_next_ga.ga_data)) | |
2156 [zero_width_next_ga.ga_len++] = next_match_idx; | |
2157 } | |
2158 next_match_idx = -1; | |
2159 } | |
2160 else | |
2161 cur_si = push_next_match(cur_si); | |
2162 found_match = TRUE; | |
2163 } | |
2164 } | |
2165 } | |
2166 | |
2167 /* | |
2168 * Handle searching for nextgroup match. | |
2169 */ | |
2170 if (current_next_list != NULL && !keep_next_list) | |
2171 { | |
2172 /* | |
2173 * If a nextgroup was not found, continue looking for one if: | |
2174 * - this is an empty line and the "skipempty" option was given | |
2175 * - we are on white space and the "skipwhite" option was given | |
2176 */ | |
2177 if (!found_match) | |
2178 { | |
2179 line = syn_getcurline(); | |
2180 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
|
2181 && VIM_ISWHITE(line[current_col])) |
7 | 2182 || ((current_next_flags & HL_SKIPEMPTY) |
2183 && *line == NUL)) | |
2184 break; | |
2185 } | |
2186 | |
2187 /* | |
2188 * If a nextgroup was found: Use it, and continue looking for | |
2189 * contained matches. | |
2190 * If a nextgroup was not found: Continue looking for a normal | |
2191 * match. | |
2192 * When did set current_next_list for a zero-width item and no | |
2193 * match was found don't loop (would get stuck). | |
2194 */ | |
2195 current_next_list = NULL; | |
2196 next_match_idx = -1; | |
2197 if (!zero_width_next_list) | |
2198 found_match = TRUE; | |
2199 } | |
2200 | |
2201 } while (found_match); | |
2202 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2203 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2204 |
7 | 2205 /* |
2206 * Use attributes from the current state, if within its highlighting. | |
2207 * If not, use attributes from the current-but-one state, etc. | |
2208 */ | |
2209 current_attr = 0; | |
2210 #ifdef FEAT_EVAL | |
2211 current_id = 0; | |
2212 current_trans_id = 0; | |
2213 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2214 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2215 current_flags = 0; |
11579
52e3a77c097b
patch 8.0.0672: third item of synconcealed() changes too often
Christian Brabandt <cb@256bit.org>
parents:
11541
diff
changeset
|
2216 current_seqnr = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2217 #endif |
7 | 2218 if (cur_si != NULL) |
2219 { | |
221 | 2220 #ifndef FEAT_EVAL |
2221 int current_trans_id = 0; | |
2222 #endif | |
7 | 2223 for (idx = current_state.ga_len - 1; idx >= 0; --idx) |
2224 { | |
2225 sip = &CUR_STATE(idx); | |
2226 if ((current_lnum > sip->si_h_startpos.lnum | |
2227 || (current_lnum == sip->si_h_startpos.lnum | |
2228 && current_col >= sip->si_h_startpos.col)) | |
2229 && (sip->si_h_endpos.lnum == 0 | |
2230 || current_lnum < sip->si_h_endpos.lnum | |
2231 || (current_lnum == sip->si_h_endpos.lnum | |
2232 && current_col < sip->si_h_endpos.col))) | |
2233 { | |
2234 current_attr = sip->si_attr; | |
2235 #ifdef FEAT_EVAL | |
2236 current_id = sip->si_id; | |
221 | 2237 #endif |
7 | 2238 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
|
2239 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2240 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
|
2241 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
|
2242 current_sub_char = sip->si_cchar; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2243 #endif |
7 | 2244 break; |
2245 } | |
2246 } | |
2247 | |
221 | 2248 if (can_spell != NULL) |
2249 { | |
2250 struct sp_syn sps; | |
2251 | |
2252 /* | |
2253 * set "can_spell" to TRUE if spell checking is supposed to be | |
2254 * done in the current item. | |
2255 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2256 if (syn_block->b_spell_cluster_id == 0) |
227 | 2257 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2258 // There is no @Spell cluster: Do spelling for items without |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2259 // @NoSpell cluster. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2260 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
|
2261 || current_trans_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2262 *can_spell = (syn_block->b_syn_spell != SYNSPL_NOTOP); |
227 | 2263 else |
2264 { | |
2265 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2266 sps.id = syn_block->b_nospell_cluster_id; |
227 | 2267 sps.cont_in_list = NULL; |
2268 *can_spell = !in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2269 } | |
2270 } | |
221 | 2271 else |
2272 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2273 // The @Spell cluster is defined: Do spelling in items with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2274 // the @Spell cluster. But not when @NoSpell is also there. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2275 // At the toplevel only spell check when ":syn spell toplevel" |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2276 // was used. |
320 | 2277 if (current_trans_id == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2278 *can_spell = (syn_block->b_syn_spell == SYNSPL_TOP); |
320 | 2279 else |
2280 { | |
2281 sps.inc_tag = 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2282 sps.id = syn_block->b_spell_cluster_id; |
320 | 2283 sps.cont_in_list = NULL; |
2284 *can_spell = in_id_list(sip, sip->si_cont_list, &sps, 0); | |
2285 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2286 if (syn_block->b_nospell_cluster_id != 0) |
320 | 2287 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2288 sps.id = syn_block->b_nospell_cluster_id; |
320 | 2289 if (in_id_list(sip, sip->si_cont_list, &sps, 0)) |
2290 *can_spell = FALSE; | |
2291 } | |
2292 } | |
221 | 2293 } |
2294 } | |
2295 | |
2296 | |
7 | 2297 /* |
2298 * Check for end of current state (and the states before it) at the | |
2299 * next column. Don't do this for syncing, because we would miss a | |
2300 * single character match. | |
2301 * First check if the current state ends at the current column. It | |
2302 * may be for an empty match and a containing item might end in the | |
2303 * current column. | |
2304 */ | |
1504 | 2305 if (!syncing && !keep_state) |
7 | 2306 { |
2307 check_state_ends(); | |
442 | 2308 if (current_state.ga_len > 0 |
2309 && syn_getcurline()[current_col] != NUL) | |
7 | 2310 { |
2311 ++current_col; | |
2312 check_state_ends(); | |
2313 --current_col; | |
2314 } | |
2315 } | |
2316 } | |
221 | 2317 else if (can_spell != NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2318 // Default: Only do spelling when there is no @Spell cluster or when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2319 // ":syn spell toplevel" was used. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2320 *can_spell = syn_block->b_syn_spell == SYNSPL_DEFAULT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2321 ? (syn_block->b_spell_cluster_id == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2322 : (syn_block->b_syn_spell == SYNSPL_TOP); |
7 | 2323 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2324 // nextgroup ends at end of line, unless "skipnl" or "skipempty" present |
7 | 2325 if (current_next_list != NULL |
13375
33f514c94943
patch 8.0.1561: crash with rust syntax highligting
Christian Brabandt <cb@256bit.org>
parents:
13339
diff
changeset
|
2326 && (line = syn_getcurline())[current_col] != NUL |
33f514c94943
patch 8.0.1561: crash with rust syntax highligting
Christian Brabandt <cb@256bit.org>
parents:
13339
diff
changeset
|
2327 && line[current_col + 1] == NUL |
7 | 2328 && !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY))) |
2329 current_next_list = NULL; | |
2330 | |
2331 if (zero_width_next_ga.ga_len > 0) | |
2332 ga_clear(&zero_width_next_ga); | |
2333 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2334 // No longer need external matches. But keep next_match_extmatch. |
7 | 2335 unref_extmatch(re_extmatch_out); |
2336 re_extmatch_out = NULL; | |
2337 unref_extmatch(cur_extmatch); | |
2338 | |
2339 return current_attr; | |
2340 } | |
2341 | |
2342 | |
2343 /* | |
2344 * Check if we already matched pattern "idx" at the current column. | |
2345 */ | |
2346 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2347 did_match_already(int idx, garray_T *gap) |
7 | 2348 { |
2349 int i; | |
2350 | |
2351 for (i = current_state.ga_len; --i >= 0; ) | |
2352 if (CUR_STATE(i).si_m_startcol == (int)current_col | |
2353 && CUR_STATE(i).si_m_lnum == (int)current_lnum | |
2354 && CUR_STATE(i).si_idx == idx) | |
2355 return TRUE; | |
2356 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2357 // Zero-width matches with a nextgroup argument are not put on the syntax |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2358 // stack, and can only be matched once anyway. |
7 | 2359 for (i = gap->ga_len; --i >= 0; ) |
2360 if (((int *)(gap->ga_data))[i] == idx) | |
2361 return TRUE; | |
2362 | |
2363 return FALSE; | |
2364 } | |
2365 | |
2366 /* | |
2367 * Push the next match onto the stack. | |
2368 */ | |
2369 static stateitem_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2370 push_next_match(stateitem_T *cur_si) |
7 | 2371 { |
2372 synpat_T *spp; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2373 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2374 int save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2375 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2376 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2377 spp = &(SYN_ITEMS(syn_block)[next_match_idx]); |
7 | 2378 |
2379 /* | |
2380 * Push the item in current_state stack; | |
2381 */ | |
2382 if (push_current_state(next_match_idx) == OK) | |
2383 { | |
2384 /* | |
2385 * If it's a start-skip-end type that crosses lines, figure out how | |
2386 * much it continues in this line. Otherwise just fill in the length. | |
2387 */ | |
2388 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2389 cur_si->si_h_startpos = next_match_h_startpos; | |
2390 cur_si->si_m_startcol = current_col; | |
2391 cur_si->si_m_lnum = current_lnum; | |
2392 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
|
2393 #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
|
2394 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
|
2395 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
|
2396 if (current_state.ga_len > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2397 cur_si->si_flags |= |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2398 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
|
2399 #endif |
7 | 2400 cur_si->si_next_list = spp->sp_next_list; |
2401 cur_si->si_extmatch = ref_extmatch(next_match_extmatch); | |
2402 if (spp->sp_type == SPTYPE_START && !(spp->sp_flags & HL_ONELINE)) | |
2403 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2404 // Try to find the end pattern in the current line |
7 | 2405 update_si_end(cur_si, (int)(next_match_m_endpos.col), TRUE); |
2406 check_keepend(); | |
2407 } | |
2408 else | |
2409 { | |
2410 cur_si->si_m_endpos = next_match_m_endpos; | |
2411 cur_si->si_h_endpos = next_match_h_endpos; | |
2412 cur_si->si_ends = TRUE; | |
2413 cur_si->si_flags |= next_match_flags; | |
2414 cur_si->si_eoe_pos = next_match_eoe_pos; | |
2415 cur_si->si_end_idx = next_match_end_idx; | |
2416 } | |
2417 if (keepend_level < 0 && (cur_si->si_flags & HL_KEEPEND)) | |
2418 keepend_level = current_state.ga_len - 1; | |
2419 check_keepend(); | |
2420 update_si_attr(current_state.ga_len - 1); | |
2421 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2422 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2423 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
|
2424 #endif |
7 | 2425 /* |
2426 * If the start pattern has another highlight group, push another item | |
2427 * on the stack for the start pattern. | |
2428 */ | |
2429 if ( spp->sp_type == SPTYPE_START | |
2430 && spp->sp_syn_match_id != 0 | |
2431 && push_current_state(next_match_idx) == OK) | |
2432 { | |
2433 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2434 cur_si->si_h_startpos = next_match_h_startpos; | |
2435 cur_si->si_m_startcol = current_col; | |
2436 cur_si->si_m_lnum = current_lnum; | |
2437 cur_si->si_m_endpos = next_match_eos_pos; | |
2438 cur_si->si_h_endpos = next_match_eos_pos; | |
2439 cur_si->si_ends = TRUE; | |
2440 cur_si->si_end_idx = 0; | |
2441 cur_si->si_flags = HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2442 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2443 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2444 cur_si->si_flags |= save_flags; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2445 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2446 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2447 #endif |
7 | 2448 cur_si->si_next_list = NULL; |
2449 check_keepend(); | |
2450 update_si_attr(current_state.ga_len - 1); | |
2451 } | |
2452 } | |
2453 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2454 next_match_idx = -1; // try other match next time |
7 | 2455 |
2456 return cur_si; | |
2457 } | |
2458 | |
2459 /* | |
2460 * Check for end of current state (and the states before it). | |
2461 */ | |
2462 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2463 check_state_ends(void) |
7 | 2464 { |
2465 stateitem_T *cur_si; | |
2863 | 2466 int had_extend; |
7 | 2467 |
2468 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2469 for (;;) | |
2470 { | |
2471 if (cur_si->si_ends | |
2472 && (cur_si->si_m_endpos.lnum < current_lnum | |
2473 || (cur_si->si_m_endpos.lnum == current_lnum | |
2474 && cur_si->si_m_endpos.col <= current_col))) | |
2475 { | |
2476 /* | |
2477 * If there is an end pattern group ID, highlight the end pattern | |
2478 * now. No need to pop the current item from the stack. | |
2479 * Only do this if the end pattern continues beyond the current | |
2480 * position. | |
2481 */ | |
2482 if (cur_si->si_end_idx | |
2483 && (cur_si->si_eoe_pos.lnum > current_lnum | |
2484 || (cur_si->si_eoe_pos.lnum == current_lnum | |
2485 && cur_si->si_eoe_pos.col > current_col))) | |
2486 { | |
2487 cur_si->si_idx = cur_si->si_end_idx; | |
2488 cur_si->si_end_idx = 0; | |
2489 cur_si->si_m_endpos = cur_si->si_eoe_pos; | |
2490 cur_si->si_h_endpos = cur_si->si_eoe_pos; | |
2491 cur_si->si_flags |= HL_MATCH; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2492 #ifdef FEAT_CONCEAL |
2418
da067045878f
Fix for "concealends". (Vince Negri)
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
2493 cur_si->si_seqnr = next_seqnr++; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2494 if (cur_si->si_flags & HL_CONCEALENDS) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2495 cur_si->si_flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2496 #endif |
7 | 2497 update_si_attr(current_state.ga_len - 1); |
36 | 2498 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2499 // nextgroup= should not match in the end pattern |
2831 | 2500 current_next_list = NULL; |
2501 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2502 // what matches next may be different now, clear it |
36 | 2503 next_match_idx = 0; |
2504 next_match_col = MAXCOL; | |
7 | 2505 break; |
2506 } | |
2507 else | |
2508 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2509 // handle next_list, unless at end of line and no "skipnl" or |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2510 // "skipempty" |
7 | 2511 current_next_list = cur_si->si_next_list; |
2512 current_next_flags = cur_si->si_flags; | |
2513 if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) | |
2514 && syn_getcurline()[current_col] == NUL) | |
2515 current_next_list = NULL; | |
2516 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2517 // When the ended item has "extend", another item with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2518 // "keepend" now needs to check for its end. |
2863 | 2519 had_extend = (cur_si->si_flags & HL_EXTEND); |
7 | 2520 |
2521 pop_current_state(); | |
2522 | |
2523 if (current_state.ga_len == 0) | |
2524 break; | |
2525 | |
1503 | 2526 if (had_extend && keepend_level >= 0) |
7 | 2527 { |
2528 syn_update_ends(FALSE); | |
2529 if (current_state.ga_len == 0) | |
2530 break; | |
2531 } | |
2532 | |
2533 cur_si = &CUR_STATE(current_state.ga_len - 1); | |
2534 | |
2535 /* | |
2536 * Only for a region the search for the end continues after | |
2537 * the end of the contained item. If the contained match | |
2538 * included the end-of-line, break here, the region continues. | |
2539 * Don't do this when: | |
2540 * - "keepend" is used for the contained item | |
2541 * - not at the end of the line (could be end="x$"me=e-1). | |
2542 * - "excludenl" is used (HL_HAS_EOL won't be set) | |
2543 */ | |
2544 if (cur_si->si_idx >= 0 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2545 && SYN_ITEMS(syn_block)[cur_si->si_idx].sp_type |
7 | 2546 == SPTYPE_START |
2547 && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) | |
2548 { | |
2549 update_si_end(cur_si, (int)current_col, TRUE); | |
2550 check_keepend(); | |
2551 if ((current_next_flags & HL_HAS_EOL) | |
2552 && keepend_level < 0 | |
2553 && syn_getcurline()[current_col] == NUL) | |
2554 break; | |
2555 } | |
2556 } | |
2557 } | |
2558 else | |
2559 break; | |
2560 } | |
2561 } | |
2562 | |
2563 /* | |
2564 * Update an entry in the current_state stack for a match or region. This | |
2565 * fills in si_attr, si_next_list and si_cont_list. | |
2566 */ | |
2567 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2568 update_si_attr(int idx) |
7 | 2569 { |
2570 stateitem_T *sip = &CUR_STATE(idx); | |
2571 synpat_T *spp; | |
2572 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2573 // This should not happen... |
1371 | 2574 if (sip->si_idx < 0) |
2575 return; | |
2576 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2577 spp = &(SYN_ITEMS(syn_block)[sip->si_idx]); |
7 | 2578 if (sip->si_flags & HL_MATCH) |
2579 sip->si_id = spp->sp_syn_match_id; | |
2580 else | |
2581 sip->si_id = spp->sp_syn.id; | |
2582 sip->si_attr = syn_id2attr(sip->si_id); | |
2583 sip->si_trans_id = sip->si_id; | |
2584 if (sip->si_flags & HL_MATCH) | |
2585 sip->si_cont_list = NULL; | |
2586 else | |
2587 sip->si_cont_list = spp->sp_cont_list; | |
2588 | |
2589 /* | |
2590 * For transparent items, take attr from outer item. | |
2591 * Also take cont_list, if there is none. | |
2592 * Don't do this for the matchgroup of a start or end pattern. | |
2593 */ | |
2594 if ((spp->sp_flags & HL_TRANSP) && !(sip->si_flags & HL_MATCH)) | |
2595 { | |
2596 if (idx == 0) | |
2597 { | |
2598 sip->si_attr = 0; | |
2599 sip->si_trans_id = 0; | |
2600 if (sip->si_cont_list == NULL) | |
2601 sip->si_cont_list = ID_LIST_ALL; | |
2602 } | |
2603 else | |
2604 { | |
2605 sip->si_attr = CUR_STATE(idx - 1).si_attr; | |
2606 sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; | |
2607 if (sip->si_cont_list == NULL) | |
2608 { | |
2609 sip->si_flags |= HL_TRANS_CONT; | |
2610 sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; | |
2611 } | |
2612 } | |
2613 } | |
2614 } | |
2615 | |
2616 /* | |
2617 * Check the current stack for patterns with "keepend" flag. | |
2618 * Propagate the match-end to contained items, until a "skipend" item is found. | |
2619 */ | |
2620 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2621 check_keepend(void) |
7 | 2622 { |
2623 int i; | |
2624 lpos_T maxpos; | |
991 | 2625 lpos_T maxpos_h; |
7 | 2626 stateitem_T *sip; |
2627 | |
2628 /* | |
2629 * This check can consume a lot of time; only do it from the level where | |
2630 * there really is a keepend. | |
2631 */ | |
2632 if (keepend_level < 0) | |
2633 return; | |
2634 | |
2635 /* | |
2636 * Find the last index of an "extend" item. "keepend" items before that | |
2637 * won't do anything. If there is no "extend" item "i" will be | |
2638 * "keepend_level" and all "keepend" items will work normally. | |
2639 */ | |
2640 for (i = current_state.ga_len - 1; i > keepend_level; --i) | |
2641 if (CUR_STATE(i).si_flags & HL_EXTEND) | |
2642 break; | |
2643 | |
2644 maxpos.lnum = 0; | |
1702 | 2645 maxpos.col = 0; |
991 | 2646 maxpos_h.lnum = 0; |
1702 | 2647 maxpos_h.col = 0; |
7 | 2648 for ( ; i < current_state.ga_len; ++i) |
2649 { | |
2650 sip = &CUR_STATE(i); | |
2651 if (maxpos.lnum != 0) | |
2652 { | |
2653 limit_pos_zero(&sip->si_m_endpos, &maxpos); | |
991 | 2654 limit_pos_zero(&sip->si_h_endpos, &maxpos_h); |
7 | 2655 limit_pos_zero(&sip->si_eoe_pos, &maxpos); |
2656 sip->si_ends = TRUE; | |
2657 } | |
991 | 2658 if (sip->si_ends && (sip->si_flags & HL_KEEPEND)) |
2659 { | |
2660 if (maxpos.lnum == 0 | |
7 | 2661 || maxpos.lnum > sip->si_m_endpos.lnum |
2662 || (maxpos.lnum == sip->si_m_endpos.lnum | |
991 | 2663 && maxpos.col > sip->si_m_endpos.col)) |
2664 maxpos = sip->si_m_endpos; | |
2665 if (maxpos_h.lnum == 0 | |
2666 || maxpos_h.lnum > sip->si_h_endpos.lnum | |
2667 || (maxpos_h.lnum == sip->si_h_endpos.lnum | |
2668 && maxpos_h.col > sip->si_h_endpos.col)) | |
2669 maxpos_h = sip->si_h_endpos; | |
2670 } | |
7 | 2671 } |
2672 } | |
2673 | |
2674 /* | |
2675 * Update an entry in the current_state stack for a start-skip-end pattern. | |
2676 * This finds the end of the current item, if it's in the current line. | |
2677 * | |
2678 * Return the flags for the matched END. | |
2679 */ | |
2680 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2681 update_si_end( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2682 stateitem_T *sip, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2683 int startcol, // where to start searching for the end |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2684 int force) // when TRUE overrule a previous end |
7 | 2685 { |
2686 lpos_T startpos; | |
2687 lpos_T endpos; | |
2688 lpos_T hl_endpos; | |
2689 lpos_T end_endpos; | |
2690 int end_idx; | |
2691 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2692 // return quickly for a keyword |
1371 | 2693 if (sip->si_idx < 0) |
2694 return; | |
2695 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2696 // Don't update when it's already done. Can be a match of an end pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2697 // that started in a previous line. Watch out: can also be a "keepend" |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2698 // from a containing item. |
7 | 2699 if (!force && sip->si_m_endpos.lnum >= current_lnum) |
2700 return; | |
2701 | |
2702 /* | |
2703 * We need to find the end of the region. It may continue in the next | |
2704 * line. | |
2705 */ | |
2706 end_idx = 0; | |
2707 startpos.lnum = current_lnum; | |
2708 startpos.col = startcol; | |
2709 find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, | |
2710 &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); | |
2711 | |
2712 if (endpos.lnum == 0) | |
2713 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2714 // No end pattern matched. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2715 if (SYN_ITEMS(syn_block)[sip->si_idx].sp_flags & HL_ONELINE) |
7 | 2716 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2717 // a "oneline" never continues in the next line |
7 | 2718 sip->si_ends = TRUE; |
2719 sip->si_m_endpos.lnum = current_lnum; | |
2720 sip->si_m_endpos.col = (colnr_T)STRLEN(syn_getcurline()); | |
2721 } | |
2722 else | |
2723 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2724 // continues in the next line |
7 | 2725 sip->si_ends = FALSE; |
2726 sip->si_m_endpos.lnum = 0; | |
2727 } | |
2728 sip->si_h_endpos = sip->si_m_endpos; | |
2729 } | |
2730 else | |
2731 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2732 // match within this line |
7 | 2733 sip->si_m_endpos = endpos; |
2734 sip->si_h_endpos = hl_endpos; | |
2735 sip->si_eoe_pos = end_endpos; | |
2736 sip->si_ends = TRUE; | |
2737 sip->si_end_idx = end_idx; | |
2738 } | |
2739 } | |
2740 | |
2741 /* | |
2742 * Add a new state to the current state stack. | |
2743 * It is cleared and the index set to "idx". | |
2744 * Return FAIL if it's not possible (out of memory). | |
2745 */ | |
2746 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2747 push_current_state(int idx) |
7 | 2748 { |
2749 if (ga_grow(¤t_state, 1) == FAIL) | |
2750 return FAIL; | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
2751 CLEAR_POINTER(&CUR_STATE(current_state.ga_len)); |
7 | 2752 CUR_STATE(current_state.ga_len).si_idx = idx; |
2753 ++current_state.ga_len; | |
2754 return OK; | |
2755 } | |
2756 | |
2757 /* | |
2758 * Remove a state from the current_state stack. | |
2759 */ | |
2760 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2761 pop_current_state(void) |
7 | 2762 { |
2763 if (current_state.ga_len) | |
2764 { | |
2765 unref_extmatch(CUR_STATE(current_state.ga_len - 1).si_extmatch); | |
2766 --current_state.ga_len; | |
2767 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2768 // after the end of a pattern, try matching a keyword or pattern |
7 | 2769 next_match_idx = -1; |
2770 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2771 // if first state with "keepend" is popped, reset keepend_level |
7 | 2772 if (keepend_level >= current_state.ga_len) |
2773 keepend_level = -1; | |
2774 } | |
2775 | |
2776 /* | |
2777 * Find the end of a start/skip/end syntax region after "startpos". | |
2778 * Only checks one line. | |
2779 * Also handles a match item that continued from a previous line. | |
2780 * If not found, the syntax item continues in the next line. m_endpos->lnum | |
2781 * will be 0. | |
2782 * If found, the end of the region and the end of the highlighting is | |
2783 * computed. | |
2784 */ | |
2785 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2786 find_endpos( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2787 int idx, // index of the pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2788 lpos_T *startpos, // where to start looking for an END match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2789 lpos_T *m_endpos, // return: end of match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2790 lpos_T *hl_endpos, // return: end of highlighting |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2791 long *flagsp, // return: flags of matching END |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2792 lpos_T *end_endpos, // return: end of end pattern match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2793 int *end_idx, // return: group ID for end pat. match, or 0 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2794 reg_extmatch_T *start_ext) // submatches from the start pattern |
7 | 2795 { |
2796 colnr_T matchcol; | |
2797 synpat_T *spp, *spp_skip; | |
2798 int start_idx; | |
2799 int best_idx; | |
2800 regmmatch_T regmatch; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2801 regmmatch_T best_regmatch; // startpos/endpos of best match |
7 | 2802 lpos_T pos; |
2803 char_u *line; | |
2804 int had_match = FALSE; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2805 char_u buf_chartab[32]; // chartab array for syn option iskyeyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2806 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2807 // just in case we are invoked for a keyword |
1371 | 2808 if (idx < 0) |
2809 return; | |
2810 | |
7 | 2811 /* |
2812 * Check for being called with a START pattern. | |
2813 * Can happen with a match that continues to the next line, because it | |
2814 * contained a region. | |
2815 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2816 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2817 if (spp->sp_type != SPTYPE_START) |
2818 { | |
2819 *hl_endpos = *startpos; | |
2820 return; | |
2821 } | |
2822 | |
2823 /* | |
2824 * Find the SKIP or first END pattern after the last START pattern. | |
2825 */ | |
2826 for (;;) | |
2827 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2828 spp = &(SYN_ITEMS(syn_block)[idx]); |
7 | 2829 if (spp->sp_type != SPTYPE_START) |
2830 break; | |
2831 ++idx; | |
2832 } | |
2833 | |
2834 /* | |
2835 * Lookup the SKIP pattern (if present) | |
2836 */ | |
2837 if (spp->sp_type == SPTYPE_SKIP) | |
2838 { | |
2839 spp_skip = spp; | |
2840 ++idx; | |
2841 } | |
2842 else | |
2843 spp_skip = NULL; | |
2844 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2845 // Setup external matches for syn_regexec(). |
7 | 2846 unref_extmatch(re_extmatch_in); |
2847 re_extmatch_in = ref_extmatch(start_ext); | |
2848 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2849 matchcol = startpos->col; // start looking for a match at sstart |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2850 start_idx = idx; // remember the first END pattern. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2851 best_regmatch.startpos[0].col = 0; // avoid compiler warning |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2852 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2853 // use syntax iskeyword option |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2854 save_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
2855 |
7 | 2856 for (;;) |
2857 { | |
2858 /* | |
2859 * Find end pattern that matches first after "matchcol". | |
2860 */ | |
2861 best_idx = -1; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2862 for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; ++idx) |
7 | 2863 { |
2864 int lc_col = matchcol; | |
6375 | 2865 int r; |
7 | 2866 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2867 spp = &(SYN_ITEMS(syn_block)[idx]); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2868 if (spp->sp_type != SPTYPE_END) // past last END pattern |
7 | 2869 break; |
2870 lc_col -= spp->sp_offsets[SPO_LC_OFF]; | |
2871 if (lc_col < 0) | |
2872 lc_col = 0; | |
2873 | |
2874 regmatch.rmm_ic = spp->sp_ic; | |
2875 regmatch.regprog = spp->sp_prog; | |
6375 | 2876 r = syn_regexec(®match, startpos->lnum, lc_col, |
2877 IF_SYN_TIME(&spp->sp_time)); | |
2878 spp->sp_prog = regmatch.regprog; | |
2879 if (r) | |
7 | 2880 { |
2881 if (best_idx == -1 || regmatch.startpos[0].col | |
2882 < best_regmatch.startpos[0].col) | |
2883 { | |
2884 best_idx = idx; | |
2885 best_regmatch.startpos[0] = regmatch.startpos[0]; | |
2886 best_regmatch.endpos[0] = regmatch.endpos[0]; | |
2887 } | |
2888 } | |
2889 } | |
2890 | |
2891 /* | |
2892 * If all end patterns have been tried, and there is no match, the | |
2893 * item continues until end-of-line. | |
2894 */ | |
2895 if (best_idx == -1) | |
2896 break; | |
2897 | |
2898 /* | |
2899 * If the skip pattern matches before the end pattern, | |
2900 * continue searching after the skip pattern. | |
2901 */ | |
2902 if (spp_skip != NULL) | |
2903 { | |
2904 int lc_col = matchcol - spp_skip->sp_offsets[SPO_LC_OFF]; | |
6375 | 2905 int r; |
7 | 2906 |
2907 if (lc_col < 0) | |
2908 lc_col = 0; | |
2909 regmatch.rmm_ic = spp_skip->sp_ic; | |
2910 regmatch.regprog = spp_skip->sp_prog; | |
6375 | 2911 r = syn_regexec(®match, startpos->lnum, lc_col, |
2912 IF_SYN_TIME(&spp_skip->sp_time)); | |
2913 spp_skip->sp_prog = regmatch.regprog; | |
2914 if (r && regmatch.startpos[0].col | |
7 | 2915 <= best_regmatch.startpos[0].col) |
2916 { | |
7500
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2917 int line_len; |
ef568437e49a
commit https://github.com/vim/vim/commit/04bff88df6211f64731bf8f5afa088e94496db16
Christian Brabandt <cb@256bit.org>
parents:
7467
diff
changeset
|
2918 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2919 // Add offset to skip pattern match |
7 | 2920 syn_add_end_off(&pos, ®match, spp_skip, SPO_ME_OFF, 1); |
2921 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2922 // If the skip pattern goes on to the next line, there is no |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2923 // match with an end pattern in this line. |
7 | 2924 if (pos.lnum > startpos->lnum) |
2925 break; | |
2926 | |
2927 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
|
2928 line_len = (int)STRLEN(line); |
7 | 2929 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2930 // take care of an empty match or negative offset |
7 | 2931 if (pos.col <= matchcol) |
2932 ++matchcol; | |
2933 else if (pos.col <= regmatch.endpos[0].col) | |
2934 matchcol = pos.col; | |
2935 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2936 // Be careful not to jump over the NUL at the end-of-line |
7 | 2937 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
|
2938 matchcol < line_len && matchcol < pos.col; |
7 | 2939 ++matchcol) |
2940 ; | |
2941 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2942 // 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
|
2943 if (matchcol >= line_len) |
7 | 2944 break; |
2945 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2946 continue; // start with first end pattern again |
7 | 2947 } |
2948 } | |
2949 | |
2950 /* | |
2951 * Match from start pattern to end pattern. | |
2952 * Correct for match and highlight offset of end pattern. | |
2953 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
2954 spp = &(SYN_ITEMS(syn_block)[best_idx]); |
7 | 2955 syn_add_end_off(m_endpos, &best_regmatch, spp, SPO_ME_OFF, 1); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2956 // can't end before the start |
7 | 2957 if (m_endpos->lnum == startpos->lnum && m_endpos->col < startpos->col) |
2958 m_endpos->col = startpos->col; | |
2959 | |
2960 syn_add_end_off(end_endpos, &best_regmatch, spp, SPO_HE_OFF, 1); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2961 // can't end before the start |
7 | 2962 if (end_endpos->lnum == startpos->lnum |
2963 && end_endpos->col < startpos->col) | |
2964 end_endpos->col = startpos->col; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2965 // can't end after the match |
7 | 2966 limit_pos(end_endpos, m_endpos); |
2967 | |
2968 /* | |
2969 * If the end group is highlighted differently, adjust the pointers. | |
2970 */ | |
2971 if (spp->sp_syn_match_id != spp->sp_syn.id && spp->sp_syn_match_id != 0) | |
2972 { | |
2973 *end_idx = best_idx; | |
2974 if (spp->sp_off_flags & (1 << (SPO_RE_OFF + SPO_COUNT))) | |
2975 { | |
2976 hl_endpos->lnum = best_regmatch.endpos[0].lnum; | |
2977 hl_endpos->col = best_regmatch.endpos[0].col; | |
2978 } | |
2979 else | |
2980 { | |
2981 hl_endpos->lnum = best_regmatch.startpos[0].lnum; | |
2982 hl_endpos->col = best_regmatch.startpos[0].col; | |
2983 } | |
2984 hl_endpos->col += spp->sp_offsets[SPO_RE_OFF]; | |
2985 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2986 // can't end before the start |
7 | 2987 if (hl_endpos->lnum == startpos->lnum |
2988 && hl_endpos->col < startpos->col) | |
2989 hl_endpos->col = startpos->col; | |
2990 limit_pos(hl_endpos, m_endpos); | |
2991 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2992 // now the match ends where the highlighting ends, it is turned |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
2993 // into the matchgroup for the end |
7 | 2994 *m_endpos = *hl_endpos; |
2995 } | |
2996 else | |
2997 { | |
2998 *end_idx = 0; | |
2999 *hl_endpos = *end_endpos; | |
3000 } | |
3001 | |
3002 *flagsp = spp->sp_flags; | |
3003 | |
3004 had_match = TRUE; | |
3005 break; | |
3006 } | |
3007 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3008 // no match for an END pattern in this line |
7 | 3009 if (!had_match) |
3010 m_endpos->lnum = 0; | |
3011 | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3012 restore_chartab(buf_chartab); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3013 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3014 // Remove external matches. |
7 | 3015 unref_extmatch(re_extmatch_in); |
3016 re_extmatch_in = NULL; | |
3017 } | |
3018 | |
3019 /* | |
3020 * Limit "pos" not to be after "limit". | |
3021 */ | |
3022 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3023 limit_pos(lpos_T *pos, lpos_T *limit) |
7 | 3024 { |
3025 if (pos->lnum > limit->lnum) | |
3026 *pos = *limit; | |
3027 else if (pos->lnum == limit->lnum && pos->col > limit->col) | |
3028 pos->col = limit->col; | |
3029 } | |
3030 | |
3031 /* | |
3032 * Limit "pos" not to be after "limit", unless pos->lnum is zero. | |
3033 */ | |
3034 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3035 limit_pos_zero( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3036 lpos_T *pos, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3037 lpos_T *limit) |
7 | 3038 { |
3039 if (pos->lnum == 0) | |
3040 *pos = *limit; | |
3041 else | |
3042 limit_pos(pos, limit); | |
3043 } | |
3044 | |
3045 /* | |
3046 * Add offset to matched text for end of match or highlight. | |
3047 */ | |
3048 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3049 syn_add_end_off( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3050 lpos_T *result, // returned position |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3051 regmmatch_T *regmatch, // start/end of match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3052 synpat_T *spp, // matched pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3053 int idx, // index of offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3054 int extra) // extra chars for offset to start |
7 | 3055 { |
3056 int col; | |
1624 | 3057 int off; |
3058 char_u *base; | |
3059 char_u *p; | |
7 | 3060 |
3061 if (spp->sp_off_flags & (1 << idx)) | |
3062 { | |
3063 result->lnum = regmatch->startpos[0].lnum; | |
1624 | 3064 col = regmatch->startpos[0].col; |
3065 off = spp->sp_offsets[idx] + extra; | |
7 | 3066 } |
3067 else | |
3068 { | |
3069 result->lnum = regmatch->endpos[0].lnum; | |
3070 col = regmatch->endpos[0].col; | |
1624 | 3071 off = spp->sp_offsets[idx]; |
3072 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3073 // Don't go past the end of the line. Matters for "rs=e+2" when there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3074 // is a matchgroup. Watch out for match with last NL in the buffer. |
1624 | 3075 if (result->lnum > syn_buf->b_ml.ml_line_count) |
3076 col = 0; | |
3077 else if (off != 0) | |
3078 { | |
3079 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3080 p = base + col; | |
3081 if (off > 0) | |
3082 { | |
3083 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
|
3084 MB_PTR_ADV(p); |
1624 | 3085 } |
3086 else if (off < 0) | |
3087 { | |
3088 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
|
3089 MB_PTR_BACK(base, p); |
1624 | 3090 } |
3091 col = (int)(p - base); | |
3092 } | |
3093 result->col = col; | |
7 | 3094 } |
3095 | |
3096 /* | |
3097 * Add offset to matched text for start of match or highlight. | |
3098 * Avoid resulting column to become negative. | |
3099 */ | |
3100 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3101 syn_add_start_off( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3102 lpos_T *result, // returned position |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3103 regmmatch_T *regmatch, // start/end of match |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3104 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3105 int idx, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3106 int extra) // extra chars for offset to end |
7 | 3107 { |
3108 int col; | |
1624 | 3109 int off; |
3110 char_u *base; | |
3111 char_u *p; | |
7 | 3112 |
3113 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) | |
3114 { | |
3115 result->lnum = regmatch->endpos[0].lnum; | |
1624 | 3116 col = regmatch->endpos[0].col; |
3117 off = spp->sp_offsets[idx] + extra; | |
7 | 3118 } |
3119 else | |
3120 { | |
3121 result->lnum = regmatch->startpos[0].lnum; | |
3122 col = regmatch->startpos[0].col; | |
1624 | 3123 off = spp->sp_offsets[idx]; |
3124 } | |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3125 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
|
3126 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3127 // a "\n" at the end of the pattern may take us below the last line |
2092
98cc757f7e3d
updated for version 7.2.376
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
3128 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
|
3129 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
|
3130 } |
1624 | 3131 if (off != 0) |
3132 { | |
3133 base = ml_get_buf(syn_buf, result->lnum, FALSE); | |
3134 p = base + col; | |
3135 if (off > 0) | |
3136 { | |
3137 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
|
3138 MB_PTR_ADV(p); |
1624 | 3139 } |
3140 else if (off < 0) | |
3141 { | |
3142 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
|
3143 MB_PTR_BACK(base, p); |
1624 | 3144 } |
3145 col = (int)(p - base); | |
3146 } | |
3147 result->col = col; | |
7 | 3148 } |
3149 | |
3150 /* | |
3151 * Get current line in syntax buffer. | |
3152 */ | |
3153 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3154 syn_getcurline(void) |
7 | 3155 { |
3156 return ml_get_buf(syn_buf, current_lnum, FALSE); | |
3157 } | |
3158 | |
3159 /* | |
410 | 3160 * Call vim_regexec() to find a match with "rmp" in "syn_buf". |
7 | 3161 * Returns TRUE when there is a match. |
3162 */ | |
3163 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3164 syn_regexec( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3165 regmmatch_T *rmp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3166 linenr_T lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3167 colnr_T col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3168 syn_time_T *st UNUSED) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3169 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3170 int r; |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3171 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3172 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
|
3173 #endif |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3174 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3175 proftime_T pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3176 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3177 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3178 profile_start(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3179 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3180 |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3181 if (rmp->regprog == NULL) |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3182 // This can happen if a previous call to vim_regexec_multi() tried to |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3183 // use the NFA engine, which resulted in NFA_TOO_EXPENSIVE, and |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3184 // compiling the pattern with the other engine fails. |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3185 return FALSE; |
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
13976
diff
changeset
|
3186 |
410 | 3187 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
|
3188 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
|
3189 #ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3190 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
|
3191 #else |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3192 NULL, NULL |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3193 #endif |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3194 ); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3195 |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
3196 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3197 if (syn_time_on) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3198 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3199 profile_end(&pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3200 profile_add(&st->total, &pt); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3201 if (profile_cmp(&pt, &st->slowest) < 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3202 st->slowest = pt; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3203 ++st->count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3204 if (r > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3205 ++st->match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3206 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3207 #endif |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3208 #ifdef FEAT_RELTIME |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3209 if (timed_out && !syn_win->w_s->b_syn_slow) |
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3210 { |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3211 syn_win->w_s->b_syn_slow = TRUE; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3212 msg(_("'redrawtime' exceeded, syntax highlighting disabled")); |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3213 } |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3214 #endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3215 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3216 if (r > 0) |
7 | 3217 { |
3218 rmp->startpos[0].lnum += lnum; | |
3219 rmp->endpos[0].lnum += lnum; | |
3220 return TRUE; | |
3221 } | |
3222 return FALSE; | |
3223 } | |
3224 | |
3225 /* | |
3226 * Check one position in a line for a matching keyword. | |
3227 * 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
|
3228 * Return its ID if found, 0 otherwise. |
7 | 3229 */ |
3230 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3231 check_keyword_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3232 char_u *line, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3233 int startcol, // position in line to check for keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3234 int *endcolp, // return: character after found keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3235 long *flagsp, // return: flags of matching keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3236 short **next_listp, // return: next_list of matching keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3237 stateitem_T *cur_si, // item at the top of the stack |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3238 int *ccharp UNUSED) // conceal substitution char |
7 | 3239 { |
134 | 3240 keyentry_T *kp; |
3241 char_u *kwp; | |
7 | 3242 int round; |
134 | 3243 int kwlen; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3244 char_u keyword[MAXKEYWLEN + 1]; // assume max. keyword len is 80 |
134 | 3245 hashtab_T *ht; |
3246 hashitem_T *hi; | |
7 | 3247 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3248 // Find first character after the keyword. First character was already |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3249 // checked. |
134 | 3250 kwp = line + startcol; |
3251 kwlen = 0; | |
7 | 3252 do |
3253 { | |
3254 if (has_mbyte) | |
474 | 3255 kwlen += (*mb_ptr2len)(kwp + kwlen); |
7 | 3256 else |
134 | 3257 ++kwlen; |
3258 } | |
4043 | 3259 while (vim_iswordp_buf(kwp + kwlen, syn_buf)); |
134 | 3260 |
3261 if (kwlen > MAXKEYWLEN) | |
7 | 3262 return 0; |
3263 | |
3264 /* | |
3265 * Must make a copy of the keyword, so we can add a NUL and make it | |
3266 * lowercase. | |
3267 */ | |
419 | 3268 vim_strncpy(keyword, kwp, kwlen); |
7 | 3269 |
3270 /* | |
3271 * Try twice: | |
3272 * 1. matching case | |
3273 * 2. ignoring case | |
3274 */ | |
3275 for (round = 1; round <= 2; ++round) | |
3276 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3277 ht = round == 1 ? &syn_block->b_keywtab : &syn_block->b_keywtab_ic; |
134 | 3278 if (ht->ht_used == 0) |
7 | 3279 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3280 if (round == 2) // ignore case |
134 | 3281 (void)str_foldcase(kwp, kwlen, keyword, MAXKEYWLEN + 1); |
7 | 3282 |
3283 /* | |
134 | 3284 * Find keywords that match. There can be several with different |
3285 * attributes. | |
7 | 3286 * When current_next_list is non-zero accept only that group, otherwise: |
3287 * Accept a not-contained keyword at toplevel. | |
3288 * Accept a keyword at other levels only if it is in the contains list. | |
3289 */ | |
134 | 3290 hi = hash_find(ht, keyword); |
3291 if (!HASHITEM_EMPTY(hi)) | |
3292 for (kp = HI2KE(hi); kp != NULL; kp = kp->ke_next) | |
7 | 3293 { |
134 | 3294 if (current_next_list != 0 |
3295 ? in_id_list(NULL, current_next_list, &kp->k_syn, 0) | |
3296 : (cur_si == NULL | |
3297 ? !(kp->flags & HL_CONTAINED) | |
3298 : in_id_list(cur_si, cur_si->si_cont_list, | |
3299 &kp->k_syn, kp->flags & HL_CONTAINED))) | |
3300 { | |
3301 *endcolp = startcol + kwlen; | |
3302 *flagsp = kp->flags; | |
3303 *next_listp = kp->next_list; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3304 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3305 *ccharp = kp->k_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3306 #endif |
134 | 3307 return kp->k_syn.id; |
3308 } | |
7 | 3309 } |
3310 } | |
3311 return 0; | |
3312 } | |
3313 | |
3314 /* | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3315 * Handle ":syntax conceal" command. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3316 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3317 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3318 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
|
3319 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3320 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3321 char_u *arg = eap->arg; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3322 char_u *next; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3323 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3324 eap->nextcmd = find_nextcmd(arg); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3325 if (eap->skip) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3326 return; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3327 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3328 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
|
3329 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
|
3330 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3331 if (curwin->w_s->b_syn_conceal) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3332 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
|
3333 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3334 msg(_("syntax conceal 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
|
3335 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3336 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
|
3337 curwin->w_s->b_syn_conceal = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3338 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
|
3339 curwin->w_s->b_syn_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3340 else |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3341 semsg(_(e_illegal_argument_str_2), arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3342 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3343 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3344 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3345 /* |
7 | 3346 * Handle ":syntax case" command. |
3347 */ | |
3348 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3349 syn_cmd_case(exarg_T *eap, int syncing UNUSED) |
7 | 3350 { |
3351 char_u *arg = eap->arg; | |
3352 char_u *next; | |
3353 | |
3354 eap->nextcmd = find_nextcmd(arg); | |
3355 if (eap->skip) | |
3356 return; | |
3357 | |
3358 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
|
3359 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
|
3360 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3361 if (curwin->w_s->b_syn_ic) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3362 msg(_("syntax case ignore")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3363 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3364 msg(_("syntax case match")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3365 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3366 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
|
3367 curwin->w_s->b_syn_ic = FALSE; |
7 | 3368 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
|
3369 curwin->w_s->b_syn_ic = TRUE; |
7 | 3370 else |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3371 semsg(_(e_illegal_argument_str_2), arg); |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3372 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3373 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3374 /* |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3375 * Handle ":syntax foldlevel" command. |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3376 */ |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3377 static void |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3378 syn_cmd_foldlevel(exarg_T *eap, int syncing UNUSED) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3379 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3380 char_u *arg = eap->arg; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3381 char_u *arg_end; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3382 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3383 eap->nextcmd = find_nextcmd(arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3384 if (eap->skip) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3385 return; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3386 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3387 if (*arg == NUL) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3388 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3389 switch (curwin->w_s->b_syn_foldlevel) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3390 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3391 case SYNFLD_START: msg(_("syntax foldlevel start")); break; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3392 case SYNFLD_MINIMUM: msg(_("syntax foldlevel minimum")); break; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3393 default: break; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3394 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3395 return; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3396 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3397 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3398 arg_end = skiptowhite(arg); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3399 if (STRNICMP(arg, "start", 5) == 0 && arg_end - arg == 5) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3400 curwin->w_s->b_syn_foldlevel = SYNFLD_START; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3401 else if (STRNICMP(arg, "minimum", 7) == 0 && arg_end - arg == 7) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3402 curwin->w_s->b_syn_foldlevel = SYNFLD_MINIMUM; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3403 else |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3404 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3405 semsg(_(e_illegal_argument_str_2), arg); |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3406 return; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3407 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3408 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3409 arg = skipwhite(arg_end); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3410 if (*arg != NUL) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3411 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3412 semsg(_(e_illegal_argument_str_2), arg); |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3413 } |
7 | 3414 } |
3415 | |
3416 /* | |
419 | 3417 * Handle ":syntax spell" command. |
3418 */ | |
3419 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3420 syn_cmd_spell(exarg_T *eap, int syncing UNUSED) |
419 | 3421 { |
3422 char_u *arg = eap->arg; | |
3423 char_u *next; | |
3424 | |
3425 eap->nextcmd = find_nextcmd(arg); | |
3426 if (eap->skip) | |
3427 return; | |
3428 | |
3429 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
|
3430 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
|
3431 { |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3432 if (curwin->w_s->b_syn_spell == SYNSPL_TOP) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3433 msg(_("syntax spell toplevel")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3434 else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3435 msg(_("syntax spell notoplevel")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3436 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3437 msg(_("syntax spell default")); |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3438 } |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
3439 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
|
3440 curwin->w_s->b_syn_spell = SYNSPL_TOP; |
419 | 3441 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
|
3442 curwin->w_s->b_syn_spell = SYNSPL_NOTOP; |
1064 | 3443 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
|
3444 curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; |
419 | 3445 else |
6880 | 3446 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3447 semsg(_(e_illegal_argument_str_2), arg); |
6880 | 3448 return; |
3449 } | |
3450 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3451 // assume spell checking changed, force a redraw |
6880 | 3452 redraw_win_later(curwin, NOT_VALID); |
419 | 3453 } |
3454 | |
3455 /* | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3456 * Handle ":syntax iskeyword" command. |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3457 */ |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3458 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3459 syn_cmd_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
|
3460 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3461 char_u *arg = eap->arg; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3462 char_u save_chartab[32]; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3463 char_u *save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3464 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3465 if (eap->skip) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3466 return; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3467 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3468 arg = skipwhite(arg); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3469 if (*arg == NUL) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3470 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3471 msg_puts("\n"); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3472 if (curwin->w_s->b_syn_isk != empty_option) |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3473 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3474 msg_puts(_("syntax iskeyword ")); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3475 msg_outtrans(curwin->w_s->b_syn_isk); |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3476 } |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3477 else |
14366
1c79c92a642e
patch 8.1.0198: there is no hint that syntax is disabled for 'redrawtime'
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
3478 msg_outtrans((char_u *)_("syntax iskeyword not set")); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3479 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3480 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3481 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3482 if (STRNICMP(arg, "clear", 5) == 0) |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3483 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3484 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
|
3485 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3486 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
|
3487 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3488 else |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3489 { |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3490 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
|
3491 save_isk = curbuf->b_p_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3492 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
|
3493 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3494 buf_init_chartab(curbuf, FALSE); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3495 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
|
3496 (size_t)32); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3497 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
|
3498 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
|
3499 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
|
3500 curbuf->b_p_isk = save_isk; |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3501 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3502 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3503 redraw_win_later(curwin, NOT_VALID); |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3504 } |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3505 |
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3506 /* |
7 | 3507 * Clear all syntax info for one buffer. |
3508 */ | |
3509 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3510 syntax_clear(synblock_T *block) |
7 | 3511 { |
3512 int i; | |
3513 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3514 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
|
3515 #ifdef FEAT_RELTIME |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3516 block->b_syn_slow = FALSE; // clear previous timeout |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
3517 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3518 block->b_syn_ic = FALSE; // Use case, by default |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
3519 block->b_syn_foldlevel = SYNFLD_START; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3520 block->b_syn_spell = SYNSPL_DEFAULT; // default spell checking |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3521 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
|
3522 #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
|
3523 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
|
3524 #endif |
7 | 3525 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3526 // free the keywords |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3527 clear_keywtab(&block->b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3528 clear_keywtab(&block->b_keywtab_ic); |
7 | 3529 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3530 // free the syntax patterns |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3531 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
|
3532 syn_clear_pattern(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3533 ga_clear(&block->b_syn_patterns); |
7 | 3534 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3535 // free the syntax clusters |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3536 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
|
3537 syn_clear_cluster(block, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3538 ga_clear(&block->b_syn_clusters); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3539 block->b_spell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3540 block->b_nospell_cluster_id = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3541 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3542 block->b_syn_sync_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3543 block->b_syn_sync_minlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3544 block->b_syn_sync_maxlines = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3545 block->b_syn_sync_linebreaks = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3546 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3547 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
|
3548 block->b_syn_linecont_prog = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
3549 VIM_CLEAR(block->b_syn_linecont_pat); |
7 | 3550 #ifdef FEAT_FOLDING |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3551 block->b_syn_folditems = 0; |
7 | 3552 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3553 clear_string_option(&block->b_syn_isk); |
7 | 3554 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3555 // free the stored states |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3556 syn_stack_free_all(block); |
7 | 3557 invalidate_current_state(); |
2743 | 3558 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3559 // Reset the counter for ":syn include" |
2743 | 3560 running_syn_inc_tag = 0; |
7 | 3561 } |
3562 | |
3563 /* | |
2253
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3564 * 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
|
3565 */ |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3566 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3567 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
|
3568 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3569 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
|
3570 { |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3571 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
|
3572 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
|
3573 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
|
3574 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3575 } |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3576 |
12ebd6f6dfce
Fixed: after ":ownsyntax perl" and ":e" syntax was cleared in other window.
Bram Moolenaar <bram@vim.org>
parents:
2252
diff
changeset
|
3577 /* |
7 | 3578 * Clear syncing info for one buffer. |
3579 */ | |
3580 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3581 syntax_sync_clear(void) |
7 | 3582 { |
3583 int i; | |
3584 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3585 // free the syntax patterns |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3586 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
|
3587 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
|
3588 syn_remove_pattern(curwin->w_s, i); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3589 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3590 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
|
3591 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
|
3592 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
|
3593 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
|
3594 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
3595 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
|
3596 curwin->w_s->b_syn_linecont_prog = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
3597 VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
3598 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
|
3599 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3600 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 3601 } |
3602 | |
3603 /* | |
3604 * Remove one pattern from the buffer's pattern list. | |
3605 */ | |
3606 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3607 syn_remove_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3608 synblock_T *block, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3609 int idx) |
7 | 3610 { |
3611 synpat_T *spp; | |
3612 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3613 spp = &(SYN_ITEMS(block)[idx]); |
7 | 3614 #ifdef FEAT_FOLDING |
3615 if (spp->sp_flags & HL_FOLD) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3616 --block->b_syn_folditems; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3617 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3618 syn_clear_pattern(block, idx); |
7 | 3619 mch_memmove(spp, spp + 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3620 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
|
3621 --block->b_syn_patterns.ga_len; |
7 | 3622 } |
3623 | |
3624 /* | |
3625 * Clear and free one syntax pattern. When clearing all, must be called from | |
3626 * last to first! | |
3627 */ | |
3628 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3629 syn_clear_pattern(synblock_T *block, int i) |
7 | 3630 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3631 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
|
3632 vim_regfree(SYN_ITEMS(block)[i].sp_prog); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3633 // 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
|
3634 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
|
3635 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3636 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
|
3637 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
|
3638 vim_free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); |
7 | 3639 } |
3640 } | |
3641 | |
3642 /* | |
3643 * Clear and free one syntax cluster. | |
3644 */ | |
3645 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3646 syn_clear_cluster(synblock_T *block, int i) |
7 | 3647 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3648 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
|
3649 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
|
3650 vim_free(SYN_CLSTR(block)[i].scl_list); |
7 | 3651 } |
3652 | |
3653 /* | |
3654 * Handle ":syntax clear" command. | |
3655 */ | |
3656 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3657 syn_cmd_clear(exarg_T *eap, int syncing) |
7 | 3658 { |
3659 char_u *arg = eap->arg; | |
3660 char_u *arg_end; | |
3661 int id; | |
3662 | |
3663 eap->nextcmd = find_nextcmd(arg); | |
3664 if (eap->skip) | |
3665 return; | |
3666 | |
3667 /* | |
3668 * We have to disable this within ":syn include @group filename", | |
3669 * because otherwise @group would get deleted. | |
3670 * Only required for Vim 5.x syntax files, 6.0 ones don't contain ":syn | |
3671 * clear". | |
3672 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3673 if (curwin->w_s->b_syn_topgrp != 0) |
7 | 3674 return; |
3675 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3676 if (ends_excmd2(eap->cmd, arg)) |
7 | 3677 { |
3678 /* | |
3679 * No argument: Clear all syntax items. | |
3680 */ | |
3681 if (syncing) | |
3682 syntax_sync_clear(); | |
3683 else | |
3684 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3685 syntax_clear(curwin->w_s); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3686 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
|
3687 do_unlet((char_u *)"b:current_syntax", TRUE); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
3688 do_unlet((char_u *)"w:current_syntax", TRUE); |
7 | 3689 } |
3690 } | |
3691 else | |
3692 { | |
3693 /* | |
3694 * Clear the group IDs that are in the argument. | |
3695 */ | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3696 while (!ends_excmd2(eap->cmd, arg)) |
7 | 3697 { |
3698 arg_end = skiptowhite(arg); | |
3699 if (*arg == '@') | |
3700 { | |
3701 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3702 if (id == 0) | |
3703 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3704 semsg(_(e_no_such_syntax_cluster_1), arg); |
7 | 3705 break; |
3706 } | |
3707 else | |
3708 { | |
3709 /* | |
3710 * We can't physically delete a cluster without changing | |
3711 * the IDs of other clusters, so we do the next best thing | |
3712 * and make it empty. | |
3713 */ | |
3714 short scl_id = id - SYNID_CLUSTER; | |
3715 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
3716 VIM_CLEAR(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); |
7 | 3717 } |
3718 } | |
3719 else | |
3720 { | |
3721 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3722 if (id == 0) | |
3723 { | |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
3724 semsg(_(e_no_such_highlight_group_name_str), arg); |
7 | 3725 break; |
3726 } | |
3727 else | |
3728 syn_clear_one(id, syncing); | |
3729 } | |
3730 arg = skipwhite(arg_end); | |
3731 } | |
3732 } | |
745 | 3733 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3734 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 3735 } |
3736 | |
3737 /* | |
3738 * Clear one syntax group for the current buffer. | |
3739 */ | |
3740 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3741 syn_clear_one(int id, int syncing) |
7 | 3742 { |
3743 synpat_T *spp; | |
3744 int idx; | |
3745 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3746 // Clear keywords only when not ":syn sync clear group-name" |
7 | 3747 if (!syncing) |
3748 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3749 (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
|
3750 (void)syn_clear_keyword(id, &curwin->w_s->b_keywtab_ic); |
7 | 3751 } |
3752 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3753 // clear the patterns for "id" |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3754 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
|
3755 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3756 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 3757 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
3758 continue; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3759 syn_remove_pattern(curwin->w_s, idx); |
7 | 3760 } |
3761 } | |
3762 | |
3763 /* | |
3764 * Handle ":syntax on" command. | |
3765 */ | |
3766 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3767 syn_cmd_on(exarg_T *eap, int syncing UNUSED) |
7 | 3768 { |
3769 syn_cmd_onoff(eap, "syntax"); | |
3770 } | |
3771 | |
3772 /* | |
3773 * Handle ":syntax enable" command. | |
3774 */ | |
3775 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3776 syn_cmd_enable(exarg_T *eap, int syncing UNUSED) |
7 | 3777 { |
26199
eaa97adb0732
patch 8.2.3631: "syntax enable" does not work properly in Vim9 context
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
3778 set_internal_string_var((char_u *)"g:syntax_cmd", (char_u *)"enable"); |
7 | 3779 syn_cmd_onoff(eap, "syntax"); |
148 | 3780 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3781 } |
3782 | |
3783 /* | |
3784 * Handle ":syntax reset" command. | |
8815
50d9fb580ffe
commit https://github.com/vim/vim/commit/8bc189e81aa98ba4aebb03a9dc9527a210fce816
Christian Brabandt <cb@256bit.org>
parents:
8806
diff
changeset
|
3785 * It actually resets highlighting, not syntax. |
7 | 3786 */ |
3787 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3788 syn_cmd_reset(exarg_T *eap, int syncing UNUSED) |
7 | 3789 { |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
3790 set_nextcmd(eap, eap->arg); |
7 | 3791 if (!eap->skip) |
3792 { | |
26199
eaa97adb0732
patch 8.2.3631: "syntax enable" does not work properly in Vim9 context
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
3793 set_internal_string_var((char_u *)"g:syntax_cmd", (char_u *)"reset"); |
7 | 3794 do_cmdline_cmd((char_u *)"runtime! syntax/syncolor.vim"); |
148 | 3795 do_unlet((char_u *)"g:syntax_cmd", TRUE); |
7 | 3796 } |
3797 } | |
3798 | |
3799 /* | |
3800 * Handle ":syntax manual" command. | |
3801 */ | |
3802 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3803 syn_cmd_manual(exarg_T *eap, int syncing UNUSED) |
7 | 3804 { |
3805 syn_cmd_onoff(eap, "manual"); | |
3806 } | |
3807 | |
3808 /* | |
3809 * Handle ":syntax off" command. | |
3810 */ | |
3811 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3812 syn_cmd_off(exarg_T *eap, int syncing UNUSED) |
7 | 3813 { |
3814 syn_cmd_onoff(eap, "nosyntax"); | |
3815 } | |
3816 | |
3817 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3818 syn_cmd_onoff(exarg_T *eap, char *name) |
7 | 3819 { |
3820 char_u buf[100]; | |
3821 | |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
3822 set_nextcmd(eap, eap->arg); |
7 | 3823 if (!eap->skip) |
3824 { | |
3825 STRCPY(buf, "so "); | |
274 | 3826 vim_snprintf((char *)buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); |
7 | 3827 do_cmdline_cmd(buf); |
3828 } | |
3829 } | |
3830 | |
3831 /* | |
3832 * Handle ":syntax [list]" command: list current syntax words. | |
3833 */ | |
3834 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3835 syn_cmd_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3836 exarg_T *eap, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3837 int syncing) // when TRUE: list syncing items |
7 | 3838 { |
3839 char_u *arg = eap->arg; | |
3840 int id; | |
3841 char_u *arg_end; | |
3842 | |
3843 eap->nextcmd = find_nextcmd(arg); | |
3844 if (eap->skip) | |
3845 return; | |
3846 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3847 if (!syntax_present(curwin)) |
7 | 3848 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3849 msg(_(msg_no_items)); |
7 | 3850 return; |
3851 } | |
3852 | |
3853 if (syncing) | |
3854 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3855 if (curwin->w_s->b_syn_sync_flags & SF_CCOMMENT) |
7 | 3856 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3857 msg_puts(_("syncing on C-style comments")); |
7 | 3858 syn_lines_msg(); |
3859 syn_match_msg(); | |
3860 return; | |
3861 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3862 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
|
3863 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3864 if (curwin->w_s->b_syn_sync_minlines == 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3865 msg_puts(_("no syncing")); |
7 | 3866 else |
3867 { | |
22928
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3868 if (curwin->w_s->b_syn_sync_minlines == MAXLNUM) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3869 msg_puts(_("syncing starts at the first line")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3870 else |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3871 { |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3872 msg_puts(_("syncing starts ")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3873 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3874 msg_puts(_(" lines before top line")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3875 } |
7 | 3876 syn_match_msg(); |
3877 } | |
3878 return; | |
3879 } | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3880 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
|
3881 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
|
3882 || 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
|
3883 || curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3884 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3885 msg_puts(_("\nsyncing on items")); |
7 | 3886 syn_lines_msg(); |
3887 syn_match_msg(); | |
3888 } | |
3889 } | |
3890 else | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3891 msg_puts_title(_("\n--- Syntax items ---")); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3892 if (ends_excmd2(eap->cmd, arg)) |
7 | 3893 { |
3894 /* | |
3895 * No argument: List all group IDs and all syntax clusters. | |
3896 */ | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
3897 for (id = 1; id <= highlight_num_groups() && !got_int; ++id) |
7 | 3898 syn_list_one(id, syncing, FALSE); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3899 for (id = 0; id < curwin->w_s->b_syn_clusters.ga_len && !got_int; ++id) |
7 | 3900 syn_list_cluster(id); |
3901 } | |
3902 else | |
3903 { | |
3904 /* | |
3905 * List the group IDs and syntax clusters that are in the argument. | |
3906 */ | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3907 while (!ends_excmd2(eap->cmd, arg) && !got_int) |
7 | 3908 { |
3909 arg_end = skiptowhite(arg); | |
3910 if (*arg == '@') | |
3911 { | |
3912 id = syn_scl_namen2id(arg + 1, (int)(arg_end - arg - 1)); | |
3913 if (id == 0) | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
3914 semsg(_(e_no_such_syntax_cluster_2), arg); |
7 | 3915 else |
3916 syn_list_cluster(id - SYNID_CLUSTER); | |
3917 } | |
3918 else | |
3919 { | |
3920 id = syn_namen2id(arg, (int)(arg_end - arg)); | |
3921 if (id == 0) | |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
3922 semsg(_(e_no_such_highlight_group_name_str), arg); |
7 | 3923 else |
3924 syn_list_one(id, syncing, TRUE); | |
3925 } | |
3926 arg = skipwhite(arg_end); | |
3927 } | |
3928 } | |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
3929 set_nextcmd(eap, arg); |
7 | 3930 } |
3931 | |
3932 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3933 syn_lines_msg(void) |
7 | 3934 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3935 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
|
3936 || curwin->w_s->b_syn_sync_minlines > 0) |
7 | 3937 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3938 msg_puts("; "); |
22928
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3939 if (curwin->w_s->b_syn_sync_minlines == MAXLNUM) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3940 msg_puts(_("from the first line")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3941 else |
7 | 3942 { |
22928
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3943 if (curwin->w_s->b_syn_sync_minlines > 0) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3944 { |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3945 msg_puts(_("minimal ")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3946 msg_outnum(curwin->w_s->b_syn_sync_minlines); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3947 if (curwin->w_s->b_syn_sync_maxlines) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3948 msg_puts(", "); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3949 } |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3950 if (curwin->w_s->b_syn_sync_maxlines > 0) |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3951 { |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3952 msg_puts(_("maximal ")); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3953 msg_outnum(curwin->w_s->b_syn_sync_maxlines); |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3954 } |
de6c242ec236
patch 8.2.2011: "syn sync" reports a very large number
Bram Moolenaar <Bram@vim.org>
parents:
22258
diff
changeset
|
3955 msg_puts(_(" lines before top line")); |
7 | 3956 } |
3957 } | |
3958 } | |
3959 | |
3960 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3961 syn_match_msg(void) |
7 | 3962 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3963 if (curwin->w_s->b_syn_sync_linebreaks > 0) |
7 | 3964 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3965 msg_puts(_("; match ")); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
3966 msg_outnum(curwin->w_s->b_syn_sync_linebreaks); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3967 msg_puts(_(" line breaks")); |
7 | 3968 } |
3969 } | |
3970 | |
3971 static int last_matchgroup; | |
3972 | |
3973 struct name_list | |
3974 { | |
3975 int flag; | |
3976 char *name; | |
3977 }; | |
3978 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
3979 static void syn_list_flags(struct name_list *nl, int flags, int attr); |
7 | 3980 |
3981 /* | |
3982 * List one syntax item, for ":syntax" or "syntax list syntax_name". | |
3983 */ | |
3984 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3985 syn_list_one( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3986 int id, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3987 int syncing, // when TRUE: list syncing items |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
3988 int link_only) // when TRUE; list link-only too |
7 | 3989 { |
3990 int attr; | |
3991 int idx; | |
3992 int did_header = FALSE; | |
3993 synpat_T *spp; | |
3994 static struct name_list namelist1[] = | |
3995 { | |
3996 {HL_DISPLAY, "display"}, | |
3997 {HL_CONTAINED, "contained"}, | |
3998 {HL_ONELINE, "oneline"}, | |
3999 {HL_KEEPEND, "keepend"}, | |
4000 {HL_EXTEND, "extend"}, | |
4001 {HL_EXCLUDENL, "excludenl"}, | |
4002 {HL_TRANSP, "transparent"}, | |
4003 {HL_FOLD, "fold"}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4004 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4005 {HL_CONCEAL, "conceal"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4006 {HL_CONCEALENDS, "concealends"}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4007 #endif |
7 | 4008 {0, NULL} |
4009 }; | |
4010 static struct name_list namelist2[] = | |
4011 { | |
4012 {HL_SKIPWHITE, "skipwhite"}, | |
4013 {HL_SKIPNL, "skipnl"}, | |
4014 {HL_SKIPEMPTY, "skipempty"}, | |
4015 {0, NULL} | |
4016 }; | |
4017 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4018 attr = HL_ATTR(HLF_D); // highlight like directories |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4019 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4020 // list the keywords for "id" |
7 | 4021 if (!syncing) |
4022 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4023 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
|
4024 did_header = syn_list_keywords(id, &curwin->w_s->b_keywtab_ic, |
7 | 4025 did_header, attr); |
4026 } | |
4027 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4028 // list the patterns for "id" |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4029 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
|
4030 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4031 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
7 | 4032 if (spp->sp_syn.id != id || spp->sp_syncing != syncing) |
4033 continue; | |
4034 | |
4035 (void)syn_list_header(did_header, 999, id); | |
4036 did_header = TRUE; | |
4037 last_matchgroup = 0; | |
4038 if (spp->sp_type == SPTYPE_MATCH) | |
4039 { | |
4040 put_pattern("match", ' ', spp, attr); | |
4041 msg_putchar(' '); | |
4042 } | |
4043 else if (spp->sp_type == SPTYPE_START) | |
4044 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4045 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
|
4046 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
|
4047 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
|
4048 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
|
4049 while (idx < curwin->w_s->b_syn_patterns.ga_len |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4050 && SYN_ITEMS(curwin->w_s)[idx].sp_type == SPTYPE_END) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4051 put_pattern("end", '=', &SYN_ITEMS(curwin->w_s)[idx++], attr); |
7 | 4052 --idx; |
4053 msg_putchar(' '); | |
4054 } | |
4055 syn_list_flags(namelist1, spp->sp_flags, attr); | |
4056 | |
4057 if (spp->sp_cont_list != NULL) | |
4058 put_id_list((char_u *)"contains", spp->sp_cont_list, attr); | |
4059 | |
4060 if (spp->sp_syn.cont_in_list != NULL) | |
4061 put_id_list((char_u *)"containedin", | |
4062 spp->sp_syn.cont_in_list, attr); | |
4063 | |
4064 if (spp->sp_next_list != NULL) | |
4065 { | |
4066 put_id_list((char_u *)"nextgroup", spp->sp_next_list, attr); | |
4067 syn_list_flags(namelist2, spp->sp_flags, attr); | |
4068 } | |
4069 if (spp->sp_flags & (HL_SYNC_HERE|HL_SYNC_THERE)) | |
4070 { | |
4071 if (spp->sp_flags & HL_SYNC_HERE) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4072 msg_puts_attr("grouphere", attr); |
7 | 4073 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4074 msg_puts_attr("groupthere", attr); |
7 | 4075 msg_putchar(' '); |
4076 if (spp->sp_sync_idx >= 0) | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4077 msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s) |
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4078 [spp->sp_sync_idx].sp_syn.id - 1)); |
7 | 4079 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4080 msg_puts("NONE"); |
7 | 4081 msg_putchar(' '); |
4082 } | |
4083 } | |
4084 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4085 // list the link, if there is one |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4086 if (highlight_link_id(id - 1) && (did_header || link_only) && !got_int) |
7 | 4087 { |
4088 (void)syn_list_header(did_header, 999, id); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4089 msg_puts_attr("links to", attr); |
7 | 4090 msg_putchar(' '); |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4091 msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1)); |
7 | 4092 } |
4093 } | |
4094 | |
4095 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4096 syn_list_flags(struct name_list *nlist, int flags, int attr) |
7 | 4097 { |
4098 int i; | |
4099 | |
3263 | 4100 for (i = 0; nlist[i].flag != 0; ++i) |
4101 if (flags & nlist[i].flag) | |
4102 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4103 msg_puts_attr(nlist[i].name, attr); |
7 | 4104 msg_putchar(' '); |
4105 } | |
4106 } | |
4107 | |
4108 /* | |
4109 * List one syntax cluster, for ":syntax" or "syntax list syntax_name". | |
4110 */ | |
4111 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4112 syn_list_cluster(int id) |
7 | 4113 { |
4114 int endcol = 15; | |
4115 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4116 // slight hack: roughly duplicate the guts of syn_list_header() |
7 | 4117 msg_putchar('\n'); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4118 msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); |
7 | 4119 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4120 if (msg_col >= endcol) // output at least one space |
7 | 4121 endcol = msg_col + 1; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4122 if (Columns <= endcol) // avoid hang for tiny window |
7 | 4123 endcol = Columns - 1; |
4124 | |
4125 msg_advance(endcol); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4126 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
|
4127 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4128 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
|
4129 HL_ATTR(HLF_D)); |
7 | 4130 } |
4131 else | |
4132 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4133 msg_puts_attr("cluster", HL_ATTR(HLF_D)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4134 msg_puts("=NONE"); |
7 | 4135 } |
4136 } | |
4137 | |
4138 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4139 put_id_list(char_u *name, short *list, int attr) |
7 | 4140 { |
4141 short *p; | |
4142 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4143 msg_puts_attr((char *)name, attr); |
7 | 4144 msg_putchar('='); |
4145 for (p = list; *p; ++p) | |
4146 { | |
4147 if (*p >= SYNID_ALLBUT && *p < SYNID_TOP) | |
4148 { | |
4149 if (p[1]) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4150 msg_puts("ALLBUT"); |
7 | 4151 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4152 msg_puts("ALL"); |
7 | 4153 } |
4154 else if (*p >= SYNID_TOP && *p < SYNID_CONTAINED) | |
4155 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4156 msg_puts("TOP"); |
7 | 4157 } |
4158 else if (*p >= SYNID_CONTAINED && *p < SYNID_CLUSTER) | |
4159 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4160 msg_puts("CONTAINED"); |
7 | 4161 } |
4162 else if (*p >= SYNID_CLUSTER) | |
4163 { | |
4164 short scl_id = *p - SYNID_CLUSTER; | |
4165 | |
4166 msg_putchar('@'); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4167 msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); |
7 | 4168 } |
4169 else | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4170 msg_outtrans(highlight_group_name(*p - 1)); |
7 | 4171 if (p[1]) |
4172 msg_putchar(','); | |
4173 } | |
4174 msg_putchar(' '); | |
4175 } | |
4176 | |
4177 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4178 put_pattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4179 char *s, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4180 int c, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4181 synpat_T *spp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4182 int attr) |
7 | 4183 { |
4184 long n; | |
4185 int mask; | |
4186 int first; | |
4187 static char *sepchars = "/+=-#@\"|'^&"; | |
4188 int i; | |
4189 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4190 // May have to write "matchgroup=group" |
7 | 4191 if (last_matchgroup != spp->sp_syn_match_id) |
4192 { | |
4193 last_matchgroup = spp->sp_syn_match_id; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4194 msg_puts_attr("matchgroup", attr); |
7 | 4195 msg_putchar('='); |
4196 if (last_matchgroup == 0) | |
4197 msg_outtrans((char_u *)"NONE"); | |
4198 else | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
4199 msg_outtrans(highlight_group_name(last_matchgroup - 1)); |
7 | 4200 msg_putchar(' '); |
4201 } | |
4202 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4203 // output the name of the pattern and an '=' or ' ' |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4204 msg_puts_attr(s, attr); |
7 | 4205 msg_putchar(c); |
4206 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4207 // output the pattern, in between a char that is not in the pattern |
7 | 4208 for (i = 0; vim_strchr(spp->sp_pattern, sepchars[i]) != NULL; ) |
4209 if (sepchars[++i] == NUL) | |
4210 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4211 i = 0; // no good char found, just use the first one |
7 | 4212 break; |
4213 } | |
4214 msg_putchar(sepchars[i]); | |
4215 msg_outtrans(spp->sp_pattern); | |
4216 msg_putchar(sepchars[i]); | |
4217 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4218 // output any pattern options |
7 | 4219 first = TRUE; |
4220 for (i = 0; i < SPO_COUNT; ++i) | |
4221 { | |
4222 mask = (1 << i); | |
4223 if (spp->sp_off_flags & (mask + (mask << SPO_COUNT))) | |
4224 { | |
4225 if (!first) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4226 msg_putchar(','); // separate with commas |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4227 msg_puts(spo_name_tab[i]); |
7 | 4228 n = spp->sp_offsets[i]; |
4229 if (i != SPO_LC_OFF) | |
4230 { | |
4231 if (spp->sp_off_flags & mask) | |
4232 msg_putchar('s'); | |
4233 else | |
4234 msg_putchar('e'); | |
4235 if (n > 0) | |
4236 msg_putchar('+'); | |
4237 } | |
4238 if (n || i == SPO_LC_OFF) | |
4239 msg_outnum(n); | |
4240 first = FALSE; | |
4241 } | |
4242 } | |
4243 msg_putchar(' '); | |
4244 } | |
4245 | |
4246 /* | |
4247 * List or clear the keywords for one syntax group. | |
4248 * Return TRUE if the header has been printed. | |
4249 */ | |
4250 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4251 syn_list_keywords( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4252 int id, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4253 hashtab_T *ht, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4254 int did_header, // header has already been printed |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4255 int attr) |
7 | 4256 { |
4257 int outlen; | |
134 | 4258 hashitem_T *hi; |
4259 keyentry_T *kp; | |
4260 int todo; | |
7 | 4261 int prev_contained = 0; |
4262 short *prev_next_list = NULL; | |
4263 short *prev_cont_in_list = NULL; | |
4264 int prev_skipnl = 0; | |
4265 int prev_skipwhite = 0; | |
4266 int prev_skipempty = 0; | |
4267 | |
4268 /* | |
4269 * Unfortunately, this list of keywords is not sorted on alphabet but on | |
4270 * hash value... | |
4271 */ | |
835 | 4272 todo = (int)ht->ht_used; |
134 | 4273 for (hi = ht->ht_array; todo > 0 && !got_int; ++hi) |
4274 { | |
4275 if (!HASHITEM_EMPTY(hi)) | |
4276 { | |
4277 --todo; | |
4278 for (kp = HI2KE(hi); kp != NULL && !got_int; kp = kp->ke_next) | |
7 | 4279 { |
134 | 4280 if (kp->k_syn.id == id) |
7 | 4281 { |
134 | 4282 if (prev_contained != (kp->flags & HL_CONTAINED) |
4283 || prev_skipnl != (kp->flags & HL_SKIPNL) | |
4284 || prev_skipwhite != (kp->flags & HL_SKIPWHITE) | |
4285 || prev_skipempty != (kp->flags & HL_SKIPEMPTY) | |
4286 || prev_cont_in_list != kp->k_syn.cont_in_list | |
4287 || prev_next_list != kp->next_list) | |
4288 outlen = 9999; | |
4289 else | |
4290 outlen = (int)STRLEN(kp->keyword); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4291 // output "contained" and "nextgroup" on each line |
134 | 4292 if (syn_list_header(did_header, outlen, id)) |
4293 { | |
4294 prev_contained = 0; | |
4295 prev_next_list = NULL; | |
4296 prev_cont_in_list = NULL; | |
4297 prev_skipnl = 0; | |
4298 prev_skipwhite = 0; | |
4299 prev_skipempty = 0; | |
4300 } | |
4301 did_header = TRUE; | |
4302 if (prev_contained != (kp->flags & HL_CONTAINED)) | |
4303 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4304 msg_puts_attr("contained", attr); |
134 | 4305 msg_putchar(' '); |
4306 prev_contained = (kp->flags & HL_CONTAINED); | |
4307 } | |
4308 if (kp->k_syn.cont_in_list != prev_cont_in_list) | |
4309 { | |
4310 put_id_list((char_u *)"containedin", | |
4311 kp->k_syn.cont_in_list, attr); | |
4312 msg_putchar(' '); | |
4313 prev_cont_in_list = kp->k_syn.cont_in_list; | |
4314 } | |
4315 if (kp->next_list != prev_next_list) | |
4316 { | |
4317 put_id_list((char_u *)"nextgroup", kp->next_list, attr); | |
4318 msg_putchar(' '); | |
4319 prev_next_list = kp->next_list; | |
4320 if (kp->flags & HL_SKIPNL) | |
4321 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4322 msg_puts_attr("skipnl", attr); |
134 | 4323 msg_putchar(' '); |
4324 prev_skipnl = (kp->flags & HL_SKIPNL); | |
4325 } | |
4326 if (kp->flags & HL_SKIPWHITE) | |
4327 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4328 msg_puts_attr("skipwhite", attr); |
134 | 4329 msg_putchar(' '); |
4330 prev_skipwhite = (kp->flags & HL_SKIPWHITE); | |
4331 } | |
4332 if (kp->flags & HL_SKIPEMPTY) | |
4333 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4334 msg_puts_attr("skipempty", attr); |
134 | 4335 msg_putchar(' '); |
4336 prev_skipempty = (kp->flags & HL_SKIPEMPTY); | |
4337 } | |
4338 } | |
4339 msg_outtrans(kp->keyword); | |
7 | 4340 } |
4341 } | |
4342 } | |
4343 } | |
4344 | |
4345 return did_header; | |
4346 } | |
4347 | |
4348 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4349 syn_clear_keyword(int id, hashtab_T *ht) |
134 | 4350 { |
4351 hashitem_T *hi; | |
4352 keyentry_T *kp; | |
4353 keyentry_T *kp_prev; | |
4354 keyentry_T *kp_next; | |
4355 int todo; | |
4356 | |
4357 hash_lock(ht); | |
835 | 4358 todo = (int)ht->ht_used; |
134 | 4359 for (hi = ht->ht_array; todo > 0; ++hi) |
4360 { | |
4361 if (!HASHITEM_EMPTY(hi)) | |
4362 { | |
4363 --todo; | |
4364 kp_prev = NULL; | |
4365 for (kp = HI2KE(hi); kp != NULL; ) | |
7 | 4366 { |
134 | 4367 if (kp->k_syn.id == id) |
4368 { | |
4369 kp_next = kp->ke_next; | |
4370 if (kp_prev == NULL) | |
4371 { | |
4372 if (kp_next == NULL) | |
4373 hash_remove(ht, hi); | |
4374 else | |
4375 hi->hi_key = KE2HIKEY(kp_next); | |
4376 } | |
4377 else | |
4378 kp_prev->ke_next = kp_next; | |
4379 vim_free(kp->next_list); | |
4380 vim_free(kp->k_syn.cont_in_list); | |
4381 vim_free(kp); | |
4382 kp = kp_next; | |
4383 } | |
7 | 4384 else |
134 | 4385 { |
4386 kp_prev = kp; | |
4387 kp = kp->ke_next; | |
4388 } | |
7 | 4389 } |
134 | 4390 } |
4391 } | |
4392 hash_unlock(ht); | |
4393 } | |
4394 | |
4395 /* | |
4396 * Clear a whole keyword table. | |
7 | 4397 */ |
4398 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4399 clear_keywtab(hashtab_T *ht) |
134 | 4400 { |
4401 hashitem_T *hi; | |
4402 int todo; | |
4403 keyentry_T *kp; | |
4404 keyentry_T *kp_next; | |
4405 | |
835 | 4406 todo = (int)ht->ht_used; |
134 | 4407 for (hi = ht->ht_array; todo > 0; ++hi) |
4408 { | |
4409 if (!HASHITEM_EMPTY(hi)) | |
4410 { | |
4411 --todo; | |
4412 for (kp = HI2KE(hi); kp != NULL; kp = kp_next) | |
7 | 4413 { |
134 | 4414 kp_next = kp->ke_next; |
4415 vim_free(kp->next_list); | |
4416 vim_free(kp->k_syn.cont_in_list); | |
4417 vim_free(kp); | |
7 | 4418 } |
134 | 4419 } |
4420 } | |
4421 hash_clear(ht); | |
4422 hash_init(ht); | |
7 | 4423 } |
4424 | |
4425 /* | |
4426 * Add a keyword to the list of keywords. | |
4427 */ | |
4428 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4429 add_keyword( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4430 char_u *name, // name of keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4431 int id, // group ID for this keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4432 int flags, // flags for this keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4433 short *cont_in_list, // containedin for this keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4434 short *next_list, // nextgroup for this keyword |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4435 int conceal_char) |
7 | 4436 { |
134 | 4437 keyentry_T *kp; |
4438 hashtab_T *ht; | |
4439 hashitem_T *hi; | |
154 | 4440 char_u *name_ic; |
134 | 4441 long_u hash; |
154 | 4442 char_u name_folded[MAXKEYWLEN + 1]; |
7 | 4443 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4444 if (curwin->w_s->b_syn_ic) |
154 | 4445 name_ic = str_foldcase(name, (int)STRLEN(name), |
4446 name_folded, MAXKEYWLEN + 1); | |
4447 else | |
4448 name_ic = name; | |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17401
diff
changeset
|
4449 kp = alloc(offsetof(keyentry_T, keyword) + STRLEN(name_ic) + 1); |
134 | 4450 if (kp == NULL) |
4451 return; | |
4452 STRCPY(kp->keyword, name_ic); | |
4453 kp->k_syn.id = id; | |
4454 kp->k_syn.inc_tag = current_syn_inc_tag; | |
4455 kp->flags = flags; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4456 kp->k_char = conceal_char; |
134 | 4457 kp->k_syn.cont_in_list = copy_id_list(cont_in_list); |
4458 if (cont_in_list != NULL) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4459 curwin->w_s->b_syn_containedin = TRUE; |
134 | 4460 kp->next_list = copy_id_list(next_list); |
4461 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4462 if (curwin->w_s->b_syn_ic) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4463 ht = &curwin->w_s->b_keywtab_ic; |
7 | 4464 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4465 ht = &curwin->w_s->b_keywtab; |
134 | 4466 |
4467 hash = hash_hash(kp->keyword); | |
4468 hi = hash_lookup(ht, kp->keyword, hash); | |
4469 if (HASHITEM_EMPTY(hi)) | |
4470 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4471 // new keyword, add to hashtable |
134 | 4472 kp->ke_next = NULL; |
4473 hash_add_item(ht, hi, kp->keyword, hash); | |
4474 } | |
4475 else | |
4476 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4477 // keyword already exists, prepend to list |
134 | 4478 kp->ke_next = HI2KE(hi); |
4479 hi->hi_key = KE2HIKEY(kp); | |
4480 } | |
7 | 4481 } |
4482 | |
4483 /* | |
4484 * Get the start and end of the group name argument. | |
4485 * Return a pointer to the first argument. | |
4486 * Return NULL if the end of the command was found instead of further args. | |
4487 */ | |
4488 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4489 get_group_name( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4490 char_u *arg, // start of the argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4491 char_u **name_end) // pointer to end of the name |
7 | 4492 { |
4493 char_u *rest; | |
4494 | |
4495 *name_end = skiptowhite(arg); | |
4496 rest = skipwhite(*name_end); | |
4497 | |
4498 /* | |
4499 * Check if there are enough arguments. The first argument may be a | |
4500 * pattern, where '|' is allowed, so only check for NUL. | |
4501 */ | |
4502 if (ends_excmd(*arg) || *rest == NUL) | |
4503 return NULL; | |
4504 return rest; | |
4505 } | |
4506 | |
4507 /* | |
4508 * Check for syntax command option arguments. | |
4509 * This can be called at any place in the list of arguments, and just picks | |
4510 * out the arguments that are known. Can be called several times in a row to | |
4511 * collect all options in between other arguments. | |
4512 * Return a pointer to the next argument (which isn't an option). | |
4513 * Return NULL for any error; | |
4514 */ | |
4515 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4516 get_syn_options( |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4517 char_u *start, // next argument to be checked |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4518 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
|
4519 int *conceal_char UNUSED, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4520 int skip) // TRUE if skipping over command |
154 | 4521 { |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4522 char_u *arg = start; |
7 | 4523 char_u *gname_start, *gname; |
4524 int syn_id; | |
4525 int len; | |
154 | 4526 char *p; |
7 | 4527 int i; |
4528 int fidx; | |
4529 static struct flag | |
4530 { | |
4531 char *name; | |
154 | 4532 int argtype; |
4533 int flags; | |
4534 } flagtab[] = { {"cCoOnNtTaAiInNeEdD", 0, HL_CONTAINED}, | |
4535 {"oOnNeElLiInNeE", 0, HL_ONELINE}, | |
4536 {"kKeEeEpPeEnNdD", 0, HL_KEEPEND}, | |
4537 {"eExXtTeEnNdD", 0, HL_EXTEND}, | |
4538 {"eExXcClLuUdDeEnNlL", 0, HL_EXCLUDENL}, | |
4539 {"tTrRaAnNsSpPaArReEnNtT", 0, HL_TRANSP}, | |
4540 {"sSkKiIpPnNlL", 0, HL_SKIPNL}, | |
4541 {"sSkKiIpPwWhHiItTeE", 0, HL_SKIPWHITE}, | |
4542 {"sSkKiIpPeEmMpPtTyY", 0, HL_SKIPEMPTY}, | |
4543 {"gGrRoOuUpPhHeErReE", 0, HL_SYNC_HERE}, | |
4544 {"gGrRoOuUpPtThHeErReE", 0, HL_SYNC_THERE}, | |
4545 {"dDiIsSpPlLaAyY", 0, HL_DISPLAY}, | |
4546 {"fFoOlLdD", 0, HL_FOLD}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4547 {"cCoOnNcCeEaAlL", 0, HL_CONCEAL}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4548 {"cCoOnNcCeEaAlLeEnNdDsS", 0, HL_CONCEALENDS}, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4549 {"cCcChHaArR", 11, 0}, |
154 | 4550 {"cCoOnNtTaAiInNsS", 1, 0}, |
4551 {"cCoOnNtTaAiInNeEdDiInN", 2, 0}, | |
4552 {"nNeExXtTgGrRoOuUpP", 3, 0}, | |
7 | 4553 }; |
154 | 4554 static char *first_letters = "cCoOkKeEtTsSgGdDfFnN"; |
7 | 4555 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4556 if (arg == NULL) // already detected error |
7 | 4557 return NULL; |
4558 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4559 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4560 if (curwin->w_s->b_syn_conceal) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4561 opt->flags |= HL_CONCEAL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4562 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4563 |
7 | 4564 for (;;) |
4565 { | |
154 | 4566 /* |
4567 * This is used very often when a large number of keywords is defined. | |
4568 * Need to skip quickly when no option name is found. | |
4569 * Also avoid tolower(), it's slow. | |
4570 */ | |
4571 if (strchr(first_letters, *arg) == NULL) | |
4572 break; | |
7 | 4573 |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24442
diff
changeset
|
4574 for (fidx = ARRAY_LENGTH(flagtab); --fidx >= 0; ) |
7 | 4575 { |
154 | 4576 p = flagtab[fidx].name; |
4577 for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) | |
4578 if (arg[len] != p[i] && arg[len] != p[i + 1]) | |
4579 break; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4580 if (p[i] == NUL && (VIM_ISWHITE(arg[len]) |
154 | 4581 || (flagtab[fidx].argtype > 0 |
4582 ? arg[len] == '=' | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4583 : ends_excmd2(start, arg + len)))) |
7 | 4584 { |
154 | 4585 if (opt->keyword |
4586 && (flagtab[fidx].flags == HL_DISPLAY | |
4587 || flagtab[fidx].flags == HL_FOLD | |
4588 || flagtab[fidx].flags == HL_EXTEND)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4589 // treat "display", "fold" and "extend" as a keyword |
7 | 4590 fidx = -1; |
4591 break; | |
4592 } | |
4593 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4594 if (fidx < 0) // no match found |
154 | 4595 break; |
4596 | |
4597 if (flagtab[fidx].argtype == 1) | |
4598 { | |
4599 if (!opt->has_cont_list) | |
7 | 4600 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4601 emsg(_(e_contains_argument_not_accepted_here)); |
7 | 4602 return NULL; |
4603 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4604 if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) |
7 | 4605 return NULL; |
4606 } | |
154 | 4607 else if (flagtab[fidx].argtype == 2) |
4608 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4609 if (get_id_list(&arg, 11, &opt->cont_in_list, skip) == FAIL) |
7 | 4610 return NULL; |
4611 } | |
154 | 4612 else if (flagtab[fidx].argtype == 3) |
4613 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4614 if (get_id_list(&arg, 9, &opt->next_list, skip) == FAIL) |
7 | 4615 return NULL; |
4616 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4617 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
|
4618 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4619 // cchar=? |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4620 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4621 { |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4622 #ifdef FEAT_CONCEAL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4623 *conceal_char = mb_ptr2char(arg + 6); |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4624 #endif |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4625 arg += mb_ptr2len(arg + 6) - 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4626 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4627 else |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4628 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4629 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4630 *conceal_char = arg[6]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4631 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4632 ; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4633 #endif |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
4634 } |
2686 | 4635 #ifdef FEAT_CONCEAL |
4636 if (!vim_isprintc_strict(*conceal_char)) | |
4637 { | |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4638 emsg(_(e_invalid_cchar_value)); |
2686 | 4639 return NULL; |
4640 } | |
4641 #endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4642 arg = skipwhite(arg + 7); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4643 } |
7 | 4644 else |
154 | 4645 { |
4646 opt->flags |= flagtab[fidx].flags; | |
4647 arg = skipwhite(arg + len); | |
4648 | |
4649 if (flagtab[fidx].flags == HL_SYNC_HERE | |
4650 || flagtab[fidx].flags == HL_SYNC_THERE) | |
4651 { | |
4652 if (opt->sync_idx == NULL) | |
4653 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4654 emsg(_(e_groupthere_not_accepted_here)); |
154 | 4655 return NULL; |
4656 } | |
4657 gname_start = arg; | |
4658 arg = skiptowhite(arg); | |
4659 if (gname_start == arg) | |
4660 return NULL; | |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
4661 gname = vim_strnsave(gname_start, arg - gname_start); |
154 | 4662 if (gname == NULL) |
4663 return NULL; | |
4664 if (STRCMP(gname, "NONE") == 0) | |
4665 *opt->sync_idx = NONE_IDX; | |
4666 else | |
4667 { | |
4668 syn_id = syn_name2id(gname); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4669 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
|
4670 if (SYN_ITEMS(curwin->w_s)[i].sp_syn.id == syn_id |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
4671 && SYN_ITEMS(curwin->w_s)[i].sp_type |
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
4672 == SPTYPE_START) |
154 | 4673 { |
4674 *opt->sync_idx = i; | |
4675 break; | |
4676 } | |
4677 if (i < 0) | |
4678 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4679 semsg(_(e_didnt_find_region_item_for_str), gname); |
154 | 4680 vim_free(gname); |
4681 return NULL; | |
4682 } | |
4683 } | |
4684 | |
4685 vim_free(gname); | |
4686 arg = skipwhite(arg); | |
4687 } | |
4688 #ifdef FEAT_FOLDING | |
4689 else if (flagtab[fidx].flags == HL_FOLD | |
4690 && foldmethodIsSyntax(curwin)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4691 // Need to update folds later. |
154 | 4692 foldUpdateAll(curwin); |
4693 #endif | |
4694 } | |
4695 } | |
7 | 4696 |
4697 return arg; | |
4698 } | |
4699 | |
4700 /* | |
4701 * Adjustments to syntax item when declared in a ":syn include"'d file. | |
4702 * Set the contained flag, and if the item is not already contained, add it | |
4703 * to the specified top-level group, if any. | |
4704 */ | |
4705 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4706 syn_incl_toplevel(int id, int *flagsp) |
7 | 4707 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4708 if ((*flagsp & HL_CONTAINED) || curwin->w_s->b_syn_topgrp == 0) |
7 | 4709 return; |
4710 *flagsp |= HL_CONTAINED; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4711 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
7 | 4712 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4713 // We have to alloc this, because syn_combine_list() will free it. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
4714 short *grp_list = ALLOC_MULT(short, 2); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4715 int tlg_id = curwin->w_s->b_syn_topgrp - SYNID_CLUSTER; |
7 | 4716 |
4717 if (grp_list != NULL) | |
4718 { | |
4719 grp_list[0] = id; | |
4720 grp_list[1] = 0; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
4721 syn_combine_list(&SYN_CLSTR(curwin->w_s)[tlg_id].scl_list, |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
4722 &grp_list, CLUSTER_ADD); |
7 | 4723 } |
4724 } | |
4725 } | |
4726 | |
4727 /* | |
4728 * Handle ":syntax include [@{group-name}] filename" command. | |
4729 */ | |
4730 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4731 syn_cmd_include(exarg_T *eap, int syncing UNUSED) |
7 | 4732 { |
4733 char_u *arg = eap->arg; | |
4734 int sgl_id = 1; | |
4735 char_u *group_name_end; | |
4736 char_u *rest; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4737 char *errormsg = NULL; |
7 | 4738 int prev_toplvl_grp; |
4739 int prev_syn_inc_tag; | |
4740 int source = FALSE; | |
4741 | |
4742 eap->nextcmd = find_nextcmd(arg); | |
4743 if (eap->skip) | |
4744 return; | |
4745 | |
4746 if (arg[0] == '@') | |
4747 { | |
4748 ++arg; | |
4749 rest = get_group_name(arg, &group_name_end); | |
4750 if (rest == NULL) | |
4751 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4752 emsg(_(e_filename_required)); |
7 | 4753 return; |
4754 } | |
4755 sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); | |
2743 | 4756 if (sgl_id == 0) |
4757 return; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4758 // separate_nextcmd() and expand_filename() depend on this |
7 | 4759 eap->arg = rest; |
4760 } | |
4761 | |
4762 /* | |
4763 * Everything that's left, up to the next command, should be the | |
4764 * filename to include. | |
4765 */ | |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
17227
diff
changeset
|
4766 eap->argt |= (EX_XFILE | EX_NOSPC); |
7 | 4767 separate_nextcmd(eap); |
4768 if (*eap->arg == '<' || *eap->arg == '$' || mch_isFullName(eap->arg)) | |
4769 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4770 // For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4771 // file. Need to expand the file name first. In other cases |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4772 // ":runtime!" is used. |
7 | 4773 source = TRUE; |
4774 if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) | |
4775 { | |
4776 if (errormsg != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
4777 emsg(errormsg); |
7 | 4778 return; |
4779 } | |
4780 } | |
4781 | |
4782 /* | |
4783 * Save and restore the existing top-level grouplist id and ":syn | |
4784 * include" tag around the actual inclusion. | |
4785 */ | |
2743 | 4786 if (running_syn_inc_tag >= MAX_SYN_INC_TAG) |
4787 { | |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4788 emsg(_(e_too_many_syntax_includes)); |
2743 | 4789 return; |
4790 } | |
7 | 4791 prev_syn_inc_tag = current_syn_inc_tag; |
4792 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
|
4793 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
|
4794 curwin->w_s->b_syn_topgrp = sgl_id; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4795 if (source ? do_source(eap->arg, FALSE, DOSO_NONE, NULL) == FAIL |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8514
diff
changeset
|
4796 : source_runtime(eap->arg, DIP_ALL) == FAIL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4797 semsg(_(e_cant_open_file_str), eap->arg); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4798 curwin->w_s->b_syn_topgrp = prev_toplvl_grp; |
7 | 4799 current_syn_inc_tag = prev_syn_inc_tag; |
4800 } | |
4801 | |
4802 /* | |
4803 * Handle ":syntax keyword {group-name} [{option}] keyword .." command. | |
4804 */ | |
4805 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4806 syn_cmd_keyword(exarg_T *eap, int syncing UNUSED) |
7 | 4807 { |
4808 char_u *arg = eap->arg; | |
4809 char_u *group_name_end; | |
4810 int syn_id; | |
4811 char_u *rest; | |
2743 | 4812 char_u *keyword_copy = NULL; |
7 | 4813 char_u *p; |
154 | 4814 char_u *kw; |
4815 syn_opt_arg_T syn_opt_arg; | |
4816 int cnt; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4817 int conceal_char = NUL; |
7 | 4818 |
4819 rest = get_group_name(arg, &group_name_end); | |
4820 | |
4821 if (rest != NULL) | |
4822 { | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4823 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
|
4824 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
|
4825 else |
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4826 syn_id = syn_check_group(arg, (int)(group_name_end - arg)); |
2743 | 4827 if (syn_id != 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4828 // allocate a buffer, for removing backslashes in the keyword |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16611
diff
changeset
|
4829 keyword_copy = alloc(STRLEN(rest) + 1); |
7 | 4830 if (keyword_copy != NULL) |
4831 { | |
154 | 4832 syn_opt_arg.flags = 0; |
4833 syn_opt_arg.keyword = TRUE; | |
4834 syn_opt_arg.sync_idx = NULL; | |
4835 syn_opt_arg.has_cont_list = FALSE; | |
4836 syn_opt_arg.cont_in_list = NULL; | |
4837 syn_opt_arg.next_list = NULL; | |
4838 | |
7 | 4839 /* |
4840 * The options given apply to ALL keywords, so all options must be | |
4841 * found before keywords can be created. | |
154 | 4842 * 1: collect the options and copy the keywords to keyword_copy. |
7 | 4843 */ |
154 | 4844 cnt = 0; |
4845 p = keyword_copy; | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4846 for ( ; rest != NULL && !ends_excmd2(eap->arg, rest); |
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4847 rest = skipwhite(rest)) |
7 | 4848 { |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
4849 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
|
4850 eap->skip); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4851 if (rest == NULL || ends_excmd2(eap->arg, rest)) |
154 | 4852 break; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4853 // 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
|
4854 while (*rest != NUL && !VIM_ISWHITE(*rest)) |
154 | 4855 { |
4856 if (*rest == '\\' && rest[1] != NUL) | |
4857 ++rest; | |
4858 *p++ = *rest++; | |
4859 } | |
4860 *p++ = NUL; | |
4861 ++cnt; | |
4862 } | |
4863 | |
4864 if (!eap->skip) | |
4865 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4866 // Adjust flags for use of ":syn include". |
154 | 4867 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
4868 | |
7 | 4869 /* |
154 | 4870 * 2: Add an entry for each keyword. |
7 | 4871 */ |
154 | 4872 for (kw = keyword_copy; --cnt >= 0; kw += STRLEN(kw) + 1) |
7 | 4873 { |
154 | 4874 for (p = vim_strchr(kw, '['); ; ) |
7 | 4875 { |
154 | 4876 if (p != NULL) |
4877 *p = NUL; | |
4878 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
|
4879 syn_opt_arg.cont_in_list, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4880 syn_opt_arg.next_list, conceal_char); |
168 | 4881 if (p == NULL) |
4882 break; | |
4883 if (p[1] == NUL) | |
4884 { | |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26913
diff
changeset
|
4885 semsg(_(e_error_missing_rsb_str), kw); |
7017 | 4886 goto error; |
168 | 4887 } |
4888 if (p[1] == ']') | |
4889 { | |
7017 | 4890 if (p[2] != NUL) |
4891 { | |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
4892 semsg(_(e_trailing_char_after_rsb_str_str), |
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
4893 kw, &p[2]); |
7017 | 4894 goto error; |
4895 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4896 kw = p + 1; // skip over the "]" |
168 | 4897 break; |
4898 } | |
154 | 4899 if (has_mbyte) |
7 | 4900 { |
474 | 4901 int l = (*mb_ptr2len)(p + 1); |
154 | 4902 |
4903 mch_memmove(p, p + 1, l); | |
4904 p += l; | |
4905 } | |
4906 else | |
4907 { | |
4908 p[0] = p[1]; | |
4909 ++p; | |
7 | 4910 } |
4911 } | |
4912 } | |
4913 } | |
7017 | 4914 error: |
7 | 4915 vim_free(keyword_copy); |
168 | 4916 vim_free(syn_opt_arg.cont_in_list); |
4917 vim_free(syn_opt_arg.next_list); | |
7 | 4918 } |
4919 } | |
4920 | |
4921 if (rest != NULL) | |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
4922 set_nextcmd(eap, rest); |
7 | 4923 else |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26199
diff
changeset
|
4924 semsg(_(e_invalid_argument_str), arg); |
7 | 4925 |
745 | 4926 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4927 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 4928 } |
4929 | |
4930 /* | |
4931 * Handle ":syntax match {name} [{options}] {pattern} [{options}]". | |
4932 * | |
4933 * Also ":syntax sync match {name} [[grouphere | groupthere] {group-name}] .." | |
4934 */ | |
4935 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4936 syn_cmd_match( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4937 exarg_T *eap, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4938 int syncing) // TRUE for ":syntax sync match .. " |
7 | 4939 { |
4940 char_u *arg = eap->arg; | |
4941 char_u *group_name_end; | |
4942 char_u *rest; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4943 synpat_T item; // the item found in the line |
7 | 4944 int syn_id; |
4945 int idx; | |
154 | 4946 syn_opt_arg_T syn_opt_arg; |
7 | 4947 int sync_idx = 0; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4948 int conceal_char = NUL; |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4949 int orig_called_emsg = called_emsg; |
7 | 4950 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4951 // Isolate the group name, check for validity |
7 | 4952 rest = get_group_name(arg, &group_name_end); |
4953 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4954 // Get options before the pattern |
154 | 4955 syn_opt_arg.flags = 0; |
4956 syn_opt_arg.keyword = FALSE; | |
4957 syn_opt_arg.sync_idx = syncing ? &sync_idx : NULL; | |
4958 syn_opt_arg.has_cont_list = TRUE; | |
4959 syn_opt_arg.cont_list = NULL; | |
4960 syn_opt_arg.cont_in_list = NULL; | |
4961 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
|
4962 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 4963 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4964 // get the pattern. |
7 | 4965 init_syn_patterns(); |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
4966 CLEAR_FIELD(item); |
7 | 4967 rest = get_syn_pattern(rest, &item); |
154 | 4968 if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
4969 syn_opt_arg.flags |= HL_HAS_EOL; | |
7 | 4970 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4971 // 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
|
4972 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
7 | 4973 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
4974 if (rest != NULL) // all arguments are valid |
7 | 4975 { |
4976 /* | |
4977 * Check for trailing command and illegal trailing arguments. | |
4978 */ | |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
4979 set_nextcmd(eap, rest); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4980 if (!ends_excmd2(eap->cmd, rest) || eap->skip) |
7 | 4981 rest = NULL; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4982 else if (ga_grow(&curwin->w_s->b_syn_patterns, 1) != FAIL |
7 | 4983 && (syn_id = syn_check_group(arg, |
4984 (int)(group_name_end - arg))) != 0) | |
4985 { | |
154 | 4986 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 4987 /* |
4988 * Store the pattern in the syn_items list | |
4989 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4990 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
|
4991 SYN_ITEMS(curwin->w_s)[idx] = item; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
4992 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
|
4993 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
|
4994 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
|
4995 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
|
4996 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
|
4997 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
|
4998 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
|
4999 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5000 syn_opt_arg.cont_in_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5001 #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
|
5002 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
|
5003 #endif |
154 | 5004 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
|
5005 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5006 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
|
5007 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5008 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5009 // remember that we found a match for syncing on |
154 | 5010 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
|
5011 curwin->w_s->b_syn_sync_flags |= SF_MATCH; |
7 | 5012 #ifdef FEAT_FOLDING |
154 | 5013 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
|
5014 ++curwin->w_s->b_syn_folditems; |
7 | 5015 #endif |
5016 | |
745 | 5017 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5018 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5019 return; // don't free the progs and patterns now |
7 | 5020 } |
5021 } | |
5022 | |
5023 /* | |
5024 * Something failed, free the allocated memory. | |
5025 */ | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5026 vim_regfree(item.sp_prog); |
7 | 5027 vim_free(item.sp_pattern); |
154 | 5028 vim_free(syn_opt_arg.cont_list); |
5029 vim_free(syn_opt_arg.cont_in_list); | |
5030 vim_free(syn_opt_arg.next_list); | |
7 | 5031 |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5032 if (rest == NULL && called_emsg == orig_called_emsg) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26199
diff
changeset
|
5033 semsg(_(e_invalid_argument_str), arg); |
7 | 5034 } |
5035 | |
5036 /* | |
5037 * Handle ":syntax region {group-name} [matchgroup={group-name}] | |
5038 * start {start} .. [skip {skip}] end {end} .. [{options}]". | |
5039 */ | |
5040 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5041 syn_cmd_region( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5042 exarg_T *eap, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5043 int syncing) // TRUE for ":syntax sync region .." |
7 | 5044 { |
5045 char_u *arg = eap->arg; | |
5046 char_u *group_name_end; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5047 char_u *rest; // next arg, NULL on error |
7 | 5048 char_u *key_end; |
5049 char_u *key = NULL; | |
5050 char_u *p; | |
5051 int item; | |
5052 #define ITEM_START 0 | |
5053 #define ITEM_SKIP 1 | |
5054 #define ITEM_END 2 | |
5055 #define ITEM_MATCHGROUP 3 | |
5056 struct pat_ptr | |
5057 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5058 synpat_T *pp_synp; // pointer to syn_pattern |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5059 int pp_matchgroup_id; // matchgroup ID |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5060 struct pat_ptr *pp_next; // pointer to next pat_ptr |
7 | 5061 } *(pat_ptrs[3]); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5062 // patterns found in the line |
7 | 5063 struct pat_ptr *ppp; |
5064 struct pat_ptr *ppp_next; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5065 int pat_count = 0; // nr of syn_patterns found |
7 | 5066 int syn_id; |
5067 int matchgroup_id = 0; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5068 int not_enough = FALSE; // not enough arguments |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5069 int illegal = FALSE; // illegal arguments |
7 | 5070 int success = FALSE; |
5071 int idx; | |
154 | 5072 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
|
5073 int conceal_char = NUL; |
7 | 5074 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5075 // Isolate the group name, check for validity |
7 | 5076 rest = get_group_name(arg, &group_name_end); |
5077 | |
5078 pat_ptrs[0] = NULL; | |
5079 pat_ptrs[1] = NULL; | |
5080 pat_ptrs[2] = NULL; | |
5081 | |
5082 init_syn_patterns(); | |
5083 | |
154 | 5084 syn_opt_arg.flags = 0; |
5085 syn_opt_arg.keyword = FALSE; | |
5086 syn_opt_arg.sync_idx = NULL; | |
5087 syn_opt_arg.has_cont_list = TRUE; | |
5088 syn_opt_arg.cont_list = NULL; | |
5089 syn_opt_arg.cont_in_list = NULL; | |
5090 syn_opt_arg.next_list = NULL; | |
5091 | |
7 | 5092 /* |
5093 * get the options, patterns and matchgroup. | |
5094 */ | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5095 while (rest != NULL && !ends_excmd2(eap->cmd, rest)) |
7 | 5096 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5097 // 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
|
5098 rest = get_syn_options(rest, &syn_opt_arg, &conceal_char, eap->skip); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5099 if (rest == NULL || ends_excmd2(eap->cmd, rest)) |
7 | 5100 break; |
5101 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5102 // must be a pattern or matchgroup then |
7 | 5103 key_end = rest; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5104 while (*key_end && !VIM_ISWHITE(*key_end) && *key_end != '=') |
7 | 5105 ++key_end; |
5106 vim_free(key); | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20623
diff
changeset
|
5107 key = vim_strnsave_up(rest, key_end - rest); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5108 if (key == NULL) // out of memory |
7 | 5109 { |
5110 rest = NULL; | |
5111 break; | |
5112 } | |
5113 if (STRCMP(key, "MATCHGROUP") == 0) | |
5114 item = ITEM_MATCHGROUP; | |
5115 else if (STRCMP(key, "START") == 0) | |
5116 item = ITEM_START; | |
5117 else if (STRCMP(key, "END") == 0) | |
5118 item = ITEM_END; | |
5119 else if (STRCMP(key, "SKIP") == 0) | |
5120 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5121 if (pat_ptrs[ITEM_SKIP] != NULL) // one skip pattern allowed |
7 | 5122 { |
5123 illegal = TRUE; | |
5124 break; | |
5125 } | |
5126 item = ITEM_SKIP; | |
5127 } | |
5128 else | |
5129 break; | |
5130 rest = skipwhite(key_end); | |
5131 if (*rest != '=') | |
5132 { | |
5133 rest = NULL; | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5134 semsg(_(e_missing_equal_str), arg); |
7 | 5135 break; |
5136 } | |
5137 rest = skipwhite(rest + 1); | |
5138 if (*rest == NUL) | |
5139 { | |
5140 not_enough = TRUE; | |
5141 break; | |
5142 } | |
5143 | |
5144 if (item == ITEM_MATCHGROUP) | |
5145 { | |
5146 p = skiptowhite(rest); | |
5147 if ((p - rest == 4 && STRNCMP(rest, "NONE", 4) == 0) || eap->skip) | |
5148 matchgroup_id = 0; | |
5149 else | |
5150 { | |
5151 matchgroup_id = syn_check_group(rest, (int)(p - rest)); | |
5152 if (matchgroup_id == 0) | |
5153 { | |
5154 illegal = TRUE; | |
5155 break; | |
5156 } | |
5157 } | |
5158 rest = skipwhite(p); | |
5159 } | |
5160 else | |
5161 { | |
5162 /* | |
5163 * Allocate room for a syn_pattern, and link it in the list of | |
5164 * syn_patterns for this item, at the start (because the list is | |
5165 * used from end to start). | |
5166 */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
5167 ppp = ALLOC_ONE(struct pat_ptr); |
7 | 5168 if (ppp == NULL) |
5169 { | |
5170 rest = NULL; | |
5171 break; | |
5172 } | |
5173 ppp->pp_next = pat_ptrs[item]; | |
5174 pat_ptrs[item] = ppp; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
5175 ppp->pp_synp = ALLOC_CLEAR_ONE(synpat_T); |
7 | 5176 if (ppp->pp_synp == NULL) |
5177 { | |
5178 rest = NULL; | |
5179 break; | |
5180 } | |
5181 | |
5182 /* | |
5183 * Get the syntax pattern and the following offset(s). | |
5184 */ | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5185 // Enable the appropriate \z specials. |
7 | 5186 if (item == ITEM_START) |
5187 reg_do_extmatch = REX_SET; | |
5188 else if (item == ITEM_SKIP || item == ITEM_END) | |
5189 reg_do_extmatch = REX_USE; | |
5190 rest = get_syn_pattern(rest, ppp->pp_synp); | |
5191 reg_do_extmatch = 0; | |
5192 if (item == ITEM_END && vim_regcomp_had_eol() | |
154 | 5193 && !(syn_opt_arg.flags & HL_EXCLUDENL)) |
7 | 5194 ppp->pp_synp->sp_flags |= HL_HAS_EOL; |
5195 ppp->pp_matchgroup_id = matchgroup_id; | |
5196 ++pat_count; | |
5197 } | |
5198 } | |
5199 vim_free(key); | |
5200 if (illegal || not_enough) | |
5201 rest = NULL; | |
5202 | |
5203 /* | |
5204 * Must have a "start" and "end" pattern. | |
5205 */ | |
5206 if (rest != NULL && (pat_ptrs[ITEM_START] == NULL || | |
5207 pat_ptrs[ITEM_END] == NULL)) | |
5208 { | |
5209 not_enough = TRUE; | |
5210 rest = NULL; | |
5211 } | |
5212 | |
5213 if (rest != NULL) | |
5214 { | |
5215 /* | |
5216 * Check for trailing garbage or command. | |
5217 * If OK, add the item. | |
5218 */ | |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
5219 set_nextcmd(eap, rest); |
7 | 5220 if (!ends_excmd(*rest) || eap->skip) |
5221 rest = NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5222 else if (ga_grow(&(curwin->w_s->b_syn_patterns), pat_count) != FAIL |
7 | 5223 && (syn_id = syn_check_group(arg, |
5224 (int)(group_name_end - arg))) != 0) | |
5225 { | |
154 | 5226 syn_incl_toplevel(syn_id, &syn_opt_arg.flags); |
7 | 5227 /* |
5228 * Store the start/skip/end in the syn_items list | |
5229 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5230 idx = curwin->w_s->b_syn_patterns.ga_len; |
7 | 5231 for (item = ITEM_START; item <= ITEM_END; ++item) |
5232 { | |
5233 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp->pp_next) | |
5234 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5235 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
|
5236 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
|
5237 SYN_ITEMS(curwin->w_s)[idx].sp_type = |
7 | 5238 (item == ITEM_START) ? SPTYPE_START : |
5239 (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
|
5240 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
|
5241 SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id; |
2743 | 5242 SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = |
5243 current_syn_inc_tag; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5244 SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id = |
7 | 5245 ppp->pp_matchgroup_id; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5246 #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
|
5247 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
|
5248 #endif |
7 | 5249 if (item == ITEM_START) |
5250 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5251 SYN_ITEMS(curwin->w_s)[idx].sp_cont_list = |
154 | 5252 syn_opt_arg.cont_list; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5253 SYN_ITEMS(curwin->w_s)[idx].sp_syn.cont_in_list = |
154 | 5254 syn_opt_arg.cont_in_list; |
5255 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
|
5256 curwin->w_s->b_syn_containedin = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5257 SYN_ITEMS(curwin->w_s)[idx].sp_next_list = |
154 | 5258 syn_opt_arg.next_list; |
7 | 5259 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5260 ++curwin->w_s->b_syn_patterns.ga_len; |
7 | 5261 ++idx; |
5262 #ifdef FEAT_FOLDING | |
154 | 5263 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
|
5264 ++curwin->w_s->b_syn_folditems; |
7 | 5265 #endif |
5266 } | |
5267 } | |
5268 | |
745 | 5269 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5270 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5271 success = TRUE; // don't free the progs and patterns now |
7 | 5272 } |
5273 } | |
5274 | |
5275 /* | |
5276 * Free the allocated memory. | |
5277 */ | |
5278 for (item = ITEM_START; item <= ITEM_END; ++item) | |
5279 for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) | |
5280 { | |
17907
4cf69f8d1ec6
patch 8.1.1950: using NULL pointer after an out-of-memory
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
5281 if (!success && ppp->pp_synp != NULL) |
7 | 5282 { |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
5283 vim_regfree(ppp->pp_synp->sp_prog); |
7 | 5284 vim_free(ppp->pp_synp->sp_pattern); |
5285 } | |
5286 vim_free(ppp->pp_synp); | |
5287 ppp_next = ppp->pp_next; | |
5288 vim_free(ppp); | |
5289 } | |
5290 | |
5291 if (!success) | |
5292 { | |
154 | 5293 vim_free(syn_opt_arg.cont_list); |
5294 vim_free(syn_opt_arg.cont_in_list); | |
5295 vim_free(syn_opt_arg.next_list); | |
7 | 5296 if (not_enough) |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5297 semsg(_(e_not_enough_arguments_syntax_region_str), arg); |
7 | 5298 else if (illegal || rest == NULL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26199
diff
changeset
|
5299 semsg(_(e_invalid_argument_str), arg); |
7 | 5300 } |
5301 } | |
5302 | |
5303 /* | |
5304 * A simple syntax group ID comparison function suitable for use in qsort() | |
5305 */ | |
5306 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5307 syn_compare_stub(const void *v1, const void *v2) |
7 | 5308 { |
5309 const short *s1 = v1; | |
5310 const short *s2 = v2; | |
5311 | |
5312 return (*s1 > *s2 ? 1 : *s1 < *s2 ? -1 : 0); | |
5313 } | |
5314 | |
5315 /* | |
5316 * Combines lists of syntax clusters. | |
5317 * *clstr1 and *clstr2 must both be allocated memory; they will be consumed. | |
5318 */ | |
5319 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5320 syn_combine_list(short **clstr1, short **clstr2, int list_op) |
7 | 5321 { |
5322 int count1 = 0; | |
5323 int count2 = 0; | |
5324 short *g1; | |
5325 short *g2; | |
5326 short *clstr = NULL; | |
5327 int count; | |
5328 int round; | |
5329 | |
5330 /* | |
5331 * Handle degenerate cases. | |
5332 */ | |
5333 if (*clstr2 == NULL) | |
5334 return; | |
5335 if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) | |
5336 { | |
5337 if (list_op == CLUSTER_REPLACE) | |
5338 vim_free(*clstr1); | |
5339 if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) | |
5340 *clstr1 = *clstr2; | |
5341 else | |
5342 vim_free(*clstr2); | |
5343 return; | |
5344 } | |
5345 | |
5346 for (g1 = *clstr1; *g1; g1++) | |
5347 ++count1; | |
5348 for (g2 = *clstr2; *g2; g2++) | |
5349 ++count2; | |
5350 | |
5351 /* | |
5352 * For speed purposes, sort both lists. | |
5353 */ | |
5354 qsort(*clstr1, (size_t)count1, sizeof(short), syn_compare_stub); | |
5355 qsort(*clstr2, (size_t)count2, sizeof(short), syn_compare_stub); | |
5356 | |
5357 /* | |
5358 * We proceed in two passes; in round 1, we count the elements to place | |
5359 * in the new list, and in round 2, we allocate and populate the new | |
5360 * list. For speed, we use a mergesort-like method, adding the smaller | |
5361 * of the current elements in each list to the new list. | |
5362 */ | |
5363 for (round = 1; round <= 2; round++) | |
5364 { | |
5365 g1 = *clstr1; | |
5366 g2 = *clstr2; | |
5367 count = 0; | |
5368 | |
5369 /* | |
5370 * First, loop through the lists until one of them is empty. | |
5371 */ | |
5372 while (*g1 && *g2) | |
5373 { | |
5374 /* | |
5375 * We always want to add from the first list. | |
5376 */ | |
5377 if (*g1 < *g2) | |
5378 { | |
5379 if (round == 2) | |
5380 clstr[count] = *g1; | |
5381 count++; | |
5382 g1++; | |
5383 continue; | |
5384 } | |
5385 /* | |
5386 * We only want to add from the second list if we're adding the | |
5387 * lists. | |
5388 */ | |
5389 if (list_op == CLUSTER_ADD) | |
5390 { | |
5391 if (round == 2) | |
5392 clstr[count] = *g2; | |
5393 count++; | |
5394 } | |
5395 if (*g1 == *g2) | |
5396 g1++; | |
5397 g2++; | |
5398 } | |
5399 | |
5400 /* | |
5401 * Now add the leftovers from whichever list didn't get finished | |
5402 * first. As before, we only want to add from the second list if | |
5403 * we're adding the lists. | |
5404 */ | |
5405 for (; *g1; g1++, count++) | |
5406 if (round == 2) | |
5407 clstr[count] = *g1; | |
5408 if (list_op == CLUSTER_ADD) | |
5409 for (; *g2; g2++, count++) | |
5410 if (round == 2) | |
5411 clstr[count] = *g2; | |
5412 | |
5413 if (round == 1) | |
5414 { | |
5415 /* | |
5416 * If the group ended up empty, we don't need to allocate any | |
5417 * space for it. | |
5418 */ | |
5419 if (count == 0) | |
5420 { | |
5421 clstr = NULL; | |
5422 break; | |
5423 } | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
5424 clstr = ALLOC_MULT(short, count + 1); |
7 | 5425 if (clstr == NULL) |
5426 break; | |
5427 clstr[count] = 0; | |
5428 } | |
5429 } | |
5430 | |
5431 /* | |
5432 * Finally, put the new list in place. | |
5433 */ | |
5434 vim_free(*clstr1); | |
5435 vim_free(*clstr2); | |
5436 *clstr1 = clstr; | |
5437 } | |
5438 | |
5439 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5440 * Lookup a syntax cluster name and return its ID. |
7 | 5441 * If it is not found, 0 is returned. |
5442 */ | |
5443 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5444 syn_scl_name2id(char_u *name) |
7 | 5445 { |
5446 int i; | |
5447 char_u *name_u; | |
5448 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5449 // Avoid using stricmp() too much, it's slow on some systems |
7 | 5450 name_u = vim_strsave_up(name); |
5451 if (name_u == NULL) | |
5452 return 0; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5453 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
|
5454 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
|
5455 && STRCMP(name_u, SYN_CLSTR(curwin->w_s)[i].scl_name_u) == 0) |
7 | 5456 break; |
5457 vim_free(name_u); | |
5458 return (i < 0 ? 0 : i + SYNID_CLUSTER); | |
5459 } | |
5460 | |
5461 /* | |
5462 * Like syn_scl_name2id(), but take a pointer + length argument. | |
5463 */ | |
5464 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5465 syn_scl_namen2id(char_u *linep, int len) |
7 | 5466 { |
5467 char_u *name; | |
5468 int id = 0; | |
5469 | |
5470 name = vim_strnsave(linep, len); | |
5471 if (name != NULL) | |
5472 { | |
5473 id = syn_scl_name2id(name); | |
5474 vim_free(name); | |
5475 } | |
5476 return id; | |
5477 } | |
5478 | |
5479 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5480 * Find syntax cluster name in the table and return its ID. |
7 | 5481 * The argument is a pointer to the name and the length of the name. |
5482 * If it doesn't exist yet, a new entry is created. | |
5483 * Return 0 for failure. | |
5484 */ | |
5485 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5486 syn_check_cluster(char_u *pp, int len) |
7 | 5487 { |
5488 int id; | |
5489 char_u *name; | |
5490 | |
5491 name = vim_strnsave(pp, len); | |
5492 if (name == NULL) | |
5493 return 0; | |
5494 | |
5495 id = syn_scl_name2id(name); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5496 if (id == 0) // doesn't exist yet |
7 | 5497 id = syn_add_cluster(name); |
5498 else | |
5499 vim_free(name); | |
5500 return id; | |
5501 } | |
5502 | |
5503 /* | |
11189
e74af2aca96e
patch 8.0.0481: unnecessary if statement
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
5504 * Add new syntax cluster and return its ID. |
7 | 5505 * "name" must be an allocated string, it will be consumed. |
5506 * Return 0 for failure. | |
5507 */ | |
5508 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5509 syn_add_cluster(char_u *name) |
221 | 5510 { |
5511 int len; | |
7 | 5512 |
5513 /* | |
5514 * First call for this growarray: init growing array. | |
5515 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5516 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
|
5517 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5518 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
|
5519 curwin->w_s->b_syn_clusters.ga_growsize = 10; |
7 | 5520 } |
5521 | |
2743 | 5522 len = curwin->w_s->b_syn_clusters.ga_len; |
5523 if (len >= MAX_CLUSTER_ID) | |
5524 { | |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
5525 emsg(_(e_too_many_syntax_clusters)); |
2743 | 5526 vim_free(name); |
5527 return 0; | |
5528 } | |
5529 | |
7 | 5530 /* |
5531 * Make room for at least one other cluster entry. | |
5532 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5533 if (ga_grow(&curwin->w_s->b_syn_clusters, 1) == FAIL) |
7 | 5534 { |
5535 vim_free(name); | |
5536 return 0; | |
5537 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5538 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19934
diff
changeset
|
5539 CLEAR_POINTER(&(SYN_CLSTR(curwin->w_s)[len])); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5540 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
|
5541 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
|
5542 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
|
5543 ++curwin->w_s->b_syn_clusters.ga_len; |
7 | 5544 |
221 | 5545 if (STRICMP(name, "Spell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5546 curwin->w_s->b_spell_cluster_id = len + SYNID_CLUSTER; |
227 | 5547 if (STRICMP(name, "NoSpell") == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5548 curwin->w_s->b_nospell_cluster_id = len + SYNID_CLUSTER; |
221 | 5549 |
7 | 5550 return len + SYNID_CLUSTER; |
5551 } | |
5552 | |
5553 /* | |
5554 * Handle ":syntax cluster {cluster-name} [contains={groupname},..] | |
5555 * [add={groupname},..] [remove={groupname},..]". | |
5556 */ | |
5557 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5558 syn_cmd_cluster(exarg_T *eap, int syncing UNUSED) |
7 | 5559 { |
5560 char_u *arg = eap->arg; | |
5561 char_u *group_name_end; | |
5562 char_u *rest; | |
5563 int scl_id; | |
5564 short *clstr_list; | |
5565 int got_clstr = FALSE; | |
5566 int opt_len; | |
5567 int list_op; | |
5568 | |
5569 eap->nextcmd = find_nextcmd(arg); | |
5570 if (eap->skip) | |
5571 return; | |
5572 | |
5573 rest = get_group_name(arg, &group_name_end); | |
5574 | |
5575 if (rest != NULL) | |
5576 { | |
2743 | 5577 scl_id = syn_check_cluster(arg, (int)(group_name_end - arg)); |
5578 if (scl_id == 0) | |
5579 return; | |
5580 scl_id -= SYNID_CLUSTER; | |
7 | 5581 |
5582 for (;;) | |
5583 { | |
5584 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
|
5585 && (VIM_ISWHITE(rest[3]) || rest[3] == '=')) |
7 | 5586 { |
5587 opt_len = 3; | |
5588 list_op = CLUSTER_ADD; | |
5589 } | |
5590 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
|
5591 && (VIM_ISWHITE(rest[6]) || rest[6] == '=')) |
7 | 5592 { |
5593 opt_len = 6; | |
5594 list_op = CLUSTER_SUBTRACT; | |
5595 } | |
5596 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
|
5597 && (VIM_ISWHITE(rest[8]) || rest[8] == '=')) |
7 | 5598 { |
5599 opt_len = 8; | |
5600 list_op = CLUSTER_REPLACE; | |
5601 } | |
5602 else | |
5603 break; | |
5604 | |
5605 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
|
5606 if (get_id_list(&rest, opt_len, &clstr_list, eap->skip) == FAIL) |
7 | 5607 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26199
diff
changeset
|
5608 semsg(_(e_invalid_argument_str), rest); |
7 | 5609 break; |
5610 } | |
10618
4ee16e5e2e26
patch 8.0.0198: some syntax arguments take effect even after "if 0"
Christian Brabandt <cb@256bit.org>
parents:
10534
diff
changeset
|
5611 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
|
5612 syn_combine_list(&SYN_CLSTR(curwin->w_s)[scl_id].scl_list, |
7 | 5613 &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
|
5614 else |
4f3decf25b7d
patch 8.0.0214: leaking memory when syntax cluster id is unknown
Christian Brabandt <cb@256bit.org>
parents:
10629
diff
changeset
|
5615 vim_free(clstr_list); |
7 | 5616 got_clstr = TRUE; |
5617 } | |
5618 | |
5619 if (got_clstr) | |
5620 { | |
745 | 5621 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5622 syn_stack_free_all(curwin->w_s); // Need to recompute all. |
7 | 5623 } |
5624 } | |
5625 | |
5626 if (!got_clstr) | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5627 emsg(_(e_no_cluster_specified)); |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5628 if (rest == NULL || !ends_excmd2(eap->cmd, rest)) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26199
diff
changeset
|
5629 semsg(_(e_invalid_argument_str), arg); |
7 | 5630 } |
5631 | |
5632 /* | |
5633 * On first call for current buffer: Init growing array. | |
5634 */ | |
5635 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5636 init_syn_patterns(void) |
7 | 5637 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5638 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
|
5639 curwin->w_s->b_syn_patterns.ga_growsize = 10; |
7 | 5640 } |
5641 | |
5642 /* | |
5643 * Get one pattern for a ":syntax match" or ":syntax region" command. | |
5644 * Stores the pattern and program in a synpat_T. | |
5645 * Returns a pointer to the next argument, or NULL in case of an error. | |
5646 */ | |
5647 static char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5648 get_syn_pattern(char_u *arg, synpat_T *ci) |
7 | 5649 { |
5650 char_u *end; | |
5651 int *p; | |
5652 int idx; | |
5653 char_u *cpo_save; | |
5654 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5655 // need at least three chars |
6993 | 5656 if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) |
7 | 5657 return NULL; |
5658 | |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
5659 end = skip_regexp(arg + 1, *arg, TRUE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5660 if (*end != *arg) // end delimiter not found |
7 | 5661 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5662 semsg(_(e_pattern_delimiter_not_found_str), arg); |
7 | 5663 return NULL; |
5664 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5665 // store the pattern and compiled regexp program |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5666 if ((ci->sp_pattern = vim_strnsave(arg + 1, end - arg - 1)) == NULL) |
7 | 5667 return NULL; |
5668 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5669 // Make 'cpoptions' empty, to avoid the 'l' flag |
7 | 5670 cpo_save = p_cpo; |
23493
f8382c4e6551
patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents:
23043
diff
changeset
|
5671 p_cpo = empty_option; |
7 | 5672 ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); |
5673 p_cpo = cpo_save; | |
5674 | |
5675 if (ci->sp_prog == NULL) | |
5676 return NULL; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5677 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
|
5678 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5679 syn_clear_time(&ci->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5680 #endif |
7 | 5681 |
5682 /* | |
5683 * Check for a match, highlight or region offset. | |
5684 */ | |
5685 ++end; | |
5686 do | |
5687 { | |
5688 for (idx = SPO_COUNT; --idx >= 0; ) | |
5689 if (STRNCMP(end, spo_name_tab[idx], 3) == 0) | |
5690 break; | |
5691 if (idx >= 0) | |
5692 { | |
5693 p = &(ci->sp_offsets[idx]); | |
5694 if (idx != SPO_LC_OFF) | |
5695 switch (end[3]) | |
5696 { | |
5697 case 's': break; | |
5698 case 'b': break; | |
5699 case 'e': idx += SPO_COUNT; break; | |
5700 default: idx = -1; break; | |
5701 } | |
5702 if (idx >= 0) | |
5703 { | |
5704 ci->sp_off_flags |= (1 << idx); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5705 if (idx == SPO_LC_OFF) // lc=99 |
7 | 5706 { |
5707 end += 3; | |
5708 *p = getdigits(&end); | |
5709 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5710 // "lc=" offset automatically sets "ms=" offset |
7 | 5711 if (!(ci->sp_off_flags & (1 << SPO_MS_OFF))) |
5712 { | |
5713 ci->sp_off_flags |= (1 << SPO_MS_OFF); | |
5714 ci->sp_offsets[SPO_MS_OFF] = *p; | |
5715 } | |
5716 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5717 else // yy=x+99 |
7 | 5718 { |
5719 end += 4; | |
5720 if (*end == '+') | |
5721 { | |
5722 ++end; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5723 *p = getdigits(&end); // positive offset |
7 | 5724 } |
5725 else if (*end == '-') | |
5726 { | |
5727 ++end; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5728 *p = -getdigits(&end); // negative offset |
7 | 5729 } |
5730 } | |
5731 if (*end != ',') | |
5732 break; | |
5733 ++end; | |
5734 } | |
5735 } | |
5736 } while (idx >= 0); | |
5737 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5738 if (!ends_excmd2(arg, end) && !VIM_ISWHITE(*end)) |
7 | 5739 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5740 semsg(_(e_garbage_after_pattern_str), arg); |
7 | 5741 return NULL; |
5742 } | |
5743 return skipwhite(end); | |
5744 } | |
5745 | |
5746 /* | |
5747 * Handle ":syntax sync .." command. | |
5748 */ | |
5749 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5750 syn_cmd_sync(exarg_T *eap, int syncing UNUSED) |
7 | 5751 { |
5752 char_u *arg_start = eap->arg; | |
5753 char_u *arg_end; | |
5754 char_u *key = NULL; | |
5755 char_u *next_arg; | |
5756 int illegal = FALSE; | |
5757 int finished = FALSE; | |
5758 long n; | |
5759 char_u *cpo_save; | |
5760 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5761 if (ends_excmd2(eap->cmd, arg_start)) |
7 | 5762 { |
5763 syn_cmd_list(eap, TRUE); | |
5764 return; | |
5765 } | |
5766 | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5767 while (!ends_excmd2(eap->cmd, arg_start)) |
7 | 5768 { |
5769 arg_end = skiptowhite(arg_start); | |
5770 next_arg = skipwhite(arg_end); | |
5771 vim_free(key); | |
20751
d9a2e5dcfd9f
patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20623
diff
changeset
|
5772 key = vim_strnsave_up(arg_start, arg_end - arg_start); |
21240
e35955a787a8
patch 8.2.1171: possible crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
5773 if (key == NULL) |
e35955a787a8
patch 8.2.1171: possible crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
5774 break; |
7 | 5775 if (STRCMP(key, "CCOMMENT") == 0) |
5776 { | |
5777 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5778 curwin->w_s->b_syn_sync_flags |= SF_CCOMMENT; |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5779 if (!ends_excmd2(eap->cmd, next_arg)) |
7 | 5780 { |
5781 arg_end = skiptowhite(next_arg); | |
5782 if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5783 curwin->w_s->b_syn_sync_id = syn_check_group(next_arg, |
7 | 5784 (int)(arg_end - next_arg)); |
5785 next_arg = skipwhite(arg_end); | |
5786 } | |
5787 else if (!eap->skip) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5788 curwin->w_s->b_syn_sync_id = syn_name2id((char_u *)"Comment"); |
7 | 5789 } |
5790 else if ( STRNCMP(key, "LINES", 5) == 0 | |
5791 || STRNCMP(key, "MINLINES", 8) == 0 | |
5792 || STRNCMP(key, "MAXLINES", 8) == 0 | |
5793 || STRNCMP(key, "LINEBREAKS", 10) == 0) | |
5794 { | |
5795 if (key[4] == 'S') | |
5796 arg_end = key + 6; | |
5797 else if (key[0] == 'L') | |
5798 arg_end = key + 11; | |
5799 else | |
5800 arg_end = key + 9; | |
5801 if (arg_end[-1] != '=' || !VIM_ISDIGIT(*arg_end)) | |
5802 { | |
5803 illegal = TRUE; | |
5804 break; | |
5805 } | |
5806 n = getdigits(&arg_end); | |
5807 if (!eap->skip) | |
5808 { | |
5809 if (key[4] == 'B') | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5810 curwin->w_s->b_syn_sync_linebreaks = n; |
7 | 5811 else if (key[1] == 'A') |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5812 curwin->w_s->b_syn_sync_maxlines = n; |
7 | 5813 else |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5814 curwin->w_s->b_syn_sync_minlines = n; |
7 | 5815 } |
5816 } | |
5817 else if (STRCMP(key, "FROMSTART") == 0) | |
5818 { | |
5819 if (!eap->skip) | |
5820 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5821 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
|
5822 curwin->w_s->b_syn_sync_maxlines = 0; |
7 | 5823 } |
5824 } | |
5825 else if (STRCMP(key, "LINECONT") == 0) | |
5826 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5827 if (*next_arg == NUL) // missing pattern |
7504
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5828 { |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5829 illegal = TRUE; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5830 break; |
013f285f31a6
commit https://github.com/vim/vim/commit/2795e21eaafaeaf95a91667fd411023280d0f902
Christian Brabandt <cb@256bit.org>
parents:
7500
diff
changeset
|
5831 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5832 if (curwin->w_s->b_syn_linecont_pat != NULL) |
7 | 5833 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5834 emsg(_(e_syntax_sync_line_continuations_pattern_specified_twice)); |
7 | 5835 finished = TRUE; |
5836 break; | |
5837 } | |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
5838 arg_end = skip_regexp(next_arg + 1, *next_arg, TRUE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5839 if (*arg_end != *next_arg) // end delimiter not found |
7 | 5840 { |
5841 illegal = TRUE; | |
5842 break; | |
5843 } | |
5844 | |
5845 if (!eap->skip) | |
5846 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5847 // store the pattern and compiled regexp program |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5848 if ((curwin->w_s->b_syn_linecont_pat = |
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5849 vim_strnsave(next_arg + 1, |
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
5850 arg_end - next_arg - 1)) == NULL) |
7 | 5851 { |
5852 finished = TRUE; | |
5853 break; | |
5854 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5855 curwin->w_s->b_syn_linecont_ic = curwin->w_s->b_syn_ic; |
7 | 5856 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5857 // Make 'cpoptions' empty, to avoid the 'l' flag |
7 | 5858 cpo_save = p_cpo; |
23493
f8382c4e6551
patch 8.2.2289: Vim9: 'cpo' can become empty
Bram Moolenaar <Bram@vim.org>
parents:
23043
diff
changeset
|
5859 p_cpo = empty_option; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5860 curwin->w_s->b_syn_linecont_prog = |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5861 vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); |
7 | 5862 p_cpo = cpo_save; |
4766
ec24ff78a79c
updated for version 7.3.1130
Bram Moolenaar <bram@vim.org>
parents:
4764
diff
changeset
|
5863 #ifdef FEAT_PROFILE |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5864 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
|
5865 #endif |
7 | 5866 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
5867 if (curwin->w_s->b_syn_linecont_prog == NULL) |
7 | 5868 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
5869 VIM_CLEAR(curwin->w_s->b_syn_linecont_pat); |
7 | 5870 finished = TRUE; |
5871 break; | |
5872 } | |
5873 } | |
5874 next_arg = skipwhite(arg_end + 1); | |
5875 } | |
5876 else | |
5877 { | |
5878 eap->arg = next_arg; | |
5879 if (STRCMP(key, "MATCH") == 0) | |
5880 syn_cmd_match(eap, TRUE); | |
5881 else if (STRCMP(key, "REGION") == 0) | |
5882 syn_cmd_region(eap, TRUE); | |
5883 else if (STRCMP(key, "CLEAR") == 0) | |
5884 syn_cmd_clear(eap, TRUE); | |
5885 else | |
5886 illegal = TRUE; | |
5887 finished = TRUE; | |
5888 break; | |
5889 } | |
5890 arg_start = next_arg; | |
5891 } | |
5892 vim_free(key); | |
5893 if (illegal) | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5894 semsg(_(e_illegal_arguments_str), arg_start); |
7 | 5895 else if (!finished) |
5896 { | |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
5897 set_nextcmd(eap, arg_start); |
745 | 5898 redraw_curbuf_later(SOME_VALID); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5899 syn_stack_free_all(curwin->w_s); // Need to recompute all syntax. |
7 | 5900 } |
5901 } | |
5902 | |
5903 /* | |
5904 * Convert a line of highlight group names into a list of group ID numbers. | |
5905 * "arg" should point to the "contains" or "nextgroup" keyword. | |
5906 * "arg" is advanced to after the last group name. | |
5907 * Careful: the argument is modified (NULs added). | |
5908 * returns FAIL for some error, OK for success. | |
5909 */ | |
5910 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5911 get_id_list( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
5912 char_u **arg, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5913 int keylen, // length of keyword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5914 short **list, // where to store the resulting list, if not |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5915 // 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
|
5916 int skip) |
7 | 5917 { |
5918 char_u *p = NULL; | |
5919 char_u *end; | |
5920 int round; | |
5921 int count; | |
5922 int total_count = 0; | |
5923 short *retval = NULL; | |
5924 char_u *name; | |
5925 regmatch_T regmatch; | |
5926 int id; | |
5927 int i; | |
5928 int failed = FALSE; | |
5929 | |
5930 /* | |
5931 * We parse the list twice: | |
5932 * round == 1: count the number of items, allocate the array. | |
5933 * round == 2: fill the array with the items. | |
5934 * In round 1 new groups may be added, causing the number of items to | |
5935 * grow when a regexp is used. In that case round 1 is done once again. | |
5936 */ | |
5937 for (round = 1; round <= 2; ++round) | |
5938 { | |
5939 /* | |
5940 * skip "contains" | |
5941 */ | |
5942 p = skipwhite(*arg + keylen); | |
5943 if (*p != '=') | |
5944 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5945 semsg(_(e_missing_equal_sign_str), *arg); |
7 | 5946 break; |
5947 } | |
5948 p = skipwhite(p + 1); | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5949 if (ends_excmd2(*arg, p)) |
7 | 5950 { |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5951 semsg(_(e_empty_argument_str), *arg); |
7 | 5952 break; |
5953 } | |
5954 | |
5955 /* | |
5956 * parse the arguments after "contains" | |
5957 */ | |
5958 count = 0; | |
20116
513c62184ed8
patch 8.2.0613: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
5959 while (!ends_excmd2(*arg, p)) |
7 | 5960 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5961 for (end = p; *end && !VIM_ISWHITE(*end) && *end != ','; ++end) |
7 | 5962 ; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
5963 name = alloc(end - p + 3); // leave room for "^$" |
7 | 5964 if (name == NULL) |
5965 { | |
5966 failed = TRUE; | |
5967 break; | |
5968 } | |
419 | 5969 vim_strncpy(name + 1, p, end - p); |
7 | 5970 if ( STRCMP(name + 1, "ALLBUT") == 0 |
5971 || STRCMP(name + 1, "ALL") == 0 | |
5972 || STRCMP(name + 1, "TOP") == 0 | |
5973 || STRCMP(name + 1, "CONTAINED") == 0) | |
5974 { | |
5975 if (TOUPPER_ASC(**arg) != 'C') | |
5976 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5977 semsg(_(e_str_not_allowed_here), name + 1); |
7 | 5978 failed = TRUE; |
5979 vim_free(name); | |
5980 break; | |
5981 } | |
5982 if (count != 0) | |
5983 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5984 semsg(_(e_str_must_be_first_in_contains_list), name + 1); |
7 | 5985 failed = TRUE; |
5986 vim_free(name); | |
5987 break; | |
5988 } | |
5989 if (name[1] == 'A') | |
24442
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5990 id = SYNID_ALLBUT + current_syn_inc_tag; |
7 | 5991 else if (name[1] == 'T') |
24442
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5992 { |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5993 if (curwin->w_s->b_syn_topgrp >= SYNID_CLUSTER) |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5994 id = curwin->w_s->b_syn_topgrp; |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5995 else |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5996 id = SYNID_TOP + current_syn_inc_tag; |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5997 } |
7 | 5998 else |
24442
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
5999 id = SYNID_CONTAINED + current_syn_inc_tag; |
d16a69f718b5
patch 8.2.2761: using "syn include" does not work properly
Bram Moolenaar <Bram@vim.org>
parents:
23493
diff
changeset
|
6000 |
7 | 6001 } |
6002 else if (name[1] == '@') | |
6003 { | |
10629
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6004 if (skip) |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6005 id = -1; |
16fc46021e51
patch 8.0.0204: compiler warns for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10624
diff
changeset
|
6006 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
|
6007 id = syn_check_cluster(name + 2, (int)(end - p - 1)); |
7 | 6008 } |
6009 else | |
6010 { | |
6011 /* | |
6012 * Handle full group name. | |
6013 */ | |
6014 if (vim_strpbrk(name + 1, (char_u *)"\\.*^$~[") == NULL) | |
6015 id = syn_check_group(name + 1, (int)(end - p)); | |
6016 else | |
6017 { | |
6018 /* | |
6019 * Handle match of regexp with group names. | |
6020 */ | |
6021 *name = '^'; | |
6022 STRCAT(name, "$"); | |
6023 regmatch.regprog = vim_regcomp(name, RE_MAGIC); | |
6024 if (regmatch.regprog == NULL) | |
6025 { | |
6026 failed = TRUE; | |
6027 vim_free(name); | |
6028 break; | |
6029 } | |
6030 | |
6031 regmatch.rm_ic = TRUE; | |
6032 id = 0; | |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
6033 for (i = highlight_num_groups(); --i >= 0; ) |
7 | 6034 { |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
6035 if (vim_regexec(®match, highlight_group_name(i), |
7 | 6036 (colnr_T)0)) |
6037 { | |
6038 if (round == 2) | |
6039 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6040 // Got more items than expected; can happen |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6041 // when adding items that match: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6042 // "contains=a.*b,axb". |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6043 // Go back to first round |
7 | 6044 if (count >= total_count) |
6045 { | |
6046 vim_free(retval); | |
6047 round = 1; | |
6048 } | |
6049 else | |
6050 retval[count] = i + 1; | |
6051 } | |
6052 ++count; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6053 id = -1; // remember that we found one |
7 | 6054 } |
6055 } | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4803
diff
changeset
|
6056 vim_regfree(regmatch.regprog); |
7 | 6057 } |
6058 } | |
6059 vim_free(name); | |
6060 if (id == 0) | |
6061 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
6062 semsg(_(e_unknown_group_name_str), p); |
7 | 6063 failed = TRUE; |
6064 break; | |
6065 } | |
6066 if (id > 0) | |
6067 { | |
6068 if (round == 2) | |
6069 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6070 // Got more items than expected, go back to first round |
7 | 6071 if (count >= total_count) |
6072 { | |
6073 vim_free(retval); | |
6074 round = 1; | |
6075 } | |
6076 else | |
6077 retval[count] = id; | |
6078 } | |
6079 ++count; | |
6080 } | |
6081 p = skipwhite(end); | |
6082 if (*p != ',') | |
6083 break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6084 p = skipwhite(p + 1); // skip comma in between arguments |
7 | 6085 } |
6086 if (failed) | |
6087 break; | |
6088 if (round == 1) | |
6089 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
6090 retval = ALLOC_MULT(short, count + 1); |
7 | 6091 if (retval == NULL) |
6092 break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6093 retval[count] = 0; // zero means end of the list |
7 | 6094 total_count = count; |
6095 } | |
6096 } | |
6097 | |
6098 *arg = p; | |
6099 if (failed || retval == NULL) | |
6100 { | |
6101 vim_free(retval); | |
6102 return FAIL; | |
6103 } | |
6104 | |
6105 if (*list == NULL) | |
6106 *list = retval; | |
6107 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6108 vim_free(retval); // list already found, don't overwrite it |
7 | 6109 |
6110 return OK; | |
6111 } | |
6112 | |
6113 /* | |
6114 * Make a copy of an ID list. | |
6115 */ | |
6116 static short * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6117 copy_id_list(short *list) |
7 | 6118 { |
6119 int len; | |
6120 int count; | |
6121 short *retval; | |
6122 | |
6123 if (list == NULL) | |
6124 return NULL; | |
6125 | |
6126 for (count = 0; list[count]; ++count) | |
6127 ; | |
6128 len = (count + 1) * sizeof(short); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
6129 retval = alloc(len); |
7 | 6130 if (retval != NULL) |
6131 mch_memmove(retval, list, (size_t)len); | |
6132 | |
6133 return retval; | |
6134 } | |
6135 | |
6136 /* | |
6137 * Check if syntax group "ssp" is in the ID list "list" of "cur_si". | |
6138 * "cur_si" can be NULL if not checking the "containedin" list. | |
6139 * Used to check if a syntax item is in the "contains" or "nextgroup" list of | |
6140 * the current item. | |
6141 * This function is called very often, keep it fast!! | |
6142 */ | |
6143 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6144 in_id_list( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6145 stateitem_T *cur_si, // current item or NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6146 short *list, // id list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6147 struct sp_syn *ssp, // group id and ":syn include" tag of group |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6148 int contained) // group id is contained |
7 | 6149 { |
6150 int retval; | |
6151 short *scl_list; | |
6152 short item; | |
6153 short id = ssp->id; | |
6154 static int depth = 0; | |
6155 int r; | |
6156 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6157 // If ssp has a "containedin" list and "cur_si" is in it, return TRUE. |
36 | 6158 if (cur_si != NULL && ssp->cont_in_list != NULL |
6159 && !(cur_si->si_flags & HL_MATCH)) | |
7 | 6160 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6161 // Ignore transparent items without a contains argument. Double check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6162 // that we don't go back past the first one. |
7 | 6163 while ((cur_si->si_flags & HL_TRANS_CONT) |
6164 && cur_si > (stateitem_T *)(current_state.ga_data)) | |
6165 --cur_si; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6166 // cur_si->si_idx is -1 for keywords, these never contain anything. |
7 | 6167 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
|
6168 &(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
|
6169 SYN_ITEMS(syn_block)[cur_si->si_idx].sp_flags & HL_CONTAINED)) |
7 | 6170 return TRUE; |
6171 } | |
6172 | |
6173 if (list == NULL) | |
6174 return FALSE; | |
6175 | |
6176 /* | |
6177 * If list is ID_LIST_ALL, we are in a transparent item that isn't | |
6178 * inside anything. Only allow not-contained groups. | |
6179 */ | |
6180 if (list == ID_LIST_ALL) | |
6181 return !contained; | |
6182 | |
6183 /* | |
6184 * If the first item is "ALLBUT", return TRUE if "id" is NOT in the | |
6185 * contains list. We also require that "id" is at the same ":syn include" | |
6186 * level as the list. | |
6187 */ | |
6188 item = *list; | |
6189 if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) | |
6190 { | |
6191 if (item < SYNID_TOP) | |
6192 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6193 // ALL or ALLBUT: accept all groups in the same file |
7 | 6194 if (item - SYNID_ALLBUT != ssp->inc_tag) |
6195 return FALSE; | |
6196 } | |
6197 else if (item < SYNID_CONTAINED) | |
6198 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6199 // TOP: accept all not-contained groups in the same file |
7 | 6200 if (item - SYNID_TOP != ssp->inc_tag || contained) |
6201 return FALSE; | |
6202 } | |
6203 else | |
6204 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6205 // CONTAINED: accept all contained groups in the same file |
7 | 6206 if (item - SYNID_CONTAINED != ssp->inc_tag || !contained) |
6207 return FALSE; | |
6208 } | |
6209 item = *++list; | |
6210 retval = FALSE; | |
6211 } | |
6212 else | |
6213 retval = TRUE; | |
6214 | |
6215 /* | |
6216 * Return "retval" if id is in the contains list. | |
6217 */ | |
6218 while (item != 0) | |
6219 { | |
6220 if (item == id) | |
6221 return retval; | |
6222 if (item >= SYNID_CLUSTER) | |
6223 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6224 scl_list = SYN_CLSTR(syn_block)[item - SYNID_CLUSTER].scl_list; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6225 // restrict recursiveness to 30 to avoid an endless loop for a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6226 // cluster that includes itself (indirectly) |
7 | 6227 if (scl_list != NULL && depth < 30) |
6228 { | |
6229 ++depth; | |
6230 r = in_id_list(NULL, scl_list, ssp, contained); | |
6231 --depth; | |
6232 if (r) | |
6233 return retval; | |
6234 } | |
6235 } | |
6236 item = *++list; | |
6237 } | |
6238 return !retval; | |
6239 } | |
6240 | |
6241 struct subcommand | |
6242 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6243 char *name; // subcommand name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6244 void (*func)(exarg_T *, int); // function to call |
7 | 6245 }; |
6246 | |
6247 static struct subcommand subcommands[] = | |
6248 { | |
6249 {"case", syn_cmd_case}, | |
6250 {"clear", syn_cmd_clear}, | |
6251 {"cluster", syn_cmd_cluster}, | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6252 {"conceal", syn_cmd_conceal}, |
7 | 6253 {"enable", syn_cmd_enable}, |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6254 {"foldlevel", syn_cmd_foldlevel}, |
7 | 6255 {"include", syn_cmd_include}, |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6256 {"iskeyword", syn_cmd_iskeyword}, |
7 | 6257 {"keyword", syn_cmd_keyword}, |
6258 {"list", syn_cmd_list}, | |
6259 {"manual", syn_cmd_manual}, | |
6260 {"match", syn_cmd_match}, | |
6261 {"on", syn_cmd_on}, | |
6262 {"off", syn_cmd_off}, | |
6263 {"region", syn_cmd_region}, | |
6264 {"reset", syn_cmd_reset}, | |
419 | 6265 {"spell", syn_cmd_spell}, |
7 | 6266 {"sync", syn_cmd_sync}, |
6267 {"", syn_cmd_list}, | |
6268 {NULL, NULL} | |
6269 }; | |
6270 | |
6271 /* | |
6272 * ":syntax". | |
6273 * This searches the subcommands[] table for the subcommand name, and calls a | |
6274 * syntax_subcommand() function to do the rest. | |
6275 */ | |
6276 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6277 ex_syntax(exarg_T *eap) |
7 | 6278 { |
6279 char_u *arg = eap->arg; | |
6280 char_u *subcmd_end; | |
6281 char_u *subcmd_name; | |
6282 int i; | |
6283 | |
6284 syn_cmdlinep = eap->cmdlinep; | |
6285 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6286 // isolate subcommand name |
7 | 6287 for (subcmd_end = arg; ASCII_ISALPHA(*subcmd_end); ++subcmd_end) |
6288 ; | |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20751
diff
changeset
|
6289 subcmd_name = vim_strnsave(arg, subcmd_end - arg); |
7 | 6290 if (subcmd_name != NULL) |
6291 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6292 if (eap->skip) // skip error messages for all subcommands |
7 | 6293 ++emsg_skip; |
6294 for (i = 0; ; ++i) | |
6295 { | |
6296 if (subcommands[i].name == NULL) | |
6297 { | |
26913
d4e61d61afd9
patch 8.2.3985: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
6298 semsg(_(e_invalid_syntax_subcommand_str), subcmd_name); |
7 | 6299 break; |
6300 } | |
6301 if (STRCMP(subcmd_name, (char_u *)subcommands[i].name) == 0) | |
6302 { | |
6303 eap->arg = skipwhite(subcmd_end); | |
6304 (subcommands[i].func)(eap, FALSE); | |
6305 break; | |
6306 } | |
6307 } | |
6308 vim_free(subcmd_name); | |
6309 if (eap->skip) | |
6310 --emsg_skip; | |
6311 } | |
6312 } | |
6313 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6314 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6315 ex_ownsyntax(exarg_T *eap) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6316 { |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6317 char_u *old_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6318 char_u *new_value; |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6319 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6320 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
|
6321 { |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16790
diff
changeset
|
6322 curwin->w_s = ALLOC_ONE(synblock_T); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6323 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
|
6324 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
|
6325 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
|
6326 #ifdef FEAT_SPELL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6327 // TODO: keep the spell checking as it was. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6328 curwin->w_p_spell = FALSE; // No spell checking |
22258
a6af570dad75
patch 8.2.1678: crash when using ":set" after ":ownsyntax"
Bram Moolenaar <Bram@vim.org>
parents:
21240
diff
changeset
|
6329 // make sure option values are "empty_option" instead of NULL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6330 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
|
6331 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
|
6332 clear_string_option(&curwin->w_s->b_p_spl); |
22258
a6af570dad75
patch 8.2.1678: crash when using ":set" after ":ownsyntax"
Bram Moolenaar <Bram@vim.org>
parents:
21240
diff
changeset
|
6333 clear_string_option(&curwin->w_s->b_p_spo); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6334 #endif |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7685
diff
changeset
|
6335 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
|
6336 } |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6337 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6338 // save value of b:current_syntax |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6339 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
|
6340 if (old_value != NULL) |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6341 old_value = vim_strsave(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6342 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6343 // Apply the "syntax" autocommand event, this finds and loads the syntax |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6344 // file. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6345 apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, TRUE, curbuf); |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6346 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6347 // move value of b:current_syntax to w:current_syntax |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6348 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
|
6349 if (new_value != NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6350 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
|
6351 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6352 // restore value of b:current_syntax |
2256
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6353 if (old_value == NULL) |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6354 do_unlet((char_u *)"b:current_syntax", TRUE); |
8b3203df361f
Fix crash for ":ownsyntax". (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2253
diff
changeset
|
6355 else |
2252
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6356 { |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6357 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
|
6358 vim_free(old_value); |
a0b5918c33cc
Fixed memory leak in ":ownsyntax".
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
6359 } |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6360 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6361 |
7 | 6362 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6363 syntax_present(win_T *win) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6364 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6365 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
|
6366 || 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
|
6367 || 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
|
6368 || win->w_s->b_keywtab_ic.ht_used > 0); |
7 | 6369 } |
6370 | |
6371 | |
6372 static enum | |
6373 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6374 EXP_SUBCMD, // expand ":syn" sub-commands |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6375 EXP_CASE, // expand ":syn case" arguments |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6376 EXP_SPELL, // expand ":syn spell" arguments |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6377 EXP_SYNC // expand ":syn sync" arguments |
7 | 6378 } expand_what; |
6379 | |
1322 | 6380 /* |
6381 * Reset include_link, include_default, include_none to 0. | |
6382 * Called when we are done expanding. | |
6383 */ | |
6384 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6385 reset_expand_highlight(void) |
1322 | 6386 { |
6387 include_link = include_default = include_none = 0; | |
6388 } | |
6389 | |
6390 /* | |
6391 * Handle command line completion for :match and :echohl command: Add "None" | |
6392 * as highlight group. | |
6393 */ | |
6394 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6395 set_context_in_echohl_cmd(expand_T *xp, char_u *arg) |
1322 | 6396 { |
6397 xp->xp_context = EXPAND_HIGHLIGHT; | |
6398 xp->xp_pattern = arg; | |
6399 include_none = 1; | |
6400 } | |
7 | 6401 |
6402 /* | |
6403 * Handle command line completion for :syntax command. | |
6404 */ | |
6405 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6406 set_context_in_syntax_cmd(expand_T *xp, char_u *arg) |
7 | 6407 { |
6408 char_u *p; | |
6409 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6410 // Default: expand subcommands |
7 | 6411 xp->xp_context = EXPAND_SYNTAX; |
6412 expand_what = EXP_SUBCMD; | |
6413 xp->xp_pattern = arg; | |
1322 | 6414 include_link = 0; |
6415 include_default = 0; | |
7 | 6416 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6417 // (part of) subcommand already typed |
7 | 6418 if (*arg != NUL) |
6419 { | |
6420 p = skiptowhite(arg); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6421 if (*p != NUL) // past first word |
7 | 6422 { |
6423 xp->xp_pattern = skipwhite(p); | |
6424 if (*skiptowhite(xp->xp_pattern) != NUL) | |
6425 xp->xp_context = EXPAND_NOTHING; | |
6426 else if (STRNICMP(arg, "case", p - arg) == 0) | |
6427 expand_what = EXP_CASE; | |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6428 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
|
6429 expand_what = EXP_SPELL; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6430 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
|
6431 expand_what = EXP_SYNC; |
7 | 6432 else if ( STRNICMP(arg, "keyword", p - arg) == 0 |
6433 || STRNICMP(arg, "region", p - arg) == 0 | |
6434 || STRNICMP(arg, "match", p - arg) == 0 | |
6435 || STRNICMP(arg, "list", p - arg) == 0) | |
6436 xp->xp_context = EXPAND_HIGHLIGHT; | |
6437 else | |
6438 xp->xp_context = EXPAND_NOTHING; | |
6439 } | |
6440 } | |
6441 } | |
6442 | |
6443 /* | |
6444 * Function given to ExpandGeneric() to obtain the list syntax names for | |
6445 * expansion. | |
6446 */ | |
6447 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6448 get_syntax_name(expand_T *xp UNUSED, int idx) |
7 | 6449 { |
10534
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6450 switch (expand_what) |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6451 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6452 case EXP_SUBCMD: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6453 return (char_u *)subcommands[idx].name; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6454 case EXP_CASE: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6455 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6456 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
|
6457 return (char_u *)case_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6458 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6459 case EXP_SPELL: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6460 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6461 static char *spell_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6462 {"toplevel", "notoplevel", "default", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6463 return (char_u *)spell_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6464 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6465 case EXP_SYNC: |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6466 { |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6467 static char *sync_args[] = |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6468 {"ccomment", "clear", "fromstart", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6469 "linebreaks=", "linecont", "lines=", "match", |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6470 "maxlines=", "minlines=", "region", NULL}; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6471 return (char_u *)sync_args[idx]; |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6472 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6473 } |
1c6db35e3527
commit https://github.com/vim/vim/commit/2d02839050a2557bf36dab37ccd9f92168a757d1
Christian Brabandt <cb@256bit.org>
parents:
10530
diff
changeset
|
6474 return NULL; |
7 | 6475 } |
6476 | |
6477 | |
6478 /* | |
6479 * Function called for expression evaluation: get syntax ID at file position. | |
6480 */ | |
6481 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6482 syn_get_id( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6483 win_T *wp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6484 long lnum, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6485 colnr_T col, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6486 int trans, // remove transparency |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6487 int *spellp, // return: can do spell checking |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6488 int keep_state) // keep state of char at "col" |
7 | 6489 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6490 // When the position is not after the current position and in the same |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6491 // line of the same buffer, need to restart parsing. |
499 | 6492 if (wp->w_buffer != syn_buf |
7 | 6493 || lnum != current_lnum |
253 | 6494 || col < current_col) |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6495 syntax_start(wp, lnum); |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6496 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
|
6497 && lnum == current_lnum |
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6498 && col > current_col) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6499 // next_match may not be correct when moving around, e.g. with the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6500 // "skip" expression in searchpair() |
7685
616460b73ee3
commit https://github.com/vim/vim/commit/6773a348da0dcf45df3c6c6649880655ec0d2042
Christian Brabandt <cb@256bit.org>
parents:
7504
diff
changeset
|
6501 next_match_idx = -1; |
7 | 6502 |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6503 (void)get_syntax_attr(col, spellp, keep_state); |
7 | 6504 |
6505 return (trans ? current_trans_id : current_id); | |
6506 } | |
6507 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6508 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6509 /* |
2375
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6510 * 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
|
6511 * 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
|
6512 * 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
|
6513 * 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
|
6514 */ |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6515 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6516 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
|
6517 { |
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
|
6518 *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
|
6519 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
|
6520 } |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6521 |
a96dd77ce213
For conceal mode: when two different syntax items follow each other, show the
Bram Moolenaar <bram@vim.org>
parents:
2318
diff
changeset
|
6522 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6523 * Return conceal substitution character |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6524 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6525 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6526 syn_get_sub_char(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6527 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6528 return current_sub_char; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6529 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6530 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
6531 |
1500 | 6532 #if defined(FEAT_EVAL) || defined(PROTO) |
6533 /* | |
6534 * Return the syntax ID at position "i" in the current stack. | |
6535 * The caller must have called syn_get_id() before to fill the stack. | |
6536 * Returns -1 when "i" is out of range. | |
6537 */ | |
6538 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6539 syn_get_stack_item(int i) |
1500 | 6540 { |
1504 | 6541 if (i >= current_state.ga_len) |
6542 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6543 // Need to invalidate the state, because we didn't properly finish it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6544 // for the last character, "keep_state" was TRUE. |
1504 | 6545 invalidate_current_state(); |
6546 current_col = MAXCOL; | |
1500 | 6547 return -1; |
1504 | 6548 } |
1500 | 6549 return CUR_STATE(i).si_id; |
6550 } | |
6551 #endif | |
6552 | |
7 | 6553 #if defined(FEAT_FOLDING) || defined(PROTO) |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6554 static int |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6555 syn_cur_foldlevel(void) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6556 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6557 int level = 0; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6558 int i; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6559 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6560 for (i = 0; i < current_state.ga_len; ++i) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6561 if (CUR_STATE(i).si_flags & HL_FOLD) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6562 ++level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6563 return level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6564 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6565 |
7 | 6566 /* |
6567 * Function called to get folding level for line "lnum" in window "wp". | |
6568 */ | |
6569 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6570 syn_get_foldlevel(win_T *wp, long lnum) |
7 | 6571 { |
6572 int level = 0; | |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6573 int low_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6574 int cur_level; |
7 | 6575 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6576 // 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
|
6577 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
|
6578 && !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
|
6579 # 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
|
6580 && !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
|
6581 # endif |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6582 ) |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6583 { |
12510
7a887dccd13a
patch 8.0.1133: syntax timeout not used correctly
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
6584 syntax_start(wp, lnum); |
7 | 6585 |
20623
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6586 // Start with the fold level at the start of the line. |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6587 level = syn_cur_foldlevel(); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6588 |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6589 if (wp->w_s->b_syn_foldlevel == SYNFLD_MINIMUM) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6590 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6591 // Find the lowest fold level that is followed by a higher one. |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6592 cur_level = level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6593 low_level = cur_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6594 while (!current_finished) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6595 { |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6596 (void)syn_current_attr(FALSE, FALSE, NULL, FALSE); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6597 cur_level = syn_cur_foldlevel(); |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6598 if (cur_level < low_level) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6599 low_level = cur_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6600 else if (cur_level > low_level) |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6601 level = low_level; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6602 ++current_col; |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6603 } |
99b6e6bf48bf
patch 8.2.0865: syntax foldlevel is taken from the start of the line
Bram Moolenaar <Bram@vim.org>
parents:
20116
diff
changeset
|
6604 } |
7 | 6605 } |
6606 if (level > wp->w_p_fdn) | |
1028 | 6607 { |
7 | 6608 level = wp->w_p_fdn; |
1028 | 6609 if (level < 0) |
6610 level = 0; | |
6611 } | |
7 | 6612 return level; |
6613 } | |
6614 #endif | |
6615 | |
6567 | 6616 #if defined(FEAT_PROFILE) || defined(PROTO) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6617 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6618 * ":syntime". |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6619 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6620 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6621 ex_syntime(exarg_T *eap) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6622 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6623 if (STRCMP(eap->arg, "on") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6624 syn_time_on = TRUE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6625 else if (STRCMP(eap->arg, "off") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6626 syn_time_on = FALSE; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6627 else if (STRCMP(eap->arg, "clear") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6628 syntime_clear(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6629 else if (STRCMP(eap->arg, "report") == 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6630 syntime_report(); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6631 else |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26199
diff
changeset
|
6632 semsg(_(e_invalid_argument_str), eap->arg); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6633 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6634 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6635 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6636 syn_clear_time(syn_time_T *st) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6637 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6638 profile_zero(&st->total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6639 profile_zero(&st->slowest); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6640 st->count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6641 st->match = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6642 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6643 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6644 /* |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6645 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6646 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6647 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6648 syntime_clear(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6649 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6650 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6651 synpat_T *spp; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6652 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6653 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6654 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6655 msg(_(msg_no_items)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6656 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6657 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6658 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
|
6659 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6660 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6661 syn_clear_time(&spp->sp_time); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6662 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6663 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6664 |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6665 /* |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6666 * 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
|
6667 * ":syntime {on,off,clear,report}" command. |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6668 */ |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6669 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6670 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
|
6671 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6672 switch (idx) |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6673 { |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6674 case 0: return (char_u *)"on"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6675 case 1: return (char_u *)"off"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6676 case 2: return (char_u *)"clear"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6677 case 3: return (char_u *)"report"; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6678 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6679 return NULL; |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6680 } |
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6681 |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6682 typedef struct |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6683 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6684 proftime_T total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6685 int count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6686 int match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6687 proftime_T slowest; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6688 proftime_T average; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6689 int id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6690 char_u *pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6691 } time_entry_T; |
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 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6694 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
|
6695 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6696 const time_entry_T *s1 = v1; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6697 const time_entry_T *s2 = v2; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6698 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6699 return profile_cmp(&s1->total, &s2->total); |
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 |
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 * Clear the syntax timing for the current buffer. |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6704 */ |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6705 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
6706 syntime_report(void) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6707 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6708 int idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6709 synpat_T *spp; |
22991
cb7df44afe7e
patch 8.2.2042: build failure with +profile but without +reltime
Bram Moolenaar <Bram@vim.org>
parents:
22928
diff
changeset
|
6710 # if defined(FEAT_RELTIME) && defined(FEAT_FLOAT) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6711 proftime_T tm; |
4803
220bdea4f579
updated for version 7.3.1148
Bram Moolenaar <bram@vim.org>
parents:
4791
diff
changeset
|
6712 # endif |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6713 int len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6714 proftime_T total_total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6715 int total_count = 0; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6716 garray_T ga; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6717 time_entry_T *p; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6718 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6719 if (!syntax_present(curwin)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6720 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6721 msg(_(msg_no_items)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6722 return; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6723 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6724 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6725 ga_init2(&ga, sizeof(time_entry_T), 50); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6726 profile_zero(&total_total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6727 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
|
6728 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6729 spp = &(SYN_ITEMS(curwin->w_s)[idx]); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6730 if (spp->sp_time.count > 0) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6731 { |
7009 | 6732 (void)ga_grow(&ga, 1); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6733 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
|
6734 p->total = spp->sp_time.total; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6735 profile_add(&total_total, &spp->sp_time.total); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6736 p->count = spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6737 p->match = spp->sp_time.match; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6738 total_count += spp->sp_time.count; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6739 p->slowest = spp->sp_time.slowest; |
22991
cb7df44afe7e
patch 8.2.2042: build failure with +profile but without +reltime
Bram Moolenaar <Bram@vim.org>
parents:
22928
diff
changeset
|
6740 # if defined(FEAT_RELTIME) && defined(FEAT_FLOAT) |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6741 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
|
6742 p->average = tm; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6743 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6744 p->id = spp->sp_syn.id; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6745 p->pattern = spp->sp_pattern; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6746 ++ga.ga_len; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6747 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6748 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6749 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6750 // Sort on total time. Skip if there are no items to avoid passing NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6751 // pointer to qsort(). |
10530
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6752 if (ga.ga_len > 1) |
ea5adbeccfc1
commit https://github.com/vim/vim/commit/a216255a4faa91a15e7005ac319f2f62294f3f9e
Christian Brabandt <cb@256bit.org>
parents:
10499
diff
changeset
|
6753 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
|
6754 syn_compare_syntime); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6755 |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6756 msg_puts_title(_(" TOTAL COUNT MATCH SLOWEST AVERAGE NAME PATTERN")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6757 msg_puts("\n"); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6758 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
|
6759 { |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6760 p = ((time_entry_T *)ga.ga_data) + idx; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6761 |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6762 msg_puts(profile_msg(&p->total)); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6763 msg_puts(" "); // make sure there is always a separating space |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6764 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6765 msg_outnum(p->count); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6766 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6767 msg_advance(20); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6768 msg_outnum(p->match); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6769 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6770 msg_advance(26); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6771 msg_puts(profile_msg(&p->slowest)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6772 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6773 msg_advance(38); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6774 # ifdef FEAT_FLOAT |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6775 msg_puts(profile_msg(&p->average)); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6776 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6777 # endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6778 msg_advance(50); |
17401
5462bb963075
patch 8.1.1699: highlight_ga can be local instead of global
Bram Moolenaar <Bram@vim.org>
parents:
17389
diff
changeset
|
6779 msg_outtrans(highlight_group_name(p->id - 1)); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6780 msg_puts(" "); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6781 |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6782 msg_advance(69); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6783 if (Columns < 80) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6784 len = 20; // will wrap anyway |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6785 else |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6786 len = Columns - 70; |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6787 if (len > (int)STRLEN(p->pattern)) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6788 len = (int)STRLEN(p->pattern); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6789 msg_outtrans_len(p->pattern, len); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6790 msg_puts("\n"); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6791 } |
4791
65cef998f860
updated for version 7.3.1142
Bram Moolenaar <bram@vim.org>
parents:
4776
diff
changeset
|
6792 ga_clear(&ga); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6793 if (!got_int) |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6794 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6795 msg_puts("\n"); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6796 msg_puts(profile_msg(&total_total)); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6797 msg_advance(13); |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6798 msg_outnum(total_count); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6799 msg_puts("\n"); |
4764
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6800 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6801 } |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6802 #endif |
f824cb97eb92
updated for version 7.3.1129
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
6803 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
17907
diff
changeset
|
6804 #endif // FEAT_SYN_HL |