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