2 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
3 Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2001,
4 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 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 thislevelstart
; /* Char number of most recent start-of-expression at current level */
75 int prevlevelstart
; /* Char number of start of containing expression */
76 int location
; /* Char number at which parsing stopped. */
77 int mindepth
; /* Minimum depth seen while scanning. */
78 int comstr_start
; /* Position just after last comment/string starter. */
79 Lisp_Object levelstarts
; /* Char numbers of starts-of-expression
80 of levels (starting from outermost). */
83 /* These variables are a cache for finding the start of a defun.
84 find_start_pos is the place for which the defun start was found.
85 find_start_value is the defun start position found for it.
86 find_start_value_byte is the corresponding byte position.
87 find_start_buffer is the buffer it was found in.
88 find_start_begv is the BEGV value when it was found.
89 find_start_modiff is the value of MODIFF when it was found. */
91 static int find_start_pos
;
92 static int find_start_value
;
93 static int find_start_value_byte
;
94 static struct buffer
*find_start_buffer
;
95 static int find_start_begv
;
96 static int find_start_modiff
;
99 static int find_defun_start
P_ ((int, int));
100 static int back_comment
P_ ((EMACS_INT
, EMACS_INT
, EMACS_INT
, int, int,
101 EMACS_INT
*, EMACS_INT
*));
102 static int char_quoted
P_ ((int, int));
103 static Lisp_Object skip_chars
P_ ((int, Lisp_Object
, Lisp_Object
, int));
104 static Lisp_Object skip_syntaxes
P_ ((int, Lisp_Object
, Lisp_Object
));
105 static Lisp_Object scan_lists
P_ ((EMACS_INT
, EMACS_INT
, EMACS_INT
, int));
106 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
108 int, Lisp_Object
, int));
109 static int in_classes
P_ ((int, Lisp_Object
));
112 struct gl_state_s gl_state
; /* Global state of syntax parser. */
114 INTERVAL
interval_of ();
115 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
116 to scan to property-change. */
118 /* Update gl_state to an appropriate interval which contains CHARPOS. The
119 sign of COUNT give the relative position of CHARPOS wrt the previously
120 valid interval. If INIT, only [be]_property fields of gl_state are
121 valid at start, the rest is filled basing on OBJECT.
123 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
124 direction than the intervals - or in an interval. We update the
125 current syntax-table basing on the property of this interval, and
126 update the interval to start further than CHARPOS - or be
127 NULL_INTERVAL. We also update lim_property to be the next value of
128 charpos to call this subroutine again - or be before/after the
129 start/end of OBJECT. */
132 update_syntax_table (charpos
, count
, init
, object
)
133 int charpos
, count
, init
;
136 Lisp_Object tmp_table
;
137 int cnt
= 0, invalidate
= 1;
142 gl_state
.old_prop
= Qnil
;
143 gl_state
.start
= gl_state
.b_property
;
144 gl_state
.stop
= gl_state
.e_property
;
145 i
= interval_of (charpos
, object
);
146 gl_state
.backward_i
= gl_state
.forward_i
= i
;
148 if (NULL_INTERVAL_P (i
))
150 /* interval_of updates only ->position of the return value, so
151 update the parents manually to speed up update_interval. */
152 while (!NULL_PARENT (i
))
154 if (AM_RIGHT_CHILD (i
))
155 INTERVAL_PARENT (i
)->position
= i
->position
156 - LEFT_TOTAL_LENGTH (i
) + TOTAL_LENGTH (i
) /* right end */
157 - TOTAL_LENGTH (INTERVAL_PARENT (i
))
158 + LEFT_TOTAL_LENGTH (INTERVAL_PARENT (i
));
160 INTERVAL_PARENT (i
)->position
= i
->position
- LEFT_TOTAL_LENGTH (i
)
162 i
= INTERVAL_PARENT (i
);
164 i
= gl_state
.forward_i
;
165 gl_state
.b_property
= i
->position
- gl_state
.offset
;
166 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
169 i
= count
> 0 ? gl_state
.forward_i
: gl_state
.backward_i
;
171 /* We are guaranteed to be called with CHARPOS either in i,
173 if (NULL_INTERVAL_P (i
))
174 error ("Error in syntax_table logic for to-the-end intervals");
175 else if (charpos
< i
->position
) /* Move left. */
178 error ("Error in syntax_table logic for intervals <-");
179 /* Update the interval. */
180 i
= update_interval (i
, charpos
);
181 if (INTERVAL_LAST_POS (i
) != gl_state
.b_property
)
184 gl_state
.forward_i
= i
;
185 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
188 else if (charpos
>= INTERVAL_LAST_POS (i
)) /* Move right. */
191 error ("Error in syntax_table logic for intervals ->");
192 /* Update the interval. */
193 i
= update_interval (i
, charpos
);
194 if (i
->position
!= gl_state
.e_property
)
197 gl_state
.backward_i
= i
;
198 gl_state
.b_property
= i
->position
- gl_state
.offset
;
203 tmp_table
= textget (i
->plist
, Qsyntax_table
);
206 invalidate
= !EQ (tmp_table
, gl_state
.old_prop
); /* Need to invalidate? */
208 if (invalidate
) /* Did not get to adjacent interval. */
209 { /* with the same table => */
210 /* invalidate the old range. */
213 gl_state
.backward_i
= i
;
214 gl_state
.b_property
= i
->position
- gl_state
.offset
;
218 gl_state
.forward_i
= i
;
219 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
223 if (!EQ (tmp_table
, gl_state
.old_prop
))
225 gl_state
.current_syntax_table
= tmp_table
;
226 gl_state
.old_prop
= tmp_table
;
227 if (EQ (Fsyntax_table_p (tmp_table
), Qt
))
229 gl_state
.use_global
= 0;
231 else if (CONSP (tmp_table
))
233 gl_state
.use_global
= 1;
234 gl_state
.global_code
= tmp_table
;
238 gl_state
.use_global
= 0;
239 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
243 while (!NULL_INTERVAL_P (i
))
245 if (cnt
&& !EQ (tmp_table
, textget (i
->plist
, Qsyntax_table
)))
249 gl_state
.e_property
= i
->position
- gl_state
.offset
;
250 gl_state
.forward_i
= i
;
255 = i
->position
+ LENGTH (i
) - gl_state
.offset
;
256 gl_state
.backward_i
= i
;
260 else if (cnt
== INTERVALS_AT_ONCE
)
265 = i
->position
+ LENGTH (i
) - gl_state
.offset
266 /* e_property at EOB is not set to ZV but to ZV+1, so that
267 we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
268 having to check eob between the two. */
269 + (NULL_INTERVAL_P (next_interval (i
)) ? 1 : 0);
270 gl_state
.forward_i
= i
;
274 gl_state
.b_property
= i
->position
- gl_state
.offset
;
275 gl_state
.backward_i
= i
;
280 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
282 eassert (NULL_INTERVAL_P (i
)); /* This property goes to the end. */
284 gl_state
.e_property
= gl_state
.stop
;
286 gl_state
.b_property
= gl_state
.start
;
289 /* Returns TRUE if char at CHARPOS is quoted.
290 Global syntax-table data should be set up already to be good at CHARPOS
291 or after. On return global syntax data is good for lookup at CHARPOS. */
294 char_quoted (charpos
, bytepos
)
295 register int charpos
, bytepos
;
297 register enum syntaxcode code
;
298 register int beg
= BEGV
;
299 register int quoted
= 0;
303 /* For some reason keeps getting called w/both 1, then segfaulting
304 due to the definitions of DEC_BOTH and DEC_POS in character.h,
305 which lead to decrementing below initial address and then examining
306 character there. Need to investigate further.. */
307 if (charpos
< 2 || bytepos
< 2)
309 //fprintf(stderr,"Returning because charpos = %d, bytepos = %d\n",charpos, bytepos);
314 DEC_BOTH (charpos
, bytepos
);
316 while (charpos
>= beg
)
320 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
321 c
= FETCH_CHAR_AS_MULTIBYTE (bytepos
);
323 if (! (code
== Scharquote
|| code
== Sescape
))
326 DEC_BOTH (charpos
, bytepos
);
330 UPDATE_SYNTAX_TABLE (orig
);
334 /* Return the bytepos one character after BYTEPOS.
335 We assume that BYTEPOS is not at the end of the buffer. */
338 inc_bytepos (bytepos
)
341 if (NILP (current_buffer
->enable_multibyte_characters
))
348 /* Return the bytepos one character before BYTEPOS.
349 We assume that BYTEPOS is not at the start of the buffer. */
352 dec_bytepos (bytepos
)
355 if (NILP (current_buffer
->enable_multibyte_characters
))
362 /* Return a defun-start position before before POS and not too far before.
363 It should be the last one before POS, or nearly the last.
365 When open_paren_in_column_0_is_defun_start is nonzero,
366 only the beginning of the buffer is treated as a defun-start.
368 We record the information about where the scan started
369 and what its result was, so that another call in the same area
370 can return the same value very quickly.
372 There is no promise at which position the global syntax data is
373 valid on return from the subroutine, so the caller should explicitly
374 update the global data. */
377 find_defun_start (pos
, pos_byte
)
380 int opoint
= PT
, opoint_byte
= PT_BYTE
;
382 if (!open_paren_in_column_0_is_defun_start
)
384 find_start_value_byte
= BEGV_BYTE
;
388 /* Use previous finding, if it's valid and applies to this inquiry. */
389 if (current_buffer
== find_start_buffer
390 /* Reuse the defun-start even if POS is a little farther on.
391 POS might be in the next defun, but that's ok.
392 Our value may not be the best possible, but will still be usable. */
393 && pos
<= find_start_pos
+ 1000
394 && pos
>= find_start_value
395 && BEGV
== find_start_begv
396 && MODIFF
== find_start_modiff
)
397 return find_start_value
;
399 /* Back up to start of line. */
400 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
402 /* We optimize syntax-table lookup for rare updates. Thus we accept
403 only those `^\s(' which are good in global _and_ text-property
405 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
406 gl_state
.use_global
= 0;
411 /* Open-paren at start of line means we may have found our
413 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
414 if (SYNTAX (c
) == Sopen
)
416 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
417 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
418 if (SYNTAX (c
) == Sopen
)
420 /* Now fallback to the default value. */
421 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
422 gl_state
.use_global
= 0;
424 /* Move to beg of previous line. */
425 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
428 /* Record what we found, for the next try. */
429 find_start_value
= PT
;
430 find_start_value_byte
= PT_BYTE
;
431 find_start_buffer
= current_buffer
;
432 find_start_modiff
= MODIFF
;
433 find_start_begv
= BEGV
;
434 find_start_pos
= pos
;
436 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
438 return find_start_value
;
441 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
444 prev_char_comend_first (pos
, pos_byte
)
449 DEC_BOTH (pos
, pos_byte
);
450 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
451 c
= FETCH_CHAR (pos_byte
);
452 val
= SYNTAX_COMEND_FIRST (c
);
453 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
457 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
460 * prev_char_comstart_first (pos, pos_byte)
465 * DEC_BOTH (pos, pos_byte);
466 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
467 * c = FETCH_CHAR (pos_byte);
468 * val = SYNTAX_COMSTART_FIRST (c);
469 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
473 /* Checks whether charpos FROM is at the end of a comment.
474 FROM_BYTE is the bytepos corresponding to FROM.
475 Do not move back before STOP.
477 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
480 If successful, store the charpos of the comment's beginning
481 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
483 Global syntax data remains valid for backward search starting at
484 the returned value (or at FROM, if the search was not successful). */
487 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
488 EMACS_INT from
, from_byte
, stop
;
489 int comnested
, comstyle
;
490 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
492 /* Look back, counting the parity of string-quotes,
493 and recording the comment-starters seen.
494 When we reach a safe place, assume that's not in a string;
495 then step the main scan to the earliest comment-starter seen
496 an even number of string quotes away from the safe place.
498 OFROM[I] is position of the earliest comment-starter seen
499 which is I+2X quotes from the comment-end.
500 PARITY is current parity of quotes from the comment end. */
501 int string_style
= -1; /* Presumed outside of any string. */
502 int string_lossage
= 0;
503 /* Not a real lossage: indicates that we have passed a matching comment
504 starter plus a non-matching comment-ender, meaning that any matching
505 comment-starter we might see later could be a false positive (hidden
506 inside another comment).
507 Test case: { a (* b } c (* d *) */
508 int comment_lossage
= 0;
509 int comment_end
= from
;
510 int comment_end_byte
= from_byte
;
511 int comstart_pos
= 0;
513 /* Place where the containing defun starts,
514 or 0 if we didn't come across it yet. */
516 int defun_start_byte
= 0;
517 register enum syntaxcode code
;
518 int nesting
= 1; /* current comment nesting */
522 /* FIXME: A }} comment-ender style leads to incorrect behavior
523 in the case of {{ c }}} because we ignore the last two chars which are
524 assumed to be comment-enders although they aren't. */
526 /* At beginning of range to scan, we're outside of strings;
527 that determines quote parity to the comment-end. */
530 int temp_byte
, prev_syntax
;
531 int com2start
, com2end
;
533 /* Move back and examine a character. */
534 DEC_BOTH (from
, from_byte
);
535 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
537 prev_syntax
= syntax
;
538 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
539 syntax
= SYNTAX_WITH_FLAGS (c
);
542 /* Check for 2-char comment markers. */
543 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
544 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
545 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
546 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
547 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
548 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
549 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
551 /* Nasty cases with overlapping 2-char comment markers:
552 - snmp-mode: -- c -- foo -- c --
560 /* If a 2-char comment sequence partly overlaps with another,
561 we don't try to be clever. */
562 if (from
> stop
&& (com2end
|| com2start
))
564 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
565 DEC_BOTH (next
, next_byte
);
566 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
567 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
568 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
569 if (((com2start
|| comnested
)
570 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
571 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
572 || ((com2end
|| comnested
)
573 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
574 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
575 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
577 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
580 if (com2start
&& comstart_pos
== 0)
581 /* We're looking at a comment starter. But it might be a comment
582 ender as well (see snmp-mode). The first time we see one, we
583 need to consider it as a comment starter,
584 and the subsequent times as a comment ender. */
587 /* Turn a 2-char comment sequences into the appropriate syntax. */
592 /* Ignore comment starters of a different style. */
593 else if (code
== Scomment
594 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
595 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
598 /* Ignore escaped characters, except comment-enders. */
599 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
606 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
608 /* Track parity of quotes. */
609 if (string_style
== -1)
610 /* Entering a string. */
612 else if (string_style
== c
)
613 /* Leaving the string. */
616 /* If we have two kinds of string delimiters.
617 There's no way to grok this scanning backwards. */
622 /* We've already checked that it is the relevant comstyle. */
623 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
624 /* There are odd string quotes involved, so let's be careful.
625 Test case in Pascal: " { " a { " } */
630 /* Record best comment-starter so far. */
632 comstart_byte
= from_byte
;
634 else if (--nesting
<= 0)
635 /* nested comments have to be balanced, so we don't need to
636 keep looking for earlier ones. We use here the same (slightly
637 incorrect) reasoning as below: since it is followed by uniform
638 paired string quotes, this comment-start has to be outside of
639 strings, else the comment-end itself would be inside a string. */
644 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
645 && ((com2end
&& SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
))
646 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
647 /* This is the same style of comment ender as ours. */
652 /* Anything before that can't count because it would match
653 this comment-ender rather than ours. */
654 from
= stop
; /* Break out of the loop. */
656 else if (comstart_pos
!= 0 || c
!= '\n')
657 /* We're mixing comment styles here, so we'd better be careful.
658 The (comstart_pos != 0 || c != '\n') check is not quite correct
659 (we should just always set comment_lossage), but removing it
660 would imply that any multiline comment in C would go through
661 lossage, which seems overkill.
662 The failure should only happen in the rare cases such as
668 /* Assume a defun-start point is outside of strings. */
669 if (open_paren_in_column_0_is_defun_start
671 || (temp_byte
= dec_bytepos (from_byte
),
672 FETCH_CHAR (temp_byte
) == '\n')))
675 defun_start_byte
= from_byte
;
676 from
= stop
; /* Break out of the loop. */
685 if (comstart_pos
== 0)
688 from_byte
= comment_end_byte
;
689 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
691 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
692 or `done'), then we've found the beginning of the non-nested comment. */
693 else if (1) /* !comnested */
696 from_byte
= comstart_byte
;
697 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
701 struct lisp_parse_state state
;
703 /* We had two kinds of string delimiters mixed up
704 together. Decode this going forwards.
705 Scan fwd from a known safe place (beginning-of-defun)
706 to the one in question; this records where we
707 last passed a comment starter. */
708 /* If we did not already find the defun start, find it now. */
709 if (defun_start
== 0)
711 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
712 defun_start_byte
= find_start_value_byte
;
716 scan_sexps_forward (&state
,
717 defun_start
, defun_start_byte
,
718 comment_end
, -10000, 0, Qnil
, 0);
719 defun_start
= comment_end
;
720 if (state
.incomment
== (comnested
? 1 : -1)
721 && state
.comstyle
== comstyle
)
722 from
= state
.comstr_start
;
727 /* If comment_end is inside some other comment, maybe ours
728 is nested, so we need to try again from within the
729 surrounding comment. Example: { a (* " *) */
731 /* FIXME: We should advance by one or two chars. */
732 defun_start
= state
.comstr_start
+ 2;
733 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
736 } while (defun_start
< comment_end
);
738 from_byte
= CHAR_TO_BYTE (from
);
739 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
744 *bytepos_ptr
= from_byte
;
746 return (from
== comment_end
) ? -1 : from
;
749 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
750 doc
: /* Return t if OBJECT is a syntax table.
751 Currently, any char-table counts as a syntax table. */)
755 if (CHAR_TABLE_P (object
)
756 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
762 check_syntax_table (obj
)
765 CHECK_TYPE (CHAR_TABLE_P (obj
) && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
),
766 Qsyntax_table_p
, obj
);
769 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
770 doc
: /* Return the current syntax table.
771 This is the one specified by the current buffer. */)
774 return current_buffer
->syntax_table
;
777 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
778 Sstandard_syntax_table
, 0, 0, 0,
779 doc
: /* Return the standard syntax table.
780 This is the one used for new buffers. */)
783 return Vstandard_syntax_table
;
786 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
787 doc
: /* Construct a new syntax table and return it.
788 It is a copy of the TABLE, which defaults to the standard syntax table. */)
795 check_syntax_table (table
);
797 table
= Vstandard_syntax_table
;
799 copy
= Fcopy_sequence (table
);
801 /* Only the standard syntax table should have a default element.
802 Other syntax tables should inherit from parents instead. */
803 XCHAR_TABLE (copy
)->defalt
= Qnil
;
805 /* Copied syntax tables should all have parents.
806 If we copied one with no parent, such as the standard syntax table,
807 use the standard syntax table as the copy's parent. */
808 if (NILP (XCHAR_TABLE (copy
)->parent
))
809 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
813 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
814 doc
: /* Select a new syntax table for the current buffer.
815 One argument, a syntax table. */)
820 check_syntax_table (table
);
821 current_buffer
->syntax_table
= table
;
822 /* Indicate that this buffer now has a specified syntax table. */
823 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
824 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
828 /* Convert a letter which signifies a syntax code
829 into the code it signifies.
830 This is used by modify-syntax-entry, and other things. */
832 unsigned char syntax_spec_code
[0400] =
833 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
834 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
835 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
836 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
837 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
838 (char) Smath
, 0377, 0377, (char) Squote
,
839 (char) Sopen
, (char) Sclose
, 0377, 0377,
840 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
841 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
842 0377, 0377, 0377, 0377,
843 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
844 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
845 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
846 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
847 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
848 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
849 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
850 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
851 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
854 /* Indexed by syntax code, give the letter that describes it. */
856 char syntax_code_spec
[16] =
858 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
862 /* Indexed by syntax code, give the object (cons of syntax code and
863 nil) to be stored in syntax table. Since these objects can be
864 shared among syntax tables, we generate them in advance. By
865 sharing objects, the function `describe-syntax' can give a more
867 static Lisp_Object Vsyntax_code_object
;
870 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
871 doc
: /* Return the syntax code of CHARACTER, described by a character.
872 For example, if CHARACTER is a word constituent,
873 the character `w' is returned.
874 The characters that correspond to various syntax codes
875 are listed in the documentation of `modify-syntax-entry'. */)
877 Lisp_Object character
;
880 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
882 gl_state
.use_global
= 0;
883 CHECK_NUMBER (character
);
884 char_int
= XINT (character
);
885 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
888 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
889 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
891 Lisp_Object character
;
894 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
895 gl_state
.use_global
= 0;
896 CHECK_NUMBER (character
);
897 char_int
= XINT (character
);
898 code
= SYNTAX (char_int
);
899 if (code
== Sopen
|| code
== Sclose
)
900 return SYNTAX_MATCH (char_int
);
904 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
905 doc
: /* Convert a syntax specification STRING into syntax cell form.
906 STRING should be a string as it is allowed as argument of
907 `modify-syntax-entry'. Value is the equivalent cons cell
908 \(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
913 register const unsigned char *p
;
914 register enum syntaxcode code
;
918 CHECK_STRING (string
);
921 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
922 if (((int) code
& 0377) == 0377)
923 error ("Invalid syntax description letter: %c", p
[-1]);
925 if (code
== Sinherit
)
931 int character
= (STRING_CHAR_AND_LENGTH
932 (p
, SBYTES (string
) - 1, len
));
933 XSETINT (match
, character
);
934 if (XFASTINT (match
) == ' ')
974 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
975 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
977 /* Since we can't use a shared object, let's make a new one. */
978 return Fcons (make_number (val
), match
);
981 /* I really don't know why this is interactive
982 help-form should at least be made useful whilst reading the second arg. */
983 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
984 "cSet syntax for character: \nsSet syntax for %s to: ",
985 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
986 The syntax is changed only for table SYNTAX-TABLE, which defaults to
987 the current buffer's syntax table.
988 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
989 in the range MIN and MAX are changed.
990 The first character of NEWENTRY should be one of the following:
991 Space or - whitespace syntax. w word constituent.
992 _ symbol constituent. . punctuation.
993 ( open-parenthesis. ) close-parenthesis.
994 " string quote. \\ escape.
995 $ paired delimiter. ' expression quote or prefix operator.
996 < comment starter. > comment ender.
997 / character-quote. @ inherit from `standard-syntax-table'.
998 | generic string fence. ! generic comment fence.
1000 Only single-character comment start and end sequences are represented thus.
1001 Two-character sequences are represented as described below.
1002 The second character of NEWENTRY is the matching parenthesis,
1003 used only if the first character is `(' or `)'.
1004 Any additional characters are flags.
1005 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
1006 1 means CHAR is the start of a two-char comment start sequence.
1007 2 means CHAR is the second character of such a sequence.
1008 3 means CHAR is the start of a two-char comment end sequence.
1009 4 means CHAR is the second character of such a sequence.
1011 There can be up to two orthogonal comment sequences. This is to support
1012 language modes such as C++. By default, all comment sequences are of style
1013 a, but you can set the comment sequence style to b (on the second character
1014 of a comment-start, or the first character of a comment-end sequence) using
1016 b means CHAR is part of comment sequence b.
1017 n means CHAR is part of a nestable comment sequence.
1019 p means CHAR is a prefix character for `backward-prefix-chars';
1020 such characters are treated as whitespace when they occur
1021 between expressions.
1022 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1023 (c
, newentry
, syntax_table
)
1024 Lisp_Object c
, newentry
, syntax_table
;
1028 CHECK_CHARACTER_CAR (c
);
1029 CHECK_CHARACTER_CDR (c
);
1032 CHECK_CHARACTER (c
);
1034 if (NILP (syntax_table
))
1035 syntax_table
= current_buffer
->syntax_table
;
1037 check_syntax_table (syntax_table
);
1039 newentry
= Fstring_to_syntax (newentry
);
1041 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1043 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1045 /* We clear the regexp cache, since character classes can now have
1046 different values from those in the compiled regexps.*/
1047 clear_regexp_cache ();
1052 /* Dump syntax table to buffer in human-readable format */
1054 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1055 Sinternal_describe_syntax_value
, 1, 1, 0,
1056 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1060 register enum syntaxcode code
;
1061 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1063 Lisp_Object first
, match_lisp
, value
= syntax
;
1067 insert_string ("default");
1071 if (CHAR_TABLE_P (value
))
1073 insert_string ("deeper char-table ...");
1079 insert_string ("invalid");
1083 first
= XCAR (value
);
1084 match_lisp
= XCDR (value
);
1086 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1088 insert_string ("invalid");
1092 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1093 start1
= (XINT (first
) >> 16) & 1;
1094 start2
= (XINT (first
) >> 17) & 1;
1095 end1
= (XINT (first
) >> 18) & 1;
1096 end2
= (XINT (first
) >> 19) & 1;
1097 prefix
= (XINT (first
) >> 20) & 1;
1098 comstyle
= (XINT (first
) >> 21) & 1;
1099 comnested
= (XINT (first
) >> 22) & 1;
1101 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1103 insert_string ("invalid");
1106 desc
= syntax_code_spec
[(int) code
];
1108 str
[0] = desc
, str
[1] = 0;
1111 if (NILP (match_lisp
))
1114 insert_char (XINT (match_lisp
));
1133 insert_string ("\twhich means: ");
1135 switch (SWITCH_ENUM_CAST (code
))
1138 insert_string ("whitespace"); break;
1140 insert_string ("punctuation"); break;
1142 insert_string ("word"); break;
1144 insert_string ("symbol"); break;
1146 insert_string ("open"); break;
1148 insert_string ("close"); break;
1150 insert_string ("prefix"); break;
1152 insert_string ("string"); break;
1154 insert_string ("math"); break;
1156 insert_string ("escape"); break;
1158 insert_string ("charquote"); break;
1160 insert_string ("comment"); break;
1162 insert_string ("endcomment"); break;
1164 insert_string ("inherit"); break;
1165 case Scomment_fence
:
1166 insert_string ("comment fence"); break;
1168 insert_string ("string fence"); break;
1170 insert_string ("invalid");
1174 if (!NILP (match_lisp
))
1176 insert_string (", matches ");
1177 insert_char (XINT (match_lisp
));
1181 insert_string (",\n\t is the first character of a comment-start sequence");
1183 insert_string (",\n\t is the second character of a comment-start sequence");
1186 insert_string (",\n\t is the first character of a comment-end sequence");
1188 insert_string (",\n\t is the second character of a comment-end sequence");
1190 insert_string (" (comment style b)");
1192 insert_string (" (nestable)");
1195 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1200 int parse_sexp_ignore_comments
;
1202 /* Char-table of functions that find the next or previous word
1204 Lisp_Object Vfind_word_boundary_function_table
;
1206 /* Return the position across COUNT words from FROM.
1207 If that many words cannot be found before the end of the buffer, return 0.
1208 COUNT negative means scan backward and stop at word beginning. */
1211 scan_words (from
, count
)
1212 register int from
, count
;
1214 register int beg
= BEGV
;
1215 register int end
= ZV
;
1216 register int from_byte
= CHAR_TO_BYTE (from
);
1217 register enum syntaxcode code
;
1219 Lisp_Object func
, script
, pos
;
1224 SETUP_SYNTAX_TABLE (from
, count
);
1235 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1236 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1237 code
= SYNTAX (ch0
);
1238 INC_BOTH (from
, from_byte
);
1239 if (words_include_escapes
1240 && (code
== Sescape
|| code
== Scharquote
))
1245 /* Now CH0 is a character which begins a word and FROM is the
1246 position of the next character. */
1247 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch0
);
1248 if (! NILP (Ffboundp (func
)))
1250 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1251 if (INTEGERP (pos
) && XINT (pos
) > from
)
1254 from_byte
= CHAR_TO_BYTE (from
);
1259 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1262 if (from
== end
) break;
1263 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1264 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1265 code
= SYNTAX (ch1
);
1267 && (! words_include_escapes
1268 || (code
!= Sescape
&& code
!= Scharquote
)))
1269 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch1
), script
))
1271 INC_BOTH (from
, from_byte
);
1286 DEC_BOTH (from
, from_byte
);
1287 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1288 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1289 code
= SYNTAX (ch1
);
1290 if (words_include_escapes
1291 && (code
== Sescape
|| code
== Scharquote
))
1296 /* Now CH1 is a character which ends a word and FROM is the
1298 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch1
);
1299 if (! NILP (Ffboundp (func
)))
1301 pos
= call2 (func
, make_number (from
), make_number (beg
));
1302 if (INTEGERP (pos
) && XINT (pos
) < from
)
1305 from_byte
= CHAR_TO_BYTE (from
);
1310 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1315 DEC_BOTH (from
, from_byte
);
1316 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1317 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1318 code
= SYNTAX (ch0
);
1320 && (! words_include_escapes
1321 || (code
!= Sescape
&& code
!= Scharquote
)))
1322 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch0
), script
))
1324 INC_BOTH (from
, from_byte
);
1338 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 0, 1, "^p",
1339 doc
: /* Move point forward ARG words (backward if ARG is negative).
1341 If an edge of the buffer or a field boundary is reached, point is left there
1342 and the function returns nil. Field boundaries are not noticed if
1343 `inhibit-field-text-motion' is non-nil. */)
1351 XSETFASTINT (arg
, 1);
1355 val
= orig_val
= scan_words (PT
, XINT (arg
));
1357 val
= XINT (arg
) > 0 ? ZV
: BEGV
;
1359 /* Avoid jumping out of an input field. */
1360 tmp
= Fconstrain_to_field (make_number (val
), make_number (PT
),
1362 val
= XFASTINT (tmp
);
1365 return val
== orig_val
? Qt
: Qnil
;
1368 Lisp_Object
skip_chars ();
1370 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1371 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1372 STRING is like the inside of a `[...]' in a regular expression
1373 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1374 (but not as the end of a range; quoting is never needed there).
1375 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1376 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1377 Char classes, e.g. `[:alpha:]', are supported.
1379 Returns the distance traveled, either zero or positive. */)
1381 Lisp_Object string
, lim
;
1383 return skip_chars (1, string
, lim
, 1);
1386 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1387 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1388 See `skip-chars-forward' for details.
1389 Returns the distance traveled, either zero or negative. */)
1391 Lisp_Object string
, lim
;
1393 return skip_chars (0, string
, lim
, 1);
1396 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1397 doc
: /* Move point forward across chars in specified syntax classes.
1398 SYNTAX is a string of syntax code characters.
1399 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1400 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1401 This function returns the distance traveled, either zero or positive. */)
1403 Lisp_Object syntax
, lim
;
1405 return skip_syntaxes (1, syntax
, lim
);
1408 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1409 doc
: /* Move point backward across chars in specified syntax classes.
1410 SYNTAX is a string of syntax code characters.
1411 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1412 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1413 This function returns the distance traveled, either zero or negative. */)
1415 Lisp_Object syntax
, lim
;
1417 return skip_syntaxes (0, syntax
, lim
);
1421 skip_chars (forwardp
, string
, lim
, handle_iso_classes
)
1423 Lisp_Object string
, lim
;
1424 int handle_iso_classes
;
1426 register unsigned int c
;
1427 unsigned char fastmap
[0400];
1428 /* Store the ranges of non-ASCII characters. */
1430 int n_char_ranges
= 0;
1432 register int i
, i_byte
;
1433 /* Set to 1 if the current buffer is multibyte and the region
1434 contains non-ASCII chars. */
1436 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1438 int string_multibyte
;
1440 const unsigned char *str
;
1442 Lisp_Object iso_classes
;
1444 CHECK_STRING (string
);
1448 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1450 CHECK_NUMBER_COERCE_MARKER (lim
);
1452 /* In any case, don't allow scan outside bounds of buffer. */
1453 if (XINT (lim
) > ZV
)
1454 XSETFASTINT (lim
, ZV
);
1455 if (XINT (lim
) < BEGV
)
1456 XSETFASTINT (lim
, BEGV
);
1458 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1459 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1460 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1462 bzero (fastmap
, sizeof fastmap
);
1464 str
= SDATA (string
);
1465 size_byte
= SBYTES (string
);
1468 if (i_byte
< size_byte
1469 && SREF (string
, 0) == '^')
1471 negate
= 1; i_byte
++;
1474 /* Find the characters specified and set their elements of fastmap.
1475 Handle backslashes and ranges specially.
1477 If STRING contains non-ASCII characters, setup char_ranges for
1478 them and use fastmap only for their leading codes. */
1480 if (! string_multibyte
)
1482 int string_has_eight_bit
= 0;
1484 /* At first setup fastmap. */
1485 while (i_byte
< size_byte
)
1489 if (handle_iso_classes
&& c
== '['
1490 && i_byte
< size_byte
1491 && str
[i_byte
] == ':')
1493 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1494 const unsigned char *class_end
= class_beg
;
1495 const unsigned char *class_limit
= str
+ size_byte
- 2;
1496 /* Leave room for the null. */
1497 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1500 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1501 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1503 while (class_end
< class_limit
1504 && *class_end
>= 'a' && *class_end
<= 'z')
1507 if (class_end
== class_beg
1508 || *class_end
!= ':' || class_end
[1] != ']')
1509 goto not_a_class_name
;
1511 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1512 class_name
[class_end
- class_beg
] = 0;
1514 cc
= re_wctype (class_name
);
1516 error ("Invalid ISO C character class");
1518 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1520 i_byte
= class_end
+ 2 - str
;
1527 if (i_byte
== size_byte
)
1532 /* Treat `-' as range character only if another character
1534 if (i_byte
+ 1 < size_byte
1535 && str
[i_byte
] == '-')
1539 /* Skip over the dash. */
1542 /* Get the end of the range. */
1545 && i_byte
< size_byte
)
1552 if (! ASCII_CHAR_P (c2
))
1553 string_has_eight_bit
= 1;
1559 if (! ASCII_CHAR_P (c
))
1560 string_has_eight_bit
= 1;
1564 /* If the current range is multibyte and STRING contains
1565 eight-bit chars, arrange fastmap and setup char_ranges for
1566 the corresponding multibyte chars. */
1567 if (multibyte
&& string_has_eight_bit
)
1569 unsigned char fastmap2
[0400];
1570 int range_start_byte
, range_start_char
;
1572 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1573 bzero (fastmap
+ 0200, 0200);
1574 /* We are sure that this loop stops. */
1575 for (i
= 0200; ! fastmap2
[i
]; i
++);
1576 c
= unibyte_char_to_multibyte (i
);
1577 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1578 range_start_byte
= i
;
1579 range_start_char
= c
;
1580 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1581 for (i
= 129; i
< 0400; i
++)
1583 c
= unibyte_char_to_multibyte (i
);
1584 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1585 if (i
- range_start_byte
!= c
- range_start_char
)
1587 char_ranges
[n_char_ranges
++] = range_start_char
;
1588 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1589 + range_start_char
);
1590 range_start_byte
= i
;
1591 range_start_char
= c
;
1594 char_ranges
[n_char_ranges
++] = range_start_char
;
1595 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1596 + range_start_char
);
1599 else /* STRING is multibyte */
1601 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1603 while (i_byte
< size_byte
)
1605 unsigned char leading_code
;
1607 leading_code
= str
[i_byte
];
1608 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1611 if (handle_iso_classes
&& c
== '['
1612 && i_byte
< size_byte
1613 && STRING_CHAR (str
+ i_byte
, size_byte
- i_byte
) == ':')
1615 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1616 const unsigned char *class_end
= class_beg
;
1617 const unsigned char *class_limit
= str
+ size_byte
- 2;
1618 /* Leave room for the null. */
1619 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1622 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1623 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1625 while (class_end
< class_limit
1626 && *class_end
>= 'a' && *class_end
<= 'z')
1629 if (class_end
== class_beg
1630 || *class_end
!= ':' || class_end
[1] != ']')
1631 goto not_a_class_name_multibyte
;
1633 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1634 class_name
[class_end
- class_beg
] = 0;
1636 cc
= re_wctype (class_name
);
1638 error ("Invalid ISO C character class");
1640 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1642 i_byte
= class_end
+ 2 - str
;
1646 not_a_class_name_multibyte
:
1649 if (i_byte
== size_byte
)
1652 leading_code
= str
[i_byte
];
1653 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1654 size_byte
- i_byte
, len
);
1657 /* Treat `-' as range character only if another character
1659 if (i_byte
+ 1 < size_byte
1660 && str
[i_byte
] == '-')
1663 unsigned char leading_code2
;
1665 /* Skip over the dash. */
1668 /* Get the end of the range. */
1669 leading_code2
= str
[i_byte
];
1670 c2
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1671 size_byte
- i_byte
, len
);
1675 && i_byte
< size_byte
)
1677 leading_code2
= str
[i_byte
];
1678 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1684 if (ASCII_CHAR_P (c
))
1686 while (c
<= c2
&& c
< 0x80)
1688 leading_code
= CHAR_LEADING_CODE (c
);
1690 if (! ASCII_CHAR_P (c
))
1692 while (leading_code
<= leading_code2
)
1693 fastmap
[leading_code
++] = 1;
1696 char_ranges
[n_char_ranges
++] = c
;
1697 char_ranges
[n_char_ranges
++] = c2
;
1703 if (ASCII_CHAR_P (c
))
1707 fastmap
[leading_code
] = 1;
1708 char_ranges
[n_char_ranges
++] = c
;
1709 char_ranges
[n_char_ranges
++] = c
;
1714 /* If the current range is unibyte and STRING contains non-ASCII
1715 chars, arrange fastmap for the corresponding unibyte
1718 if (! multibyte
&& n_char_ranges
> 0)
1720 bzero (fastmap
+ 0200, 0200);
1721 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1723 int c1
= char_ranges
[i
];
1724 int c2
= char_ranges
[i
+ 1];
1726 for (; c1
<= c2
; c1
++)
1728 int b
= CHAR_TO_BYTE_SAFE (c1
);
1736 /* If ^ was the first character, complement the fastmap. */
1740 for (i
= 0; i
< sizeof fastmap
; i
++)
1744 for (i
= 0; i
< 0200; i
++)
1746 /* All non-ASCII chars possibly match. */
1747 for (; i
< sizeof fastmap
; i
++)
1753 int start_point
= PT
;
1755 int pos_byte
= PT_BYTE
;
1756 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1760 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1761 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1765 endp
= CHAR_POS_ADDR (XINT (lim
));
1766 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1784 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1785 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1795 if (! ASCII_CHAR_P (c
))
1797 /* As we are looking at a multibyte character, we
1798 must look up the character in the table
1799 CHAR_RANGES. If there's no data in the table,
1800 that character is not what we want to skip. */
1802 /* The following code do the right thing even if
1803 n_char_ranges is zero (i.e. no data in
1805 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1806 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1808 if (!(negate
^ (i
< n_char_ranges
)))
1812 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1825 if (!NILP (iso_classes
) && in_classes (*p
, iso_classes
))
1830 goto fwd_unibyte_ok
;
1836 p
++, pos
++, pos_byte
++;
1844 unsigned char *prev_p
;
1854 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1855 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1857 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1867 if (! ASCII_CHAR_P (c
))
1869 /* See the comment in the previous similar code. */
1870 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1871 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1873 if (!(negate
^ (i
< n_char_ranges
)))
1877 pos
--, pos_byte
-= prev_p
- p
;
1890 if (! NILP (iso_classes
) && in_classes (p
[-1], iso_classes
))
1895 goto back_unibyte_ok
;
1898 if (!fastmap
[p
[-1]])
1901 p
--, pos
--, pos_byte
--;
1905 SET_PT_BOTH (pos
, pos_byte
);
1908 return make_number (PT
- start_point
);
1914 skip_syntaxes (forwardp
, string
, lim
)
1916 Lisp_Object string
, lim
;
1918 register unsigned int c
;
1919 unsigned char fastmap
[0400];
1921 register int i
, i_byte
;
1926 CHECK_STRING (string
);
1929 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1931 CHECK_NUMBER_COERCE_MARKER (lim
);
1933 /* In any case, don't allow scan outside bounds of buffer. */
1934 if (XINT (lim
) > ZV
)
1935 XSETFASTINT (lim
, ZV
);
1936 if (XINT (lim
) < BEGV
)
1937 XSETFASTINT (lim
, BEGV
);
1939 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1940 return make_number (0);
1942 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1943 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1945 bzero (fastmap
, sizeof fastmap
);
1947 if (SBYTES (string
) > SCHARS (string
))
1948 /* As this is very rare case (syntax spec is ASCII only), don't
1949 consider efficiency. */
1950 string
= string_make_unibyte (string
);
1952 str
= SDATA (string
);
1953 size_byte
= SBYTES (string
);
1956 if (i_byte
< size_byte
1957 && SREF (string
, 0) == '^')
1959 negate
= 1; i_byte
++;
1962 /* Find the syntaxes specified and set their elements of fastmap. */
1964 while (i_byte
< size_byte
)
1967 fastmap
[syntax_spec_code
[c
]] = 1;
1970 /* If ^ was the first character, complement the fastmap. */
1972 for (i
= 0; i
< sizeof fastmap
; i
++)
1976 int start_point
= PT
;
1978 int pos_byte
= PT_BYTE
;
1979 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1983 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1984 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1988 endp
= CHAR_POS_ADDR (XINT (lim
));
1989 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1993 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
2009 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
2010 if (! fastmap
[(int) SYNTAX (c
)])
2012 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
2013 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2027 if (! fastmap
[(int) SYNTAX (*p
)])
2029 p
++, pos
++, pos_byte
++;
2030 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2040 unsigned char *prev_p
;
2049 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2051 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
2052 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
2053 if (! fastmap
[(int) SYNTAX (c
)])
2055 pos
--, pos_byte
-= prev_p
- p
;
2069 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2070 if (! fastmap
[(int) SYNTAX (p
[-1])])
2072 p
--, pos
--, pos_byte
--;
2077 SET_PT_BOTH (pos
, pos_byte
);
2080 return make_number (PT
- start_point
);
2084 /* Return 1 if character C belongs to one of the ISO classes
2085 in the list ISO_CLASSES. Each class is represented by an
2086 integer which is its type according to re_wctype. */
2089 in_classes (c
, iso_classes
)
2091 Lisp_Object iso_classes
;
2095 while (! NILP (iso_classes
))
2098 elt
= XCAR (iso_classes
);
2099 iso_classes
= XCDR (iso_classes
);
2101 if (re_iswctype (c
, XFASTINT (elt
)))
2108 /* Jump over a comment, assuming we are at the beginning of one.
2109 FROM is the current position.
2110 FROM_BYTE is the bytepos corresponding to FROM.
2111 Do not move past STOP (a charpos).
2112 The comment over which we have to jump is of style STYLE
2113 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2114 NESTING should be positive to indicate the nesting at the beginning
2115 for nested comments and should be zero or negative else.
2116 ST_COMMENT_STYLE cannot be nested.
2117 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
2118 (or 0 If the search cannot start in the middle of a two-character).
2120 If successful, return 1 and store the charpos of the comment's end
2121 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
2122 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
2123 corresponding bytepos into *BYTEPOS_PTR and the current nesting
2124 (as defined for state.incomment) in *INCOMMENT_PTR.
2126 The comment end is the last character of the comment rather than the
2127 character just after the comment.
2129 Global syntax data is assumed to initially be valid for FROM and
2130 remains valid for forward search starting at the returned position. */
2133 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
2134 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
2135 EMACS_INT from
, from_byte
, stop
;
2136 int nesting
, style
, prev_syntax
;
2137 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
2141 register enum syntaxcode code
;
2142 register int syntax
;
2144 if (nesting
<= 0) nesting
= -1;
2146 /* Enter the loop in the middle so that we find
2147 a 2-char comment ender if we start in the middle of it. */
2148 syntax
= prev_syntax
;
2149 if (syntax
!= 0) goto forw_incomment
;
2155 *incomment_ptr
= nesting
;
2156 *charpos_ptr
= from
;
2157 *bytepos_ptr
= from_byte
;
2160 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2161 syntax
= SYNTAX_WITH_FLAGS (c
);
2162 code
= syntax
& 0xff;
2163 if (code
== Sendcomment
2164 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2165 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
2166 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
2167 /* we have encountered a comment end of the same style
2168 as the comment sequence which began this comment
2171 if (code
== Scomment_fence
2172 && style
== ST_COMMENT_STYLE
)
2173 /* we have encountered a comment end of the same style
2174 as the comment sequence which began this comment
2179 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
2180 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
2181 /* we have encountered a nested comment of the same style
2182 as the comment sequence which began this comment section */
2184 INC_BOTH (from
, from_byte
);
2185 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2188 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2189 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2190 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2191 SYNTAX_COMEND_SECOND (c1
))
2192 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2193 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2196 /* we have encountered a comment end of the same style
2197 as the comment sequence which began this comment
2202 INC_BOTH (from
, from_byte
);
2203 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2208 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2209 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2210 SYNTAX_COMMENT_STYLE (c1
) == style
2211 && SYNTAX_COMSTART_SECOND (c1
))
2212 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2213 SYNTAX_COMMENT_NESTED (c1
)))
2214 /* we have encountered a nested comment of the same style
2215 as the comment sequence which began this comment
2218 INC_BOTH (from
, from_byte
);
2219 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2223 *charpos_ptr
= from
;
2224 *bytepos_ptr
= from_byte
;
2228 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2230 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2231 Stop scanning if we find something other than a comment or whitespace.
2232 Set point to where scanning stops.
2233 If COUNT comments are found as expected, with nothing except whitespace
2234 between them, return t; otherwise return nil. */)
2238 register EMACS_INT from
;
2239 EMACS_INT from_byte
;
2240 register EMACS_INT stop
;
2242 register enum syntaxcode code
;
2243 int comstyle
= 0; /* style of comment encountered */
2244 int comnested
= 0; /* whether the comment is nestable or not */
2247 EMACS_INT out_charpos
, out_bytepos
;
2250 CHECK_NUMBER (count
);
2251 count1
= XINT (count
);
2252 stop
= count1
> 0 ? ZV
: BEGV
;
2258 from_byte
= PT_BYTE
;
2260 SETUP_SYNTAX_TABLE (from
, count1
);
2269 SET_PT_BOTH (from
, from_byte
);
2273 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2275 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2276 comnested
= SYNTAX_COMMENT_NESTED (c
);
2277 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2278 INC_BOTH (from
, from_byte
);
2279 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2280 if (from
< stop
&& comstart_first
2281 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2282 SYNTAX_COMSTART_SECOND (c1
)))
2284 /* We have encountered a comment start sequence and we
2285 are ignoring all text inside comments. We must record
2286 the comment style this sequence begins so that later,
2287 only a comment end of the same style actually ends
2288 the comment section. */
2290 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2291 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2292 INC_BOTH (from
, from_byte
);
2293 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2296 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2298 if (code
== Scomment_fence
)
2299 comstyle
= ST_COMMENT_STYLE
;
2300 else if (code
!= Scomment
)
2303 DEC_BOTH (from
, from_byte
);
2304 SET_PT_BOTH (from
, from_byte
);
2307 /* We're at the start of a comment. */
2308 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2309 &out_charpos
, &out_bytepos
, &dummy
);
2310 from
= out_charpos
; from_byte
= out_bytepos
;
2314 SET_PT_BOTH (from
, from_byte
);
2317 INC_BOTH (from
, from_byte
);
2318 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2319 /* We have skipped one comment. */
2331 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2336 DEC_BOTH (from
, from_byte
);
2337 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2338 quoted
= char_quoted (from
, from_byte
);
2339 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2342 comnested
= SYNTAX_COMMENT_NESTED (c
);
2343 if (code
== Sendcomment
)
2344 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2345 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2346 && prev_char_comend_first (from
, from_byte
)
2347 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2349 /* We must record the comment style encountered so that
2350 later, we can match only the proper comment begin
2351 sequence of the same style. */
2352 DEC_BOTH (from
, from_byte
);
2354 /* Calling char_quoted, above, set up global syntax position
2355 at the new value of FROM. */
2356 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2357 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2358 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2361 if (code
== Scomment_fence
)
2363 /* Skip until first preceding unquoted comment_fence. */
2364 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2368 DEC_BOTH (from
, from_byte
);
2369 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2370 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2371 if (SYNTAX (c
) == Scomment_fence
2372 && !char_quoted (from
, from_byte
))
2377 else if (from
== stop
)
2382 from
= ini
; /* Set point to ini + 1. */
2383 from_byte
= ini_byte
;
2387 /* We have skipped one comment. */
2390 else if (code
== Sendcomment
)
2392 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2393 &out_charpos
, &out_bytepos
);
2397 /* This end-of-line is not an end-of-comment.
2398 Treat it like a whitespace.
2399 CC-mode (and maybe others) relies on this behavior. */
2403 /* Failure: we should go back to the end of this
2404 not-quite-endcomment. */
2405 if (SYNTAX(c
) != code
)
2406 /* It was a two-char Sendcomment. */
2407 INC_BOTH (from
, from_byte
);
2413 /* We have skipped one comment. */
2414 from
= out_charpos
, from_byte
= out_bytepos
;
2418 else if (code
!= Swhitespace
|| quoted
)
2422 INC_BOTH (from
, from_byte
);
2423 SET_PT_BOTH (from
, from_byte
);
2431 SET_PT_BOTH (from
, from_byte
);
2436 /* Return syntax code of character C if C is an ASCII character
2437 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2439 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2440 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2441 ? SYNTAX (c) : Ssymbol)
2444 scan_lists (from
, count
, depth
, sexpflag
)
2445 register EMACS_INT from
;
2446 EMACS_INT count
, depth
;
2450 register EMACS_INT stop
= count
> 0 ? ZV
: BEGV
;
2455 register enum syntaxcode code
, temp_code
;
2456 int min_depth
= depth
; /* Err out if depth gets less than this. */
2457 int comstyle
= 0; /* style of comment encountered */
2458 int comnested
= 0; /* whether the comment is nestable or not */
2460 EMACS_INT last_good
= from
;
2462 EMACS_INT from_byte
;
2463 EMACS_INT out_bytepos
, out_charpos
;
2465 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2467 if (depth
> 0) min_depth
= 0;
2469 if (from
> ZV
) from
= ZV
;
2470 if (from
< BEGV
) from
= BEGV
;
2472 from_byte
= CHAR_TO_BYTE (from
);
2477 SETUP_SYNTAX_TABLE (from
, count
);
2482 int comstart_first
, prefix
;
2483 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2484 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2485 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2486 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2487 comnested
= SYNTAX_COMMENT_NESTED (c
);
2488 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2489 prefix
= SYNTAX_PREFIX (c
);
2490 if (depth
== min_depth
)
2492 INC_BOTH (from
, from_byte
);
2493 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2494 if (from
< stop
&& comstart_first
2495 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2496 SYNTAX_COMSTART_SECOND (c
))
2497 && parse_sexp_ignore_comments
)
2499 /* we have encountered a comment start sequence and we
2500 are ignoring all text inside comments. We must record
2501 the comment style this sequence begins so that later,
2502 only a comment end of the same style actually ends
2503 the comment section */
2505 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2506 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2507 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2508 INC_BOTH (from
, from_byte
);
2509 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2515 switch (SWITCH_ENUM_CAST (code
))
2521 INC_BOTH (from
, from_byte
);
2522 /* treat following character as a word constituent */
2525 if (depth
|| !sexpflag
) break;
2526 /* This word counts as a sexp; return at end of it. */
2529 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2531 /* Some compilers can't handle this inside the switch. */
2532 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2533 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2538 INC_BOTH (from
, from_byte
);
2549 INC_BOTH (from
, from_byte
);
2553 case Scomment_fence
:
2554 comstyle
= ST_COMMENT_STYLE
;
2557 if (!parse_sexp_ignore_comments
) break;
2558 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2559 found
= forw_comment (from
, from_byte
, stop
,
2560 comnested
, comstyle
, 0,
2561 &out_charpos
, &out_bytepos
, &dummy
);
2562 from
= out_charpos
, from_byte
= out_bytepos
;
2569 INC_BOTH (from
, from_byte
);
2570 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2576 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2578 INC_BOTH (from
, from_byte
);
2588 if (!++depth
) goto done
;
2593 if (!--depth
) goto done
;
2594 if (depth
< min_depth
)
2595 xsignal3 (Qscan_error
,
2596 build_string ("Containing expression ends prematurely"),
2597 make_number (last_good
), make_number (from
));
2602 temp_pos
= dec_bytepos (from_byte
);
2603 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2608 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2609 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2612 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2613 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2616 /* Some compilers can't handle this inside the switch. */
2617 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2622 INC_BOTH (from
, from_byte
);
2624 INC_BOTH (from
, from_byte
);
2626 INC_BOTH (from
, from_byte
);
2627 if (!depth
&& sexpflag
) goto done
;
2630 /* Ignore whitespace, punctuation, quote, endcomment. */
2635 /* Reached end of buffer. Error if within object, return nil if between */
2642 /* End of object reached */
2651 DEC_BOTH (from
, from_byte
);
2652 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2653 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2654 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2655 if (depth
== min_depth
)
2658 comnested
= SYNTAX_COMMENT_NESTED (c
);
2659 if (code
== Sendcomment
)
2660 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2661 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2662 && prev_char_comend_first (from
, from_byte
)
2663 && parse_sexp_ignore_comments
)
2665 /* We must record the comment style encountered so that
2666 later, we can match only the proper comment begin
2667 sequence of the same style. */
2668 DEC_BOTH (from
, from_byte
);
2669 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2671 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2672 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2673 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2676 /* Quoting turns anything except a comment-ender
2677 into a word character. Note that this cannot be true
2678 if we decremented FROM in the if-statement above. */
2679 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2681 DEC_BOTH (from
, from_byte
);
2684 else if (SYNTAX_PREFIX (c
))
2687 switch (SWITCH_ENUM_CAST (code
))
2693 if (depth
|| !sexpflag
) break;
2694 /* This word counts as a sexp; count object finished
2695 after passing it. */
2698 temp_pos
= from_byte
;
2699 if (! NILP (current_buffer
->enable_multibyte_characters
))
2703 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2704 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2705 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2706 /* Don't allow comment-end to be quoted. */
2707 if (temp_code
== Sendcomment
)
2709 quoted
= char_quoted (from
- 1, temp_pos
);
2712 DEC_BOTH (from
, from_byte
);
2713 temp_pos
= dec_bytepos (temp_pos
);
2714 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2716 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2717 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2718 if (! (quoted
|| temp_code
== Sword
2719 || temp_code
== Ssymbol
2720 || temp_code
== Squote
))
2722 DEC_BOTH (from
, from_byte
);
2729 temp_pos
= dec_bytepos (from_byte
);
2730 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2731 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2732 DEC_BOTH (from
, from_byte
);
2741 if (!++depth
) goto done2
;
2746 if (!--depth
) goto done2
;
2747 if (depth
< min_depth
)
2748 xsignal3 (Qscan_error
,
2749 build_string ("Containing expression ends prematurely"),
2750 make_number (last_good
), make_number (from
));
2754 if (!parse_sexp_ignore_comments
)
2756 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2757 &out_charpos
, &out_bytepos
);
2758 /* FIXME: if found == -1, then it really wasn't a comment-end.
2759 For single-char Sendcomment, we can't do much about it apart
2760 from skipping the char.
2761 For 2-char endcomments, we could try again, taking both
2762 chars as separate entities, but it's a lot of trouble
2763 for very little gain, so we don't bother either. -sm */
2765 from
= out_charpos
, from_byte
= out_bytepos
;
2768 case Scomment_fence
:
2774 DEC_BOTH (from
, from_byte
);
2775 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2776 if (!char_quoted (from
, from_byte
)
2777 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2778 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2781 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2785 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2790 DEC_BOTH (from
, from_byte
);
2791 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2792 if (!char_quoted (from
, from_byte
)
2794 == (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
)))
2795 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2798 if (!depth
&& sexpflag
) goto done2
;
2801 /* Ignore whitespace, punctuation, quote, endcomment. */
2806 /* Reached start of buffer. Error if within object, return nil if between */
2819 XSETFASTINT (val
, from
);
2823 xsignal3 (Qscan_error
,
2824 build_string ("Unbalanced parentheses"),
2825 make_number (last_good
), make_number (from
));
2828 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2829 doc
: /* Scan from character number FROM by COUNT lists.
2830 Returns the character number of the position thus found.
2832 If DEPTH is nonzero, paren depth begins counting from that value,
2833 only places where the depth in parentheses becomes zero
2834 are candidates for stopping; COUNT such places are counted.
2835 Thus, a positive value for DEPTH means go out levels.
2837 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2839 If the beginning or end of (the accessible part of) the buffer is reached
2840 and the depth is wrong, an error is signaled.
2841 If the depth is right but the count is not used up, nil is returned. */)
2842 (from
, count
, depth
)
2843 Lisp_Object from
, count
, depth
;
2845 CHECK_NUMBER (from
);
2846 CHECK_NUMBER (count
);
2847 CHECK_NUMBER (depth
);
2849 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2852 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2853 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2854 If COUNT is negative, scan backwards.
2855 Returns the character number of the position thus found.
2857 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2859 If the beginning or end of (the accessible part of) the buffer is reached
2860 in the middle of a parenthetical grouping, an error is signaled.
2861 If the beginning or end is reached between groupings
2862 but before count is used up, nil is returned. */)
2864 Lisp_Object from
, count
;
2866 CHECK_NUMBER (from
);
2867 CHECK_NUMBER (count
);
2869 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2872 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2874 doc
: /* Move point backward over any number of chars with prefix syntax.
2875 This includes chars with "quote" or "prefix" syntax (' or p). */)
2880 int opoint_byte
= PT_BYTE
;
2882 int pos_byte
= PT_BYTE
;
2887 SET_PT_BOTH (opoint
, opoint_byte
);
2892 SETUP_SYNTAX_TABLE (pos
, -1);
2894 DEC_BOTH (pos
, pos_byte
);
2896 while (!char_quoted (pos
, pos_byte
)
2897 /* Previous statement updates syntax table. */
2898 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2899 || SYNTAX_PREFIX (c
)))
2902 opoint_byte
= pos_byte
;
2905 DEC_BOTH (pos
, pos_byte
);
2908 SET_PT_BOTH (opoint
, opoint_byte
);
2913 /* Parse forward from FROM / FROM_BYTE to END,
2914 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2915 and return a description of the state of the parse at END.
2916 If STOPBEFORE is nonzero, stop at the start of an atom.
2917 If COMMENTSTOP is 1, stop at the start of a comment.
2918 If COMMENTSTOP is -1, stop at the start or end of a comment,
2919 after the beginning of a string, or after the end of a string. */
2922 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2923 stopbefore
, oldstate
, commentstop
)
2924 struct lisp_parse_state
*stateptr
;
2927 int end
, targetdepth
, stopbefore
;
2928 Lisp_Object oldstate
;
2931 struct lisp_parse_state state
;
2933 register enum syntaxcode code
;
2936 struct level
{ int last
, prev
; };
2937 struct level levelstart
[100];
2938 register struct level
*curlevel
= levelstart
;
2939 struct level
*endlevel
= levelstart
+ 100;
2940 register int depth
; /* Paren depth of current scanning location.
2941 level - levelstart equals this except
2942 when the depth becomes negative. */
2943 int mindepth
; /* Lowest DEPTH value seen. */
2944 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2946 int prev_from
; /* Keep one character before FROM. */
2948 int prev_from_syntax
;
2949 int boundary_stop
= commentstop
== -1;
2952 EMACS_INT out_bytepos
, out_charpos
;
2956 prev_from_byte
= from_byte
;
2958 DEC_BOTH (prev_from
, prev_from_byte
);
2960 /* Use this macro instead of `from++'. */
2962 do { prev_from = from; \
2963 prev_from_byte = from_byte; \
2964 temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
2965 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
2966 INC_BOTH (from, from_byte); \
2968 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2974 if (NILP (oldstate
))
2977 state
.instring
= -1;
2978 state
.incomment
= 0;
2979 state
.comstyle
= 0; /* comment style a by default. */
2980 state
.comstr_start
= -1; /* no comment/string seen. */
2984 tem
= Fcar (oldstate
);
2990 oldstate
= Fcdr (oldstate
);
2991 oldstate
= Fcdr (oldstate
);
2992 oldstate
= Fcdr (oldstate
);
2993 tem
= Fcar (oldstate
);
2994 /* Check whether we are inside string_fence-style string: */
2995 state
.instring
= (!NILP (tem
)
2996 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2999 oldstate
= Fcdr (oldstate
);
3000 tem
= Fcar (oldstate
);
3001 state
.incomment
= (!NILP (tem
)
3002 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
3005 oldstate
= Fcdr (oldstate
);
3006 tem
= Fcar (oldstate
);
3007 start_quoted
= !NILP (tem
);
3009 /* if the eighth element of the list is nil, we are in comment
3010 style a. If it is non-nil, we are in comment style b */
3011 oldstate
= Fcdr (oldstate
);
3012 oldstate
= Fcdr (oldstate
);
3013 tem
= Fcar (oldstate
);
3014 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
3015 ? ST_COMMENT_STYLE
: 1);
3017 oldstate
= Fcdr (oldstate
);
3018 tem
= Fcar (oldstate
);
3019 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
3020 oldstate
= Fcdr (oldstate
);
3021 tem
= Fcar (oldstate
);
3022 while (!NILP (tem
)) /* >= second enclosing sexps. */
3024 /* curlevel++->last ran into compiler bug on Apollo */
3025 curlevel
->last
= XINT (Fcar (tem
));
3026 if (++curlevel
== endlevel
)
3027 curlevel
--; /* error ("Nesting too deep for parser"); */
3028 curlevel
->prev
= -1;
3029 curlevel
->last
= -1;
3036 curlevel
->prev
= -1;
3037 curlevel
->last
= -1;
3039 SETUP_SYNTAX_TABLE (prev_from
, 1);
3040 temp
= FETCH_CHAR (prev_from_byte
);
3041 prev_from_syntax
= SYNTAX_WITH_FLAGS (temp
);
3042 UPDATE_SYNTAX_TABLE_FORWARD (from
);
3044 /* Enter the loop at a place appropriate for initial state. */
3046 if (state
.incomment
)
3047 goto startincomment
;
3048 if (state
.instring
>= 0)
3050 nofence
= state
.instring
!= ST_STRING_STYLE
;
3052 goto startquotedinstring
;
3055 else if (start_quoted
)
3061 code
= prev_from_syntax
& 0xff;
3064 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
)
3065 && (c1
= FETCH_CHAR (from_byte
),
3066 SYNTAX_COMSTART_SECOND (c1
)))
3067 /* Duplicate code to avoid a complex if-expression
3068 which causes trouble for the SGI compiler. */
3070 /* Record the comment style we have entered so that only
3071 the comment-end sequence of the same style actually
3072 terminates the comment section. */
3073 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
3074 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
3075 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
3076 state
.incomment
= comnested
? 1 : -1;
3077 state
.comstr_start
= prev_from
;
3081 else if (code
== Scomment_fence
)
3083 /* Record the comment style we have entered so that only
3084 the comment-end sequence of the same style actually
3085 terminates the comment section. */
3086 state
.comstyle
= ST_COMMENT_STYLE
;
3087 state
.incomment
= -1;
3088 state
.comstr_start
= prev_from
;
3091 else if (code
== Scomment
)
3093 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
3094 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
3096 state
.comstr_start
= prev_from
;
3099 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
3101 switch (SWITCH_ENUM_CAST (code
))
3105 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3106 curlevel
->last
= prev_from
;
3108 if (from
== end
) goto endquoted
;
3111 /* treat following character as a word constituent */
3114 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3115 curlevel
->last
= prev_from
;
3119 /* Some compilers can't handle this inside the switch. */
3120 temp
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3121 temp
= SYNTAX (temp
);
3127 if (from
== end
) goto endquoted
;
3139 curlevel
->prev
= curlevel
->last
;
3142 case Scomment_fence
: /* Can't happen because it's handled above. */
3144 if (commentstop
|| boundary_stop
) goto done
;
3146 /* The (from == BEGV) test was to enter the loop in the middle so
3147 that we find a 2-char comment ender even if we start in the
3148 middle of it. We don't want to do that if we're just at the
3149 beginning of the comment (think of (*) ... (*)). */
3150 found
= forw_comment (from
, from_byte
, end
,
3151 state
.incomment
, state
.comstyle
,
3152 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
3153 ? 0 : prev_from_syntax
,
3154 &out_charpos
, &out_bytepos
, &state
.incomment
);
3155 from
= out_charpos
; from_byte
= out_bytepos
;
3156 /* Beware! prev_from and friends are invalid now.
3157 Luckily, the `done' doesn't use them and the INC_FROM
3158 sets them to a sane value without looking at them. */
3159 if (!found
) goto done
;
3161 state
.incomment
= 0;
3162 state
.comstyle
= 0; /* reset the comment style */
3163 if (boundary_stop
) goto done
;
3167 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3169 /* curlevel++->last ran into compiler bug on Apollo */
3170 curlevel
->last
= prev_from
;
3171 if (++curlevel
== endlevel
)
3172 curlevel
--; /* error ("Nesting too deep for parser"); */
3173 curlevel
->prev
= -1;
3174 curlevel
->last
= -1;
3175 if (targetdepth
== depth
) goto done
;
3180 if (depth
< mindepth
)
3182 if (curlevel
!= levelstart
)
3184 curlevel
->prev
= curlevel
->last
;
3185 if (targetdepth
== depth
) goto done
;
3190 state
.comstr_start
= from
- 1;
3191 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3192 curlevel
->last
= prev_from
;
3193 state
.instring
= (code
== Sstring
3194 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3196 if (boundary_stop
) goto done
;
3199 nofence
= state
.instring
!= ST_STRING_STYLE
;
3205 if (from
>= end
) goto done
;
3206 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3207 /* Some compilers can't handle this inside the switch. */
3210 /* Check TEMP here so that if the char has
3211 a syntax-table property which says it is NOT
3212 a string character, it does not end the string. */
3213 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3219 if (!nofence
) goto string_end
;
3224 startquotedinstring
:
3225 if (from
>= end
) goto endquoted
;
3231 state
.instring
= -1;
3232 curlevel
->prev
= curlevel
->last
;
3234 if (boundary_stop
) goto done
;
3238 /* FIXME: We should do something with it. */
3241 /* Ignore whitespace, punctuation, quote, endcomment. */
3247 stop
: /* Here if stopping before start of sexp. */
3248 from
= prev_from
; /* We have just fetched the char that starts it; */
3249 goto done
; /* but return the position before it. */
3254 state
.depth
= depth
;
3255 state
.mindepth
= mindepth
;
3256 state
.thislevelstart
= curlevel
->prev
;
3257 state
.prevlevelstart
3258 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3259 state
.location
= from
;
3260 state
.levelstarts
= Qnil
;
3261 while (--curlevel
>= levelstart
)
3262 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3269 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3270 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3271 Parsing stops at TO or when certain criteria are met;
3272 point is set to where parsing stops.
3273 If fifth arg OLDSTATE is omitted or nil,
3274 parsing assumes that FROM is the beginning of a function.
3275 Value is a list of elements describing final state of parsing:
3277 1. character address of start of innermost containing list; nil if none.
3278 2. character address of start of last complete sexp terminated.
3279 3. non-nil if inside a string.
3280 (it is the character that will terminate the string,
3281 or t if the string should be terminated by a generic string delimiter.)
3282 4. nil if outside a comment, t if inside a non-nestable comment,
3283 else an integer (the current comment nesting).
3284 5. t if following a quote character.
3285 6. the minimum paren-depth encountered during this scan.
3286 7. t if in a comment of style b; symbol `syntax-table' if the comment
3287 should be terminated by a generic comment delimiter.
3288 8. character address of start of comment or string; nil if not in one.
3289 9. Intermediate data for continuation of parsing (subject to change).
3290 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3291 in parentheses becomes equal to TARGETDEPTH.
3292 Fourth arg STOPBEFORE non-nil means stop when come to
3293 any character that starts a sexp.
3294 Fifth arg OLDSTATE is a list like what this function returns.
3295 It is used to initialize the state of the parse. Elements number 1, 2, 6
3297 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3298 If it is symbol `syntax-table', stop after the start of a comment or a
3299 string, or after end of a comment or a string. */)
3300 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3301 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3303 struct lisp_parse_state state
;
3306 if (!NILP (targetdepth
))
3308 CHECK_NUMBER (targetdepth
);
3309 target
= XINT (targetdepth
);
3312 target
= -100000; /* We won't reach this depth */
3314 validate_region (&from
, &to
);
3315 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3317 target
, !NILP (stopbefore
), oldstate
,
3319 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3321 SET_PT (state
.location
);
3323 return Fcons (make_number (state
.depth
),
3324 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3325 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3326 Fcons (state
.instring
>= 0
3327 ? (state
.instring
== ST_STRING_STYLE
3328 ? Qt
: make_number (state
.instring
)) : Qnil
,
3329 Fcons (state
.incomment
< 0 ? Qt
:
3330 (state
.incomment
== 0 ? Qnil
:
3331 make_number (state
.incomment
)),
3332 Fcons (state
.quoted
? Qt
: Qnil
,
3333 Fcons (make_number (state
.mindepth
),
3334 Fcons ((state
.comstyle
3335 ? (state
.comstyle
== ST_COMMENT_STYLE
3336 ? Qsyntax_table
: Qt
) :
3338 Fcons (((state
.incomment
3339 || (state
.instring
>= 0))
3340 ? make_number (state
.comstr_start
)
3342 Fcons (state
.levelstarts
, Qnil
))))))))));
3351 /* This has to be done here, before we call Fmake_char_table. */
3352 Qsyntax_table
= intern ("syntax-table");
3353 staticpro (&Qsyntax_table
);
3355 /* Intern this now in case it isn't already done.
3356 Setting this variable twice is harmless.
3357 But don't staticpro it here--that is done in alloc.c. */
3358 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3360 /* Create objects which can be shared among syntax tables. */
3361 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3362 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3363 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3364 = Fcons (make_number (i
), Qnil
);
3366 /* Now we are ready to set up this property, so we can
3367 create syntax tables. */
3368 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3370 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3372 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3374 /* Control characters should not be whitespace. */
3375 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3376 for (i
= 0; i
<= ' ' - 1; i
++)
3377 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3378 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 0177, temp
);
3380 /* Except that a few really are whitespace. */
3381 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3382 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ' ', temp
);
3383 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\t', temp
);
3384 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\n', temp
);
3385 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 015, temp
);
3386 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 014, temp
);
3388 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3389 for (i
= 'a'; i
<= 'z'; i
++)
3390 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3391 for (i
= 'A'; i
<= 'Z'; i
++)
3392 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3393 for (i
= '0'; i
<= '9'; i
++)
3394 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3396 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3397 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3399 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3400 Fcons (make_number (Sopen
), make_number (')')));
3401 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3402 Fcons (make_number (Sclose
), make_number ('(')));
3403 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3404 Fcons (make_number (Sopen
), make_number (']')));
3405 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3406 Fcons (make_number (Sclose
), make_number ('[')));
3407 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3408 Fcons (make_number (Sopen
), make_number ('}')));
3409 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3410 Fcons (make_number (Sclose
), make_number ('{')));
3411 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3412 Fcons (make_number ((int) Sstring
), Qnil
));
3413 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3414 Fcons (make_number ((int) Sescape
), Qnil
));
3416 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3417 for (i
= 0; i
< 10; i
++)
3419 c
= "_-+*/&|<>="[i
];
3420 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3423 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3424 for (i
= 0; i
< 12; i
++)
3426 c
= ".,;:?!#@~^'`"[i
];
3427 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3430 /* All multibyte characters have syntax `word' by default. */
3431 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3432 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3438 Qsyntax_table_p
= intern ("syntax-table-p");
3439 staticpro (&Qsyntax_table_p
);
3441 staticpro (&Vsyntax_code_object
);
3443 staticpro (&gl_state
.object
);
3444 staticpro (&gl_state
.global_code
);
3445 staticpro (&gl_state
.current_syntax_table
);
3446 staticpro (&gl_state
.old_prop
);
3448 /* Defined in regex.c */
3449 staticpro (&re_match_object
);
3451 Qscan_error
= intern ("scan-error");
3452 staticpro (&Qscan_error
);
3453 Fput (Qscan_error
, Qerror_conditions
,
3454 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3455 Fput (Qscan_error
, Qerror_message
,
3456 build_string ("Scan error"));
3458 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3459 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3461 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3462 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3463 Otherwise, that text property is simply ignored.
3464 See the info node `(elisp)Syntax Properties' for a description of the
3465 `syntax-table' property. */);
3467 words_include_escapes
= 0;
3468 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3469 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3471 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3472 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3473 multibyte_syntax_as_symbol
= 0;
3475 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3476 &open_paren_in_column_0_is_defun_start
,
3477 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3478 open_paren_in_column_0_is_defun_start
= 1;
3481 DEFVAR_LISP ("find-word-boundary-function-table",
3482 &Vfind_word_boundary_function_table
,
3484 Char table of functions to search for the word boundary.
3485 Each function is called with two arguments; POS and LIMIT.
3486 POS and LIMIT are character positions in the current buffer.
3488 If POS is less than LIMIT, POS is at the first character of a word,
3489 and the return value of a function is a position after the last
3490 character of that word.
3492 If POS is not less than LIMIT, POS is at the last character of a word,
3493 and the return value of a function is a position at the first
3494 character of that word.
3496 In both cases, LIMIT bounds the search. */);
3497 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3499 defsubr (&Ssyntax_table_p
);
3500 defsubr (&Ssyntax_table
);
3501 defsubr (&Sstandard_syntax_table
);
3502 defsubr (&Scopy_syntax_table
);
3503 defsubr (&Sset_syntax_table
);
3504 defsubr (&Schar_syntax
);
3505 defsubr (&Smatching_paren
);
3506 defsubr (&Sstring_to_syntax
);
3507 defsubr (&Smodify_syntax_entry
);
3508 defsubr (&Sinternal_describe_syntax_value
);
3510 defsubr (&Sforward_word
);
3512 defsubr (&Sskip_chars_forward
);
3513 defsubr (&Sskip_chars_backward
);
3514 defsubr (&Sskip_syntax_forward
);
3515 defsubr (&Sskip_syntax_backward
);
3517 defsubr (&Sforward_comment
);
3518 defsubr (&Sscan_lists
);
3519 defsubr (&Sscan_sexps
);
3520 defsubr (&Sbackward_prefix_chars
);
3521 defsubr (&Sparse_partial_sexp
);
3524 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
3525 (do not change this comment) */