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