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
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/>. */
27 #include "character.h"
31 /* Make syntax table lookup grant data in gl_state. */
32 #define SYNTAX_ENTRY_VIA_PROPERTY
35 #include "intervals.h"
37 /* We use these constants in place for comment-style and
38 string-ender-char to distinguish comments/strings started by
39 comment_fence and string_fence codes. */
41 #define ST_COMMENT_STYLE (256 + 1)
42 #define ST_STRING_STYLE (256 + 2)
45 Lisp_Object Qsyntax_table_p
, Qsyntax_table
, Qscan_error
;
47 int words_include_escapes
;
48 int parse_sexp_lookup_properties
;
50 /* Nonzero means `scan-sexps' treat all multibyte characters as symbol. */
51 int multibyte_syntax_as_symbol
;
53 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
54 if not compiled with GCC. No need to mark it, since it is used
55 only very temporarily. */
56 Lisp_Object syntax_temp
;
58 /* Non-zero means an open parenthesis in column 0 is always considered
59 to be the start of a defun. Zero means an open parenthesis in
60 column 0 has no special meaning. */
62 int open_paren_in_column_0_is_defun_start
;
64 /* This is the internal form of the parse state used in parse-partial-sexp. */
66 struct lisp_parse_state
68 int depth
; /* Depth at end of parsing. */
69 int instring
; /* -1 if not within string, else desired terminator. */
70 int incomment
; /* -1 if in unnestable comment else comment nesting */
71 int comstyle
; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
72 int quoted
; /* Nonzero if just after an escape char at end of parsing */
73 int thislevelstart
; /* Char number of most recent start-of-expression at current level */
74 int prevlevelstart
; /* Char number of start of containing expression */
75 int location
; /* Char number at which parsing stopped. */
76 int mindepth
; /* Minimum depth seen while scanning. */
77 int comstr_start
; /* Position just after last comment/string starter. */
78 Lisp_Object levelstarts
; /* Char numbers of starts-of-expression
79 of levels (starting from outermost). */
82 /* These variables are a cache for finding the start of a defun.
83 find_start_pos is the place for which the defun start was found.
84 find_start_value is the defun start position found for it.
85 find_start_value_byte is the corresponding byte position.
86 find_start_buffer is the buffer it was found in.
87 find_start_begv is the BEGV value when it was found.
88 find_start_modiff is the value of MODIFF when it was found. */
90 static int find_start_pos
;
91 static int find_start_value
;
92 static int find_start_value_byte
;
93 static struct buffer
*find_start_buffer
;
94 static int find_start_begv
;
95 static int find_start_modiff
;
98 static int find_defun_start
P_ ((int, int));
99 static int back_comment
P_ ((EMACS_INT
, EMACS_INT
, EMACS_INT
, int, int,
100 EMACS_INT
*, EMACS_INT
*));
101 static int char_quoted
P_ ((int, int));
102 static Lisp_Object skip_chars
P_ ((int, Lisp_Object
, Lisp_Object
, int));
103 static Lisp_Object skip_syntaxes
P_ ((int, Lisp_Object
, Lisp_Object
));
104 static Lisp_Object scan_lists
P_ ((EMACS_INT
, EMACS_INT
, EMACS_INT
, int));
105 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
107 int, Lisp_Object
, int));
108 static int in_classes
P_ ((int, Lisp_Object
));
111 struct gl_state_s gl_state
; /* Global state of syntax parser. */
113 INTERVAL
interval_of ();
114 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
115 to scan to property-change. */
117 /* Update gl_state to an appropriate interval which contains CHARPOS. The
118 sign of COUNT give the relative position of CHARPOS wrt the previously
119 valid interval. If INIT, only [be]_property fields of gl_state are
120 valid at start, the rest is filled basing on OBJECT.
122 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
123 direction than the intervals - or in an interval. We update the
124 current syntax-table basing on the property of this interval, and
125 update the interval to start further than CHARPOS - or be
126 NULL_INTERVAL. We also update lim_property to be the next value of
127 charpos to call this subroutine again - or be before/after the
128 start/end of OBJECT. */
131 update_syntax_table (charpos
, count
, init
, object
)
132 int charpos
, count
, init
;
135 Lisp_Object tmp_table
;
136 int cnt
= 0, invalidate
= 1;
141 gl_state
.old_prop
= Qnil
;
142 gl_state
.start
= gl_state
.b_property
;
143 gl_state
.stop
= gl_state
.e_property
;
144 i
= interval_of (charpos
, object
);
145 gl_state
.backward_i
= gl_state
.forward_i
= i
;
147 if (NULL_INTERVAL_P (i
))
149 /* interval_of updates only ->position of the return value, so
150 update the parents manually to speed up update_interval. */
151 while (!NULL_PARENT (i
))
153 if (AM_RIGHT_CHILD (i
))
154 INTERVAL_PARENT (i
)->position
= i
->position
155 - LEFT_TOTAL_LENGTH (i
) + TOTAL_LENGTH (i
) /* right end */
156 - TOTAL_LENGTH (INTERVAL_PARENT (i
))
157 + LEFT_TOTAL_LENGTH (INTERVAL_PARENT (i
));
159 INTERVAL_PARENT (i
)->position
= i
->position
- LEFT_TOTAL_LENGTH (i
)
161 i
= INTERVAL_PARENT (i
);
163 i
= gl_state
.forward_i
;
164 gl_state
.b_property
= i
->position
- gl_state
.offset
;
165 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
168 i
= count
> 0 ? gl_state
.forward_i
: gl_state
.backward_i
;
170 /* We are guaranteed to be called with CHARPOS either in i,
172 if (NULL_INTERVAL_P (i
))
173 error ("Error in syntax_table logic for to-the-end intervals");
174 else if (charpos
< i
->position
) /* Move left. */
177 error ("Error in syntax_table logic for intervals <-");
178 /* Update the interval. */
179 i
= update_interval (i
, charpos
);
180 if (INTERVAL_LAST_POS (i
) != gl_state
.b_property
)
183 gl_state
.forward_i
= i
;
184 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
187 else if (charpos
>= INTERVAL_LAST_POS (i
)) /* Move right. */
190 error ("Error in syntax_table logic for intervals ->");
191 /* Update the interval. */
192 i
= update_interval (i
, charpos
);
193 if (i
->position
!= gl_state
.e_property
)
196 gl_state
.backward_i
= i
;
197 gl_state
.b_property
= i
->position
- gl_state
.offset
;
202 tmp_table
= textget (i
->plist
, Qsyntax_table
);
205 invalidate
= !EQ (tmp_table
, gl_state
.old_prop
); /* Need to invalidate? */
207 if (invalidate
) /* Did not get to adjacent interval. */
208 { /* with the same table => */
209 /* invalidate the old range. */
212 gl_state
.backward_i
= i
;
213 gl_state
.b_property
= i
->position
- gl_state
.offset
;
217 gl_state
.forward_i
= i
;
218 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
222 if (!EQ (tmp_table
, gl_state
.old_prop
))
224 gl_state
.current_syntax_table
= tmp_table
;
225 gl_state
.old_prop
= tmp_table
;
226 if (EQ (Fsyntax_table_p (tmp_table
), Qt
))
228 gl_state
.use_global
= 0;
230 else if (CONSP (tmp_table
))
232 gl_state
.use_global
= 1;
233 gl_state
.global_code
= tmp_table
;
237 gl_state
.use_global
= 0;
238 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
242 while (!NULL_INTERVAL_P (i
))
244 if (cnt
&& !EQ (tmp_table
, textget (i
->plist
, Qsyntax_table
)))
248 gl_state
.e_property
= i
->position
- gl_state
.offset
;
249 gl_state
.forward_i
= i
;
254 = i
->position
+ LENGTH (i
) - gl_state
.offset
;
255 gl_state
.backward_i
= i
;
259 else if (cnt
== INTERVALS_AT_ONCE
)
264 = i
->position
+ LENGTH (i
) - gl_state
.offset
265 /* e_property at EOB is not set to ZV but to ZV+1, so that
266 we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
267 having to check eob between the two. */
268 + (NULL_INTERVAL_P (next_interval (i
)) ? 1 : 0);
269 gl_state
.forward_i
= i
;
273 gl_state
.b_property
= i
->position
- gl_state
.offset
;
274 gl_state
.backward_i
= i
;
279 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
281 eassert (NULL_INTERVAL_P (i
)); /* This property goes to the end. */
283 gl_state
.e_property
= gl_state
.stop
;
285 gl_state
.b_property
= gl_state
.start
;
288 /* Returns TRUE if char at CHARPOS is quoted.
289 Global syntax-table data should be set up already to be good at CHARPOS
290 or after. On return global syntax data is good for lookup at CHARPOS. */
293 char_quoted (charpos
, bytepos
)
294 register int charpos
, bytepos
;
296 register enum syntaxcode code
;
297 register int beg
= BEGV
;
298 register int quoted
= 0;
302 /* For some reason keeps getting called w/both 1, then segfaulting
303 due to the definitions of DEC_BOTH and DEC_POS in character.h,
304 which lead to decrementing below initial address and then examining
305 character there. Need to investigate further.. */
306 if (charpos
< 2 || bytepos
< 2)
308 //fprintf(stderr,"Returning because charpos = %d, bytepos = %d\n",charpos, bytepos);
313 DEC_BOTH (charpos
, bytepos
);
315 while (charpos
>= beg
)
319 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
320 c
= FETCH_CHAR_AS_MULTIBYTE (bytepos
);
322 if (! (code
== Scharquote
|| code
== Sescape
))
325 DEC_BOTH (charpos
, bytepos
);
329 UPDATE_SYNTAX_TABLE (orig
);
333 /* Return the bytepos one character after BYTEPOS.
334 We assume that BYTEPOS is not at the end of the buffer. */
337 inc_bytepos (bytepos
)
340 if (NILP (current_buffer
->enable_multibyte_characters
))
347 /* Return the bytepos one character before BYTEPOS.
348 We assume that BYTEPOS is not at the start of the buffer. */
351 dec_bytepos (bytepos
)
354 if (NILP (current_buffer
->enable_multibyte_characters
))
361 /* Return a defun-start position before before POS and not too far before.
362 It should be the last one before POS, or nearly the last.
364 When open_paren_in_column_0_is_defun_start is nonzero,
365 only the beginning of the buffer is treated as a defun-start.
367 We record the information about where the scan started
368 and what its result was, so that another call in the same area
369 can return the same value very quickly.
371 There is no promise at which position the global syntax data is
372 valid on return from the subroutine, so the caller should explicitly
373 update the global data. */
376 find_defun_start (pos
, pos_byte
)
379 int opoint
= PT
, opoint_byte
= PT_BYTE
;
381 if (!open_paren_in_column_0_is_defun_start
)
383 find_start_value_byte
= BEGV_BYTE
;
387 /* Use previous finding, if it's valid and applies to this inquiry. */
388 if (current_buffer
== find_start_buffer
389 /* Reuse the defun-start even if POS is a little farther on.
390 POS might be in the next defun, but that's ok.
391 Our value may not be the best possible, but will still be usable. */
392 && pos
<= find_start_pos
+ 1000
393 && pos
>= find_start_value
394 && BEGV
== find_start_begv
395 && MODIFF
== find_start_modiff
)
396 return find_start_value
;
398 /* Back up to start of line. */
399 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
401 /* We optimize syntax-table lookup for rare updates. Thus we accept
402 only those `^\s(' which are good in global _and_ text-property
404 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
405 gl_state
.use_global
= 0;
410 /* Open-paren at start of line means we may have found our
412 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
413 if (SYNTAX (c
) == Sopen
)
415 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
416 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
417 if (SYNTAX (c
) == Sopen
)
419 /* Now fallback to the default value. */
420 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
421 gl_state
.use_global
= 0;
423 /* Move to beg of previous line. */
424 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
427 /* Record what we found, for the next try. */
428 find_start_value
= PT
;
429 find_start_value_byte
= PT_BYTE
;
430 find_start_buffer
= current_buffer
;
431 find_start_modiff
= MODIFF
;
432 find_start_begv
= BEGV
;
433 find_start_pos
= pos
;
435 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
437 return find_start_value
;
440 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
443 prev_char_comend_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_COMEND_FIRST (c
);
452 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
456 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
459 * prev_char_comstart_first (pos, pos_byte)
464 * DEC_BOTH (pos, pos_byte);
465 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
466 * c = FETCH_CHAR (pos_byte);
467 * val = SYNTAX_COMSTART_FIRST (c);
468 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
472 /* Checks whether charpos FROM is at the end of a comment.
473 FROM_BYTE is the bytepos corresponding to FROM.
474 Do not move back before STOP.
476 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
479 If successful, store the charpos of the comment's beginning
480 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
482 Global syntax data remains valid for backward search starting at
483 the returned value (or at FROM, if the search was not successful). */
486 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
487 EMACS_INT from
, from_byte
, stop
;
488 int comnested
, comstyle
;
489 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
491 /* Look back, counting the parity of string-quotes,
492 and recording the comment-starters seen.
493 When we reach a safe place, assume that's not in a string;
494 then step the main scan to the earliest comment-starter seen
495 an even number of string quotes away from the safe place.
497 OFROM[I] is position of the earliest comment-starter seen
498 which is I+2X quotes from the comment-end.
499 PARITY is current parity of quotes from the comment end. */
500 int string_style
= -1; /* Presumed outside of any string. */
501 int string_lossage
= 0;
502 /* Not a real lossage: indicates that we have passed a matching comment
503 starter plus a non-matching comment-ender, meaning that any matching
504 comment-starter we might see later could be a false positive (hidden
505 inside another comment).
506 Test case: { a (* b } c (* d *) */
507 int comment_lossage
= 0;
508 int comment_end
= from
;
509 int comment_end_byte
= from_byte
;
510 int comstart_pos
= 0;
512 /* Place where the containing defun starts,
513 or 0 if we didn't come across it yet. */
515 int defun_start_byte
= 0;
516 register enum syntaxcode code
;
517 int nesting
= 1; /* current comment nesting */
521 /* FIXME: A }} comment-ender style leads to incorrect behavior
522 in the case of {{ c }}} because we ignore the last two chars which are
523 assumed to be comment-enders although they aren't. */
525 /* At beginning of range to scan, we're outside of strings;
526 that determines quote parity to the comment-end. */
529 int temp_byte
, prev_syntax
;
530 int com2start
, com2end
;
532 /* Move back and examine a character. */
533 DEC_BOTH (from
, from_byte
);
534 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
536 prev_syntax
= syntax
;
537 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
538 syntax
= SYNTAX_WITH_FLAGS (c
);
541 /* Check for 2-char comment markers. */
542 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
543 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
544 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
545 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
546 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
547 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
548 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
550 /* Nasty cases with overlapping 2-char comment markers:
551 - snmp-mode: -- c -- foo -- c --
559 /* If a 2-char comment sequence partly overlaps with another,
560 we don't try to be clever. */
561 if (from
> stop
&& (com2end
|| com2start
))
563 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
564 DEC_BOTH (next
, next_byte
);
565 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
566 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
567 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
568 if (((com2start
|| comnested
)
569 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
570 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
571 || ((com2end
|| comnested
)
572 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
573 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
574 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
576 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
579 if (com2start
&& comstart_pos
== 0)
580 /* We're looking at a comment starter. But it might be a comment
581 ender as well (see snmp-mode). The first time we see one, we
582 need to consider it as a comment starter,
583 and the subsequent times as a comment ender. */
586 /* Turn a 2-char comment sequences into the appropriate syntax. */
591 /* Ignore comment starters of a different style. */
592 else if (code
== Scomment
593 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
594 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
597 /* Ignore escaped characters, except comment-enders. */
598 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
605 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
607 /* Track parity of quotes. */
608 if (string_style
== -1)
609 /* Entering a string. */
611 else if (string_style
== c
)
612 /* Leaving the string. */
615 /* If we have two kinds of string delimiters.
616 There's no way to grok this scanning backwards. */
621 /* We've already checked that it is the relevant comstyle. */
622 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
623 /* There are odd string quotes involved, so let's be careful.
624 Test case in Pascal: " { " a { " } */
629 /* Record best comment-starter so far. */
631 comstart_byte
= from_byte
;
633 else if (--nesting
<= 0)
634 /* nested comments have to be balanced, so we don't need to
635 keep looking for earlier ones. We use here the same (slightly
636 incorrect) reasoning as below: since it is followed by uniform
637 paired string quotes, this comment-start has to be outside of
638 strings, else the comment-end itself would be inside a string. */
643 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
644 && ((com2end
&& SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
))
645 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
646 /* This is the same style of comment ender as ours. */
651 /* Anything before that can't count because it would match
652 this comment-ender rather than ours. */
653 from
= stop
; /* Break out of the loop. */
655 else if (comstart_pos
!= 0 || c
!= '\n')
656 /* We're mixing comment styles here, so we'd better be careful.
657 The (comstart_pos != 0 || c != '\n') check is not quite correct
658 (we should just always set comment_lossage), but removing it
659 would imply that any multiline comment in C would go through
660 lossage, which seems overkill.
661 The failure should only happen in the rare cases such as
667 /* Assume a defun-start point is outside of strings. */
668 if (open_paren_in_column_0_is_defun_start
670 || (temp_byte
= dec_bytepos (from_byte
),
671 FETCH_CHAR (temp_byte
) == '\n')))
674 defun_start_byte
= from_byte
;
675 from
= stop
; /* Break out of the loop. */
684 if (comstart_pos
== 0)
687 from_byte
= comment_end_byte
;
688 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
690 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
691 or `done'), then we've found the beginning of the non-nested comment. */
692 else if (1) /* !comnested */
695 from_byte
= comstart_byte
;
696 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
700 struct lisp_parse_state state
;
702 /* We had two kinds of string delimiters mixed up
703 together. Decode this going forwards.
704 Scan fwd from a known safe place (beginning-of-defun)
705 to the one in question; this records where we
706 last passed a comment starter. */
707 /* If we did not already find the defun start, find it now. */
708 if (defun_start
== 0)
710 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
711 defun_start_byte
= find_start_value_byte
;
715 scan_sexps_forward (&state
,
716 defun_start
, defun_start_byte
,
717 comment_end
, -10000, 0, Qnil
, 0);
718 defun_start
= comment_end
;
719 if (state
.incomment
== (comnested
? 1 : -1)
720 && state
.comstyle
== comstyle
)
721 from
= state
.comstr_start
;
726 /* If comment_end is inside some other comment, maybe ours
727 is nested, so we need to try again from within the
728 surrounding comment. Example: { a (* " *) */
730 /* FIXME: We should advance by one or two chars. */
731 defun_start
= state
.comstr_start
+ 2;
732 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
735 } while (defun_start
< comment_end
);
737 from_byte
= CHAR_TO_BYTE (from
);
738 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
743 *bytepos_ptr
= from_byte
;
745 return (from
== comment_end
) ? -1 : from
;
748 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
749 doc
: /* Return t if OBJECT is a syntax table.
750 Currently, any char-table counts as a syntax table. */)
754 if (CHAR_TABLE_P (object
)
755 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
761 check_syntax_table (obj
)
764 CHECK_TYPE (CHAR_TABLE_P (obj
) && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
),
765 Qsyntax_table_p
, obj
);
768 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
769 doc
: /* Return the current syntax table.
770 This is the one specified by the current buffer. */)
773 return current_buffer
->syntax_table
;
776 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
777 Sstandard_syntax_table
, 0, 0, 0,
778 doc
: /* Return the standard syntax table.
779 This is the one used for new buffers. */)
782 return Vstandard_syntax_table
;
785 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
786 doc
: /* Construct a new syntax table and return it.
787 It is a copy of the TABLE, which defaults to the standard syntax table. */)
794 check_syntax_table (table
);
796 table
= Vstandard_syntax_table
;
798 copy
= Fcopy_sequence (table
);
800 /* Only the standard syntax table should have a default element.
801 Other syntax tables should inherit from parents instead. */
802 XCHAR_TABLE (copy
)->defalt
= Qnil
;
804 /* Copied syntax tables should all have parents.
805 If we copied one with no parent, such as the standard syntax table,
806 use the standard syntax table as the copy's parent. */
807 if (NILP (XCHAR_TABLE (copy
)->parent
))
808 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
812 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
813 doc
: /* Select a new syntax table for the current buffer.
814 One argument, a syntax table. */)
819 check_syntax_table (table
);
820 current_buffer
->syntax_table
= table
;
821 /* Indicate that this buffer now has a specified syntax table. */
822 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
823 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
827 /* Convert a letter which signifies a syntax code
828 into the code it signifies.
829 This is used by modify-syntax-entry, and other things. */
831 unsigned char syntax_spec_code
[0400] =
832 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
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 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
837 (char) Smath
, 0377, 0377, (char) Squote
,
838 (char) Sopen
, (char) Sclose
, 0377, 0377,
839 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
840 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
841 0377, 0377, 0377, 0377,
842 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
843 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
844 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
845 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
846 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
847 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
848 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
849 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
850 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
853 /* Indexed by syntax code, give the letter that describes it. */
855 char syntax_code_spec
[16] =
857 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
861 /* Indexed by syntax code, give the object (cons of syntax code and
862 nil) to be stored in syntax table. Since these objects can be
863 shared among syntax tables, we generate them in advance. By
864 sharing objects, the function `describe-syntax' can give a more
866 static Lisp_Object Vsyntax_code_object
;
869 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
870 doc
: /* Return the syntax code of CHARACTER, described by a character.
871 For example, if CHARACTER is a word constituent,
872 the character `w' is returned.
873 The characters that correspond to various syntax codes
874 are listed in the documentation of `modify-syntax-entry'. */)
876 Lisp_Object character
;
879 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
881 gl_state
.use_global
= 0;
882 CHECK_NUMBER (character
);
883 char_int
= XINT (character
);
884 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
887 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
888 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
890 Lisp_Object character
;
893 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
894 gl_state
.use_global
= 0;
895 CHECK_NUMBER (character
);
896 char_int
= XINT (character
);
897 code
= SYNTAX (char_int
);
898 if (code
== Sopen
|| code
== Sclose
)
899 return SYNTAX_MATCH (char_int
);
903 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
904 doc
: /* Convert a syntax specification STRING into syntax cell form.
905 STRING should be a string as it is allowed as argument of
906 `modify-syntax-entry'. Value is the equivalent cons cell
907 \(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
912 register const unsigned char *p
;
913 register enum syntaxcode code
;
917 CHECK_STRING (string
);
920 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
921 if (((int) code
& 0377) == 0377)
922 error ("Invalid syntax description letter: %c", p
[-1]);
924 if (code
== Sinherit
)
930 int character
= (STRING_CHAR_AND_LENGTH
931 (p
, SBYTES (string
) - 1, len
));
932 XSETINT (match
, character
);
933 if (XFASTINT (match
) == ' ')
973 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
974 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
976 /* Since we can't use a shared object, let's make a new one. */
977 return Fcons (make_number (val
), match
);
980 /* I really don't know why this is interactive
981 help-form should at least be made useful whilst reading the second arg. */
982 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
983 "cSet syntax for character: \nsSet syntax for %s to: ",
984 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
985 The syntax is changed only for table SYNTAX-TABLE, which defaults to
986 the current buffer's syntax table.
987 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
988 in the range MIN and MAX are changed.
989 The first character of NEWENTRY should be one of the following:
990 Space or - whitespace syntax. w word constituent.
991 _ symbol constituent. . punctuation.
992 ( open-parenthesis. ) close-parenthesis.
993 " string quote. \\ escape.
994 $ paired delimiter. ' expression quote or prefix operator.
995 < comment starter. > comment ender.
996 / character-quote. @ inherit from `standard-syntax-table'.
997 | generic string fence. ! generic comment fence.
999 Only single-character comment start and end sequences are represented thus.
1000 Two-character sequences are represented as described below.
1001 The second character of NEWENTRY is the matching parenthesis,
1002 used only if the first character is `(' or `)'.
1003 Any additional characters are flags.
1004 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
1005 1 means CHAR is the start of a two-char comment start sequence.
1006 2 means CHAR is the second character of such a sequence.
1007 3 means CHAR is the start of a two-char comment end sequence.
1008 4 means CHAR is the second character of such a sequence.
1010 There can be up to two orthogonal comment sequences. This is to support
1011 language modes such as C++. By default, all comment sequences are of style
1012 a, but you can set the comment sequence style to b (on the second character
1013 of a comment-start, or the first character of a comment-end sequence) using
1015 b means CHAR is part of comment sequence b.
1016 n means CHAR is part of a nestable comment sequence.
1018 p means CHAR is a prefix character for `backward-prefix-chars';
1019 such characters are treated as whitespace when they occur
1020 between expressions.
1021 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1022 (c
, newentry
, syntax_table
)
1023 Lisp_Object c
, newentry
, syntax_table
;
1027 CHECK_CHARACTER_CAR (c
);
1028 CHECK_CHARACTER_CDR (c
);
1031 CHECK_CHARACTER (c
);
1033 if (NILP (syntax_table
))
1034 syntax_table
= current_buffer
->syntax_table
;
1036 check_syntax_table (syntax_table
);
1038 newentry
= Fstring_to_syntax (newentry
);
1040 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1042 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1044 /* We clear the regexp cache, since character classes can now have
1045 different values from those in the compiled regexps.*/
1046 clear_regexp_cache ();
1051 /* Dump syntax table to buffer in human-readable format */
1053 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1054 Sinternal_describe_syntax_value
, 1, 1, 0,
1055 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1059 register enum syntaxcode code
;
1060 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1062 Lisp_Object first
, match_lisp
, value
= syntax
;
1066 insert_string ("default");
1070 if (CHAR_TABLE_P (value
))
1072 insert_string ("deeper char-table ...");
1078 insert_string ("invalid");
1082 first
= XCAR (value
);
1083 match_lisp
= XCDR (value
);
1085 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1087 insert_string ("invalid");
1091 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1092 start1
= (XINT (first
) >> 16) & 1;
1093 start2
= (XINT (first
) >> 17) & 1;
1094 end1
= (XINT (first
) >> 18) & 1;
1095 end2
= (XINT (first
) >> 19) & 1;
1096 prefix
= (XINT (first
) >> 20) & 1;
1097 comstyle
= (XINT (first
) >> 21) & 1;
1098 comnested
= (XINT (first
) >> 22) & 1;
1100 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1102 insert_string ("invalid");
1105 desc
= syntax_code_spec
[(int) code
];
1107 str
[0] = desc
, str
[1] = 0;
1110 if (NILP (match_lisp
))
1113 insert_char (XINT (match_lisp
));
1132 insert_string ("\twhich means: ");
1134 switch (SWITCH_ENUM_CAST (code
))
1137 insert_string ("whitespace"); break;
1139 insert_string ("punctuation"); break;
1141 insert_string ("word"); break;
1143 insert_string ("symbol"); break;
1145 insert_string ("open"); break;
1147 insert_string ("close"); break;
1149 insert_string ("prefix"); break;
1151 insert_string ("string"); break;
1153 insert_string ("math"); break;
1155 insert_string ("escape"); break;
1157 insert_string ("charquote"); break;
1159 insert_string ("comment"); break;
1161 insert_string ("endcomment"); break;
1163 insert_string ("inherit"); break;
1164 case Scomment_fence
:
1165 insert_string ("comment fence"); break;
1167 insert_string ("string fence"); break;
1169 insert_string ("invalid");
1173 if (!NILP (match_lisp
))
1175 insert_string (", matches ");
1176 insert_char (XINT (match_lisp
));
1180 insert_string (",\n\t is the first character of a comment-start sequence");
1182 insert_string (",\n\t is the second character of a comment-start sequence");
1185 insert_string (",\n\t is the first character of a comment-end sequence");
1187 insert_string (",\n\t is the second character of a comment-end sequence");
1189 insert_string (" (comment style b)");
1191 insert_string (" (nestable)");
1194 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1199 int parse_sexp_ignore_comments
;
1201 /* Char-table of functions that find the next or previous word
1203 Lisp_Object Vfind_word_boundary_function_table
;
1205 /* Return the position across COUNT words from FROM.
1206 If that many words cannot be found before the end of the buffer, return 0.
1207 COUNT negative means scan backward and stop at word beginning. */
1210 scan_words (from
, count
)
1211 register int from
, count
;
1213 register int beg
= BEGV
;
1214 register int end
= ZV
;
1215 register int from_byte
= CHAR_TO_BYTE (from
);
1216 register enum syntaxcode code
;
1218 Lisp_Object func
, script
, pos
;
1223 SETUP_SYNTAX_TABLE (from
, count
);
1234 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1235 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1236 code
= SYNTAX (ch0
);
1237 INC_BOTH (from
, from_byte
);
1238 if (words_include_escapes
1239 && (code
== Sescape
|| code
== Scharquote
))
1244 /* Now CH0 is a character which begins a word and FROM is the
1245 position of the next character. */
1246 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch0
);
1247 if (! NILP (Ffboundp (func
)))
1249 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1250 if (INTEGERP (pos
) && XINT (pos
) > from
)
1253 from_byte
= CHAR_TO_BYTE (from
);
1258 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1261 if (from
== end
) break;
1262 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1263 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1264 code
= SYNTAX (ch1
);
1266 && (! words_include_escapes
1267 || (code
!= Sescape
&& code
!= Scharquote
)))
1268 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch1
), script
))
1270 INC_BOTH (from
, from_byte
);
1285 DEC_BOTH (from
, from_byte
);
1286 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1287 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1288 code
= SYNTAX (ch1
);
1289 if (words_include_escapes
1290 && (code
== Sescape
|| code
== Scharquote
))
1295 /* Now CH1 is a character which ends a word and FROM is the
1297 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch1
);
1298 if (! NILP (Ffboundp (func
)))
1300 pos
= call2 (func
, make_number (from
), make_number (beg
));
1301 if (INTEGERP (pos
) && XINT (pos
) < from
)
1304 from_byte
= CHAR_TO_BYTE (from
);
1309 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1314 DEC_BOTH (from
, from_byte
);
1315 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1316 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1317 code
= SYNTAX (ch0
);
1319 && (! words_include_escapes
1320 || (code
!= Sescape
&& code
!= Scharquote
)))
1321 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch0
), script
))
1323 INC_BOTH (from
, from_byte
);
1337 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 0, 1, "^p",
1338 doc
: /* Move point forward ARG words (backward if ARG is negative).
1340 If an edge of the buffer or a field boundary is reached, point is left there
1341 and the function returns nil. Field boundaries are not noticed if
1342 `inhibit-field-text-motion' is non-nil. */)
1350 XSETFASTINT (arg
, 1);
1354 val
= orig_val
= scan_words (PT
, XINT (arg
));
1356 val
= XINT (arg
) > 0 ? ZV
: BEGV
;
1358 /* Avoid jumping out of an input field. */
1359 tmp
= Fconstrain_to_field (make_number (val
), make_number (PT
),
1361 val
= XFASTINT (tmp
);
1364 return val
== orig_val
? Qt
: Qnil
;
1367 Lisp_Object
skip_chars ();
1369 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1370 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1371 STRING is like the inside of a `[...]' in a regular expression
1372 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1373 (but not as the end of a range; quoting is never needed there).
1374 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1375 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1376 Char classes, e.g. `[:alpha:]', are supported.
1378 Returns the distance traveled, either zero or positive. */)
1380 Lisp_Object string
, lim
;
1382 return skip_chars (1, string
, lim
, 1);
1385 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1386 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1387 See `skip-chars-forward' for details.
1388 Returns the distance traveled, either zero or negative. */)
1390 Lisp_Object string
, lim
;
1392 return skip_chars (0, string
, lim
, 1);
1395 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1396 doc
: /* Move point forward across chars in specified syntax classes.
1397 SYNTAX is a string of syntax code characters.
1398 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1399 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1400 This function returns the distance traveled, either zero or positive. */)
1402 Lisp_Object syntax
, lim
;
1404 return skip_syntaxes (1, syntax
, lim
);
1407 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1408 doc
: /* Move point backward across chars in specified syntax classes.
1409 SYNTAX is a string of syntax code characters.
1410 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1411 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1412 This function returns the distance traveled, either zero or negative. */)
1414 Lisp_Object syntax
, lim
;
1416 return skip_syntaxes (0, syntax
, lim
);
1420 skip_chars (forwardp
, string
, lim
, handle_iso_classes
)
1422 Lisp_Object string
, lim
;
1423 int handle_iso_classes
;
1425 register unsigned int c
;
1426 unsigned char fastmap
[0400];
1427 /* Store the ranges of non-ASCII characters. */
1429 int n_char_ranges
= 0;
1431 register int i
, i_byte
;
1432 /* Set to 1 if the current buffer is multibyte and the region
1433 contains non-ASCII chars. */
1435 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1437 int string_multibyte
;
1439 const unsigned char *str
;
1441 Lisp_Object iso_classes
;
1443 CHECK_STRING (string
);
1447 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1449 CHECK_NUMBER_COERCE_MARKER (lim
);
1451 /* In any case, don't allow scan outside bounds of buffer. */
1452 if (XINT (lim
) > ZV
)
1453 XSETFASTINT (lim
, ZV
);
1454 if (XINT (lim
) < BEGV
)
1455 XSETFASTINT (lim
, BEGV
);
1457 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1458 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1459 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1461 bzero (fastmap
, sizeof fastmap
);
1463 str
= SDATA (string
);
1464 size_byte
= SBYTES (string
);
1467 if (i_byte
< size_byte
1468 && SREF (string
, 0) == '^')
1470 negate
= 1; i_byte
++;
1473 /* Find the characters specified and set their elements of fastmap.
1474 Handle backslashes and ranges specially.
1476 If STRING contains non-ASCII characters, setup char_ranges for
1477 them and use fastmap only for their leading codes. */
1479 if (! string_multibyte
)
1481 int string_has_eight_bit
= 0;
1483 /* At first setup fastmap. */
1484 while (i_byte
< size_byte
)
1488 if (handle_iso_classes
&& c
== '['
1489 && i_byte
< size_byte
1490 && str
[i_byte
] == ':')
1492 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1493 const unsigned char *class_end
= class_beg
;
1494 const unsigned char *class_limit
= str
+ size_byte
- 2;
1495 /* Leave room for the null. */
1496 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1499 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1500 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1502 while (class_end
< class_limit
1503 && *class_end
>= 'a' && *class_end
<= 'z')
1506 if (class_end
== class_beg
1507 || *class_end
!= ':' || class_end
[1] != ']')
1508 goto not_a_class_name
;
1510 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1511 class_name
[class_end
- class_beg
] = 0;
1513 cc
= re_wctype (class_name
);
1515 error ("Invalid ISO C character class");
1517 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1519 i_byte
= class_end
+ 2 - str
;
1526 if (i_byte
== size_byte
)
1531 /* Treat `-' as range character only if another character
1533 if (i_byte
+ 1 < size_byte
1534 && str
[i_byte
] == '-')
1538 /* Skip over the dash. */
1541 /* Get the end of the range. */
1544 && i_byte
< size_byte
)
1551 if (! ASCII_CHAR_P (c2
))
1552 string_has_eight_bit
= 1;
1558 if (! ASCII_CHAR_P (c
))
1559 string_has_eight_bit
= 1;
1563 /* If the current range is multibyte and STRING contains
1564 eight-bit chars, arrange fastmap and setup char_ranges for
1565 the corresponding multibyte chars. */
1566 if (multibyte
&& string_has_eight_bit
)
1568 unsigned char fastmap2
[0400];
1569 int range_start_byte
, range_start_char
;
1571 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1572 bzero (fastmap
+ 0200, 0200);
1573 /* We are sure that this loop stops. */
1574 for (i
= 0200; ! fastmap2
[i
]; i
++);
1575 c
= unibyte_char_to_multibyte (i
);
1576 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1577 range_start_byte
= i
;
1578 range_start_char
= c
;
1579 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1580 for (i
= 129; i
< 0400; i
++)
1582 c
= unibyte_char_to_multibyte (i
);
1583 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1584 if (i
- range_start_byte
!= c
- range_start_char
)
1586 char_ranges
[n_char_ranges
++] = range_start_char
;
1587 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1588 + range_start_char
);
1589 range_start_byte
= i
;
1590 range_start_char
= c
;
1593 char_ranges
[n_char_ranges
++] = range_start_char
;
1594 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1595 + range_start_char
);
1598 else /* STRING is multibyte */
1600 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1602 while (i_byte
< size_byte
)
1604 unsigned char leading_code
;
1606 leading_code
= str
[i_byte
];
1607 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1610 if (handle_iso_classes
&& c
== '['
1611 && i_byte
< size_byte
1612 && STRING_CHAR (str
+ i_byte
, size_byte
- i_byte
) == ':')
1614 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1615 const unsigned char *class_end
= class_beg
;
1616 const unsigned char *class_limit
= str
+ size_byte
- 2;
1617 /* Leave room for the null. */
1618 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1621 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1622 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1624 while (class_end
< class_limit
1625 && *class_end
>= 'a' && *class_end
<= 'z')
1628 if (class_end
== class_beg
1629 || *class_end
!= ':' || class_end
[1] != ']')
1630 goto not_a_class_name_multibyte
;
1632 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1633 class_name
[class_end
- class_beg
] = 0;
1635 cc
= re_wctype (class_name
);
1637 error ("Invalid ISO C character class");
1639 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1641 i_byte
= class_end
+ 2 - str
;
1645 not_a_class_name_multibyte
:
1648 if (i_byte
== size_byte
)
1651 leading_code
= str
[i_byte
];
1652 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1653 size_byte
- i_byte
, len
);
1656 /* Treat `-' as range character only if another character
1658 if (i_byte
+ 1 < size_byte
1659 && str
[i_byte
] == '-')
1662 unsigned char leading_code2
;
1664 /* Skip over the dash. */
1667 /* Get the end of the range. */
1668 leading_code2
= str
[i_byte
];
1669 c2
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1670 size_byte
- i_byte
, len
);
1674 && i_byte
< size_byte
)
1676 leading_code2
= str
[i_byte
];
1677 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1683 if (ASCII_CHAR_P (c
))
1685 while (c
<= c2
&& c
< 0x80)
1687 leading_code
= CHAR_LEADING_CODE (c
);
1689 if (! ASCII_CHAR_P (c
))
1691 while (leading_code
<= leading_code2
)
1692 fastmap
[leading_code
++] = 1;
1695 char_ranges
[n_char_ranges
++] = c
;
1696 char_ranges
[n_char_ranges
++] = c2
;
1702 if (ASCII_CHAR_P (c
))
1706 fastmap
[leading_code
] = 1;
1707 char_ranges
[n_char_ranges
++] = c
;
1708 char_ranges
[n_char_ranges
++] = c
;
1713 /* If the current range is unibyte and STRING contains non-ASCII
1714 chars, arrange fastmap for the corresponding unibyte
1717 if (! multibyte
&& n_char_ranges
> 0)
1719 bzero (fastmap
+ 0200, 0200);
1720 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1722 int c1
= char_ranges
[i
];
1723 int c2
= char_ranges
[i
+ 1];
1725 for (; c1
<= c2
; c1
++)
1727 int b
= CHAR_TO_BYTE_SAFE (c1
);
1735 /* If ^ was the first character, complement the fastmap. */
1739 for (i
= 0; i
< sizeof fastmap
; i
++)
1743 for (i
= 0; i
< 0200; i
++)
1745 /* All non-ASCII chars possibly match. */
1746 for (; i
< sizeof fastmap
; i
++)
1752 int start_point
= PT
;
1754 int pos_byte
= PT_BYTE
;
1755 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1759 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1760 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1764 endp
= CHAR_POS_ADDR (XINT (lim
));
1765 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1783 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1784 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1794 if (! ASCII_CHAR_P (c
))
1796 /* As we are looking at a multibyte character, we
1797 must look up the character in the table
1798 CHAR_RANGES. If there's no data in the table,
1799 that character is not what we want to skip. */
1801 /* The following code do the right thing even if
1802 n_char_ranges is zero (i.e. no data in
1804 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1805 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1807 if (!(negate
^ (i
< n_char_ranges
)))
1811 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1824 if (!NILP (iso_classes
) && in_classes (*p
, iso_classes
))
1829 goto fwd_unibyte_ok
;
1835 p
++, pos
++, pos_byte
++;
1843 unsigned char *prev_p
;
1853 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1854 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1856 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1866 if (! ASCII_CHAR_P (c
))
1868 /* See the comment in the previous similar code. */
1869 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1870 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1872 if (!(negate
^ (i
< n_char_ranges
)))
1876 pos
--, pos_byte
-= prev_p
- p
;
1889 if (! NILP (iso_classes
) && in_classes (p
[-1], iso_classes
))
1894 goto back_unibyte_ok
;
1897 if (!fastmap
[p
[-1]])
1900 p
--, pos
--, pos_byte
--;
1904 SET_PT_BOTH (pos
, pos_byte
);
1907 return make_number (PT
- start_point
);
1913 skip_syntaxes (forwardp
, string
, lim
)
1915 Lisp_Object string
, lim
;
1917 register unsigned int c
;
1918 unsigned char fastmap
[0400];
1920 register int i
, i_byte
;
1925 CHECK_STRING (string
);
1928 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1930 CHECK_NUMBER_COERCE_MARKER (lim
);
1932 /* In any case, don't allow scan outside bounds of buffer. */
1933 if (XINT (lim
) > ZV
)
1934 XSETFASTINT (lim
, ZV
);
1935 if (XINT (lim
) < BEGV
)
1936 XSETFASTINT (lim
, BEGV
);
1938 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1939 return make_number (0);
1941 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1942 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1944 bzero (fastmap
, sizeof fastmap
);
1946 if (SBYTES (string
) > SCHARS (string
))
1947 /* As this is very rare case (syntax spec is ASCII only), don't
1948 consider efficiency. */
1949 string
= string_make_unibyte (string
);
1951 str
= SDATA (string
);
1952 size_byte
= SBYTES (string
);
1955 if (i_byte
< size_byte
1956 && SREF (string
, 0) == '^')
1958 negate
= 1; i_byte
++;
1961 /* Find the syntaxes specified and set their elements of fastmap. */
1963 while (i_byte
< size_byte
)
1966 fastmap
[syntax_spec_code
[c
]] = 1;
1969 /* If ^ was the first character, complement the fastmap. */
1971 for (i
= 0; i
< sizeof fastmap
; i
++)
1975 int start_point
= PT
;
1977 int pos_byte
= PT_BYTE
;
1978 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1982 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1983 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1987 endp
= CHAR_POS_ADDR (XINT (lim
));
1988 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1992 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
2008 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
2009 if (! fastmap
[(int) SYNTAX (c
)])
2011 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
2012 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2026 if (! fastmap
[(int) SYNTAX (*p
)])
2028 p
++, pos
++, pos_byte
++;
2029 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2039 unsigned char *prev_p
;
2048 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2050 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
2051 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
2052 if (! fastmap
[(int) SYNTAX (c
)])
2054 pos
--, pos_byte
-= prev_p
- p
;
2068 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2069 if (! fastmap
[(int) SYNTAX (p
[-1])])
2071 p
--, pos
--, pos_byte
--;
2076 SET_PT_BOTH (pos
, pos_byte
);
2079 return make_number (PT
- start_point
);
2083 /* Return 1 if character C belongs to one of the ISO classes
2084 in the list ISO_CLASSES. Each class is represented by an
2085 integer which is its type according to re_wctype. */
2088 in_classes (c
, iso_classes
)
2090 Lisp_Object iso_classes
;
2094 while (! NILP (iso_classes
))
2097 elt
= XCAR (iso_classes
);
2098 iso_classes
= XCDR (iso_classes
);
2100 if (re_iswctype (c
, XFASTINT (elt
)))
2107 /* Jump over a comment, assuming we are at the beginning of one.
2108 FROM is the current position.
2109 FROM_BYTE is the bytepos corresponding to FROM.
2110 Do not move past STOP (a charpos).
2111 The comment over which we have to jump is of style STYLE
2112 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2113 NESTING should be positive to indicate the nesting at the beginning
2114 for nested comments and should be zero or negative else.
2115 ST_COMMENT_STYLE cannot be nested.
2116 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
2117 (or 0 If the search cannot start in the middle of a two-character).
2119 If successful, return 1 and store the charpos of the comment's end
2120 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
2121 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
2122 corresponding bytepos into *BYTEPOS_PTR and the current nesting
2123 (as defined for state.incomment) in *INCOMMENT_PTR.
2125 The comment end is the last character of the comment rather than the
2126 character just after the comment.
2128 Global syntax data is assumed to initially be valid for FROM and
2129 remains valid for forward search starting at the returned position. */
2132 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
2133 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
2134 EMACS_INT from
, from_byte
, stop
;
2135 int nesting
, style
, prev_syntax
;
2136 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
2140 register enum syntaxcode code
;
2141 register int syntax
;
2143 if (nesting
<= 0) nesting
= -1;
2145 /* Enter the loop in the middle so that we find
2146 a 2-char comment ender if we start in the middle of it. */
2147 syntax
= prev_syntax
;
2148 if (syntax
!= 0) goto forw_incomment
;
2154 *incomment_ptr
= nesting
;
2155 *charpos_ptr
= from
;
2156 *bytepos_ptr
= from_byte
;
2159 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2160 syntax
= SYNTAX_WITH_FLAGS (c
);
2161 code
= syntax
& 0xff;
2162 if (code
== Sendcomment
2163 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2164 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
2165 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
2166 /* we have encountered a comment end of the same style
2167 as the comment sequence which began this comment
2170 if (code
== Scomment_fence
2171 && style
== ST_COMMENT_STYLE
)
2172 /* we have encountered a comment end of the same style
2173 as the comment sequence which began this comment
2178 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
2179 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
2180 /* we have encountered a nested comment of the same style
2181 as the comment sequence which began this comment section */
2183 INC_BOTH (from
, from_byte
);
2184 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2187 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2188 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2189 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2190 SYNTAX_COMEND_SECOND (c1
))
2191 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2192 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2195 /* we have encountered a comment end of the same style
2196 as the comment sequence which began this comment
2201 INC_BOTH (from
, from_byte
);
2202 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2207 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2208 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2209 SYNTAX_COMMENT_STYLE (c1
) == style
2210 && SYNTAX_COMSTART_SECOND (c1
))
2211 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2212 SYNTAX_COMMENT_NESTED (c1
)))
2213 /* we have encountered a nested comment of the same style
2214 as the comment sequence which began this comment
2217 INC_BOTH (from
, from_byte
);
2218 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2222 *charpos_ptr
= from
;
2223 *bytepos_ptr
= from_byte
;
2227 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2229 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2230 Stop scanning if we find something other than a comment or whitespace.
2231 Set point to where scanning stops.
2232 If COUNT comments are found as expected, with nothing except whitespace
2233 between them, return t; otherwise return nil. */)
2237 register EMACS_INT from
;
2238 EMACS_INT from_byte
;
2239 register EMACS_INT stop
;
2241 register enum syntaxcode code
;
2242 int comstyle
= 0; /* style of comment encountered */
2243 int comnested
= 0; /* whether the comment is nestable or not */
2246 EMACS_INT out_charpos
, out_bytepos
;
2249 CHECK_NUMBER (count
);
2250 count1
= XINT (count
);
2251 stop
= count1
> 0 ? ZV
: BEGV
;
2257 from_byte
= PT_BYTE
;
2259 SETUP_SYNTAX_TABLE (from
, count1
);
2268 SET_PT_BOTH (from
, from_byte
);
2272 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2274 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2275 comnested
= SYNTAX_COMMENT_NESTED (c
);
2276 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2277 INC_BOTH (from
, from_byte
);
2278 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2279 if (from
< stop
&& comstart_first
2280 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2281 SYNTAX_COMSTART_SECOND (c1
)))
2283 /* We have encountered a comment start sequence and we
2284 are ignoring all text inside comments. We must record
2285 the comment style this sequence begins so that later,
2286 only a comment end of the same style actually ends
2287 the comment section. */
2289 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2290 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2291 INC_BOTH (from
, from_byte
);
2292 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2295 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2297 if (code
== Scomment_fence
)
2298 comstyle
= ST_COMMENT_STYLE
;
2299 else if (code
!= Scomment
)
2302 DEC_BOTH (from
, from_byte
);
2303 SET_PT_BOTH (from
, from_byte
);
2306 /* We're at the start of a comment. */
2307 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2308 &out_charpos
, &out_bytepos
, &dummy
);
2309 from
= out_charpos
; from_byte
= out_bytepos
;
2313 SET_PT_BOTH (from
, from_byte
);
2316 INC_BOTH (from
, from_byte
);
2317 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2318 /* We have skipped one comment. */
2330 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2335 DEC_BOTH (from
, from_byte
);
2336 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2337 quoted
= char_quoted (from
, from_byte
);
2338 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2341 comnested
= SYNTAX_COMMENT_NESTED (c
);
2342 if (code
== Sendcomment
)
2343 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2344 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2345 && prev_char_comend_first (from
, from_byte
)
2346 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2348 /* We must record the comment style encountered so that
2349 later, we can match only the proper comment begin
2350 sequence of the same style. */
2351 DEC_BOTH (from
, from_byte
);
2353 /* Calling char_quoted, above, set up global syntax position
2354 at the new value of FROM. */
2355 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2356 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2357 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2360 if (code
== Scomment_fence
)
2362 /* Skip until first preceding unquoted comment_fence. */
2363 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2367 DEC_BOTH (from
, from_byte
);
2368 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2369 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2370 if (SYNTAX (c
) == Scomment_fence
2371 && !char_quoted (from
, from_byte
))
2376 else if (from
== stop
)
2381 from
= ini
; /* Set point to ini + 1. */
2382 from_byte
= ini_byte
;
2386 /* We have skipped one comment. */
2389 else if (code
== Sendcomment
)
2391 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2392 &out_charpos
, &out_bytepos
);
2396 /* This end-of-line is not an end-of-comment.
2397 Treat it like a whitespace.
2398 CC-mode (and maybe others) relies on this behavior. */
2402 /* Failure: we should go back to the end of this
2403 not-quite-endcomment. */
2404 if (SYNTAX(c
) != code
)
2405 /* It was a two-char Sendcomment. */
2406 INC_BOTH (from
, from_byte
);
2412 /* We have skipped one comment. */
2413 from
= out_charpos
, from_byte
= out_bytepos
;
2417 else if (code
!= Swhitespace
|| quoted
)
2421 INC_BOTH (from
, from_byte
);
2422 SET_PT_BOTH (from
, from_byte
);
2430 SET_PT_BOTH (from
, from_byte
);
2435 /* Return syntax code of character C if C is an ASCII character
2436 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2438 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2439 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2440 ? SYNTAX (c) : Ssymbol)
2443 scan_lists (from
, count
, depth
, sexpflag
)
2444 register EMACS_INT from
;
2445 EMACS_INT count
, depth
;
2449 register EMACS_INT stop
= count
> 0 ? ZV
: BEGV
;
2454 register enum syntaxcode code
, temp_code
;
2455 int min_depth
= depth
; /* Err out if depth gets less than this. */
2456 int comstyle
= 0; /* style of comment encountered */
2457 int comnested
= 0; /* whether the comment is nestable or not */
2459 EMACS_INT last_good
= from
;
2461 EMACS_INT from_byte
;
2462 EMACS_INT out_bytepos
, out_charpos
;
2464 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2466 if (depth
> 0) min_depth
= 0;
2468 if (from
> ZV
) from
= ZV
;
2469 if (from
< BEGV
) from
= BEGV
;
2471 from_byte
= CHAR_TO_BYTE (from
);
2476 SETUP_SYNTAX_TABLE (from
, count
);
2481 int comstart_first
, prefix
;
2482 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2483 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2484 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2485 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2486 comnested
= SYNTAX_COMMENT_NESTED (c
);
2487 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2488 prefix
= SYNTAX_PREFIX (c
);
2489 if (depth
== min_depth
)
2491 INC_BOTH (from
, from_byte
);
2492 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2493 if (from
< stop
&& comstart_first
2494 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2495 SYNTAX_COMSTART_SECOND (c
))
2496 && parse_sexp_ignore_comments
)
2498 /* we have encountered a comment start sequence and we
2499 are ignoring all text inside comments. We must record
2500 the comment style this sequence begins so that later,
2501 only a comment end of the same style actually ends
2502 the comment section */
2504 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2505 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2506 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2507 INC_BOTH (from
, from_byte
);
2508 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2514 switch (SWITCH_ENUM_CAST (code
))
2520 INC_BOTH (from
, from_byte
);
2521 /* treat following character as a word constituent */
2524 if (depth
|| !sexpflag
) break;
2525 /* This word counts as a sexp; return at end of it. */
2528 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2530 /* Some compilers can't handle this inside the switch. */
2531 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2532 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2537 INC_BOTH (from
, from_byte
);
2548 INC_BOTH (from
, from_byte
);
2552 case Scomment_fence
:
2553 comstyle
= ST_COMMENT_STYLE
;
2556 if (!parse_sexp_ignore_comments
) break;
2557 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2558 found
= forw_comment (from
, from_byte
, stop
,
2559 comnested
, comstyle
, 0,
2560 &out_charpos
, &out_bytepos
, &dummy
);
2561 from
= out_charpos
, from_byte
= out_bytepos
;
2568 INC_BOTH (from
, from_byte
);
2569 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2575 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2577 INC_BOTH (from
, from_byte
);
2587 if (!++depth
) goto done
;
2592 if (!--depth
) goto done
;
2593 if (depth
< min_depth
)
2594 xsignal3 (Qscan_error
,
2595 build_string ("Containing expression ends prematurely"),
2596 make_number (last_good
), make_number (from
));
2601 temp_pos
= dec_bytepos (from_byte
);
2602 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2607 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2608 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2611 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2612 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2615 /* Some compilers can't handle this inside the switch. */
2616 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2621 INC_BOTH (from
, from_byte
);
2623 INC_BOTH (from
, from_byte
);
2625 INC_BOTH (from
, from_byte
);
2626 if (!depth
&& sexpflag
) goto done
;
2629 /* Ignore whitespace, punctuation, quote, endcomment. */
2634 /* Reached end of buffer. Error if within object, return nil if between */
2641 /* End of object reached */
2650 DEC_BOTH (from
, from_byte
);
2651 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2652 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2653 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2654 if (depth
== min_depth
)
2657 comnested
= SYNTAX_COMMENT_NESTED (c
);
2658 if (code
== Sendcomment
)
2659 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2660 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2661 && prev_char_comend_first (from
, from_byte
)
2662 && parse_sexp_ignore_comments
)
2664 /* We must record the comment style encountered so that
2665 later, we can match only the proper comment begin
2666 sequence of the same style. */
2667 DEC_BOTH (from
, from_byte
);
2668 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2670 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2671 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2672 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2675 /* Quoting turns anything except a comment-ender
2676 into a word character. Note that this cannot be true
2677 if we decremented FROM in the if-statement above. */
2678 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2680 DEC_BOTH (from
, from_byte
);
2683 else if (SYNTAX_PREFIX (c
))
2686 switch (SWITCH_ENUM_CAST (code
))
2692 if (depth
|| !sexpflag
) break;
2693 /* This word counts as a sexp; count object finished
2694 after passing it. */
2697 temp_pos
= from_byte
;
2698 if (! NILP (current_buffer
->enable_multibyte_characters
))
2702 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2703 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2704 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2705 /* Don't allow comment-end to be quoted. */
2706 if (temp_code
== Sendcomment
)
2708 quoted
= char_quoted (from
- 1, temp_pos
);
2711 DEC_BOTH (from
, from_byte
);
2712 temp_pos
= dec_bytepos (temp_pos
);
2713 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2715 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2716 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2717 if (! (quoted
|| temp_code
== Sword
2718 || temp_code
== Ssymbol
2719 || temp_code
== Squote
))
2721 DEC_BOTH (from
, from_byte
);
2728 temp_pos
= dec_bytepos (from_byte
);
2729 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2730 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2731 DEC_BOTH (from
, from_byte
);
2740 if (!++depth
) goto done2
;
2745 if (!--depth
) goto done2
;
2746 if (depth
< min_depth
)
2747 xsignal3 (Qscan_error
,
2748 build_string ("Containing expression ends prematurely"),
2749 make_number (last_good
), make_number (from
));
2753 if (!parse_sexp_ignore_comments
)
2755 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2756 &out_charpos
, &out_bytepos
);
2757 /* FIXME: if found == -1, then it really wasn't a comment-end.
2758 For single-char Sendcomment, we can't do much about it apart
2759 from skipping the char.
2760 For 2-char endcomments, we could try again, taking both
2761 chars as separate entities, but it's a lot of trouble
2762 for very little gain, so we don't bother either. -sm */
2764 from
= out_charpos
, from_byte
= out_bytepos
;
2767 case Scomment_fence
:
2773 DEC_BOTH (from
, from_byte
);
2774 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2775 if (!char_quoted (from
, from_byte
)
2776 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2777 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2780 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2784 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2789 DEC_BOTH (from
, from_byte
);
2790 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2791 if (!char_quoted (from
, from_byte
)
2793 == (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
)))
2794 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2797 if (!depth
&& sexpflag
) goto done2
;
2800 /* Ignore whitespace, punctuation, quote, endcomment. */
2805 /* Reached start of buffer. Error if within object, return nil if between */
2818 XSETFASTINT (val
, from
);
2822 xsignal3 (Qscan_error
,
2823 build_string ("Unbalanced parentheses"),
2824 make_number (last_good
), make_number (from
));
2827 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2828 doc
: /* Scan from character number FROM by COUNT lists.
2829 Returns the character number of the position thus found.
2831 If DEPTH is nonzero, paren depth begins counting from that value,
2832 only places where the depth in parentheses becomes zero
2833 are candidates for stopping; COUNT such places are counted.
2834 Thus, a positive value for DEPTH means go out levels.
2836 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2838 If the beginning or end of (the accessible part of) the buffer is reached
2839 and the depth is wrong, an error is signaled.
2840 If the depth is right but the count is not used up, nil is returned. */)
2841 (from
, count
, depth
)
2842 Lisp_Object from
, count
, depth
;
2844 CHECK_NUMBER (from
);
2845 CHECK_NUMBER (count
);
2846 CHECK_NUMBER (depth
);
2848 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2851 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2852 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2853 If COUNT is negative, scan backwards.
2854 Returns the character number of the position thus found.
2856 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2858 If the beginning or end of (the accessible part of) the buffer is reached
2859 in the middle of a parenthetical grouping, an error is signaled.
2860 If the beginning or end is reached between groupings
2861 but before count is used up, nil is returned. */)
2863 Lisp_Object from
, count
;
2865 CHECK_NUMBER (from
);
2866 CHECK_NUMBER (count
);
2868 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2871 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2873 doc
: /* Move point backward over any number of chars with prefix syntax.
2874 This includes chars with "quote" or "prefix" syntax (' or p). */)
2879 int opoint_byte
= PT_BYTE
;
2881 int pos_byte
= PT_BYTE
;
2886 SET_PT_BOTH (opoint
, opoint_byte
);
2891 SETUP_SYNTAX_TABLE (pos
, -1);
2893 DEC_BOTH (pos
, pos_byte
);
2895 while (!char_quoted (pos
, pos_byte
)
2896 /* Previous statement updates syntax table. */
2897 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2898 || SYNTAX_PREFIX (c
)))
2901 opoint_byte
= pos_byte
;
2904 DEC_BOTH (pos
, pos_byte
);
2907 SET_PT_BOTH (opoint
, opoint_byte
);
2912 /* Parse forward from FROM / FROM_BYTE to END,
2913 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2914 and return a description of the state of the parse at END.
2915 If STOPBEFORE is nonzero, stop at the start of an atom.
2916 If COMMENTSTOP is 1, stop at the start of a comment.
2917 If COMMENTSTOP is -1, stop at the start or end of a comment,
2918 after the beginning of a string, or after the end of a string. */
2921 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2922 stopbefore
, oldstate
, commentstop
)
2923 struct lisp_parse_state
*stateptr
;
2926 int end
, targetdepth
, stopbefore
;
2927 Lisp_Object oldstate
;
2930 struct lisp_parse_state state
;
2932 register enum syntaxcode code
;
2935 struct level
{ int last
, prev
; };
2936 struct level levelstart
[100];
2937 register struct level
*curlevel
= levelstart
;
2938 struct level
*endlevel
= levelstart
+ 100;
2939 register int depth
; /* Paren depth of current scanning location.
2940 level - levelstart equals this except
2941 when the depth becomes negative. */
2942 int mindepth
; /* Lowest DEPTH value seen. */
2943 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2945 int prev_from
; /* Keep one character before FROM. */
2947 int prev_from_syntax
;
2948 int boundary_stop
= commentstop
== -1;
2951 EMACS_INT out_bytepos
, out_charpos
;
2955 prev_from_byte
= from_byte
;
2957 DEC_BOTH (prev_from
, prev_from_byte
);
2959 /* Use this macro instead of `from++'. */
2961 do { prev_from = from; \
2962 prev_from_byte = from_byte; \
2963 temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
2964 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
2965 INC_BOTH (from, from_byte); \
2967 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2973 if (NILP (oldstate
))
2976 state
.instring
= -1;
2977 state
.incomment
= 0;
2978 state
.comstyle
= 0; /* comment style a by default. */
2979 state
.comstr_start
= -1; /* no comment/string seen. */
2983 tem
= Fcar (oldstate
);
2989 oldstate
= Fcdr (oldstate
);
2990 oldstate
= Fcdr (oldstate
);
2991 oldstate
= Fcdr (oldstate
);
2992 tem
= Fcar (oldstate
);
2993 /* Check whether we are inside string_fence-style string: */
2994 state
.instring
= (!NILP (tem
)
2995 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2998 oldstate
= Fcdr (oldstate
);
2999 tem
= Fcar (oldstate
);
3000 state
.incomment
= (!NILP (tem
)
3001 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
3004 oldstate
= Fcdr (oldstate
);
3005 tem
= Fcar (oldstate
);
3006 start_quoted
= !NILP (tem
);
3008 /* if the eighth element of the list is nil, we are in comment
3009 style a. If it is non-nil, we are in comment style b */
3010 oldstate
= Fcdr (oldstate
);
3011 oldstate
= Fcdr (oldstate
);
3012 tem
= Fcar (oldstate
);
3013 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
3014 ? ST_COMMENT_STYLE
: 1);
3016 oldstate
= Fcdr (oldstate
);
3017 tem
= Fcar (oldstate
);
3018 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
3019 oldstate
= Fcdr (oldstate
);
3020 tem
= Fcar (oldstate
);
3021 while (!NILP (tem
)) /* >= second enclosing sexps. */
3023 /* curlevel++->last ran into compiler bug on Apollo */
3024 curlevel
->last
= XINT (Fcar (tem
));
3025 if (++curlevel
== endlevel
)
3026 curlevel
--; /* error ("Nesting too deep for parser"); */
3027 curlevel
->prev
= -1;
3028 curlevel
->last
= -1;
3035 curlevel
->prev
= -1;
3036 curlevel
->last
= -1;
3038 SETUP_SYNTAX_TABLE (prev_from
, 1);
3039 temp
= FETCH_CHAR (prev_from_byte
);
3040 prev_from_syntax
= SYNTAX_WITH_FLAGS (temp
);
3041 UPDATE_SYNTAX_TABLE_FORWARD (from
);
3043 /* Enter the loop at a place appropriate for initial state. */
3045 if (state
.incomment
)
3046 goto startincomment
;
3047 if (state
.instring
>= 0)
3049 nofence
= state
.instring
!= ST_STRING_STYLE
;
3051 goto startquotedinstring
;
3054 else if (start_quoted
)
3060 code
= prev_from_syntax
& 0xff;
3063 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
)
3064 && (c1
= FETCH_CHAR (from_byte
),
3065 SYNTAX_COMSTART_SECOND (c1
)))
3066 /* Duplicate code to avoid a complex if-expression
3067 which causes trouble for the SGI compiler. */
3069 /* Record the comment style we have entered so that only
3070 the comment-end sequence of the same style actually
3071 terminates the comment section. */
3072 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
3073 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
3074 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
3075 state
.incomment
= comnested
? 1 : -1;
3076 state
.comstr_start
= prev_from
;
3080 else if (code
== Scomment_fence
)
3082 /* Record the comment style we have entered so that only
3083 the comment-end sequence of the same style actually
3084 terminates the comment section. */
3085 state
.comstyle
= ST_COMMENT_STYLE
;
3086 state
.incomment
= -1;
3087 state
.comstr_start
= prev_from
;
3090 else if (code
== Scomment
)
3092 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
3093 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
3095 state
.comstr_start
= prev_from
;
3098 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
3100 switch (SWITCH_ENUM_CAST (code
))
3104 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3105 curlevel
->last
= prev_from
;
3107 if (from
== end
) goto endquoted
;
3110 /* treat following character as a word constituent */
3113 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3114 curlevel
->last
= prev_from
;
3118 /* Some compilers can't handle this inside the switch. */
3119 temp
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3120 temp
= SYNTAX (temp
);
3126 if (from
== end
) goto endquoted
;
3138 curlevel
->prev
= curlevel
->last
;
3141 case Scomment_fence
: /* Can't happen because it's handled above. */
3143 if (commentstop
|| boundary_stop
) goto done
;
3145 /* The (from == BEGV) test was to enter the loop in the middle so
3146 that we find a 2-char comment ender even if we start in the
3147 middle of it. We don't want to do that if we're just at the
3148 beginning of the comment (think of (*) ... (*)). */
3149 found
= forw_comment (from
, from_byte
, end
,
3150 state
.incomment
, state
.comstyle
,
3151 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
3152 ? 0 : prev_from_syntax
,
3153 &out_charpos
, &out_bytepos
, &state
.incomment
);
3154 from
= out_charpos
; from_byte
= out_bytepos
;
3155 /* Beware! prev_from and friends are invalid now.
3156 Luckily, the `done' doesn't use them and the INC_FROM
3157 sets them to a sane value without looking at them. */
3158 if (!found
) goto done
;
3160 state
.incomment
= 0;
3161 state
.comstyle
= 0; /* reset the comment style */
3162 if (boundary_stop
) goto done
;
3166 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3168 /* curlevel++->last ran into compiler bug on Apollo */
3169 curlevel
->last
= prev_from
;
3170 if (++curlevel
== endlevel
)
3171 curlevel
--; /* error ("Nesting too deep for parser"); */
3172 curlevel
->prev
= -1;
3173 curlevel
->last
= -1;
3174 if (targetdepth
== depth
) goto done
;
3179 if (depth
< mindepth
)
3181 if (curlevel
!= levelstart
)
3183 curlevel
->prev
= curlevel
->last
;
3184 if (targetdepth
== depth
) goto done
;
3189 state
.comstr_start
= from
- 1;
3190 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3191 curlevel
->last
= prev_from
;
3192 state
.instring
= (code
== Sstring
3193 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3195 if (boundary_stop
) goto done
;
3198 nofence
= state
.instring
!= ST_STRING_STYLE
;
3204 if (from
>= end
) goto done
;
3205 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3206 /* Some compilers can't handle this inside the switch. */
3209 /* Check TEMP here so that if the char has
3210 a syntax-table property which says it is NOT
3211 a string character, it does not end the string. */
3212 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3218 if (!nofence
) goto string_end
;
3223 startquotedinstring
:
3224 if (from
>= end
) goto endquoted
;
3230 state
.instring
= -1;
3231 curlevel
->prev
= curlevel
->last
;
3233 if (boundary_stop
) goto done
;
3237 /* FIXME: We should do something with it. */
3240 /* Ignore whitespace, punctuation, quote, endcomment. */
3246 stop
: /* Here if stopping before start of sexp. */
3247 from
= prev_from
; /* We have just fetched the char that starts it; */
3248 goto done
; /* but return the position before it. */
3253 state
.depth
= depth
;
3254 state
.mindepth
= mindepth
;
3255 state
.thislevelstart
= curlevel
->prev
;
3256 state
.prevlevelstart
3257 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3258 state
.location
= from
;
3259 state
.levelstarts
= Qnil
;
3260 while (--curlevel
>= levelstart
)
3261 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3268 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3269 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3270 Parsing stops at TO or when certain criteria are met;
3271 point is set to where parsing stops.
3272 If fifth arg OLDSTATE is omitted or nil,
3273 parsing assumes that FROM is the beginning of a function.
3274 Value is a list of elements describing final state of parsing:
3276 1. character address of start of innermost containing list; nil if none.
3277 2. character address of start of last complete sexp terminated.
3278 3. non-nil if inside a string.
3279 (it is the character that will terminate the string,
3280 or t if the string should be terminated by a generic string delimiter.)
3281 4. nil if outside a comment, t if inside a non-nestable comment,
3282 else an integer (the current comment nesting).
3283 5. t if following a quote character.
3284 6. the minimum paren-depth encountered during this scan.
3285 7. t if in a comment of style b; symbol `syntax-table' if the comment
3286 should be terminated by a generic comment delimiter.
3287 8. character address of start of comment or string; nil if not in one.
3288 9. Intermediate data for continuation of parsing (subject to change).
3289 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3290 in parentheses becomes equal to TARGETDEPTH.
3291 Fourth arg STOPBEFORE non-nil means stop when come to
3292 any character that starts a sexp.
3293 Fifth arg OLDSTATE is a list like what this function returns.
3294 It is used to initialize the state of the parse. Elements number 1, 2, 6
3296 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3297 If it is symbol `syntax-table', stop after the start of a comment or a
3298 string, or after end of a comment or a string. */)
3299 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3300 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3302 struct lisp_parse_state state
;
3305 if (!NILP (targetdepth
))
3307 CHECK_NUMBER (targetdepth
);
3308 target
= XINT (targetdepth
);
3311 target
= -100000; /* We won't reach this depth */
3313 validate_region (&from
, &to
);
3314 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3316 target
, !NILP (stopbefore
), oldstate
,
3318 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3320 SET_PT (state
.location
);
3322 return Fcons (make_number (state
.depth
),
3323 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3324 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3325 Fcons (state
.instring
>= 0
3326 ? (state
.instring
== ST_STRING_STYLE
3327 ? Qt
: make_number (state
.instring
)) : Qnil
,
3328 Fcons (state
.incomment
< 0 ? Qt
:
3329 (state
.incomment
== 0 ? Qnil
:
3330 make_number (state
.incomment
)),
3331 Fcons (state
.quoted
? Qt
: Qnil
,
3332 Fcons (make_number (state
.mindepth
),
3333 Fcons ((state
.comstyle
3334 ? (state
.comstyle
== ST_COMMENT_STYLE
3335 ? Qsyntax_table
: Qt
) :
3337 Fcons (((state
.incomment
3338 || (state
.instring
>= 0))
3339 ? make_number (state
.comstr_start
)
3341 Fcons (state
.levelstarts
, Qnil
))))))))));
3350 /* This has to be done here, before we call Fmake_char_table. */
3351 Qsyntax_table
= intern ("syntax-table");
3352 staticpro (&Qsyntax_table
);
3354 /* Intern this now in case it isn't already done.
3355 Setting this variable twice is harmless.
3356 But don't staticpro it here--that is done in alloc.c. */
3357 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3359 /* Create objects which can be shared among syntax tables. */
3360 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3361 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3362 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3363 = Fcons (make_number (i
), Qnil
);
3365 /* Now we are ready to set up this property, so we can
3366 create syntax tables. */
3367 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3369 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3371 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3373 /* Control characters should not be whitespace. */
3374 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3375 for (i
= 0; i
<= ' ' - 1; i
++)
3376 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3377 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 0177, temp
);
3379 /* Except that a few really are whitespace. */
3380 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3381 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ' ', temp
);
3382 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\t', temp
);
3383 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\n', temp
);
3384 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 015, temp
);
3385 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 014, temp
);
3387 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3388 for (i
= 'a'; i
<= 'z'; i
++)
3389 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3390 for (i
= 'A'; i
<= 'Z'; i
++)
3391 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3392 for (i
= '0'; i
<= '9'; i
++)
3393 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3395 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3396 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3398 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3399 Fcons (make_number (Sopen
), make_number (')')));
3400 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3401 Fcons (make_number (Sclose
), make_number ('(')));
3402 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3403 Fcons (make_number (Sopen
), make_number (']')));
3404 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3405 Fcons (make_number (Sclose
), make_number ('[')));
3406 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3407 Fcons (make_number (Sopen
), make_number ('}')));
3408 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3409 Fcons (make_number (Sclose
), make_number ('{')));
3410 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3411 Fcons (make_number ((int) Sstring
), Qnil
));
3412 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3413 Fcons (make_number ((int) Sescape
), Qnil
));
3415 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3416 for (i
= 0; i
< 10; i
++)
3418 c
= "_-+*/&|<>="[i
];
3419 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3422 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3423 for (i
= 0; i
< 12; i
++)
3425 c
= ".,;:?!#@~^'`"[i
];
3426 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3429 /* All multibyte characters have syntax `word' by default. */
3430 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3431 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3437 Qsyntax_table_p
= intern ("syntax-table-p");
3438 staticpro (&Qsyntax_table_p
);
3440 staticpro (&Vsyntax_code_object
);
3442 staticpro (&gl_state
.object
);
3443 staticpro (&gl_state
.global_code
);
3444 staticpro (&gl_state
.current_syntax_table
);
3445 staticpro (&gl_state
.old_prop
);
3447 /* Defined in regex.c */
3448 staticpro (&re_match_object
);
3450 Qscan_error
= intern ("scan-error");
3451 staticpro (&Qscan_error
);
3452 Fput (Qscan_error
, Qerror_conditions
,
3453 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3454 Fput (Qscan_error
, Qerror_message
,
3455 build_string ("Scan error"));
3457 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3458 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3460 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3461 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3462 Otherwise, that text property is simply ignored.
3463 See the info node `(elisp)Syntax Properties' for a description of the
3464 `syntax-table' property. */);
3466 words_include_escapes
= 0;
3467 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3468 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3470 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3471 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3472 multibyte_syntax_as_symbol
= 0;
3474 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3475 &open_paren_in_column_0_is_defun_start
,
3476 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3477 open_paren_in_column_0_is_defun_start
= 1;
3480 DEFVAR_LISP ("find-word-boundary-function-table",
3481 &Vfind_word_boundary_function_table
,
3483 Char table of functions to search for the word boundary.
3484 Each function is called with two arguments; POS and LIMIT.
3485 POS and LIMIT are character positions in the current buffer.
3487 If POS is less than LIMIT, POS is at the first character of a word,
3488 and the return value of a function is a position after the last
3489 character of that word.
3491 If POS is not less than LIMIT, POS is at the last character of a word,
3492 and the return value of a function is a position at the first
3493 character of that word.
3495 In both cases, LIMIT bounds the search. */);
3496 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3498 defsubr (&Ssyntax_table_p
);
3499 defsubr (&Ssyntax_table
);
3500 defsubr (&Sstandard_syntax_table
);
3501 defsubr (&Scopy_syntax_table
);
3502 defsubr (&Sset_syntax_table
);
3503 defsubr (&Schar_syntax
);
3504 defsubr (&Smatching_paren
);
3505 defsubr (&Sstring_to_syntax
);
3506 defsubr (&Smodify_syntax_entry
);
3507 defsubr (&Sinternal_describe_syntax_value
);
3509 defsubr (&Sforward_word
);
3511 defsubr (&Sskip_chars_forward
);
3512 defsubr (&Sskip_chars_backward
);
3513 defsubr (&Sskip_syntax_forward
);
3514 defsubr (&Sskip_syntax_backward
);
3516 defsubr (&Sforward_comment
);
3517 defsubr (&Sscan_lists
);
3518 defsubr (&Sscan_sexps
);
3519 defsubr (&Sbackward_prefix_chars
);
3520 defsubr (&Sparse_partial_sexp
);
3523 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
3524 (do not change this comment) */