Mercurial > emacs
comparison src/syntax.h @ 20649:388cedeebb88
(SYNTAX_TABLE_BYTE_TO_CHAR): New macro.
(struct gl_state_s): New field `object'.
(SETUP_SYNTAX_TABLE_FOR_OBJECT): Set it.
Handle non-current buffer properly. Args renamed to all caps.
(SETUP_SYNTAX_TABLE): Set `object'. Args renamed to all caps.
(UPDATE_SYNTAX_TABLE): Use gl_state.object.
(UPDATE_SYNTAX_TABLE_FORWARD, UPDATE_SYNTAX_TABLE_BACKWARD): Likewise.
(SETUP_SYNTAX_TABLE_FOR_OBJECT): Add gl_state.offset
when using the arg FROM. Use BYTE_TO_CHAR.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 16 Jan 1998 17:52:16 +0000 |
parents | a884f0426ab9 |
children | ed9ed828415e |
comparison
equal
deleted
inserted
replaced
20648:b644667dcd19 | 20649:388cedeebb88 |
---|---|
192 | 192 |
193 /* Indexed by syntax code, give the letter that describes it. */ | 193 /* Indexed by syntax code, give the letter that describes it. */ |
194 | 194 |
195 extern char syntax_code_spec[16]; | 195 extern char syntax_code_spec[16]; |
196 | 196 |
197 /* Convert the byte offset BYTEPOS into a character position, | |
198 for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT. */ | |
199 | |
200 #define SYNTAX_TABLE_BYTE_TO_CHAR(bytepos) \ | |
201 (STRINGP (gl_state.object) \ | |
202 ? string_byte_to_char (gl_state.object, (bytepos)) \ | |
203 : BUFFERP (gl_state.object) \ | |
204 ? buf_bytepos_to_charpos (XBUFFER (gl_state.object), (bytepos)) \ | |
205 : NILP (gl_state.object) \ | |
206 ? BYTE_TO_CHAR ((bytepos)) \ | |
207 : (bytepos)) | |
208 | |
197 /* Make syntax table state (gl_state) good for POS, assuming it is | 209 /* Make syntax table state (gl_state) good for POS, assuming it is |
198 currently good for a position before POS. */ | 210 currently good for a position before POS. */ |
199 | 211 |
200 #define UPDATE_SYNTAX_TABLE_FORWARD(pos) \ | 212 #define UPDATE_SYNTAX_TABLE_FORWARD(pos) \ |
201 ((pos) >= gl_state.e_property - gl_state.offset \ | 213 ((pos) >= gl_state.e_property - gl_state.offset \ |
202 ? (update_syntax_table ((pos) + gl_state.offset, 1, 0, Qnil), 1) : 0) | 214 ? (update_syntax_table ((pos) + gl_state.offset, 1, 0, \ |
215 gl_state.object), \ | |
216 1) \ | |
217 : 0) | |
203 | 218 |
204 /* Make syntax table state (gl_state) good for POS, assuming it is | 219 /* Make syntax table state (gl_state) good for POS, assuming it is |
205 currently good for a position after POS. */ | 220 currently good for a position after POS. */ |
206 | 221 |
207 #define UPDATE_SYNTAX_TABLE_BACKWARD(pos) \ | 222 #define UPDATE_SYNTAX_TABLE_BACKWARD(pos) \ |
208 ((pos) <= gl_state.b_property - gl_state.offset \ | 223 ((pos) <= gl_state.b_property - gl_state.offset \ |
209 ? (update_syntax_table ((pos) + gl_state.offset, -1, 0, Qnil), 1) : 0) | 224 ? (update_syntax_table ((pos) + gl_state.offset, -1, 0, \ |
225 gl_state.object), \ | |
226 1) \ | |
227 : 0) | |
210 | 228 |
211 /* Make syntax table good for POS. */ | 229 /* Make syntax table good for POS. */ |
212 | 230 |
213 #define UPDATE_SYNTAX_TABLE(pos) \ | 231 #define UPDATE_SYNTAX_TABLE(pos) \ |
214 ((pos) <= gl_state.b_property - gl_state.offset \ | 232 ((pos) <= gl_state.b_property - gl_state.offset \ |
215 ? (update_syntax_table ((pos) + gl_state.offset, -1, 0, Qnil), 1) \ | 233 ? (update_syntax_table ((pos) + gl_state.offset, -1, 0, \ |
216 : ((pos) >= gl_state.e_property - gl_state.offset \ | 234 gl_state.object), \ |
217 ? (update_syntax_table ((pos) + gl_state.offset, 1, 0, Qnil), 1) : 0)) | 235 1) \ |
236 : ((pos) >= gl_state.e_property - gl_state.offset \ | |
237 ? (update_syntax_table ((pos) + gl_state.offset, 1, 0, \ | |
238 gl_state.object), \ | |
239 1) \ | |
240 : 0)) | |
218 | 241 |
219 /* This macro should be called with FROM at the start of forward | 242 /* This macro should be called with FROM at the start of forward |
220 search, or after the last position of the backward search. It | 243 search, or after the last position of the backward search. It |
221 makes sure that the first char is picked up with correct table, so | 244 makes sure that the first char is picked up with correct table, so |
222 one does not need to call UPDATE_SYNTAX_TABLE immediately after the | 245 one does not need to call UPDATE_SYNTAX_TABLE immediately after the |
223 call. | 246 call. |
224 Sign of COUNT gives the direction of the search. | 247 Sign of COUNT gives the direction of the search. |
225 */ | 248 */ |
226 | 249 |
227 #define SETUP_SYNTAX_TABLE(from,count) \ | 250 #define SETUP_SYNTAX_TABLE(FROM, COUNT) \ |
228 gl_state.b_property = BEGV - 1; \ | 251 gl_state.b_property = BEGV - 1; \ |
229 gl_state.e_property = ZV + 1; \ | 252 gl_state.e_property = ZV + 1; \ |
253 gl_state.object = Qnil; \ | |
230 gl_state.use_global = 0; \ | 254 gl_state.use_global = 0; \ |
231 gl_state.offset = 0; \ | 255 gl_state.offset = 0; \ |
232 gl_state.current_syntax_table = current_buffer->syntax_table; \ | 256 gl_state.current_syntax_table = current_buffer->syntax_table; \ |
233 if (parse_sexp_lookup_properties) \ | 257 if (parse_sexp_lookup_properties) \ |
234 update_syntax_table ((count) > 0 ? (from) : (from) - 1, (count), \ | 258 update_syntax_table ((COUNT) > 0 ? (FROM) : (FROM) - 1, (COUNT), \ |
235 1, Qnil); | 259 1, Qnil); |
236 | 260 |
237 /* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. | 261 /* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. |
238 If it is t, ignore properties altogether. | 262 If it is t, ignore properties altogether. |
239 | 263 |
240 This is meant for regex.c to use. For buffers, regex.c passes arguments | 264 This is meant for regex.c to use. For buffers, regex.c passes arguments |
241 to the UPDATE_SYNTAX_TABLE macros which are relative to BEGV. | 265 to the UPDATE_SYNTAX_TABLE macros which are relative to BEGV. |
242 So if it is a buffer, we set the offset field to BEGV. */ | 266 So if it is a buffer, we set the offset field to BEGV. */ |
243 | 267 |
244 #define SETUP_SYNTAX_TABLE_FOR_OBJECT(object, from, count) \ | 268 #define SETUP_SYNTAX_TABLE_FOR_OBJECT(OBJECT, FROM, COUNT) \ |
245 if (1) \ | 269 if (1) \ |
246 { \ | 270 { \ |
247 if (BUFFERP (object) || NILP (object)) \ | 271 gl_state.object = (OBJECT); \ |
272 if (BUFFERP (gl_state.object)) \ | |
273 { \ | |
274 struct buffer *buf = XBUFFER (gl_state.object); \ | |
275 gl_state.b_property = BUF_BEGV (buf) - 1; \ | |
276 gl_state.e_property = BUF_ZV (buf); \ | |
277 gl_state.offset = BUF_BEGV (buf) - 1; \ | |
278 } \ | |
279 else if (NILP (gl_state.object)) \ | |
248 { \ | 280 { \ |
249 gl_state.b_property = BEGV - 1; \ | 281 gl_state.b_property = BEGV - 1; \ |
250 gl_state.e_property = ZV; \ | 282 gl_state.e_property = ZV; \ |
251 gl_state.offset = BEGV - 1; \ | 283 gl_state.offset = BEGV - 1; \ |
252 } \ | 284 } \ |
253 else if (EQ (object, Qt)) \ | 285 else if (EQ (gl_state.object, Qt)) \ |
254 { \ | 286 { \ |
255 gl_state.b_property = - 1; \ | 287 gl_state.b_property = - 1; \ |
256 gl_state.e_property = 1500000000; \ | 288 gl_state.e_property = 1500000000; \ |
257 gl_state.offset = 0; \ | 289 gl_state.offset = 0; \ |
258 } \ | 290 } \ |
259 else \ | 291 else \ |
260 { \ | 292 { \ |
261 gl_state.b_property = -1; \ | 293 gl_state.b_property = -1; \ |
262 gl_state.e_property = 1 + XSTRING (object)->size; \ | 294 gl_state.e_property = 1 + XSTRING (gl_state.object)->size; \ |
263 gl_state.offset = 0; \ | 295 gl_state.offset = 0; \ |
264 } \ | 296 } \ |
265 gl_state.use_global = 0; \ | 297 gl_state.use_global = 0; \ |
266 gl_state.current_syntax_table = current_buffer->syntax_table; \ | 298 gl_state.current_syntax_table = current_buffer->syntax_table; \ |
267 if (parse_sexp_lookup_properties) \ | 299 if (parse_sexp_lookup_properties) \ |
268 update_syntax_table ((bytepos_to_charpos (from) \ | 300 update_syntax_table ((BYTE_TO_CHAR ((FROM) + gl_state.offset) \ |
269 + (count > 0 ? 0 : -1)), \ | 301 + (COUNT > 0 ? 0 : -1)), \ |
270 count, 1, object); \ | 302 COUNT, 1, gl_state.object); \ |
271 } \ | 303 } \ |
272 else | 304 else |
273 | 305 |
274 struct gl_state_s | 306 struct gl_state_s |
275 { | 307 { |
308 Lisp_Object object; /* The object we are scanning. */ | |
276 int start; /* Where to stop. */ | 309 int start; /* Where to stop. */ |
277 int stop; /* Where to stop. */ | 310 int stop; /* Where to stop. */ |
278 int use_global; /* Whether to use global_code | 311 int use_global; /* Whether to use global_code |
279 or c_s_t. */ | 312 or c_s_t. */ |
280 Lisp_Object global_code; /* Syntax code of current char. */ | 313 Lisp_Object global_code; /* Syntax code of current char. */ |