1 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
2 Copyright (C) 1985, 87, 93, 94, 95, 97, 1998, 1999, 2004 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., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
27 #include "character.h"
31 /* Make syntax table lookup grant data in gl_state. */
32 #define SYNTAX_ENTRY_VIA_PROPERTY
35 #include "intervals.h"
37 /* We use these constants in place for comment-style and
38 string-ender-char to distinguish comments/strings started by
39 comment_fence and string_fence codes. */
41 #define ST_COMMENT_STYLE (256 + 1)
42 #define ST_STRING_STYLE (256 + 2)
45 Lisp_Object Qsyntax_table_p
, Qsyntax_table
, Qscan_error
;
47 int words_include_escapes
;
48 int parse_sexp_lookup_properties
;
50 /* Nonzero means `scan-sexps' treat all multibyte characters as symbol. */
51 int multibyte_syntax_as_symbol
;
53 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
54 if not compiled with GCC. No need to mark it, since it is used
55 only very temporarily. */
56 Lisp_Object syntax_temp
;
58 /* Non-zero means an open parenthesis in column 0 is always considered
59 to be the start of a defun. Zero means an open parenthesis in
60 column 0 has no special meaning. */
62 int open_paren_in_column_0_is_defun_start
;
64 /* This is the internal form of the parse state used in parse-partial-sexp. */
66 struct lisp_parse_state
68 int depth
; /* Depth at end of parsing. */
69 int instring
; /* -1 if not within string, else desired terminator. */
70 int incomment
; /* -1 if in unnestable comment else comment nesting */
71 int comstyle
; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
72 int quoted
; /* Nonzero if just after an escape char at end of parsing */
73 int thislevelstart
; /* Char number of most recent start-of-expression at current level */
74 int prevlevelstart
; /* Char number of start of containing expression */
75 int location
; /* Char number at which parsing stopped. */
76 int mindepth
; /* Minimum depth seen while scanning. */
77 int comstr_start
; /* Position just after last comment/string starter. */
78 Lisp_Object levelstarts
; /* Char numbers of starts-of-expression
79 of levels (starting from outermost). */
82 /* These variables are a cache for finding the start of a defun.
83 find_start_pos is the place for which the defun start was found.
84 find_start_value is the defun start position found for it.
85 find_start_value_byte is the corresponding byte position.
86 find_start_buffer is the buffer it was found in.
87 find_start_begv is the BEGV value when it was found.
88 find_start_modiff is the value of MODIFF when it was found. */
90 static int find_start_pos
;
91 static int find_start_value
;
92 static int find_start_value_byte
;
93 static struct buffer
*find_start_buffer
;
94 static int find_start_begv
;
95 static int find_start_modiff
;
98 static int find_defun_start
P_ ((int, int));
99 static int back_comment
P_ ((int, int, int, int, int, int *, int *));
100 static int char_quoted
P_ ((int, int));
101 static Lisp_Object skip_chars
P_ ((int, Lisp_Object
, Lisp_Object
, int));
102 static Lisp_Object skip_syntaxes
P_ ((int, Lisp_Object
, Lisp_Object
));
103 static Lisp_Object scan_lists
P_ ((int, int, int, int));
104 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
106 int, Lisp_Object
, int));
107 static int in_classes
P_ ((int, Lisp_Object
));
110 struct gl_state_s gl_state
; /* Global state of syntax parser. */
112 INTERVAL
interval_of ();
113 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
114 to scan to property-change. */
116 /* Update gl_state to an appropriate interval which contains CHARPOS. The
117 sign of COUNT give the relative position of CHARPOS wrt the previously
118 valid interval. If INIT, only [be]_property fields of gl_state are
119 valid at start, the rest is filled basing on OBJECT.
121 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
122 direction than the intervals - or in an interval. We update the
123 current syntax-table basing on the property of this interval, and
124 update the interval to start further than CHARPOS - or be
125 NULL_INTERVAL. We also update lim_property to be the next value of
126 charpos to call this subroutine again - or be before/after the
127 start/end of OBJECT. */
130 update_syntax_table (charpos
, count
, init
, object
)
131 int charpos
, count
, init
;
134 Lisp_Object tmp_table
;
135 int cnt
= 0, invalidate
= 1;
140 gl_state
.old_prop
= Qnil
;
141 gl_state
.start
= gl_state
.b_property
;
142 gl_state
.stop
= gl_state
.e_property
;
143 i
= interval_of (charpos
, object
);
144 gl_state
.backward_i
= gl_state
.forward_i
= i
;
146 if (NULL_INTERVAL_P (i
))
148 /* interval_of updates only ->position of the return value, so
149 update the parents manually to speed up update_interval. */
150 while (!NULL_PARENT (i
))
152 if (AM_RIGHT_CHILD (i
))
153 INTERVAL_PARENT (i
)->position
= i
->position
154 - LEFT_TOTAL_LENGTH (i
) + TOTAL_LENGTH (i
) /* right end */
155 - TOTAL_LENGTH (INTERVAL_PARENT (i
))
156 + LEFT_TOTAL_LENGTH (INTERVAL_PARENT (i
));
158 INTERVAL_PARENT (i
)->position
= i
->position
- LEFT_TOTAL_LENGTH (i
)
160 i
= INTERVAL_PARENT (i
);
162 i
= gl_state
.forward_i
;
163 gl_state
.b_property
= i
->position
- gl_state
.offset
;
164 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
167 oldi
= i
= count
> 0 ? gl_state
.forward_i
: gl_state
.backward_i
;
169 /* We are guaranteed to be called with CHARPOS either in i,
171 if (NULL_INTERVAL_P (i
))
172 error ("Error in syntax_table logic for to-the-end intervals");
173 else if (charpos
< i
->position
) /* Move left. */
176 error ("Error in syntax_table logic for intervals <-");
177 /* Update the interval. */
178 i
= update_interval (i
, charpos
);
179 if (INTERVAL_LAST_POS (i
) != gl_state
.b_property
)
182 gl_state
.forward_i
= i
;
183 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
186 else if (charpos
>= INTERVAL_LAST_POS (i
)) /* Move right. */
189 error ("Error in syntax_table logic for intervals ->");
190 /* Update the interval. */
191 i
= update_interval (i
, charpos
);
192 if (i
->position
!= gl_state
.e_property
)
195 gl_state
.backward_i
= i
;
196 gl_state
.b_property
= i
->position
- gl_state
.offset
;
201 tmp_table
= textget (i
->plist
, Qsyntax_table
);
204 invalidate
= !EQ (tmp_table
, gl_state
.old_prop
); /* Need to invalidate? */
206 if (invalidate
) /* Did not get to adjacent interval. */
207 { /* with the same table => */
208 /* invalidate the old range. */
211 gl_state
.backward_i
= i
;
212 gl_state
.b_property
= i
->position
- gl_state
.offset
;
216 gl_state
.forward_i
= i
;
217 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
221 if (!EQ (tmp_table
, gl_state
.old_prop
))
223 gl_state
.current_syntax_table
= tmp_table
;
224 gl_state
.old_prop
= tmp_table
;
225 if (EQ (Fsyntax_table_p (tmp_table
), Qt
))
227 gl_state
.use_global
= 0;
229 else if (CONSP (tmp_table
))
231 gl_state
.use_global
= 1;
232 gl_state
.global_code
= tmp_table
;
236 gl_state
.use_global
= 0;
237 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
241 while (!NULL_INTERVAL_P (i
))
243 if (cnt
&& !EQ (tmp_table
, textget (i
->plist
, Qsyntax_table
)))
247 gl_state
.e_property
= i
->position
- gl_state
.offset
;
248 gl_state
.forward_i
= i
;
252 gl_state
.b_property
= i
->position
+ LENGTH (i
) - gl_state
.offset
;
253 gl_state
.backward_i
= i
;
257 else if (cnt
== INTERVALS_AT_ONCE
)
261 gl_state
.e_property
= i
->position
+ LENGTH (i
) - gl_state
.offset
;
262 gl_state
.forward_i
= i
;
266 gl_state
.b_property
= i
->position
- gl_state
.offset
;
267 gl_state
.backward_i
= i
;
272 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
274 eassert (NULL_INTERVAL_P (i
)); /* This property goes to the end. */
276 gl_state
.e_property
= gl_state
.stop
;
278 gl_state
.b_property
= gl_state
.start
;
281 /* Returns TRUE if char at CHARPOS is quoted.
282 Global syntax-table data should be set up already to be good at CHARPOS
283 or after. On return global syntax data is good for lookup at CHARPOS. */
286 char_quoted (charpos
, bytepos
)
287 register int charpos
, bytepos
;
289 register enum syntaxcode code
;
290 register int beg
= BEGV
;
291 register int quoted
= 0;
294 DEC_BOTH (charpos
, bytepos
);
296 while (charpos
>= beg
)
300 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
301 c
= FETCH_CHAR_AS_MULTIBYTE (bytepos
);
303 if (! (code
== Scharquote
|| code
== Sescape
))
306 DEC_BOTH (charpos
, bytepos
);
310 UPDATE_SYNTAX_TABLE (orig
);
314 /* Return the bytepos one character after BYTEPOS.
315 We assume that BYTEPOS is not at the end of the buffer. */
318 inc_bytepos (bytepos
)
321 if (NILP (current_buffer
->enable_multibyte_characters
))
328 /* Return the bytepos one character before BYTEPOS.
329 We assume that BYTEPOS is not at the start of the buffer. */
332 dec_bytepos (bytepos
)
335 if (NILP (current_buffer
->enable_multibyte_characters
))
342 /* Return a defun-start position before before POS and not too far before.
343 It should be the last one before POS, or nearly the last.
345 When open_paren_in_column_0_is_defun_start is nonzero,
346 only the beginning of the buffer is treated as a defun-start.
348 We record the information about where the scan started
349 and what its result was, so that another call in the same area
350 can return the same value very quickly.
352 There is no promise at which position the global syntax data is
353 valid on return from the subroutine, so the caller should explicitly
354 update the global data. */
357 find_defun_start (pos
, pos_byte
)
360 int opoint
= PT
, opoint_byte
= PT_BYTE
;
362 if (!open_paren_in_column_0_is_defun_start
)
364 find_start_value_byte
= BEGV_BYTE
;
368 /* Use previous finding, if it's valid and applies to this inquiry. */
369 if (current_buffer
== find_start_buffer
370 /* Reuse the defun-start even if POS is a little farther on.
371 POS might be in the next defun, but that's ok.
372 Our value may not be the best possible, but will still be usable. */
373 && pos
<= find_start_pos
+ 1000
374 && pos
>= find_start_value
375 && BEGV
== find_start_begv
376 && MODIFF
== find_start_modiff
)
377 return find_start_value
;
379 /* Back up to start of line. */
380 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
382 /* We optimize syntax-table lookup for rare updates. Thus we accept
383 only those `^\s(' which are good in global _and_ text-property
385 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
386 gl_state
.use_global
= 0;
391 /* Open-paren at start of line means we may have found our
393 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
394 if (SYNTAX (c
) == Sopen
)
396 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
397 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
398 if (SYNTAX (c
) == Sopen
)
400 /* Now fallback to the default value. */
401 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
402 gl_state
.use_global
= 0;
404 /* Move to beg of previous line. */
405 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
408 /* Record what we found, for the next try. */
409 find_start_value
= PT
;
410 find_start_value_byte
= PT_BYTE
;
411 find_start_buffer
= current_buffer
;
412 find_start_modiff
= MODIFF
;
413 find_start_begv
= BEGV
;
414 find_start_pos
= pos
;
416 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
418 return find_start_value
;
421 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
424 prev_char_comend_first (pos
, pos_byte
)
429 DEC_BOTH (pos
, pos_byte
);
430 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
431 c
= FETCH_CHAR (pos_byte
);
432 val
= SYNTAX_COMEND_FIRST (c
);
433 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
437 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
440 * prev_char_comstart_first (pos, pos_byte)
445 * DEC_BOTH (pos, pos_byte);
446 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
447 * c = FETCH_CHAR (pos_byte);
448 * val = SYNTAX_COMSTART_FIRST (c);
449 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
453 /* Checks whether charpos FROM is at the end of a comment.
454 FROM_BYTE is the bytepos corresponding to FROM.
455 Do not move back before STOP.
457 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
460 If successful, store the charpos of the comment's beginning
461 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
463 Global syntax data remains valid for backward search starting at
464 the returned value (or at FROM, if the search was not successful). */
467 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
468 int from
, from_byte
, stop
;
469 int comnested
, comstyle
;
470 int *charpos_ptr
, *bytepos_ptr
;
472 /* Look back, counting the parity of string-quotes,
473 and recording the comment-starters seen.
474 When we reach a safe place, assume that's not in a string;
475 then step the main scan to the earliest comment-starter seen
476 an even number of string quotes away from the safe place.
478 OFROM[I] is position of the earliest comment-starter seen
479 which is I+2X quotes from the comment-end.
480 PARITY is current parity of quotes from the comment end. */
481 int string_style
= -1; /* Presumed outside of any string. */
482 int string_lossage
= 0;
483 /* Not a real lossage: indicates that we have passed a matching comment
484 starter plus a non-matching comment-ender, meaning that any matching
485 comment-starter we might see later could be a false positive (hidden
486 inside another comment).
487 Test case: { a (* b } c (* d *) */
488 int comment_lossage
= 0;
489 int comment_end
= from
;
490 int comment_end_byte
= from_byte
;
491 int comstart_pos
= 0;
493 /* Place where the containing defun starts,
494 or 0 if we didn't come across it yet. */
496 int defun_start_byte
= 0;
497 register enum syntaxcode code
;
498 int nesting
= 1; /* current comment nesting */
502 /* FIXME: A }} comment-ender style leads to incorrect behavior
503 in the case of {{ c }}} because we ignore the last two chars which are
504 assumed to be comment-enders although they aren't. */
506 /* At beginning of range to scan, we're outside of strings;
507 that determines quote parity to the comment-end. */
510 int temp_byte
, prev_syntax
;
511 int com2start
, com2end
;
513 /* Move back and examine a character. */
514 DEC_BOTH (from
, from_byte
);
515 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
517 prev_syntax
= syntax
;
518 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
519 syntax
= SYNTAX_WITH_FLAGS (c
);
522 /* Check for 2-char comment markers. */
523 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
524 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
525 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
526 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
527 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
528 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
529 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
531 /* Nasty cases with overlapping 2-char comment markers:
532 - snmp-mode: -- c -- foo -- c --
540 /* If a 2-char comment sequence partly overlaps with another,
541 we don't try to be clever. */
542 if (from
> stop
&& (com2end
|| com2start
))
544 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
545 DEC_BOTH (next
, next_byte
);
546 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
547 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
548 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
549 if (((com2start
|| comnested
)
550 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
551 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
552 || ((com2end
|| comnested
)
553 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
554 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
555 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
557 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
560 if (com2start
&& comstart_pos
== 0)
561 /* We're looking at a comment starter. But it might be a comment
562 ender as well (see snmp-mode). The first time we see one, we
563 need to consider it as a comment starter,
564 and the subsequent times as a comment ender. */
567 /* Turn a 2-char comment sequences into the appropriate syntax. */
572 /* Ignore comment starters of a different style. */
573 else if (code
== Scomment
574 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
575 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
578 /* Ignore escaped characters, except comment-enders. */
579 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
586 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
588 /* Track parity of quotes. */
589 if (string_style
== -1)
590 /* Entering a string. */
592 else if (string_style
== c
)
593 /* Leaving the string. */
596 /* If we have two kinds of string delimiters.
597 There's no way to grok this scanning backwards. */
602 /* We've already checked that it is the relevant comstyle. */
603 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
604 /* There are odd string quotes involved, so let's be careful.
605 Test case in Pascal: " { " a { " } */
610 /* Record best comment-starter so far. */
612 comstart_byte
= from_byte
;
614 else if (--nesting
<= 0)
615 /* nested comments have to be balanced, so we don't need to
616 keep looking for earlier ones. We use here the same (slightly
617 incorrect) reasoning as below: since it is followed by uniform
618 paired string quotes, this comment-start has to be outside of
619 strings, else the comment-end itself would be inside a string. */
624 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
625 && ((com2end
&& SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
))
626 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
627 /* This is the same style of comment ender as ours. */
632 /* Anything before that can't count because it would match
633 this comment-ender rather than ours. */
634 from
= stop
; /* Break out of the loop. */
636 else if (comstart_pos
!= 0 || c
!= '\n')
637 /* We're mixing comment styles here, so we'd better be careful.
638 The (comstart_pos != 0 || c != '\n') check is not quite correct
639 (we should just always set comment_lossage), but removing it
640 would imply that any multiline comment in C would go through
641 lossage, which seems overkill.
642 The failure should only happen in the rare cases such as
648 /* Assume a defun-start point is outside of strings. */
649 if (open_paren_in_column_0_is_defun_start
651 || (temp_byte
= dec_bytepos (from_byte
),
652 FETCH_CHAR (temp_byte
) == '\n')))
655 defun_start_byte
= from_byte
;
656 from
= stop
; /* Break out of the loop. */
665 if (comstart_pos
== 0)
668 from_byte
= comment_end_byte
;
669 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
671 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
672 or `done'), then we've found the beginning of the non-nested comment. */
673 else if (1) /* !comnested */
676 from_byte
= comstart_byte
;
677 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
681 struct lisp_parse_state state
;
683 /* We had two kinds of string delimiters mixed up
684 together. Decode this going forwards.
685 Scan fwd from a known safe place (beginning-of-defun)
686 to the one in question; this records where we
687 last passed a comment starter. */
688 /* If we did not already find the defun start, find it now. */
689 if (defun_start
== 0)
691 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
692 defun_start_byte
= find_start_value_byte
;
696 scan_sexps_forward (&state
,
697 defun_start
, defun_start_byte
,
698 comment_end
, -10000, 0, Qnil
, 0);
699 defun_start
= comment_end
;
700 if (state
.incomment
== (comnested
? 1 : -1)
701 && state
.comstyle
== comstyle
)
702 from
= state
.comstr_start
;
707 /* If comment_end is inside some other comment, maybe ours
708 is nested, so we need to try again from within the
709 surrounding comment. Example: { a (* " *) */
711 /* FIXME: We should advance by one or two chars. */
712 defun_start
= state
.comstr_start
+ 2;
713 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
716 } while (defun_start
< comment_end
);
718 from_byte
= CHAR_TO_BYTE (from
);
719 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
724 *bytepos_ptr
= from_byte
;
726 return (from
== comment_end
) ? -1 : from
;
729 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
730 doc
: /* Return t if OBJECT is a syntax table.
731 Currently, any char-table counts as a syntax table. */)
735 if (CHAR_TABLE_P (object
)
736 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
742 check_syntax_table (obj
)
745 if (!(CHAR_TABLE_P (obj
)
746 && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
)))
747 wrong_type_argument (Qsyntax_table_p
, obj
);
750 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
751 doc
: /* Return the current syntax table.
752 This is the one specified by the current buffer. */)
755 return current_buffer
->syntax_table
;
758 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
759 Sstandard_syntax_table
, 0, 0, 0,
760 doc
: /* Return the standard syntax table.
761 This is the one used for new buffers. */)
764 return Vstandard_syntax_table
;
767 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
768 doc
: /* Construct a new syntax table and return it.
769 It is a copy of the TABLE, which defaults to the standard syntax table. */)
776 check_syntax_table (table
);
778 table
= Vstandard_syntax_table
;
780 copy
= Fcopy_sequence (table
);
782 /* Only the standard syntax table should have a default element.
783 Other syntax tables should inherit from parents instead. */
784 XCHAR_TABLE (copy
)->defalt
= Qnil
;
786 /* Copied syntax tables should all have parents.
787 If we copied one with no parent, such as the standard syntax table,
788 use the standard syntax table as the copy's parent. */
789 if (NILP (XCHAR_TABLE (copy
)->parent
))
790 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
794 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
795 doc
: /* Select a new syntax table for the current buffer.
796 One argument, a syntax table. */)
801 check_syntax_table (table
);
802 current_buffer
->syntax_table
= table
;
803 /* Indicate that this buffer now has a specified syntax table. */
804 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
805 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
809 /* Convert a letter which signifies a syntax code
810 into the code it signifies.
811 This is used by modify-syntax-entry, and other things. */
813 unsigned char syntax_spec_code
[0400] =
814 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
815 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
816 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
817 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
818 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
819 (char) Smath
, 0377, 0377, (char) Squote
,
820 (char) Sopen
, (char) Sclose
, 0377, 0377,
821 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
822 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
823 0377, 0377, 0377, 0377,
824 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
825 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
826 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
827 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
828 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
829 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
830 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
831 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
832 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
835 /* Indexed by syntax code, give the letter that describes it. */
837 char syntax_code_spec
[16] =
839 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
843 /* Indexed by syntax code, give the object (cons of syntax code and
844 nil) to be stored in syntax table. Since these objects can be
845 shared among syntax tables, we generate them in advance. By
846 sharing objects, the function `describe-syntax' can give a more
848 static Lisp_Object Vsyntax_code_object
;
851 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
852 doc
: /* Return the syntax code of CHARACTER, described by a character.
853 For example, if CHARACTER is a word constituent,
854 the character `w' is returned.
855 The characters that correspond to various syntax codes
856 are listed in the documentation of `modify-syntax-entry'. */)
858 Lisp_Object character
;
861 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
863 gl_state
.use_global
= 0;
864 CHECK_NUMBER (character
);
865 char_int
= XINT (character
);
866 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
869 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
870 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
872 Lisp_Object character
;
875 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
876 gl_state
.use_global
= 0;
877 CHECK_NUMBER (character
);
878 char_int
= XINT (character
);
879 code
= SYNTAX (char_int
);
880 if (code
== Sopen
|| code
== Sclose
)
881 return SYNTAX_MATCH (char_int
);
885 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
886 doc
: /* Convert a syntax specification STRING into syntax cell form.
887 STRING should be a string as it is allowed as argument of
888 `modify-syntax-entry'. Value is the equivalent cons cell
889 (CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
894 register const unsigned char *p
;
895 register enum syntaxcode code
;
899 CHECK_STRING (string
);
902 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
903 if (((int) code
& 0377) == 0377)
904 error ("Invalid syntax description letter: %c", p
[-1]);
906 if (code
== Sinherit
)
912 int character
= (STRING_CHAR_AND_LENGTH
913 (p
, SBYTES (string
) - 1, len
));
914 XSETINT (match
, character
);
915 if (XFASTINT (match
) == ' ')
955 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
956 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
958 /* Since we can't use a shared object, let's make a new one. */
959 return Fcons (make_number (val
), match
);
962 /* I really don't know why this is interactive
963 help-form should at least be made useful whilst reading the second arg. */
964 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
965 "cSet syntax for character: \nsSet syntax for %s to: ",
966 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
967 The syntax is changed only for table SYNTAX-TABLE, which defaults to
968 the current buffer's syntax table.
969 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
970 in the range MIN and MAX are changed.
971 The first character of NEWENTRY should be one of the following:
972 Space or - whitespace syntax. w word constituent.
973 _ symbol constituent. . punctuation.
974 ( open-parenthesis. ) close-parenthesis.
975 " string quote. \\ escape.
976 $ paired delimiter. ' expression quote or prefix operator.
977 < comment starter. > comment ender.
978 / character-quote. @ inherit from `standard-syntax-table'.
979 | generic string fence. ! generic comment fence.
981 Only single-character comment start and end sequences are represented thus.
982 Two-character sequences are represented as described below.
983 The second character of NEWENTRY is the matching parenthesis,
984 used only if the first character is `(' or `)'.
985 Any additional characters are flags.
986 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
987 1 means CHAR is the start of a two-char comment start sequence.
988 2 means CHAR is the second character of such a sequence.
989 3 means CHAR is the start of a two-char comment end sequence.
990 4 means CHAR is the second character of such a sequence.
992 There can be up to two orthogonal comment sequences. This is to support
993 language modes such as C++. By default, all comment sequences are of style
994 a, but you can set the comment sequence style to b (on the second character
995 of a comment-start, or the first character of a comment-end sequence) using
997 b means CHAR is part of comment sequence b.
998 n means CHAR is part of a nestable comment sequence.
1000 p means CHAR is a prefix character for `backward-prefix-chars';
1001 such characters are treated as whitespace when they occur
1002 between expressions.
1003 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1004 (c
, newentry
, syntax_table
)
1005 Lisp_Object c
, newentry
, syntax_table
;
1009 CHECK_CHARACTER_CAR (c
);
1010 CHECK_CHARACTER_CDR (c
);
1013 CHECK_CHARACTER (c
);
1015 if (NILP (syntax_table
))
1016 syntax_table
= current_buffer
->syntax_table
;
1018 check_syntax_table (syntax_table
);
1020 newentry
= Fstring_to_syntax (newentry
);
1022 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1024 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1028 /* Dump syntax table to buffer in human-readable format */
1030 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1031 Sinternal_describe_syntax_value
, 1, 1, 0,
1032 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1036 register enum syntaxcode code
;
1037 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1039 Lisp_Object first
, match_lisp
, value
= syntax
;
1043 insert_string ("default");
1047 if (CHAR_TABLE_P (value
))
1049 insert_string ("deeper char-table ...");
1055 insert_string ("invalid");
1059 first
= XCAR (value
);
1060 match_lisp
= XCDR (value
);
1062 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1064 insert_string ("invalid");
1068 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1069 start1
= (XINT (first
) >> 16) & 1;
1070 start2
= (XINT (first
) >> 17) & 1;
1071 end1
= (XINT (first
) >> 18) & 1;
1072 end2
= (XINT (first
) >> 19) & 1;
1073 prefix
= (XINT (first
) >> 20) & 1;
1074 comstyle
= (XINT (first
) >> 21) & 1;
1075 comnested
= (XINT (first
) >> 22) & 1;
1077 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1079 insert_string ("invalid");
1082 desc
= syntax_code_spec
[(int) code
];
1084 str
[0] = desc
, str
[1] = 0;
1087 if (NILP (match_lisp
))
1090 insert_char (XINT (match_lisp
));
1109 insert_string ("\twhich means: ");
1111 switch (SWITCH_ENUM_CAST (code
))
1114 insert_string ("whitespace"); break;
1116 insert_string ("punctuation"); break;
1118 insert_string ("word"); break;
1120 insert_string ("symbol"); break;
1122 insert_string ("open"); break;
1124 insert_string ("close"); break;
1126 insert_string ("prefix"); break;
1128 insert_string ("string"); break;
1130 insert_string ("math"); break;
1132 insert_string ("escape"); break;
1134 insert_string ("charquote"); break;
1136 insert_string ("comment"); break;
1138 insert_string ("endcomment"); break;
1140 insert_string ("inherit"); break;
1141 case Scomment_fence
:
1142 insert_string ("comment fence"); break;
1144 insert_string ("string fence"); break;
1146 insert_string ("invalid");
1150 if (!NILP (match_lisp
))
1152 insert_string (", matches ");
1153 insert_char (XINT (match_lisp
));
1157 insert_string (",\n\t is the first character of a comment-start sequence");
1159 insert_string (",\n\t is the second character of a comment-start sequence");
1162 insert_string (",\n\t is the first character of a comment-end sequence");
1164 insert_string (",\n\t is the second character of a comment-end sequence");
1166 insert_string (" (comment style b)");
1168 insert_string (" (nestable)");
1171 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1176 int parse_sexp_ignore_comments
;
1178 /* Char-table of functions that find the next or previous word
1180 Lisp_Object Vfind_word_boundary_function_table
;
1182 /* Return the position across COUNT words from FROM.
1183 If that many words cannot be found before the end of the buffer, return 0.
1184 COUNT negative means scan backward and stop at word beginning. */
1187 scan_words (from
, count
)
1188 register int from
, count
;
1190 register int beg
= BEGV
;
1191 register int end
= ZV
;
1192 register int from_byte
= CHAR_TO_BYTE (from
);
1193 register enum syntaxcode code
;
1195 Lisp_Object func
, script
, pos
;
1200 SETUP_SYNTAX_TABLE (from
, count
);
1211 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1212 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1213 code
= SYNTAX (ch0
);
1214 INC_BOTH (from
, from_byte
);
1215 if (words_include_escapes
1216 && (code
== Sescape
|| code
== Scharquote
))
1221 /* Now CH0 is a character which begins a word and FROM is the
1222 position of the next character. */
1223 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch0
);
1224 if (! NILP (Ffboundp (func
)))
1226 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1227 if (INTEGERP (pos
) && XINT (pos
) > from
)
1230 from_byte
= CHAR_TO_BYTE (from
);
1235 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1238 if (from
== end
) break;
1239 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1240 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1241 code
= SYNTAX (ch1
);
1243 && (! words_include_escapes
1244 || (code
!= Sescape
&& code
!= Scharquote
)))
1245 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch1
), script
))
1247 INC_BOTH (from
, from_byte
);
1262 DEC_BOTH (from
, from_byte
);
1263 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1264 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1265 code
= SYNTAX (ch1
);
1266 if (words_include_escapes
1267 && (code
== Sescape
|| code
== Scharquote
))
1272 /* Now CH1 is a character which ends a word and FROM is the
1274 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch1
);
1275 if (! NILP (Ffboundp (func
)))
1277 pos
= call2 (func
, make_number (from
), make_number (beg
));
1278 if (INTEGERP (pos
) && XINT (pos
) < from
)
1281 from_byte
= CHAR_TO_BYTE (from
);
1286 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1293 temp_byte
= dec_bytepos (from_byte
);
1294 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1295 ch0
= FETCH_CHAR_AS_MULTIBYTE (temp_byte
);
1296 code
= SYNTAX (ch0
);
1298 && (! words_include_escapes
1299 || (code
!= Sescape
&& code
!= Scharquote
)))
1300 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch0
), script
))
1302 DEC_BOTH (from
, from_byte
);
1314 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 0, 1, "p",
1315 doc
: /* Move point forward ARG words (backward if ARG is negative).
1317 If an edge of the buffer or a field boundary is reached, point is left there
1318 and the function returns nil. Field boundaries are not noticed if
1319 `inhibit-field-text-motion' is non-nil. */)
1327 XSETFASTINT (arg
, 1);
1331 val
= orig_val
= scan_words (PT
, XINT (arg
));
1333 val
= XINT (arg
) > 0 ? ZV
: BEGV
;
1335 /* Avoid jumping out of an input field. */
1336 tmp
= Fconstrain_to_field (make_number (val
), make_number (PT
),
1338 val
= XFASTINT (tmp
);
1341 return val
== orig_val
? Qt
: Qnil
;
1344 Lisp_Object
skip_chars ();
1346 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1347 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1348 STRING is like the inside of a `[...]' in a regular expression
1349 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1350 (but not as the end of a range; quoting is never needed there).
1351 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1352 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1353 Char classes, e.g. `[:alpha:]', are supported.
1355 Returns the distance traveled, either zero or positive. */)
1357 Lisp_Object string
, lim
;
1359 return skip_chars (1, string
, lim
, 1);
1362 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1363 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1364 See `skip-chars-forward' for details.
1365 Returns the distance traveled, either zero or negative. */)
1367 Lisp_Object string
, lim
;
1369 return skip_chars (0, string
, lim
, 1);
1372 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1373 doc
: /* Move point forward across chars in specified syntax classes.
1374 SYNTAX is a string of syntax code characters.
1375 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1376 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1377 This function returns the distance traveled, either zero or positive. */)
1379 Lisp_Object syntax
, lim
;
1381 return skip_syntaxes (1, syntax
, lim
);
1384 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1385 doc
: /* Move point backward across chars in specified syntax classes.
1386 SYNTAX is a string of syntax code characters.
1387 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1388 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1389 This function returns the distance traveled, either zero or negative. */)
1391 Lisp_Object syntax
, lim
;
1393 return skip_syntaxes (0, syntax
, lim
);
1397 skip_chars (forwardp
, string
, lim
, handle_iso_classes
)
1399 Lisp_Object string
, lim
;
1400 int handle_iso_classes
;
1402 register unsigned int c
;
1403 unsigned char fastmap
[0400];
1404 /* Store the ranges of non-ASCII characters. */
1406 int n_char_ranges
= 0;
1408 register int i
, i_byte
;
1409 /* Set to 1 if the current buffer is multibyte and the region
1410 contains non-ASCII chars. */
1412 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1414 int string_multibyte
;
1416 const unsigned char *str
;
1418 Lisp_Object iso_classes
;
1420 CHECK_STRING (string
);
1424 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1426 CHECK_NUMBER_COERCE_MARKER (lim
);
1428 /* In any case, don't allow scan outside bounds of buffer. */
1429 if (XINT (lim
) > ZV
)
1430 XSETFASTINT (lim
, ZV
);
1431 if (XINT (lim
) < BEGV
)
1432 XSETFASTINT (lim
, BEGV
);
1434 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1435 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1436 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1438 bzero (fastmap
, sizeof fastmap
);
1440 str
= SDATA (string
);
1441 size_byte
= SBYTES (string
);
1444 if (i_byte
< size_byte
1445 && SREF (string
, 0) == '^')
1447 negate
= 1; i_byte
++;
1450 /* Find the characters specified and set their elements of fastmap.
1451 Handle backslashes and ranges specially.
1453 If STRING contains non-ASCII characters, setup char_ranges for
1454 them and use fastmap only for their leading codes. */
1456 if (! string_multibyte
)
1458 int string_has_eight_bit
= 0;
1460 /* At first setup fastmap. */
1461 while (i_byte
< size_byte
)
1465 if (handle_iso_classes
&& c
== '['
1466 && i_byte
< size_byte
1467 && str
[i_byte
] == ':')
1469 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1470 const unsigned char *class_end
= class_beg
;
1471 const unsigned char *class_limit
= str
+ size_byte
- 2;
1472 /* Leave room for the null. */
1473 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1476 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1477 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1479 while (class_end
< class_limit
1480 && *class_end
>= 'a' && *class_end
<= 'z')
1483 if (class_end
== class_beg
1484 || *class_end
!= ':' || class_end
[1] != ']')
1485 goto not_a_class_name
;
1487 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1488 class_name
[class_end
- class_beg
] = 0;
1490 cc
= re_wctype (class_name
);
1492 error ("Invalid ISO C character class");
1494 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1496 i_byte
= class_end
+ 2 - str
;
1503 if (i_byte
== size_byte
)
1508 /* Treat `-' as range character only if another character
1510 if (i_byte
+ 1 < size_byte
1511 && str
[i_byte
] == '-')
1515 /* Skip over the dash. */
1518 /* Get the end of the range. */
1521 && i_byte
< size_byte
)
1528 if (! ASCII_CHAR_P (c2
))
1529 string_has_eight_bit
= 1;
1535 if (! ASCII_CHAR_P (c
))
1536 string_has_eight_bit
= 1;
1540 /* If the current range is multibyte and STRING contains
1541 eight-bit chars, arrange fastmap and setup char_ranges for
1542 the corresponding multibyte chars. */
1543 if (multibyte
&& string_has_eight_bit
)
1545 unsigned char fastmap2
[0400];
1546 int range_start_byte
, range_start_char
;
1548 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1549 bzero (fastmap
+ 0200, 0200);
1550 /* We are sure that this loop stops. */
1551 for (i
= 0200; ! fastmap2
[i
]; i
++);
1552 c
= unibyte_char_to_multibyte (i
);
1553 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1554 range_start_byte
= i
;
1555 range_start_char
= c
;
1556 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1557 for (i
= 129; i
< 0400; i
++)
1559 c
= unibyte_char_to_multibyte (i
);
1560 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1561 if (i
- range_start_byte
!= c
- range_start_char
)
1563 char_ranges
[n_char_ranges
++] = range_start_char
;
1564 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1565 + range_start_char
);
1566 range_start_byte
= i
;
1567 range_start_char
= c
;
1570 char_ranges
[n_char_ranges
++] = range_start_char
;
1571 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1572 + range_start_char
);
1575 else /* STRING is multibyte */
1577 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1579 while (i_byte
< size_byte
)
1581 unsigned char leading_code
;
1583 leading_code
= str
[i_byte
];
1584 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1587 if (handle_iso_classes
&& c
== '['
1588 && i_byte
< size_byte
1589 && STRING_CHAR (str
+ i_byte
, size_byte
- i_byte
) == ':')
1591 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1592 const unsigned char *class_end
= class_beg
;
1593 const unsigned char *class_limit
= str
+ size_byte
- 2;
1594 /* Leave room for the null. */
1595 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1598 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1599 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1601 while (class_end
< class_limit
1602 && *class_end
>= 'a' && *class_end
<= 'z')
1605 if (class_end
== class_beg
1606 || *class_end
!= ':' || class_end
[1] != ']')
1607 goto not_a_class_name_multibyte
;
1609 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1610 class_name
[class_end
- class_beg
] = 0;
1612 cc
= re_wctype (class_name
);
1614 error ("Invalid ISO C character class");
1616 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1618 i_byte
= class_end
+ 2 - str
;
1622 not_a_class_name_multibyte
:
1625 if (i_byte
== size_byte
)
1628 leading_code
= str
[i_byte
];
1629 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1630 size_byte
- i_byte
, len
);
1633 /* Treat `-' as range character only if another character
1635 if (i_byte
+ 1 < size_byte
1636 && str
[i_byte
] == '-')
1639 unsigned char leading_code2
;
1641 /* Skip over the dash. */
1644 /* Get the end of the range. */
1645 leading_code2
= str
[i_byte
];
1646 c2
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1647 size_byte
- i_byte
, len
);
1651 && i_byte
< size_byte
)
1653 leading_code2
= str
[i_byte
];
1654 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1660 if (ASCII_CHAR_P (c
))
1662 while (c
<= c2
&& c
< 0x80)
1664 leading_code
= CHAR_LEADING_CODE (c
);
1666 if (! ASCII_CHAR_P (c
))
1668 while (leading_code
<= leading_code2
)
1669 fastmap
[leading_code
++] = 1;
1672 char_ranges
[n_char_ranges
++] = c
;
1673 char_ranges
[n_char_ranges
++] = c2
;
1679 if (ASCII_CHAR_P (c
))
1683 fastmap
[leading_code
] = 1;
1684 char_ranges
[n_char_ranges
++] = c
;
1685 char_ranges
[n_char_ranges
++] = c
;
1690 /* If the current range is unibyte and STRING contains non-ASCII
1691 chars, arrange fastmap for the corresponding unibyte
1694 if (! multibyte
&& n_char_ranges
> 0)
1696 bzero (fastmap
+ 0200, 0200);
1697 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1699 int c1
= char_ranges
[i
];
1700 int c2
= char_ranges
[i
+ 1];
1702 for (; c1
<= c2
; c1
++)
1703 fastmap
[CHAR_TO_BYTE8 (c1
)] = 1;
1708 /* If ^ was the first character, complement the fastmap. */
1712 for (i
= 0; i
< sizeof fastmap
; i
++)
1716 for (i
= 0; i
< 0200; i
++)
1718 /* All non-ASCII chars possibly match. */
1719 for (; i
< sizeof fastmap
; i
++)
1725 int start_point
= PT
;
1727 int pos_byte
= PT_BYTE
;
1728 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1732 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1733 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1737 endp
= CHAR_POS_ADDR (XINT (lim
));
1738 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1756 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1757 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1767 if (! ASCII_CHAR_P (c
))
1769 /* As we are looking at a multibyte character, we
1770 must look up the character in the table
1771 CHAR_RANGES. If there's no data in the table,
1772 that character is not what we want to skip. */
1774 /* The following code do the right thing even if
1775 n_char_ranges is zero (i.e. no data in
1777 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1778 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1780 if (!(negate
^ (i
< n_char_ranges
)))
1784 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1797 if (!NILP (iso_classes
) && in_classes (*p
, iso_classes
))
1802 goto fwd_unibyte_ok
;
1808 p
++, pos
++, pos_byte
++;
1816 unsigned char *prev_p
;
1826 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1827 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1829 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1839 if (! ASCII_CHAR_P (c
))
1841 /* See the comment in the previous similar code. */
1842 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1843 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1845 if (!(negate
^ (i
< n_char_ranges
)))
1849 pos
--, pos_byte
-= prev_p
- p
;
1862 if (! NILP (iso_classes
) && in_classes (p
[-1], iso_classes
))
1867 goto back_unibyte_ok
;
1870 if (!fastmap
[p
[-1]])
1873 p
--, pos
--, pos_byte
--;
1877 SET_PT_BOTH (pos
, pos_byte
);
1880 return make_number (PT
- start_point
);
1886 skip_syntaxes (forwardp
, string
, lim
)
1888 Lisp_Object string
, lim
;
1890 register unsigned int c
;
1891 unsigned char fastmap
[0400];
1893 register int i
, i_byte
;
1898 CHECK_STRING (string
);
1901 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1903 CHECK_NUMBER_COERCE_MARKER (lim
);
1905 /* In any case, don't allow scan outside bounds of buffer. */
1906 if (XINT (lim
) > ZV
)
1907 XSETFASTINT (lim
, ZV
);
1908 if (XINT (lim
) < BEGV
)
1909 XSETFASTINT (lim
, BEGV
);
1911 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1912 return make_number (0);
1914 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1915 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1917 bzero (fastmap
, sizeof fastmap
);
1919 if (SBYTES (string
) > SCHARS (string
))
1920 /* As this is very rare case (syntax spec is ASCII only), don't
1921 consider efficiency. */
1922 string
= string_make_unibyte (string
);
1924 str
= SDATA (string
);
1925 size_byte
= SBYTES (string
);
1928 if (i_byte
< size_byte
1929 && SREF (string
, 0) == '^')
1931 negate
= 1; i_byte
++;
1934 /* Find the syntaxes specified and set their elements of fastmap. */
1936 while (i_byte
< size_byte
)
1939 fastmap
[syntax_spec_code
[c
]] = 1;
1942 /* If ^ was the first character, complement the fastmap. */
1944 for (i
= 0; i
< sizeof fastmap
; i
++)
1948 int start_point
= PT
;
1950 int pos_byte
= PT_BYTE
;
1951 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1955 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1956 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1960 endp
= CHAR_POS_ADDR (XINT (lim
));
1961 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1965 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1981 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1982 if (! fastmap
[(int) SYNTAX (c
)])
1984 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1985 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1999 if (! fastmap
[(int) SYNTAX (*p
)])
2001 p
++, pos
++, pos_byte
++;
2002 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2012 unsigned char *prev_p
;
2022 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
2023 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
2024 if (! fastmap
[(int) SYNTAX (c
)])
2026 pos
--, pos_byte
-= prev_p
- p
;
2027 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
2041 if (! fastmap
[(int) SYNTAX (p
[-1])])
2043 p
--, pos
--, pos_byte
--;
2044 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2049 SET_PT_BOTH (pos
, pos_byte
);
2052 return make_number (PT
- start_point
);
2056 /* Return 1 if character C belongs to one of the ISO classes
2057 in the list ISO_CLASSES. Each class is represented by an
2058 integer which is its type according to re_wctype. */
2061 in_classes (c
, iso_classes
)
2063 Lisp_Object iso_classes
;
2067 while (! NILP (iso_classes
))
2070 elt
= XCAR (iso_classes
);
2071 iso_classes
= XCDR (iso_classes
);
2073 if (re_iswctype (c
, XFASTINT (elt
)))
2080 /* Jump over a comment, assuming we are at the beginning of one.
2081 FROM is the current position.
2082 FROM_BYTE is the bytepos corresponding to FROM.
2083 Do not move past STOP (a charpos).
2084 The comment over which we have to jump is of style STYLE
2085 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2086 NESTING should be positive to indicate the nesting at the beginning
2087 for nested comments and should be zero or negative else.
2088 ST_COMMENT_STYLE cannot be nested.
2089 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
2090 (or 0 If the search cannot start in the middle of a two-character).
2092 If successful, return 1 and store the charpos of the comment's end
2093 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
2094 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
2095 corresponding bytepos into *BYTEPOS_PTR and the current nesting
2096 (as defined for state.incomment) in *INCOMMENT_PTR.
2098 The comment end is the last character of the comment rather than the
2099 character just after the comment.
2101 Global syntax data is assumed to initially be valid for FROM and
2102 remains valid for forward search starting at the returned position. */
2105 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
2106 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
2107 int from
, from_byte
, stop
;
2108 int nesting
, style
, prev_syntax
;
2109 int *charpos_ptr
, *bytepos_ptr
, *incomment_ptr
;
2112 register enum syntaxcode code
;
2113 register int syntax
;
2115 if (nesting
<= 0) nesting
= -1;
2117 /* Enter the loop in the middle so that we find
2118 a 2-char comment ender if we start in the middle of it. */
2119 syntax
= prev_syntax
;
2120 if (syntax
!= 0) goto forw_incomment
;
2126 *incomment_ptr
= nesting
;
2127 *charpos_ptr
= from
;
2128 *bytepos_ptr
= from_byte
;
2131 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2132 syntax
= SYNTAX_WITH_FLAGS (c
);
2133 code
= syntax
& 0xff;
2134 if (code
== Sendcomment
2135 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2136 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
2137 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
2138 /* we have encountered a comment end of the same style
2139 as the comment sequence which began this comment
2142 if (code
== Scomment_fence
2143 && style
== ST_COMMENT_STYLE
)
2144 /* we have encountered a comment end of the same style
2145 as the comment sequence which began this comment
2150 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
2151 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
2152 /* we have encountered a nested comment of the same style
2153 as the comment sequence which began this comment section */
2155 INC_BOTH (from
, from_byte
);
2156 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2159 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2160 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2161 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2162 SYNTAX_COMEND_SECOND (c1
))
2163 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2164 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2167 /* we have encountered a comment end of the same style
2168 as the comment sequence which began this comment
2173 INC_BOTH (from
, from_byte
);
2174 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2179 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2180 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2181 SYNTAX_COMMENT_STYLE (c1
) == style
2182 && SYNTAX_COMSTART_SECOND (c1
))
2183 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2184 SYNTAX_COMMENT_NESTED (c1
)))
2185 /* we have encountered a nested comment of the same style
2186 as the comment sequence which began this comment
2189 INC_BOTH (from
, from_byte
);
2190 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2194 *charpos_ptr
= from
;
2195 *bytepos_ptr
= from_byte
;
2199 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2201 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2202 Stop scanning if we find something other than a comment or whitespace.
2203 Set point to where scanning stops.
2204 If COUNT comments are found as expected, with nothing except whitespace
2205 between them, return t; otherwise return nil. */)
2213 register enum syntaxcode code
;
2214 int comstyle
= 0; /* style of comment encountered */
2215 int comnested
= 0; /* whether the comment is nestable or not */
2218 int out_charpos
, out_bytepos
;
2221 CHECK_NUMBER (count
);
2222 count1
= XINT (count
);
2223 stop
= count1
> 0 ? ZV
: BEGV
;
2229 from_byte
= PT_BYTE
;
2231 SETUP_SYNTAX_TABLE (from
, count1
);
2240 SET_PT_BOTH (from
, from_byte
);
2244 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2246 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2247 comnested
= SYNTAX_COMMENT_NESTED (c
);
2248 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2249 INC_BOTH (from
, from_byte
);
2250 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2251 if (from
< stop
&& comstart_first
2252 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2253 SYNTAX_COMSTART_SECOND (c1
)))
2255 /* We have encountered a comment start sequence and we
2256 are ignoring all text inside comments. We must record
2257 the comment style this sequence begins so that later,
2258 only a comment end of the same style actually ends
2259 the comment section. */
2261 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2262 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2263 INC_BOTH (from
, from_byte
);
2264 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2267 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2269 if (code
== Scomment_fence
)
2270 comstyle
= ST_COMMENT_STYLE
;
2271 else if (code
!= Scomment
)
2274 DEC_BOTH (from
, from_byte
);
2275 SET_PT_BOTH (from
, from_byte
);
2278 /* We're at the start of a comment. */
2279 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2280 &out_charpos
, &out_bytepos
, &dummy
);
2281 from
= out_charpos
; from_byte
= out_bytepos
;
2285 SET_PT_BOTH (from
, from_byte
);
2288 INC_BOTH (from
, from_byte
);
2289 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2290 /* We have skipped one comment. */
2302 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2307 DEC_BOTH (from
, from_byte
);
2308 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2309 quoted
= char_quoted (from
, from_byte
);
2310 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2313 comnested
= SYNTAX_COMMENT_NESTED (c
);
2314 if (code
== Sendcomment
)
2315 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2316 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2317 && prev_char_comend_first (from
, from_byte
)
2318 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2320 /* We must record the comment style encountered so that
2321 later, we can match only the proper comment begin
2322 sequence of the same style. */
2323 DEC_BOTH (from
, from_byte
);
2325 /* Calling char_quoted, above, set up global syntax position
2326 at the new value of FROM. */
2327 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2328 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2329 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2332 if (code
== Scomment_fence
)
2334 /* Skip until first preceding unquoted comment_fence. */
2335 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2339 DEC_BOTH (from
, from_byte
);
2342 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2343 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2344 if (SYNTAX (c
) == Scomment_fence
2345 && !char_quoted (from
, from_byte
))
2353 from
= ini
; /* Set point to ini + 1. */
2354 from_byte
= ini_byte
;
2358 else if (code
== Sendcomment
)
2360 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2361 &out_charpos
, &out_bytepos
);
2365 /* This end-of-line is not an end-of-comment.
2366 Treat it like a whitespace.
2367 CC-mode (and maybe others) relies on this behavior. */
2371 /* Failure: we should go back to the end of this
2372 not-quite-endcomment. */
2373 if (SYNTAX(c
) != code
)
2374 /* It was a two-char Sendcomment. */
2375 INC_BOTH (from
, from_byte
);
2381 /* We have skipped one comment. */
2382 from
= out_charpos
, from_byte
= out_bytepos
;
2386 else if (code
!= Swhitespace
|| quoted
)
2390 INC_BOTH (from
, from_byte
);
2391 SET_PT_BOTH (from
, from_byte
);
2399 SET_PT_BOTH (from
, from_byte
);
2404 /* Return syntax code of character C if C is an ASCII character
2405 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2407 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2408 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2409 ? SYNTAX (c) : Ssymbol)
2412 scan_lists (from
, count
, depth
, sexpflag
)
2414 int count
, depth
, sexpflag
;
2417 register int stop
= count
> 0 ? ZV
: BEGV
;
2422 register enum syntaxcode code
, temp_code
;
2423 int min_depth
= depth
; /* Err out if depth gets less than this. */
2424 int comstyle
= 0; /* style of comment encountered */
2425 int comnested
= 0; /* whether the comment is nestable or not */
2427 int last_good
= from
;
2430 int out_bytepos
, out_charpos
;
2432 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2434 if (depth
> 0) min_depth
= 0;
2436 if (from
> ZV
) from
= ZV
;
2437 if (from
< BEGV
) from
= BEGV
;
2439 from_byte
= CHAR_TO_BYTE (from
);
2444 SETUP_SYNTAX_TABLE (from
, count
);
2449 int comstart_first
, prefix
;
2450 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2451 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2452 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2453 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2454 comnested
= SYNTAX_COMMENT_NESTED (c
);
2455 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2456 prefix
= SYNTAX_PREFIX (c
);
2457 if (depth
== min_depth
)
2459 INC_BOTH (from
, from_byte
);
2460 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2461 if (from
< stop
&& comstart_first
2462 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2463 SYNTAX_COMSTART_SECOND (c
))
2464 && parse_sexp_ignore_comments
)
2466 /* we have encountered a comment start sequence and we
2467 are ignoring all text inside comments. We must record
2468 the comment style this sequence begins so that later,
2469 only a comment end of the same style actually ends
2470 the comment section */
2472 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2473 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2474 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2475 INC_BOTH (from
, from_byte
);
2476 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2482 switch (SWITCH_ENUM_CAST (code
))
2486 if (from
== stop
) goto lose
;
2487 INC_BOTH (from
, from_byte
);
2488 /* treat following character as a word constituent */
2491 if (depth
|| !sexpflag
) break;
2492 /* This word counts as a sexp; return at end of it. */
2495 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2497 /* Some compilers can't handle this inside the switch. */
2498 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2499 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2504 INC_BOTH (from
, from_byte
);
2505 if (from
== stop
) goto lose
;
2514 INC_BOTH (from
, from_byte
);
2518 case Scomment_fence
:
2519 comstyle
= ST_COMMENT_STYLE
;
2522 if (!parse_sexp_ignore_comments
) break;
2523 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2524 found
= forw_comment (from
, from_byte
, stop
,
2525 comnested
, comstyle
, 0,
2526 &out_charpos
, &out_bytepos
, &dummy
);
2527 from
= out_charpos
, from_byte
= out_bytepos
;
2534 INC_BOTH (from
, from_byte
);
2535 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2541 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2543 INC_BOTH (from
, from_byte
);
2553 if (!++depth
) goto done
;
2558 if (!--depth
) goto done
;
2559 if (depth
< min_depth
)
2560 Fsignal (Qscan_error
,
2561 Fcons (build_string ("Containing expression ends prematurely"),
2562 Fcons (make_number (last_good
),
2563 Fcons (make_number (from
), Qnil
))));
2568 temp_pos
= dec_bytepos (from_byte
);
2569 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2572 if (from
>= stop
) goto lose
;
2573 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2574 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2577 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2578 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2581 /* Some compilers can't handle this inside the switch. */
2582 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2587 INC_BOTH (from
, from_byte
);
2589 INC_BOTH (from
, from_byte
);
2591 INC_BOTH (from
, from_byte
);
2592 if (!depth
&& sexpflag
) goto done
;
2595 /* Ignore whitespace, punctuation, quote, endcomment. */
2600 /* Reached end of buffer. Error if within object, return nil if between */
2601 if (depth
) goto lose
;
2606 /* End of object reached */
2615 DEC_BOTH (from
, from_byte
);
2616 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2617 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2618 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2619 if (depth
== min_depth
)
2622 comnested
= SYNTAX_COMMENT_NESTED (c
);
2623 if (code
== Sendcomment
)
2624 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2625 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2626 && prev_char_comend_first (from
, from_byte
)
2627 && parse_sexp_ignore_comments
)
2629 /* We must record the comment style encountered so that
2630 later, we can match only the proper comment begin
2631 sequence of the same style. */
2632 DEC_BOTH (from
, from_byte
);
2633 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2635 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2636 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2637 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2640 /* Quoting turns anything except a comment-ender
2641 into a word character. Note that this cannot be true
2642 if we decremented FROM in the if-statement above. */
2643 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2645 DEC_BOTH (from
, from_byte
);
2648 else if (SYNTAX_PREFIX (c
))
2651 switch (SWITCH_ENUM_CAST (code
))
2657 if (depth
|| !sexpflag
) break;
2658 /* This word counts as a sexp; count object finished
2659 after passing it. */
2662 temp_pos
= from_byte
;
2663 if (! NILP (current_buffer
->enable_multibyte_characters
))
2667 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2668 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2669 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2670 /* Don't allow comment-end to be quoted. */
2671 if (temp_code
== Sendcomment
)
2673 quoted
= char_quoted (from
- 1, temp_pos
);
2676 DEC_BOTH (from
, from_byte
);
2677 temp_pos
= dec_bytepos (temp_pos
);
2678 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2680 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2681 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2682 if (! (quoted
|| temp_code
== Sword
2683 || temp_code
== Ssymbol
2684 || temp_code
== Squote
))
2686 DEC_BOTH (from
, from_byte
);
2693 temp_pos
= dec_bytepos (from_byte
);
2694 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2695 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2696 DEC_BOTH (from
, from_byte
);
2705 if (!++depth
) goto done2
;
2710 if (!--depth
) goto done2
;
2711 if (depth
< min_depth
)
2712 Fsignal (Qscan_error
,
2713 Fcons (build_string ("Containing expression ends prematurely"),
2714 Fcons (make_number (last_good
),
2715 Fcons (make_number (from
), Qnil
))));
2719 if (!parse_sexp_ignore_comments
)
2721 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2722 &out_charpos
, &out_bytepos
);
2723 /* FIXME: if found == -1, then it really wasn't a comment-end.
2724 For single-char Sendcomment, we can't do much about it apart
2725 from skipping the char.
2726 For 2-char endcomments, we could try again, taking both
2727 chars as separate entities, but it's a lot of trouble
2728 for very little gain, so we don't bother either. -sm */
2730 from
= out_charpos
, from_byte
= out_bytepos
;
2733 case Scomment_fence
:
2737 if (from
== stop
) goto lose
;
2738 DEC_BOTH (from
, from_byte
);
2739 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2740 if (!char_quoted (from
, from_byte
)
2741 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2742 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2745 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2749 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2752 if (from
== stop
) goto lose
;
2753 DEC_BOTH (from
, from_byte
);
2754 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2755 if (!char_quoted (from
, from_byte
)
2757 == (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
)))
2758 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2761 if (!depth
&& sexpflag
) goto done2
;
2764 /* Ignore whitespace, punctuation, quote, endcomment. */
2769 /* Reached start of buffer. Error if within object, return nil if between */
2770 if (depth
) goto lose
;
2781 XSETFASTINT (val
, from
);
2785 Fsignal (Qscan_error
,
2786 Fcons (build_string ("Unbalanced parentheses"),
2787 Fcons (make_number (last_good
),
2788 Fcons (make_number (from
), Qnil
))));
2793 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2794 doc
: /* Scan from character number FROM by COUNT lists.
2795 Returns the character number of the position thus found.
2797 If DEPTH is nonzero, paren depth begins counting from that value,
2798 only places where the depth in parentheses becomes zero
2799 are candidates for stopping; COUNT such places are counted.
2800 Thus, a positive value for DEPTH means go out levels.
2802 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2804 If the beginning or end of (the accessible part of) the buffer is reached
2805 and the depth is wrong, an error is signaled.
2806 If the depth is right but the count is not used up, nil is returned. */)
2807 (from
, count
, depth
)
2808 Lisp_Object from
, count
, depth
;
2810 CHECK_NUMBER (from
);
2811 CHECK_NUMBER (count
);
2812 CHECK_NUMBER (depth
);
2814 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2817 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2818 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2819 If COUNT is negative, scan backwards.
2820 Returns the character number of the position thus found.
2822 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2824 If the beginning or end of (the accessible part of) the buffer is reached
2825 in the middle of a parenthetical grouping, an error is signaled.
2826 If the beginning or end is reached between groupings
2827 but before count is used up, nil is returned. */)
2829 Lisp_Object from
, count
;
2831 CHECK_NUMBER (from
);
2832 CHECK_NUMBER (count
);
2834 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2837 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2839 doc
: /* Move point backward over any number of chars with prefix syntax.
2840 This includes chars with "quote" or "prefix" syntax (' or p). */)
2845 int opoint_byte
= PT_BYTE
;
2847 int pos_byte
= PT_BYTE
;
2852 SET_PT_BOTH (opoint
, opoint_byte
);
2857 SETUP_SYNTAX_TABLE (pos
, -1);
2859 DEC_BOTH (pos
, pos_byte
);
2861 while (!char_quoted (pos
, pos_byte
)
2862 /* Previous statement updates syntax table. */
2863 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2864 || SYNTAX_PREFIX (c
)))
2867 opoint_byte
= pos_byte
;
2870 DEC_BOTH (pos
, pos_byte
);
2873 SET_PT_BOTH (opoint
, opoint_byte
);
2878 /* Parse forward from FROM / FROM_BYTE to END,
2879 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2880 and return a description of the state of the parse at END.
2881 If STOPBEFORE is nonzero, stop at the start of an atom.
2882 If COMMENTSTOP is 1, stop at the start of a comment.
2883 If COMMENTSTOP is -1, stop at the start or end of a comment,
2884 after the beginning of a string, or after the end of a string. */
2887 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2888 stopbefore
, oldstate
, commentstop
)
2889 struct lisp_parse_state
*stateptr
;
2892 int end
, targetdepth
, stopbefore
;
2893 Lisp_Object oldstate
;
2896 struct lisp_parse_state state
;
2898 register enum syntaxcode code
;
2901 struct level
{ int last
, prev
; };
2902 struct level levelstart
[100];
2903 register struct level
*curlevel
= levelstart
;
2904 struct level
*endlevel
= levelstart
+ 100;
2905 register int depth
; /* Paren depth of current scanning location.
2906 level - levelstart equals this except
2907 when the depth becomes negative. */
2908 int mindepth
; /* Lowest DEPTH value seen. */
2909 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2911 int prev_from
; /* Keep one character before FROM. */
2913 int prev_from_syntax
;
2914 int boundary_stop
= commentstop
== -1;
2917 int out_bytepos
, out_charpos
;
2921 prev_from_byte
= from_byte
;
2923 DEC_BOTH (prev_from
, prev_from_byte
);
2925 /* Use this macro instead of `from++'. */
2927 do { prev_from = from; \
2928 prev_from_byte = from_byte; \
2929 temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
2930 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
2931 INC_BOTH (from, from_byte); \
2933 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2939 if (NILP (oldstate
))
2942 state
.instring
= -1;
2943 state
.incomment
= 0;
2944 state
.comstyle
= 0; /* comment style a by default. */
2945 state
.comstr_start
= -1; /* no comment/string seen. */
2949 tem
= Fcar (oldstate
);
2955 oldstate
= Fcdr (oldstate
);
2956 oldstate
= Fcdr (oldstate
);
2957 oldstate
= Fcdr (oldstate
);
2958 tem
= Fcar (oldstate
);
2959 /* Check whether we are inside string_fence-style string: */
2960 state
.instring
= (!NILP (tem
)
2961 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2964 oldstate
= Fcdr (oldstate
);
2965 tem
= Fcar (oldstate
);
2966 state
.incomment
= (!NILP (tem
)
2967 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
2970 oldstate
= Fcdr (oldstate
);
2971 tem
= Fcar (oldstate
);
2972 start_quoted
= !NILP (tem
);
2974 /* if the eighth element of the list is nil, we are in comment
2975 style a. If it is non-nil, we are in comment style b */
2976 oldstate
= Fcdr (oldstate
);
2977 oldstate
= Fcdr (oldstate
);
2978 tem
= Fcar (oldstate
);
2979 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
2980 ? ST_COMMENT_STYLE
: 1);
2982 oldstate
= Fcdr (oldstate
);
2983 tem
= Fcar (oldstate
);
2984 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2985 oldstate
= Fcdr (oldstate
);
2986 tem
= Fcar (oldstate
);
2987 while (!NILP (tem
)) /* >= second enclosing sexps. */
2989 /* curlevel++->last ran into compiler bug on Apollo */
2990 curlevel
->last
= XINT (Fcar (tem
));
2991 if (++curlevel
== endlevel
)
2992 curlevel
--; /* error ("Nesting too deep for parser"); */
2993 curlevel
->prev
= -1;
2994 curlevel
->last
= -1;
3001 curlevel
->prev
= -1;
3002 curlevel
->last
= -1;
3004 SETUP_SYNTAX_TABLE (prev_from
, 1);
3005 temp
= FETCH_CHAR (prev_from_byte
);
3006 prev_from_syntax
= SYNTAX_WITH_FLAGS (temp
);
3007 UPDATE_SYNTAX_TABLE_FORWARD (from
);
3009 /* Enter the loop at a place appropriate for initial state. */
3011 if (state
.incomment
)
3012 goto startincomment
;
3013 if (state
.instring
>= 0)
3015 nofence
= state
.instring
!= ST_STRING_STYLE
;
3017 goto startquotedinstring
;
3020 else if (start_quoted
)
3026 code
= prev_from_syntax
& 0xff;
3029 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
)
3030 && (c1
= FETCH_CHAR (from_byte
),
3031 SYNTAX_COMSTART_SECOND (c1
)))
3032 /* Duplicate code to avoid a complex if-expression
3033 which causes trouble for the SGI compiler. */
3035 /* Record the comment style we have entered so that only
3036 the comment-end sequence of the same style actually
3037 terminates the comment section. */
3038 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
3039 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
3040 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
3041 state
.incomment
= comnested
? 1 : -1;
3042 state
.comstr_start
= prev_from
;
3046 else if (code
== Scomment_fence
)
3048 /* Record the comment style we have entered so that only
3049 the comment-end sequence of the same style actually
3050 terminates the comment section. */
3051 state
.comstyle
= ST_COMMENT_STYLE
;
3052 state
.incomment
= -1;
3053 state
.comstr_start
= prev_from
;
3056 else if (code
== Scomment
)
3058 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
3059 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
3061 state
.comstr_start
= prev_from
;
3064 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
3066 switch (SWITCH_ENUM_CAST (code
))
3070 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3071 curlevel
->last
= prev_from
;
3073 if (from
== end
) goto endquoted
;
3076 /* treat following character as a word constituent */
3079 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3080 curlevel
->last
= prev_from
;
3084 /* Some compilers can't handle this inside the switch. */
3085 temp
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3086 temp
= SYNTAX (temp
);
3092 if (from
== end
) goto endquoted
;
3104 curlevel
->prev
= curlevel
->last
;
3107 case Scomment_fence
: /* Can't happen because it's handled above. */
3109 if (commentstop
|| boundary_stop
) goto done
;
3111 /* The (from == BEGV) test was to enter the loop in the middle so
3112 that we find a 2-char comment ender even if we start in the
3113 middle of it. We don't want to do that if we're just at the
3114 beginning of the comment (think of (*) ... (*)). */
3115 found
= forw_comment (from
, from_byte
, end
,
3116 state
.incomment
, state
.comstyle
,
3117 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
3118 ? 0 : prev_from_syntax
,
3119 &out_charpos
, &out_bytepos
, &state
.incomment
);
3120 from
= out_charpos
; from_byte
= out_bytepos
;
3121 /* Beware! prev_from and friends are invalid now.
3122 Luckily, the `done' doesn't use them and the INC_FROM
3123 sets them to a sane value without looking at them. */
3124 if (!found
) goto done
;
3126 state
.incomment
= 0;
3127 state
.comstyle
= 0; /* reset the comment style */
3128 if (boundary_stop
) goto done
;
3132 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3134 /* curlevel++->last ran into compiler bug on Apollo */
3135 curlevel
->last
= prev_from
;
3136 if (++curlevel
== endlevel
)
3137 curlevel
--; /* error ("Nesting too deep for parser"); */
3138 curlevel
->prev
= -1;
3139 curlevel
->last
= -1;
3140 if (targetdepth
== depth
) goto done
;
3145 if (depth
< mindepth
)
3147 if (curlevel
!= levelstart
)
3149 curlevel
->prev
= curlevel
->last
;
3150 if (targetdepth
== depth
) goto done
;
3155 state
.comstr_start
= from
- 1;
3156 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3157 curlevel
->last
= prev_from
;
3158 state
.instring
= (code
== Sstring
3159 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3161 if (boundary_stop
) goto done
;
3164 nofence
= state
.instring
!= ST_STRING_STYLE
;
3170 if (from
>= end
) goto done
;
3171 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3172 /* Some compilers can't handle this inside the switch. */
3175 /* Check TEMP here so that if the char has
3176 a syntax-table property which says it is NOT
3177 a string character, it does not end the string. */
3178 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3184 if (!nofence
) goto string_end
;
3189 startquotedinstring
:
3190 if (from
>= end
) goto endquoted
;
3196 state
.instring
= -1;
3197 curlevel
->prev
= curlevel
->last
;
3199 if (boundary_stop
) goto done
;
3203 /* FIXME: We should do something with it. */
3206 /* Ignore whitespace, punctuation, quote, endcomment. */
3212 stop
: /* Here if stopping before start of sexp. */
3213 from
= prev_from
; /* We have just fetched the char that starts it; */
3214 goto done
; /* but return the position before it. */
3219 state
.depth
= depth
;
3220 state
.mindepth
= mindepth
;
3221 state
.thislevelstart
= curlevel
->prev
;
3222 state
.prevlevelstart
3223 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3224 state
.location
= from
;
3225 state
.levelstarts
= Qnil
;
3226 while (--curlevel
>= levelstart
)
3227 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3234 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3235 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3236 Parsing stops at TO or when certain criteria are met;
3237 point is set to where parsing stops.
3238 If fifth arg OLDSTATE is omitted or nil,
3239 parsing assumes that FROM is the beginning of a function.
3240 Value is a list of ten elements describing final state of parsing:
3242 1. character address of start of innermost containing list; nil if none.
3243 2. character address of start of last complete sexp terminated.
3244 3. non-nil if inside a string.
3245 (it is the character that will terminate the string,
3246 or t if the string should be terminated by a generic string delimiter.)
3247 4. nil if outside a comment, t if inside a non-nestable comment,
3248 else an integer (the current comment nesting).
3249 5. t if following a quote character.
3250 6. the minimum paren-depth encountered during this scan.
3251 7. t if in a comment of style b; symbol `syntax-table' if the comment
3252 should be terminated by a generic comment delimiter.
3253 8. character address of start of comment or string; nil if not in one.
3254 9. Intermediate data for continuation of parsing (subject to change).
3255 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3256 in parentheses becomes equal to TARGETDEPTH.
3257 Fourth arg STOPBEFORE non-nil means stop when come to
3258 any character that starts a sexp.
3259 Fifth arg OLDSTATE is a nine-element list like what this function returns.
3260 It is used to initialize the state of the parse. Elements number 1, 2, 6
3261 and 8 are ignored; you can leave off element 8 (the last) entirely.
3262 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3263 If it is symbol `syntax-table', stop after the start of a comment or a
3264 string, or after end of a comment or a string. */)
3265 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3266 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3268 struct lisp_parse_state state
;
3271 if (!NILP (targetdepth
))
3273 CHECK_NUMBER (targetdepth
);
3274 target
= XINT (targetdepth
);
3277 target
= -100000; /* We won't reach this depth */
3279 validate_region (&from
, &to
);
3280 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3282 target
, !NILP (stopbefore
), oldstate
,
3284 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3286 SET_PT (state
.location
);
3288 return Fcons (make_number (state
.depth
),
3289 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3290 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3291 Fcons (state
.instring
>= 0
3292 ? (state
.instring
== ST_STRING_STYLE
3293 ? Qt
: make_number (state
.instring
)) : Qnil
,
3294 Fcons (state
.incomment
< 0 ? Qt
:
3295 (state
.incomment
== 0 ? Qnil
:
3296 make_number (state
.incomment
)),
3297 Fcons (state
.quoted
? Qt
: Qnil
,
3298 Fcons (make_number (state
.mindepth
),
3299 Fcons ((state
.comstyle
3300 ? (state
.comstyle
== ST_COMMENT_STYLE
3301 ? Qsyntax_table
: Qt
) :
3303 Fcons (((state
.incomment
3304 || (state
.instring
>= 0))
3305 ? make_number (state
.comstr_start
)
3307 Fcons (state
.levelstarts
, Qnil
))))))))));
3316 /* This has to be done here, before we call Fmake_char_table. */
3317 Qsyntax_table
= intern ("syntax-table");
3318 staticpro (&Qsyntax_table
);
3320 /* Intern this now in case it isn't already done.
3321 Setting this variable twice is harmless.
3322 But don't staticpro it here--that is done in alloc.c. */
3323 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3325 /* Create objects which can be shared among syntax tables. */
3326 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3327 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3328 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3329 = Fcons (make_number (i
), Qnil
);
3331 /* Now we are ready to set up this property, so we can
3332 create syntax tables. */
3333 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3335 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3337 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3339 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3340 for (i
= 'a'; i
<= 'z'; i
++)
3341 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3342 for (i
= 'A'; i
<= 'Z'; i
++)
3343 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3344 for (i
= '0'; i
<= '9'; i
++)
3345 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3347 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3348 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3350 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3351 Fcons (make_number (Sopen
), make_number (')')));
3352 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3353 Fcons (make_number (Sclose
), make_number ('(')));
3354 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3355 Fcons (make_number (Sopen
), make_number (']')));
3356 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3357 Fcons (make_number (Sclose
), make_number ('[')));
3358 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3359 Fcons (make_number (Sopen
), make_number ('}')));
3360 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3361 Fcons (make_number (Sclose
), make_number ('{')));
3362 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3363 Fcons (make_number ((int) Sstring
), Qnil
));
3364 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3365 Fcons (make_number ((int) Sescape
), Qnil
));
3367 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3368 for (i
= 0; i
< 10; i
++)
3370 c
= "_-+*/&|<>="[i
];
3371 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3374 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3375 for (i
= 0; i
< 12; i
++)
3377 c
= ".,;:?!#@~^'`"[i
];
3378 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3381 /* All multibyte characters have syntax `word' by default. */
3382 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3383 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3389 Qsyntax_table_p
= intern ("syntax-table-p");
3390 staticpro (&Qsyntax_table_p
);
3392 staticpro (&Vsyntax_code_object
);
3394 Qscan_error
= intern ("scan-error");
3395 staticpro (&Qscan_error
);
3396 Fput (Qscan_error
, Qerror_conditions
,
3397 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3398 Fput (Qscan_error
, Qerror_message
,
3399 build_string ("Scan error"));
3401 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3402 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3404 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3405 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3406 Otherwise, that text property is simply ignored.
3407 See the info node `(elisp)Syntax Properties' for a description of the
3408 `syntax-table' property. */);
3410 words_include_escapes
= 0;
3411 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3412 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3414 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3415 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3416 multibyte_syntax_as_symbol
= 0;
3418 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3419 &open_paren_in_column_0_is_defun_start
,
3420 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3421 open_paren_in_column_0_is_defun_start
= 1;
3424 DEFVAR_LISP ("find-word-boundary-function-table",
3425 &Vfind_word_boundary_function_table
,
3427 Char table of functions to search for the word boundary.
3428 Each function is called with two arguments; POS and LIMIT.
3429 POS and LIMIT are character positions in the current buffer.
3431 If POS is less than LIMIT, POS is at the first character of a word,
3432 and the return value of a function is a position after the last
3433 character of that word.
3435 If POS is not less than LIMIT, POS is at the last character of a word,
3436 and the return value of a function is a position at the first
3437 character of that word.
3439 In both cases, LIMIT bounds the search. */);
3440 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3442 defsubr (&Ssyntax_table_p
);
3443 defsubr (&Ssyntax_table
);
3444 defsubr (&Sstandard_syntax_table
);
3445 defsubr (&Scopy_syntax_table
);
3446 defsubr (&Sset_syntax_table
);
3447 defsubr (&Schar_syntax
);
3448 defsubr (&Smatching_paren
);
3449 defsubr (&Sstring_to_syntax
);
3450 defsubr (&Smodify_syntax_entry
);
3451 defsubr (&Sinternal_describe_syntax_value
);
3453 defsubr (&Sforward_word
);
3455 defsubr (&Sskip_chars_forward
);
3456 defsubr (&Sskip_chars_backward
);
3457 defsubr (&Sskip_syntax_forward
);
3458 defsubr (&Sskip_syntax_backward
);
3460 defsubr (&Sforward_comment
);
3461 defsubr (&Sscan_lists
);
3462 defsubr (&Sscan_sexps
);
3463 defsubr (&Sbackward_prefix_chars
);
3464 defsubr (&Sparse_partial_sexp
);
3467 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
3468 (do not change this comment) */