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