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, 2002,
3 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
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;
302 DEC_BOTH (charpos
, bytepos
);
304 while (charpos
>= beg
)
308 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
309 c
= FETCH_CHAR_AS_MULTIBYTE (bytepos
);
311 if (! (code
== Scharquote
|| code
== Sescape
))
314 DEC_BOTH (charpos
, bytepos
);
318 UPDATE_SYNTAX_TABLE (orig
);
322 /* Return the bytepos one character after BYTEPOS.
323 We assume that BYTEPOS is not at the end of the buffer. */
326 inc_bytepos (bytepos
)
329 if (NILP (current_buffer
->enable_multibyte_characters
))
336 /* Return the bytepos one character before BYTEPOS.
337 We assume that BYTEPOS is not at the start of the buffer. */
340 dec_bytepos (bytepos
)
343 if (NILP (current_buffer
->enable_multibyte_characters
))
350 /* Return a defun-start position before before POS and not too far before.
351 It should be the last one before POS, or nearly the last.
353 When open_paren_in_column_0_is_defun_start is nonzero,
354 only the beginning of the buffer is treated as a defun-start.
356 We record the information about where the scan started
357 and what its result was, so that another call in the same area
358 can return the same value very quickly.
360 There is no promise at which position the global syntax data is
361 valid on return from the subroutine, so the caller should explicitly
362 update the global data. */
365 find_defun_start (pos
, pos_byte
)
368 int opoint
= PT
, opoint_byte
= PT_BYTE
;
370 if (!open_paren_in_column_0_is_defun_start
)
372 find_start_value_byte
= BEGV_BYTE
;
376 /* Use previous finding, if it's valid and applies to this inquiry. */
377 if (current_buffer
== find_start_buffer
378 /* Reuse the defun-start even if POS is a little farther on.
379 POS might be in the next defun, but that's ok.
380 Our value may not be the best possible, but will still be usable. */
381 && pos
<= find_start_pos
+ 1000
382 && pos
>= find_start_value
383 && BEGV
== find_start_begv
384 && MODIFF
== find_start_modiff
)
385 return find_start_value
;
387 /* Back up to start of line. */
388 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
390 /* We optimize syntax-table lookup for rare updates. Thus we accept
391 only those `^\s(' which are good in global _and_ text-property
393 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
394 gl_state
.use_global
= 0;
399 /* Open-paren at start of line means we may have found our
401 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
402 if (SYNTAX (c
) == Sopen
)
404 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
405 c
= FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
);
406 if (SYNTAX (c
) == Sopen
)
408 /* Now fallback to the default value. */
409 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
410 gl_state
.use_global
= 0;
412 /* Move to beg of previous line. */
413 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
416 /* Record what we found, for the next try. */
417 find_start_value
= PT
;
418 find_start_value_byte
= PT_BYTE
;
419 find_start_buffer
= current_buffer
;
420 find_start_modiff
= MODIFF
;
421 find_start_begv
= BEGV
;
422 find_start_pos
= pos
;
424 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
426 return find_start_value
;
429 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
432 prev_char_comend_first (pos
, pos_byte
)
437 DEC_BOTH (pos
, pos_byte
);
438 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
439 c
= FETCH_CHAR (pos_byte
);
440 val
= SYNTAX_COMEND_FIRST (c
);
441 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
445 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
448 * prev_char_comstart_first (pos, pos_byte)
453 * DEC_BOTH (pos, pos_byte);
454 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
455 * c = FETCH_CHAR (pos_byte);
456 * val = SYNTAX_COMSTART_FIRST (c);
457 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
461 /* Checks whether charpos FROM is at the end of a comment.
462 FROM_BYTE is the bytepos corresponding to FROM.
463 Do not move back before STOP.
465 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
468 If successful, store the charpos of the comment's beginning
469 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
471 Global syntax data remains valid for backward search starting at
472 the returned value (or at FROM, if the search was not successful). */
475 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
476 EMACS_INT from
, from_byte
, stop
;
477 int comnested
, comstyle
;
478 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
480 /* Look back, counting the parity of string-quotes,
481 and recording the comment-starters seen.
482 When we reach a safe place, assume that's not in a string;
483 then step the main scan to the earliest comment-starter seen
484 an even number of string quotes away from the safe place.
486 OFROM[I] is position of the earliest comment-starter seen
487 which is I+2X quotes from the comment-end.
488 PARITY is current parity of quotes from the comment end. */
489 int string_style
= -1; /* Presumed outside of any string. */
490 int string_lossage
= 0;
491 /* Not a real lossage: indicates that we have passed a matching comment
492 starter plus a non-matching comment-ender, meaning that any matching
493 comment-starter we might see later could be a false positive (hidden
494 inside another comment).
495 Test case: { a (* b } c (* d *) */
496 int comment_lossage
= 0;
497 int comment_end
= from
;
498 int comment_end_byte
= from_byte
;
499 int comstart_pos
= 0;
501 /* Place where the containing defun starts,
502 or 0 if we didn't come across it yet. */
504 int defun_start_byte
= 0;
505 register enum syntaxcode code
;
506 int nesting
= 1; /* current comment nesting */
510 /* FIXME: A }} comment-ender style leads to incorrect behavior
511 in the case of {{ c }}} because we ignore the last two chars which are
512 assumed to be comment-enders although they aren't. */
514 /* At beginning of range to scan, we're outside of strings;
515 that determines quote parity to the comment-end. */
518 int temp_byte
, prev_syntax
;
519 int com2start
, com2end
;
521 /* Move back and examine a character. */
522 DEC_BOTH (from
, from_byte
);
523 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
525 prev_syntax
= syntax
;
526 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
527 syntax
= SYNTAX_WITH_FLAGS (c
);
530 /* Check for 2-char comment markers. */
531 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
532 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
533 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
534 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
535 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
536 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
537 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
539 /* Nasty cases with overlapping 2-char comment markers:
540 - snmp-mode: -- c -- foo -- c --
548 /* If a 2-char comment sequence partly overlaps with another,
549 we don't try to be clever. */
550 if (from
> stop
&& (com2end
|| com2start
))
552 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
553 DEC_BOTH (next
, next_byte
);
554 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
555 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
556 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
557 if (((com2start
|| comnested
)
558 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
559 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
560 || ((com2end
|| comnested
)
561 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
562 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
563 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
565 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
568 if (com2start
&& comstart_pos
== 0)
569 /* We're looking at a comment starter. But it might be a comment
570 ender as well (see snmp-mode). The first time we see one, we
571 need to consider it as a comment starter,
572 and the subsequent times as a comment ender. */
575 /* Turn a 2-char comment sequences into the appropriate syntax. */
580 /* Ignore comment starters of a different style. */
581 else if (code
== Scomment
582 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
583 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
586 /* Ignore escaped characters, except comment-enders. */
587 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
594 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
596 /* Track parity of quotes. */
597 if (string_style
== -1)
598 /* Entering a string. */
600 else if (string_style
== c
)
601 /* Leaving the string. */
604 /* If we have two kinds of string delimiters.
605 There's no way to grok this scanning backwards. */
610 /* We've already checked that it is the relevant comstyle. */
611 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
612 /* There are odd string quotes involved, so let's be careful.
613 Test case in Pascal: " { " a { " } */
618 /* Record best comment-starter so far. */
620 comstart_byte
= from_byte
;
622 else if (--nesting
<= 0)
623 /* nested comments have to be balanced, so we don't need to
624 keep looking for earlier ones. We use here the same (slightly
625 incorrect) reasoning as below: since it is followed by uniform
626 paired string quotes, this comment-start has to be outside of
627 strings, else the comment-end itself would be inside a string. */
632 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
633 && ((com2end
&& SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
))
634 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
635 /* This is the same style of comment ender as ours. */
640 /* Anything before that can't count because it would match
641 this comment-ender rather than ours. */
642 from
= stop
; /* Break out of the loop. */
644 else if (comstart_pos
!= 0 || c
!= '\n')
645 /* We're mixing comment styles here, so we'd better be careful.
646 The (comstart_pos != 0 || c != '\n') check is not quite correct
647 (we should just always set comment_lossage), but removing it
648 would imply that any multiline comment in C would go through
649 lossage, which seems overkill.
650 The failure should only happen in the rare cases such as
656 /* Assume a defun-start point is outside of strings. */
657 if (open_paren_in_column_0_is_defun_start
659 || (temp_byte
= dec_bytepos (from_byte
),
660 FETCH_CHAR (temp_byte
) == '\n')))
663 defun_start_byte
= from_byte
;
664 from
= stop
; /* Break out of the loop. */
673 if (comstart_pos
== 0)
676 from_byte
= comment_end_byte
;
677 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
679 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
680 or `done'), then we've found the beginning of the non-nested comment. */
681 else if (1) /* !comnested */
684 from_byte
= comstart_byte
;
685 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
689 struct lisp_parse_state state
;
691 /* We had two kinds of string delimiters mixed up
692 together. Decode this going forwards.
693 Scan fwd from a known safe place (beginning-of-defun)
694 to the one in question; this records where we
695 last passed a comment starter. */
696 /* If we did not already find the defun start, find it now. */
697 if (defun_start
== 0)
699 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
700 defun_start_byte
= find_start_value_byte
;
704 scan_sexps_forward (&state
,
705 defun_start
, defun_start_byte
,
706 comment_end
, -10000, 0, Qnil
, 0);
707 defun_start
= comment_end
;
708 if (state
.incomment
== (comnested
? 1 : -1)
709 && state
.comstyle
== comstyle
)
710 from
= state
.comstr_start
;
715 /* If comment_end is inside some other comment, maybe ours
716 is nested, so we need to try again from within the
717 surrounding comment. Example: { a (* " *) */
719 /* FIXME: We should advance by one or two chars. */
720 defun_start
= state
.comstr_start
+ 2;
721 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
724 } while (defun_start
< comment_end
);
726 from_byte
= CHAR_TO_BYTE (from
);
727 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
732 *bytepos_ptr
= from_byte
;
734 return (from
== comment_end
) ? -1 : from
;
737 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
738 doc
: /* Return t if OBJECT is a syntax table.
739 Currently, any char-table counts as a syntax table. */)
743 if (CHAR_TABLE_P (object
)
744 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
750 check_syntax_table (obj
)
753 CHECK_TYPE (CHAR_TABLE_P (obj
) && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
),
754 Qsyntax_table_p
, obj
);
757 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
758 doc
: /* Return the current syntax table.
759 This is the one specified by the current buffer. */)
762 return current_buffer
->syntax_table
;
765 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
766 Sstandard_syntax_table
, 0, 0, 0,
767 doc
: /* Return the standard syntax table.
768 This is the one used for new buffers. */)
771 return Vstandard_syntax_table
;
774 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
775 doc
: /* Construct a new syntax table and return it.
776 It is a copy of the TABLE, which defaults to the standard syntax table. */)
783 check_syntax_table (table
);
785 table
= Vstandard_syntax_table
;
787 copy
= Fcopy_sequence (table
);
789 /* Only the standard syntax table should have a default element.
790 Other syntax tables should inherit from parents instead. */
791 XCHAR_TABLE (copy
)->defalt
= Qnil
;
793 /* Copied syntax tables should all have parents.
794 If we copied one with no parent, such as the standard syntax table,
795 use the standard syntax table as the copy's parent. */
796 if (NILP (XCHAR_TABLE (copy
)->parent
))
797 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
801 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
802 doc
: /* Select a new syntax table for the current buffer.
803 One argument, a syntax table. */)
808 check_syntax_table (table
);
809 current_buffer
->syntax_table
= table
;
810 /* Indicate that this buffer now has a specified syntax table. */
811 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
812 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
816 /* Convert a letter which signifies a syntax code
817 into the code it signifies.
818 This is used by modify-syntax-entry, and other things. */
820 unsigned char syntax_spec_code
[0400] =
821 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
822 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
823 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
824 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
825 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
826 (char) Smath
, 0377, 0377, (char) Squote
,
827 (char) Sopen
, (char) Sclose
, 0377, 0377,
828 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
829 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
830 0377, 0377, 0377, 0377,
831 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
832 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
833 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
834 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
835 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
836 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
837 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
838 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
839 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
842 /* Indexed by syntax code, give the letter that describes it. */
844 char syntax_code_spec
[16] =
846 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
850 /* Indexed by syntax code, give the object (cons of syntax code and
851 nil) to be stored in syntax table. Since these objects can be
852 shared among syntax tables, we generate them in advance. By
853 sharing objects, the function `describe-syntax' can give a more
855 static Lisp_Object Vsyntax_code_object
;
858 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
859 doc
: /* Return the syntax code of CHARACTER, described by a character.
860 For example, if CHARACTER is a word constituent,
861 the character `w' is returned.
862 The characters that correspond to various syntax codes
863 are listed in the documentation of `modify-syntax-entry'. */)
865 Lisp_Object character
;
868 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
870 gl_state
.use_global
= 0;
871 CHECK_NUMBER (character
);
872 char_int
= XINT (character
);
873 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
876 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
877 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
879 Lisp_Object character
;
882 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
883 gl_state
.use_global
= 0;
884 CHECK_NUMBER (character
);
885 char_int
= XINT (character
);
886 code
= SYNTAX (char_int
);
887 if (code
== Sopen
|| code
== Sclose
)
888 return SYNTAX_MATCH (char_int
);
892 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
893 doc
: /* Convert a syntax specification STRING into syntax cell form.
894 STRING should be a string as it is allowed as argument of
895 `modify-syntax-entry'. Value is the equivalent cons cell
896 (CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
901 register const unsigned char *p
;
902 register enum syntaxcode code
;
906 CHECK_STRING (string
);
909 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
910 if (((int) code
& 0377) == 0377)
911 error ("Invalid syntax description letter: %c", p
[-1]);
913 if (code
== Sinherit
)
919 int character
= (STRING_CHAR_AND_LENGTH
920 (p
, SBYTES (string
) - 1, len
));
921 XSETINT (match
, character
);
922 if (XFASTINT (match
) == ' ')
962 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
963 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
965 /* Since we can't use a shared object, let's make a new one. */
966 return Fcons (make_number (val
), match
);
969 /* I really don't know why this is interactive
970 help-form should at least be made useful whilst reading the second arg. */
971 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
972 "cSet syntax for character: \nsSet syntax for %s to: ",
973 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
974 The syntax is changed only for table SYNTAX-TABLE, which defaults to
975 the current buffer's syntax table.
976 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
977 in the range MIN and MAX are changed.
978 The first character of NEWENTRY should be one of the following:
979 Space or - whitespace syntax. w word constituent.
980 _ symbol constituent. . punctuation.
981 ( open-parenthesis. ) close-parenthesis.
982 " string quote. \\ escape.
983 $ paired delimiter. ' expression quote or prefix operator.
984 < comment starter. > comment ender.
985 / character-quote. @ inherit from `standard-syntax-table'.
986 | generic string fence. ! generic comment fence.
988 Only single-character comment start and end sequences are represented thus.
989 Two-character sequences are represented as described below.
990 The second character of NEWENTRY is the matching parenthesis,
991 used only if the first character is `(' or `)'.
992 Any additional characters are flags.
993 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
994 1 means CHAR is the start of a two-char comment start sequence.
995 2 means CHAR is the second character of such a sequence.
996 3 means CHAR is the start of a two-char comment end sequence.
997 4 means CHAR is the second character of such a sequence.
999 There can be up to two orthogonal comment sequences. This is to support
1000 language modes such as C++. By default, all comment sequences are of style
1001 a, but you can set the comment sequence style to b (on the second character
1002 of a comment-start, or the first character of a comment-end sequence) using
1004 b means CHAR is part of comment sequence b.
1005 n means CHAR is part of a nestable comment sequence.
1007 p means CHAR is a prefix character for `backward-prefix-chars';
1008 such characters are treated as whitespace when they occur
1009 between expressions.
1010 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1011 (c
, newentry
, syntax_table
)
1012 Lisp_Object c
, newentry
, syntax_table
;
1016 CHECK_CHARACTER_CAR (c
);
1017 CHECK_CHARACTER_CDR (c
);
1020 CHECK_CHARACTER (c
);
1022 if (NILP (syntax_table
))
1023 syntax_table
= current_buffer
->syntax_table
;
1025 check_syntax_table (syntax_table
);
1027 newentry
= Fstring_to_syntax (newentry
);
1029 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1031 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1035 /* Dump syntax table to buffer in human-readable format */
1037 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1038 Sinternal_describe_syntax_value
, 1, 1, 0,
1039 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1043 register enum syntaxcode code
;
1044 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1046 Lisp_Object first
, match_lisp
, value
= syntax
;
1050 insert_string ("default");
1054 if (CHAR_TABLE_P (value
))
1056 insert_string ("deeper char-table ...");
1062 insert_string ("invalid");
1066 first
= XCAR (value
);
1067 match_lisp
= XCDR (value
);
1069 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1071 insert_string ("invalid");
1075 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1076 start1
= (XINT (first
) >> 16) & 1;
1077 start2
= (XINT (first
) >> 17) & 1;
1078 end1
= (XINT (first
) >> 18) & 1;
1079 end2
= (XINT (first
) >> 19) & 1;
1080 prefix
= (XINT (first
) >> 20) & 1;
1081 comstyle
= (XINT (first
) >> 21) & 1;
1082 comnested
= (XINT (first
) >> 22) & 1;
1084 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1086 insert_string ("invalid");
1089 desc
= syntax_code_spec
[(int) code
];
1091 str
[0] = desc
, str
[1] = 0;
1094 if (NILP (match_lisp
))
1097 insert_char (XINT (match_lisp
));
1116 insert_string ("\twhich means: ");
1118 switch (SWITCH_ENUM_CAST (code
))
1121 insert_string ("whitespace"); break;
1123 insert_string ("punctuation"); break;
1125 insert_string ("word"); break;
1127 insert_string ("symbol"); break;
1129 insert_string ("open"); break;
1131 insert_string ("close"); break;
1133 insert_string ("prefix"); break;
1135 insert_string ("string"); break;
1137 insert_string ("math"); break;
1139 insert_string ("escape"); break;
1141 insert_string ("charquote"); break;
1143 insert_string ("comment"); break;
1145 insert_string ("endcomment"); break;
1147 insert_string ("inherit"); break;
1148 case Scomment_fence
:
1149 insert_string ("comment fence"); break;
1151 insert_string ("string fence"); break;
1153 insert_string ("invalid");
1157 if (!NILP (match_lisp
))
1159 insert_string (", matches ");
1160 insert_char (XINT (match_lisp
));
1164 insert_string (",\n\t is the first character of a comment-start sequence");
1166 insert_string (",\n\t is the second character of a comment-start sequence");
1169 insert_string (",\n\t is the first character of a comment-end sequence");
1171 insert_string (",\n\t is the second character of a comment-end sequence");
1173 insert_string (" (comment style b)");
1175 insert_string (" (nestable)");
1178 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1183 int parse_sexp_ignore_comments
;
1185 /* Char-table of functions that find the next or previous word
1187 Lisp_Object Vfind_word_boundary_function_table
;
1189 /* Return the position across COUNT words from FROM.
1190 If that many words cannot be found before the end of the buffer, return 0.
1191 COUNT negative means scan backward and stop at word beginning. */
1194 scan_words (from
, count
)
1195 register int from
, count
;
1197 register int beg
= BEGV
;
1198 register int end
= ZV
;
1199 register int from_byte
= CHAR_TO_BYTE (from
);
1200 register enum syntaxcode code
;
1202 Lisp_Object func
, script
, pos
;
1207 SETUP_SYNTAX_TABLE (from
, count
);
1218 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1219 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1220 code
= SYNTAX (ch0
);
1221 INC_BOTH (from
, from_byte
);
1222 if (words_include_escapes
1223 && (code
== Sescape
|| code
== Scharquote
))
1228 /* Now CH0 is a character which begins a word and FROM is the
1229 position of the next character. */
1230 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch0
);
1231 if (! NILP (Ffboundp (func
)))
1233 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1234 if (INTEGERP (pos
) && XINT (pos
) > from
)
1237 from_byte
= CHAR_TO_BYTE (from
);
1242 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1245 if (from
== end
) break;
1246 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1247 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1248 code
= SYNTAX (ch1
);
1250 && (! words_include_escapes
1251 || (code
!= Sescape
&& code
!= Scharquote
)))
1252 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch1
), script
))
1254 INC_BOTH (from
, from_byte
);
1269 DEC_BOTH (from
, from_byte
);
1270 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1271 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1272 code
= SYNTAX (ch1
);
1273 if (words_include_escapes
1274 && (code
== Sescape
|| code
== Scharquote
))
1279 /* Now CH1 is a character which ends a word and FROM is the
1281 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch1
);
1282 if (! NILP (Ffboundp (func
)))
1284 pos
= call2 (func
, make_number (from
), make_number (beg
));
1285 if (INTEGERP (pos
) && XINT (pos
) < from
)
1288 from_byte
= CHAR_TO_BYTE (from
);
1293 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1300 temp_byte
= dec_bytepos (from_byte
);
1301 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1302 ch0
= FETCH_CHAR_AS_MULTIBYTE (temp_byte
);
1303 code
= SYNTAX (ch0
);
1305 && (! words_include_escapes
1306 || (code
!= Sescape
&& code
!= Scharquote
)))
1307 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch0
), script
))
1309 DEC_BOTH (from
, from_byte
);
1321 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 0, 1, "p",
1322 doc
: /* Move point forward ARG words (backward if ARG is negative).
1324 If an edge of the buffer or a field boundary is reached, point is left there
1325 and the function returns nil. Field boundaries are not noticed if
1326 `inhibit-field-text-motion' is non-nil. */)
1334 XSETFASTINT (arg
, 1);
1338 val
= orig_val
= scan_words (PT
, XINT (arg
));
1340 val
= XINT (arg
) > 0 ? ZV
: BEGV
;
1342 /* Avoid jumping out of an input field. */
1343 tmp
= Fconstrain_to_field (make_number (val
), make_number (PT
),
1345 val
= XFASTINT (tmp
);
1348 return val
== orig_val
? Qt
: Qnil
;
1351 Lisp_Object
skip_chars ();
1353 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1354 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1355 STRING is like the inside of a `[...]' in a regular expression
1356 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1357 (but not as the end of a range; quoting is never needed there).
1358 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1359 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1360 Char classes, e.g. `[:alpha:]', are supported.
1362 Returns the distance traveled, either zero or positive. */)
1364 Lisp_Object string
, lim
;
1366 return skip_chars (1, string
, lim
, 1);
1369 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1370 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1371 See `skip-chars-forward' for details.
1372 Returns the distance traveled, either zero or negative. */)
1374 Lisp_Object string
, lim
;
1376 return skip_chars (0, string
, lim
, 1);
1379 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1380 doc
: /* Move point forward across chars in specified syntax classes.
1381 SYNTAX is a string of syntax code characters.
1382 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1383 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1384 This function returns the distance traveled, either zero or positive. */)
1386 Lisp_Object syntax
, lim
;
1388 return skip_syntaxes (1, syntax
, lim
);
1391 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1392 doc
: /* Move point backward across chars in specified syntax classes.
1393 SYNTAX is a string of syntax code characters.
1394 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1395 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1396 This function returns the distance traveled, either zero or negative. */)
1398 Lisp_Object syntax
, lim
;
1400 return skip_syntaxes (0, syntax
, lim
);
1404 skip_chars (forwardp
, string
, lim
, handle_iso_classes
)
1406 Lisp_Object string
, lim
;
1407 int handle_iso_classes
;
1409 register unsigned int c
;
1410 unsigned char fastmap
[0400];
1411 /* Store the ranges of non-ASCII characters. */
1413 int n_char_ranges
= 0;
1415 register int i
, i_byte
;
1416 /* Set to 1 if the current buffer is multibyte and the region
1417 contains non-ASCII chars. */
1419 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1421 int string_multibyte
;
1423 const unsigned char *str
;
1425 Lisp_Object iso_classes
;
1427 CHECK_STRING (string
);
1431 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1433 CHECK_NUMBER_COERCE_MARKER (lim
);
1435 /* In any case, don't allow scan outside bounds of buffer. */
1436 if (XINT (lim
) > ZV
)
1437 XSETFASTINT (lim
, ZV
);
1438 if (XINT (lim
) < BEGV
)
1439 XSETFASTINT (lim
, BEGV
);
1441 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1442 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1443 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1445 bzero (fastmap
, sizeof fastmap
);
1447 str
= SDATA (string
);
1448 size_byte
= SBYTES (string
);
1451 if (i_byte
< size_byte
1452 && SREF (string
, 0) == '^')
1454 negate
= 1; i_byte
++;
1457 /* Find the characters specified and set their elements of fastmap.
1458 Handle backslashes and ranges specially.
1460 If STRING contains non-ASCII characters, setup char_ranges for
1461 them and use fastmap only for their leading codes. */
1463 if (! string_multibyte
)
1465 int string_has_eight_bit
= 0;
1467 /* At first setup fastmap. */
1468 while (i_byte
< size_byte
)
1472 if (handle_iso_classes
&& c
== '['
1473 && i_byte
< size_byte
1474 && str
[i_byte
] == ':')
1476 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1477 const unsigned char *class_end
= class_beg
;
1478 const unsigned char *class_limit
= str
+ size_byte
- 2;
1479 /* Leave room for the null. */
1480 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1483 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1484 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1486 while (class_end
< class_limit
1487 && *class_end
>= 'a' && *class_end
<= 'z')
1490 if (class_end
== class_beg
1491 || *class_end
!= ':' || class_end
[1] != ']')
1492 goto not_a_class_name
;
1494 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1495 class_name
[class_end
- class_beg
] = 0;
1497 cc
= re_wctype (class_name
);
1499 error ("Invalid ISO C character class");
1501 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1503 i_byte
= class_end
+ 2 - str
;
1510 if (i_byte
== size_byte
)
1515 /* Treat `-' as range character only if another character
1517 if (i_byte
+ 1 < size_byte
1518 && str
[i_byte
] == '-')
1522 /* Skip over the dash. */
1525 /* Get the end of the range. */
1528 && i_byte
< size_byte
)
1535 if (! ASCII_CHAR_P (c2
))
1536 string_has_eight_bit
= 1;
1542 if (! ASCII_CHAR_P (c
))
1543 string_has_eight_bit
= 1;
1547 /* If the current range is multibyte and STRING contains
1548 eight-bit chars, arrange fastmap and setup char_ranges for
1549 the corresponding multibyte chars. */
1550 if (multibyte
&& string_has_eight_bit
)
1552 unsigned char fastmap2
[0400];
1553 int range_start_byte
, range_start_char
;
1555 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1556 bzero (fastmap
+ 0200, 0200);
1557 /* We are sure that this loop stops. */
1558 for (i
= 0200; ! fastmap2
[i
]; i
++);
1559 c
= unibyte_char_to_multibyte (i
);
1560 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1561 range_start_byte
= i
;
1562 range_start_char
= c
;
1563 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1564 for (i
= 129; i
< 0400; i
++)
1566 c
= unibyte_char_to_multibyte (i
);
1567 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1568 if (i
- range_start_byte
!= c
- range_start_char
)
1570 char_ranges
[n_char_ranges
++] = range_start_char
;
1571 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1572 + range_start_char
);
1573 range_start_byte
= i
;
1574 range_start_char
= c
;
1577 char_ranges
[n_char_ranges
++] = range_start_char
;
1578 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1579 + range_start_char
);
1582 else /* STRING is multibyte */
1584 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1586 while (i_byte
< size_byte
)
1588 unsigned char leading_code
;
1590 leading_code
= str
[i_byte
];
1591 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1594 if (handle_iso_classes
&& c
== '['
1595 && i_byte
< size_byte
1596 && STRING_CHAR (str
+ i_byte
, size_byte
- i_byte
) == ':')
1598 const unsigned char *class_beg
= str
+ i_byte
+ 1;
1599 const unsigned char *class_end
= class_beg
;
1600 const unsigned char *class_limit
= str
+ size_byte
- 2;
1601 /* Leave room for the null. */
1602 unsigned char class_name
[CHAR_CLASS_MAX_LENGTH
+ 1];
1605 if (class_limit
- class_beg
> CHAR_CLASS_MAX_LENGTH
)
1606 class_limit
= class_beg
+ CHAR_CLASS_MAX_LENGTH
;
1608 while (class_end
< class_limit
1609 && *class_end
>= 'a' && *class_end
<= 'z')
1612 if (class_end
== class_beg
1613 || *class_end
!= ':' || class_end
[1] != ']')
1614 goto not_a_class_name_multibyte
;
1616 bcopy (class_beg
, class_name
, class_end
- class_beg
);
1617 class_name
[class_end
- class_beg
] = 0;
1619 cc
= re_wctype (class_name
);
1621 error ("Invalid ISO C character class");
1623 iso_classes
= Fcons (make_number (cc
), iso_classes
);
1625 i_byte
= class_end
+ 2 - str
;
1629 not_a_class_name_multibyte
:
1632 if (i_byte
== size_byte
)
1635 leading_code
= str
[i_byte
];
1636 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1637 size_byte
- i_byte
, len
);
1640 /* Treat `-' as range character only if another character
1642 if (i_byte
+ 1 < size_byte
1643 && str
[i_byte
] == '-')
1646 unsigned char leading_code2
;
1648 /* Skip over the dash. */
1651 /* Get the end of the range. */
1652 leading_code2
= str
[i_byte
];
1653 c2
= STRING_CHAR_AND_LENGTH (str
+ i_byte
,
1654 size_byte
- i_byte
, len
);
1658 && i_byte
< size_byte
)
1660 leading_code2
= str
[i_byte
];
1661 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1667 if (ASCII_CHAR_P (c
))
1669 while (c
<= c2
&& c
< 0x80)
1671 leading_code
= CHAR_LEADING_CODE (c
);
1673 if (! ASCII_CHAR_P (c
))
1675 while (leading_code
<= leading_code2
)
1676 fastmap
[leading_code
++] = 1;
1679 char_ranges
[n_char_ranges
++] = c
;
1680 char_ranges
[n_char_ranges
++] = c2
;
1686 if (ASCII_CHAR_P (c
))
1690 fastmap
[leading_code
] = 1;
1691 char_ranges
[n_char_ranges
++] = c
;
1692 char_ranges
[n_char_ranges
++] = c
;
1697 /* If the current range is unibyte and STRING contains non-ASCII
1698 chars, arrange fastmap for the corresponding unibyte
1701 if (! multibyte
&& n_char_ranges
> 0)
1703 bzero (fastmap
+ 0200, 0200);
1704 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1706 int c1
= char_ranges
[i
];
1707 int c2
= char_ranges
[i
+ 1];
1709 for (; c1
<= c2
; c1
++)
1710 fastmap
[CHAR_TO_BYTE8 (c1
)] = 1;
1715 /* If ^ was the first character, complement the fastmap. */
1719 for (i
= 0; i
< sizeof fastmap
; i
++)
1723 for (i
= 0; i
< 0200; i
++)
1725 /* All non-ASCII chars possibly match. */
1726 for (; i
< sizeof fastmap
; i
++)
1732 int start_point
= PT
;
1734 int pos_byte
= PT_BYTE
;
1735 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1739 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1740 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1744 endp
= CHAR_POS_ADDR (XINT (lim
));
1745 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1763 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1764 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1774 if (! ASCII_CHAR_P (c
))
1776 /* As we are looking at a multibyte character, we
1777 must look up the character in the table
1778 CHAR_RANGES. If there's no data in the table,
1779 that character is not what we want to skip. */
1781 /* The following code do the right thing even if
1782 n_char_ranges is zero (i.e. no data in
1784 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1785 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1787 if (!(negate
^ (i
< n_char_ranges
)))
1791 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1804 if (!NILP (iso_classes
) && in_classes (*p
, iso_classes
))
1809 goto fwd_unibyte_ok
;
1815 p
++, pos
++, pos_byte
++;
1823 unsigned char *prev_p
;
1833 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1834 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1836 if (! NILP (iso_classes
) && in_classes (c
, iso_classes
))
1846 if (! ASCII_CHAR_P (c
))
1848 /* See the comment in the previous similar code. */
1849 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1850 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1852 if (!(negate
^ (i
< n_char_ranges
)))
1856 pos
--, pos_byte
-= prev_p
- p
;
1869 if (! NILP (iso_classes
) && in_classes (p
[-1], iso_classes
))
1874 goto back_unibyte_ok
;
1877 if (!fastmap
[p
[-1]])
1880 p
--, pos
--, pos_byte
--;
1884 SET_PT_BOTH (pos
, pos_byte
);
1887 return make_number (PT
- start_point
);
1893 skip_syntaxes (forwardp
, string
, lim
)
1895 Lisp_Object string
, lim
;
1897 register unsigned int c
;
1898 unsigned char fastmap
[0400];
1900 register int i
, i_byte
;
1905 CHECK_STRING (string
);
1908 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1910 CHECK_NUMBER_COERCE_MARKER (lim
);
1912 /* In any case, don't allow scan outside bounds of buffer. */
1913 if (XINT (lim
) > ZV
)
1914 XSETFASTINT (lim
, ZV
);
1915 if (XINT (lim
) < BEGV
)
1916 XSETFASTINT (lim
, BEGV
);
1918 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1919 return make_number (0);
1921 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1922 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1924 bzero (fastmap
, sizeof fastmap
);
1926 if (SBYTES (string
) > SCHARS (string
))
1927 /* As this is very rare case (syntax spec is ASCII only), don't
1928 consider efficiency. */
1929 string
= string_make_unibyte (string
);
1931 str
= SDATA (string
);
1932 size_byte
= SBYTES (string
);
1935 if (i_byte
< size_byte
1936 && SREF (string
, 0) == '^')
1938 negate
= 1; i_byte
++;
1941 /* Find the syntaxes specified and set their elements of fastmap. */
1943 while (i_byte
< size_byte
)
1946 fastmap
[syntax_spec_code
[c
]] = 1;
1949 /* If ^ was the first character, complement the fastmap. */
1951 for (i
= 0; i
< sizeof fastmap
; i
++)
1955 int start_point
= PT
;
1957 int pos_byte
= PT_BYTE
;
1958 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1962 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1963 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1967 endp
= CHAR_POS_ADDR (XINT (lim
));
1968 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1972 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1988 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1989 if (! fastmap
[(int) SYNTAX (c
)])
1991 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1992 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2006 if (! fastmap
[(int) SYNTAX (*p
)])
2008 p
++, pos
++, pos_byte
++;
2009 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
2019 unsigned char *prev_p
;
2029 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
2030 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
2031 if (! fastmap
[(int) SYNTAX (c
)])
2033 pos
--, pos_byte
-= prev_p
- p
;
2034 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
2048 if (! fastmap
[(int) SYNTAX (p
[-1])])
2050 p
--, pos
--, pos_byte
--;
2051 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
2056 SET_PT_BOTH (pos
, pos_byte
);
2059 return make_number (PT
- start_point
);
2063 /* Return 1 if character C belongs to one of the ISO classes
2064 in the list ISO_CLASSES. Each class is represented by an
2065 integer which is its type according to re_wctype. */
2068 in_classes (c
, iso_classes
)
2070 Lisp_Object iso_classes
;
2074 while (! NILP (iso_classes
))
2077 elt
= XCAR (iso_classes
);
2078 iso_classes
= XCDR (iso_classes
);
2080 if (re_iswctype (c
, XFASTINT (elt
)))
2087 /* Jump over a comment, assuming we are at the beginning of one.
2088 FROM is the current position.
2089 FROM_BYTE is the bytepos corresponding to FROM.
2090 Do not move past STOP (a charpos).
2091 The comment over which we have to jump is of style STYLE
2092 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
2093 NESTING should be positive to indicate the nesting at the beginning
2094 for nested comments and should be zero or negative else.
2095 ST_COMMENT_STYLE cannot be nested.
2096 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
2097 (or 0 If the search cannot start in the middle of a two-character).
2099 If successful, return 1 and store the charpos of the comment's end
2100 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
2101 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
2102 corresponding bytepos into *BYTEPOS_PTR and the current nesting
2103 (as defined for state.incomment) in *INCOMMENT_PTR.
2105 The comment end is the last character of the comment rather than the
2106 character just after the comment.
2108 Global syntax data is assumed to initially be valid for FROM and
2109 remains valid for forward search starting at the returned position. */
2112 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
2113 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
2114 EMACS_INT from
, from_byte
, stop
;
2115 int nesting
, style
, prev_syntax
;
2116 EMACS_INT
*charpos_ptr
, *bytepos_ptr
;
2120 register enum syntaxcode code
;
2121 register int syntax
;
2123 if (nesting
<= 0) nesting
= -1;
2125 /* Enter the loop in the middle so that we find
2126 a 2-char comment ender if we start in the middle of it. */
2127 syntax
= prev_syntax
;
2128 if (syntax
!= 0) goto forw_incomment
;
2134 *incomment_ptr
= nesting
;
2135 *charpos_ptr
= from
;
2136 *bytepos_ptr
= from_byte
;
2139 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2140 syntax
= SYNTAX_WITH_FLAGS (c
);
2141 code
= syntax
& 0xff;
2142 if (code
== Sendcomment
2143 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2144 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
2145 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
2146 /* we have encountered a comment end of the same style
2147 as the comment sequence which began this comment
2150 if (code
== Scomment_fence
2151 && style
== ST_COMMENT_STYLE
)
2152 /* we have encountered a comment end of the same style
2153 as the comment sequence which began this comment
2158 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
2159 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
2160 /* we have encountered a nested comment of the same style
2161 as the comment sequence which began this comment section */
2163 INC_BOTH (from
, from_byte
);
2164 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2167 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2168 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2169 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2170 SYNTAX_COMEND_SECOND (c1
))
2171 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2172 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2175 /* we have encountered a comment end of the same style
2176 as the comment sequence which began this comment
2181 INC_BOTH (from
, from_byte
);
2182 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2187 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2188 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2189 SYNTAX_COMMENT_STYLE (c1
) == style
2190 && SYNTAX_COMSTART_SECOND (c1
))
2191 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2192 SYNTAX_COMMENT_NESTED (c1
)))
2193 /* we have encountered a nested comment of the same style
2194 as the comment sequence which began this comment
2197 INC_BOTH (from
, from_byte
);
2198 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2202 *charpos_ptr
= from
;
2203 *bytepos_ptr
= from_byte
;
2207 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2209 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2210 Stop scanning if we find something other than a comment or whitespace.
2211 Set point to where scanning stops.
2212 If COUNT comments are found as expected, with nothing except whitespace
2213 between them, return t; otherwise return nil. */)
2217 register EMACS_INT from
;
2218 EMACS_INT from_byte
;
2219 register EMACS_INT stop
;
2221 register enum syntaxcode code
;
2222 int comstyle
= 0; /* style of comment encountered */
2223 int comnested
= 0; /* whether the comment is nestable or not */
2226 EMACS_INT out_charpos
, out_bytepos
;
2229 CHECK_NUMBER (count
);
2230 count1
= XINT (count
);
2231 stop
= count1
> 0 ? ZV
: BEGV
;
2237 from_byte
= PT_BYTE
;
2239 SETUP_SYNTAX_TABLE (from
, count1
);
2248 SET_PT_BOTH (from
, from_byte
);
2252 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2254 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2255 comnested
= SYNTAX_COMMENT_NESTED (c
);
2256 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2257 INC_BOTH (from
, from_byte
);
2258 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2259 if (from
< stop
&& comstart_first
2260 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2261 SYNTAX_COMSTART_SECOND (c1
)))
2263 /* We have encountered a comment start sequence and we
2264 are ignoring all text inside comments. We must record
2265 the comment style this sequence begins so that later,
2266 only a comment end of the same style actually ends
2267 the comment section. */
2269 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2270 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2271 INC_BOTH (from
, from_byte
);
2272 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2275 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2277 if (code
== Scomment_fence
)
2278 comstyle
= ST_COMMENT_STYLE
;
2279 else if (code
!= Scomment
)
2282 DEC_BOTH (from
, from_byte
);
2283 SET_PT_BOTH (from
, from_byte
);
2286 /* We're at the start of a comment. */
2287 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2288 &out_charpos
, &out_bytepos
, &dummy
);
2289 from
= out_charpos
; from_byte
= out_bytepos
;
2293 SET_PT_BOTH (from
, from_byte
);
2296 INC_BOTH (from
, from_byte
);
2297 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2298 /* We have skipped one comment. */
2310 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2315 DEC_BOTH (from
, from_byte
);
2316 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2317 quoted
= char_quoted (from
, from_byte
);
2318 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2321 comnested
= SYNTAX_COMMENT_NESTED (c
);
2322 if (code
== Sendcomment
)
2323 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2324 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2325 && prev_char_comend_first (from
, from_byte
)
2326 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2328 /* We must record the comment style encountered so that
2329 later, we can match only the proper comment begin
2330 sequence of the same style. */
2331 DEC_BOTH (from
, from_byte
);
2333 /* Calling char_quoted, above, set up global syntax position
2334 at the new value of FROM. */
2335 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2336 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2337 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2340 if (code
== Scomment_fence
)
2342 /* Skip until first preceding unquoted comment_fence. */
2343 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2347 DEC_BOTH (from
, from_byte
);
2348 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2349 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2350 if (SYNTAX (c
) == Scomment_fence
2351 && !char_quoted (from
, from_byte
))
2356 else if (from
== stop
)
2361 from
= ini
; /* Set point to ini + 1. */
2362 from_byte
= ini_byte
;
2366 /* We have skipped one comment. */
2369 else if (code
== Sendcomment
)
2371 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2372 &out_charpos
, &out_bytepos
);
2376 /* This end-of-line is not an end-of-comment.
2377 Treat it like a whitespace.
2378 CC-mode (and maybe others) relies on this behavior. */
2382 /* Failure: we should go back to the end of this
2383 not-quite-endcomment. */
2384 if (SYNTAX(c
) != code
)
2385 /* It was a two-char Sendcomment. */
2386 INC_BOTH (from
, from_byte
);
2392 /* We have skipped one comment. */
2393 from
= out_charpos
, from_byte
= out_bytepos
;
2397 else if (code
!= Swhitespace
|| quoted
)
2401 INC_BOTH (from
, from_byte
);
2402 SET_PT_BOTH (from
, from_byte
);
2410 SET_PT_BOTH (from
, from_byte
);
2415 /* Return syntax code of character C if C is an ASCII character
2416 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2418 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2419 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2420 ? SYNTAX (c) : Ssymbol)
2423 scan_lists (from
, count
, depth
, sexpflag
)
2424 register EMACS_INT from
;
2425 EMACS_INT count
, depth
;
2429 register EMACS_INT stop
= count
> 0 ? ZV
: BEGV
;
2434 register enum syntaxcode code
, temp_code
;
2435 int min_depth
= depth
; /* Err out if depth gets less than this. */
2436 int comstyle
= 0; /* style of comment encountered */
2437 int comnested
= 0; /* whether the comment is nestable or not */
2439 EMACS_INT last_good
= from
;
2441 EMACS_INT from_byte
;
2442 EMACS_INT out_bytepos
, out_charpos
;
2444 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2446 if (depth
> 0) min_depth
= 0;
2448 if (from
> ZV
) from
= ZV
;
2449 if (from
< BEGV
) from
= BEGV
;
2451 from_byte
= CHAR_TO_BYTE (from
);
2456 SETUP_SYNTAX_TABLE (from
, count
);
2461 int comstart_first
, prefix
;
2462 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2463 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2464 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2465 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2466 comnested
= SYNTAX_COMMENT_NESTED (c
);
2467 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2468 prefix
= SYNTAX_PREFIX (c
);
2469 if (depth
== min_depth
)
2471 INC_BOTH (from
, from_byte
);
2472 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2473 if (from
< stop
&& comstart_first
2474 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2475 SYNTAX_COMSTART_SECOND (c
))
2476 && parse_sexp_ignore_comments
)
2478 /* we have encountered a comment start sequence and we
2479 are ignoring all text inside comments. We must record
2480 the comment style this sequence begins so that later,
2481 only a comment end of the same style actually ends
2482 the comment section */
2484 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2485 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2486 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2487 INC_BOTH (from
, from_byte
);
2488 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2494 switch (SWITCH_ENUM_CAST (code
))
2498 if (from
== stop
) goto lose
;
2499 INC_BOTH (from
, from_byte
);
2500 /* treat following character as a word constituent */
2503 if (depth
|| !sexpflag
) break;
2504 /* This word counts as a sexp; return at end of it. */
2507 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2509 /* Some compilers can't handle this inside the switch. */
2510 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2511 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2516 INC_BOTH (from
, from_byte
);
2517 if (from
== stop
) goto lose
;
2526 INC_BOTH (from
, from_byte
);
2530 case Scomment_fence
:
2531 comstyle
= ST_COMMENT_STYLE
;
2534 if (!parse_sexp_ignore_comments
) break;
2535 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2536 found
= forw_comment (from
, from_byte
, stop
,
2537 comnested
, comstyle
, 0,
2538 &out_charpos
, &out_bytepos
, &dummy
);
2539 from
= out_charpos
, from_byte
= out_bytepos
;
2546 INC_BOTH (from
, from_byte
);
2547 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2553 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2555 INC_BOTH (from
, from_byte
);
2565 if (!++depth
) goto done
;
2570 if (!--depth
) goto done
;
2571 if (depth
< min_depth
)
2572 xsignal3 (Qscan_error
,
2573 build_string ("Containing expression ends prematurely"),
2574 make_number (last_good
), make_number (from
));
2579 temp_pos
= dec_bytepos (from_byte
);
2580 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2583 if (from
>= stop
) goto lose
;
2584 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2585 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2588 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2589 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2592 /* Some compilers can't handle this inside the switch. */
2593 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2598 INC_BOTH (from
, from_byte
);
2600 INC_BOTH (from
, from_byte
);
2602 INC_BOTH (from
, from_byte
);
2603 if (!depth
&& sexpflag
) goto done
;
2606 /* Ignore whitespace, punctuation, quote, endcomment. */
2611 /* Reached end of buffer. Error if within object, return nil if between */
2612 if (depth
) goto lose
;
2617 /* End of object reached */
2626 DEC_BOTH (from
, from_byte
);
2627 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2628 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2629 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2630 if (depth
== min_depth
)
2633 comnested
= SYNTAX_COMMENT_NESTED (c
);
2634 if (code
== Sendcomment
)
2635 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2636 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2637 && prev_char_comend_first (from
, from_byte
)
2638 && parse_sexp_ignore_comments
)
2640 /* We must record the comment style encountered so that
2641 later, we can match only the proper comment begin
2642 sequence of the same style. */
2643 DEC_BOTH (from
, from_byte
);
2644 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2646 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2647 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2648 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2651 /* Quoting turns anything except a comment-ender
2652 into a word character. Note that this cannot be true
2653 if we decremented FROM in the if-statement above. */
2654 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2656 DEC_BOTH (from
, from_byte
);
2659 else if (SYNTAX_PREFIX (c
))
2662 switch (SWITCH_ENUM_CAST (code
))
2668 if (depth
|| !sexpflag
) break;
2669 /* This word counts as a sexp; count object finished
2670 after passing it. */
2673 temp_pos
= from_byte
;
2674 if (! NILP (current_buffer
->enable_multibyte_characters
))
2678 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2679 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2680 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2681 /* Don't allow comment-end to be quoted. */
2682 if (temp_code
== Sendcomment
)
2684 quoted
= char_quoted (from
- 1, temp_pos
);
2687 DEC_BOTH (from
, from_byte
);
2688 temp_pos
= dec_bytepos (temp_pos
);
2689 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2691 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2692 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2693 if (! (quoted
|| temp_code
== Sword
2694 || temp_code
== Ssymbol
2695 || temp_code
== Squote
))
2697 DEC_BOTH (from
, from_byte
);
2704 temp_pos
= dec_bytepos (from_byte
);
2705 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2706 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2707 DEC_BOTH (from
, from_byte
);
2716 if (!++depth
) goto done2
;
2721 if (!--depth
) goto done2
;
2722 if (depth
< min_depth
)
2723 xsignal3 (Qscan_error
,
2724 build_string ("Containing expression ends prematurely"),
2725 make_number (last_good
), make_number (from
));
2729 if (!parse_sexp_ignore_comments
)
2731 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2732 &out_charpos
, &out_bytepos
);
2733 /* FIXME: if found == -1, then it really wasn't a comment-end.
2734 For single-char Sendcomment, we can't do much about it apart
2735 from skipping the char.
2736 For 2-char endcomments, we could try again, taking both
2737 chars as separate entities, but it's a lot of trouble
2738 for very little gain, so we don't bother either. -sm */
2740 from
= out_charpos
, from_byte
= out_bytepos
;
2743 case Scomment_fence
:
2747 if (from
== stop
) goto lose
;
2748 DEC_BOTH (from
, from_byte
);
2749 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2750 if (!char_quoted (from
, from_byte
)
2751 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2752 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2755 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2759 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2762 if (from
== stop
) goto lose
;
2763 DEC_BOTH (from
, from_byte
);
2764 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2765 if (!char_quoted (from
, from_byte
)
2767 == (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
)))
2768 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2771 if (!depth
&& sexpflag
) goto done2
;
2774 /* Ignore whitespace, punctuation, quote, endcomment. */
2779 /* Reached start of buffer. Error if within object, return nil if between */
2780 if (depth
) goto lose
;
2791 XSETFASTINT (val
, from
);
2795 xsignal3 (Qscan_error
,
2796 build_string ("Unbalanced parentheses"),
2797 make_number (last_good
), make_number (from
));
2800 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2801 doc
: /* Scan from character number FROM by COUNT lists.
2802 Returns the character number of the position thus found.
2804 If DEPTH is nonzero, paren depth begins counting from that value,
2805 only places where the depth in parentheses becomes zero
2806 are candidates for stopping; COUNT such places are counted.
2807 Thus, a positive value for DEPTH means go out levels.
2809 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2811 If the beginning or end of (the accessible part of) the buffer is reached
2812 and the depth is wrong, an error is signaled.
2813 If the depth is right but the count is not used up, nil is returned. */)
2814 (from
, count
, depth
)
2815 Lisp_Object from
, count
, depth
;
2817 CHECK_NUMBER (from
);
2818 CHECK_NUMBER (count
);
2819 CHECK_NUMBER (depth
);
2821 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2824 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2825 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2826 If COUNT is negative, scan backwards.
2827 Returns the character number of the position thus found.
2829 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2831 If the beginning or end of (the accessible part of) the buffer is reached
2832 in the middle of a parenthetical grouping, an error is signaled.
2833 If the beginning or end is reached between groupings
2834 but before count is used up, nil is returned. */)
2836 Lisp_Object from
, count
;
2838 CHECK_NUMBER (from
);
2839 CHECK_NUMBER (count
);
2841 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2844 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2846 doc
: /* Move point backward over any number of chars with prefix syntax.
2847 This includes chars with "quote" or "prefix" syntax (' or p). */)
2852 int opoint_byte
= PT_BYTE
;
2854 int pos_byte
= PT_BYTE
;
2859 SET_PT_BOTH (opoint
, opoint_byte
);
2864 SETUP_SYNTAX_TABLE (pos
, -1);
2866 DEC_BOTH (pos
, pos_byte
);
2868 while (!char_quoted (pos
, pos_byte
)
2869 /* Previous statement updates syntax table. */
2870 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2871 || SYNTAX_PREFIX (c
)))
2874 opoint_byte
= pos_byte
;
2877 DEC_BOTH (pos
, pos_byte
);
2880 SET_PT_BOTH (opoint
, opoint_byte
);
2885 /* Parse forward from FROM / FROM_BYTE to END,
2886 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2887 and return a description of the state of the parse at END.
2888 If STOPBEFORE is nonzero, stop at the start of an atom.
2889 If COMMENTSTOP is 1, stop at the start of a comment.
2890 If COMMENTSTOP is -1, stop at the start or end of a comment,
2891 after the beginning of a string, or after the end of a string. */
2894 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2895 stopbefore
, oldstate
, commentstop
)
2896 struct lisp_parse_state
*stateptr
;
2899 int end
, targetdepth
, stopbefore
;
2900 Lisp_Object oldstate
;
2903 struct lisp_parse_state state
;
2905 register enum syntaxcode code
;
2908 struct level
{ int last
, prev
; };
2909 struct level levelstart
[100];
2910 register struct level
*curlevel
= levelstart
;
2911 struct level
*endlevel
= levelstart
+ 100;
2912 register int depth
; /* Paren depth of current scanning location.
2913 level - levelstart equals this except
2914 when the depth becomes negative. */
2915 int mindepth
; /* Lowest DEPTH value seen. */
2916 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2918 int prev_from
; /* Keep one character before FROM. */
2920 int prev_from_syntax
;
2921 int boundary_stop
= commentstop
== -1;
2924 EMACS_INT out_bytepos
, out_charpos
;
2928 prev_from_byte
= from_byte
;
2930 DEC_BOTH (prev_from
, prev_from_byte
);
2932 /* Use this macro instead of `from++'. */
2934 do { prev_from = from; \
2935 prev_from_byte = from_byte; \
2936 temp = FETCH_CHAR_AS_MULTIBYTE (prev_from_byte); \
2937 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
2938 INC_BOTH (from, from_byte); \
2940 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2946 if (NILP (oldstate
))
2949 state
.instring
= -1;
2950 state
.incomment
= 0;
2951 state
.comstyle
= 0; /* comment style a by default. */
2952 state
.comstr_start
= -1; /* no comment/string seen. */
2956 tem
= Fcar (oldstate
);
2962 oldstate
= Fcdr (oldstate
);
2963 oldstate
= Fcdr (oldstate
);
2964 oldstate
= Fcdr (oldstate
);
2965 tem
= Fcar (oldstate
);
2966 /* Check whether we are inside string_fence-style string: */
2967 state
.instring
= (!NILP (tem
)
2968 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2971 oldstate
= Fcdr (oldstate
);
2972 tem
= Fcar (oldstate
);
2973 state
.incomment
= (!NILP (tem
)
2974 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
2977 oldstate
= Fcdr (oldstate
);
2978 tem
= Fcar (oldstate
);
2979 start_quoted
= !NILP (tem
);
2981 /* if the eighth element of the list is nil, we are in comment
2982 style a. If it is non-nil, we are in comment style b */
2983 oldstate
= Fcdr (oldstate
);
2984 oldstate
= Fcdr (oldstate
);
2985 tem
= Fcar (oldstate
);
2986 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
2987 ? ST_COMMENT_STYLE
: 1);
2989 oldstate
= Fcdr (oldstate
);
2990 tem
= Fcar (oldstate
);
2991 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2992 oldstate
= Fcdr (oldstate
);
2993 tem
= Fcar (oldstate
);
2994 while (!NILP (tem
)) /* >= second enclosing sexps. */
2996 /* curlevel++->last ran into compiler bug on Apollo */
2997 curlevel
->last
= XINT (Fcar (tem
));
2998 if (++curlevel
== endlevel
)
2999 curlevel
--; /* error ("Nesting too deep for parser"); */
3000 curlevel
->prev
= -1;
3001 curlevel
->last
= -1;
3008 curlevel
->prev
= -1;
3009 curlevel
->last
= -1;
3011 SETUP_SYNTAX_TABLE (prev_from
, 1);
3012 temp
= FETCH_CHAR (prev_from_byte
);
3013 prev_from_syntax
= SYNTAX_WITH_FLAGS (temp
);
3014 UPDATE_SYNTAX_TABLE_FORWARD (from
);
3016 /* Enter the loop at a place appropriate for initial state. */
3018 if (state
.incomment
)
3019 goto startincomment
;
3020 if (state
.instring
>= 0)
3022 nofence
= state
.instring
!= ST_STRING_STYLE
;
3024 goto startquotedinstring
;
3027 else if (start_quoted
)
3033 code
= prev_from_syntax
& 0xff;
3036 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
)
3037 && (c1
= FETCH_CHAR (from_byte
),
3038 SYNTAX_COMSTART_SECOND (c1
)))
3039 /* Duplicate code to avoid a complex if-expression
3040 which causes trouble for the SGI compiler. */
3042 /* Record the comment style we have entered so that only
3043 the comment-end sequence of the same style actually
3044 terminates the comment section. */
3045 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
3046 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
3047 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
3048 state
.incomment
= comnested
? 1 : -1;
3049 state
.comstr_start
= prev_from
;
3053 else if (code
== Scomment_fence
)
3055 /* Record the comment style we have entered so that only
3056 the comment-end sequence of the same style actually
3057 terminates the comment section. */
3058 state
.comstyle
= ST_COMMENT_STYLE
;
3059 state
.incomment
= -1;
3060 state
.comstr_start
= prev_from
;
3063 else if (code
== Scomment
)
3065 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
3066 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
3068 state
.comstr_start
= prev_from
;
3071 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
3073 switch (SWITCH_ENUM_CAST (code
))
3077 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3078 curlevel
->last
= prev_from
;
3080 if (from
== end
) goto endquoted
;
3083 /* treat following character as a word constituent */
3086 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3087 curlevel
->last
= prev_from
;
3091 /* Some compilers can't handle this inside the switch. */
3092 temp
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3093 temp
= SYNTAX (temp
);
3099 if (from
== end
) goto endquoted
;
3111 curlevel
->prev
= curlevel
->last
;
3114 case Scomment_fence
: /* Can't happen because it's handled above. */
3116 if (commentstop
|| boundary_stop
) goto done
;
3118 /* The (from == BEGV) test was to enter the loop in the middle so
3119 that we find a 2-char comment ender even if we start in the
3120 middle of it. We don't want to do that if we're just at the
3121 beginning of the comment (think of (*) ... (*)). */
3122 found
= forw_comment (from
, from_byte
, end
,
3123 state
.incomment
, state
.comstyle
,
3124 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
3125 ? 0 : prev_from_syntax
,
3126 &out_charpos
, &out_bytepos
, &state
.incomment
);
3127 from
= out_charpos
; from_byte
= out_bytepos
;
3128 /* Beware! prev_from and friends are invalid now.
3129 Luckily, the `done' doesn't use them and the INC_FROM
3130 sets them to a sane value without looking at them. */
3131 if (!found
) goto done
;
3133 state
.incomment
= 0;
3134 state
.comstyle
= 0; /* reset the comment style */
3135 if (boundary_stop
) goto done
;
3139 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3141 /* curlevel++->last ran into compiler bug on Apollo */
3142 curlevel
->last
= prev_from
;
3143 if (++curlevel
== endlevel
)
3144 curlevel
--; /* error ("Nesting too deep for parser"); */
3145 curlevel
->prev
= -1;
3146 curlevel
->last
= -1;
3147 if (targetdepth
== depth
) goto done
;
3152 if (depth
< mindepth
)
3154 if (curlevel
!= levelstart
)
3156 curlevel
->prev
= curlevel
->last
;
3157 if (targetdepth
== depth
) goto done
;
3162 state
.comstr_start
= from
- 1;
3163 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3164 curlevel
->last
= prev_from
;
3165 state
.instring
= (code
== Sstring
3166 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3168 if (boundary_stop
) goto done
;
3171 nofence
= state
.instring
!= ST_STRING_STYLE
;
3177 if (from
>= end
) goto done
;
3178 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3179 /* Some compilers can't handle this inside the switch. */
3182 /* Check TEMP here so that if the char has
3183 a syntax-table property which says it is NOT
3184 a string character, it does not end the string. */
3185 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3191 if (!nofence
) goto string_end
;
3196 startquotedinstring
:
3197 if (from
>= end
) goto endquoted
;
3203 state
.instring
= -1;
3204 curlevel
->prev
= curlevel
->last
;
3206 if (boundary_stop
) goto done
;
3210 /* FIXME: We should do something with it. */
3213 /* Ignore whitespace, punctuation, quote, endcomment. */
3219 stop
: /* Here if stopping before start of sexp. */
3220 from
= prev_from
; /* We have just fetched the char that starts it; */
3221 goto done
; /* but return the position before it. */
3226 state
.depth
= depth
;
3227 state
.mindepth
= mindepth
;
3228 state
.thislevelstart
= curlevel
->prev
;
3229 state
.prevlevelstart
3230 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3231 state
.location
= from
;
3232 state
.levelstarts
= Qnil
;
3233 while (--curlevel
>= levelstart
)
3234 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3241 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3242 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3243 Parsing stops at TO or when certain criteria are met;
3244 point is set to where parsing stops.
3245 If fifth arg OLDSTATE is omitted or nil,
3246 parsing assumes that FROM is the beginning of a function.
3247 Value is a list of elements describing final state of parsing:
3249 1. character address of start of innermost containing list; nil if none.
3250 2. character address of start of last complete sexp terminated.
3251 3. non-nil if inside a string.
3252 (it is the character that will terminate the string,
3253 or t if the string should be terminated by a generic string delimiter.)
3254 4. nil if outside a comment, t if inside a non-nestable comment,
3255 else an integer (the current comment nesting).
3256 5. t if following a quote character.
3257 6. the minimum paren-depth encountered during this scan.
3258 7. t if in a comment of style b; symbol `syntax-table' if the comment
3259 should be terminated by a generic comment delimiter.
3260 8. character address of start of comment or string; nil if not in one.
3261 9. Intermediate data for continuation of parsing (subject to change).
3262 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3263 in parentheses becomes equal to TARGETDEPTH.
3264 Fourth arg STOPBEFORE non-nil means stop when come to
3265 any character that starts a sexp.
3266 Fifth arg OLDSTATE is a list like what this function returns.
3267 It is used to initialize the state of the parse. Elements number 1, 2, 6
3268 and 8 are ignored; you can leave off element 8 (the last) entirely.
3269 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3270 If it is symbol `syntax-table', stop after the start of a comment or a
3271 string, or after end of a comment or a string. */)
3272 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3273 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3275 struct lisp_parse_state state
;
3278 if (!NILP (targetdepth
))
3280 CHECK_NUMBER (targetdepth
);
3281 target
= XINT (targetdepth
);
3284 target
= -100000; /* We won't reach this depth */
3286 validate_region (&from
, &to
);
3287 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3289 target
, !NILP (stopbefore
), oldstate
,
3291 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3293 SET_PT (state
.location
);
3295 return Fcons (make_number (state
.depth
),
3296 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3297 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3298 Fcons (state
.instring
>= 0
3299 ? (state
.instring
== ST_STRING_STYLE
3300 ? Qt
: make_number (state
.instring
)) : Qnil
,
3301 Fcons (state
.incomment
< 0 ? Qt
:
3302 (state
.incomment
== 0 ? Qnil
:
3303 make_number (state
.incomment
)),
3304 Fcons (state
.quoted
? Qt
: Qnil
,
3305 Fcons (make_number (state
.mindepth
),
3306 Fcons ((state
.comstyle
3307 ? (state
.comstyle
== ST_COMMENT_STYLE
3308 ? Qsyntax_table
: Qt
) :
3310 Fcons (((state
.incomment
3311 || (state
.instring
>= 0))
3312 ? make_number (state
.comstr_start
)
3314 Fcons (state
.levelstarts
, Qnil
))))))))));
3323 /* This has to be done here, before we call Fmake_char_table. */
3324 Qsyntax_table
= intern ("syntax-table");
3325 staticpro (&Qsyntax_table
);
3327 /* Intern this now in case it isn't already done.
3328 Setting this variable twice is harmless.
3329 But don't staticpro it here--that is done in alloc.c. */
3330 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3332 /* Create objects which can be shared among syntax tables. */
3333 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3334 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3335 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3336 = Fcons (make_number (i
), Qnil
);
3338 /* Now we are ready to set up this property, so we can
3339 create syntax tables. */
3340 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3342 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3344 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3346 /* Control characters should not be whitespace. */
3347 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3348 for (i
= 0; i
<= ' ' - 1; i
++)
3349 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3350 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 0177, temp
);
3352 /* Except that a few really are whitespace. */
3353 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3354 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ' ', temp
);
3355 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\t', temp
);
3356 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\n', temp
);
3357 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 015, temp
);
3358 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, 014, temp
);
3360 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3361 for (i
= 'a'; i
<= 'z'; i
++)
3362 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3363 for (i
= 'A'; i
<= 'Z'; i
++)
3364 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3365 for (i
= '0'; i
<= '9'; i
++)
3366 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3368 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3369 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3371 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3372 Fcons (make_number (Sopen
), make_number (')')));
3373 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3374 Fcons (make_number (Sclose
), make_number ('(')));
3375 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3376 Fcons (make_number (Sopen
), make_number (']')));
3377 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3378 Fcons (make_number (Sclose
), make_number ('[')));
3379 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3380 Fcons (make_number (Sopen
), make_number ('}')));
3381 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3382 Fcons (make_number (Sclose
), make_number ('{')));
3383 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3384 Fcons (make_number ((int) Sstring
), Qnil
));
3385 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3386 Fcons (make_number ((int) Sescape
), Qnil
));
3388 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3389 for (i
= 0; i
< 10; i
++)
3391 c
= "_-+*/&|<>="[i
];
3392 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3395 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3396 for (i
= 0; i
< 12; i
++)
3398 c
= ".,;:?!#@~^'`"[i
];
3399 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3402 /* All multibyte characters have syntax `word' by default. */
3403 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3404 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3410 Qsyntax_table_p
= intern ("syntax-table-p");
3411 staticpro (&Qsyntax_table_p
);
3413 staticpro (&Vsyntax_code_object
);
3415 staticpro (&gl_state
.object
);
3416 staticpro (&gl_state
.global_code
);
3417 staticpro (&gl_state
.current_syntax_table
);
3418 staticpro (&gl_state
.old_prop
);
3420 /* Defined in regex.c */
3421 staticpro (&re_match_object
);
3423 Qscan_error
= intern ("scan-error");
3424 staticpro (&Qscan_error
);
3425 Fput (Qscan_error
, Qerror_conditions
,
3426 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3427 Fput (Qscan_error
, Qerror_message
,
3428 build_string ("Scan error"));
3430 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3431 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3433 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3434 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3435 Otherwise, that text property is simply ignored.
3436 See the info node `(elisp)Syntax Properties' for a description of the
3437 `syntax-table' property. */);
3439 words_include_escapes
= 0;
3440 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3441 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3443 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3444 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3445 multibyte_syntax_as_symbol
= 0;
3447 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3448 &open_paren_in_column_0_is_defun_start
,
3449 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3450 open_paren_in_column_0_is_defun_start
= 1;
3453 DEFVAR_LISP ("find-word-boundary-function-table",
3454 &Vfind_word_boundary_function_table
,
3456 Char table of functions to search for the word boundary.
3457 Each function is called with two arguments; POS and LIMIT.
3458 POS and LIMIT are character positions in the current buffer.
3460 If POS is less than LIMIT, POS is at the first character of a word,
3461 and the return value of a function is a position after the last
3462 character of that word.
3464 If POS is not less than LIMIT, POS is at the last character of a word,
3465 and the return value of a function is a position at the first
3466 character of that word.
3468 In both cases, LIMIT bounds the search. */);
3469 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3471 defsubr (&Ssyntax_table_p
);
3472 defsubr (&Ssyntax_table
);
3473 defsubr (&Sstandard_syntax_table
);
3474 defsubr (&Scopy_syntax_table
);
3475 defsubr (&Sset_syntax_table
);
3476 defsubr (&Schar_syntax
);
3477 defsubr (&Smatching_paren
);
3478 defsubr (&Sstring_to_syntax
);
3479 defsubr (&Smodify_syntax_entry
);
3480 defsubr (&Sinternal_describe_syntax_value
);
3482 defsubr (&Sforward_word
);
3484 defsubr (&Sskip_chars_forward
);
3485 defsubr (&Sskip_chars_backward
);
3486 defsubr (&Sskip_syntax_forward
);
3487 defsubr (&Sskip_syntax_backward
);
3489 defsubr (&Sforward_comment
);
3490 defsubr (&Sscan_lists
);
3491 defsubr (&Sscan_sexps
);
3492 defsubr (&Sbackward_prefix_chars
);
3493 defsubr (&Sparse_partial_sexp
);
3496 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
3497 (do not change this comment) */