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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, 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. */)
1326 XSETFASTINT (arg
, 1);
1330 val
= orig_val
= scan_words (PT
, XINT (arg
));
1332 val
= XINT (arg
) > 0 ? ZV
: BEGV
;
1334 /* Avoid jumping out of an input field. */
1335 val
= XFASTINT (Fconstrain_to_field (make_number (val
), make_number (PT
),
1339 return val
== orig_val
? Qt
: Qnil
;
1342 Lisp_Object
skip_chars ();
1344 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1345 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1346 STRING is like the inside of a `[...]' in a regular expression
1347 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1348 (but not as the end of a range; quoting is never needed there).
1349 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1350 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1351 Char classes, e.g. `[:alpha:]', are supported.
1353 Returns the distance traveled, either zero or positive. */)
1355 Lisp_Object string
, lim
;
1357 return skip_chars (1, string
, lim
, 1);
1360 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1361 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1362 See `skip-chars-forward' for details.
1363 Returns the distance traveled, either zero or negative. */)
1365 Lisp_Object string
, lim
;
1367 return skip_chars (0, string
, lim
, 1);
1370 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1371 doc
: /* Move point forward across chars in specified syntax classes.
1372 SYNTAX is a string of syntax code characters.
1373 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1374 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1375 This function returns the distance traveled, either zero or positive. */)
1377 Lisp_Object syntax
, lim
;
1379 return skip_syntaxes (1, syntax
, lim
);
1382 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1383 doc
: /* Move point backward across chars in specified syntax classes.
1384 SYNTAX is a string of syntax code characters.
1385 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1386 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1387 This function returns the distance traveled, either zero or negative. */)
1389 Lisp_Object syntax
, lim
;
1391 return skip_syntaxes (0, syntax
, lim
);
1395 skip_chars (forwardp
, string
, lim
, handle_iso_classes
)
1397 Lisp_Object string
, lim
;
1398 int handle_iso_classes
;
1400 register unsigned int c
;
1401 unsigned char fastmap
[0400];
1402 /* Store the ranges of non-ASCII characters. */
1404 int n_char_ranges
= 0;
1406 register int i
, i_byte
;
1407 /* Set to 1 if the current buffer is multibyte and the region
1408 contains non-ASCII chars. */
1410 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1412 int string_multibyte
;
1414 const unsigned char *str
;
1416 Lisp_Object iso_classes
;
1418 CHECK_STRING (string
);
1422 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1424 CHECK_NUMBER_COERCE_MARKER (lim
);
1426 /* In any case, don't allow scan outside bounds of buffer. */
1427 if (XINT (lim
) > ZV
)
1428 XSETFASTINT (lim
, ZV
);
1429 if (XINT (lim
) < BEGV
)
1430 XSETFASTINT (lim
, BEGV
);
1432 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1433 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1434 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1436 bzero (fastmap
, sizeof fastmap
);
1438 str
= SDATA (string
);
1439 size_byte
= SBYTES (string
);
1442 if (i_byte
< size_byte
1443 && SREF (string
, 0) == '^')
1445 negate
= 1; i_byte
++;
1448 /* Find the characters specified and set their elements of fastmap.
1449 Handle backslashes and ranges specially.
1451 If STRING contains non-ASCII characters, setup char_ranges for
1452 them and use fastmap only for their leading codes. */
1454 if (! string_multibyte
)
1456 int string_has_eight_bit
= 0;
1458 /* At first setup fastmap. */
1459 while (i_byte
< size_byte
)
1463 if (handle_iso_classes
&& c
== '['
1464 && i_byte
< size_byte
1465 && str
[i_byte
] == ':')
1467 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1468 const unsigned char *class_end
= class_beg
;
1469 const unsigned char *class_limit
= str
+ size_byte
- 2;
1470 /* Leave room for the null. */
1471 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1474 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1475 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1477 while (class_end
< class_limit
1478 && *class_end
>= 'a' && *class_end
<= 'z')
1481 if (class_end
== class_beg
1482 || *class_end
!= ':' || class_end
[1] != ']')
1483 goto not_a_class_name
;
1485 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1486 class_name
[class_end
- class_beg
] = 0;
1488 cc
= re_wctype (class_name
);
1490 error ("Invalid ISO C character class");
1492 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1494 i_byte
= class_end
+ 2 - str
;
1501 if (i_byte
== size_byte
)
1506 /* Treat `-' as range character only if another character
1508 if (i_byte
+ 1 < size_byte
1509 && str
[i_byte
] == '-')
1513 /* Skip over the dash. */
1516 /* Get the end of the range. */
1519 && i_byte
< size_byte
)
1526 if (! ASCII_CHAR_P (c2
))
1527 string_has_eight_bit
= 1;
1533 if (! ASCII_CHAR_P (c
))
1534 string_has_eight_bit
= 1;
1538 /* If the current range is multibyte and STRING contains
1539 eight-bit chars, arrange fastmap and setup char_ranges for
1540 the corresponding multibyte chars. */
1541 if (multibyte
&& string_has_eight_bit
)
1543 unsigned char fastmap2
[0400];
1544 int range_start_byte
, range_start_char
;
1546 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1547 bzero (fastmap
+ 0200, 0200);
1548 /* We are sure that this loop stops. */
1549 for (i
= 0200; ! fastmap2
[i
]; i
++);
1550 c
= unibyte_char_to_multibyte (i
);
1551 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1552 range_start_byte
= i
;
1553 range_start_char
= c
;
1554 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1555 for (i
= 129; i
< 0400; i
++)
1557 c
= unibyte_char_to_multibyte (i
);
1558 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1559 if (i
- range_start_byte
!= c
- range_start_char
)
1561 char_ranges
[n_char_ranges
++] = range_start_char
;
1562 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1563 + range_start_char
);
1564 range_start_byte
= i
;
1565 range_start_char
= c
;
1568 char_ranges
[n_char_ranges
++] = range_start_char
;
1569 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1570 + range_start_char
);
1573 else /* STRING is multibyte */
1575 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1577 while (i_byte
< size_byte
)
1579 unsigned char leading_code
;
1581 leading_code
= str
[i_byte
];
1582 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1585 if (handle_iso_classes
&& c
== '['
1586 && i_byte
< size_byte
1587 && STRING_CHAR (str
+ i_byte
, size_byte
- i_byte
) == ':')
1589 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1590 const unsigned char *class_end
= class_beg
;
1591 const unsigned char *class_limit
= str
+ size_byte
- 2;
1592 /* Leave room for the null. */
1593 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1596 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1597 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1599 while (class_end
< class_limit
1600 && *class_end
>= 'a' && *class_end
<= 'z')
1603 if (class_end
== class_beg
1604 || *class_end
!= ':' || class_end
[1] != ']')
1605 goto not_a_class_name_multibyte
;
1607 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1608 class_name
[class_end
- class_beg
] = 0;
1610 cc
= re_wctype (class_name
);
1612 error ("Invalid ISO C character class");
1614 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1616 i_byte
= class_end
+ 2 - str
;
1620 not_a_class_name_multibyte
:
1623 if (i_byte
== size_byte
)
1626 leading_code
= str
[i_byte
];
1627 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1628 size_byte
- i_byte
, len
);
1631 /* Treat `-' as range character only if another character
1633 if (i_byte
+ 1 < size_byte
1634 && str
[i_byte
] == '-')
1637 unsigned char leading_code2
;
1639 /* Skip over the dash. */
1642 /* Get the end of the range. */
1643 leading_code2
= str
[i_byte
];
1644 c2
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1645 size_byte
- i_byte
, len
);
1649 && i_byte
< size_byte
)
1651 leading_code2
= str
[i_byte
];
1652 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1658 if (ASCII_CHAR_P (c
))
1660 while (c
<= c2
&& c
< 0x80)
1662 leading_code
= CHAR_LEADING_CODE (c
);
1664 if (! ASCII_CHAR_P (c
))
1666 while (leading_code
<= leading_code2
)
1667 fastmap
[leading_code
++] = 1;
1670 char_ranges
[n_char_ranges
++] = c
;
1671 char_ranges
[n_char_ranges
++] = c2
;
1677 if (ASCII_CHAR_P (c
))
1681 fastmap
[leading_code
] = 1;
1682 char_ranges
[n_char_ranges
++] = c
;
1683 char_ranges
[n_char_ranges
++] = c
;
1688 /* If the current range is unibyte and STRING contains non-ASCII
1689 chars, arrange fastmap for the corresponding unibyte
1692 if (! multibyte
&& n_char_ranges
> 0)
1694 bzero (fastmap
+ 0200, 0200);
1695 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1697 int c1
= char_ranges
[i
];
1698 int c2
= char_ranges
[i
+ 1];
1700 for (; c1
<= c2
; c1
++)
1701 fastmap
[CHAR_TO_BYTE8 (c1
)] = 1;
1706 /* If ^ was the first character, complement the fastmap. */
1710 for (i
= 0; i
< sizeof fastmap
; i
++)
1714 for (i
= 0; i
< 0200; i
++)
1716 /* All non-ASCII chars possibly match. */
1717 for (; i
< sizeof fastmap
; i
++)
1723 int start_point
= PT
;
1725 int pos_byte
= PT_BYTE
;
1726 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1730 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1731 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1735 endp
= CHAR_POS_ADDR (XINT (lim
));
1736 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1754 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1755 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1765 if (! ASCII_CHAR_P (c
))
1767 /* As we are looking at a multibyte character, we
1768 must look up the character in the table
1769 CHAR_RANGES. If there's no data in the table,
1770 that character is not what we want to skip. */
1772 /* The following code do the right thing even if
1773 n_char_ranges is zero (i.e. no data in
1775 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1776 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1778 if (!(negate
^ (i
< n_char_ranges
)))
1782 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1795 if (!NILP (iso_classes
) && in_classes (*p
, iso_classes
))
1800 goto fwd_unibyte_ok
;
1806 p
++, pos
++, pos_byte
++;
1814 unsigned char *prev_p
;
1824 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1825 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1827 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1837 if (! ASCII_CHAR_P (c
))
1839 /* See the comment in the previous similar code. */
1840 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1841 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1843 if (!(negate
^ (i
< n_char_ranges
)))
1847 pos
--, pos_byte
-= prev_p
- p
;
1860 if (! NILP (iso_classes
) && in_classes (p
[-1], iso_classes
))
1865 goto back_unibyte_ok
;
1868 if (!fastmap
[p
[-1]])
1871 p
--, pos
--, pos_byte
--;
1875 SET_PT_BOTH (pos
, pos_byte
);
1878 return make_number (PT
- start_point
);
1884 skip_syntaxes (forwardp
, string
, lim
)
1886 Lisp_Object string
, lim
;
1888 register unsigned int c
;
1889 unsigned char fastmap
[0400];
1891 register int i
, i_byte
;
1896 CHECK_STRING (string
);
1899 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1901 CHECK_NUMBER_COERCE_MARKER (lim
);
1903 /* In any case, don't allow scan outside bounds of buffer. */
1904 if (XINT (lim
) > ZV
)
1905 XSETFASTINT (lim
, ZV
);
1906 if (XINT (lim
) < BEGV
)
1907 XSETFASTINT (lim
, BEGV
);
1909 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1912 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1913 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1915 bzero (fastmap
, sizeof fastmap
);
1917 if (SBYTES (string
) > SCHARS (string
))
1918 /* As this is very rare case (syntax spec is ASCII only), don't
1919 consider efficiency. */
1920 string
= string_make_unibyte (string
);
1922 str
= SDATA (string
);
1923 size_byte
= SBYTES (string
);
1926 if (i_byte
< size_byte
1927 && SREF (string
, 0) == '^')
1929 negate
= 1; i_byte
++;
1932 /* Find the syntaxes specified and set their elements of fastmap. */
1934 while (i_byte
< size_byte
)
1937 fastmap
[syntax_spec_code
[c
]] = 1;
1940 /* If ^ was the first character, complement the fastmap. */
1942 for (i
= 0; i
< sizeof fastmap
; i
++)
1946 int start_point
= PT
;
1948 int pos_byte
= PT_BYTE
;
1949 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1953 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1954 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1958 endp
= CHAR_POS_ADDR (XINT (lim
));
1959 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1963 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1979 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1980 if (! fastmap
[(int) SYNTAX (c
)])
1982 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1983 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1997 if (! fastmap
[(int) SYNTAX (*p
)])
1999 p
++, pos
++, pos_byte
++;
2000 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2010 unsigned char *prev_p
;
2020 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
2021 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
2022 if (! fastmap
[(int) SYNTAX (c
)])
2024 pos
--, pos_byte
-= prev_p
- p
;
2025 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
2039 if (! fastmap
[(int) SYNTAX (p
[-1])])
2041 p
--, pos
--, pos_byte
--;
2042 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2047 SET_PT_BOTH (pos
, pos_byte
);
2050 return make_number (PT
- start_point
);
2054 /* Return 1 if character C belongs to one of the ISO classes
2055 in the list ISO_CLASSES. Each class is represented by an
2056 integer which is its type according to re_wctype. */
2059 in_classes (c
, iso_classes
)
2061 Lisp_Object iso_classes
;
2065 while (! NILP (iso_classes
))
2068 elt
= XCAR (iso_classes
);
2069 iso_classes
= XCDR (iso_classes
);
2071 if (re_iswctype (c
, XFASTINT (elt
)))
2078 /* Jump over a comment, assuming we are at the beginning of one.
2079 FROM is the current position.
2080 FROM_BYTE is the bytepos corresponding to FROM.
2081 Do not move past STOP (a charpos).
2082 The comment over which we have to jump is of style STYLE
2083 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2084 NESTING should be positive to indicate the nesting at the beginning
2085 for nested comments and should be zero or negative else.
2086 ST_COMMENT_STYLE cannot be nested.
2087 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
2088 (or 0 If the search cannot start in the middle of a two-character).
2090 If successful, return 1 and store the charpos of the comment's end
2091 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
2092 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
2093 corresponding bytepos into *BYTEPOS_PTR and the current nesting
2094 (as defined for state.incomment) in *INCOMMENT_PTR.
2096 The comment end is the last character of the comment rather than the
2097 character just after the comment.
2099 Global syntax data is assumed to initially be valid for FROM and
2100 remains valid for forward search starting at the returned position. */
2103 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
2104 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
2105 int from
, from_byte
, stop
;
2106 int nesting
, style
, prev_syntax
;
2107 int *charpos_ptr
, *bytepos_ptr
, *incomment_ptr
;
2110 register enum syntaxcode code
;
2111 register int syntax
;
2113 if (nesting
<= 0) nesting
= -1;
2115 /* Enter the loop in the middle so that we find
2116 a 2-char comment ender if we start in the middle of it. */
2117 syntax
= prev_syntax
;
2118 if (syntax
!= 0) goto forw_incomment
;
2124 *incomment_ptr
= nesting
;
2125 *charpos_ptr
= from
;
2126 *bytepos_ptr
= from_byte
;
2129 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2130 syntax
= SYNTAX_WITH_FLAGS (c
);
2131 code
= syntax
& 0xff;
2132 if (code
== Sendcomment
2133 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2134 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
2135 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
2136 /* we have encountered a comment end of the same style
2137 as the comment sequence which began this comment
2140 if (code
== Scomment_fence
2141 && style
== ST_COMMENT_STYLE
)
2142 /* we have encountered a comment end of the same style
2143 as the comment sequence which began this comment
2148 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
2149 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
2150 /* we have encountered a nested comment of the same style
2151 as the comment sequence which began this comment section */
2153 INC_BOTH (from
, from_byte
);
2154 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2157 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2158 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2159 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2160 SYNTAX_COMEND_SECOND (c1
))
2161 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2162 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2165 /* we have encountered a comment end of the same style
2166 as the comment sequence which began this comment
2171 INC_BOTH (from
, from_byte
);
2172 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2177 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2178 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2179 SYNTAX_COMMENT_STYLE (c1
) == style
2180 && SYNTAX_COMSTART_SECOND (c1
))
2181 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2182 SYNTAX_COMMENT_NESTED (c1
)))
2183 /* we have encountered a nested comment of the same style
2184 as the comment sequence which began this comment
2187 INC_BOTH (from
, from_byte
);
2188 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2192 *charpos_ptr
= from
;
2193 *bytepos_ptr
= from_byte
;
2197 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2199 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2200 Stop scanning if we find something other than a comment or whitespace.
2201 Set point to where scanning stops.
2202 If COUNT comments are found as expected, with nothing except whitespace
2203 between them, return t; otherwise return nil. */)
2211 register enum syntaxcode code
;
2212 int comstyle
= 0; /* style of comment encountered */
2213 int comnested
= 0; /* whether the comment is nestable or not */
2216 int out_charpos
, out_bytepos
;
2219 CHECK_NUMBER (count
);
2220 count1
= XINT (count
);
2221 stop
= count1
> 0 ? ZV
: BEGV
;
2227 from_byte
= PT_BYTE
;
2229 SETUP_SYNTAX_TABLE (from
, count1
);
2238 SET_PT_BOTH (from
, from_byte
);
2242 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2244 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2245 comnested
= SYNTAX_COMMENT_NESTED (c
);
2246 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2247 INC_BOTH (from
, from_byte
);
2248 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2249 if (from
< stop
&& comstart_first
2250 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2251 SYNTAX_COMSTART_SECOND (c1
)))
2253 /* We have encountered a comment start sequence and we
2254 are ignoring all text inside comments. We must record
2255 the comment style this sequence begins so that later,
2256 only a comment end of the same style actually ends
2257 the comment section. */
2259 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2260 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2261 INC_BOTH (from
, from_byte
);
2262 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2265 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2267 if (code
== Scomment_fence
)
2268 comstyle
= ST_COMMENT_STYLE
;
2269 else if (code
!= Scomment
)
2272 DEC_BOTH (from
, from_byte
);
2273 SET_PT_BOTH (from
, from_byte
);
2276 /* We're at the start of a comment. */
2277 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2278 &out_charpos
, &out_bytepos
, &dummy
);
2279 from
= out_charpos
; from_byte
= out_bytepos
;
2283 SET_PT_BOTH (from
, from_byte
);
2286 INC_BOTH (from
, from_byte
);
2287 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2288 /* We have skipped one comment. */
2300 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2305 DEC_BOTH (from
, from_byte
);
2306 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2307 quoted
= char_quoted (from
, from_byte
);
2308 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2311 comnested
= SYNTAX_COMMENT_NESTED (c
);
2312 if (code
== Sendcomment
)
2313 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2314 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2315 && prev_char_comend_first (from
, from_byte
)
2316 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2318 /* We must record the comment style encountered so that
2319 later, we can match only the proper comment begin
2320 sequence of the same style. */
2321 DEC_BOTH (from
, from_byte
);
2323 /* Calling char_quoted, above, set up global syntax position
2324 at the new value of FROM. */
2325 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2326 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2327 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2330 if (code
== Scomment_fence
)
2332 /* Skip until first preceding unquoted comment_fence. */
2333 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2337 DEC_BOTH (from
, from_byte
);
2340 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2341 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2342 if (SYNTAX (c
) == Scomment_fence
2343 && !char_quoted (from
, from_byte
))
2351 from
= ini
; /* Set point to ini + 1. */
2352 from_byte
= ini_byte
;
2356 else if (code
== Sendcomment
)
2358 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2359 &out_charpos
, &out_bytepos
);
2363 /* This end-of-line is not an end-of-comment.
2364 Treat it like a whitespace.
2365 CC-mode (and maybe others) relies on this behavior. */
2369 /* Failure: we should go back to the end of this
2370 not-quite-endcomment. */
2371 if (SYNTAX(c
) != code
)
2372 /* It was a two-char Sendcomment. */
2373 INC_BOTH (from
, from_byte
);
2379 /* We have skipped one comment. */
2380 from
= out_charpos
, from_byte
= out_bytepos
;
2384 else if (code
!= Swhitespace
|| quoted
)
2388 INC_BOTH (from
, from_byte
);
2389 SET_PT_BOTH (from
, from_byte
);
2397 SET_PT_BOTH (from
, from_byte
);
2402 /* Return syntax code of character C if C is an ASCII character
2403 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2405 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2406 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2407 ? SYNTAX (c) : Ssymbol)
2410 scan_lists (from
, count
, depth
, sexpflag
)
2412 int count
, depth
, sexpflag
;
2415 register int stop
= count
> 0 ? ZV
: BEGV
;
2420 register enum syntaxcode code
, temp_code
;
2421 int min_depth
= depth
; /* Err out if depth gets less than this. */
2422 int comstyle
= 0; /* style of comment encountered */
2423 int comnested
= 0; /* whether the comment is nestable or not */
2425 int last_good
= from
;
2428 int out_bytepos
, out_charpos
;
2430 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2432 if (depth
> 0) min_depth
= 0;
2434 if (from
> ZV
) from
= ZV
;
2435 if (from
< BEGV
) from
= BEGV
;
2437 from_byte
= CHAR_TO_BYTE (from
);
2442 SETUP_SYNTAX_TABLE (from
, count
);
2447 int comstart_first
, prefix
;
2448 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2449 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2450 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2451 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2452 comnested
= SYNTAX_COMMENT_NESTED (c
);
2453 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2454 prefix
= SYNTAX_PREFIX (c
);
2455 if (depth
== min_depth
)
2457 INC_BOTH (from
, from_byte
);
2458 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2459 if (from
< stop
&& comstart_first
2460 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2461 SYNTAX_COMSTART_SECOND (c
))
2462 && parse_sexp_ignore_comments
)
2464 /* we have encountered a comment start sequence and we
2465 are ignoring all text inside comments. We must record
2466 the comment style this sequence begins so that later,
2467 only a comment end of the same style actually ends
2468 the comment section */
2470 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2471 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2472 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2473 INC_BOTH (from
, from_byte
);
2474 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2480 switch (SWITCH_ENUM_CAST (code
))
2484 if (from
== stop
) goto lose
;
2485 INC_BOTH (from
, from_byte
);
2486 /* treat following character as a word constituent */
2489 if (depth
|| !sexpflag
) break;
2490 /* This word counts as a sexp; return at end of it. */
2493 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2495 /* Some compilers can't handle this inside the switch. */
2496 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2497 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2502 INC_BOTH (from
, from_byte
);
2503 if (from
== stop
) goto lose
;
2512 INC_BOTH (from
, from_byte
);
2516 case Scomment_fence
:
2517 comstyle
= ST_COMMENT_STYLE
;
2520 if (!parse_sexp_ignore_comments
) break;
2521 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2522 found
= forw_comment (from
, from_byte
, stop
,
2523 comnested
, comstyle
, 0,
2524 &out_charpos
, &out_bytepos
, &dummy
);
2525 from
= out_charpos
, from_byte
= out_bytepos
;
2532 INC_BOTH (from
, from_byte
);
2533 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2539 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2541 INC_BOTH (from
, from_byte
);
2551 if (!++depth
) goto done
;
2556 if (!--depth
) goto done
;
2557 if (depth
< min_depth
)
2558 Fsignal (Qscan_error
,
2559 Fcons (build_string ("Containing expression ends prematurely"),
2560 Fcons (make_number (last_good
),
2561 Fcons (make_number (from
), Qnil
))));
2566 temp_pos
= dec_bytepos (from_byte
);
2567 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2570 if (from
>= stop
) goto lose
;
2571 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2572 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2575 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2576 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2579 /* Some compilers can't handle this inside the switch. */
2580 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2585 INC_BOTH (from
, from_byte
);
2587 INC_BOTH (from
, from_byte
);
2589 INC_BOTH (from
, from_byte
);
2590 if (!depth
&& sexpflag
) goto done
;
2593 /* Ignore whitespace, punctuation, quote, endcomment. */
2598 /* Reached end of buffer. Error if within object, return nil if between */
2599 if (depth
) goto lose
;
2604 /* End of object reached */
2613 DEC_BOTH (from
, from_byte
);
2614 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2615 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2616 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2617 if (depth
== min_depth
)
2620 comnested
= SYNTAX_COMMENT_NESTED (c
);
2621 if (code
== Sendcomment
)
2622 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2623 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2624 && prev_char_comend_first (from
, from_byte
)
2625 && parse_sexp_ignore_comments
)
2627 /* We must record the comment style encountered so that
2628 later, we can match only the proper comment begin
2629 sequence of the same style. */
2630 DEC_BOTH (from
, from_byte
);
2631 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2633 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2634 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2635 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2638 /* Quoting turns anything except a comment-ender
2639 into a word character. Note that this cannot be true
2640 if we decremented FROM in the if-statement above. */
2641 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2643 DEC_BOTH (from
, from_byte
);
2646 else if (SYNTAX_PREFIX (c
))
2649 switch (SWITCH_ENUM_CAST (code
))
2655 if (depth
|| !sexpflag
) break;
2656 /* This word counts as a sexp; count object finished
2657 after passing it. */
2660 temp_pos
= from_byte
;
2661 if (! NILP (current_buffer
->enable_multibyte_characters
))
2665 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2666 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2667 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2668 /* Don't allow comment-end to be quoted. */
2669 if (temp_code
== Sendcomment
)
2671 quoted
= char_quoted (from
- 1, temp_pos
);
2674 DEC_BOTH (from
, from_byte
);
2675 temp_pos
= dec_bytepos (temp_pos
);
2676 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2678 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2679 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2680 if (! (quoted
|| temp_code
== Sword
2681 || temp_code
== Ssymbol
2682 || temp_code
== Squote
))
2684 DEC_BOTH (from
, from_byte
);
2691 temp_pos
= dec_bytepos (from_byte
);
2692 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2693 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2694 DEC_BOTH (from
, from_byte
);
2703 if (!++depth
) goto done2
;
2708 if (!--depth
) goto done2
;
2709 if (depth
< min_depth
)
2710 Fsignal (Qscan_error
,
2711 Fcons (build_string ("Containing expression ends prematurely"),
2712 Fcons (make_number (last_good
),
2713 Fcons (make_number (from
), Qnil
))));
2717 if (!parse_sexp_ignore_comments
)
2719 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2720 &out_charpos
, &out_bytepos
);
2721 /* FIXME: if found == -1, then it really wasn't a comment-end.
2722 For single-char Sendcomment, we can't do much about it apart
2723 from skipping the char.
2724 For 2-char endcomments, we could try again, taking both
2725 chars as separate entities, but it's a lot of trouble
2726 for very little gain, so we don't bother either. -sm */
2728 from
= out_charpos
, from_byte
= out_bytepos
;
2731 case Scomment_fence
:
2735 if (from
== stop
) goto lose
;
2736 DEC_BOTH (from
, from_byte
);
2737 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2738 if (!char_quoted (from
, from_byte
)
2739 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2740 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2743 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2747 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2750 if (from
== stop
) goto lose
;
2751 DEC_BOTH (from
, from_byte
);
2752 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2753 if (!char_quoted (from
, from_byte
)
2755 == (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
)))
2756 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2759 if (!depth
&& sexpflag
) goto done2
;
2762 /* Ignore whitespace, punctuation, quote, endcomment. */
2767 /* Reached start of buffer. Error if within object, return nil if between */
2768 if (depth
) goto lose
;
2779 XSETFASTINT (val
, from
);
2783 Fsignal (Qscan_error
,
2784 Fcons (build_string ("Unbalanced parentheses"),
2785 Fcons (make_number (last_good
),
2786 Fcons (make_number (from
), Qnil
))));
2791 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2792 doc
: /* Scan from character number FROM by COUNT lists.
2793 Returns the character number of the position thus found.
2795 If DEPTH is nonzero, paren depth begins counting from that value,
2796 only places where the depth in parentheses becomes zero
2797 are candidates for stopping; COUNT such places are counted.
2798 Thus, a positive value for DEPTH means go out levels.
2800 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2802 If the beginning or end of (the accessible part of) the buffer is reached
2803 and the depth is wrong, an error is signaled.
2804 If the depth is right but the count is not used up, nil is returned. */)
2805 (from
, count
, depth
)
2806 Lisp_Object from
, count
, depth
;
2808 CHECK_NUMBER (from
);
2809 CHECK_NUMBER (count
);
2810 CHECK_NUMBER (depth
);
2812 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2815 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2816 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2817 If COUNT is negative, scan backwards.
2818 Returns the character number of the position thus found.
2820 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2822 If the beginning or end of (the accessible part of) the buffer is reached
2823 in the middle of a parenthetical grouping, an error is signaled.
2824 If the beginning or end is reached between groupings
2825 but before count is used up, nil is returned. */)
2827 Lisp_Object from
, count
;
2829 CHECK_NUMBER (from
);
2830 CHECK_NUMBER (count
);
2832 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2835 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2837 doc
: /* Move point backward over any number of chars with prefix syntax.
2838 This includes chars with "quote" or "prefix" syntax (' or p). */)
2843 int opoint_byte
= PT_BYTE
;
2845 int pos_byte
= PT_BYTE
;
2850 SET_PT_BOTH (opoint
, opoint_byte
);
2855 SETUP_SYNTAX_TABLE (pos
, -1);
2857 DEC_BOTH (pos
, pos_byte
);
2859 while (!char_quoted (pos
, pos_byte
)
2860 /* Previous statement updates syntax table. */
2861 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2862 || SYNTAX_PREFIX (c
)))
2865 opoint_byte
= pos_byte
;
2868 DEC_BOTH (pos
, pos_byte
);
2871 SET_PT_BOTH (opoint
, opoint_byte
);
2876 /* Parse forward from FROM / FROM_BYTE to END,
2877 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2878 and return a description of the state of the parse at END.
2879 If STOPBEFORE is nonzero, stop at the start of an atom.
2880 If COMMENTSTOP is 1, stop at the start of a comment.
2881 If COMMENTSTOP is -1, stop at the start or end of a comment,
2882 after the beginning of a string, or after the end of a string. */
2885 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2886 stopbefore
, oldstate
, commentstop
)
2887 struct lisp_parse_state
*stateptr
;
2890 int end
, targetdepth
, stopbefore
;
2891 Lisp_Object oldstate
;
2894 struct lisp_parse_state state
;
2896 register enum syntaxcode code
;
2899 struct level
{ int last
, prev
; };
2900 struct level levelstart
[100];
2901 register struct level
*curlevel
= levelstart
;
2902 struct level
*endlevel
= levelstart
+ 100;
2903 register int depth
; /* Paren depth of current scanning location.
2904 level - levelstart equals this except
2905 when the depth becomes negative. */
2906 int mindepth
; /* Lowest DEPTH value seen. */
2907 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2909 int prev_from
; /* Keep one character before FROM. */
2911 int prev_from_syntax
;
2912 int boundary_stop
= commentstop
== -1;
2915 int out_bytepos
, out_charpos
;
2919 prev_from_byte
= from_byte
;
2921 DEC_BOTH (prev_from
, prev_from_byte
);
2923 /* Use this macro instead of `from++'. */
2925 do { prev_from = from; \
2926 prev_from_byte = from_byte; \
2927 temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
2928 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
2929 INC_BOTH (from, from_byte); \
2931 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2937 if (NILP (oldstate
))
2940 state
.instring
= -1;
2941 state
.incomment
= 0;
2942 state
.comstyle
= 0; /* comment style a by default. */
2943 state
.comstr_start
= -1; /* no comment/string seen. */
2947 tem
= Fcar (oldstate
);
2953 oldstate
= Fcdr (oldstate
);
2954 oldstate
= Fcdr (oldstate
);
2955 oldstate
= Fcdr (oldstate
);
2956 tem
= Fcar (oldstate
);
2957 /* Check whether we are inside string_fence-style string: */
2958 state
.instring
= (!NILP (tem
)
2959 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2962 oldstate
= Fcdr (oldstate
);
2963 tem
= Fcar (oldstate
);
2964 state
.incomment
= (!NILP (tem
)
2965 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
2968 oldstate
= Fcdr (oldstate
);
2969 tem
= Fcar (oldstate
);
2970 start_quoted
= !NILP (tem
);
2972 /* if the eighth element of the list is nil, we are in comment
2973 style a. If it is non-nil, we are in comment style b */
2974 oldstate
= Fcdr (oldstate
);
2975 oldstate
= Fcdr (oldstate
);
2976 tem
= Fcar (oldstate
);
2977 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
2978 ? ST_COMMENT_STYLE
: 1);
2980 oldstate
= Fcdr (oldstate
);
2981 tem
= Fcar (oldstate
);
2982 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2983 oldstate
= Fcdr (oldstate
);
2984 tem
= Fcar (oldstate
);
2985 while (!NILP (tem
)) /* >= second enclosing sexps. */
2987 /* curlevel++->last ran into compiler bug on Apollo */
2988 curlevel
->last
= XINT (Fcar (tem
));
2989 if (++curlevel
== endlevel
)
2990 curlevel
--; /* error ("Nesting too deep for parser"); */
2991 curlevel
->prev
= -1;
2992 curlevel
->last
= -1;
2999 curlevel
->prev
= -1;
3000 curlevel
->last
= -1;
3002 SETUP_SYNTAX_TABLE (prev_from
, 1);
3003 temp
= FETCH_CHAR (prev_from_byte
);
3004 prev_from_syntax
= SYNTAX_WITH_FLAGS (temp
);
3005 UPDATE_SYNTAX_TABLE_FORWARD (from
);
3007 /* Enter the loop at a place appropriate for initial state. */
3009 if (state
.incomment
)
3010 goto startincomment
;
3011 if (state
.instring
>= 0)
3013 nofence
= state
.instring
!= ST_STRING_STYLE
;
3015 goto startquotedinstring
;
3018 else if (start_quoted
)
3024 code
= prev_from_syntax
& 0xff;
3026 if (code
== Scomment
)
3028 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
3029 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
3031 state
.comstr_start
= prev_from
;
3033 else if (code
== Scomment_fence
)
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
= ST_COMMENT_STYLE
;
3039 state
.incomment
= -1;
3040 state
.comstr_start
= prev_from
;
3043 else if (from
< end
)
3044 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
))
3045 if (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
3046 SYNTAX_COMSTART_SECOND (c1
))
3047 /* Duplicate code to avoid a complex if-expression
3048 which causes trouble for the SGI compiler. */
3050 /* Record the comment style we have entered so that only
3051 the comment-end sequence of the same style actually
3052 terminates the comment section. */
3053 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
3054 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
3055 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
3056 state
.incomment
= comnested
? 1 : -1;
3057 state
.comstr_start
= prev_from
;
3062 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
3064 switch (SWITCH_ENUM_CAST (code
))
3068 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3069 curlevel
->last
= prev_from
;
3071 if (from
== end
) goto endquoted
;
3074 /* treat following character as a word constituent */
3077 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3078 curlevel
->last
= prev_from
;
3082 /* Some compilers can't handle this inside the switch. */
3083 temp
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3084 temp
= SYNTAX (temp
);
3090 if (from
== end
) goto endquoted
;
3102 curlevel
->prev
= curlevel
->last
;
3105 case Scomment_fence
: /* Can't happen because it's handled above. */
3107 if (commentstop
|| boundary_stop
) goto done
;
3109 /* The (from == BEGV) test was to enter the loop in the middle so
3110 that we find a 2-char comment ender even if we start in the
3111 middle of it. We don't want to do that if we're just at the
3112 beginning of the comment (think of (*) ... (*)). */
3113 found
= forw_comment (from
, from_byte
, end
,
3114 state
.incomment
, state
.comstyle
,
3115 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
3116 ? 0 : prev_from_syntax
,
3117 &out_charpos
, &out_bytepos
, &state
.incomment
);
3118 from
= out_charpos
; from_byte
= out_bytepos
;
3119 /* Beware! prev_from and friends are invalid now.
3120 Luckily, the `done' doesn't use them and the INC_FROM
3121 sets them to a sane value without looking at them. */
3122 if (!found
) goto done
;
3124 state
.incomment
= 0;
3125 state
.comstyle
= 0; /* reset the comment style */
3126 if (boundary_stop
) goto done
;
3130 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3132 /* curlevel++->last ran into compiler bug on Apollo */
3133 curlevel
->last
= prev_from
;
3134 if (++curlevel
== endlevel
)
3135 curlevel
--; /* error ("Nesting too deep for parser"); */
3136 curlevel
->prev
= -1;
3137 curlevel
->last
= -1;
3138 if (targetdepth
== depth
) goto done
;
3143 if (depth
< mindepth
)
3145 if (curlevel
!= levelstart
)
3147 curlevel
->prev
= curlevel
->last
;
3148 if (targetdepth
== depth
) goto done
;
3153 state
.comstr_start
= from
- 1;
3154 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3155 curlevel
->last
= prev_from
;
3156 state
.instring
= (code
== Sstring
3157 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3159 if (boundary_stop
) goto done
;
3162 nofence
= state
.instring
!= ST_STRING_STYLE
;
3168 if (from
>= end
) goto done
;
3169 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3170 /* Some compilers can't handle this inside the switch. */
3173 /* Check TEMP here so that if the char has
3174 a syntax-table property which says it is NOT
3175 a string character, it does not end the string. */
3176 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3182 if (!nofence
) goto string_end
;
3187 startquotedinstring
:
3188 if (from
>= end
) goto endquoted
;
3194 state
.instring
= -1;
3195 curlevel
->prev
= curlevel
->last
;
3197 if (boundary_stop
) goto done
;
3201 /* FIXME: We should do something with it. */
3204 /* Ignore whitespace, punctuation, quote, endcomment. */
3210 stop
: /* Here if stopping before start of sexp. */
3211 from
= prev_from
; /* We have just fetched the char that starts it; */
3212 goto done
; /* but return the position before it. */
3217 state
.depth
= depth
;
3218 state
.mindepth
= mindepth
;
3219 state
.thislevelstart
= curlevel
->prev
;
3220 state
.prevlevelstart
3221 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3222 state
.location
= from
;
3223 state
.levelstarts
= Qnil
;
3224 while (--curlevel
>= levelstart
)
3225 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3232 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3233 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3234 Parsing stops at TO or when certain criteria are met;
3235 point is set to where parsing stops.
3236 If fifth arg OLDSTATE is omitted or nil,
3237 parsing assumes that FROM is the beginning of a function.
3238 Value is a list of ten elements describing final state of parsing:
3240 1. character address of start of innermost containing list; nil if none.
3241 2. character address of start of last complete sexp terminated.
3242 3. non-nil if inside a string.
3243 (it is the character that will terminate the string,
3244 or t if the string should be terminated by a generic string delimiter.)
3245 4. nil if outside a comment, t if inside a non-nestable comment,
3246 else an integer (the current comment nesting).
3247 5. t if following a quote character.
3248 6. the minimum paren-depth encountered during this scan.
3249 7. t if in a comment of style b; symbol `syntax-table' if the comment
3250 should be terminated by a generic comment delimiter.
3251 8. character address of start of comment or string; nil if not in one.
3252 9. Intermediate data for continuation of parsing (subject to change).
3253 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3254 in parentheses becomes equal to TARGETDEPTH.
3255 Fourth arg STOPBEFORE non-nil means stop when come to
3256 any character that starts a sexp.
3257 Fifth arg OLDSTATE is a nine-element list like what this function returns.
3258 It is used to initialize the state of the parse. Elements number 1, 2, 6
3259 and 8 are ignored; you can leave off element 8 (the last) entirely.
3260 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3261 If it is symbol `syntax-table', stop after the start of a comment or a
3262 string, or after end of a comment or a string. */)
3263 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3264 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3266 struct lisp_parse_state state
;
3269 if (!NILP (targetdepth
))
3271 CHECK_NUMBER (targetdepth
);
3272 target
= XINT (targetdepth
);
3275 target
= -100000; /* We won't reach this depth */
3277 validate_region (&from
, &to
);
3278 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3280 target
, !NILP (stopbefore
), oldstate
,
3282 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3284 SET_PT (state
.location
);
3286 return Fcons (make_number (state
.depth
),
3287 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3288 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3289 Fcons (state
.instring
>= 0
3290 ? (state
.instring
== ST_STRING_STYLE
3291 ? Qt
: make_number (state
.instring
)) : Qnil
,
3292 Fcons (state
.incomment
< 0 ? Qt
:
3293 (state
.incomment
== 0 ? Qnil
:
3294 make_number (state
.incomment
)),
3295 Fcons (state
.quoted
? Qt
: Qnil
,
3296 Fcons (make_number (state
.mindepth
),
3297 Fcons ((state
.comstyle
3298 ? (state
.comstyle
== ST_COMMENT_STYLE
3299 ? Qsyntax_table
: Qt
) :
3301 Fcons (((state
.incomment
3302 || (state
.instring
>= 0))
3303 ? make_number (state
.comstr_start
)
3305 Fcons (state
.levelstarts
, Qnil
))))))))));
3314 /* This has to be done here, before we call Fmake_char_table. */
3315 Qsyntax_table
= intern ("syntax-table");
3316 staticpro (&Qsyntax_table
);
3318 /* Intern this now in case it isn't already done.
3319 Setting this variable twice is harmless.
3320 But don't staticpro it here--that is done in alloc.c. */
3321 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3323 /* Create objects which can be shared among syntax tables. */
3324 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3325 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3326 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3327 = Fcons (make_number (i
), Qnil
);
3329 /* Now we are ready to set up this property, so we can
3330 create syntax tables. */
3331 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3333 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3335 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3337 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3338 for (i
= 'a'; i
<= 'z'; i
++)
3339 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3340 for (i
= 'A'; i
<= 'Z'; i
++)
3341 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3342 for (i
= '0'; i
<= '9'; i
++)
3343 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3345 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3346 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3348 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3349 Fcons (make_number (Sopen
), make_number (')')));
3350 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3351 Fcons (make_number (Sclose
), make_number ('(')));
3352 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3353 Fcons (make_number (Sopen
), make_number (']')));
3354 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3355 Fcons (make_number (Sclose
), make_number ('[')));
3356 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3357 Fcons (make_number (Sopen
), make_number ('}')));
3358 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3359 Fcons (make_number (Sclose
), make_number ('{')));
3360 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3361 Fcons (make_number ((int) Sstring
), Qnil
));
3362 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3363 Fcons (make_number ((int) Sescape
), Qnil
));
3365 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3366 for (i
= 0; i
< 10; i
++)
3368 c
= "_-+*/&|<>="[i
];
3369 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3372 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3373 for (i
= 0; i
< 12; i
++)
3375 c
= ".,;:?!#@~^'`"[i
];
3376 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3379 /* All multibyte characters have syntax `word' by default. */
3380 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3381 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3387 Qsyntax_table_p
= intern ("syntax-table-p");
3388 staticpro (&Qsyntax_table_p
);
3390 staticpro (&Vsyntax_code_object
);
3392 Qscan_error
= intern ("scan-error");
3393 staticpro (&Qscan_error
);
3394 Fput (Qscan_error
, Qerror_conditions
,
3395 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3396 Fput (Qscan_error
, Qerror_message
,
3397 build_string ("Scan error"));
3399 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3400 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3402 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3403 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3404 Otherwise, that text property is simply ignored.
3405 See the info node `(elisp)Syntax Properties' for a description of the
3406 `syntax-table' property. */);
3408 words_include_escapes
= 0;
3409 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3410 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3412 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3413 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3414 multibyte_syntax_as_symbol
= 0;
3416 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3417 &open_paren_in_column_0_is_defun_start
,
3418 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3419 open_paren_in_column_0_is_defun_start
= 1;
3422 DEFVAR_LISP ("find-word-boundary-function-table",
3423 &Vfind_word_boundary_function_table
,
3425 Char table of functions to search for the word boundary.
3426 Each function is called with two arguments; POS and LIMIT.
3427 POS and LIMIT are character positions in the current buffer.
3429 If POS is less than LIMIT, POS is at the first character of a word,
3430 and the return value of a function is a position after the last
3431 character of that word.
3433 If POS is not less than LIMIT, POS is at the last character of a word,
3434 and the return value of a function is a position at the first
3435 character of that word.
3437 In both cases, LIMIT bounds the search. */);
3438 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3440 defsubr (&Ssyntax_table_p
);
3441 defsubr (&Ssyntax_table
);
3442 defsubr (&Sstandard_syntax_table
);
3443 defsubr (&Scopy_syntax_table
);
3444 defsubr (&Sset_syntax_table
);
3445 defsubr (&Schar_syntax
);
3446 defsubr (&Smatching_paren
);
3447 defsubr (&Sstring_to_syntax
);
3448 defsubr (&Smodify_syntax_entry
);
3449 defsubr (&Sinternal_describe_syntax_value
);
3451 defsubr (&Sforward_word
);
3453 defsubr (&Sskip_chars_forward
);
3454 defsubr (&Sskip_chars_backward
);
3455 defsubr (&Sskip_syntax_forward
);
3456 defsubr (&Sskip_syntax_backward
);
3458 defsubr (&Sforward_comment
);
3459 defsubr (&Sscan_lists
);
3460 defsubr (&Sscan_sexps
);
3461 defsubr (&Sbackward_prefix_chars
);
3462 defsubr (&Sparse_partial_sexp
);
3465 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
3466 (do not change this comment) */