1 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
2 Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28 #include "character.h"
32 /* Make syntax table lookup grant data in gl_state. */
33 #define SYNTAX_ENTRY_VIA_PROPERTY
36 #include "intervals.h"
38 /* We use these constants in place for comment-style and
39 string-ender-char to distinguish comments/strings started by
40 comment_fence and string_fence codes. */
42 #define ST_COMMENT_STYLE (256 + 1)
43 #define ST_STRING_STYLE (256 + 2)
46 Lisp_Object Qsyntax_table_p
, Qsyntax_table
, Qscan_error
;
48 int words_include_escapes
;
49 int parse_sexp_lookup_properties
;
51 /* Nonzero means `scan-sexps' treat all multibyte characters as symbol. */
52 int multibyte_syntax_as_symbol
;
54 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
55 if not compiled with GCC. No need to mark it, since it is used
56 only very temporarily. */
57 Lisp_Object syntax_temp
;
59 /* Non-zero means an open parenthesis in column 0 is always considered
60 to be the start of a defun. Zero means an open parenthesis in
61 column 0 has no special meaning. */
63 int open_paren_in_column_0_is_defun_start
;
65 /* This is the internal form of the parse state used in parse-partial-sexp. */
67 struct lisp_parse_state
69 int depth
; /* Depth at end of parsing. */
70 int instring
; /* -1 if not within string, else desired terminator. */
71 int incomment
; /* -1 if in unnestable comment else comment nesting */
72 int comstyle
; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
73 int quoted
; /* Nonzero if just after an escape char at end of parsing */
74 int mindepth
; /* Minimum depth seen while scanning. */
75 /* Char number of most recent start-of-expression at current level */
76 EMACS_INT thislevelstart
;
77 /* Char number of start of containing expression */
78 EMACS_INT prevlevelstart
;
79 EMACS_INT location
; /* Char number at which parsing stopped. */
80 EMACS_INT comstr_start
; /* Position of last comment/string starter. */
81 Lisp_Object levelstarts
; /* Char numbers of starts-of-expression
82 of levels (starting from outermost). */
85 /* These variables are a cache for finding the start of a defun.
86 find_start_pos is the place for which the defun start was found.
87 find_start_value is the defun start position found for it.
88 find_start_value_byte is the corresponding byte position.
89 find_start_buffer is the buffer it was found in.
90 find_start_begv is the BEGV value when it was found.
91 find_start_modiff is the value of MODIFF when it was found. */
93 static EMACS_INT find_start_pos
;
94 static EMACS_INT find_start_value
;
95 static EMACS_INT find_start_value_byte
;
96 static struct buffer
*find_start_buffer
;
97 static EMACS_INT find_start_begv
;
98 static int find_start_modiff
;
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_ ((EMACS_INT
, EMACS_INT
, EMACS_INT
, int));
104 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
105 EMACS_INT
, EMACS_INT
, EMACS_INT
, int,
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 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
;
253 = i
->position
+ LENGTH (i
) - gl_state
.offset
;
254 gl_state
.backward_i
= i
;
258 else if (cnt
== INTERVALS_AT_ONCE
)
263 = i
->position
+ LENGTH (i
) - gl_state
.offset
264 /* e_property at EOB is not set to ZV but to ZV+1, so that
265 we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
266 having to check eob between the two. */
267 + (NULL_INTERVAL_P (next_interval (i
)) ? 1 : 0);
268 gl_state
.forward_i
= i
;
272 gl_state
.b_property
= i
->position
- gl_state
.offset
;
273 gl_state
.backward_i
= i
;
278 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
280 eassert (NULL_INTERVAL_P (i
)); /* This property goes to the end. */
282 gl_state
.e_property
= gl_state
.stop
;
284 gl_state
.b_property
= gl_state
.start
;
287 /* Returns TRUE if char at CHARPOS is quoted.
288 Global syntax-table data should be set up already to be good at CHARPOS
289 or after. On return global syntax data is good for lookup at CHARPOS. */
292 char_quoted (EMACS_INT charpos
, EMACS_INT bytepos
)
294 register enum syntaxcode code
;
295 register EMACS_INT beg
= BEGV
;
296 register int quoted
= 0;
297 EMACS_INT orig
= charpos
;
299 while (charpos
> beg
)
302 DEC_BOTH (charpos
, bytepos
);
304 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
305 c
= FETCH_CHAR_AS_MULTIBYTE (bytepos
);
307 if (! (code
== Scharquote
|| code
== Sescape
))
313 UPDATE_SYNTAX_TABLE (orig
);
317 /* Return the bytepos one character after BYTEPOS.
318 We assume that BYTEPOS is not at the end of the buffer. */
321 inc_bytepos (bytepos
)
324 if (NILP (current_buffer
->enable_multibyte_characters
))
331 /* Return the bytepos one character before BYTEPOS.
332 We assume that BYTEPOS is not at the start of the buffer. */
335 dec_bytepos (bytepos
)
338 if (NILP (current_buffer
->enable_multibyte_characters
))
345 /* Return a defun-start position before POS and not too far before.
346 It should be the last one before POS, or nearly the last.
348 When open_paren_in_column_0_is_defun_start is nonzero,
349 only the beginning of the buffer is treated as a defun-start.
351 We record the information about where the scan started
352 and what its result was, so that another call in the same area
353 can return the same value very quickly.
355 There is no promise at which position the global syntax data is
356 valid on return from the subroutine, so the caller should explicitly
357 update the global data. */
360 find_defun_start (pos
, pos_byte
)
361 EMACS_INT pos
, pos_byte
;
363 EMACS_INT opoint
= PT
, opoint_byte
= PT_BYTE
;
365 if (!open_paren_in_column_0_is_defun_start
)
367 find_start_value_byte
= BEGV_BYTE
;
371 /* Use previous finding, if it's valid and applies to this inquiry. */
372 if (current_buffer
== find_start_buffer
373 /* Reuse the defun-start even if POS is a little farther on.
374 POS might be in the next defun, but that's ok.
375 Our value may not be the best possible, but will still be usable. */
376 && pos
<= find_start_pos
+ 1000
377 && pos
>= find_start_value
378 && BEGV
== find_start_begv
379 && MODIFF
== find_start_modiff
)
380 return find_start_value
;
382 /* Back up to start of line. */
383 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
385 /* We optimize syntax-table lookup for rare updates. Thus we accept
386 only those `^\s(' which are good in global _and_ text-property
388 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
389 gl_state
.use_global
= 0;
394 /* Open-paren at start of line means we may have found our
396 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
397 if (SYNTAX (c
) == Sopen
)
399 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
400 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
401 if (SYNTAX (c
) == Sopen
)
403 /* Now fallback to the default value. */
404 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
405 gl_state
.use_global
= 0;
407 /* Move to beg of previous line. */
408 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
411 /* Record what we found, for the next try. */
412 find_start_value
= PT
;
413 find_start_value_byte
= PT_BYTE
;
414 find_start_buffer
= current_buffer
;
415 find_start_modiff
= MODIFF
;
416 find_start_begv
= BEGV
;
417 find_start_pos
= pos
;
419 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
421 return find_start_value
;
424 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
427 prev_char_comend_first (pos
, pos_byte
)
432 DEC_BOTH (pos
, pos_byte
);
433 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
434 c
= FETCH_CHAR (pos_byte
);
435 val
= SYNTAX_COMEND_FIRST (c
);
436 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
440 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
443 * prev_char_comstart_first (pos, pos_byte)
448 * DEC_BOTH (pos, pos_byte);
449 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
450 * c = FETCH_CHAR (pos_byte);
451 * val = SYNTAX_COMSTART_FIRST (c);
452 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
456 /* Checks whether charpos FROM is at the end of a comment.
457 FROM_BYTE is the bytepos corresponding to FROM.
458 Do not move back before STOP.
460 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
463 If successful, store the charpos of the comment's beginning
464 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
466 Global syntax data remains valid for backward search starting at
467 the returned value (or at FROM, if the search was not successful). */
470 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
471 EMACS_INT from
, from_byte
, stop
;
472 int comnested
, comstyle
;
473 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
475 /* Look back, counting the parity of string-quotes,
476 and recording the comment-starters seen.
477 When we reach a safe place, assume that's not in a string;
478 then step the main scan to the earliest comment-starter seen
479 an even number of string quotes away from the safe place.
481 OFROM[I] is position of the earliest comment-starter seen
482 which is I+2X quotes from the comment-end.
483 PARITY is current parity of quotes from the comment end. */
484 int string_style
= -1; /* Presumed outside of any string. */
485 int string_lossage
= 0;
486 /* Not a real lossage: indicates that we have passed a matching comment
487 starter plus a non-matching comment-ender, meaning that any matching
488 comment-starter we might see later could be a false positive (hidden
489 inside another comment).
490 Test case: { a (* b } c (* d *) */
491 int comment_lossage
= 0;
492 EMACS_INT comment_end
= from
;
493 EMACS_INT comment_end_byte
= from_byte
;
494 EMACS_INT comstart_pos
= 0;
495 EMACS_INT comstart_byte
;
496 /* Place where the containing defun starts,
497 or 0 if we didn't come across it yet. */
498 EMACS_INT defun_start
= 0;
499 EMACS_INT defun_start_byte
= 0;
500 register enum syntaxcode code
;
501 int nesting
= 1; /* current comment nesting */
505 /* FIXME: A }} comment-ender style leads to incorrect behavior
506 in the case of {{ c }}} because we ignore the last two chars which are
507 assumed to be comment-enders although they aren't. */
509 /* At beginning of range to scan, we're outside of strings;
510 that determines quote parity to the comment-end. */
513 int temp_byte
, prev_syntax
;
514 int com2start
, com2end
;
516 /* Move back and examine a character. */
517 DEC_BOTH (from
, from_byte
);
518 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
520 prev_syntax
= syntax
;
521 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
522 syntax
= SYNTAX_WITH_FLAGS (c
);
525 /* Check for 2-char comment markers. */
526 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
527 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
528 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
529 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
530 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
531 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
532 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
534 /* Nasty cases with overlapping 2-char comment markers:
535 - snmp-mode: -- c -- foo -- c --
543 /* If a 2-char comment sequence partly overlaps with another,
544 we don't try to be clever. */
545 if (from
> stop
&& (com2end
|| com2start
))
547 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
548 DEC_BOTH (next
, next_byte
);
549 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
550 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
551 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
552 if (((com2start
|| comnested
)
553 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
554 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
555 || ((com2end
|| comnested
)
556 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
557 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
558 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
560 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
563 if (com2start
&& comstart_pos
== 0)
564 /* We're looking at a comment starter. But it might be a comment
565 ender as well (see snmp-mode). The first time we see one, we
566 need to consider it as a comment starter,
567 and the subsequent times as a comment ender. */
570 /* Turn a 2-char comment sequences into the appropriate syntax. */
575 /* Ignore comment starters of a different style. */
576 else if (code
== Scomment
577 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
578 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
581 /* Ignore escaped characters, except comment-enders. */
582 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
589 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
591 /* Track parity of quotes. */
592 if (string_style
== -1)
593 /* Entering a string. */
595 else if (string_style
== c
)
596 /* Leaving the string. */
599 /* If we have two kinds of string delimiters.
600 There's no way to grok this scanning backwards. */
605 /* We've already checked that it is the relevant comstyle. */
606 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
607 /* There are odd string quotes involved, so let's be careful.
608 Test case in Pascal: " { " a { " } */
613 /* Record best comment-starter so far. */
615 comstart_byte
= from_byte
;
617 else if (--nesting
<= 0)
618 /* nested comments have to be balanced, so we don't need to
619 keep looking for earlier ones. We use here the same (slightly
620 incorrect) reasoning as below: since it is followed by uniform
621 paired string quotes, this comment-start has to be outside of
622 strings, else the comment-end itself would be inside a string. */
627 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
628 && ((com2end
&& SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
))
629 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
630 /* This is the same style of comment ender as ours. */
635 /* Anything before that can't count because it would match
636 this comment-ender rather than ours. */
637 from
= stop
; /* Break out of the loop. */
639 else if (comstart_pos
!= 0 || c
!= '\n')
640 /* We're mixing comment styles here, so we'd better be careful.
641 The (comstart_pos != 0 || c != '\n') check is not quite correct
642 (we should just always set comment_lossage), but removing it
643 would imply that any multiline comment in C would go through
644 lossage, which seems overkill.
645 The failure should only happen in the rare cases such as
651 /* Assume a defun-start point is outside of strings. */
652 if (open_paren_in_column_0_is_defun_start
654 || (temp_byte
= dec_bytepos (from_byte
),
655 FETCH_CHAR (temp_byte
) == '\n')))
658 defun_start_byte
= from_byte
;
659 from
= stop
; /* Break out of the loop. */
668 if (comstart_pos
== 0)
671 from_byte
= comment_end_byte
;
672 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
674 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
675 or `done'), then we've found the beginning of the non-nested comment. */
676 else if (1) /* !comnested */
679 from_byte
= comstart_byte
;
680 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
684 struct lisp_parse_state state
;
686 /* We had two kinds of string delimiters mixed up
687 together. Decode this going forwards.
688 Scan fwd from a known safe place (beginning-of-defun)
689 to the one in question; this records where we
690 last passed a comment starter. */
691 /* If we did not already find the defun start, find it now. */
692 if (defun_start
== 0)
694 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
695 defun_start_byte
= find_start_value_byte
;
699 scan_sexps_forward (&state
,
700 defun_start
, defun_start_byte
,
701 comment_end
, -10000, 0, Qnil
, 0);
702 defun_start
= comment_end
;
703 if (state
.incomment
== (comnested
? 1 : -1)
704 && state
.comstyle
== comstyle
)
705 from
= state
.comstr_start
;
710 /* If comment_end is inside some other comment, maybe ours
711 is nested, so we need to try again from within the
712 surrounding comment. Example: { a (* " *) */
714 /* FIXME: We should advance by one or two chars. */
715 defun_start
= state
.comstr_start
+ 2;
716 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
719 } while (defun_start
< comment_end
);
721 from_byte
= CHAR_TO_BYTE (from
);
722 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
727 *bytepos_ptr
= from_byte
;
729 return (from
== comment_end
) ? -1 : from
;
732 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
733 doc
: /* Return t if OBJECT is a syntax table.
734 Currently, any char-table counts as a syntax table. */)
738 if (CHAR_TABLE_P (object
)
739 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
745 check_syntax_table (obj
)
748 CHECK_TYPE (CHAR_TABLE_P (obj
) && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
),
749 Qsyntax_table_p
, obj
);
752 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
753 doc
: /* Return the current syntax table.
754 This is the one specified by the current buffer. */)
757 return current_buffer
->syntax_table
;
760 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
761 Sstandard_syntax_table
, 0, 0, 0,
762 doc
: /* Return the standard syntax table.
763 This is the one used for new buffers. */)
766 return Vstandard_syntax_table
;
769 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
770 doc
: /* Construct a new syntax table and return it.
771 It is a copy of the TABLE, which defaults to the standard syntax table. */)
778 check_syntax_table (table
);
780 table
= Vstandard_syntax_table
;
782 copy
= Fcopy_sequence (table
);
784 /* Only the standard syntax table should have a default element.
785 Other syntax tables should inherit from parents instead. */
786 XCHAR_TABLE (copy
)->defalt
= Qnil
;
788 /* Copied syntax tables should all have parents.
789 If we copied one with no parent, such as the standard syntax table,
790 use the standard syntax table as the copy's parent. */
791 if (NILP (XCHAR_TABLE (copy
)->parent
))
792 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
796 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
797 doc
: /* Select a new syntax table for the current buffer.
798 One argument, a syntax table. */)
803 check_syntax_table (table
);
804 current_buffer
->syntax_table
= table
;
805 /* Indicate that this buffer now has a specified syntax table. */
806 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
807 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
811 /* Convert a letter which signifies a syntax code
812 into the code it signifies.
813 This is used by modify-syntax-entry, and other things. */
815 unsigned char syntax_spec_code
[0400] =
816 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
817 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
818 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
819 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
820 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
821 (char) Smath
, 0377, 0377, (char) Squote
,
822 (char) Sopen
, (char) Sclose
, 0377, 0377,
823 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
824 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
825 0377, 0377, 0377, 0377,
826 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
827 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
828 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
829 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
830 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
831 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
832 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
833 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
834 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
837 /* Indexed by syntax code, give the letter that describes it. */
839 char syntax_code_spec
[16] =
841 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
845 /* Indexed by syntax code, give the object (cons of syntax code and
846 nil) to be stored in syntax table. Since these objects can be
847 shared among syntax tables, we generate them in advance. By
848 sharing objects, the function `describe-syntax' can give a more
850 static Lisp_Object Vsyntax_code_object
;
853 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
854 doc
: /* Return the syntax code of CHARACTER, described by a character.
855 For example, if CHARACTER is a word constituent, the
856 character `w' (119) is returned.
857 The characters that correspond to various syntax codes
858 are listed in the documentation of `modify-syntax-entry'. */)
860 Lisp_Object character
;
863 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
865 gl_state
.use_global
= 0;
866 CHECK_NUMBER (character
);
867 char_int
= XINT (character
);
868 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
871 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
872 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
874 Lisp_Object character
;
877 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
878 gl_state
.use_global
= 0;
879 CHECK_NUMBER (character
);
880 char_int
= XINT (character
);
881 code
= SYNTAX (char_int
);
882 if (code
== Sopen
|| code
== Sclose
)
883 return SYNTAX_MATCH (char_int
);
887 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
888 doc
: /* Convert a syntax specification STRING into syntax cell form.
889 STRING should be a string as it is allowed as argument of
890 `modify-syntax-entry'. Value is the equivalent cons cell
891 \(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
896 register const unsigned char *p
;
897 register enum syntaxcode code
;
901 CHECK_STRING (string
);
904 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
905 if (((int) code
& 0377) == 0377)
906 error ("Invalid syntax description letter: %c", p
[-1]);
908 if (code
== Sinherit
)
914 int character
= (STRING_CHAR_AND_LENGTH
915 (p
, SBYTES (string
) - 1, len
));
916 XSETINT (match
, character
);
917 if (XFASTINT (match
) == ' ')
957 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
958 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
960 /* Since we can't use a shared object, let's make a new one. */
961 return Fcons (make_number (val
), match
);
964 /* I really don't know why this is interactive
965 help-form should at least be made useful whilst reading the second arg. */
966 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
967 "cSet syntax for character: \nsSet syntax for %s to: ",
968 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
969 The syntax is changed only for table SYNTAX-TABLE, which defaults to
970 the current buffer's syntax table.
971 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
972 in the range MIN to MAX are changed.
973 The first character of NEWENTRY should be one of the following:
974 Space or - whitespace syntax. w word constituent.
975 _ symbol constituent. . punctuation.
976 ( open-parenthesis. ) close-parenthesis.
977 " string quote. \\ escape.
978 $ paired delimiter. ' expression quote or prefix operator.
979 < comment starter. > comment ender.
980 / character-quote. @ inherit from `standard-syntax-table'.
981 | generic string fence. ! generic comment fence.
983 Only single-character comment start and end sequences are represented thus.
984 Two-character sequences are represented as described below.
985 The second character of NEWENTRY is the matching parenthesis,
986 used only if the first character is `(' or `)'.
987 Any additional characters are flags.
988 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
989 1 means CHAR is the start of a two-char comment start sequence.
990 2 means CHAR is the second character of such a sequence.
991 3 means CHAR is the start of a two-char comment end sequence.
992 4 means CHAR is the second character of such a sequence.
994 There can be up to two orthogonal comment sequences. This is to support
995 language modes such as C++. By default, all comment sequences are of style
996 a, but you can set the comment sequence style to b (on the second character
997 of a comment-start, or the first character of a comment-end sequence) using
999 b means CHAR is part of comment sequence b.
1000 n means CHAR is part of a nestable comment sequence.
1002 p means CHAR is a prefix character for `backward-prefix-chars';
1003 such characters are treated as whitespace when they occur
1004 between expressions.
1005 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1006 (c
, newentry
, syntax_table
)
1007 Lisp_Object c
, newentry
, syntax_table
;
1011 CHECK_CHARACTER_CAR (c
);
1012 CHECK_CHARACTER_CDR (c
);
1015 CHECK_CHARACTER (c
);
1017 if (NILP (syntax_table
))
1018 syntax_table
= current_buffer
->syntax_table
;
1020 check_syntax_table (syntax_table
);
1022 newentry
= Fstring_to_syntax (newentry
);
1024 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1026 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1028 /* We clear the regexp cache, since character classes can now have
1029 different values from those in the compiled regexps.*/
1030 clear_regexp_cache ();
1035 /* Dump syntax table to buffer in human-readable format */
1037 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1038 Sinternal_describe_syntax_value
, 1, 1, 0,
1039 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1043 register enum syntaxcode code
;
1044 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1046 Lisp_Object first
, match_lisp
, value
= syntax
;
1050 insert_string ("default");
1054 if (CHAR_TABLE_P (value
))
1056 insert_string ("deeper char-table ...");
1062 insert_string ("invalid");
1066 first
= XCAR (value
);
1067 match_lisp
= XCDR (value
);
1069 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1071 insert_string ("invalid");
1075 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1076 start1
= (XINT (first
) >> 16) & 1;
1077 start2
= (XINT (first
) >> 17) & 1;
1078 end1
= (XINT (first
) >> 18) & 1;
1079 end2
= (XINT (first
) >> 19) & 1;
1080 prefix
= (XINT (first
) >> 20) & 1;
1081 comstyle
= (XINT (first
) >> 21) & 1;
1082 comnested
= (XINT (first
) >> 22) & 1;
1084 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1086 insert_string ("invalid");
1089 desc
= syntax_code_spec
[(int) code
];
1091 str
[0] = desc
, str
[1] = 0;
1094 if (NILP (match_lisp
))
1097 insert_char (XINT (match_lisp
));
1116 insert_string ("\twhich means: ");
1118 switch (SWITCH_ENUM_CAST (code
))
1121 insert_string ("whitespace"); break;
1123 insert_string ("punctuation"); break;
1125 insert_string ("word"); break;
1127 insert_string ("symbol"); break;
1129 insert_string ("open"); break;
1131 insert_string ("close"); break;
1133 insert_string ("prefix"); break;
1135 insert_string ("string"); break;
1137 insert_string ("math"); break;
1139 insert_string ("escape"); break;
1141 insert_string ("charquote"); break;
1143 insert_string ("comment"); break;
1145 insert_string ("endcomment"); break;
1147 insert_string ("inherit"); break;
1148 case Scomment_fence
:
1149 insert_string ("comment fence"); break;
1151 insert_string ("string fence"); break;
1153 insert_string ("invalid");
1157 if (!NILP (match_lisp
))
1159 insert_string (", matches ");
1160 insert_char (XINT (match_lisp
));
1164 insert_string (",\n\t is the first character of a comment-start sequence");
1166 insert_string (",\n\t is the second character of a comment-start sequence");
1169 insert_string (",\n\t is the first character of a comment-end sequence");
1171 insert_string (",\n\t is the second character of a comment-end sequence");
1173 insert_string (" (comment style b)");
1175 insert_string (" (nestable)");
1178 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1183 int parse_sexp_ignore_comments
;
1185 /* Char-table of functions that find the next or previous word
1187 Lisp_Object Vfind_word_boundary_function_table
;
1189 /* Return the position across COUNT words from FROM.
1190 If that many words cannot be found before the end of the buffer, return 0.
1191 COUNT negative means scan backward and stop at word beginning. */
1194 scan_words (from
, count
)
1195 register int from
, count
;
1197 register int beg
= BEGV
;
1198 register int end
= ZV
;
1199 register int from_byte
= CHAR_TO_BYTE (from
);
1200 register enum syntaxcode code
;
1202 Lisp_Object func
, script
, pos
;
1207 SETUP_SYNTAX_TABLE (from
, count
);
1218 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1219 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1220 code
= SYNTAX (ch0
);
1221 INC_BOTH (from
, from_byte
);
1222 if (words_include_escapes
1223 && (code
== Sescape
|| code
== Scharquote
))
1228 /* Now CH0 is a character which begins a word and FROM is the
1229 position of the next character. */
1230 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch0
);
1231 if (! NILP (Ffboundp (func
)))
1233 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1234 if (INTEGERP (pos
) && XINT (pos
) > from
)
1237 from_byte
= CHAR_TO_BYTE (from
);
1242 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1245 if (from
== end
) break;
1246 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1247 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1248 code
= SYNTAX (ch1
);
1250 && (! words_include_escapes
1251 || (code
!= Sescape
&& code
!= Scharquote
)))
1252 || word_boundary_p (ch0
, ch1
))
1254 INC_BOTH (from
, from_byte
);
1269 DEC_BOTH (from
, from_byte
);
1270 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1271 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1272 code
= SYNTAX (ch1
);
1273 if (words_include_escapes
1274 && (code
== Sescape
|| code
== Scharquote
))
1279 /* Now CH1 is a character which ends a word and FROM is the
1281 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch1
);
1282 if (! NILP (Ffboundp (func
)))
1284 pos
= call2 (func
, make_number (from
), make_number (beg
));
1285 if (INTEGERP (pos
) && XINT (pos
) < from
)
1288 from_byte
= CHAR_TO_BYTE (from
);
1293 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1298 DEC_BOTH (from
, from_byte
);
1299 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1300 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1301 code
= SYNTAX (ch0
);
1303 && (! words_include_escapes
1304 || (code
!= Sescape
&& code
!= Scharquote
)))
1305 || word_boundary_p (ch0
, ch1
))
1307 INC_BOTH (from
, from_byte
);
1321 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 0, 1, "^p",
1322 doc
: /* Move point forward ARG words (backward if ARG is negative).
1324 If an edge of the buffer or a field boundary is reached, point is left there
1325 and the function returns nil. Field boundaries are not noticed if
1326 `inhibit-field-text-motion' is non-nil. */)
1334 XSETFASTINT (arg
, 1);
1338 val
= orig_val
= scan_words (PT
, XINT (arg
));
1340 val
= XINT (arg
) > 0 ? ZV
: BEGV
;
1342 /* Avoid jumping out of an input field. */
1343 tmp
= Fconstrain_to_field (make_number (val
), make_number (PT
),
1345 val
= XFASTINT (tmp
);
1348 return val
== orig_val
? Qt
: Qnil
;
1351 Lisp_Object
skip_chars ();
1353 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1354 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1355 STRING is like the inside of a `[...]' in a regular expression
1356 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1357 (but not at the end of a range; quoting is never needed there).
1358 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1359 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1360 Char classes, e.g. `[:alpha:]', are supported.
1362 Returns the distance traveled, either zero or positive. */)
1364 Lisp_Object string
, lim
;
1366 return skip_chars (1, string
, lim
, 1);
1369 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1370 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1371 See `skip-chars-forward' for details.
1372 Returns the distance traveled, either zero or negative. */)
1374 Lisp_Object string
, lim
;
1376 return skip_chars (0, string
, lim
, 1);
1379 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1380 doc
: /* Move point forward across chars in specified syntax classes.
1381 SYNTAX is a string of syntax code characters.
1382 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1383 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1384 This function returns the distance traveled, either zero or positive. */)
1386 Lisp_Object syntax
, lim
;
1388 return skip_syntaxes (1, syntax
, lim
);
1391 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1392 doc
: /* Move point backward across chars in specified syntax classes.
1393 SYNTAX is a string of syntax code characters.
1394 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1395 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1396 This function returns the distance traveled, either zero or negative. */)
1398 Lisp_Object syntax
, lim
;
1400 return skip_syntaxes (0, syntax
, lim
);
1404 skip_chars (forwardp
, string
, lim
, handle_iso_classes
)
1406 Lisp_Object string
, lim
;
1407 int handle_iso_classes
;
1409 register unsigned int c
;
1410 unsigned char fastmap
[0400];
1411 /* Store the ranges of non-ASCII characters. */
1413 int n_char_ranges
= 0;
1415 register int i
, i_byte
;
1416 /* Set to 1 if the current buffer is multibyte and the region
1417 contains non-ASCII chars. */
1419 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1421 int string_multibyte
;
1423 const unsigned char *str
;
1425 Lisp_Object iso_classes
;
1427 CHECK_STRING (string
);
1431 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1433 CHECK_NUMBER_COERCE_MARKER (lim
);
1435 /* In any case, don't allow scan outside bounds of buffer. */
1436 if (XINT (lim
) > ZV
)
1437 XSETFASTINT (lim
, ZV
);
1438 if (XINT (lim
) < BEGV
)
1439 XSETFASTINT (lim
, BEGV
);
1441 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1442 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1443 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1445 bzero (fastmap
, sizeof fastmap
);
1447 str
= SDATA (string
);
1448 size_byte
= SBYTES (string
);
1451 if (i_byte
< size_byte
1452 && SREF (string
, 0) == '^')
1454 negate
= 1; i_byte
++;
1457 /* Find the characters specified and set their elements of fastmap.
1458 Handle backslashes and ranges specially.
1460 If STRING contains non-ASCII characters, setup char_ranges for
1461 them and use fastmap only for their leading codes. */
1463 if (! string_multibyte
)
1465 int string_has_eight_bit
= 0;
1467 /* At first setup fastmap. */
1468 while (i_byte
< size_byte
)
1472 if (handle_iso_classes
&& c
== '['
1473 && i_byte
< size_byte
1474 && str
[i_byte
] == ':')
1476 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1477 const unsigned char *class_end
= class_beg
;
1478 const unsigned char *class_limit
= str
+ size_byte
- 2;
1479 /* Leave room for the null. */
1480 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1483 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1484 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1486 while (class_end
< class_limit
1487 && *class_end
>= 'a' && *class_end
<= 'z')
1490 if (class_end
== class_beg
1491 || *class_end
!= ':' || class_end
[1] != ']')
1492 goto not_a_class_name
;
1494 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1495 class_name
[class_end
- class_beg
] = 0;
1497 cc
= re_wctype (class_name
);
1499 error ("Invalid ISO C character class");
1501 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1503 i_byte
= class_end
+ 2 - str
;
1510 if (i_byte
== size_byte
)
1515 /* Treat `-' as range character only if another character
1517 if (i_byte
+ 1 < size_byte
1518 && str
[i_byte
] == '-')
1522 /* Skip over the dash. */
1525 /* Get the end of the range. */
1528 && i_byte
< size_byte
)
1535 if (! ASCII_CHAR_P (c2
))
1536 string_has_eight_bit
= 1;
1542 if (! ASCII_CHAR_P (c
))
1543 string_has_eight_bit
= 1;
1547 /* If the current range is multibyte and STRING contains
1548 eight-bit chars, arrange fastmap and setup char_ranges for
1549 the corresponding multibyte chars. */
1550 if (multibyte
&& string_has_eight_bit
)
1552 unsigned char fastmap2
[0400];
1553 int range_start_byte
, range_start_char
;
1555 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1556 bzero (fastmap
+ 0200, 0200);
1557 /* We are sure that this loop stops. */
1558 for (i
= 0200; ! fastmap2
[i
]; i
++);
1559 c
= BYTE8_TO_CHAR (i
);
1560 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1561 range_start_byte
= i
;
1562 range_start_char
= c
;
1563 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1564 for (i
= 129; i
< 0400; i
++)
1566 c
= BYTE8_TO_CHAR (i
);
1567 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1568 if (i
- range_start_byte
!= c
- range_start_char
)
1570 char_ranges
[n_char_ranges
++] = range_start_char
;
1571 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1572 + range_start_char
);
1573 range_start_byte
= i
;
1574 range_start_char
= c
;
1577 char_ranges
[n_char_ranges
++] = range_start_char
;
1578 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1579 + range_start_char
);
1582 else /* STRING is multibyte */
1584 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1586 while (i_byte
< size_byte
)
1588 unsigned char leading_code
;
1590 leading_code
= str
[i_byte
];
1591 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1594 if (handle_iso_classes
&& c
== '['
1595 && i_byte
< size_byte
1596 && STRING_CHAR (str
+ i_byte
, size_byte
- i_byte
) == ':')
1598 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1599 const unsigned char *class_end
= class_beg
;
1600 const unsigned char *class_limit
= str
+ size_byte
- 2;
1601 /* Leave room for the null. */
1602 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1605 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1606 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1608 while (class_end
< class_limit
1609 && *class_end
>= 'a' && *class_end
<= 'z')
1612 if (class_end
== class_beg
1613 || *class_end
!= ':' || class_end
[1] != ']')
1614 goto not_a_class_name_multibyte
;
1616 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1617 class_name
[class_end
- class_beg
] = 0;
1619 cc
= re_wctype (class_name
);
1621 error ("Invalid ISO C character class");
1623 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1625 i_byte
= class_end
+ 2 - str
;
1629 not_a_class_name_multibyte
:
1632 if (i_byte
== size_byte
)
1635 leading_code
= str
[i_byte
];
1636 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1637 size_byte
- i_byte
, len
);
1640 /* Treat `-' as range character only if another character
1642 if (i_byte
+ 1 < size_byte
1643 && str
[i_byte
] == '-')
1646 unsigned char leading_code2
;
1648 /* Skip over the dash. */
1651 /* Get the end of the range. */
1652 leading_code2
= str
[i_byte
];
1653 c2
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1654 size_byte
- i_byte
, len
);
1658 && i_byte
< size_byte
)
1660 leading_code2
= str
[i_byte
];
1661 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1667 if (ASCII_CHAR_P (c
))
1669 while (c
<= c2
&& c
< 0x80)
1671 leading_code
= CHAR_LEADING_CODE (c
);
1673 if (! ASCII_CHAR_P (c
))
1675 while (leading_code
<= leading_code2
)
1676 fastmap
[leading_code
++] = 1;
1679 char_ranges
[n_char_ranges
++] = c
;
1680 char_ranges
[n_char_ranges
++] = c2
;
1686 if (ASCII_CHAR_P (c
))
1690 fastmap
[leading_code
] = 1;
1691 char_ranges
[n_char_ranges
++] = c
;
1692 char_ranges
[n_char_ranges
++] = c
;
1697 /* If the current range is unibyte and STRING contains non-ASCII
1698 chars, arrange fastmap for the corresponding unibyte
1701 if (! multibyte
&& n_char_ranges
> 0)
1703 bzero (fastmap
+ 0200, 0200);
1704 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1706 int c1
= char_ranges
[i
];
1707 int c2
= char_ranges
[i
+ 1];
1709 for (; c1
<= c2
; c1
++)
1711 int b
= CHAR_TO_BYTE_SAFE (c1
);
1719 /* If ^ was the first character, complement the fastmap. */
1723 for (i
= 0; i
< sizeof fastmap
; i
++)
1727 for (i
= 0; i
< 0200; i
++)
1729 /* All non-ASCII chars possibly match. */
1730 for (; i
< sizeof fastmap
; i
++)
1736 int start_point
= PT
;
1738 int pos_byte
= PT_BYTE
;
1739 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1743 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1744 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1748 endp
= CHAR_POS_ADDR (XINT (lim
));
1749 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1767 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1768 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1778 if (! ASCII_CHAR_P (c
))
1780 /* As we are looking at a multibyte character, we
1781 must look up the character in the table
1782 CHAR_RANGES. If there's no data in the table,
1783 that character is not what we want to skip. */
1785 /* The following code do the right thing even if
1786 n_char_ranges is zero (i.e. no data in
1788 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1789 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1791 if (!(negate
^ (i
< n_char_ranges
)))
1795 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1808 if (!NILP (iso_classes
) && in_classes (*p
, iso_classes
))
1813 goto fwd_unibyte_ok
;
1819 p
++, pos
++, pos_byte
++;
1827 unsigned char *prev_p
;
1837 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1838 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1840 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1850 if (! ASCII_CHAR_P (c
))
1852 /* See the comment in the previous similar code. */
1853 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1854 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1856 if (!(negate
^ (i
< n_char_ranges
)))
1860 pos
--, pos_byte
-= prev_p
- p
;
1873 if (! NILP (iso_classes
) && in_classes (p
[-1], iso_classes
))
1878 goto back_unibyte_ok
;
1881 if (!fastmap
[p
[-1]])
1884 p
--, pos
--, pos_byte
--;
1888 SET_PT_BOTH (pos
, pos_byte
);
1891 return make_number (PT
- start_point
);
1897 skip_syntaxes (forwardp
, string
, lim
)
1899 Lisp_Object string
, lim
;
1901 register unsigned int c
;
1902 unsigned char fastmap
[0400];
1904 register int i
, i_byte
;
1909 CHECK_STRING (string
);
1912 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1914 CHECK_NUMBER_COERCE_MARKER (lim
);
1916 /* In any case, don't allow scan outside bounds of buffer. */
1917 if (XINT (lim
) > ZV
)
1918 XSETFASTINT (lim
, ZV
);
1919 if (XINT (lim
) < BEGV
)
1920 XSETFASTINT (lim
, BEGV
);
1922 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1923 return make_number (0);
1925 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1926 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1928 bzero (fastmap
, sizeof fastmap
);
1930 if (SBYTES (string
) > SCHARS (string
))
1931 /* As this is very rare case (syntax spec is ASCII only), don't
1932 consider efficiency. */
1933 string
= string_make_unibyte (string
);
1935 str
= SDATA (string
);
1936 size_byte
= SBYTES (string
);
1939 if (i_byte
< size_byte
1940 && SREF (string
, 0) == '^')
1942 negate
= 1; i_byte
++;
1945 /* Find the syntaxes specified and set their elements of fastmap. */
1947 while (i_byte
< size_byte
)
1950 fastmap
[syntax_spec_code
[c
]] = 1;
1953 /* If ^ was the first character, complement the fastmap. */
1955 for (i
= 0; i
< sizeof fastmap
; i
++)
1959 int start_point
= PT
;
1961 int pos_byte
= PT_BYTE
;
1962 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1966 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1967 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1971 endp
= CHAR_POS_ADDR (XINT (lim
));
1972 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1976 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1992 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1993 if (! fastmap
[(int) SYNTAX (c
)])
1995 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1996 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2010 if (! fastmap
[(int) SYNTAX (*p
)])
2012 p
++, pos
++, pos_byte
++;
2013 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2023 unsigned char *prev_p
;
2032 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2034 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
2035 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
2036 if (! fastmap
[(int) SYNTAX (c
)])
2038 pos
--, pos_byte
-= prev_p
- p
;
2052 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2053 if (! fastmap
[(int) SYNTAX (p
[-1])])
2055 p
--, pos
--, pos_byte
--;
2060 SET_PT_BOTH (pos
, pos_byte
);
2063 return make_number (PT
- start_point
);
2067 /* Return 1 if character C belongs to one of the ISO classes
2068 in the list ISO_CLASSES. Each class is represented by an
2069 integer which is its type according to re_wctype. */
2072 in_classes (c
, iso_classes
)
2074 Lisp_Object iso_classes
;
2078 while (! NILP (iso_classes
))
2081 elt
= XCAR (iso_classes
);
2082 iso_classes
= XCDR (iso_classes
);
2084 if (re_iswctype (c
, XFASTINT (elt
)))
2091 /* Jump over a comment, assuming we are at the beginning of one.
2092 FROM is the current position.
2093 FROM_BYTE is the bytepos corresponding to FROM.
2094 Do not move past STOP (a charpos).
2095 The comment over which we have to jump is of style STYLE
2096 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2097 NESTING should be positive to indicate the nesting at the beginning
2098 for nested comments and should be zero or negative else.
2099 ST_COMMENT_STYLE cannot be nested.
2100 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
2101 (or 0 If the search cannot start in the middle of a two-character).
2103 If successful, return 1 and store the charpos of the comment's end
2104 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
2105 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
2106 corresponding bytepos into *BYTEPOS_PTR and the current nesting
2107 (as defined for state.incomment) in *INCOMMENT_PTR.
2109 The comment end is the last character of the comment rather than the
2110 character just after the comment.
2112 Global syntax data is assumed to initially be valid for FROM and
2113 remains valid for forward search starting at the returned position. */
2116 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
2117 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
2118 EMACS_INT from
, from_byte
, stop
;
2119 int nesting
, style
, prev_syntax
;
2120 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
2124 register enum syntaxcode code
;
2125 register int syntax
;
2127 if (nesting
<= 0) nesting
= -1;
2129 /* Enter the loop in the middle so that we find
2130 a 2-char comment ender if we start in the middle of it. */
2131 syntax
= prev_syntax
;
2132 if (syntax
!= 0) goto forw_incomment
;
2138 *incomment_ptr
= nesting
;
2139 *charpos_ptr
= from
;
2140 *bytepos_ptr
= from_byte
;
2143 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2144 syntax
= SYNTAX_WITH_FLAGS (c
);
2145 code
= syntax
& 0xff;
2146 if (code
== Sendcomment
2147 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2148 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
2149 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
2150 /* we have encountered a comment end of the same style
2151 as the comment sequence which began this comment
2154 if (code
== Scomment_fence
2155 && style
== ST_COMMENT_STYLE
)
2156 /* we have encountered a comment end of the same style
2157 as the comment sequence which began this comment
2162 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
2163 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
2164 /* we have encountered a nested comment of the same style
2165 as the comment sequence which began this comment section */
2167 INC_BOTH (from
, from_byte
);
2168 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2171 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2172 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2173 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2174 SYNTAX_COMEND_SECOND (c1
))
2175 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2176 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2179 /* we have encountered a comment end of the same style
2180 as the comment sequence which began this comment
2185 INC_BOTH (from
, from_byte
);
2186 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2191 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2192 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2193 SYNTAX_COMMENT_STYLE (c1
) == style
2194 && SYNTAX_COMSTART_SECOND (c1
))
2195 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2196 SYNTAX_COMMENT_NESTED (c1
)))
2197 /* we have encountered a nested comment of the same style
2198 as the comment sequence which began this comment
2201 INC_BOTH (from
, from_byte
);
2202 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2206 *charpos_ptr
= from
;
2207 *bytepos_ptr
= from_byte
;
2211 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2213 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2214 Stop scanning if we find something other than a comment or whitespace.
2215 Set point to where scanning stops.
2216 If COUNT comments are found as expected, with nothing except whitespace
2217 between them, return t; otherwise return nil. */)
2221 register EMACS_INT from
;
2222 EMACS_INT from_byte
;
2223 register EMACS_INT stop
;
2225 register enum syntaxcode code
;
2226 int comstyle
= 0; /* style of comment encountered */
2227 int comnested
= 0; /* whether the comment is nestable or not */
2230 EMACS_INT out_charpos
, out_bytepos
;
2233 CHECK_NUMBER (count
);
2234 count1
= XINT (count
);
2235 stop
= count1
> 0 ? ZV
: BEGV
;
2241 from_byte
= PT_BYTE
;
2243 SETUP_SYNTAX_TABLE (from
, count1
);
2252 SET_PT_BOTH (from
, from_byte
);
2256 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2258 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2259 comnested
= SYNTAX_COMMENT_NESTED (c
);
2260 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2261 INC_BOTH (from
, from_byte
);
2262 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2263 if (from
< stop
&& comstart_first
2264 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2265 SYNTAX_COMSTART_SECOND (c1
)))
2267 /* We have encountered a comment start sequence and we
2268 are ignoring all text inside comments. We must record
2269 the comment style this sequence begins so that later,
2270 only a comment end of the same style actually ends
2271 the comment section. */
2273 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2274 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2275 INC_BOTH (from
, from_byte
);
2276 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2279 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2281 if (code
== Scomment_fence
)
2282 comstyle
= ST_COMMENT_STYLE
;
2283 else if (code
!= Scomment
)
2286 DEC_BOTH (from
, from_byte
);
2287 SET_PT_BOTH (from
, from_byte
);
2290 /* We're at the start of a comment. */
2291 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2292 &out_charpos
, &out_bytepos
, &dummy
);
2293 from
= out_charpos
; from_byte
= out_bytepos
;
2297 SET_PT_BOTH (from
, from_byte
);
2300 INC_BOTH (from
, from_byte
);
2301 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2302 /* We have skipped one comment. */
2314 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2319 DEC_BOTH (from
, from_byte
);
2320 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2321 quoted
= char_quoted (from
, from_byte
);
2322 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2325 comnested
= SYNTAX_COMMENT_NESTED (c
);
2326 if (code
== Sendcomment
)
2327 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2328 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2329 && prev_char_comend_first (from
, from_byte
)
2330 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2332 /* We must record the comment style encountered so that
2333 later, we can match only the proper comment begin
2334 sequence of the same style. */
2335 DEC_BOTH (from
, from_byte
);
2337 /* Calling char_quoted, above, set up global syntax position
2338 at the new value of FROM. */
2339 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2340 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2341 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2344 if (code
== Scomment_fence
)
2346 /* Skip until first preceding unquoted comment_fence. */
2347 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2351 DEC_BOTH (from
, from_byte
);
2352 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2353 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2354 if (SYNTAX (c
) == Scomment_fence
2355 && !char_quoted (from
, from_byte
))
2360 else if (from
== stop
)
2365 from
= ini
; /* Set point to ini + 1. */
2366 from_byte
= ini_byte
;
2370 /* We have skipped one comment. */
2373 else if (code
== Sendcomment
)
2375 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2376 &out_charpos
, &out_bytepos
);
2380 /* This end-of-line is not an end-of-comment.
2381 Treat it like a whitespace.
2382 CC-mode (and maybe others) relies on this behavior. */
2386 /* Failure: we should go back to the end of this
2387 not-quite-endcomment. */
2388 if (SYNTAX(c
) != code
)
2389 /* It was a two-char Sendcomment. */
2390 INC_BOTH (from
, from_byte
);
2396 /* We have skipped one comment. */
2397 from
= out_charpos
, from_byte
= out_bytepos
;
2401 else if (code
!= Swhitespace
|| quoted
)
2405 INC_BOTH (from
, from_byte
);
2406 SET_PT_BOTH (from
, from_byte
);
2414 SET_PT_BOTH (from
, from_byte
);
2419 /* Return syntax code of character C if C is an ASCII character
2420 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2422 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2423 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2424 ? SYNTAX (c) : Ssymbol)
2427 scan_lists (from
, count
, depth
, sexpflag
)
2428 register EMACS_INT from
;
2429 EMACS_INT count
, depth
;
2433 register EMACS_INT stop
= count
> 0 ? ZV
: BEGV
;
2438 register enum syntaxcode code
, temp_code
;
2439 int min_depth
= depth
; /* Err out if depth gets less than this. */
2440 int comstyle
= 0; /* style of comment encountered */
2441 int comnested
= 0; /* whether the comment is nestable or not */
2443 EMACS_INT last_good
= from
;
2445 EMACS_INT from_byte
;
2446 EMACS_INT out_bytepos
, out_charpos
;
2448 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2450 if (depth
> 0) min_depth
= 0;
2452 if (from
> ZV
) from
= ZV
;
2453 if (from
< BEGV
) from
= BEGV
;
2455 from_byte
= CHAR_TO_BYTE (from
);
2460 SETUP_SYNTAX_TABLE (from
, count
);
2465 int comstart_first
, prefix
;
2466 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2467 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2468 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2469 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2470 comnested
= SYNTAX_COMMENT_NESTED (c
);
2471 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2472 prefix
= SYNTAX_PREFIX (c
);
2473 if (depth
== min_depth
)
2475 INC_BOTH (from
, from_byte
);
2476 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2477 if (from
< stop
&& comstart_first
2478 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2479 SYNTAX_COMSTART_SECOND (c
))
2480 && parse_sexp_ignore_comments
)
2482 /* we have encountered a comment start sequence and we
2483 are ignoring all text inside comments. We must record
2484 the comment style this sequence begins so that later,
2485 only a comment end of the same style actually ends
2486 the comment section */
2488 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2489 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2490 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2491 INC_BOTH (from
, from_byte
);
2492 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2498 switch (SWITCH_ENUM_CAST (code
))
2504 INC_BOTH (from
, from_byte
);
2505 /* treat following character as a word constituent */
2508 if (depth
|| !sexpflag
) break;
2509 /* This word counts as a sexp; return at end of it. */
2512 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2514 /* Some compilers can't handle this inside the switch. */
2515 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2516 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2521 INC_BOTH (from
, from_byte
);
2532 INC_BOTH (from
, from_byte
);
2536 case Scomment_fence
:
2537 comstyle
= ST_COMMENT_STYLE
;
2540 if (!parse_sexp_ignore_comments
) break;
2541 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2542 found
= forw_comment (from
, from_byte
, stop
,
2543 comnested
, comstyle
, 0,
2544 &out_charpos
, &out_bytepos
, &dummy
);
2545 from
= out_charpos
, from_byte
= out_bytepos
;
2552 INC_BOTH (from
, from_byte
);
2553 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2559 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2561 INC_BOTH (from
, from_byte
);
2571 if (!++depth
) goto done
;
2576 if (!--depth
) goto done
;
2577 if (depth
< min_depth
)
2578 xsignal3 (Qscan_error
,
2579 build_string ("Containing expression ends prematurely"),
2580 make_number (last_good
), make_number (from
));
2585 temp_pos
= dec_bytepos (from_byte
);
2586 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2591 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2592 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2595 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2596 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2599 /* Some compilers can't handle this inside the switch. */
2600 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2605 INC_BOTH (from
, from_byte
);
2607 INC_BOTH (from
, from_byte
);
2609 INC_BOTH (from
, from_byte
);
2610 if (!depth
&& sexpflag
) goto done
;
2613 /* Ignore whitespace, punctuation, quote, endcomment. */
2618 /* Reached end of buffer. Error if within object, return nil if between */
2625 /* End of object reached */
2634 DEC_BOTH (from
, from_byte
);
2635 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2636 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2637 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2638 if (depth
== min_depth
)
2641 comnested
= SYNTAX_COMMENT_NESTED (c
);
2642 if (code
== Sendcomment
)
2643 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2644 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2645 && prev_char_comend_first (from
, from_byte
)
2646 && parse_sexp_ignore_comments
)
2648 /* We must record the comment style encountered so that
2649 later, we can match only the proper comment begin
2650 sequence of the same style. */
2651 DEC_BOTH (from
, from_byte
);
2652 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2654 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2655 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2656 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2659 /* Quoting turns anything except a comment-ender
2660 into a word character. Note that this cannot be true
2661 if we decremented FROM in the if-statement above. */
2662 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2664 DEC_BOTH (from
, from_byte
);
2667 else if (SYNTAX_PREFIX (c
))
2670 switch (SWITCH_ENUM_CAST (code
))
2676 if (depth
|| !sexpflag
) break;
2677 /* This word counts as a sexp; count object finished
2678 after passing it. */
2681 temp_pos
= from_byte
;
2682 if (! NILP (current_buffer
->enable_multibyte_characters
))
2686 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2687 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2688 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2689 /* Don't allow comment-end to be quoted. */
2690 if (temp_code
== Sendcomment
)
2692 quoted
= char_quoted (from
- 1, temp_pos
);
2695 DEC_BOTH (from
, from_byte
);
2696 temp_pos
= dec_bytepos (temp_pos
);
2697 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2699 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2700 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2701 if (! (quoted
|| temp_code
== Sword
2702 || temp_code
== Ssymbol
2703 || temp_code
== Squote
))
2705 DEC_BOTH (from
, from_byte
);
2712 temp_pos
= dec_bytepos (from_byte
);
2713 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2714 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2715 DEC_BOTH (from
, from_byte
);
2724 if (!++depth
) goto done2
;
2729 if (!--depth
) goto done2
;
2730 if (depth
< min_depth
)
2731 xsignal3 (Qscan_error
,
2732 build_string ("Containing expression ends prematurely"),
2733 make_number (last_good
), make_number (from
));
2737 if (!parse_sexp_ignore_comments
)
2739 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2740 &out_charpos
, &out_bytepos
);
2741 /* FIXME: if found == -1, then it really wasn't a comment-end.
2742 For single-char Sendcomment, we can't do much about it apart
2743 from skipping the char.
2744 For 2-char endcomments, we could try again, taking both
2745 chars as separate entities, but it's a lot of trouble
2746 for very little gain, so we don't bother either. -sm */
2748 from
= out_charpos
, from_byte
= out_bytepos
;
2751 case Scomment_fence
:
2757 DEC_BOTH (from
, from_byte
);
2758 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2759 if (!char_quoted (from
, from_byte
)
2760 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2761 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2764 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2768 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2773 DEC_BOTH (from
, from_byte
);
2774 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2775 if (!char_quoted (from
, from_byte
)
2777 == (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
)))
2778 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2781 if (!depth
&& sexpflag
) goto done2
;
2784 /* Ignore whitespace, punctuation, quote, endcomment. */
2789 /* Reached start of buffer. Error if within object, return nil if between */
2802 XSETFASTINT (val
, from
);
2806 xsignal3 (Qscan_error
,
2807 build_string ("Unbalanced parentheses"),
2808 make_number (last_good
), make_number (from
));
2811 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2812 doc
: /* Scan from character number FROM by COUNT lists.
2813 Returns the character number of the position thus found.
2815 If DEPTH is nonzero, paren depth begins counting from that value,
2816 only places where the depth in parentheses becomes zero
2817 are candidates for stopping; COUNT such places are counted.
2818 Thus, a positive value for DEPTH means go out levels.
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 and the depth is wrong, an error is signaled.
2824 If the depth is right but the count is not used up, nil is returned. */)
2825 (from
, count
, depth
)
2826 Lisp_Object from
, count
, depth
;
2828 CHECK_NUMBER (from
);
2829 CHECK_NUMBER (count
);
2830 CHECK_NUMBER (depth
);
2832 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2835 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2836 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2837 If COUNT is negative, scan backwards.
2838 Returns the character number of the position thus found.
2840 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2842 If the beginning or end of (the accessible part of) the buffer is reached
2843 in the middle of a parenthetical grouping, an error is signaled.
2844 If the beginning or end is reached between groupings
2845 but before count is used up, nil is returned. */)
2847 Lisp_Object from
, count
;
2849 CHECK_NUMBER (from
);
2850 CHECK_NUMBER (count
);
2852 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2855 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2857 doc
: /* Move point backward over any number of chars with prefix syntax.
2858 This includes chars with "quote" or "prefix" syntax (' or p). */)
2863 int opoint_byte
= PT_BYTE
;
2865 int pos_byte
= PT_BYTE
;
2870 SET_PT_BOTH (opoint
, opoint_byte
);
2875 SETUP_SYNTAX_TABLE (pos
, -1);
2877 DEC_BOTH (pos
, pos_byte
);
2879 while (!char_quoted (pos
, pos_byte
)
2880 /* Previous statement updates syntax table. */
2881 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2882 || SYNTAX_PREFIX (c
)))
2885 opoint_byte
= pos_byte
;
2888 DEC_BOTH (pos
, pos_byte
);
2891 SET_PT_BOTH (opoint
, opoint_byte
);
2896 /* Parse forward from FROM / FROM_BYTE to END,
2897 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2898 and return a description of the state of the parse at END.
2899 If STOPBEFORE is nonzero, stop at the start of an atom.
2900 If COMMENTSTOP is 1, stop at the start of a comment.
2901 If COMMENTSTOP is -1, stop at the start or end of a comment,
2902 after the beginning of a string, or after the end of a string. */
2905 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2906 stopbefore
, oldstate
, commentstop
)
2907 struct lisp_parse_state
*stateptr
;
2908 register EMACS_INT from
;
2909 EMACS_INT from_byte
, end
;
2910 int targetdepth
, stopbefore
;
2911 Lisp_Object oldstate
;
2914 struct lisp_parse_state state
;
2916 register enum syntaxcode code
;
2919 struct level
{ int last
, prev
; };
2920 struct level levelstart
[100];
2921 register struct level
*curlevel
= levelstart
;
2922 struct level
*endlevel
= levelstart
+ 100;
2923 register int depth
; /* Paren depth of current scanning location.
2924 level - levelstart equals this except
2925 when the depth becomes negative. */
2926 int mindepth
; /* Lowest DEPTH value seen. */
2927 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2929 EMACS_INT prev_from
; /* Keep one character before FROM. */
2930 EMACS_INT prev_from_byte
;
2931 int prev_from_syntax
;
2932 int boundary_stop
= commentstop
== -1;
2935 EMACS_INT out_bytepos
, out_charpos
;
2939 prev_from_byte
= from_byte
;
2941 DEC_BOTH (prev_from
, prev_from_byte
);
2943 /* Use this macro instead of `from++'. */
2945 do { prev_from = from; \
2946 prev_from_byte = from_byte; \
2947 temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
2948 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
2949 INC_BOTH (from, from_byte); \
2951 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2957 if (NILP (oldstate
))
2960 state
.instring
= -1;
2961 state
.incomment
= 0;
2962 state
.comstyle
= 0; /* comment style a by default. */
2963 state
.comstr_start
= -1; /* no comment/string seen. */
2967 tem
= Fcar (oldstate
);
2973 oldstate
= Fcdr (oldstate
);
2974 oldstate
= Fcdr (oldstate
);
2975 oldstate
= Fcdr (oldstate
);
2976 tem
= Fcar (oldstate
);
2977 /* Check whether we are inside string_fence-style string: */
2978 state
.instring
= (!NILP (tem
)
2979 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2982 oldstate
= Fcdr (oldstate
);
2983 tem
= Fcar (oldstate
);
2984 state
.incomment
= (!NILP (tem
)
2985 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
2988 oldstate
= Fcdr (oldstate
);
2989 tem
= Fcar (oldstate
);
2990 start_quoted
= !NILP (tem
);
2992 /* if the eighth element of the list is nil, we are in comment
2993 style a. If it is non-nil, we are in comment style b */
2994 oldstate
= Fcdr (oldstate
);
2995 oldstate
= Fcdr (oldstate
);
2996 tem
= Fcar (oldstate
);
2997 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
2998 ? ST_COMMENT_STYLE
: 1);
3000 oldstate
= Fcdr (oldstate
);
3001 tem
= Fcar (oldstate
);
3002 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
3003 oldstate
= Fcdr (oldstate
);
3004 tem
= Fcar (oldstate
);
3005 while (!NILP (tem
)) /* >= second enclosing sexps. */
3007 /* curlevel++->last ran into compiler bug on Apollo */
3008 curlevel
->last
= XINT (Fcar (tem
));
3009 if (++curlevel
== endlevel
)
3010 curlevel
--; /* error ("Nesting too deep for parser"); */
3011 curlevel
->prev
= -1;
3012 curlevel
->last
= -1;
3019 curlevel
->prev
= -1;
3020 curlevel
->last
= -1;
3022 SETUP_SYNTAX_TABLE (prev_from
, 1);
3023 temp
= FETCH_CHAR (prev_from_byte
);
3024 prev_from_syntax
= SYNTAX_WITH_FLAGS (temp
);
3025 UPDATE_SYNTAX_TABLE_FORWARD (from
);
3027 /* Enter the loop at a place appropriate for initial state. */
3029 if (state
.incomment
)
3030 goto startincomment
;
3031 if (state
.instring
>= 0)
3033 nofence
= state
.instring
!= ST_STRING_STYLE
;
3035 goto startquotedinstring
;
3038 else if (start_quoted
)
3044 code
= prev_from_syntax
& 0xff;
3047 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
)
3048 && (c1
= FETCH_CHAR (from_byte
),
3049 SYNTAX_COMSTART_SECOND (c1
)))
3050 /* Duplicate code to avoid a complex if-expression
3051 which causes trouble for the SGI compiler. */
3053 /* Record the comment style we have entered so that only
3054 the comment-end sequence of the same style actually
3055 terminates the comment section. */
3056 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
3057 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
3058 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
3059 state
.incomment
= comnested
? 1 : -1;
3060 state
.comstr_start
= prev_from
;
3064 else if (code
== Scomment_fence
)
3066 /* Record the comment style we have entered so that only
3067 the comment-end sequence of the same style actually
3068 terminates the comment section. */
3069 state
.comstyle
= ST_COMMENT_STYLE
;
3070 state
.incomment
= -1;
3071 state
.comstr_start
= prev_from
;
3074 else if (code
== Scomment
)
3076 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
3077 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
3079 state
.comstr_start
= prev_from
;
3082 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
3084 switch (SWITCH_ENUM_CAST (code
))
3088 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3089 curlevel
->last
= prev_from
;
3091 if (from
== end
) goto endquoted
;
3094 /* treat following character as a word constituent */
3097 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3098 curlevel
->last
= prev_from
;
3102 /* Some compilers can't handle this inside the switch. */
3103 temp
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3104 temp
= SYNTAX (temp
);
3110 if (from
== end
) goto endquoted
;
3122 curlevel
->prev
= curlevel
->last
;
3125 case Scomment_fence
: /* Can't happen because it's handled above. */
3127 if (commentstop
|| boundary_stop
) goto done
;
3129 /* The (from == BEGV) test was to enter the loop in the middle so
3130 that we find a 2-char comment ender even if we start in the
3131 middle of it. We don't want to do that if we're just at the
3132 beginning of the comment (think of (*) ... (*)). */
3133 found
= forw_comment (from
, from_byte
, end
,
3134 state
.incomment
, state
.comstyle
,
3135 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
3136 ? 0 : prev_from_syntax
,
3137 &out_charpos
, &out_bytepos
, &state
.incomment
);
3138 from
= out_charpos
; from_byte
= out_bytepos
;
3139 /* Beware! prev_from and friends are invalid now.
3140 Luckily, the `done' doesn't use them and the INC_FROM
3141 sets them to a sane value without looking at them. */
3142 if (!found
) goto done
;
3144 state
.incomment
= 0;
3145 state
.comstyle
= 0; /* reset the comment style */
3146 if (boundary_stop
) goto done
;
3150 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3152 /* curlevel++->last ran into compiler bug on Apollo */
3153 curlevel
->last
= prev_from
;
3154 if (++curlevel
== endlevel
)
3155 curlevel
--; /* error ("Nesting too deep for parser"); */
3156 curlevel
->prev
= -1;
3157 curlevel
->last
= -1;
3158 if (targetdepth
== depth
) goto done
;
3163 if (depth
< mindepth
)
3165 if (curlevel
!= levelstart
)
3167 curlevel
->prev
= curlevel
->last
;
3168 if (targetdepth
== depth
) goto done
;
3173 state
.comstr_start
= from
- 1;
3174 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3175 curlevel
->last
= prev_from
;
3176 state
.instring
= (code
== Sstring
3177 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3179 if (boundary_stop
) goto done
;
3182 nofence
= state
.instring
!= ST_STRING_STYLE
;
3188 if (from
>= end
) goto done
;
3189 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3190 /* Some compilers can't handle this inside the switch. */
3193 /* Check TEMP here so that if the char has
3194 a syntax-table property which says it is NOT
3195 a string character, it does not end the string. */
3196 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3202 if (!nofence
) goto string_end
;
3207 startquotedinstring
:
3208 if (from
>= end
) goto endquoted
;
3214 state
.instring
= -1;
3215 curlevel
->prev
= curlevel
->last
;
3217 if (boundary_stop
) goto done
;
3221 /* FIXME: We should do something with it. */
3224 /* Ignore whitespace, punctuation, quote, endcomment. */
3230 stop
: /* Here if stopping before start of sexp. */
3231 from
= prev_from
; /* We have just fetched the char that starts it; */
3232 goto done
; /* but return the position before it. */
3237 state
.depth
= depth
;
3238 state
.mindepth
= mindepth
;
3239 state
.thislevelstart
= curlevel
->prev
;
3240 state
.prevlevelstart
3241 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3242 state
.location
= from
;
3243 state
.levelstarts
= Qnil
;
3244 while (--curlevel
>= levelstart
)
3245 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3252 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3253 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3254 Parsing stops at TO or when certain criteria are met;
3255 point is set to where parsing stops.
3256 If fifth arg OLDSTATE is omitted or nil,
3257 parsing assumes that FROM is the beginning of a function.
3258 Value is a list of elements describing final state of parsing:
3260 1. character address of start of innermost containing list; nil if none.
3261 2. character address of start of last complete sexp terminated.
3262 3. non-nil if inside a string.
3263 (it is the character that will terminate the string,
3264 or t if the string should be terminated by a generic string delimiter.)
3265 4. nil if outside a comment, t if inside a non-nestable comment,
3266 else an integer (the current comment nesting).
3267 5. t if following a quote character.
3268 6. the minimum paren-depth encountered during this scan.
3269 7. t if in a comment of style b; symbol `syntax-table' if the comment
3270 should be terminated by a generic comment delimiter.
3271 8. character address of start of comment or string; nil if not in one.
3272 9. Intermediate data for continuation of parsing (subject to change).
3273 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3274 in parentheses becomes equal to TARGETDEPTH.
3275 Fourth arg STOPBEFORE non-nil means stop when come to
3276 any character that starts a sexp.
3277 Fifth arg OLDSTATE is a list like what this function returns.
3278 It is used to initialize the state of the parse. Elements number 1, 2, 6
3280 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3281 If it is symbol `syntax-table', stop after the start of a comment or a
3282 string, or after end of a comment or a string. */)
3283 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3284 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3286 struct lisp_parse_state state
;
3289 if (!NILP (targetdepth
))
3291 CHECK_NUMBER (targetdepth
);
3292 target
= XINT (targetdepth
);
3295 target
= -100000; /* We won't reach this depth */
3297 validate_region (&from
, &to
);
3298 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3300 target
, !NILP (stopbefore
), oldstate
,
3302 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3304 SET_PT (state
.location
);
3306 return Fcons (make_number (state
.depth
),
3307 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3308 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3309 Fcons (state
.instring
>= 0
3310 ? (state
.instring
== ST_STRING_STYLE
3311 ? Qt
: make_number (state
.instring
)) : Qnil
,
3312 Fcons (state
.incomment
< 0 ? Qt
:
3313 (state
.incomment
== 0 ? Qnil
:
3314 make_number (state
.incomment
)),
3315 Fcons (state
.quoted
? Qt
: Qnil
,
3316 Fcons (make_number (state
.mindepth
),
3317 Fcons ((state
.comstyle
3318 ? (state
.comstyle
== ST_COMMENT_STYLE
3319 ? Qsyntax_table
: Qt
) :
3321 Fcons (((state
.incomment
3322 || (state
.instring
>= 0))
3323 ? make_number (state
.comstr_start
)
3325 Fcons (state
.levelstarts
, Qnil
))))))))));
3334 /* This has to be done here, before we call Fmake_char_table. */
3335 Qsyntax_table
= intern_c_string ("syntax-table");
3336 staticpro (&Qsyntax_table
);
3338 /* Intern_C_String this now in case it isn't already done.
3339 Setting this variable twice is harmless.
3340 But don't staticpro it here--that is done in alloc.c. */
3341 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
3343 /* Create objects which can be shared among syntax tables. */
3344 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3345 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3346 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3347 = Fcons (make_number (i
), Qnil
);
3349 /* Now we are ready to set up this property, so we can
3350 create syntax tables. */
3351 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3353 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3355 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3357 /* Control characters should not be whitespace. */
3358 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3359 for (i
= 0; i
<= ' ' - 1; i
++)
3360 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3361 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 0177, temp
);
3363 /* Except that a few really are whitespace. */
3364 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3365 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ' ', temp
);
3366 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\t', temp
);
3367 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\n', temp
);
3368 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 015, temp
);
3369 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 014, temp
);
3371 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3372 for (i
= 'a'; i
<= 'z'; i
++)
3373 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3374 for (i
= 'A'; i
<= 'Z'; i
++)
3375 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3376 for (i
= '0'; i
<= '9'; i
++)
3377 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3379 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3380 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3382 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3383 Fcons (make_number (Sopen
), make_number (')')));
3384 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3385 Fcons (make_number (Sclose
), make_number ('(')));
3386 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3387 Fcons (make_number (Sopen
), make_number (']')));
3388 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3389 Fcons (make_number (Sclose
), make_number ('[')));
3390 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3391 Fcons (make_number (Sopen
), make_number ('}')));
3392 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3393 Fcons (make_number (Sclose
), make_number ('{')));
3394 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3395 Fcons (make_number ((int) Sstring
), Qnil
));
3396 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3397 Fcons (make_number ((int) Sescape
), Qnil
));
3399 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3400 for (i
= 0; i
< 10; i
++)
3402 c
= "_-+*/&|<>="[i
];
3403 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3406 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3407 for (i
= 0; i
< 12; i
++)
3409 c
= ".,;:?!#@~^'`"[i
];
3410 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3413 /* All multibyte characters have syntax `word' by default. */
3414 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3415 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3421 Qsyntax_table_p
= intern_c_string ("syntax-table-p");
3422 staticpro (&Qsyntax_table_p
);
3424 staticpro (&Vsyntax_code_object
);
3426 staticpro (&gl_state
.object
);
3427 staticpro (&gl_state
.global_code
);
3428 staticpro (&gl_state
.current_syntax_table
);
3429 staticpro (&gl_state
.old_prop
);
3431 /* Defined in regex.c */
3432 staticpro (&re_match_object
);
3434 Qscan_error
= intern_c_string ("scan-error");
3435 staticpro (&Qscan_error
);
3436 Fput (Qscan_error
, Qerror_conditions
,
3437 pure_cons (Qscan_error
, pure_cons (Qerror
, Qnil
)));
3438 Fput (Qscan_error
, Qerror_message
,
3439 make_pure_c_string ("Scan error"));
3441 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3442 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3444 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3445 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3446 Otherwise, that text property is simply ignored.
3447 See the info node `(elisp)Syntax Properties' for a description of the
3448 `syntax-table' property. */);
3450 words_include_escapes
= 0;
3451 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3452 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3454 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3455 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3456 multibyte_syntax_as_symbol
= 0;
3458 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3459 &open_paren_in_column_0_is_defun_start
,
3460 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3461 open_paren_in_column_0_is_defun_start
= 1;
3464 DEFVAR_LISP ("find-word-boundary-function-table",
3465 &Vfind_word_boundary_function_table
,
3467 Char table of functions to search for the word boundary.
3468 Each function is called with two arguments; POS and LIMIT.
3469 POS and LIMIT are character positions in the current buffer.
3471 If POS is less than LIMIT, POS is at the first character of a word,
3472 and the return value of a function is a position after the last
3473 character of that word.
3475 If POS is not less than LIMIT, POS is at the last character of a word,
3476 and the return value of a function is a position at the first
3477 character of that word.
3479 In both cases, LIMIT bounds the search. */);
3480 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3482 defsubr (&Ssyntax_table_p
);
3483 defsubr (&Ssyntax_table
);
3484 defsubr (&Sstandard_syntax_table
);
3485 defsubr (&Scopy_syntax_table
);
3486 defsubr (&Sset_syntax_table
);
3487 defsubr (&Schar_syntax
);
3488 defsubr (&Smatching_paren
);
3489 defsubr (&Sstring_to_syntax
);
3490 defsubr (&Smodify_syntax_entry
);
3491 defsubr (&Sinternal_describe_syntax_value
);
3493 defsubr (&Sforward_word
);
3495 defsubr (&Sskip_chars_forward
);
3496 defsubr (&Sskip_chars_backward
);
3497 defsubr (&Sskip_syntax_forward
);
3498 defsubr (&Sskip_syntax_backward
);
3500 defsubr (&Sforward_comment
);
3501 defsubr (&Sscan_lists
);
3502 defsubr (&Sscan_sexps
);
3503 defsubr (&Sbackward_prefix_chars
);
3504 defsubr (&Sparse_partial_sexp
);
3507 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
3508 (do not change this comment) */