428
|
1 /* XEmacs routines to deal with syntax tables; also word and list parsing.
|
|
2 Copyright (C) 1985-1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
1296
|
4 Copyright (C) 2001, 2002, 2003 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 19.28. */
|
|
24
|
|
25 /* This file has been Mule-ized. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "syntax.h"
|
460
|
32 #include "extents.h"
|
428
|
33
|
460
|
34 #define ST_COMMENT_STYLE 0x101
|
|
35 #define ST_STRING_STYLE 0x102
|
|
36
|
|
37 Lisp_Object Qsyntax_table;
|
|
38 int lookup_syntax_properties;
|
|
39
|
428
|
40 Lisp_Object Qsyntax_table_p;
|
|
41
|
|
42 int words_include_escapes;
|
|
43
|
|
44 int parse_sexp_ignore_comments;
|
|
45
|
|
46 /* The following two variables are provided to tell additional information
|
|
47 to the regex routines. We do it this way rather than change the
|
|
48 arguments to re_search_2() in an attempt to maintain some call
|
|
49 compatibility with other versions of the regex code. */
|
|
50
|
|
51 /* Tell the regex routines not to QUIT. Normally there is a QUIT
|
|
52 each iteration in re_search_2(). */
|
|
53 int no_quit_in_re_search;
|
|
54
|
826
|
55 /* The standard syntax table is stored where it will automatically
|
|
56 be used in all new buffers. */
|
428
|
57 Lisp_Object Vstandard_syntax_table;
|
|
58
|
|
59 Lisp_Object Vsyntax_designator_chars_string;
|
|
60
|
826
|
61 Lisp_Object Vtemp_table_for_use_updating_syntax_tables;
|
|
62
|
1296
|
63 /* A value that is guaranteed not be in a syntax table. */
|
|
64 Lisp_Object Vbogus_syntax_table_value;
|
|
65
|
826
|
66 static void syntax_cache_table_was_changed (struct buffer *buf);
|
|
67
|
428
|
68 /* This is the internal form of the parse state used in parse-partial-sexp. */
|
|
69
|
|
70 struct lisp_parse_state
|
|
71 {
|
|
72 int depth; /* Depth at end of parsing */
|
867
|
73 Ichar instring; /* -1 if not within string, else desired terminator */
|
428
|
74 int incomment; /* Nonzero if within a comment at end of parsing */
|
460
|
75 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE */
|
428
|
76 int quoted; /* Nonzero if just after an escape char at end of
|
|
77 parsing */
|
665
|
78 Charbpos thislevelstart;/* Char number of most recent start-of-expression
|
428
|
79 at current level */
|
665
|
80 Charbpos prevlevelstart;/* Char number of start of containing expression */
|
|
81 Charbpos location; /* Char number at which parsing stopped */
|
428
|
82 int mindepth; /* Minimum depth seen while scanning */
|
826
|
83 Charbpos comstr_start;/* Position just after last comment/string starter */
|
|
84 Lisp_Object levelstarts;/* Char numbers of starts-of-expression
|
|
85 of levels (starting from outermost). */
|
428
|
86 };
|
|
87
|
|
88 /* These variables are a cache for finding the start of a defun.
|
|
89 find_start_pos is the place for which the defun start was found.
|
|
90 find_start_value is the defun start position found for it.
|
|
91 find_start_buffer is the buffer it was found in.
|
|
92 find_start_begv is the BEGV value when it was found.
|
|
93 find_start_modiff is the value of MODIFF when it was found. */
|
|
94
|
665
|
95 static Charbpos find_start_pos;
|
|
96 static Charbpos find_start_value;
|
428
|
97 static struct buffer *find_start_buffer;
|
665
|
98 static Charbpos find_start_begv;
|
428
|
99 static int find_start_modiff;
|
|
100
|
|
101 /* Find a defun-start that is the last one before POS (or nearly the last).
|
|
102 We record what we find, so that another call in the same area
|
|
103 can return the same value right away. */
|
|
104
|
665
|
105 static Charbpos
|
|
106 find_defun_start (struct buffer *buf, Charbpos pos)
|
428
|
107 {
|
665
|
108 Charbpos tem;
|
826
|
109 struct syntax_cache *scache;
|
|
110
|
428
|
111 /* Use previous finding, if it's valid and applies to this inquiry. */
|
|
112 if (buf == find_start_buffer
|
|
113 /* Reuse the defun-start even if POS is a little farther on.
|
|
114 POS might be in the next defun, but that's ok.
|
|
115 Our value may not be the best possible, but will still be usable. */
|
|
116 && pos <= find_start_pos + 1000
|
|
117 && pos >= find_start_value
|
|
118 && BUF_BEGV (buf) == find_start_begv
|
|
119 && BUF_MODIFF (buf) == find_start_modiff)
|
|
120 return find_start_value;
|
|
121
|
|
122 /* Back up to start of line. */
|
|
123 tem = find_next_newline (buf, pos, -1);
|
|
124
|
826
|
125 scache = setup_buffer_syntax_cache (buf, tem, 1);
|
428
|
126 while (tem > BUF_BEGV (buf))
|
|
127 {
|
826
|
128 UPDATE_SYNTAX_CACHE_BACKWARD (scache, tem);
|
460
|
129
|
428
|
130 /* Open-paren at start of line means we found our defun-start. */
|
826
|
131 if (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, tem)) == Sopen)
|
428
|
132 break;
|
|
133 /* Move to beg of previous line. */
|
|
134 tem = find_next_newline (buf, tem, -2);
|
|
135 }
|
|
136
|
|
137 /* Record what we found, for the next try. */
|
|
138 find_start_value = tem;
|
|
139 find_start_buffer = buf;
|
|
140 find_start_modiff = BUF_MODIFF (buf);
|
|
141 find_start_begv = BUF_BEGV (buf);
|
|
142 find_start_pos = pos;
|
|
143
|
|
144 return find_start_value;
|
|
145 }
|
|
146
|
|
147 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /*
|
444
|
148 Return t if OBJECT is a syntax table.
|
428
|
149 Any vector of 256 elements will do.
|
|
150 */
|
444
|
151 (object))
|
428
|
152 {
|
444
|
153 return (CHAR_TABLEP (object)
|
|
154 && XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_SYNTAX)
|
428
|
155 ? Qt : Qnil;
|
|
156 }
|
|
157
|
|
158 static Lisp_Object
|
|
159 check_syntax_table (Lisp_Object obj, Lisp_Object default_)
|
|
160 {
|
|
161 if (NILP (obj))
|
|
162 obj = default_;
|
|
163 while (NILP (Fsyntax_table_p (obj)))
|
|
164 obj = wrong_type_argument (Qsyntax_table_p, obj);
|
|
165 return obj;
|
|
166 }
|
|
167
|
|
168 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /*
|
|
169 Return the current syntax table.
|
|
170 This is the one specified by the current buffer, or by BUFFER if it
|
|
171 is non-nil.
|
|
172 */
|
|
173 (buffer))
|
|
174 {
|
|
175 return decode_buffer (buffer, 0)->syntax_table;
|
|
176 }
|
|
177
|
826
|
178 #ifdef DEBUG_XEMACS
|
|
179
|
|
180 DEFUN ("mirror-syntax-table", Fmirror_syntax_table, 0, 1, 0, /*
|
|
181 Return the current mirror syntax table, for debugging purposes.
|
|
182 This is the one specified by the current buffer, or by BUFFER if it
|
|
183 is non-nil.
|
|
184 */
|
|
185 (buffer))
|
|
186 {
|
|
187 return decode_buffer (buffer, 0)->mirror_syntax_table;
|
|
188 }
|
|
189
|
|
190 DEFUN ("syntax-cache-info", Fsyntax_cache_info, 0, 1, 0, /*
|
|
191 Return info about the syntax cache in BUFFER.
|
|
192 BUFFER defaults to the current buffer if nil.
|
|
193 */
|
|
194 (buffer))
|
|
195 {
|
|
196 struct buffer *buf = decode_buffer (buffer, 0);
|
|
197 struct syntax_cache *cache = buf->syntax_cache;
|
|
198 return list4 (cache->start, cache->end, make_int (cache->prev_change),
|
|
199 make_int (cache->next_change));
|
|
200 }
|
|
201
|
|
202 #endif /* DEBUG_XEMACS */
|
|
203
|
428
|
204 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /*
|
|
205 Return the standard syntax table.
|
|
206 This is the one used for new buffers.
|
|
207 */
|
|
208 ())
|
|
209 {
|
|
210 return Vstandard_syntax_table;
|
|
211 }
|
|
212
|
|
213 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /*
|
444
|
214 Return a new syntax table which is a copy of SYNTAX-TABLE.
|
|
215 SYNTAX-TABLE defaults to the standard syntax table.
|
428
|
216 */
|
444
|
217 (syntax_table))
|
428
|
218 {
|
|
219 if (NILP (Vstandard_syntax_table))
|
|
220 return Fmake_char_table (Qsyntax);
|
|
221
|
444
|
222 syntax_table = check_syntax_table (syntax_table, Vstandard_syntax_table);
|
|
223 return Fcopy_char_table (syntax_table);
|
428
|
224 }
|
|
225
|
|
226 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /*
|
444
|
227 Select SYNTAX-TABLE as the new syntax table for BUFFER.
|
428
|
228 BUFFER defaults to the current buffer if omitted.
|
|
229 */
|
444
|
230 (syntax_table, buffer))
|
428
|
231 {
|
|
232 struct buffer *buf = decode_buffer (buffer, 0);
|
444
|
233 syntax_table = check_syntax_table (syntax_table, Qnil);
|
|
234 buf->syntax_table = syntax_table;
|
|
235 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table;
|
826
|
236 syntax_cache_table_was_changed (buf);
|
428
|
237 /* Indicate that this buffer now has a specified syntax table. */
|
|
238 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table);
|
444
|
239 return syntax_table;
|
428
|
240 }
|
|
241
|
826
|
242
|
|
243 static void
|
|
244 init_syntax_cache (struct syntax_cache *cache, Lisp_Object object,
|
|
245 struct buffer *buffer, int infinite)
|
|
246 {
|
|
247 xzero (*cache);
|
|
248 cache->object = object;
|
|
249 cache->buffer = buffer;
|
|
250 cache->no_syntax_table_prop = 1;
|
1296
|
251 cache->syntax_table =
|
|
252 BUFFER_SYNTAX_TABLE (cache->buffer);
|
|
253 cache->mirror_table =
|
826
|
254 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
|
|
255 cache->start = Qnil;
|
|
256 cache->end = Qnil;
|
|
257 if (infinite)
|
|
258 {
|
|
259 cache->prev_change = EMACS_INT_MIN;
|
|
260 cache->next_change = EMACS_INT_MAX;
|
|
261 }
|
|
262 else
|
|
263 {
|
|
264 cache->prev_change = -1;
|
|
265 cache->next_change = -1;
|
|
266 }
|
|
267 }
|
|
268
|
|
269 struct syntax_cache *
|
|
270 setup_syntax_cache (struct syntax_cache *cache, Lisp_Object object,
|
|
271 struct buffer *buffer, Charxpos from, int count)
|
|
272 {
|
|
273 if (BUFFERP (object))
|
|
274 cache = XBUFFER (object)->syntax_cache;
|
|
275 if (!lookup_syntax_properties)
|
|
276 init_syntax_cache (cache, object, buffer, 1);
|
|
277 else if (!BUFFERP (object))
|
|
278 init_syntax_cache (cache, object, buffer, 0);
|
|
279 if (lookup_syntax_properties)
|
|
280 {
|
|
281 if (count <= 0)
|
|
282 {
|
|
283 from--;
|
2167
|
284 from = buffer_or_string_clip_to_accessible_char (cache->object,
|
826
|
285 from);
|
|
286 }
|
|
287 if (!(from >= cache->prev_change && from < cache->next_change))
|
|
288 update_syntax_cache (cache, from, count);
|
|
289 }
|
1296
|
290 #ifdef NOT_WORTH_THE_EFFORT
|
|
291 update_mirror_syntax_if_dirty (cache->mirror_table);
|
|
292 #endif /* NOT_WORTH_THE_EFFORT */
|
826
|
293 return cache;
|
|
294 }
|
|
295
|
|
296 struct syntax_cache *
|
|
297 setup_buffer_syntax_cache (struct buffer *buffer, Charxpos from, int count)
|
|
298 {
|
|
299 return setup_syntax_cache (NULL, wrap_buffer (buffer), buffer, from, count);
|
|
300 }
|
|
301
|
1296
|
302 static const struct memory_description syntax_cache_description_1 [] = {
|
|
303 { XD_LISP_OBJECT, offsetof (struct syntax_cache, object) },
|
|
304 { XD_LISP_OBJECT, offsetof (struct syntax_cache, buffer) },
|
|
305 { XD_LISP_OBJECT, offsetof (struct syntax_cache, syntax_table) },
|
|
306 { XD_LISP_OBJECT, offsetof (struct syntax_cache, mirror_table) },
|
|
307 { XD_LISP_OBJECT, offsetof (struct syntax_cache, start) },
|
|
308 { XD_LISP_OBJECT, offsetof (struct syntax_cache, end) },
|
|
309 { XD_END }
|
|
310 };
|
|
311
|
3092
|
312 #ifdef NEW_GC
|
|
313 DEFINE_LRECORD_IMPLEMENTATION ("syntax-cache", syntax_cache,
|
|
314 1, /*dumpable-flag*/
|
|
315 0, 0, 0, 0, 0,
|
|
316 syntax_cache_description_1,
|
|
317 Lisp_Syntax_Cache);
|
|
318 #else /* not NEW_GC */
|
|
319
|
1296
|
320 const struct sized_memory_description syntax_cache_description = {
|
|
321 sizeof (struct syntax_cache),
|
|
322 syntax_cache_description_1
|
|
323 };
|
3092
|
324 #endif /* not NEW_GC */
|
1296
|
325
|
826
|
326 void
|
|
327 mark_buffer_syntax_cache (struct buffer *buf)
|
|
328 {
|
|
329 struct syntax_cache *cache = buf->syntax_cache;
|
|
330 if (!cache) /* Vbuffer_defaults and such don't have caches */
|
|
331 return;
|
|
332 mark_object (cache->object);
|
|
333 if (cache->buffer)
|
|
334 mark_object (wrap_buffer (cache->buffer));
|
1296
|
335 mark_object (cache->syntax_table);
|
|
336 mark_object (cache->mirror_table);
|
826
|
337 mark_object (cache->start);
|
|
338 mark_object (cache->end);
|
|
339 }
|
460
|
340
|
826
|
341 static void
|
|
342 reset_buffer_cache_range (struct syntax_cache *cache, Lisp_Object buffer)
|
|
343 {
|
|
344 Fset_marker (cache->start, make_int (1), buffer);
|
|
345 Fset_marker (cache->end, make_int (1), buffer);
|
|
346 Fset_marker_insertion_type (cache->start, Qt);
|
|
347 Fset_marker_insertion_type (cache->end, Qnil);
|
|
348 cache->prev_change = -1;
|
|
349 cache->next_change = -1;
|
|
350 }
|
|
351
|
|
352 void
|
|
353 init_buffer_syntax_cache (struct buffer *buf)
|
|
354 {
|
|
355 struct syntax_cache *cache;
|
3092
|
356 #ifdef NEW_GC
|
|
357 buf->syntax_cache = alloc_lrecord_type (struct syntax_cache,
|
|
358 &lrecord_syntax_cache);
|
|
359 #else /* not NEW_GC */
|
826
|
360 buf->syntax_cache = xnew_and_zero (struct syntax_cache);
|
3092
|
361 #endif /* not NEW_GC */
|
826
|
362 cache = buf->syntax_cache;
|
|
363 cache->object = wrap_buffer (buf);
|
|
364 cache->buffer = buf;
|
|
365 cache->no_syntax_table_prop = 1;
|
1296
|
366 cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer);
|
|
367 cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
|
826
|
368 cache->start = Fmake_marker ();
|
|
369 cache->end = Fmake_marker ();
|
|
370 reset_buffer_cache_range (cache, cache->object);
|
|
371 }
|
|
372
|
|
373 void
|
|
374 uninit_buffer_syntax_cache (struct buffer *buf)
|
|
375 {
|
3092
|
376 #ifdef NEW_GC
|
|
377 mc_free (buf->syntax_cache);
|
|
378 #else /* not NEW_GC */
|
1726
|
379 xfree (buf->syntax_cache, struct syntax_cache *);
|
3092
|
380 #endif /* not NEW_GC */
|
826
|
381 buf->syntax_cache = 0;
|
|
382 }
|
|
383
|
|
384
|
|
385 static void
|
|
386 syntax_cache_table_was_changed (struct buffer *buf)
|
|
387 {
|
|
388 struct syntax_cache *cache = buf->syntax_cache;
|
|
389 if (cache->no_syntax_table_prop)
|
1296
|
390 {
|
|
391 cache->syntax_table =
|
|
392 BUFFER_SYNTAX_TABLE (buf);
|
|
393 cache->mirror_table =
|
|
394 BUFFER_MIRROR_SYNTAX_TABLE (buf);
|
|
395 }
|
826
|
396 }
|
|
397
|
|
398 /* The syntax-table property on the range covered by EXTENT may be changing,
|
|
399 either because EXTENT has a syntax-table property and is being attached
|
|
400 or detached (this includes having its endpoints changed), or because
|
|
401 the value of EXTENT's syntax-table property is changing. */
|
|
402
|
|
403 void
|
|
404 signal_syntax_table_extent_changed (EXTENT extent)
|
|
405 {
|
872
|
406 Lisp_Object buffer = Fextent_object (wrap_extent (extent));
|
826
|
407 if (BUFFERP (buffer))
|
|
408 {
|
|
409 struct syntax_cache *cache = XBUFFER (buffer)->syntax_cache;
|
|
410 Bytexpos start = extent_endpoint_byte (extent, 0);
|
|
411 Bytexpos end = extent_endpoint_byte (extent, 1);
|
|
412 Bytexpos start2 = byte_marker_position (cache->start);
|
|
413 Bytexpos end2 = byte_marker_position (cache->end);
|
|
414 /* If the extent is entirely before or entirely after the cache range,
|
|
415 it doesn't overlap. Otherwise, invalidate the range. */
|
|
416 if (!(end < start2 || start > end2))
|
|
417 reset_buffer_cache_range (cache, buffer);
|
|
418 }
|
|
419 }
|
|
420
|
|
421 /* Extents have been adjusted for insertion or deletion, so we need to
|
|
422 refetch the start and end position of the extent */
|
|
423 void
|
|
424 signal_syntax_table_extent_adjust (struct buffer *buf)
|
|
425 {
|
|
426 struct syntax_cache *cache = buf->syntax_cache;
|
|
427 /* If the cache was invalid before, leave it that way. We only want
|
|
428 to update the limits of validity when they were actually valid. */
|
|
429 if (cache->prev_change < 0)
|
|
430 return;
|
|
431 cache->prev_change = marker_position (cache->start);
|
|
432 cache->next_change = marker_position (cache->end);
|
|
433 }
|
460
|
434
|
|
435 /*
|
|
436 Update syntax_cache to an appropriate setting for position POS
|
|
437
|
|
438 The sign of COUNT gives the relative position of POS wrt the
|
|
439 previously valid interval. (not currently used)
|
|
440
|
|
441 `syntax_cache.*_change' are the next and previous positions at
|
|
442 which syntax_code and c_s_t will need to be recalculated.
|
|
443
|
3025
|
444 #### Currently this code uses `get-char-property', which will
|
460
|
445 return the "last smallest" extent at a given position. In cases
|
|
446 where overlapping extents are defined, this code will simply use
|
|
447 whatever is returned by get-char-property.
|
|
448
|
|
449 It might be worth it at some point to merge provided syntax tables
|
826
|
450 outward to the current buffer (#### rewrite in English please?!). */
|
460
|
451
|
|
452 void
|
2286
|
453 update_syntax_cache (struct syntax_cache *cache, Charxpos cpos,
|
|
454 int UNUSED (count))
|
460
|
455 {
|
|
456 Lisp_Object tmp_table;
|
826
|
457 Bytexpos pos;
|
|
458 Bytexpos lim;
|
|
459 Bytexpos next, prev;
|
|
460 int at_begin = 0, at_end = 0;
|
460
|
461
|
826
|
462 if (NILP (cache->object))
|
|
463 return;
|
|
464
|
|
465 pos = buffer_or_string_charxpos_to_bytexpos (cache->object, cpos);
|
|
466
|
|
467 tmp_table = get_char_property (pos, Qsyntax_table, cache->object,
|
|
468 EXTENT_AT_AFTER, 0);
|
2506
|
469 lim = next_previous_single_property_change (pos, Qsyntax_table,
|
|
470 cache->object, -1, 1, 0);
|
826
|
471 if (lim < 0)
|
460
|
472 {
|
826
|
473 next = buffer_or_string_absolute_end_byte (cache->object);
|
|
474 at_begin = 1;
|
460
|
475 }
|
826
|
476 else
|
|
477 next = lim;
|
460
|
478
|
826
|
479 if (pos < buffer_or_string_absolute_end_byte (cache->object))
|
|
480 pos = next_bytexpos (cache->object, pos);
|
2506
|
481 lim = next_previous_single_property_change (pos, Qsyntax_table,
|
|
482 cache->object, -1, 0, 0);
|
826
|
483 if (lim < 0)
|
460
|
484 {
|
826
|
485 prev = buffer_or_string_absolute_begin_byte (cache->object);
|
|
486 at_end = 1;
|
460
|
487 }
|
|
488 else
|
826
|
489 prev = lim;
|
460
|
490
|
826
|
491 cache->prev_change =
|
|
492 buffer_or_string_bytexpos_to_charxpos (cache->object, prev);
|
|
493 cache->next_change =
|
|
494 buffer_or_string_bytexpos_to_charxpos (cache->object, next);
|
460
|
495
|
826
|
496 if (BUFFERP (cache->object))
|
|
497 {
|
|
498 /* If we are at the beginning or end of buffer, check to see if there's
|
|
499 a zero-length `syntax-table' extent there (highly unlikely); if not,
|
|
500 then we can safely make the end closed, so it will take in newly
|
|
501 inserted text. (If such an extent is inserted, we will be informed
|
|
502 through signal_syntax_table_extent_changed().) */
|
|
503 Fset_marker (cache->start, make_int (cache->prev_change), cache->object);
|
|
504 Fset_marker_insertion_type
|
|
505 (cache->start,
|
|
506 at_begin && NILP (extent_at (prev, cache->object, Qsyntax_table,
|
|
507 NULL, EXTENT_AT_AT, 0))
|
|
508 ? Qnil : Qt);
|
|
509 Fset_marker (cache->end, make_int (cache->next_change), cache->object);
|
|
510 Fset_marker_insertion_type
|
|
511 (cache->end,
|
|
512 at_end && NILP (extent_at (next, cache->object, Qsyntax_table,
|
|
513 NULL, EXTENT_AT_AT, 0))
|
|
514 ? Qt : Qnil);
|
|
515 }
|
|
516
|
|
517 if (!NILP (Fsyntax_table_p (tmp_table)))
|
|
518 {
|
|
519 cache->use_code = 0;
|
1296
|
520 cache->syntax_table = tmp_table;
|
|
521 cache->mirror_table = XCHAR_TABLE (tmp_table)->mirror_table;
|
826
|
522 cache->no_syntax_table_prop = 0;
|
1296
|
523 #ifdef NOT_WORTH_THE_EFFORT
|
|
524 update_mirror_syntax_if_dirty (cache->mirror_table);
|
|
525 #endif /* NOT_WORTH_THE_EFFORT */
|
826
|
526 }
|
|
527 else if (CONSP (tmp_table) && INTP (XCAR (tmp_table)))
|
|
528 {
|
|
529 cache->use_code = 1;
|
|
530 cache->syntax_code = XINT (XCAR (tmp_table));
|
|
531 cache->no_syntax_table_prop = 0;
|
|
532 }
|
|
533 else
|
|
534 {
|
|
535 cache->use_code = 0;
|
|
536 cache->no_syntax_table_prop = 1;
|
1296
|
537 cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer);
|
|
538 cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer);
|
|
539 #ifdef NOT_WORTH_THE_EFFORT
|
|
540 update_mirror_syntax_if_dirty (cache->mirror_table);
|
|
541 #endif /* NOT_WORTH_THE_EFFORT */
|
460
|
542 }
|
|
543 }
|
|
544
|
428
|
545 /* Convert a letter which signifies a syntax code
|
|
546 into the code it signifies.
|
|
547 This is used by modify-syntax-entry, and other things. */
|
|
548
|
442
|
549 const unsigned char syntax_spec_code[0400] =
|
428
|
550 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
551 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
552 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
553 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
554 (char) Swhitespace, 0377, (char) Sstring, 0377,
|
|
555 (char) Smath, 0377, 0377, (char) Squote,
|
|
556 (char) Sopen, (char) Sclose, 0377, 0377,
|
|
557 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote,
|
|
558 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
559 0377, 0377, 0377, 0377,
|
|
560 (char) Scomment, 0377, (char) Sendcomment, 0377,
|
|
561 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
|
|
562 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
563 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
|
|
564 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol,
|
|
565 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
|
|
566 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
567 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
|
460
|
568 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377
|
428
|
569 };
|
|
570
|
460
|
571 const unsigned char syntax_code_spec[] = " .w_()'\"$\\/<>@!|";
|
428
|
572
|
|
573 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /*
|
|
574 Return a string of the recognized syntax designator chars.
|
|
575 The chars are ordered by their internal syntax codes, which are
|
|
576 numbered starting at 0.
|
|
577 */
|
|
578 ())
|
|
579 {
|
|
580 return Vsyntax_designator_chars_string;
|
|
581 }
|
|
582
|
|
583 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /*
|
444
|
584 Return the syntax code of CHARACTER, described by a character.
|
|
585 For example, if CHARACTER is a word constituent,
|
|
586 the character `?w' is returned.
|
428
|
587 The characters that correspond to various syntax codes
|
|
588 are listed in the documentation of `modify-syntax-entry'.
|
444
|
589 Optional second argument SYNTAX-TABLE defaults to the current buffer's
|
428
|
590 syntax table.
|
|
591 */
|
444
|
592 (character, syntax_table))
|
428
|
593 {
|
826
|
594 Lisp_Object mirrortab;
|
428
|
595
|
444
|
596 if (NILP (character))
|
428
|
597 {
|
444
|
598 character = make_char ('\000');
|
428
|
599 }
|
444
|
600 CHECK_CHAR_COERCE_INT (character);
|
826
|
601 syntax_table = check_syntax_table (syntax_table,
|
|
602 current_buffer->syntax_table);
|
|
603 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table;
|
|
604 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab,
|
|
605 XCHAR (character))]);
|
428
|
606 }
|
|
607
|
|
608 #ifdef MULE
|
|
609
|
|
610 enum syntaxcode
|
2286
|
611 charset_syntax (struct buffer *UNUSED (buf), Lisp_Object UNUSED (charset),
|
|
612 int *multi_p_out)
|
428
|
613 {
|
|
614 *multi_p_out = 1;
|
826
|
615 /* !!#### get this right */
|
3152
|
616 return Sword;
|
428
|
617 }
|
|
618
|
|
619 #endif
|
|
620
|
|
621 Lisp_Object
|
867
|
622 syntax_match (Lisp_Object syntax_table, Ichar ch)
|
428
|
623 {
|
826
|
624 Lisp_Object code = get_char_table (ch, syntax_table);
|
428
|
625 Lisp_Object code2 = code;
|
|
626
|
|
627 if (CONSP (code))
|
|
628 code2 = XCAR (code);
|
|
629 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit)
|
826
|
630 code = get_char_table (ch, Vstandard_syntax_table);
|
428
|
631
|
|
632 return CONSP (code) ? XCDR (code) : Qnil;
|
|
633 }
|
|
634
|
|
635 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /*
|
444
|
636 Return the matching parenthesis of CHARACTER, or nil if none.
|
|
637 Optional second argument SYNTAX-TABLE defaults to the current buffer's
|
428
|
638 syntax table.
|
|
639 */
|
444
|
640 (character, syntax_table))
|
428
|
641 {
|
826
|
642 Lisp_Object mirrortab;
|
1315
|
643 enum syntaxcode code;
|
428
|
644
|
444
|
645 CHECK_CHAR_COERCE_INT (character);
|
826
|
646 syntax_table = check_syntax_table (syntax_table,
|
|
647 current_buffer->syntax_table);
|
|
648 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table;
|
444
|
649 code = SYNTAX (mirrortab, XCHAR (character));
|
428
|
650 if (code == Sopen || code == Sclose || code == Sstring)
|
444
|
651 return syntax_match (syntax_table, XCHAR (character));
|
428
|
652 return Qnil;
|
|
653 }
|
|
654
|
|
655
|
|
656
|
|
657 #ifdef MULE
|
|
658 /* Return 1 if there is a word boundary between two word-constituent
|
|
659 characters C1 and C2 if they appear in this order, else return 0.
|
|
660 There is no word boundary between two word-constituent ASCII
|
|
661 characters. */
|
|
662 #define WORD_BOUNDARY_P(c1, c2) \
|
867
|
663 (!(ichar_ascii_p (c1) && ichar_ascii_p (c2)) \
|
428
|
664 && word_boundary_p (c1, c2))
|
|
665 #endif
|
|
666
|
|
667 /* Return the position across COUNT words from FROM.
|
|
668 If that many words cannot be found before the end of the buffer, return 0.
|
|
669 COUNT negative means scan backward and stop at word beginning. */
|
|
670
|
665
|
671 Charbpos
|
|
672 scan_words (struct buffer *buf, Charbpos from, int count)
|
428
|
673 {
|
665
|
674 Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
|
867
|
675 Ichar ch0, ch1;
|
428
|
676 enum syntaxcode code;
|
826
|
677 struct syntax_cache *scache = setup_buffer_syntax_cache (buf, from, count);
|
460
|
678
|
428
|
679 /* #### is it really worth it to hand expand both cases? JV */
|
|
680 while (count > 0)
|
|
681 {
|
|
682 QUIT;
|
|
683
|
|
684 while (1)
|
|
685 {
|
|
686 if (from == limit)
|
|
687 return 0;
|
|
688
|
826
|
689 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
690 ch0 = BUF_FETCH_CHAR (buf, from);
|
826
|
691 code = SYNTAX_FROM_CACHE (scache, ch0);
|
428
|
692
|
442
|
693 from++;
|
428
|
694 if (words_include_escapes
|
|
695 && (code == Sescape || code == Scharquote))
|
|
696 break;
|
|
697 if (code == Sword)
|
|
698 break;
|
|
699 }
|
|
700
|
|
701 QUIT;
|
|
702
|
|
703 while (from != limit)
|
|
704 {
|
826
|
705 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
706 ch1 = BUF_FETCH_CHAR (buf, from);
|
826
|
707 code = SYNTAX_FROM_CACHE (scache, ch1);
|
428
|
708 if (!(words_include_escapes
|
|
709 && (code == Sescape || code == Scharquote)))
|
|
710 if (code != Sword
|
|
711 #ifdef MULE
|
|
712 || WORD_BOUNDARY_P (ch0, ch1)
|
434
|
713 #endif
|
428
|
714 )
|
|
715 break;
|
|
716 #ifdef MULE
|
|
717 ch0 = ch1;
|
434
|
718 #endif
|
428
|
719 from++;
|
|
720 }
|
|
721 count--;
|
|
722 }
|
|
723
|
|
724 while (count < 0)
|
|
725 {
|
|
726 QUIT;
|
|
727
|
|
728 while (1)
|
|
729 {
|
|
730 if (from == limit)
|
|
731 return 0;
|
|
732
|
826
|
733 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
428
|
734 ch1 = BUF_FETCH_CHAR (buf, from - 1);
|
826
|
735 code = SYNTAX_FROM_CACHE (scache, ch1);
|
460
|
736 from--;
|
442
|
737
|
428
|
738 if (words_include_escapes
|
|
739 && (code == Sescape || code == Scharquote))
|
|
740 break;
|
|
741 if (code == Sword)
|
|
742 break;
|
|
743 }
|
|
744
|
|
745 QUIT;
|
|
746
|
|
747 while (from != limit)
|
|
748 {
|
826
|
749 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
428
|
750 ch0 = BUF_FETCH_CHAR (buf, from - 1);
|
826
|
751 code = SYNTAX_FROM_CACHE (scache, ch0);
|
460
|
752
|
428
|
753 if (!(words_include_escapes
|
|
754 && (code == Sescape || code == Scharquote)))
|
|
755 if (code != Sword
|
|
756 #ifdef MULE
|
|
757 || WORD_BOUNDARY_P (ch0, ch1)
|
|
758 #endif
|
|
759 )
|
|
760 break;
|
|
761 #ifdef MULE
|
|
762 ch1 = ch0;
|
|
763 #endif
|
|
764 from--;
|
|
765 }
|
|
766 count++;
|
|
767 }
|
|
768
|
|
769 return from;
|
|
770 }
|
|
771
|
446
|
772 DEFUN ("forward-word", Fforward_word, 0, 2, "_p", /*
|
428
|
773 Move point forward COUNT words (backward if COUNT is negative).
|
446
|
774 Normally t is returned, but if an edge of the buffer is reached,
|
|
775 point is left there and nil is returned.
|
428
|
776
|
462
|
777 The characters that are moved over may be added to the current selection
|
|
778 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
779 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
780 the documentation for this variable for more details.
|
|
781
|
446
|
782 COUNT defaults to 1, and BUFFER defaults to the current buffer.
|
428
|
783 */
|
|
784 (count, buffer))
|
|
785 {
|
665
|
786 Charbpos val;
|
428
|
787 struct buffer *buf = decode_buffer (buffer, 0);
|
446
|
788 EMACS_INT n;
|
|
789
|
|
790 if (NILP (count))
|
|
791 n = 1;
|
|
792 else
|
|
793 {
|
|
794 CHECK_INT (count);
|
|
795 n = XINT (count);
|
|
796 }
|
428
|
797
|
446
|
798 val = scan_words (buf, BUF_PT (buf), n);
|
|
799 if (val)
|
428
|
800 {
|
446
|
801 BUF_SET_PT (buf, val);
|
|
802 return Qt;
|
|
803 }
|
|
804 else
|
|
805 {
|
|
806 BUF_SET_PT (buf, n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf));
|
428
|
807 return Qnil;
|
|
808 }
|
|
809 }
|
|
810
|
|
811 static void scan_sexps_forward (struct buffer *buf,
|
|
812 struct lisp_parse_state *,
|
665
|
813 Charbpos from, Charbpos end,
|
428
|
814 int targetdepth, int stopbefore,
|
|
815 Lisp_Object oldstate,
|
|
816 int commentstop);
|
|
817
|
|
818 static int
|
665
|
819 find_start_of_comment (struct buffer *buf, Charbpos from, Charbpos stop,
|
460
|
820 int comstyle)
|
428
|
821 {
|
867
|
822 Ichar c;
|
428
|
823 enum syntaxcode code;
|
|
824
|
|
825 /* Look back, counting the parity of string-quotes,
|
|
826 and recording the comment-starters seen.
|
|
827 When we reach a safe place, assume that's not in a string;
|
|
828 then step the main scan to the earliest comment-starter seen
|
|
829 an even number of string quotes away from the safe place.
|
|
830
|
|
831 OFROM[I] is position of the earliest comment-starter seen
|
|
832 which is I+2X quotes from the comment-end.
|
|
833 PARITY is current parity of quotes from the comment end. */
|
|
834 int parity = 0;
|
867
|
835 Ichar my_stringend = 0;
|
428
|
836 int string_lossage = 0;
|
665
|
837 Charbpos comment_end = from;
|
|
838 Charbpos comstart_pos = 0;
|
428
|
839 int comstart_parity = 0;
|
|
840 int styles_match_p = 0;
|
460
|
841 /* mask to match comment styles against; for ST_COMMENT_STYLE, this
|
|
842 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */
|
|
843 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
|
826
|
844 struct syntax_cache *scache = buf->syntax_cache;
|
428
|
845
|
|
846 /* At beginning of range to scan, we're outside of strings;
|
|
847 that determines quote parity to the comment-end. */
|
|
848 while (from != stop)
|
|
849 {
|
460
|
850 int syncode;
|
|
851
|
428
|
852 /* Move back and examine a character. */
|
|
853 from--;
|
826
|
854 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
|
428
|
855
|
|
856 c = BUF_FETCH_CHAR (buf, from);
|
826
|
857 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
|
|
858 code = SYNTAX_FROM_CODE (syncode);
|
428
|
859
|
|
860 /* is this a 1-char comment end sequence? if so, try
|
|
861 to see if style matches previously extracted mask */
|
|
862 if (code == Sendcomment)
|
|
863 {
|
|
864 styles_match_p =
|
460
|
865 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
|
428
|
866 }
|
|
867
|
|
868 /* or are we looking at a 1-char comment start sequence
|
|
869 of the style matching mask? */
|
460
|
870 else if (code == Scomment)
|
428
|
871 {
|
460
|
872 styles_match_p =
|
|
873 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
|
428
|
874 }
|
|
875
|
460
|
876 /* otherwise, is this a 2-char comment end or start sequence? */
|
|
877 else if (from > stop)
|
|
878 do
|
|
879 {
|
|
880 /* 2-char comment end sequence? */
|
|
881 if (SYNTAX_CODE_END_SECOND_P (syncode))
|
|
882 {
|
|
883 int prev_syncode;
|
826
|
884 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
460
|
885 prev_syncode =
|
1315
|
886 SYNTAX_CODE_FROM_CACHE (scache,
|
|
887 BUF_FETCH_CHAR (buf, from - 1));
|
460
|
888
|
|
889 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
|
|
890 {
|
|
891 code = Sendcomment;
|
|
892 styles_match_p =
|
826
|
893 SYNTAX_CODES_COMMENT_MASK_END (prev_syncode,
|
|
894 syncode) & mask;
|
460
|
895 from--;
|
826
|
896 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
|
460
|
897 c = BUF_FETCH_CHAR (buf, from);
|
|
898
|
|
899 /* Found a comment-end sequence, so skip past the
|
|
900 check for a comment-start */
|
|
901 break;
|
|
902 }
|
|
903 }
|
|
904
|
|
905 /* 2-char comment start sequence? */
|
|
906 if (SYNTAX_CODE_START_SECOND_P (syncode))
|
|
907 {
|
|
908 int prev_syncode;
|
826
|
909 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
460
|
910 prev_syncode =
|
1315
|
911 SYNTAX_CODE_FROM_CACHE (scache,
|
|
912 BUF_FETCH_CHAR (buf, from - 1));
|
460
|
913
|
|
914 if (SYNTAX_CODES_START_P (prev_syncode, syncode))
|
|
915 {
|
|
916 code = Scomment;
|
|
917 styles_match_p =
|
826
|
918 SYNTAX_CODES_COMMENT_MASK_START (prev_syncode,
|
|
919 syncode) & mask;
|
460
|
920 from--;
|
826
|
921 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
|
460
|
922 c = BUF_FETCH_CHAR (buf, from);
|
|
923 }
|
|
924 }
|
|
925 } while (0);
|
428
|
926
|
|
927 /* Ignore escaped characters. */
|
|
928 if (char_quoted (buf, from))
|
|
929 continue;
|
|
930
|
|
931 /* Track parity of quotes. */
|
|
932 if (code == Sstring)
|
|
933 {
|
|
934 parity ^= 1;
|
|
935 if (my_stringend == 0)
|
|
936 my_stringend = c;
|
|
937 /* If we have two kinds of string delimiters.
|
|
938 There's no way to grok this scanning backwards. */
|
|
939 else if (my_stringend != c)
|
|
940 string_lossage = 1;
|
|
941 }
|
|
942
|
460
|
943 if (code == Sstring_fence || code == Scomment_fence)
|
|
944 {
|
|
945 parity ^= 1;
|
|
946 if (my_stringend == 0)
|
|
947 my_stringend =
|
|
948 code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE;
|
|
949 /* If we have two kinds of string delimiters.
|
|
950 There's no way to grok this scanning backwards. */
|
|
951 else if (my_stringend != (code == Sstring_fence
|
|
952 ? ST_STRING_STYLE : ST_COMMENT_STYLE))
|
|
953 string_lossage = 1;
|
|
954 }
|
|
955
|
428
|
956 /* Record comment-starters according to that
|
|
957 quote-parity to the comment-end. */
|
|
958 if (code == Scomment && styles_match_p)
|
|
959 {
|
|
960 comstart_parity = parity;
|
|
961 comstart_pos = from;
|
|
962 }
|
|
963
|
|
964 /* If we find another earlier comment-ender,
|
|
965 any comment-starts earlier than that don't count
|
|
966 (because they go with the earlier comment-ender). */
|
|
967 if (code == Sendcomment && styles_match_p)
|
|
968 break;
|
|
969
|
|
970 /* Assume a defun-start point is outside of strings. */
|
|
971 if (code == Sopen
|
|
972 && (from == stop || BUF_FETCH_CHAR (buf, from - 1) == '\n'))
|
|
973 break;
|
|
974 }
|
|
975
|
|
976 if (comstart_pos == 0)
|
|
977 from = comment_end;
|
|
978 /* If the earliest comment starter
|
|
979 is followed by uniform paired string quotes or none,
|
|
980 we know it can't be inside a string
|
|
981 since if it were then the comment ender would be inside one.
|
|
982 So it does start a comment. Skip back to it. */
|
|
983 else if (comstart_parity == 0 && !string_lossage)
|
|
984 from = comstart_pos;
|
|
985 else
|
|
986 {
|
|
987 /* We had two kinds of string delimiters mixed up
|
|
988 together. Decode this going forwards.
|
|
989 Scan fwd from the previous comment ender
|
|
990 to the one in question; this records where we
|
|
991 last passed a comment starter. */
|
|
992
|
|
993 struct lisp_parse_state state;
|
|
994 scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end),
|
|
995 comment_end - 1, -10000, 0, Qnil, 0);
|
|
996 if (state.incomment)
|
460
|
997 from = state.comstr_start;
|
428
|
998 else
|
|
999 /* We can't grok this as a comment; scan it normally. */
|
|
1000 from = comment_end;
|
826
|
1001 UPDATE_SYNTAX_CACHE_FORWARD (scache, from - 1);
|
428
|
1002 }
|
|
1003 return from;
|
|
1004 }
|
|
1005
|
665
|
1006 static Charbpos
|
826
|
1007 find_end_of_comment (struct buffer *buf, Charbpos from, Charbpos stop,
|
|
1008 int comstyle)
|
428
|
1009 {
|
|
1010 int c;
|
460
|
1011 int prev_code;
|
|
1012 /* mask to match comment styles against; for ST_COMMENT_STYLE, this
|
|
1013 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */
|
|
1014 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
|
826
|
1015 struct syntax_cache *scache = buf->syntax_cache;
|
428
|
1016
|
460
|
1017 /* This is only called by functions which have already set up the
|
|
1018 syntax_cache and are keeping it up-to-date */
|
428
|
1019 while (1)
|
|
1020 {
|
|
1021 if (from == stop)
|
|
1022 {
|
|
1023 return -1;
|
|
1024 }
|
460
|
1025
|
826
|
1026 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1027 c = BUF_FETCH_CHAR (buf, from);
|
460
|
1028
|
|
1029 /* Test for generic comments */
|
|
1030 if (comstyle == ST_COMMENT_STYLE)
|
|
1031 {
|
826
|
1032 if (SYNTAX_FROM_CACHE (scache, c) == Scomment_fence)
|
460
|
1033 {
|
|
1034 from++;
|
826
|
1035 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1036 break;
|
|
1037 }
|
|
1038 from++;
|
|
1039 continue; /* No need to test other comment styles in a
|
|
1040 generic comment */
|
|
1041 }
|
|
1042 else
|
|
1043
|
826
|
1044 if (SYNTAX_FROM_CACHE (scache, c) == Sendcomment
|
460
|
1045 && SYNTAX_CODE_MATCHES_1CHAR_P
|
826
|
1046 (SYNTAX_CODE_FROM_CACHE (scache, c), mask))
|
428
|
1047 /* we have encountered a comment end of the same style
|
|
1048 as the comment sequence which began this comment
|
|
1049 section */
|
460
|
1050 {
|
|
1051 from++;
|
826
|
1052 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1053 break;
|
|
1054 }
|
428
|
1055
|
826
|
1056 prev_code = SYNTAX_CODE_FROM_CACHE (scache, c);
|
428
|
1057 from++;
|
826
|
1058 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1059 if (from < stop
|
460
|
1060 && SYNTAX_CODES_MATCH_END_P
|
|
1061 (prev_code,
|
826
|
1062 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)),
|
460
|
1063 mask)
|
|
1064
|
|
1065 )
|
428
|
1066 /* we have encountered a comment end of the same style
|
|
1067 as the comment sequence which began this comment
|
|
1068 section */
|
460
|
1069 {
|
|
1070 from++;
|
826
|
1071 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1072 break;
|
|
1073 }
|
428
|
1074 }
|
|
1075 return from;
|
|
1076 }
|
|
1077
|
|
1078
|
|
1079 /* #### between FSF 19.23 and 19.28 there are some changes to the logic
|
|
1080 in this function (and minor changes to find_start_of_comment(),
|
|
1081 above, which is part of Fforward_comment() in FSF). Attempts to port
|
|
1082 that logic made this function break, so I'm leaving it out. If anyone
|
|
1083 ever complains about this function not working properly, take a look
|
|
1084 at those changes. --ben */
|
|
1085
|
446
|
1086 DEFUN ("forward-comment", Fforward_comment, 0, 2, 0, /*
|
444
|
1087 Move forward across up to COUNT comments, or backwards if COUNT is negative.
|
428
|
1088 Stop scanning if we find something other than a comment or whitespace.
|
|
1089 Set point to where scanning stops.
|
444
|
1090 If COUNT comments are found as expected, with nothing except whitespace
|
428
|
1091 between them, return t; otherwise return nil.
|
|
1092 Point is set in either case.
|
446
|
1093 COUNT defaults to 1, and BUFFER defaults to the current buffer.
|
428
|
1094 */
|
444
|
1095 (count, buffer))
|
428
|
1096 {
|
665
|
1097 Charbpos from;
|
|
1098 Charbpos stop;
|
867
|
1099 Ichar c;
|
428
|
1100 enum syntaxcode code;
|
460
|
1101 int syncode;
|
444
|
1102 EMACS_INT n;
|
428
|
1103 struct buffer *buf = decode_buffer (buffer, 0);
|
826
|
1104 struct syntax_cache *scache;
|
|
1105
|
446
|
1106 if (NILP (count))
|
|
1107 n = 1;
|
|
1108 else
|
|
1109 {
|
|
1110 CHECK_INT (count);
|
|
1111 n = XINT (count);
|
|
1112 }
|
428
|
1113
|
|
1114 from = BUF_PT (buf);
|
|
1115
|
826
|
1116 scache = setup_buffer_syntax_cache (buf, from, n);
|
444
|
1117 while (n > 0)
|
428
|
1118 {
|
|
1119 QUIT;
|
|
1120
|
|
1121 stop = BUF_ZV (buf);
|
|
1122 while (from < stop)
|
|
1123 {
|
460
|
1124 int comstyle = 0; /* mask for finding matching comment style */
|
428
|
1125
|
|
1126 if (char_quoted (buf, from))
|
|
1127 {
|
|
1128 from++;
|
|
1129 continue;
|
|
1130 }
|
|
1131
|
826
|
1132 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1133 c = BUF_FETCH_CHAR (buf, from);
|
826
|
1134 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
|
|
1135 code = SYNTAX_FROM_CODE (syncode);
|
428
|
1136
|
|
1137 if (code == Scomment)
|
|
1138 {
|
|
1139 /* we have encountered a single character comment start
|
|
1140 sequence, and we are ignoring all text inside comments.
|
|
1141 we must record the comment style this character begins
|
|
1142 so that later, only a comment end of the same style actually
|
|
1143 ends the comment section */
|
460
|
1144 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
|
|
1145 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
428
|
1146 }
|
|
1147
|
460
|
1148 else if (code == Scomment_fence)
|
|
1149 {
|
|
1150 from++;
|
|
1151 code = Scomment;
|
|
1152 comstyle = ST_COMMENT_STYLE;
|
|
1153 }
|
|
1154
|
428
|
1155 else if (from < stop
|
460
|
1156 && SYNTAX_CODE_START_FIRST_P (syncode))
|
428
|
1157 {
|
460
|
1158 int next_syncode;
|
826
|
1159 UPDATE_SYNTAX_CACHE_FORWARD (scache, from + 1);
|
460
|
1160 next_syncode =
|
826
|
1161 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from + 1));
|
460
|
1162
|
|
1163 if (SYNTAX_CODES_START_P (syncode, next_syncode))
|
|
1164 {
|
|
1165 /* we have encountered a 2char comment start sequence and we
|
|
1166 are ignoring all text inside comments. we must record
|
|
1167 the comment style this sequence begins so that later,
|
|
1168 only a comment end of the same style actually ends
|
|
1169 the comment section */
|
|
1170 code = Scomment;
|
|
1171 comstyle =
|
|
1172 SYNTAX_CODES_COMMENT_MASK_START (syncode, next_syncode)
|
|
1173 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
|
1174 from++;
|
|
1175 }
|
428
|
1176 }
|
|
1177
|
|
1178 if (code == Scomment)
|
|
1179 {
|
826
|
1180 Charbpos newfrom = find_end_of_comment (buf, from, stop,
|
|
1181 comstyle);
|
428
|
1182 if (newfrom < 0)
|
|
1183 {
|
|
1184 /* we stopped because from==stop */
|
|
1185 BUF_SET_PT (buf, stop);
|
|
1186 return Qnil;
|
|
1187 }
|
|
1188 from = newfrom;
|
|
1189
|
|
1190 /* We have skipped one comment. */
|
|
1191 break;
|
|
1192 }
|
|
1193 else if (code != Swhitespace
|
|
1194 && code != Sendcomment
|
|
1195 && code != Scomment )
|
|
1196 {
|
|
1197 BUF_SET_PT (buf, from);
|
|
1198 return Qnil;
|
|
1199 }
|
|
1200 from++;
|
|
1201 }
|
|
1202
|
|
1203 /* End of comment reached */
|
444
|
1204 n--;
|
428
|
1205 }
|
|
1206
|
444
|
1207 while (n < 0)
|
428
|
1208 {
|
|
1209 QUIT;
|
|
1210
|
|
1211 stop = BUF_BEGV (buf);
|
|
1212 while (from > stop)
|
|
1213 {
|
460
|
1214 int comstyle = 0; /* mask for finding matching comment style */
|
428
|
1215
|
|
1216 from--;
|
|
1217 if (char_quoted (buf, from))
|
|
1218 {
|
|
1219 from--;
|
|
1220 continue;
|
|
1221 }
|
|
1222
|
|
1223 c = BUF_FETCH_CHAR (buf, from);
|
826
|
1224 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
|
|
1225 code = SYNTAX_FROM_CODE (syncode);
|
428
|
1226
|
|
1227 if (code == Sendcomment)
|
|
1228 {
|
|
1229 /* we have found a single char end comment. we must record
|
|
1230 the comment style encountered so that later, we can match
|
|
1231 only the proper comment begin sequence of the same style */
|
460
|
1232 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
|
|
1233 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
|
1234 }
|
|
1235
|
|
1236 else if (code == Scomment_fence)
|
|
1237 {
|
|
1238 code = Sendcomment;
|
|
1239 comstyle = ST_COMMENT_STYLE;
|
428
|
1240 }
|
|
1241
|
|
1242 else if (from > stop
|
460
|
1243 && SYNTAX_CODE_END_SECOND_P (syncode))
|
428
|
1244 {
|
460
|
1245 int prev_syncode;
|
826
|
1246 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
460
|
1247 prev_syncode =
|
826
|
1248 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1));
|
460
|
1249 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
|
|
1250 {
|
|
1251 /* We must record the comment style encountered so that
|
|
1252 later, we can match only the proper comment begin
|
|
1253 sequence of the same style. */
|
|
1254 code = Sendcomment;
|
|
1255 comstyle = SYNTAX_CODES_COMMENT_MASK_END
|
|
1256 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
|
1257 from--;
|
|
1258 }
|
428
|
1259 }
|
|
1260
|
|
1261 if (code == Sendcomment)
|
|
1262 {
|
460
|
1263 from = find_start_of_comment (buf, from, stop, comstyle);
|
428
|
1264 break;
|
|
1265 }
|
|
1266
|
|
1267 else if (code != Swhitespace
|
460
|
1268 && code != Scomment
|
|
1269 && code != Sendcomment)
|
428
|
1270 {
|
|
1271 BUF_SET_PT (buf, from + 1);
|
|
1272 return Qnil;
|
|
1273 }
|
|
1274 }
|
|
1275
|
444
|
1276 n++;
|
428
|
1277 }
|
|
1278
|
|
1279 BUF_SET_PT (buf, from);
|
|
1280 return Qt;
|
|
1281 }
|
|
1282
|
|
1283
|
|
1284 Lisp_Object
|
665
|
1285 scan_lists (struct buffer *buf, Charbpos from, int count, int depth,
|
444
|
1286 int sexpflag, int noerror)
|
428
|
1287 {
|
665
|
1288 Charbpos stop;
|
867
|
1289 Ichar c;
|
428
|
1290 int quoted;
|
|
1291 int mathexit = 0;
|
|
1292 enum syntaxcode code;
|
460
|
1293 int syncode;
|
428
|
1294 int min_depth = depth; /* Err out if depth gets less than this. */
|
826
|
1295 struct syntax_cache *scache;
|
|
1296
|
428
|
1297 if (depth > 0) min_depth = 0;
|
|
1298
|
826
|
1299 scache = setup_buffer_syntax_cache (buf, from, count);
|
428
|
1300 while (count > 0)
|
|
1301 {
|
|
1302 QUIT;
|
|
1303
|
|
1304 stop = BUF_ZV (buf);
|
|
1305 while (from < stop)
|
|
1306 {
|
460
|
1307 int comstyle = 0; /* mask for finding matching comment style */
|
428
|
1308
|
826
|
1309 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1310 c = BUF_FETCH_CHAR (buf, from);
|
826
|
1311 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
|
|
1312 code = SYNTAX_FROM_CODE (syncode);
|
428
|
1313 from++;
|
|
1314
|
|
1315 /* a 1-char comment start sequence */
|
|
1316 if (code == Scomment && parse_sexp_ignore_comments)
|
|
1317 {
|
460
|
1318 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) ==
|
|
1319 SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
428
|
1320 }
|
|
1321
|
|
1322 /* else, a 2-char comment start sequence? */
|
|
1323 else if (from < stop
|
460
|
1324 && SYNTAX_CODE_START_FIRST_P (syncode)
|
428
|
1325 && parse_sexp_ignore_comments)
|
|
1326 {
|
460
|
1327 int next_syncode;
|
826
|
1328 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1329 next_syncode =
|
826
|
1330 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from));
|
460
|
1331
|
|
1332 if (SYNTAX_CODES_START_P (syncode, next_syncode))
|
|
1333 {
|
826
|
1334 /* we have encountered a comment start sequence and we
|
|
1335 are ignoring all text inside comments. we must record
|
|
1336 the comment style this sequence begins so that later,
|
|
1337 only a comment end of the same style actually ends
|
|
1338 the comment section */
|
|
1339 code = Scomment;
|
460
|
1340 comstyle = SYNTAX_CODES_COMMENT_MASK_START
|
|
1341 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
826
|
1342 from++;
|
|
1343 }
|
428
|
1344 }
|
826
|
1345 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1346
|
460
|
1347 if (SYNTAX_CODE_PREFIX (syncode))
|
428
|
1348 continue;
|
|
1349
|
|
1350 switch (code)
|
|
1351 {
|
|
1352 case Sescape:
|
|
1353 case Scharquote:
|
|
1354 if (from == stop) goto lose;
|
|
1355 from++;
|
|
1356 /* treat following character as a word constituent */
|
|
1357 case Sword:
|
|
1358 case Ssymbol:
|
|
1359 if (depth || !sexpflag) break;
|
|
1360 /* This word counts as a sexp; return at end of it. */
|
|
1361 while (from < stop)
|
|
1362 {
|
826
|
1363 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
|
1364 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)))
|
428
|
1365 {
|
|
1366 case Scharquote:
|
|
1367 case Sescape:
|
|
1368 from++;
|
|
1369 if (from == stop) goto lose;
|
|
1370 break;
|
|
1371 case Sword:
|
|
1372 case Ssymbol:
|
|
1373 case Squote:
|
|
1374 break;
|
|
1375 default:
|
|
1376 goto done;
|
|
1377 }
|
|
1378 from++;
|
|
1379 }
|
|
1380 goto done;
|
|
1381
|
460
|
1382 case Scomment_fence:
|
|
1383 comstyle = ST_COMMENT_STYLE;
|
428
|
1384 case Scomment:
|
|
1385 if (!parse_sexp_ignore_comments)
|
|
1386 break;
|
826
|
1387 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1388 {
|
665
|
1389 Charbpos newfrom =
|
460
|
1390 find_end_of_comment (buf, from, stop, comstyle);
|
428
|
1391 if (newfrom < 0)
|
|
1392 {
|
|
1393 /* we stopped because from == stop in search forward */
|
|
1394 from = stop;
|
|
1395 if (depth == 0)
|
|
1396 goto done;
|
|
1397 goto lose;
|
|
1398 }
|
|
1399 from = newfrom;
|
|
1400 }
|
|
1401 break;
|
|
1402
|
|
1403 case Smath:
|
|
1404 if (!sexpflag)
|
|
1405 break;
|
|
1406 if (from != stop && c == BUF_FETCH_CHAR (buf, from))
|
|
1407 from++;
|
|
1408 if (mathexit)
|
|
1409 {
|
|
1410 mathexit = 0;
|
|
1411 goto close1;
|
|
1412 }
|
|
1413 mathexit = 1;
|
|
1414
|
|
1415 case Sopen:
|
|
1416 if (!++depth) goto done;
|
|
1417 break;
|
|
1418
|
|
1419 case Sclose:
|
|
1420 close1:
|
|
1421 if (!--depth) goto done;
|
|
1422 if (depth < min_depth)
|
|
1423 {
|
444
|
1424 if (noerror)
|
428
|
1425 return Qnil;
|
826
|
1426 syntax_error ("Containing expression ends prematurely",
|
|
1427 Qunbound);
|
428
|
1428 }
|
|
1429 break;
|
|
1430
|
460
|
1431 case Sstring_fence:
|
428
|
1432 case Sstring:
|
|
1433 {
|
867
|
1434 Ichar stringterm;
|
460
|
1435
|
|
1436 if (code != Sstring_fence)
|
|
1437 {
|
826
|
1438 /* XEmacs change: call syntax_match on character */
|
867
|
1439 Ichar ch = BUF_FETCH_CHAR (buf, from - 1);
|
460
|
1440 Lisp_Object stermobj =
|
1296
|
1441 syntax_match (scache->syntax_table, ch);
|
428
|
1442
|
|
1443 if (CHARP (stermobj))
|
|
1444 stringterm = XCHAR (stermobj);
|
|
1445 else
|
|
1446 stringterm = ch;
|
460
|
1447 }
|
|
1448 else
|
|
1449 stringterm = '\0'; /* avoid compiler warnings */
|
428
|
1450
|
|
1451 while (1)
|
|
1452 {
|
|
1453 if (from >= stop)
|
|
1454 goto lose;
|
826
|
1455 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1456 c = BUF_FETCH_CHAR (buf, from);
|
|
1457 if (code == Sstring
|
|
1458 ? c == stringterm
|
826
|
1459 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence)
|
428
|
1460 break;
|
460
|
1461
|
826
|
1462 switch (SYNTAX_FROM_CACHE (scache, c))
|
428
|
1463 {
|
|
1464 case Scharquote:
|
|
1465 case Sescape:
|
|
1466 from++;
|
|
1467 break;
|
|
1468 default:
|
|
1469 break;
|
|
1470 }
|
|
1471 from++;
|
|
1472 }
|
|
1473 from++;
|
|
1474 if (!depth && sexpflag) goto done;
|
|
1475 break;
|
|
1476 }
|
|
1477
|
|
1478 default:
|
|
1479 break;
|
|
1480 }
|
|
1481 }
|
|
1482
|
|
1483 /* Reached end of buffer. Error if within object,
|
|
1484 return nil if between */
|
|
1485 if (depth) goto lose;
|
|
1486
|
|
1487 return Qnil;
|
|
1488
|
|
1489 /* End of object reached */
|
|
1490 done:
|
|
1491 count--;
|
|
1492 }
|
|
1493
|
|
1494 while (count < 0)
|
|
1495 {
|
|
1496 QUIT;
|
|
1497
|
|
1498 stop = BUF_BEGV (buf);
|
|
1499 while (from > stop)
|
|
1500 {
|
460
|
1501 int comstyle = 0; /* mask for finding matching comment style */
|
428
|
1502
|
|
1503 from--;
|
826
|
1504 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
|
428
|
1505 quoted = char_quoted (buf, from);
|
|
1506 if (quoted)
|
460
|
1507 {
|
428
|
1508 from--;
|
826
|
1509 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
|
460
|
1510 }
|
428
|
1511
|
|
1512 c = BUF_FETCH_CHAR (buf, from);
|
826
|
1513 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
|
|
1514 code = SYNTAX_FROM_CODE (syncode);
|
428
|
1515
|
|
1516 if (code == Sendcomment && parse_sexp_ignore_comments)
|
|
1517 {
|
|
1518 /* we have found a single char end comment. we must record
|
|
1519 the comment style encountered so that later, we can match
|
|
1520 only the proper comment begin sequence of the same style */
|
460
|
1521 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
|
|
1522 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
428
|
1523 }
|
|
1524
|
|
1525 else if (from > stop
|
460
|
1526 && SYNTAX_CODE_END_SECOND_P (syncode)
|
428
|
1527 && !char_quoted (buf, from - 1)
|
|
1528 && parse_sexp_ignore_comments)
|
|
1529 {
|
460
|
1530 int prev_syncode;
|
826
|
1531 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
|
1532 prev_syncode =
|
|
1533 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1));
|
460
|
1534
|
|
1535 if (SYNTAX_CODES_END_P (prev_syncode, syncode))
|
|
1536 {
|
428
|
1537 /* we must record the comment style encountered so that
|
|
1538 later, we can match only the proper comment begin
|
|
1539 sequence of the same style */
|
|
1540 code = Sendcomment;
|
460
|
1541 comstyle = SYNTAX_CODES_COMMENT_MASK_END
|
|
1542 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
428
|
1543 from--;
|
|
1544 }
|
460
|
1545 }
|
428
|
1546
|
460
|
1547 if (SYNTAX_CODE_PREFIX (syncode))
|
428
|
1548 continue;
|
|
1549
|
434
|
1550 switch (quoted ? Sword : code)
|
428
|
1551 {
|
|
1552 case Sword:
|
|
1553 case Ssymbol:
|
|
1554 if (depth || !sexpflag) break;
|
|
1555 /* This word counts as a sexp; count object finished after
|
|
1556 passing it. */
|
|
1557 while (from > stop)
|
|
1558 {
|
826
|
1559 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from);
|
428
|
1560 quoted = char_quoted (buf, from - 1);
|
|
1561
|
|
1562 if (quoted)
|
|
1563 from--;
|
|
1564 if (! (quoted
|
|
1565 || (syncode =
|
826
|
1566 SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf,
|
|
1567 from - 1)))
|
428
|
1568 == Sword
|
|
1569 || syncode == Ssymbol
|
|
1570 || syncode == Squote))
|
|
1571 goto done2;
|
|
1572 from--;
|
|
1573 }
|
|
1574 goto done2;
|
|
1575
|
|
1576 case Smath:
|
|
1577 if (!sexpflag)
|
|
1578 break;
|
|
1579 if (from != stop && c == BUF_FETCH_CHAR (buf, from - 1))
|
|
1580 from--;
|
|
1581 if (mathexit)
|
|
1582 {
|
|
1583 mathexit = 0;
|
|
1584 goto open2;
|
|
1585 }
|
|
1586 mathexit = 1;
|
|
1587
|
|
1588 case Sclose:
|
|
1589 if (!++depth) goto done2;
|
|
1590 break;
|
|
1591
|
|
1592 case Sopen:
|
|
1593 open2:
|
|
1594 if (!--depth) goto done2;
|
|
1595 if (depth < min_depth)
|
|
1596 {
|
444
|
1597 if (noerror)
|
428
|
1598 return Qnil;
|
826
|
1599 syntax_error ("Containing expression ends prematurely",
|
|
1600 Qunbound);
|
428
|
1601 }
|
|
1602 break;
|
|
1603
|
460
|
1604 case Scomment_fence:
|
|
1605 comstyle = ST_COMMENT_STYLE;
|
428
|
1606 case Sendcomment:
|
|
1607 if (parse_sexp_ignore_comments)
|
460
|
1608 from = find_start_of_comment (buf, from, stop, comstyle);
|
428
|
1609 break;
|
|
1610
|
460
|
1611 case Sstring_fence:
|
428
|
1612 case Sstring:
|
|
1613 {
|
867
|
1614 Ichar stringterm;
|
460
|
1615
|
|
1616 if (code != Sstring_fence)
|
|
1617 {
|
428
|
1618 /* XEmacs change: call syntax_match() on character */
|
867
|
1619 Ichar ch = BUF_FETCH_CHAR (buf, from);
|
460
|
1620 Lisp_Object stermobj =
|
1296
|
1621 syntax_match (scache->syntax_table, ch);
|
428
|
1622
|
|
1623 if (CHARP (stermobj))
|
|
1624 stringterm = XCHAR (stermobj);
|
|
1625 else
|
|
1626 stringterm = ch;
|
460
|
1627 }
|
|
1628 else
|
|
1629 stringterm = '\0'; /* avoid compiler warnings */
|
428
|
1630
|
|
1631 while (1)
|
|
1632 {
|
|
1633 if (from == stop) goto lose;
|
460
|
1634
|
826
|
1635 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1);
|
460
|
1636 c = BUF_FETCH_CHAR (buf, from - 1);
|
|
1637
|
|
1638 if ((code == Sstring
|
|
1639 ? c == stringterm
|
826
|
1640 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence)
|
460
|
1641 && !char_quoted (buf, from - 1))
|
|
1642 {
|
428
|
1643 break;
|
460
|
1644 }
|
|
1645
|
428
|
1646 from--;
|
|
1647 }
|
|
1648 from--;
|
|
1649 if (!depth && sexpflag) goto done2;
|
|
1650 break;
|
|
1651 }
|
|
1652 }
|
|
1653 }
|
|
1654
|
|
1655 /* Reached start of buffer. Error if within object,
|
|
1656 return nil if between */
|
|
1657 if (depth) goto lose;
|
|
1658
|
|
1659 return Qnil;
|
|
1660
|
|
1661 done2:
|
|
1662 count++;
|
|
1663 }
|
|
1664
|
|
1665
|
|
1666 return (make_int (from));
|
|
1667
|
|
1668 lose:
|
444
|
1669 if (!noerror)
|
826
|
1670 syntax_error ("Unbalanced parentheses", Qunbound);
|
428
|
1671 return Qnil;
|
|
1672 }
|
|
1673
|
|
1674 int
|
665
|
1675 char_quoted (struct buffer *buf, Charbpos pos)
|
428
|
1676 {
|
|
1677 enum syntaxcode code;
|
665
|
1678 Charbpos beg = BUF_BEGV (buf);
|
428
|
1679 int quoted = 0;
|
665
|
1680 Charbpos startpos = pos;
|
826
|
1681 struct syntax_cache *scache = buf->syntax_cache;
|
460
|
1682
|
|
1683 while (pos > beg)
|
|
1684 {
|
826
|
1685 UPDATE_SYNTAX_CACHE_BACKWARD (scache, pos - 1);
|
|
1686 code = SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, pos - 1));
|
428
|
1687
|
460
|
1688 if (code != Scharquote && code != Sescape)
|
|
1689 break;
|
|
1690 pos--;
|
|
1691 quoted = !quoted;
|
|
1692 }
|
|
1693
|
826
|
1694 UPDATE_SYNTAX_CACHE (scache, startpos);
|
428
|
1695 return quoted;
|
|
1696 }
|
|
1697
|
|
1698 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /*
|
|
1699 Scan from character number FROM by COUNT lists.
|
|
1700 Returns the character number of the position thus found.
|
|
1701
|
|
1702 If DEPTH is nonzero, paren depth begins counting from that value,
|
|
1703 only places where the depth in parentheses becomes zero
|
|
1704 are candidates for stopping; COUNT such places are counted.
|
|
1705 Thus, a positive value for DEPTH means go out levels.
|
|
1706
|
|
1707 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
|
|
1708
|
|
1709 If the beginning or end of (the accessible part of) the buffer is reached
|
|
1710 and the depth is wrong, an error is signaled.
|
|
1711 If the depth is right but the count is not used up, nil is returned.
|
|
1712
|
|
1713 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
|
|
1714 of in the current buffer.
|
|
1715
|
|
1716 If optional arg NOERROR is non-nil, scan-lists will return nil instead of
|
|
1717 signalling an error.
|
|
1718 */
|
444
|
1719 (from, count, depth, buffer, noerror))
|
428
|
1720 {
|
|
1721 struct buffer *buf;
|
|
1722
|
|
1723 CHECK_INT (from);
|
|
1724 CHECK_INT (count);
|
|
1725 CHECK_INT (depth);
|
|
1726 buf = decode_buffer (buffer, 0);
|
|
1727
|
|
1728 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0,
|
444
|
1729 !NILP (noerror));
|
428
|
1730 }
|
|
1731
|
|
1732 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /*
|
|
1733 Scan from character number FROM by COUNT balanced expressions.
|
|
1734 If COUNT is negative, scan backwards.
|
|
1735 Returns the character number of the position thus found.
|
|
1736
|
|
1737 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
|
|
1738
|
|
1739 If the beginning or end of (the accessible part of) the buffer is reached
|
|
1740 in the middle of a parenthetical grouping, an error is signaled.
|
|
1741 If the beginning or end is reached between groupings
|
|
1742 but before count is used up, nil is returned.
|
|
1743
|
|
1744 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
|
|
1745 of in the current buffer.
|
|
1746
|
|
1747 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of
|
|
1748 signalling an error.
|
|
1749 */
|
444
|
1750 (from, count, buffer, noerror))
|
428
|
1751 {
|
|
1752 struct buffer *buf = decode_buffer (buffer, 0);
|
|
1753 CHECK_INT (from);
|
|
1754 CHECK_INT (count);
|
|
1755
|
444
|
1756 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (noerror));
|
428
|
1757 }
|
|
1758
|
|
1759 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /*
|
|
1760 Move point backward over any number of chars with prefix syntax.
|
|
1761 This includes chars with "quote" or "prefix" syntax (' or p).
|
|
1762
|
|
1763 Optional arg BUFFER defaults to the current buffer.
|
|
1764 */
|
|
1765 (buffer))
|
|
1766 {
|
|
1767 struct buffer *buf = decode_buffer (buffer, 0);
|
665
|
1768 Charbpos beg = BUF_BEGV (buf);
|
|
1769 Charbpos pos = BUF_PT (buf);
|
867
|
1770 Ichar c = '\0'; /* initialize to avoid compiler warnings */
|
826
|
1771 struct syntax_cache *scache;
|
|
1772
|
|
1773 scache = setup_buffer_syntax_cache (buf, pos, -1);
|
428
|
1774
|
|
1775 while (pos > beg && !char_quoted (buf, pos - 1)
|
460
|
1776 /* Previous statement updates syntax table. */
|
826
|
1777 && (SYNTAX_FROM_CACHE (scache, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote
|
|
1778 || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (scache, c))))
|
428
|
1779 pos--;
|
|
1780
|
|
1781 BUF_SET_PT (buf, pos);
|
|
1782
|
|
1783 return Qnil;
|
|
1784 }
|
|
1785
|
|
1786 /* Parse forward from FROM to END,
|
|
1787 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
|
|
1788 and return a description of the state of the parse at END.
|
|
1789 If STOPBEFORE is nonzero, stop at the start of an atom.
|
|
1790 If COMMENTSTOP is nonzero, stop at the start of a comment. */
|
|
1791
|
|
1792 static void
|
|
1793 scan_sexps_forward (struct buffer *buf, struct lisp_parse_state *stateptr,
|
665
|
1794 Charbpos from, Charbpos end,
|
428
|
1795 int targetdepth, int stopbefore,
|
|
1796 Lisp_Object oldstate,
|
|
1797 int commentstop)
|
|
1798 {
|
|
1799 struct lisp_parse_state state;
|
|
1800
|
|
1801 enum syntaxcode code;
|
|
1802 struct level { int last, prev; };
|
|
1803 struct level levelstart[100];
|
|
1804 struct level *curlevel = levelstart;
|
|
1805 struct level *endlevel = levelstart + 100;
|
|
1806 int depth; /* Paren depth of current scanning location.
|
|
1807 level - levelstart equals this except
|
|
1808 when the depth becomes negative. */
|
|
1809 int mindepth; /* Lowest DEPTH value seen. */
|
|
1810 int start_quoted = 0; /* Nonzero means starting after a char quote */
|
460
|
1811 int boundary_stop = commentstop == -1;
|
428
|
1812 Lisp_Object tem;
|
826
|
1813 struct syntax_cache *scache;
|
|
1814
|
|
1815 scache = setup_buffer_syntax_cache (buf, from, 1);
|
428
|
1816 if (NILP (oldstate))
|
|
1817 {
|
|
1818 depth = 0;
|
|
1819 state.instring = -1;
|
|
1820 state.incomment = 0;
|
|
1821 state.comstyle = 0; /* comment style a by default */
|
460
|
1822 state.comstr_start = -1; /* no comment/string seen. */
|
428
|
1823 }
|
|
1824 else
|
|
1825 {
|
|
1826 tem = Fcar (oldstate); /* elt 0, depth */
|
|
1827 if (!NILP (tem))
|
|
1828 depth = XINT (tem);
|
|
1829 else
|
|
1830 depth = 0;
|
|
1831
|
|
1832 oldstate = Fcdr (oldstate);
|
|
1833 oldstate = Fcdr (oldstate);
|
|
1834 oldstate = Fcdr (oldstate);
|
|
1835 tem = Fcar (oldstate); /* elt 3, instring */
|
460
|
1836 state.instring = ( !NILP (tem)
|
|
1837 ? ( INTP (tem) ? XINT (tem) : ST_STRING_STYLE)
|
|
1838 : -1);
|
428
|
1839
|
460
|
1840 oldstate = Fcdr (oldstate);
|
|
1841 tem = Fcar (oldstate); /* elt 4, incomment */
|
428
|
1842 state.incomment = !NILP (tem);
|
|
1843
|
|
1844 oldstate = Fcdr (oldstate);
|
|
1845 tem = Fcar (oldstate); /* elt 5, follows-quote */
|
|
1846 start_quoted = !NILP (tem);
|
|
1847
|
|
1848 /* if the eighth element of the list is nil, we are in comment style
|
3025
|
1849 a; if it is t, we are in comment style b; if it is `syntax-table',
|
460
|
1850 we are in a generic comment */
|
428
|
1851 oldstate = Fcdr (oldstate);
|
|
1852 oldstate = Fcdr (oldstate);
|
460
|
1853 tem = Fcar (oldstate); /* elt 7, comment style a/b/fence */
|
|
1854 state.comstyle = NILP (tem) ? 0 : ( EQ (tem, Qsyntax_table)
|
|
1855 ? ST_COMMENT_STYLE : 1 );
|
|
1856
|
|
1857 oldstate = Fcdr (oldstate); /* elt 8, start of last comment/string */
|
|
1858 tem = Fcar (oldstate);
|
|
1859 state.comstr_start = NILP (tem) ? -1 : XINT (tem);
|
|
1860
|
|
1861 /* elt 9, char numbers of starts-of-expression of levels
|
|
1862 (starting from outermost). */
|
|
1863 oldstate = Fcdr (oldstate);
|
|
1864 tem = Fcar (oldstate); /* elt 9, intermediate data for
|
|
1865 continuation of parsing (subject
|
|
1866 to change). */
|
|
1867 while (!NILP (tem)) /* >= second enclosing sexps. */
|
|
1868 {
|
|
1869 curlevel->last = XINT (Fcar (tem));
|
|
1870 if (++curlevel == endlevel)
|
826
|
1871 stack_overflow ("Nesting too deep for parser",
|
|
1872 make_int (curlevel - levelstart));
|
460
|
1873 curlevel->prev = -1;
|
|
1874 curlevel->last = -1;
|
|
1875 tem = Fcdr (tem);
|
|
1876 }
|
428
|
1877 }
|
|
1878 state.quoted = 0;
|
|
1879 mindepth = depth;
|
|
1880
|
|
1881 curlevel->prev = -1;
|
|
1882 curlevel->last = -1;
|
|
1883
|
|
1884 /* Enter the loop at a place appropriate for initial state. */
|
|
1885
|
|
1886 if (state.incomment) goto startincomment;
|
|
1887 if (state.instring >= 0)
|
|
1888 {
|
|
1889 if (start_quoted) goto startquotedinstring;
|
|
1890 goto startinstring;
|
|
1891 }
|
|
1892 if (start_quoted) goto startquoted;
|
|
1893
|
|
1894 while (from < end)
|
|
1895 {
|
867
|
1896 Ichar c;
|
460
|
1897 int syncode;
|
|
1898
|
428
|
1899 QUIT;
|
|
1900
|
826
|
1901 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1902 c = BUF_FETCH_CHAR (buf, from);
|
826
|
1903 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
|
|
1904 code = SYNTAX_FROM_CODE (syncode);
|
428
|
1905 from++;
|
|
1906
|
|
1907 /* record the comment style we have entered so that only the
|
|
1908 comment-ender sequence (or single char) of the same style
|
|
1909 actually terminates the comment section. */
|
460
|
1910 if (code == Scomment)
|
|
1911 {
|
|
1912 state.comstyle =
|
|
1913 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
|
|
1914 == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
|
1915 state.comstr_start = from - 1;
|
|
1916 }
|
|
1917
|
|
1918 /* a generic comment delimiter? */
|
|
1919 else if (code == Scomment_fence)
|
|
1920 {
|
|
1921 state.comstyle = ST_COMMENT_STYLE;
|
|
1922 state.comstr_start = from - 1;
|
|
1923 code = Scomment;
|
428
|
1924 }
|
|
1925
|
|
1926 else if (from < end &&
|
460
|
1927 SYNTAX_CODE_START_FIRST_P (syncode))
|
428
|
1928 {
|
460
|
1929 int next_syncode;
|
826
|
1930 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1931 next_syncode =
|
826
|
1932 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from));
|
460
|
1933
|
|
1934 if (SYNTAX_CODES_START_P (syncode, next_syncode))
|
|
1935 {
|
428
|
1936 code = Scomment;
|
460
|
1937 state.comstyle = SYNTAX_CODES_COMMENT_MASK_START
|
|
1938 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
|
|
1939 state.comstr_start = from - 1;
|
428
|
1940 from++;
|
826
|
1941 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
1942 }
|
428
|
1943 }
|
|
1944
|
460
|
1945 if (SYNTAX_CODE_PREFIX (syncode))
|
428
|
1946 continue;
|
|
1947 switch (code)
|
|
1948 {
|
|
1949 case Sescape:
|
|
1950 case Scharquote:
|
|
1951 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
|
1952 curlevel->last = from - 1;
|
|
1953 startquoted:
|
|
1954 if (from == end) goto endquoted;
|
|
1955 from++;
|
|
1956 goto symstarted;
|
|
1957 /* treat following character as a word constituent */
|
|
1958 case Sword:
|
|
1959 case Ssymbol:
|
|
1960 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
|
1961 curlevel->last = from - 1;
|
|
1962 symstarted:
|
|
1963 while (from < end)
|
|
1964 {
|
826
|
1965 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
|
1966 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)))
|
428
|
1967 {
|
|
1968 case Scharquote:
|
|
1969 case Sescape:
|
|
1970 from++;
|
|
1971 if (from == end) goto endquoted;
|
|
1972 break;
|
|
1973 case Sword:
|
|
1974 case Ssymbol:
|
|
1975 case Squote:
|
|
1976 break;
|
|
1977 default:
|
|
1978 goto symdone;
|
|
1979 }
|
|
1980 from++;
|
|
1981 }
|
|
1982 symdone:
|
|
1983 curlevel->prev = curlevel->last;
|
|
1984 break;
|
|
1985
|
|
1986 case Scomment:
|
|
1987 state.incomment = 1;
|
460
|
1988 if (commentstop || boundary_stop) goto done;
|
428
|
1989 startincomment:
|
460
|
1990 if (commentstop == 1)
|
428
|
1991 goto done;
|
826
|
1992 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
428
|
1993 {
|
826
|
1994 Charbpos newfrom = find_end_of_comment (buf, from, end,
|
|
1995 state.comstyle);
|
428
|
1996 if (newfrom < 0)
|
|
1997 {
|
|
1998 /* we terminated search because from == end */
|
|
1999 from = end;
|
|
2000 goto done;
|
|
2001 }
|
|
2002 from = newfrom;
|
|
2003 }
|
|
2004 state.incomment = 0;
|
|
2005 state.comstyle = 0; /* reset the comment style */
|
460
|
2006 if (boundary_stop) goto done;
|
428
|
2007 break;
|
|
2008
|
|
2009 case Sopen:
|
|
2010 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
|
2011 depth++;
|
|
2012 /* curlevel++->last ran into compiler bug on Apollo */
|
|
2013 curlevel->last = from - 1;
|
|
2014 if (++curlevel == endlevel)
|
826
|
2015 stack_overflow ("Nesting too deep for parser",
|
|
2016 make_int (curlevel - levelstart));
|
428
|
2017 curlevel->prev = -1;
|
|
2018 curlevel->last = -1;
|
|
2019 if (targetdepth == depth) goto done;
|
|
2020 break;
|
|
2021
|
|
2022 case Sclose:
|
|
2023 depth--;
|
|
2024 if (depth < mindepth)
|
|
2025 mindepth = depth;
|
|
2026 if (curlevel != levelstart)
|
|
2027 curlevel--;
|
|
2028 curlevel->prev = curlevel->last;
|
|
2029 if (targetdepth == depth) goto done;
|
|
2030 break;
|
|
2031
|
|
2032 case Sstring:
|
460
|
2033 case Sstring_fence:
|
|
2034 state.comstr_start = from - 1;
|
428
|
2035 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
|
2036 curlevel->last = from - 1;
|
460
|
2037 if (code == Sstring_fence)
|
428
|
2038 {
|
460
|
2039 state.instring = ST_STRING_STYLE;
|
|
2040 }
|
|
2041 else
|
|
2042 {
|
|
2043 /* XEmacs change: call syntax_match() on character */
|
867
|
2044 Ichar ch = BUF_FETCH_CHAR (buf, from - 1);
|
460
|
2045 Lisp_Object stermobj =
|
1296
|
2046 syntax_match (scache->syntax_table, ch);
|
428
|
2047
|
|
2048 if (CHARP (stermobj))
|
|
2049 state.instring = XCHAR (stermobj);
|
|
2050 else
|
|
2051 state.instring = ch;
|
|
2052 }
|
460
|
2053 if (boundary_stop) goto done;
|
428
|
2054 startinstring:
|
|
2055 while (1)
|
|
2056 {
|
460
|
2057 enum syntaxcode temp_code;
|
|
2058
|
428
|
2059 if (from >= end) goto done;
|
460
|
2060
|
826
|
2061 UPDATE_SYNTAX_CACHE_FORWARD (scache, from);
|
460
|
2062 c = BUF_FETCH_CHAR (buf, from);
|
826
|
2063 temp_code = SYNTAX_FROM_CACHE (scache, c);
|
460
|
2064
|
|
2065 if (
|
|
2066 state.instring != ST_STRING_STYLE &&
|
|
2067 temp_code == Sstring &&
|
|
2068 c == state.instring) break;
|
|
2069
|
|
2070 switch (temp_code)
|
428
|
2071 {
|
460
|
2072 case Sstring_fence:
|
|
2073 if (state.instring == ST_STRING_STYLE)
|
|
2074 goto string_end;
|
|
2075 break;
|
428
|
2076 case Scharquote:
|
|
2077 case Sescape:
|
|
2078 {
|
|
2079 from++;
|
|
2080 startquotedinstring:
|
|
2081 if (from >= end) goto endquoted;
|
|
2082 break;
|
|
2083 }
|
|
2084 default:
|
|
2085 break;
|
|
2086 }
|
|
2087 from++;
|
|
2088 }
|
460
|
2089 string_end:
|
428
|
2090 state.instring = -1;
|
|
2091 curlevel->prev = curlevel->last;
|
|
2092 from++;
|
460
|
2093 if (boundary_stop) goto done;
|
428
|
2094 break;
|
|
2095
|
|
2096 case Smath:
|
|
2097 break;
|
|
2098
|
|
2099 case Swhitespace:
|
|
2100 case Spunct:
|
|
2101 case Squote:
|
|
2102 case Sendcomment:
|
460
|
2103 case Scomment_fence:
|
428
|
2104 case Sinherit:
|
|
2105 case Smax:
|
|
2106 break;
|
|
2107 }
|
|
2108 }
|
|
2109 goto done;
|
|
2110
|
|
2111 stop: /* Here if stopping before start of sexp. */
|
|
2112 from--; /* We have just fetched the char that starts it; */
|
|
2113 goto done; /* but return the position before it. */
|
|
2114
|
|
2115 endquoted:
|
|
2116 state.quoted = 1;
|
|
2117 done:
|
|
2118 state.depth = depth;
|
|
2119 state.mindepth = mindepth;
|
|
2120 state.thislevelstart = curlevel->prev;
|
|
2121 state.prevlevelstart
|
|
2122 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
|
|
2123 state.location = from;
|
460
|
2124 state.levelstarts = Qnil;
|
|
2125 while (--curlevel >= levelstart)
|
|
2126 state.levelstarts = Fcons (make_int (curlevel->last),
|
|
2127 state.levelstarts);
|
428
|
2128
|
|
2129 *stateptr = state;
|
|
2130 }
|
|
2131
|
|
2132 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /*
|
|
2133 Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
|
|
2134 Parsing stops at TO or when certain criteria are met;
|
|
2135 point is set to where parsing stops.
|
444
|
2136 If fifth arg OLDSTATE is omitted or nil,
|
428
|
2137 parsing assumes that FROM is the beginning of a function.
|
460
|
2138 Value is a list of nine elements describing final state of parsing:
|
428
|
2139 0. depth in parens.
|
|
2140 1. character address of start of innermost containing list; nil if none.
|
|
2141 2. character address of start of last complete sexp terminated.
|
|
2142 3. non-nil if inside a string.
|
460
|
2143 (It is the character that will terminate the string,
|
|
2144 or t if the string should be terminated by an explicit
|
|
2145 `syntax-table' property.)
|
428
|
2146 4. t if inside a comment.
|
|
2147 5. t if following a quote character.
|
|
2148 6. the minimum paren-depth encountered during this scan.
|
460
|
2149 7. nil if in comment style a, or not in a comment; t if in comment style b;
|
|
2150 `syntax-table' if given by an explicit `syntax-table' property.
|
|
2151 8. character address of start of last comment or string; nil if none.
|
|
2152 9. Intermediate data for continuation of parsing (subject to change).
|
428
|
2153 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
|
|
2154 in parentheses becomes equal to TARGETDEPTH.
|
|
2155 Fourth arg STOPBEFORE non-nil means stop when come to
|
|
2156 any character that starts a sexp.
|
460
|
2157 Fifth arg OLDSTATE is a nine-element list like what this function returns.
|
428
|
2158 It is used to initialize the state of the parse. Its second and third
|
|
2159 elements are ignored.
|
460
|
2160 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. If it
|
|
2161 is `syntax-table', stop after the start of a comment or a string, or after
|
|
2162 the end of a comment or string.
|
826
|
2163 Seventh arg BUFFER specifies the buffer to do the parsing in, and defaults
|
|
2164 to the current buffer.
|
428
|
2165 */
|
|
2166 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer))
|
|
2167 {
|
|
2168 struct lisp_parse_state state;
|
|
2169 int target;
|
665
|
2170 Charbpos start, end;
|
428
|
2171 struct buffer *buf = decode_buffer (buffer, 0);
|
|
2172 Lisp_Object val;
|
|
2173
|
|
2174 if (!NILP (targetdepth))
|
|
2175 {
|
|
2176 CHECK_INT (targetdepth);
|
|
2177 target = XINT (targetdepth);
|
|
2178 }
|
|
2179 else
|
|
2180 target = -100000; /* We won't reach this depth */
|
|
2181
|
|
2182 get_buffer_range_char (buf, from, to, &start, &end, 0);
|
|
2183 scan_sexps_forward (buf, &state, start, end,
|
|
2184 target, !NILP (stopbefore), oldstate,
|
460
|
2185 (NILP (commentstop)
|
|
2186 ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1)));
|
428
|
2187 BUF_SET_PT (buf, state.location);
|
|
2188
|
|
2189 /* reverse order */
|
|
2190 val = Qnil;
|
460
|
2191 val = Fcons (state.levelstarts, val);
|
|
2192 val = Fcons ((state.incomment || (state.instring >= 0))
|
|
2193 ? make_int (state.comstr_start) : Qnil, val);
|
|
2194 val = Fcons (state.comstyle ? (state.comstyle == ST_COMMENT_STYLE
|
|
2195 ? Qsyntax_table : Qt) : Qnil, val);
|
428
|
2196 val = Fcons (make_int (state.mindepth), val);
|
|
2197 val = Fcons (state.quoted ? Qt : Qnil, val);
|
|
2198 val = Fcons (state.incomment ? Qt : Qnil, val);
|
460
|
2199 val = Fcons (state.instring < 0
|
|
2200 ? Qnil
|
|
2201 : (state.instring == ST_STRING_STYLE
|
|
2202 ? Qt : make_int (state.instring)), val);
|
826
|
2203 val = Fcons (state.thislevelstart < 0 ? Qnil :
|
|
2204 make_int (state.thislevelstart), val);
|
|
2205 val = Fcons (state.prevlevelstart < 0 ? Qnil :
|
|
2206 make_int (state.prevlevelstart), val);
|
428
|
2207 val = Fcons (make_int (state.depth), val);
|
|
2208
|
|
2209 return val;
|
|
2210 }
|
|
2211
|
|
2212
|
|
2213 /* Updating of the mirror syntax table.
|
|
2214
|
1296
|
2215 Each syntax table has a corresponding mirror table in it. Whenever we
|
|
2216 make a change to a syntax table, we set a dirty flag. When accessing a
|
|
2217 value from the mirror table and the table is dirty, we call
|
|
2218 update_syntax_table() to clean it up.
|
428
|
2219
|
|
2220 #### We really only need to map over the changed range.
|
|
2221
|
|
2222 If we change the standard syntax table, we need to map over
|
|
2223 all tables because any of them could be inheriting from the
|
|
2224 standard syntax table.
|
|
2225
|
|
2226 When `set-syntax-table' is called, we set the buffer's mirror
|
|
2227 syntax table as well.
|
|
2228 */
|
|
2229
|
826
|
2230 static int
|
2286
|
2231 copy_to_mirrortab (struct chartab_range *range, Lisp_Object UNUSED (table),
|
826
|
2232 Lisp_Object val, void *arg)
|
428
|
2233 {
|
826
|
2234 Lisp_Object mirrortab = VOID_TO_LISP (arg);
|
428
|
2235
|
|
2236 if (CONSP (val))
|
|
2237 val = XCAR (val);
|
826
|
2238 if (SYNTAX_FROM_CODE (XINT (val)) != Sinherit)
|
|
2239 put_char_table (mirrortab, range, val);
|
|
2240 return 0;
|
|
2241 }
|
|
2242
|
|
2243 static int
|
2286
|
2244 copy_if_not_already_present (struct chartab_range *range,
|
|
2245 Lisp_Object UNUSED (table),
|
826
|
2246 Lisp_Object val, void *arg)
|
|
2247 {
|
1296
|
2248 Lisp_Object mirrortab = VOID_TO_LISP (arg);
|
826
|
2249 if (CONSP (val))
|
|
2250 val = XCAR (val);
|
|
2251 if (SYNTAX_FROM_CODE (XINT (val)) != Sinherit)
|
|
2252 {
|
|
2253 Lisp_Object existing =
|
1296
|
2254 updating_mirror_get_range_char_table (range, mirrortab,
|
|
2255 Vbogus_syntax_table_value);
|
826
|
2256 if (NILP (existing))
|
|
2257 /* nothing at all */
|
1296
|
2258 put_char_table (mirrortab, range, val);
|
|
2259 else if (!EQ (existing, Vbogus_syntax_table_value))
|
826
|
2260 /* full */
|
|
2261 ;
|
|
2262 else
|
|
2263 {
|
|
2264 Freset_char_table (Vtemp_table_for_use_updating_syntax_tables);
|
|
2265 copy_char_table_range
|
1296
|
2266 (mirrortab, Vtemp_table_for_use_updating_syntax_tables, range);
|
|
2267 put_char_table (mirrortab, range, val);
|
826
|
2268 copy_char_table_range
|
1296
|
2269 (Vtemp_table_for_use_updating_syntax_tables, mirrortab, range);
|
826
|
2270 }
|
428
|
2271 }
|
826
|
2272
|
428
|
2273 return 0;
|
|
2274 }
|
|
2275
|
|
2276 static void
|
826
|
2277 update_just_this_syntax_table (Lisp_Object table)
|
428
|
2278 {
|
|
2279 struct chartab_range range;
|
826
|
2280 Lisp_Object mirrortab = XCHAR_TABLE (table)->mirror_table;
|
|
2281
|
1296
|
2282 assert (!XCHAR_TABLE (table)->mirror_table_p);
|
826
|
2283 range.type = CHARTAB_RANGE_ALL;
|
|
2284 Freset_char_table (mirrortab);
|
1296
|
2285
|
826
|
2286 /* First, copy the tables values other than inherit into the mirror
|
|
2287 table. Then, for tables other than the standard syntax table, map
|
|
2288 over the standard table, copying values into the mirror table only if
|
|
2289 entries don't already exist in that table. (The copying step requires
|
|
2290 another mapping.)
|
|
2291 */
|
428
|
2292
|
826
|
2293 map_char_table (table, &range, copy_to_mirrortab, LISP_TO_VOID (mirrortab));
|
|
2294 /* second clause catches bootstrapping problems when initializing the
|
|
2295 standard syntax table */
|
|
2296 if (!EQ (table, Vstandard_syntax_table) && !NILP (Vstandard_syntax_table))
|
1296
|
2297 map_char_table (Vstandard_syntax_table, &range,
|
|
2298 copy_if_not_already_present, LISP_TO_VOID (mirrortab));
|
3152
|
2299 /* The resetting made the default be Qnil. Put it back to Sword. */
|
|
2300 set_char_table_default (mirrortab, make_int (Sword));
|
1296
|
2301 XCHAR_TABLE (mirrortab)->dirty = 0;
|
428
|
2302 }
|
|
2303
|
|
2304 /* Called from chartab.c when a change is made to a syntax table.
|
|
2305 If this is the standard syntax table, we need to recompute
|
|
2306 *all* syntax tables (yuck). Otherwise we just recompute this
|
|
2307 one. */
|
|
2308
|
|
2309 void
|
826
|
2310 update_syntax_table (Lisp_Object table)
|
428
|
2311 {
|
1296
|
2312 Lisp_Object nonmirror = XCHAR_TABLE (table)->mirror_table;
|
|
2313 assert (XCHAR_TABLE (table)->mirror_table_p);
|
|
2314 if (EQ (nonmirror, Vstandard_syntax_table))
|
428
|
2315 {
|
|
2316 Lisp_Object syntab;
|
|
2317
|
|
2318 for (syntab = Vall_syntax_tables; !NILP (syntab);
|
|
2319 syntab = XCHAR_TABLE (syntab)->next_table)
|
826
|
2320 update_just_this_syntax_table (syntab);
|
428
|
2321 }
|
|
2322 else
|
1296
|
2323 update_just_this_syntax_table (nonmirror);
|
428
|
2324 }
|
|
2325
|
|
2326
|
|
2327 /************************************************************************/
|
|
2328 /* initialization */
|
|
2329 /************************************************************************/
|
|
2330
|
|
2331 void
|
|
2332 syms_of_syntax (void)
|
|
2333 {
|
3092
|
2334 #ifdef NEW_GC
|
|
2335 INIT_LRECORD_IMPLEMENTATION (syntax_cache);
|
|
2336 #endif /* NEW_GC */
|
563
|
2337 DEFSYMBOL (Qsyntax_table_p);
|
|
2338 DEFSYMBOL (Qsyntax_table);
|
428
|
2339
|
|
2340 DEFSUBR (Fsyntax_table_p);
|
|
2341 DEFSUBR (Fsyntax_table);
|
826
|
2342 #ifdef DEBUG_XEMACS
|
|
2343 DEFSUBR (Fmirror_syntax_table);
|
|
2344 DEFSUBR (Fsyntax_cache_info);
|
|
2345 #endif /* DEBUG_XEMACS */
|
428
|
2346 DEFSUBR (Fstandard_syntax_table);
|
|
2347 DEFSUBR (Fcopy_syntax_table);
|
|
2348 DEFSUBR (Fset_syntax_table);
|
|
2349 DEFSUBR (Fsyntax_designator_chars);
|
|
2350 DEFSUBR (Fchar_syntax);
|
|
2351 DEFSUBR (Fmatching_paren);
|
|
2352 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */
|
|
2353 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */
|
|
2354
|
|
2355 DEFSUBR (Fforward_word);
|
|
2356
|
|
2357 DEFSUBR (Fforward_comment);
|
|
2358 DEFSUBR (Fscan_lists);
|
|
2359 DEFSUBR (Fscan_sexps);
|
|
2360 DEFSUBR (Fbackward_prefix_chars);
|
|
2361 DEFSUBR (Fparse_partial_sexp);
|
|
2362 }
|
|
2363
|
|
2364 void
|
|
2365 vars_of_syntax (void)
|
|
2366 {
|
|
2367 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments /*
|
|
2368 Non-nil means `forward-sexp', etc., should treat comments as whitespace.
|
|
2369 */ );
|
434
|
2370 parse_sexp_ignore_comments = 0;
|
428
|
2371
|
460
|
2372 DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /*
|
826
|
2373 Non-nil means `forward-sexp', etc., respect the `syntax-table' property.
|
|
2374 This property can be placed on buffers or strings and can be used to explicitly
|
|
2375 specify the syntax table to be used for looking up the syntax of the chars
|
|
2376 having this property, or to directly specify the syntax of the chars.
|
|
2377
|
460
|
2378 The value of this property should be either a syntax table, or a cons
|
|
2379 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric
|
|
2380 syntax code, MATCHCHAR being nil or the character to match (which is
|
826
|
2381 relevant only when the syntax code is open/close-type).
|
460
|
2382 */ );
|
|
2383 lookup_syntax_properties = 1;
|
|
2384
|
428
|
2385 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /*
|
|
2386 Non-nil means `forward-word', etc., should treat escape chars part of words.
|
|
2387 */ );
|
434
|
2388 words_include_escapes = 0;
|
428
|
2389
|
|
2390 no_quit_in_re_search = 0;
|
1296
|
2391
|
|
2392 Vbogus_syntax_table_value = make_float (0.0);
|
|
2393 staticpro (&Vbogus_syntax_table_value);
|
428
|
2394 }
|
|
2395
|
|
2396 static void
|
442
|
2397 define_standard_syntax (const char *p, enum syntaxcode syn)
|
428
|
2398 {
|
|
2399 for (; *p; p++)
|
|
2400 Fput_char_table (make_char (*p), make_int (syn), Vstandard_syntax_table);
|
|
2401 }
|
|
2402
|
|
2403 void
|
|
2404 complex_vars_of_syntax (void)
|
|
2405 {
|
867
|
2406 Ichar i;
|
442
|
2407 const char *p;
|
428
|
2408 /* Set this now, so first buffer creation can refer to it. */
|
|
2409 /* Make it nil before calling copy-syntax-table
|
|
2410 so that copy-syntax-table will know not to try to copy from garbage */
|
|
2411 Vstandard_syntax_table = Qnil;
|
|
2412 Vstandard_syntax_table = Fcopy_syntax_table (Qnil);
|
|
2413 staticpro (&Vstandard_syntax_table);
|
|
2414
|
826
|
2415 Vtemp_table_for_use_updating_syntax_tables = Fmake_char_table (Qgeneric);
|
|
2416 staticpro (&Vtemp_table_for_use_updating_syntax_tables);
|
|
2417
|
428
|
2418 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec,
|
|
2419 Smax);
|
|
2420 staticpro (&Vsyntax_designator_chars_string);
|
|
2421
|
3152
|
2422 set_char_table_default (Vstandard_syntax_table, make_int (Sword));
|
428
|
2423
|
|
2424 for (i = 0; i <= 32; i++) /* Control 0 plus SPACE */
|
|
2425 Fput_char_table (make_char (i), make_int (Swhitespace),
|
|
2426 Vstandard_syntax_table);
|
|
2427 for (i = 127; i <= 159; i++) /* DEL plus Control 1 */
|
|
2428 Fput_char_table (make_char (i), make_int (Swhitespace),
|
|
2429 Vstandard_syntax_table);
|
|
2430
|
|
2431 define_standard_syntax ("abcdefghijklmnopqrstuvwxyz"
|
|
2432 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
2433 "0123456789"
|
|
2434 "$%", Sword);
|
|
2435 define_standard_syntax ("\"", Sstring);
|
|
2436 define_standard_syntax ("\\", Sescape);
|
|
2437 define_standard_syntax ("_-+*/&|<>=", Ssymbol);
|
|
2438 define_standard_syntax (".,;:?!#@~^'`", Spunct);
|
|
2439
|
|
2440 for (p = "()[]{}"; *p; p+=2)
|
|
2441 {
|
|
2442 Fput_char_table (make_char (p[0]),
|
|
2443 Fcons (make_int (Sopen), make_char (p[1])),
|
|
2444 Vstandard_syntax_table);
|
|
2445 Fput_char_table (make_char (p[1]),
|
|
2446 Fcons (make_int (Sclose), make_char (p[0])),
|
|
2447 Vstandard_syntax_table);
|
|
2448 }
|
|
2449 }
|