1 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
2 Copyright (C) 1985, 87, 93, 94, 95, 97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
29 /* Make syntax table lookup grant data in gl_state. */
30 #define SYNTAX_ENTRY_VIA_PROPERTY
33 #include "intervals.h"
35 /* We use these constants in place for comment-style and
36 string-ender-char to distinguish comments/strings started by
37 comment_fence and string_fence codes. */
39 #define ST_COMMENT_STYLE (256 + 1)
40 #define ST_STRING_STYLE (256 + 2)
43 Lisp_Object Qsyntax_table_p
, Qsyntax_table
, Qscan_error
;
45 int words_include_escapes
;
46 int parse_sexp_lookup_properties
;
48 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
49 if not compiled with GCC. No need to mark it, since it is used
50 only very temporarily. */
51 Lisp_Object syntax_temp
;
53 /* This is the internal form of the parse state used in parse-partial-sexp. */
55 struct lisp_parse_state
57 int depth
; /* Depth at end of parsing. */
58 int instring
; /* -1 if not within string, else desired terminator. */
59 int incomment
; /* Nonzero if within a comment at end of parsing. */
60 int comstyle
; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
61 int quoted
; /* Nonzero if just after an escape char at end of parsing */
62 int thislevelstart
; /* Char number of most recent start-of-expression at current level */
63 int prevlevelstart
; /* Char number of start of containing expression */
64 int location
; /* Char number at which parsing stopped. */
65 int mindepth
; /* Minimum depth seen while scanning. */
66 int comstr_start
; /* Position just after last comment/string starter. */
69 /* These variables are a cache for finding the start of a defun.
70 find_start_pos is the place for which the defun start was found.
71 find_start_value is the defun start position found for it.
72 find_start_value_byte is the corresponding byte position.
73 find_start_buffer is the buffer it was found in.
74 find_start_begv is the BEGV value when it was found.
75 find_start_modiff is the value of MODIFF when it was found. */
77 static int find_start_pos
;
78 static int find_start_value
;
79 static int find_start_value_byte
;
80 static struct buffer
*find_start_buffer
;
81 static int find_start_begv
;
82 static int find_start_modiff
;
85 static int find_defun_start
P_ ((int, int));
86 static int back_comment
P_ ((int, int, int, int, int *, int *));
87 static int char_quoted
P_ ((int, int));
88 static Lisp_Object skip_chars
P_ ((int, int, Lisp_Object
, Lisp_Object
));
89 static Lisp_Object scan_lists
P_ ((int, int, int, int));
90 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
92 int, Lisp_Object
, int));
95 struct gl_state_s gl_state
; /* Global state of syntax parser. */
97 INTERVAL
interval_of ();
98 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
99 to scan to property-change. */
101 /* Update gl_state to an appropriate interval which contains CHARPOS. The
102 sign of COUNT give the relative position of CHARPOS wrt the previously
103 valid interval. If INIT, only [be]_property fields of gl_state are
104 valid at start, the rest is filled basing on OBJECT.
106 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
107 direction than the intervals - or in an interval. We update the
108 current syntax-table basing on the property of this interval, and
109 update the interval to start further than CHARPOS - or be
110 NULL_INTERVAL. We also update lim_property to be the next value of
111 charpos to call this subroutine again - or be before/after the
112 start/end of OBJECT. */
115 update_syntax_table (charpos
, count
, init
, object
)
116 int charpos
, count
, init
;
119 Lisp_Object tmp_table
;
120 int cnt
= 0, doing_extra
= 0, invalidate
= 1;
125 gl_state
.start
= gl_state
.b_property
;
126 gl_state
.stop
= gl_state
.e_property
;
127 gl_state
.forward_i
= interval_of (charpos
, object
);
128 i
= gl_state
.backward_i
= gl_state
.forward_i
;
129 gl_state
.left_ok
= gl_state
.right_ok
= 1;
131 if (NULL_INTERVAL_P (i
))
133 gl_state
.b_property
= i
->position
- 1 - gl_state
.offset
;
134 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
137 oldi
= i
= count
> 0 ? gl_state
.forward_i
: gl_state
.backward_i
;
139 /* We are guarantied to be called with CHARPOS either in i,
141 if (NULL_INTERVAL_P (i
))
142 error ("Error in syntax_table logic for to-the-end intervals");
143 else if (charpos
< i
->position
) /* Move left. */
146 error ("Error in syntax_table logic for intervals <-.");
147 /* Update the interval. */
148 i
= update_interval (i
, charpos
);
149 if (oldi
->position
!= INTERVAL_LAST_POS (i
))
152 gl_state
.right_ok
= 1; /* Invalidate the other end. */
153 gl_state
.forward_i
= i
;
154 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
157 else if (charpos
>= INTERVAL_LAST_POS (i
)) /* Move right. */
160 error ("Error in syntax_table logic for intervals ->.");
161 /* Update the interval. */
162 i
= update_interval (i
, charpos
);
163 if (i
->position
!= INTERVAL_LAST_POS (oldi
))
166 gl_state
.left_ok
= 1; /* Invalidate the other end. */
167 gl_state
.backward_i
= i
;
168 gl_state
.b_property
= i
->position
- 1 - gl_state
.offset
;
171 else if (count
> 0 ? gl_state
.right_ok
: gl_state
.left_ok
)
173 /* We do not need to recalculate tmp_table. */
174 tmp_table
= gl_state
.old_prop
;
178 tmp_table
= textget (i
->plist
, Qsyntax_table
);
181 invalidate
= !EQ (tmp_table
, gl_state
.old_prop
); /* Need to invalidate? */
183 if (invalidate
) /* Did not get to adjacent interval. */
184 { /* with the same table => */
185 /* invalidate the old range. */
188 gl_state
.backward_i
= i
;
189 gl_state
.left_ok
= 1; /* Invalidate the other end. */
190 gl_state
.b_property
= i
->position
- 1 - gl_state
.offset
;
194 gl_state
.forward_i
= i
;
195 gl_state
.right_ok
= 1; /* Invalidate the other end. */
196 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
200 gl_state
.current_syntax_table
= tmp_table
;
201 gl_state
.old_prop
= tmp_table
;
202 if (EQ (Fsyntax_table_p (tmp_table
), Qt
))
204 gl_state
.use_global
= 0;
206 else if (CONSP (tmp_table
))
208 gl_state
.use_global
= 1;
209 gl_state
.global_code
= tmp_table
;
213 gl_state
.use_global
= 0;
214 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
217 while (!NULL_INTERVAL_P (i
))
219 if (cnt
&& !EQ (tmp_table
, textget (i
->plist
, Qsyntax_table
)))
222 gl_state
.right_ok
= 0;
224 gl_state
.left_ok
= 0;
227 else if (cnt
== INTERVALS_AT_ONCE
)
230 gl_state
.right_ok
= 1;
232 gl_state
.left_ok
= 1;
236 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
238 if (NULL_INTERVAL_P (i
))
239 { /* This property goes to the end. */
241 gl_state
.e_property
= gl_state
.stop
;
243 gl_state
.b_property
= gl_state
.start
;
249 gl_state
.e_property
= i
->position
- gl_state
.offset
;
250 gl_state
.forward_i
= i
;
254 gl_state
.b_property
= i
->position
+ LENGTH (i
) - 1 - gl_state
.offset
;
255 gl_state
.backward_i
= i
;
260 /* Returns TRUE if char at CHARPOS is quoted.
261 Global syntax-table data should be set up already to be good at CHARPOS
262 or after. On return global syntax data is good for lookup at CHARPOS. */
265 char_quoted (charpos
, bytepos
)
266 register int charpos
, bytepos
;
268 register enum syntaxcode code
;
269 register int beg
= BEGV
;
270 register int quoted
= 0;
273 DEC_BOTH (charpos
, bytepos
);
275 while (bytepos
>= beg
)
277 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
278 code
= SYNTAX (FETCH_CHAR (bytepos
));
279 if (! (code
== Scharquote
|| code
== Sescape
))
282 DEC_BOTH (charpos
, bytepos
);
286 UPDATE_SYNTAX_TABLE (orig
);
290 /* Return the bytepos one character after BYTEPOS.
291 We assume that BYTEPOS is not at the end of the buffer. */
294 inc_bytepos (bytepos
)
297 if (NILP (current_buffer
->enable_multibyte_characters
))
304 /* Return the bytepos one character before BYTEPOS.
305 We assume that BYTEPOS is not at the start of the buffer. */
308 dec_bytepos (bytepos
)
311 if (NILP (current_buffer
->enable_multibyte_characters
))
318 /* Find a defun-start that is the last one before POS (or nearly the last).
319 We record what we find, so that another call in the same area
320 can return the same value right away.
322 There is no promise at which position the global syntax data is
323 valid on return from the subroutine, so the caller should explicitly
324 update the global data. */
327 find_defun_start (pos
, pos_byte
)
332 int opoint
= PT
, opoint_byte
= PT_BYTE
;
334 /* Use previous finding, if it's valid and applies to this inquiry. */
335 if (current_buffer
== find_start_buffer
336 /* Reuse the defun-start even if POS is a little farther on.
337 POS might be in the next defun, but that's ok.
338 Our value may not be the best possible, but will still be usable. */
339 && pos
<= find_start_pos
+ 1000
340 && pos
>= find_start_value
341 && BEGV
== find_start_begv
342 && MODIFF
== find_start_modiff
)
343 return find_start_value
;
345 /* Back up to start of line. */
346 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
348 /* We optimize syntax-table lookup for rare updates. Thus we accept
349 only those `^\s(' which are good in global _and_ text-property
351 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
352 gl_state
.use_global
= 0;
355 /* Open-paren at start of line means we found our defun-start. */
356 if (SYNTAX (FETCH_CHAR (PT_BYTE
)) == Sopen
)
358 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
359 if (SYNTAX (FETCH_CHAR (PT_BYTE
)) == Sopen
)
361 /* Now fallback to the default value. */
362 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
363 gl_state
.use_global
= 0;
365 /* Move to beg of previous line. */
366 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
369 /* Record what we found, for the next try. */
370 find_start_value
= PT
;
371 find_start_value_byte
= PT_BYTE
;
372 find_start_buffer
= current_buffer
;
373 find_start_modiff
= MODIFF
;
374 find_start_begv
= BEGV
;
375 find_start_pos
= pos
;
377 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
379 return find_start_value
;
382 /* Checks whether charpos FROM is at the end of a comment.
383 FROM_BYTE is the bytepos corresponding to FROM.
384 Do not move back before STOP.
386 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
389 If successful, store the charpos of the comment's beginning
390 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
392 Global syntax data remains valid for backward search starting at
393 the returned value (or at FROM, if the search was not successful). */
396 back_comment (from
, from_byte
, stop
, comstyle
, charpos_ptr
, bytepos_ptr
)
397 int from
, from_byte
, stop
;
399 int *charpos_ptr
, *bytepos_ptr
;
401 /* Look back, counting the parity of string-quotes,
402 and recording the comment-starters seen.
403 When we reach a safe place, assume that's not in a string;
404 then step the main scan to the earliest comment-starter seen
405 an even number of string quotes away from the safe place.
407 OFROM[I] is position of the earliest comment-starter seen
408 which is I+2X quotes from the comment-end.
409 PARITY is current parity of quotes from the comment end. */
411 int my_stringend
= 0;
412 int string_lossage
= 0;
413 int comment_end
= from
;
414 int comment_end_byte
= from_byte
;
415 int comstart_pos
= 0;
417 /* Value that PARITY had, when we reached the position
419 int comstart_parity
= 0;
420 int scanstart
= from
- 1;
421 /* Place where the containing defun starts,
422 or 0 if we didn't come across it yet. */
424 int defun_start_byte
= 0;
425 register enum syntaxcode code
;
428 /* At beginning of range to scan, we're outside of strings;
429 that determines quote parity to the comment-end. */
434 /* Move back and examine a character. */
435 DEC_BOTH (from
, from_byte
);
436 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
438 c
= FETCH_CHAR (from_byte
);
441 /* If this char is the second of a 2-char comment end sequence,
442 back up and give the pair the appropriate syntax. */
443 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
444 && (temp_byte
= dec_bytepos (from_byte
),
445 SYNTAX_COMEND_FIRST (FETCH_CHAR (temp_byte
))))
448 DEC_BOTH (from
, from_byte
);
449 /* This is apparently the best we can do: */
450 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
451 c
= FETCH_CHAR (from_byte
);
454 /* If this char starts a 2-char comment start sequence,
455 treat it like a 1-char comment starter. */
456 if (from
< scanstart
&& SYNTAX_COMSTART_FIRST (c
)
457 && (temp_byte
= inc_bytepos (from_byte
),
458 (SYNTAX_COMSTART_SECOND (FETCH_CHAR (temp_byte
))
459 && comstyle
== SYNTAX_COMMENT_STYLE (FETCH_CHAR (temp_byte
)))))
462 /* Ignore escaped characters, except comment-enders. */
463 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
466 /* Track parity of quotes. */
470 if (my_stringend
== 0)
472 /* If we have two kinds of string delimiters.
473 There's no way to grok this scanning backwards. */
474 else if (my_stringend
!= c
)
478 if (code
== Sstring_fence
|| code
== Scomment_fence
)
481 if (my_stringend
== 0)
483 = code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
;
484 /* If we have two kinds of string delimiters.
485 There's no way to grok this scanning backwards. */
486 else if (my_stringend
!= (code
== Sstring_fence
487 ? ST_STRING_STYLE
: ST_COMMENT_STYLE
))
491 /* Record comment-starters according to that
492 quote-parity to the comment-end. */
493 if (code
== Scomment
)
495 comstart_parity
= parity
;
497 comstart_byte
= from_byte
;
500 /* If we find another earlier comment-ender,
501 any comment-starts earlier than that don't count
502 (because they go with the earlier comment-ender). */
503 if (code
== Sendcomment
504 && SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
)) == comstyle
)
507 /* Assume a defun-start point is outside of strings. */
510 || (temp_byte
= dec_bytepos (from_byte
),
511 FETCH_CHAR (temp_byte
) == '\n')))
514 defun_start_byte
= from_byte
;
519 if (comstart_pos
== 0)
522 from_byte
= comment_end_byte
;
523 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
525 /* If the earliest comment starter
526 is followed by uniform paired string quotes or none,
527 we know it can't be inside a string
528 since if it were then the comment ender would be inside one.
529 So it does start a comment. Skip back to it. */
530 else if (comstart_parity
== 0 && !string_lossage
)
533 from_byte
= comstart_byte
;
534 /* Globals are correct now. */
538 /* We had two kinds of string delimiters mixed up
539 together. Decode this going forwards.
540 Scan fwd from the previous comment ender
541 to the one in question; this records where we
542 last passed a comment starter. */
543 struct lisp_parse_state state
;
544 /* If we did not already find the defun start, find it now. */
545 if (defun_start
== 0)
547 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
548 defun_start_byte
= find_start_value_byte
;
550 scan_sexps_forward (&state
,
551 defun_start
, defun_start_byte
,
552 comment_end
- 1, -10000, 0, Qnil
, 0);
555 /* scan_sexps_forward changed the direction of search in
556 global variables, so we need to update it completely. */
558 from
= state
.comstr_start
;
564 from_byte
= CHAR_TO_BYTE (from
);
565 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
569 *bytepos_ptr
= from_byte
;
574 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
575 "Return t if OBJECT is a syntax table.\n\
576 Currently, any char-table counts as a syntax table.")
580 if (CHAR_TABLE_P (object
)
581 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
587 check_syntax_table (obj
)
590 if (!(CHAR_TABLE_P (obj
)
591 && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
)))
592 wrong_type_argument (Qsyntax_table_p
, obj
);
595 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
596 "Return the current syntax table.\n\
597 This is the one specified by the current buffer.")
600 return current_buffer
->syntax_table
;
603 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
604 Sstandard_syntax_table
, 0, 0, 0,
605 "Return the standard syntax table.\n\
606 This is the one used for new buffers.")
609 return Vstandard_syntax_table
;
612 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
613 "Construct a new syntax table and return it.\n\
614 It is a copy of the TABLE, which defaults to the standard syntax table.")
621 check_syntax_table (table
);
623 table
= Vstandard_syntax_table
;
625 copy
= Fcopy_sequence (table
);
627 /* Only the standard syntax table should have a default element.
628 Other syntax tables should inherit from parents instead. */
629 XCHAR_TABLE (copy
)->defalt
= Qnil
;
631 /* Copied syntax tables should all have parents.
632 If we copied one with no parent, such as the standard syntax table,
633 use the standard syntax table as the copy's parent. */
634 if (NILP (XCHAR_TABLE (copy
)->parent
))
635 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
639 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
640 "Select a new syntax table for the current buffer.\n\
641 One argument, a syntax table.")
645 check_syntax_table (table
);
646 current_buffer
->syntax_table
= table
;
647 /* Indicate that this buffer now has a specified syntax table. */
648 current_buffer
->local_var_flags
649 |= XFASTINT (buffer_local_flags
.syntax_table
);
653 /* Convert a letter which signifies a syntax code
654 into the code it signifies.
655 This is used by modify-syntax-entry, and other things. */
657 unsigned char syntax_spec_code
[0400] =
658 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
659 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
660 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
661 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
662 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
663 (char) Smath
, 0377, 0377, (char) Squote
,
664 (char) Sopen
, (char) Sclose
, 0377, 0377,
665 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
666 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
667 0377, 0377, 0377, 0377,
668 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
669 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
670 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
671 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
672 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
673 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
674 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
675 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
676 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
679 /* Indexed by syntax code, give the letter that describes it. */
681 char syntax_code_spec
[16] =
683 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
687 /* Indexed by syntax code, give the object (cons of syntax code and
688 nil) to be stored in syntax table. Since these objects can be
689 shared among syntax tables, we generate them in advance. By
690 sharing objects, the function `describe-syntax' can give a more
692 static Lisp_Object Vsyntax_code_object
;
695 /* Look up the value for CHARACTER in syntax table TABLE's parent
696 and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil
697 for CHARACTER. It's actually used only when not compiled with GCC. */
700 syntax_parent_lookup (table
, character
)
708 table
= XCHAR_TABLE (table
)->parent
;
712 value
= XCHAR_TABLE (table
)->contents
[character
];
718 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
719 "Return the syntax code of CHARACTER, described by a character.\n\
720 For example, if CHARACTER is a word constituent,\n\
721 the character `w' is returned.\n\
722 The characters that correspond to various syntax codes\n\
723 are listed in the documentation of `modify-syntax-entry'.")
725 Lisp_Object character
;
728 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
730 gl_state
.use_global
= 0;
731 CHECK_NUMBER (character
, 0);
732 char_int
= XINT (character
);
733 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
736 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
737 "Return the matching parenthesis of CHARACTER, or nil if none.")
739 Lisp_Object character
;
742 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
743 gl_state
.use_global
= 0;
744 CHECK_NUMBER (character
, 0);
745 char_int
= XINT (character
);
746 code
= SYNTAX (char_int
);
747 if (code
== Sopen
|| code
== Sclose
)
748 return SYNTAX_MATCH (char_int
);
752 /* This comment supplies the doc string for modify-syntax-entry,
753 for make-docfile to see. We cannot put this in the real DEFUN
754 due to limits in the Unix cpp.
756 DEFUN ("modify-syntax-entry", foo, bar, 2, 3, 0,
757 "Set syntax for character CHAR according to string S.\n\
758 The syntax is changed only for table TABLE, which defaults to\n\
759 the current buffer's syntax table.\n\
760 The first character of S should be one of the following:\n\
761 Space or - whitespace syntax. w word constituent.\n\
762 _ symbol constituent. . punctuation.\n\
763 ( open-parenthesis. ) close-parenthesis.\n\
764 \" string quote. \\ escape.\n\
765 $ paired delimiter. ' expression quote or prefix operator.\n\
766 < comment starter. > comment ender.\n\
767 / character-quote. @ inherit from `standard-syntax-table'.\n\
769 Only single-character comment start and end sequences are represented thus.\n\
770 Two-character sequences are represented as described below.\n\
771 The second character of S is the matching parenthesis,\n\
772 used only if the first character is `(' or `)'.\n\
773 Any additional characters are flags.\n\
774 Defined flags are the characters 1, 2, 3, 4, b, and p.\n\
775 1 means CHAR is the start of a two-char comment start sequence.\n\
776 2 means CHAR is the second character of such a sequence.\n\
777 3 means CHAR is the start of a two-char comment end sequence.\n\
778 4 means CHAR is the second character of such a sequence.\n\
780 There can be up to two orthogonal comment sequences. This is to support\n\
781 language modes such as C++. By default, all comment sequences are of style\n\
782 a, but you can set the comment sequence style to b (on the second character\n\
783 of a comment-start, or the first character of a comment-end sequence) using\n\
785 b means CHAR is part of comment sequence b.\n\
787 p means CHAR is a prefix character for `backward-prefix-chars';\n\
788 such characters are treated as whitespace when they occur\n\
789 between expressions.")
793 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
794 /* I really don't know why this is interactive
795 help-form should at least be made useful whilst reading the second arg
797 "cSet syntax for character: \nsSet syntax for %s to: ",
798 0 /* See immediately above */)
799 (c
, newentry
, syntax_table
)
800 Lisp_Object c
, newentry
, syntax_table
;
802 register unsigned char *p
;
803 register enum syntaxcode code
;
808 CHECK_STRING (newentry
, 1);
810 if (NILP (syntax_table
))
811 syntax_table
= current_buffer
->syntax_table
;
813 check_syntax_table (syntax_table
);
815 p
= XSTRING (newentry
)->data
;
816 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
817 if (((int) code
& 0377) == 0377)
818 error ("invalid syntax description letter: %c", p
[-1]);
820 if (code
== Sinherit
)
822 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), Qnil
);
829 int character
= STRING_CHAR_AND_LENGTH (p
, XSTRING (newentry
)->size
- 1,
831 XSETINT (match
, character
);
832 if (XFASTINT (match
) == ' ')
868 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
869 newentry
= XVECTOR (Vsyntax_code_object
)->contents
[val
];
871 /* Since we can't use a shared object, let's make a new one. */
872 newentry
= Fcons (make_number (val
), match
);
874 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
879 /* Dump syntax table to buffer in human-readable format */
882 describe_syntax (value
)
885 register enum syntaxcode code
;
886 char desc
, match
, start1
, start2
, end1
, end2
, prefix
, comstyle
;
888 Lisp_Object first
, match_lisp
;
890 Findent_to (make_number (16), make_number (1));
894 insert_string ("default\n");
898 if (CHAR_TABLE_P (value
))
900 insert_string ("deeper char-table ...\n");
906 insert_string ("invalid\n");
910 first
= XCONS (value
)->car
;
911 match_lisp
= XCONS (value
)->cdr
;
913 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
915 insert_string ("invalid\n");
919 code
= (enum syntaxcode
) (XINT (first
) & 0377);
920 start1
= (XINT (first
) >> 16) & 1;
921 start2
= (XINT (first
) >> 17) & 1;
922 end1
= (XINT (first
) >> 18) & 1;
923 end2
= (XINT (first
) >> 19) & 1;
924 prefix
= (XINT (first
) >> 20) & 1;
925 comstyle
= (XINT (first
) >> 21) & 1;
927 if ((int) code
< 0 || (int) code
>= (int) Smax
)
929 insert_string ("invalid");
932 desc
= syntax_code_spec
[(int) code
];
934 str
[0] = desc
, str
[1] = 0;
937 if (NILP (match_lisp
))
940 insert_char (XINT (match_lisp
));
957 insert_string ("\twhich means: ");
959 switch (SWITCH_ENUM_CAST (code
))
962 insert_string ("whitespace"); break;
964 insert_string ("punctuation"); break;
966 insert_string ("word"); break;
968 insert_string ("symbol"); break;
970 insert_string ("open"); break;
972 insert_string ("close"); break;
974 insert_string ("quote"); break;
976 insert_string ("string"); break;
978 insert_string ("math"); break;
980 insert_string ("escape"); break;
982 insert_string ("charquote"); break;
984 insert_string ("comment"); break;
986 insert_string ("endcomment"); break;
988 insert_string ("invalid");
992 if (!NILP (match_lisp
))
994 insert_string (", matches ");
995 insert_char (XINT (match_lisp
));
999 insert_string (",\n\t is the first character of a comment-start sequence");
1001 insert_string (",\n\t is the second character of a comment-start sequence");
1004 insert_string (",\n\t is the first character of a comment-end sequence");
1006 insert_string (",\n\t is the second character of a comment-end sequence");
1008 insert_string (" (comment style b)");
1011 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1013 insert_string ("\n");
1017 describe_syntax_1 (vector
)
1020 struct buffer
*old
= current_buffer
;
1021 set_buffer_internal (XBUFFER (Vstandard_output
));
1022 describe_vector (vector
, Qnil
, describe_syntax
, 0, Qnil
, Qnil
, (int *) 0, 0);
1023 while (! NILP (XCHAR_TABLE (vector
)->parent
))
1025 vector
= XCHAR_TABLE (vector
)->parent
;
1026 insert_string ("\nThe parent syntax table is:");
1027 describe_vector (vector
, Qnil
, describe_syntax
, 0, Qnil
, Qnil
,
1031 call0 (intern ("help-mode"));
1032 set_buffer_internal (old
);
1036 DEFUN ("describe-syntax", Fdescribe_syntax
, Sdescribe_syntax
, 0, 0, "",
1037 "Describe the syntax specifications in the syntax table.\n\
1038 The descriptions are inserted in a buffer, which is then displayed.")
1041 internal_with_output_to_temp_buffer
1042 ("*Help*", describe_syntax_1
, current_buffer
->syntax_table
);
1047 int parse_sexp_ignore_comments
;
1049 /* Return the position across COUNT words from FROM.
1050 If that many words cannot be found before the end of the buffer, return 0.
1051 COUNT negative means scan backward and stop at word beginning. */
1053 scan_words (from
, count
)
1054 register int from
, count
;
1056 register int beg
= BEGV
;
1057 register int end
= ZV
;
1058 register int from_byte
= CHAR_TO_BYTE (from
);
1059 register enum syntaxcode code
;
1065 SETUP_SYNTAX_TABLE (from
, count
);
1076 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1077 ch0
= FETCH_CHAR (from_byte
);
1078 code
= SYNTAX (ch0
);
1079 INC_BOTH (from
, from_byte
);
1080 if (words_include_escapes
1081 && (code
== Sescape
|| code
== Scharquote
))
1086 /* Now CH0 is a character which begins a word and FROM is the
1087 position of the next character. */
1090 if (from
== end
) break;
1091 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1092 ch1
= FETCH_CHAR (from_byte
);
1093 code
= SYNTAX (ch1
);
1094 if (!(words_include_escapes
1095 && (code
== Sescape
|| code
== Scharquote
)))
1096 if (code
!= Sword
|| WORD_BOUNDARY_P (ch0
, ch1
))
1098 INC_BOTH (from
, from_byte
);
1112 DEC_BOTH (from
, from_byte
);
1113 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1114 ch1
= FETCH_CHAR (from_byte
);
1115 code
= SYNTAX (ch1
);
1116 if (words_include_escapes
1117 && (code
== Sescape
|| code
== Scharquote
))
1122 /* Now CH1 is a character which ends a word and FROM is the
1130 temp_byte
= dec_bytepos (from_byte
);
1131 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1132 ch0
= FETCH_CHAR (temp_byte
);
1133 code
= SYNTAX (ch0
);
1134 if (!(words_include_escapes
1135 && (code
== Sescape
|| code
== Scharquote
)))
1136 if (code
!= Sword
|| WORD_BOUNDARY_P (ch0
, ch1
))
1138 DEC_BOTH (from
, from_byte
);
1149 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 1, 1, "p",
1150 "Move point forward ARG words (backward if ARG is negative).\n\
1151 Normally returns t.\n\
1152 If an edge of the buffer is reached, point is left there\n\
1153 and nil is returned.")
1158 CHECK_NUMBER (count
, 0);
1160 if (!(val
= scan_words (PT
, XINT (count
))))
1162 SET_PT (XINT (count
) > 0 ? ZV
: BEGV
);
1169 Lisp_Object
skip_chars ();
1171 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1172 "Move point forward, stopping before a char not in STRING, or at pos LIM.\n\
1173 STRING is like the inside of a `[...]' in a regular expression\n\
1174 except that `]' is never special and `\\' quotes `^', `-' or `\\'.\n\
1175 Thus, with arg \"a-zA-Z\", this skips letters stopping before first nonletter.\n\
1176 With arg \"^a-zA-Z\", skips nonletters stopping before first letter.\n\
1177 Returns the distance traveled, either zero or positive.")
1179 Lisp_Object string
, lim
;
1181 return skip_chars (1, 0, string
, lim
);
1184 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1185 "Move point backward, stopping after a char not in STRING, or at pos LIM.\n\
1186 See `skip-chars-forward' for details.\n\
1187 Returns the distance traveled, either zero or negative.")
1189 Lisp_Object string
, lim
;
1191 return skip_chars (0, 0, string
, lim
);
1194 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1195 "Move point forward across chars in specified syntax classes.\n\
1196 SYNTAX is a string of syntax code characters.\n\
1197 Stop before a char whose syntax is not in SYNTAX, or at position LIM.\n\
1198 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.\n\
1199 This function returns the distance traveled, either zero or positive.")
1201 Lisp_Object syntax
, lim
;
1203 return skip_chars (1, 1, syntax
, lim
);
1206 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1207 "Move point backward across chars in specified syntax classes.\n\
1208 SYNTAX is a string of syntax code characters.\n\
1209 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.\n\
1210 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.\n\
1211 This function returns the distance traveled, either zero or negative.")
1213 Lisp_Object syntax
, lim
;
1215 return skip_chars (0, 1, syntax
, lim
);
1219 skip_chars (forwardp
, syntaxp
, string
, lim
)
1220 int forwardp
, syntaxp
;
1221 Lisp_Object string
, lim
;
1223 register unsigned char *p
, *pend
;
1224 register unsigned int c
;
1226 unsigned char fastmap
[0400];
1227 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters
1228 of which codes don't fit in FASTMAP. In that case, we set the
1229 first byte of multibyte form (i.e. base leading-code) in FASTMAP
1230 and set the actual ranges of characters in CHAR_RANGES. In the
1231 form "X-Y" of STRING, both X and Y must belong to the same
1232 character set because a range striding across character sets is
1235 int n_char_ranges
= 0;
1237 register int i
, i_byte
;
1238 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
1239 int string_multibyte
= STRING_MULTIBYTE (string
);
1241 CHECK_STRING (string
, 0);
1242 char_ranges
= (int *) alloca (XSTRING (string
)->size
* (sizeof (int)) * 2);
1245 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1247 CHECK_NUMBER_COERCE_MARKER (lim
, 0);
1249 /* In any case, don't allow scan outside bounds of buffer. */
1250 if (XINT (lim
) > ZV
)
1251 XSETFASTINT (lim
, ZV
);
1252 if (XINT (lim
) < BEGV
)
1253 XSETFASTINT (lim
, BEGV
);
1255 bzero (fastmap
, sizeof fastmap
);
1259 if (i
< XSTRING (string
)->size
1260 && XSTRING (string
)->data
[0] == '^')
1262 negate
= 1; i
++, i_byte
++;
1265 /* Find the characters specified and set their elements of fastmap.
1266 If syntaxp, each character counts as itself.
1267 Otherwise, handle backslashes and ranges specially. */
1269 while (i
< XSTRING (string
)->size
)
1273 if (string_multibyte
)
1275 c_leading_code
= XSTRING (string
)->data
[i_byte
];
1276 FETCH_STRING_CHAR_ADVANCE (c
, string
, i
, i_byte
);
1279 c
= c_leading_code
= XSTRING (string
)->data
[i
++];
1281 /* Convert multibyteness between what the string has
1282 and what the buffer has. */
1284 c
= unibyte_char_to_multibyte (c
);
1289 fastmap
[syntax_spec_code
[c
& 0377]] = 1;
1294 if (i
== XSTRING (string
)->size
)
1297 if (string_multibyte
)
1298 FETCH_STRING_CHAR_ADVANCE (c
, string
, i
, i_byte
);
1300 c
= XSTRING (string
)->data
[i
++];
1302 if (i
< XSTRING (string
)->size
&& XSTRING (string
)->data
[i
] == '-')
1306 /* Skip over the dash. */
1309 if (i
== XSTRING (string
)->size
)
1312 /* Get the end of the range. */
1313 if (string_multibyte
)
1314 FETCH_STRING_CHAR_ADVANCE (c2
, string
, i
, i_byte
);
1316 c2
= XSTRING (string
)->data
[i
++];
1318 if (SINGLE_BYTE_CHAR_P (c
))
1326 fastmap
[c_leading_code
] = 1;
1329 char_ranges
[n_char_ranges
++] = c
;
1330 char_ranges
[n_char_ranges
++] = c2
;
1336 fastmap
[c_leading_code
] = 1;
1337 if (!SINGLE_BYTE_CHAR_P (c
))
1339 char_ranges
[n_char_ranges
++] = c
;
1340 char_ranges
[n_char_ranges
++] = c
;
1346 /* If ^ was the first character, complement the fastmap. In
1347 addition, as all multibyte characters have possibility of
1348 matching, set all entries for base leading codes, which is
1349 harmless even if SYNTAXP is 1. */
1352 for (i
= 0; i
< sizeof fastmap
; i
++)
1354 if (!multibyte
|| !BASE_LEADING_CODE_P (i
))
1361 int start_point
= PT
;
1363 int pos_byte
= PT_BYTE
;
1368 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1373 if (pos
< XINT (lim
))
1374 while (fastmap
[(int) SYNTAX (FETCH_CHAR (pos_byte
))])
1376 /* Since we already checked for multibyteness,
1377 avoid using INC_BOTH which checks again. */
1380 if (pos
>= XINT (lim
))
1382 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1387 while (pos
< XINT (lim
)
1388 && fastmap
[(int) SYNTAX (FETCH_BYTE (pos
))])
1391 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1399 while (pos
> XINT (lim
))
1401 int savepos
= pos_byte
;
1402 /* Since we already checked for multibyteness,
1403 avoid using DEC_BOTH which checks again. */
1406 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
1407 if (!fastmap
[(int) SYNTAX (FETCH_CHAR (pos_byte
))])
1417 if (pos
> XINT (lim
))
1418 while (fastmap
[(int) SYNTAX (FETCH_BYTE (pos
- 1))])
1421 if (pos
<= XINT (lim
))
1423 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
1433 while (pos
< XINT (lim
) && fastmap
[(c
= FETCH_BYTE (pos_byte
))])
1435 if (!BASE_LEADING_CODE_P (c
))
1436 INC_BOTH (pos
, pos_byte
);
1437 else if (n_char_ranges
)
1439 /* We much check CHAR_RANGES for a multibyte
1441 ch
= FETCH_MULTIBYTE_CHAR (pos_byte
);
1442 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1443 if ((ch
>= char_ranges
[i
] && ch
<= char_ranges
[i
+ 1]))
1445 if (!(negate
^ (i
< n_char_ranges
)))
1448 INC_BOTH (pos
, pos_byte
);
1453 INC_BOTH (pos
, pos_byte
);
1457 while (pos
< XINT (lim
) && fastmap
[FETCH_BYTE (pos
)])
1463 while (pos
> XINT (lim
))
1465 int savepos
= pos_byte
;
1466 DEC_BOTH (pos
, pos_byte
);
1467 if (fastmap
[(c
= FETCH_BYTE (pos_byte
))])
1469 if (!BASE_LEADING_CODE_P (c
))
1471 else if (n_char_ranges
)
1473 /* We much check CHAR_RANGES for a multibyte
1475 ch
= FETCH_MULTIBYTE_CHAR (pos_byte
);
1476 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1477 if (ch
>= char_ranges
[i
] && ch
<= char_ranges
[i
+ 1])
1479 if (!(negate
^ (i
< n_char_ranges
)))
1502 while (pos
> XINT (lim
) && fastmap
[FETCH_BYTE (pos
- 1)])
1507 #if 0 /* Not needed now that a position in mid-character
1508 cannot be specified in Lisp. */
1510 /* INC_POS or DEC_POS might have moved POS over LIM. */
1511 && (forwardp
? (pos
> XINT (lim
)) : (pos
< XINT (lim
))))
1518 SET_PT_BOTH (pos
, pos_byte
);
1521 return make_number (PT
- start_point
);
1525 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
1526 "Move forward across up to N comments. If N is negative, move backward.\n\
1527 Stop scanning if we find something other than a comment or whitespace.\n\
1528 Set point to where scanning stops.\n\
1529 If N comments are found as expected, with nothing except whitespace\n\
1530 between them, return t; otherwise return nil.")
1538 register enum syntaxcode code
;
1539 int comstyle
= 0; /* style of comment encountered */
1543 int out_charpos
, out_bytepos
;
1545 CHECK_NUMBER (count
, 0);
1546 count1
= XINT (count
);
1547 stop
= count1
> 0 ? ZV
: BEGV
;
1553 from_byte
= PT_BYTE
;
1555 SETUP_SYNTAX_TABLE (from
, count1
);
1562 SET_PT_BOTH (from
, from_byte
);
1566 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1567 c
= FETCH_CHAR (from_byte
);
1569 INC_BOTH (from
, from_byte
);
1571 if (from
< stop
&& SYNTAX_COMSTART_FIRST (c
)
1572 && (c1
= FETCH_CHAR (from_byte
),
1573 SYNTAX_COMSTART_SECOND (c1
)))
1575 /* We have encountered a comment start sequence and we
1576 are ignoring all text inside comments. We must record
1577 the comment style this sequence begins so that later,
1578 only a comment end of the same style actually ends
1579 the comment section. */
1581 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
1582 INC_BOTH (from
, from_byte
);
1585 while (code
== Swhitespace
|| code
== Sendcomment
);
1587 if (code
!= Scomment
&& code
!= Scomment_fence
)
1590 DEC_BOTH (from
, from_byte
);
1591 SET_PT_BOTH (from
, from_byte
);
1594 /* We're at the start of a comment. */
1600 SET_PT_BOTH (from
, from_byte
);
1603 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1604 c
= FETCH_CHAR (from_byte
);
1605 INC_BOTH (from
, from_byte
);
1606 if (SYNTAX (c
) == Sendcomment
1607 && SYNTAX_COMMENT_STYLE (c
) == comstyle
)
1608 /* we have encountered a comment end of the same style
1609 as the comment sequence which began this comment
1612 if (SYNTAX (c
) == Scomment_fence
1613 && comstyle
== ST_COMMENT_STYLE
)
1614 /* we have encountered a comment end of the same style
1615 as the comment sequence which began this comment
1618 if (from
< stop
&& SYNTAX_COMEND_FIRST (c
)
1619 && (c1
= FETCH_CHAR (from_byte
),
1620 SYNTAX_COMEND_SECOND (c1
))
1621 && SYNTAX_COMMENT_STYLE (c
) == comstyle
)
1622 /* we have encountered a comment end of the same style
1623 as the comment sequence which began this comment
1626 INC_BOTH (from
, from_byte
);
1630 /* We have skipped one comment. */
1641 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
1646 DEC_BOTH (from
, from_byte
);
1647 quoted
= char_quoted (from
, from_byte
);
1650 DEC_BOTH (from
, from_byte
);
1653 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1654 c
= FETCH_CHAR (from_byte
);
1657 if (code
== Sendcomment
)
1658 comstyle
= SYNTAX_COMMENT_STYLE (c
);
1659 temp_pos
= dec_bytepos (from_byte
);
1660 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
1661 && (c1
= FETCH_CHAR (temp_pos
),
1662 SYNTAX_COMEND_FIRST (c1
))
1663 && !char_quoted (from
- 1, temp_pos
))
1665 /* We must record the comment style encountered so that
1666 later, we can match only the proper comment begin
1667 sequence of the same style. */
1669 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
1670 DEC_BOTH (from
, from_byte
);
1672 if (from
> stop
&& SYNTAX_COMSTART_SECOND (c
)
1673 && (c1
= FETCH_CHAR (temp_pos
),
1674 SYNTAX_COMSTART_FIRST (c1
))
1675 && !char_quoted (from
- 1, temp_pos
))
1677 /* We must record the comment style encountered so that
1678 later, we can match only the proper comment begin
1679 sequence of the same style. */
1681 DEC_BOTH (from
, from_byte
);
1684 if (code
== Scomment_fence
)
1686 /* Skip until first preceding unquoted comment_fence. */
1687 int found
= 0, ini
= from
, ini_byte
= from_byte
;
1691 DEC_BOTH (from
, from_byte
);
1694 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1695 c
= FETCH_CHAR (from_byte
);
1696 if (SYNTAX (c
) == Scomment_fence
1697 && !char_quoted (from
, from_byte
))
1705 from
= ini
; /* Set point to ini + 1. */
1706 from_byte
= ini_byte
;
1710 else if (code
== Sendcomment
)
1712 found
= back_comment (from
, from_byte
, stop
, comstyle
,
1713 &out_charpos
, &out_bytepos
);
1715 from
= out_charpos
, from_byte
= out_bytepos
;
1716 /* We have skipped one comment. */
1719 else if (code
!= Swhitespace
&& code
!= Scomment
)
1723 INC_BOTH (from
, from_byte
);
1724 SET_PT_BOTH (from
, from_byte
);
1732 SET_PT_BOTH (from
, from_byte
);
1738 scan_lists (from
, count
, depth
, sexpflag
)
1740 int count
, depth
, sexpflag
;
1743 register int stop
= count
> 0 ? ZV
: BEGV
;
1748 register enum syntaxcode code
, temp_code
;
1749 int min_depth
= depth
; /* Err out if depth gets less than this. */
1750 int comstyle
= 0; /* style of comment encountered */
1752 int last_good
= from
;
1754 int from_byte
= CHAR_TO_BYTE (from
);
1755 int out_bytepos
, out_charpos
;
1757 if (depth
> 0) min_depth
= 0;
1762 SETUP_SYNTAX_TABLE (from
, count
);
1767 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1768 c
= FETCH_CHAR (from_byte
);
1770 if (depth
== min_depth
)
1772 INC_BOTH (from
, from_byte
);
1773 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1774 if (from
< stop
&& SYNTAX_COMSTART_FIRST (c
)
1775 && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from_byte
))
1776 && parse_sexp_ignore_comments
)
1778 /* we have encountered a comment start sequence and we
1779 are ignoring all text inside comments. We must record
1780 the comment style this sequence begins so that later,
1781 only a comment end of the same style actually ends
1782 the comment section */
1784 comstyle
= SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
));
1785 INC_BOTH (from
, from_byte
);
1788 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1789 if (SYNTAX_PREFIX (c
))
1792 switch (SWITCH_ENUM_CAST (code
))
1796 if (from
== stop
) goto lose
;
1797 INC_BOTH (from
, from_byte
);
1798 /* treat following character as a word constituent */
1801 if (depth
|| !sexpflag
) break;
1802 /* This word counts as a sexp; return at end of it. */
1805 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1806 switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte
))))
1810 INC_BOTH (from
, from_byte
);
1811 if (from
== stop
) goto lose
;
1820 INC_BOTH (from
, from_byte
);
1825 case Scomment_fence
:
1826 if (!parse_sexp_ignore_comments
) break;
1835 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1836 c
= FETCH_CHAR (from_byte
);
1837 if (code
== Scomment
1838 ? (SYNTAX (c
) == Sendcomment
1839 && SYNTAX_COMMENT_STYLE (c
) == comstyle
)
1840 : (SYNTAX (c
) == Scomment_fence
))
1841 /* we have encountered a comment end of the same style
1842 as the comment sequence which began this comment
1845 INC_BOTH (from
, from_byte
);
1846 if (from
< stop
&& SYNTAX_COMEND_FIRST (c
)
1847 && SYNTAX_COMEND_SECOND (FETCH_CHAR (from_byte
))
1848 && SYNTAX_COMMENT_STYLE (c
) == comstyle
1849 && code
== Scomment
)
1850 /* we have encountered a comment end of the same style
1851 as the comment sequence which began this comment
1854 INC_BOTH (from
, from_byte
);
1863 if (from
!= stop
&& c
== FETCH_CHAR (from_byte
))
1865 INC_BOTH (from
, from_byte
);
1875 if (!++depth
) goto done
;
1880 if (!--depth
) goto done
;
1881 if (depth
< min_depth
)
1882 Fsignal (Qscan_error
,
1883 Fcons (build_string ("Containing expression ends prematurely"),
1884 Fcons (make_number (last_good
),
1885 Fcons (make_number (from
), Qnil
))));
1890 temp_pos
= dec_bytepos (from_byte
);
1891 stringterm
= FETCH_CHAR (temp_pos
);
1894 if (from
>= stop
) goto lose
;
1895 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1897 ? (FETCH_CHAR (from_byte
) == stringterm
)
1898 : SYNTAX (FETCH_CHAR (from_byte
)) == Sstring_fence
)
1900 switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte
))))
1904 INC_BOTH (from
, from_byte
);
1906 INC_BOTH (from
, from_byte
);
1908 INC_BOTH (from
, from_byte
);
1909 if (!depth
&& sexpflag
) goto done
;
1914 /* Reached end of buffer. Error if within object, return nil if between */
1915 if (depth
) goto lose
;
1920 /* End of object reached */
1929 DEC_BOTH (from
, from_byte
);
1930 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1931 c
= FETCH_CHAR (from_byte
);
1933 if (depth
== min_depth
)
1936 if (code
== Sendcomment
)
1937 comstyle
= SYNTAX_COMMENT_STYLE (c
);
1938 temp_pos
= from_byte
;
1939 if (! NILP (current_buffer
->enable_multibyte_characters
))
1943 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
1944 && (c1
= FETCH_CHAR (temp_pos
), SYNTAX_COMEND_FIRST (c1
))
1945 && parse_sexp_ignore_comments
)
1947 /* we must record the comment style encountered so that
1948 later, we can match only the proper comment begin
1949 sequence of the same style */
1951 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
1952 DEC_BOTH (from
, from_byte
);
1955 /* Quoting turns anything except a comment-ender
1956 into a word character. */
1957 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
1959 else if (SYNTAX_PREFIX (c
))
1962 switch (SWITCH_ENUM_CAST (code
))
1968 if (depth
|| !sexpflag
) break;
1969 /* This word counts as a sexp; count object finished
1970 after passing it. */
1973 temp_pos
= from_byte
;
1974 if (! NILP (current_buffer
->enable_multibyte_characters
))
1978 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
1979 c1
= FETCH_CHAR (temp_pos
);
1980 temp_code
= SYNTAX (c1
);
1981 /* Don't allow comment-end to be quoted. */
1982 if (temp_code
== Sendcomment
)
1984 quoted
= char_quoted (from
- 1, temp_pos
);
1987 DEC_BOTH (from
, from_byte
);
1988 temp_pos
= dec_bytepos (temp_pos
);
1989 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
1991 c1
= FETCH_CHAR (temp_pos
);
1992 temp_code
= SYNTAX (c1
);
1993 if (! (quoted
|| temp_code
== Sword
1994 || temp_code
== Ssymbol
1995 || temp_code
== Squote
))
1997 DEC_BOTH (from
, from_byte
);
2004 temp_pos
= dec_bytepos (from_byte
);
2005 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2006 if (from
!= stop
&& c
== FETCH_CHAR (temp_pos
))
2007 DEC_BOTH (from
, from_byte
);
2016 if (!++depth
) goto done2
;
2021 if (!--depth
) goto done2
;
2022 if (depth
< min_depth
)
2023 Fsignal (Qscan_error
,
2024 Fcons (build_string ("Containing expression ends prematurely"),
2025 Fcons (make_number (last_good
),
2026 Fcons (make_number (from
), Qnil
))));
2030 if (!parse_sexp_ignore_comments
)
2032 found
= back_comment (from
, from_byte
, stop
, comstyle
,
2033 &out_charpos
, &out_bytepos
);
2035 from
= out_charpos
, from_byte
= out_bytepos
;
2038 case Scomment_fence
:
2042 DEC_BOTH (from
, from_byte
);
2043 if (from
== stop
) goto lose
;
2044 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2045 if (!char_quoted (from
, from_byte
)
2046 && SYNTAX (FETCH_CHAR (from_byte
)) == code
)
2049 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2053 stringterm
= FETCH_CHAR (from_byte
);
2056 if (from
== stop
) goto lose
;
2057 temp_pos
= from_byte
;
2058 if (! NILP (current_buffer
->enable_multibyte_characters
))
2062 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2063 if (!char_quoted (from
- 1, temp_pos
)
2064 && stringterm
== FETCH_CHAR (temp_pos
))
2066 DEC_BOTH (from
, from_byte
);
2068 DEC_BOTH (from
, from_byte
);
2069 if (!depth
&& sexpflag
) goto done2
;
2074 /* Reached start of buffer. Error if within object, return nil if between */
2075 if (depth
) goto lose
;
2086 XSETFASTINT (val
, from
);
2090 Fsignal (Qscan_error
,
2091 Fcons (build_string ("Unbalanced parentheses"),
2092 Fcons (make_number (last_good
),
2093 Fcons (make_number (from
), Qnil
))));
2098 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2099 "Scan from character number FROM by COUNT lists.\n\
2100 Returns the character number of the position thus found.\n\
2102 If DEPTH is nonzero, paren depth begins counting from that value,\n\
2103 only places where the depth in parentheses becomes zero\n\
2104 are candidates for stopping; COUNT such places are counted.\n\
2105 Thus, a positive value for DEPTH means go out levels.\n\
2107 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.\n\
2109 If the beginning or end of (the accessible part of) the buffer is reached\n\
2110 and the depth is wrong, an error is signaled.\n\
2111 If the depth is right but the count is not used up, nil is returned.")
2112 (from
, count
, depth
)
2113 Lisp_Object from
, count
, depth
;
2115 CHECK_NUMBER (from
, 0);
2116 CHECK_NUMBER (count
, 1);
2117 CHECK_NUMBER (depth
, 2);
2119 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2122 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2123 "Scan from character number FROM by COUNT balanced expressions.\n\
2124 If COUNT is negative, scan backwards.\n\
2125 Returns the character number of the position thus found.\n\
2127 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.\n\
2129 If the beginning or end of (the accessible part of) the buffer is reached\n\
2130 in the middle of a parenthetical grouping, an error is signaled.\n\
2131 If the beginning or end is reached between groupings\n\
2132 but before count is used up, nil is returned.")
2134 Lisp_Object from
, count
;
2136 CHECK_NUMBER (from
, 0);
2137 CHECK_NUMBER (count
, 1);
2139 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2142 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2144 "Move point backward over any number of chars with prefix syntax.\n\
2145 This includes chars with \"quote\" or \"prefix\" syntax (' or p).")
2150 int opoint_byte
= PT_BYTE
;
2152 int pos_byte
= PT_BYTE
;
2157 SETUP_SYNTAX_TABLE (pos
, -1);
2160 DEC_BOTH (pos
, pos_byte
);
2162 while (pos
+ 1 > beg
&& !char_quoted (pos
, pos_byte
)
2163 /* Previous statement updates syntax table. */
2164 && ((c
= FETCH_CHAR (pos_byte
), SYNTAX (c
) == Squote
)
2165 || SYNTAX_PREFIX (c
)))
2167 DEC_BOTH (pos
, pos_byte
);
2170 SET_PT_BOTH (opoint
, opoint_byte
);
2175 /* Parse forward from FROM / FROM_BYTE to END,
2176 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2177 and return a description of the state of the parse at END.
2178 If STOPBEFORE is nonzero, stop at the start of an atom.
2179 If COMMENTSTOP is 1, stop at the start of a comment.
2180 If COMMENTSTOP is -1, stop at the start or end of a comment,
2181 after the beginning of a string, or after the end of a string. */
2184 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2185 stopbefore
, oldstate
, commentstop
)
2186 struct lisp_parse_state
*stateptr
;
2188 int end
, targetdepth
, stopbefore
;
2189 Lisp_Object oldstate
;
2192 struct lisp_parse_state state
;
2194 register enum syntaxcode code
;
2195 struct level
{ int last
, prev
; };
2196 struct level levelstart
[100];
2197 register struct level
*curlevel
= levelstart
;
2198 struct level
*endlevel
= levelstart
+ 100;
2200 register int depth
; /* Paren depth of current scanning location.
2201 level - levelstart equals this except
2202 when the depth becomes negative. */
2203 int mindepth
; /* Lowest DEPTH value seen. */
2204 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2206 int prev_from
; /* Keep one character before FROM. */
2208 int boundary_stop
= commentstop
== -1;
2212 prev_from_byte
= from_byte
;
2214 DEC_BOTH (prev_from
, prev_from_byte
);
2216 /* Use this macro instead of `from++'. */
2218 do { prev_from = from; \
2219 prev_from_byte = from_byte; \
2220 INC_BOTH (from, from_byte); \
2226 SETUP_SYNTAX_TABLE (from
, 1);
2228 if (NILP (oldstate
))
2231 state
.instring
= -1;
2232 state
.incomment
= 0;
2233 state
.comstyle
= 0; /* comment style a by default. */
2234 state
.comstr_start
= -1; /* no comment/string seen. */
2238 tem
= Fcar (oldstate
);
2244 oldstate
= Fcdr (oldstate
);
2245 oldstate
= Fcdr (oldstate
);
2246 oldstate
= Fcdr (oldstate
);
2247 tem
= Fcar (oldstate
);
2248 /* Check whether we are inside string_fence-style string: */
2249 state
.instring
= ( !NILP (tem
)
2250 ? ( INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2253 oldstate
= Fcdr (oldstate
);
2254 tem
= Fcar (oldstate
);
2255 state
.incomment
= !NILP (tem
);
2257 oldstate
= Fcdr (oldstate
);
2258 tem
= Fcar (oldstate
);
2259 start_quoted
= !NILP (tem
);
2261 /* if the eight element of the list is nil, we are in comment
2262 style a. If it is non-nil, we are in comment style b */
2263 oldstate
= Fcdr (oldstate
);
2264 oldstate
= Fcdr (oldstate
);
2265 tem
= Fcar (oldstate
);
2266 state
.comstyle
= NILP (tem
) ? 0 : ( EQ (tem
, Qsyntax_table
)
2267 ? ST_COMMENT_STYLE
: 1 );
2269 oldstate
= Fcdr (oldstate
);
2270 tem
= Fcar (oldstate
);
2271 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2276 curlevel
->prev
= -1;
2277 curlevel
->last
= -1;
2279 /* Enter the loop at a place appropriate for initial state. */
2281 if (state
.incomment
) goto startincomment
;
2282 if (state
.instring
>= 0)
2284 nofence
= state
.instring
!= ST_STRING_STYLE
;
2285 if (start_quoted
) goto startquotedinstring
;
2288 if (start_quoted
) goto startquoted
;
2292 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2293 code
= SYNTAX (FETCH_CHAR (from_byte
));
2296 if (code
== Scomment
)
2297 state
.comstr_start
= prev_from
;
2298 else if (code
== Scomment_fence
)
2300 /* Record the comment style we have entered so that only
2301 the comment-end sequence of the same style actually
2302 terminates the comment section. */
2303 state
.comstyle
= ( code
== Scomment_fence
2305 : SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
)));
2306 state
.comstr_start
= prev_from
;
2307 if (code
!= Scomment_fence
) INC_FROM
;
2310 else if (from
< end
)
2311 if (SYNTAX_COMSTART_FIRST (FETCH_CHAR (prev_from_byte
)))
2312 if (SYNTAX_COMSTART_SECOND (FETCH_CHAR (from_byte
)))
2313 /* Duplicate code to avoid a very complex if-expression
2314 which causes trouble for the SGI compiler. */
2316 /* Record the comment style we have entered so that only
2317 the comment-end sequence of the same style actually
2318 terminates the comment section. */
2319 state
.comstyle
= ( code
== Scomment_fence
2321 : SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
)));
2322 state
.comstr_start
= prev_from
;
2323 if (code
!= Scomment_fence
) INC_FROM
;
2327 if (SYNTAX_PREFIX (FETCH_CHAR (prev_from_byte
)))
2329 switch (SWITCH_ENUM_CAST (code
))
2333 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2334 curlevel
->last
= prev_from
;
2336 if (from
== end
) goto endquoted
;
2339 /* treat following character as a word constituent */
2342 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2343 curlevel
->last
= prev_from
;
2347 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2348 switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte
))))
2353 if (from
== end
) goto endquoted
;
2365 curlevel
->prev
= curlevel
->last
;
2369 if (commentstop
== 1)
2373 /* Enter the loop in the middle so that we find
2374 a 2-char comment ender if we start in the middle of it. */
2375 prev
= FETCH_CHAR (prev_from_byte
);
2376 goto startincomment_1
;
2378 /* At beginning of buffer, enter the loop the ordinary way. */
2379 state
.incomment
= 1;
2383 state
.incomment
= 1;
2384 if (commentstop
|| boundary_stop
) goto done
;
2388 if (from
== end
) goto done
;
2389 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2390 prev
= FETCH_CHAR (from_byte
);
2391 if (SYNTAX (prev
) == Sendcomment
2392 && SYNTAX_COMMENT_STYLE (prev
) == state
.comstyle
)
2393 /* Only terminate the comment section if the endcomment
2394 of the same style as the start sequence has been
2397 if (state
.comstyle
== ST_COMMENT_STYLE
2398 && SYNTAX (prev
) == Scomment_fence
)
2402 if (from
< end
&& SYNTAX_COMEND_FIRST (prev
)
2403 && SYNTAX_COMEND_SECOND (FETCH_CHAR (from_byte
))
2404 && SYNTAX_COMMENT_STYLE (prev
) == state
.comstyle
)
2405 /* Only terminate the comment section if the end-comment
2406 sequence of the same style as the start sequence has
2407 been encountered. */
2411 state
.incomment
= 0;
2412 state
.comstyle
= 0; /* reset the comment style */
2413 if (boundary_stop
) goto done
;
2417 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2419 /* curlevel++->last ran into compiler bug on Apollo */
2420 curlevel
->last
= prev_from
;
2421 if (++curlevel
== endlevel
)
2422 error ("Nesting too deep for parser");
2423 curlevel
->prev
= -1;
2424 curlevel
->last
= -1;
2425 if (targetdepth
== depth
) goto done
;
2430 if (depth
< mindepth
)
2432 if (curlevel
!= levelstart
)
2434 curlevel
->prev
= curlevel
->last
;
2435 if (targetdepth
== depth
) goto done
;
2440 state
.comstr_start
= from
- 1;
2441 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2442 curlevel
->last
= prev_from
;
2443 state
.instring
= (code
== Sstring
2444 ? (FETCH_CHAR (prev_from_byte
))
2446 if (boundary_stop
) goto done
;
2449 nofence
= state
.instring
!= ST_STRING_STYLE
;
2455 if (from
>= end
) goto done
;
2456 c
= FETCH_CHAR (from_byte
);
2457 if (nofence
&& c
== state
.instring
) break;
2458 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2459 switch (SWITCH_ENUM_CAST (SYNTAX (c
)))
2462 if (!nofence
) goto string_end
;
2467 startquotedinstring
:
2468 if (from
>= end
) goto endquoted
;
2474 state
.instring
= -1;
2475 curlevel
->prev
= curlevel
->last
;
2477 if (boundary_stop
) goto done
;
2486 stop
: /* Here if stopping before start of sexp. */
2487 from
= prev_from
; /* We have just fetched the char that starts it; */
2488 goto done
; /* but return the position before it. */
2493 state
.depth
= depth
;
2494 state
.mindepth
= mindepth
;
2495 state
.thislevelstart
= curlevel
->prev
;
2496 state
.prevlevelstart
2497 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
2498 state
.location
= from
;
2504 /* This comment supplies the doc string for parse-partial-sexp,
2505 for make-docfile to see. We cannot put this in the real DEFUN
2506 due to limits in the Unix cpp.
2508 DEFUN ("parse-partial-sexp", Ffoo, Sfoo, 2, 6, 0,
2509 "Parse Lisp syntax starting at FROM until TO; return status of parse at TO.\n\
2510 Parsing stops at TO or when certain criteria are met;\n\
2511 point is set to where parsing stops.\n\
2512 If fifth arg STATE is omitted or nil,\n\
2513 parsing assumes that FROM is the beginning of a function.\n\
2514 Value is a list of nine elements describing final state of parsing:\n\
2515 0. depth in parens.\n\
2516 1. character address of start of innermost containing list; nil if none.\n\
2517 2. character address of start of last complete sexp terminated.\n\
2518 3. non-nil if inside a string.\n\
2519 (it is the character that will terminate the string,\n\
2520 or t if the string should be terminated by a generic string delimiter.)\n\
2521 4. t if inside a comment.\n\
2522 5. t if following a quote character.\n\
2523 6. the minimum paren-depth encountered during this scan.\n\
2524 7. t if in a comment of style b; `syntax-table' if the comment\n\
2525 should be terminated by a generic comment delimiter.\n\
2526 8. character address of start of comment or string; nil if not in one.\n\
2527 If third arg TARGETDEPTH is non-nil, parsing stops if the depth\n\
2528 in parentheses becomes equal to TARGETDEPTH.\n\
2529 Fourth arg STOPBEFORE non-nil means stop when come to\n\
2530 any character that starts a sexp.\n\
2531 Fifth arg STATE is a nine-element list like what this function returns.\n\
2532 It is used to initialize the state of the parse. Elements number 1, 2, 6\n\
2533 and 8 are ignored; you can leave off element 8 (the last) entirely.\n\
2534 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.\n\
2535 If it is `syntax-table', stop after the start of a comment or a string,\n\
2536 or after end of a comment or a string.")
2537 (from, to, targetdepth, stopbefore, state, commentstop)
2540 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
2541 0 /* See immediately above */)
2542 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
2543 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
2545 struct lisp_parse_state state
;
2548 if (!NILP (targetdepth
))
2550 CHECK_NUMBER (targetdepth
, 3);
2551 target
= XINT (targetdepth
);
2554 target
= -100000; /* We won't reach this depth */
2556 validate_region (&from
, &to
);
2557 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
2559 target
, !NILP (stopbefore
), oldstate
,
2561 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
2563 SET_PT (state
.location
);
2565 return Fcons (make_number (state
.depth
),
2566 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
2567 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
2568 Fcons (state
.instring
>= 0
2569 ? (state
.instring
== ST_STRING_STYLE
2570 ? Qt
: make_number (state
.instring
)) : Qnil
,
2571 Fcons (state
.incomment
? Qt
: Qnil
,
2572 Fcons (state
.quoted
? Qt
: Qnil
,
2573 Fcons (make_number (state
.mindepth
),
2574 Fcons ((state
.comstyle
2575 ? (state
.comstyle
== ST_COMMENT_STYLE
2576 ? Qsyntax_table
: Qt
) :
2578 Fcons ((state
.incomment
|| state
.instring
2579 ? make_number (state
.comstr_start
)
2589 /* This has to be done here, before we call Fmake_char_table. */
2590 Qsyntax_table
= intern ("syntax-table");
2591 staticpro (&Qsyntax_table
);
2593 /* Intern this now in case it isn't already done.
2594 Setting this variable twice is harmless.
2595 But don't staticpro it here--that is done in alloc.c. */
2596 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
2598 /* Create objects which can be shared among syntax tables. */
2599 Vsyntax_code_object
= Fmake_vector (make_number (13), Qnil
);
2600 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
2601 XVECTOR (Vsyntax_code_object
)->contents
[i
]
2602 = Fcons (make_number (i
), Qnil
);
2604 /* Now we are ready to set up this property, so we can
2605 create syntax tables. */
2606 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
2608 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
2610 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
2612 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
2613 for (i
= 'a'; i
<= 'z'; i
++)
2614 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
2615 for (i
= 'A'; i
<= 'Z'; i
++)
2616 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
2617 for (i
= '0'; i
<= '9'; i
++)
2618 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
2620 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
2621 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
2623 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
2624 Fcons (make_number (Sopen
), make_number (')')));
2625 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
2626 Fcons (make_number (Sclose
), make_number ('(')));
2627 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
2628 Fcons (make_number (Sopen
), make_number (']')));
2629 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
2630 Fcons (make_number (Sclose
), make_number ('[')));
2631 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
2632 Fcons (make_number (Sopen
), make_number ('}')));
2633 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
2634 Fcons (make_number (Sclose
), make_number ('{')));
2635 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
2636 Fcons (make_number ((int) Sstring
), Qnil
));
2637 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
2638 Fcons (make_number ((int) Sescape
), Qnil
));
2640 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
2641 for (i
= 0; i
< 10; i
++)
2643 c
= "_-+*/&|<>="[i
];
2644 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
2647 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
2648 for (i
= 0; i
< 12; i
++)
2650 c
= ".,;:?!#@~^'`"[i
];
2651 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
2657 Qsyntax_table_p
= intern ("syntax-table-p");
2658 staticpro (&Qsyntax_table_p
);
2660 staticpro (&Vsyntax_code_object
);
2662 Qscan_error
= intern ("scan-error");
2663 staticpro (&Qscan_error
);
2664 Fput (Qscan_error
, Qerror_conditions
,
2665 Fcons (Qerror
, Qnil
));
2666 Fput (Qscan_error
, Qerror_message
,
2667 build_string ("Scan error"));
2669 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
2670 "Non-nil means `forward-sexp', etc., should treat comments as whitespace.");
2672 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
2673 "Non-nil means `forward-sexp', etc., grant `syntax-table' property.\n\
2674 The value of this property should be either a syntax table, or a cons\n\
2675 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric\n\
2676 syntax code, MATCHCHAR being nil or the character to match (which is\n\
2677 relevant only for open/close type.");
2679 words_include_escapes
= 0;
2680 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
2681 "Non-nil means `forward-word', etc., should treat escape chars part of words.");
2683 defsubr (&Ssyntax_table_p
);
2684 defsubr (&Ssyntax_table
);
2685 defsubr (&Sstandard_syntax_table
);
2686 defsubr (&Scopy_syntax_table
);
2687 defsubr (&Sset_syntax_table
);
2688 defsubr (&Schar_syntax
);
2689 defsubr (&Smatching_paren
);
2690 defsubr (&Smodify_syntax_entry
);
2691 defsubr (&Sdescribe_syntax
);
2693 defsubr (&Sforward_word
);
2695 defsubr (&Sskip_chars_forward
);
2696 defsubr (&Sskip_chars_backward
);
2697 defsubr (&Sskip_syntax_forward
);
2698 defsubr (&Sskip_syntax_backward
);
2700 defsubr (&Sforward_comment
);
2701 defsubr (&Sscan_lists
);
2702 defsubr (&Sscan_sexps
);
2703 defsubr (&Sbackward_prefix_chars
);
2704 defsubr (&Sparse_partial_sexp
);