1 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
2 Copyright (C) 1985, 87, 93, 94, 95, 97, 1998, 1999 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 #include "character.h"
30 /* Make syntax table lookup grant data in gl_state. */
31 #define SYNTAX_ENTRY_VIA_PROPERTY
34 #include "intervals.h"
36 /* We use these constants in place for comment-style and
37 string-ender-char to distinguish comments/strings started by
38 comment_fence and string_fence codes. */
40 #define ST_COMMENT_STYLE (256 + 1)
41 #define ST_STRING_STYLE (256 + 2)
44 Lisp_Object Qsyntax_table_p
, Qsyntax_table
, Qscan_error
;
46 int words_include_escapes
;
47 int parse_sexp_lookup_properties
;
49 /* Nonzero means `scan-sexps' treat all multibyte characters as symbol. */
50 int multibyte_syntax_as_symbol
;
52 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
53 if not compiled with GCC. No need to mark it, since it is used
54 only very temporarily. */
55 Lisp_Object syntax_temp
;
57 /* Non-zero means an open parenthesis in column 0 is always considered
58 to be the start of a defun. Zero means an open parenthesis in
59 column 0 has no special meaning. */
61 int open_paren_in_column_0_is_defun_start
;
63 /* This is the internal form of the parse state used in parse-partial-sexp. */
65 struct lisp_parse_state
67 int depth
; /* Depth at end of parsing. */
68 int instring
; /* -1 if not within string, else desired terminator. */
69 int incomment
; /* -1 if in unnestable comment else comment nesting */
70 int comstyle
; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
71 int quoted
; /* Nonzero if just after an escape char at end of parsing */
72 int thislevelstart
; /* Char number of most recent start-of-expression at current level */
73 int prevlevelstart
; /* Char number of start of containing expression */
74 int location
; /* Char number at which parsing stopped. */
75 int mindepth
; /* Minimum depth seen while scanning. */
76 int comstr_start
; /* Position just after last comment/string starter. */
77 Lisp_Object levelstarts
; /* Char numbers of starts-of-expression
78 of levels (starting from outermost). */
81 /* These variables are a cache for finding the start of a defun.
82 find_start_pos is the place for which the defun start was found.
83 find_start_value is the defun start position found for it.
84 find_start_value_byte is the corresponding byte position.
85 find_start_buffer is the buffer it was found in.
86 find_start_begv is the BEGV value when it was found.
87 find_start_modiff is the value of MODIFF when it was found. */
89 static int find_start_pos
;
90 static int find_start_value
;
91 static int find_start_value_byte
;
92 static struct buffer
*find_start_buffer
;
93 static int find_start_begv
;
94 static int find_start_modiff
;
97 static int find_defun_start
P_ ((int, int));
98 static int back_comment
P_ ((int, int, int, int, int, int *, int *));
99 static int char_quoted
P_ ((int, int));
100 static Lisp_Object skip_chars
P_ ((int, Lisp_Object
, Lisp_Object
));
101 static Lisp_Object skip_syntaxes
P_ ((int, Lisp_Object
, Lisp_Object
));
102 static Lisp_Object scan_lists
P_ ((int, int, int, int));
103 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
105 int, Lisp_Object
, int));
108 struct gl_state_s gl_state
; /* Global state of syntax parser. */
110 INTERVAL
interval_of ();
111 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
112 to scan to property-change. */
114 /* Update gl_state to an appropriate interval which contains CHARPOS. The
115 sign of COUNT give the relative position of CHARPOS wrt the previously
116 valid interval. If INIT, only [be]_property fields of gl_state are
117 valid at start, the rest is filled basing on OBJECT.
119 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
120 direction than the intervals - or in an interval. We update the
121 current syntax-table basing on the property of this interval, and
122 update the interval to start further than CHARPOS - or be
123 NULL_INTERVAL. We also update lim_property to be the next value of
124 charpos to call this subroutine again - or be before/after the
125 start/end of OBJECT. */
128 update_syntax_table (charpos
, count
, init
, object
)
129 int charpos
, count
, init
;
132 Lisp_Object tmp_table
;
133 int cnt
= 0, invalidate
= 1;
138 gl_state
.old_prop
= Qnil
;
139 gl_state
.start
= gl_state
.b_property
;
140 gl_state
.stop
= gl_state
.e_property
;
141 i
= interval_of (charpos
, object
);
142 gl_state
.backward_i
= gl_state
.forward_i
= i
;
144 if (NULL_INTERVAL_P (i
))
146 /* interval_of updates only ->position of the return value, so
147 update the parents manually to speed up update_interval. */
148 while (!NULL_PARENT (i
))
150 if (AM_RIGHT_CHILD (i
))
151 INTERVAL_PARENT (i
)->position
= i
->position
152 - LEFT_TOTAL_LENGTH (i
) + TOTAL_LENGTH (i
) /* right end */
153 - TOTAL_LENGTH (INTERVAL_PARENT (i
))
154 + LEFT_TOTAL_LENGTH (INTERVAL_PARENT (i
));
156 INTERVAL_PARENT (i
)->position
= i
->position
- LEFT_TOTAL_LENGTH (i
)
158 i
= INTERVAL_PARENT (i
);
160 i
= gl_state
.forward_i
;
161 gl_state
.b_property
= i
->position
- gl_state
.offset
;
162 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
165 oldi
= i
= count
> 0 ? gl_state
.forward_i
: gl_state
.backward_i
;
167 /* We are guaranteed to be called with CHARPOS either in i,
169 if (NULL_INTERVAL_P (i
))
170 error ("Error in syntax_table logic for to-the-end intervals");
171 else if (charpos
< i
->position
) /* Move left. */
174 error ("Error in syntax_table logic for intervals <-");
175 /* Update the interval. */
176 i
= update_interval (i
, charpos
);
177 if (INTERVAL_LAST_POS (i
) != gl_state
.b_property
)
180 gl_state
.forward_i
= i
;
181 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
184 else if (charpos
>= INTERVAL_LAST_POS (i
)) /* Move right. */
187 error ("Error in syntax_table logic for intervals ->");
188 /* Update the interval. */
189 i
= update_interval (i
, charpos
);
190 if (i
->position
!= gl_state
.e_property
)
193 gl_state
.backward_i
= i
;
194 gl_state
.b_property
= i
->position
- gl_state
.offset
;
199 tmp_table
= textget (i
->plist
, Qsyntax_table
);
202 invalidate
= !EQ (tmp_table
, gl_state
.old_prop
); /* Need to invalidate? */
204 if (invalidate
) /* Did not get to adjacent interval. */
205 { /* with the same table => */
206 /* invalidate the old range. */
209 gl_state
.backward_i
= i
;
210 gl_state
.b_property
= i
->position
- gl_state
.offset
;
214 gl_state
.forward_i
= i
;
215 gl_state
.e_property
= INTERVAL_LAST_POS (i
) - gl_state
.offset
;
219 if (!EQ (tmp_table
, gl_state
.old_prop
))
221 gl_state
.current_syntax_table
= tmp_table
;
222 gl_state
.old_prop
= tmp_table
;
223 if (EQ (Fsyntax_table_p (tmp_table
), Qt
))
225 gl_state
.use_global
= 0;
227 else if (CONSP (tmp_table
))
229 gl_state
.use_global
= 1;
230 gl_state
.global_code
= tmp_table
;
234 gl_state
.use_global
= 0;
235 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
239 while (!NULL_INTERVAL_P (i
))
241 if (cnt
&& !EQ (tmp_table
, textget (i
->plist
, Qsyntax_table
)))
245 gl_state
.e_property
= i
->position
- gl_state
.offset
;
246 gl_state
.forward_i
= i
;
250 gl_state
.b_property
= i
->position
+ LENGTH (i
) - gl_state
.offset
;
251 gl_state
.backward_i
= i
;
255 else if (cnt
== INTERVALS_AT_ONCE
)
259 gl_state
.e_property
= i
->position
+ LENGTH (i
) - gl_state
.offset
;
260 gl_state
.forward_i
= i
;
264 gl_state
.b_property
= i
->position
- gl_state
.offset
;
265 gl_state
.backward_i
= i
;
270 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
272 eassert (NULL_INTERVAL_P (i
)); /* This property goes to the end. */
274 gl_state
.e_property
= gl_state
.stop
;
276 gl_state
.b_property
= gl_state
.start
;
279 /* Returns TRUE if char at CHARPOS is quoted.
280 Global syntax-table data should be set up already to be good at CHARPOS
281 or after. On return global syntax data is good for lookup at CHARPOS. */
284 char_quoted (charpos
, bytepos
)
285 register int charpos
, bytepos
;
287 register enum syntaxcode code
;
288 register int beg
= BEGV
;
289 register int quoted
= 0;
292 DEC_BOTH (charpos
, bytepos
);
294 while (bytepos
>= beg
)
296 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
297 code
= SYNTAX (FETCH_CHAR_AS_MULTIBYTE (bytepos
));
298 if (! (code
== Scharquote
|| code
== Sescape
))
301 DEC_BOTH (charpos
, bytepos
);
305 UPDATE_SYNTAX_TABLE (orig
);
309 /* Return the bytepos one character after BYTEPOS.
310 We assume that BYTEPOS is not at the end of the buffer. */
313 inc_bytepos (bytepos
)
316 if (NILP (current_buffer
->enable_multibyte_characters
))
323 /* Return the bytepos one character before BYTEPOS.
324 We assume that BYTEPOS is not at the start of the buffer. */
327 dec_bytepos (bytepos
)
330 if (NILP (current_buffer
->enable_multibyte_characters
))
337 /* Return a defun-start position before before POS and not too far before.
338 It should be the last one before POS, or nearly the last.
340 When open_paren_in_column_0_is_defun_start is nonzero,
341 only the beginning of the buffer is treated as a defun-start.
343 We record the information about where the scan started
344 and what its result was, so that another call in the same area
345 can return the same value very quickly.
347 There is no promise at which position the global syntax data is
348 valid on return from the subroutine, so the caller should explicitly
349 update the global data. */
352 find_defun_start (pos
, pos_byte
)
355 int opoint
= PT
, opoint_byte
= PT_BYTE
;
357 if (!open_paren_in_column_0_is_defun_start
)
359 find_start_value_byte
= BEGV_BYTE
;
363 /* Use previous finding, if it's valid and applies to this inquiry. */
364 if (current_buffer
== find_start_buffer
365 /* Reuse the defun-start even if POS is a little farther on.
366 POS might be in the next defun, but that's ok.
367 Our value may not be the best possible, but will still be usable. */
368 && pos
<= find_start_pos
+ 1000
369 && pos
>= find_start_value
370 && BEGV
== find_start_begv
371 && MODIFF
== find_start_modiff
)
372 return find_start_value
;
374 /* Back up to start of line. */
375 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
377 /* We optimize syntax-table lookup for rare updates. Thus we accept
378 only those `^\s(' which are good in global _and_ text-property
380 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
381 gl_state
.use_global
= 0;
384 /* Open-paren at start of line means we may have found our
386 if (SYNTAX (FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
)) == Sopen
)
388 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
389 if (SYNTAX (FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
)) == Sopen
)
391 /* Now fallback to the default value. */
392 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
393 gl_state
.use_global
= 0;
395 /* Move to beg of previous line. */
396 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
399 /* Record what we found, for the next try. */
400 find_start_value
= PT
;
401 find_start_value_byte
= PT_BYTE
;
402 find_start_buffer
= current_buffer
;
403 find_start_modiff
= MODIFF
;
404 find_start_begv
= BEGV
;
405 find_start_pos
= pos
;
407 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
409 return find_start_value
;
412 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
415 prev_char_comend_first (pos
, pos_byte
)
420 DEC_BOTH (pos
, pos_byte
);
421 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
422 c
= FETCH_CHAR (pos_byte
);
423 val
= SYNTAX_COMEND_FIRST (c
);
424 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
428 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
431 * prev_char_comstart_first (pos, pos_byte)
436 * DEC_BOTH (pos, pos_byte);
437 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
438 * c = FETCH_CHAR (pos_byte);
439 * val = SYNTAX_COMSTART_FIRST (c);
440 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
444 /* Checks whether charpos FROM is at the end of a comment.
445 FROM_BYTE is the bytepos corresponding to FROM.
446 Do not move back before STOP.
448 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
451 If successful, store the charpos of the comment's beginning
452 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
454 Global syntax data remains valid for backward search starting at
455 the returned value (or at FROM, if the search was not successful). */
458 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
459 int from
, from_byte
, stop
;
460 int comnested
, comstyle
;
461 int *charpos_ptr
, *bytepos_ptr
;
463 /* Look back, counting the parity of string-quotes,
464 and recording the comment-starters seen.
465 When we reach a safe place, assume that's not in a string;
466 then step the main scan to the earliest comment-starter seen
467 an even number of string quotes away from the safe place.
469 OFROM[I] is position of the earliest comment-starter seen
470 which is I+2X quotes from the comment-end.
471 PARITY is current parity of quotes from the comment end. */
472 int string_style
= -1; /* Presumed outside of any string. */
473 int string_lossage
= 0;
474 /* Not a real lossage: indicates that we have passed a matching comment
475 starter plus a non-matching comment-ender, meaning that any matching
476 comment-starter we might see later could be a false positive (hidden
477 inside another comment).
478 Test case: { a (* b } c (* d *) */
479 int comment_lossage
= 0;
480 int comment_end
= from
;
481 int comment_end_byte
= from_byte
;
482 int comstart_pos
= 0;
484 /* Place where the containing defun starts,
485 or 0 if we didn't come across it yet. */
487 int defun_start_byte
= 0;
488 register enum syntaxcode code
;
489 int nesting
= 1; /* current comment nesting */
493 /* FIXME: A }} comment-ender style leads to incorrect behavior
494 in the case of {{ c }}} because we ignore the last two chars which are
495 assumed to be comment-enders although they aren't. */
497 /* At beginning of range to scan, we're outside of strings;
498 that determines quote parity to the comment-end. */
501 int temp_byte
, prev_syntax
;
502 int com2start
, com2end
;
504 /* Move back and examine a character. */
505 DEC_BOTH (from
, from_byte
);
506 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
508 prev_syntax
= syntax
;
509 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
510 syntax
= SYNTAX_WITH_FLAGS (c
);
513 /* Check for 2-char comment markers. */
514 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
515 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
516 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
517 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
518 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
519 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
520 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
522 /* Nasty cases with overlapping 2-char comment markers:
523 - snmp-mode: -- c -- foo -- c --
531 /* If a 2-char comment sequence partly overlaps with another,
532 we don't try to be clever. */
533 if (from
> stop
&& (com2end
|| com2start
))
535 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
536 DEC_BOTH (next
, next_byte
);
537 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
538 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
539 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
540 if (((com2start
|| comnested
)
541 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
542 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
543 || ((com2end
|| comnested
)
544 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
545 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
546 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
548 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
551 if (com2start
&& comstart_pos
== 0)
552 /* We're looking at a comment starter. But it might be a comment
553 ender as well (see snmp-mode). The first time we see one, we
554 need to consider it as a comment starter,
555 and the subsequent times as a comment ender. */
558 /* Turn a 2-char comment sequences into the appropriate syntax. */
563 /* Ignore comment starters of a different style. */
564 else if (code
== Scomment
565 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
566 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
569 /* Ignore escaped characters, except comment-enders. */
570 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
577 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
579 /* Track parity of quotes. */
580 if (string_style
== -1)
581 /* Entering a string. */
583 else if (string_style
== c
)
584 /* Leaving the string. */
587 /* If we have two kinds of string delimiters.
588 There's no way to grok this scanning backwards. */
593 /* We've already checked that it is the relevant comstyle. */
594 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
595 /* There are odd string quotes involved, so let's be careful.
596 Test case in Pascal: " { " a { " } */
601 /* Record best comment-starter so far. */
603 comstart_byte
= from_byte
;
605 else if (--nesting
<= 0)
606 /* nested comments have to be balanced, so we don't need to
607 keep looking for earlier ones. We use here the same (slightly
608 incorrect) reasoning as below: since it is followed by uniform
609 paired string quotes, this comment-start has to be outside of
610 strings, else the comment-end itself would be inside a string. */
615 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
616 && ((com2end
&& SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
))
617 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
618 /* This is the same style of comment ender as ours. */
623 /* Anything before that can't count because it would match
624 this comment-ender rather than ours. */
625 from
= stop
; /* Break out of the loop. */
627 else if (comstart_pos
!= 0 || c
!= '\n')
628 /* We're mixing comment styles here, so we'd better be careful.
629 The (comstart_pos != 0 || c != '\n') check is not quite correct
630 (we should just always set comment_lossage), but removing it
631 would imply that any multiline comment in C would go through
632 lossage, which seems overkill.
633 The failure should only happen in the rare cases such as
639 /* Assume a defun-start point is outside of strings. */
640 if (open_paren_in_column_0_is_defun_start
642 || (temp_byte
= dec_bytepos (from_byte
),
643 FETCH_CHAR (temp_byte
) == '\n')))
646 defun_start_byte
= from_byte
;
647 from
= stop
; /* Break out of the loop. */
656 if (comstart_pos
== 0)
659 from_byte
= comment_end_byte
;
660 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
662 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
663 or `done'), then we've found the beginning of the non-nested comment. */
664 else if (1) /* !comnested */
667 from_byte
= comstart_byte
;
668 /* Globals are correct now. */
672 struct lisp_parse_state state
;
674 /* We had two kinds of string delimiters mixed up
675 together. Decode this going forwards.
676 Scan fwd from a known safe place (beginning-of-defun)
677 to the one in question; this records where we
678 last passed a comment starter. */
679 /* If we did not already find the defun start, find it now. */
680 if (defun_start
== 0)
682 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
683 defun_start_byte
= find_start_value_byte
;
687 scan_sexps_forward (&state
,
688 defun_start
, defun_start_byte
,
689 comment_end
, -10000, 0, Qnil
, 0);
690 defun_start
= comment_end
;
691 if (state
.incomment
== (comnested
? 1 : -1)
692 && state
.comstyle
== comstyle
)
693 from
= state
.comstr_start
;
698 /* If comment_end is inside some other comment, maybe ours
699 is nested, so we need to try again from within the
700 surrounding comment. Example: { a (* " *) */
702 /* FIXME: We should advance by one or two chars. */
703 defun_start
= state
.comstr_start
+ 2;
704 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
707 } while (defun_start
< comment_end
);
709 from_byte
= CHAR_TO_BYTE (from
);
710 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
715 *bytepos_ptr
= from_byte
;
717 return (from
== comment_end
) ? -1 : from
;
720 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
721 doc
: /* Return t if OBJECT is a syntax table.
722 Currently, any char-table counts as a syntax table. */)
726 if (CHAR_TABLE_P (object
)
727 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
733 check_syntax_table (obj
)
736 if (!(CHAR_TABLE_P (obj
)
737 && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
)))
738 wrong_type_argument (Qsyntax_table_p
, obj
);
741 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
742 doc
: /* Return the current syntax table.
743 This is the one specified by the current buffer. */)
746 return current_buffer
->syntax_table
;
749 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
750 Sstandard_syntax_table
, 0, 0, 0,
751 doc
: /* Return the standard syntax table.
752 This is the one used for new buffers. */)
755 return Vstandard_syntax_table
;
758 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
759 doc
: /* Construct a new syntax table and return it.
760 It is a copy of the TABLE, which defaults to the standard syntax table. */)
767 check_syntax_table (table
);
769 table
= Vstandard_syntax_table
;
771 copy
= Fcopy_sequence (table
);
773 /* Only the standard syntax table should have a default element.
774 Other syntax tables should inherit from parents instead. */
775 XCHAR_TABLE (copy
)->defalt
= Qnil
;
777 /* Copied syntax tables should all have parents.
778 If we copied one with no parent, such as the standard syntax table,
779 use the standard syntax table as the copy's parent. */
780 if (NILP (XCHAR_TABLE (copy
)->parent
))
781 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
785 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
786 doc
: /* Select a new syntax table for the current buffer.
787 One argument, a syntax table. */)
792 check_syntax_table (table
);
793 current_buffer
->syntax_table
= table
;
794 /* Indicate that this buffer now has a specified syntax table. */
795 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
796 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
800 /* Convert a letter which signifies a syntax code
801 into the code it signifies.
802 This is used by modify-syntax-entry, and other things. */
804 unsigned char syntax_spec_code
[0400] =
805 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
806 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
807 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
808 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
809 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
810 (char) Smath
, 0377, 0377, (char) Squote
,
811 (char) Sopen
, (char) Sclose
, 0377, 0377,
812 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
813 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
814 0377, 0377, 0377, 0377,
815 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
816 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
817 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
818 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
819 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
820 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
821 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
822 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
823 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
826 /* Indexed by syntax code, give the letter that describes it. */
828 char syntax_code_spec
[16] =
830 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
834 /* Indexed by syntax code, give the object (cons of syntax code and
835 nil) to be stored in syntax table. Since these objects can be
836 shared among syntax tables, we generate them in advance. By
837 sharing objects, the function `describe-syntax' can give a more
839 static Lisp_Object Vsyntax_code_object
;
842 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
843 doc
: /* Return the syntax code of CHARACTER, described by a character.
844 For example, if CHARACTER is a word constituent,
845 the character `w' is returned.
846 The characters that correspond to various syntax codes
847 are listed in the documentation of `modify-syntax-entry'. */)
849 Lisp_Object character
;
852 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
854 gl_state
.use_global
= 0;
855 CHECK_NUMBER (character
);
856 char_int
= XINT (character
);
857 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
860 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
861 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
863 Lisp_Object character
;
866 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
867 gl_state
.use_global
= 0;
868 CHECK_NUMBER (character
);
869 char_int
= XINT (character
);
870 code
= SYNTAX (char_int
);
871 if (code
== Sopen
|| code
== Sclose
)
872 return SYNTAX_MATCH (char_int
);
876 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
877 doc
: /* Convert a syntax specification STRING into syntax cell form.
878 STRING should be a string as it is allowed as argument of
879 `modify-syntax-entry'. Value is the equivalent cons cell
880 (CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
885 register const unsigned char *p
;
886 register enum syntaxcode code
;
890 CHECK_STRING (string
);
893 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
894 if (((int) code
& 0377) == 0377)
895 error ("invalid syntax description letter: %c", p
[-1]);
897 if (code
== Sinherit
)
903 int character
= (STRING_CHAR_AND_LENGTH
904 (p
, SBYTES (string
) - 1, len
));
905 XSETINT (match
, character
);
906 if (XFASTINT (match
) == ' ')
946 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
947 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
949 /* Since we can't use a shared object, let's make a new one. */
950 return Fcons (make_number (val
), match
);
953 /* I really don't know why this is interactive
954 help-form should at least be made useful whilst reading the second arg. */
955 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
956 "cSet syntax for character: \nsSet syntax for %s to: ",
957 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
958 The syntax is changed only for table SYNTAX_TABLE, which defaults to
959 the current buffer's syntax table.
960 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
961 in the range MIN and MAX are changed.
962 The first character of NEWENTRY should be one of the following:
963 Space or - whitespace syntax. w word constituent.
964 _ symbol constituent. . punctuation.
965 ( open-parenthesis. ) close-parenthesis.
966 " string quote. \\ escape.
967 $ paired delimiter. ' expression quote or prefix operator.
968 < comment starter. > comment ender.
969 / character-quote. @ inherit from `standard-syntax-table'.
970 | generic string fence. ! generic comment fence.
972 Only single-character comment start and end sequences are represented thus.
973 Two-character sequences are represented as described below.
974 The second character of NEWENTRY is the matching parenthesis,
975 used only if the first character is `(' or `)'.
976 Any additional characters are flags.
977 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
978 1 means CHAR is the start of a two-char comment start sequence.
979 2 means CHAR is the second character of such a sequence.
980 3 means CHAR is the start of a two-char comment end sequence.
981 4 means CHAR is the second character of such a sequence.
983 There can be up to two orthogonal comment sequences. This is to support
984 language modes such as C++. By default, all comment sequences are of style
985 a, but you can set the comment sequence style to b (on the second character
986 of a comment-start, or the first character of a comment-end sequence) using
988 b means CHAR is part of comment sequence b.
989 n means CHAR is part of a nestable comment sequence.
991 p means CHAR is a prefix character for `backward-prefix-chars';
992 such characters are treated as whitespace when they occur
994 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
995 (c
, newentry
, syntax_table
)
996 Lisp_Object c
, newentry
, syntax_table
;
1000 CHECK_CHARACTER_CAR (c
);
1001 CHECK_CHARACTER_CDR (c
);
1004 CHECK_CHARACTER (c
);
1006 if (NILP (syntax_table
))
1007 syntax_table
= current_buffer
->syntax_table
;
1009 check_syntax_table (syntax_table
);
1011 newentry
= Fstring_to_syntax (newentry
);
1013 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1015 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1019 /* Dump syntax table to buffer in human-readable format */
1021 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1022 Sinternal_describe_syntax_value
, 1, 1, 0,
1023 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1027 register enum syntaxcode code
;
1028 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1030 Lisp_Object first
, match_lisp
, value
= syntax
;
1034 insert_string ("default");
1038 if (CHAR_TABLE_P (value
))
1040 insert_string ("deeper char-table ...");
1046 insert_string ("invalid");
1050 first
= XCAR (value
);
1051 match_lisp
= XCDR (value
);
1053 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1055 insert_string ("invalid");
1059 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1060 start1
= (XINT (first
) >> 16) & 1;
1061 start2
= (XINT (first
) >> 17) & 1;
1062 end1
= (XINT (first
) >> 18) & 1;
1063 end2
= (XINT (first
) >> 19) & 1;
1064 prefix
= (XINT (first
) >> 20) & 1;
1065 comstyle
= (XINT (first
) >> 21) & 1;
1066 comnested
= (XINT (first
) >> 22) & 1;
1068 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1070 insert_string ("invalid");
1073 desc
= syntax_code_spec
[(int) code
];
1075 str
[0] = desc
, str
[1] = 0;
1078 if (NILP (match_lisp
))
1081 insert_char (XINT (match_lisp
));
1100 insert_string ("\twhich means: ");
1102 switch (SWITCH_ENUM_CAST (code
))
1105 insert_string ("whitespace"); break;
1107 insert_string ("punctuation"); break;
1109 insert_string ("word"); break;
1111 insert_string ("symbol"); break;
1113 insert_string ("open"); break;
1115 insert_string ("close"); break;
1117 insert_string ("prefix"); break;
1119 insert_string ("string"); break;
1121 insert_string ("math"); break;
1123 insert_string ("escape"); break;
1125 insert_string ("charquote"); break;
1127 insert_string ("comment"); break;
1129 insert_string ("endcomment"); break;
1131 insert_string ("inherit"); break;
1132 case Scomment_fence
:
1133 insert_string ("comment fence"); break;
1135 insert_string ("string fence"); break;
1137 insert_string ("invalid");
1141 if (!NILP (match_lisp
))
1143 insert_string (", matches ");
1144 insert_char (XINT (match_lisp
));
1148 insert_string (",\n\t is the first character of a comment-start sequence");
1150 insert_string (",\n\t is the second character of a comment-start sequence");
1153 insert_string (",\n\t is the first character of a comment-end sequence");
1155 insert_string (",\n\t is the second character of a comment-end sequence");
1157 insert_string (" (comment style b)");
1159 insert_string (" (nestable)");
1162 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1167 int parse_sexp_ignore_comments
;
1169 /* Char-table of functions that find the next or previous word
1171 Lisp_Object Vfind_word_boundary_function_table
;
1173 /* Return the position across COUNT words from FROM.
1174 If that many words cannot be found before the end of the buffer, return 0.
1175 COUNT negative means scan backward and stop at word beginning. */
1178 scan_words (from
, count
)
1179 register int from
, count
;
1181 register int beg
= BEGV
;
1182 register int end
= ZV
;
1183 register int from_byte
= CHAR_TO_BYTE (from
);
1184 register enum syntaxcode code
;
1186 Lisp_Object func
, script
, pos
;
1191 SETUP_SYNTAX_TABLE (from
, count
);
1202 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1203 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1204 code
= SYNTAX (ch0
);
1205 INC_BOTH (from
, from_byte
);
1206 if (words_include_escapes
1207 && (code
== Sescape
|| code
== Scharquote
))
1212 /* Now CH0 is a character which begins a word and FROM is the
1213 position of the next character. */
1214 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch0
);
1215 if (! NILP (Ffboundp (func
)))
1217 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1218 if (INTEGERP (pos
) && XINT (pos
) > from
)
1221 from_byte
= CHAR_TO_BYTE (from
);
1226 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1229 if (from
== end
) break;
1230 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1231 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1232 code
= SYNTAX (ch1
);
1234 && (! words_include_escapes
1235 || (code
!= Sescape
&& code
!= Scharquote
)))
1236 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch1
), script
))
1238 INC_BOTH (from
, from_byte
);
1253 DEC_BOTH (from
, from_byte
);
1254 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1255 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1256 code
= SYNTAX (ch1
);
1257 if (words_include_escapes
1258 && (code
== Sescape
|| code
== Scharquote
))
1263 /* Now CH1 is a character which ends a word and FROM is the
1265 func
= CHAR_TABLE_REF (Vfind_word_boundary_function_table
, ch1
);
1266 if (! NILP (Ffboundp (func
)))
1268 pos
= call2 (func
, make_number (from
), make_number (beg
));
1269 if (INTEGERP (pos
) && XINT (pos
) < from
)
1272 from_byte
= CHAR_TO_BYTE (from
);
1277 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1284 temp_byte
= dec_bytepos (from_byte
);
1285 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1286 ch0
= FETCH_CHAR_AS_MULTIBYTE (temp_byte
);
1287 code
= SYNTAX (ch0
);
1289 && (! words_include_escapes
1290 || (code
!= Sescape
&& code
!= Scharquote
)))
1291 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch0
), script
))
1293 DEC_BOTH (from
, from_byte
);
1305 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 1, 1, "p",
1306 doc
: /* Move point forward ARG words (backward if ARG is negative).
1308 If an edge of the buffer or a field boundary is reached, point is left there
1309 and the function returns nil. Field boundaries are not noticed if
1310 `inhibit-field-text-motion' is non-nil. */)
1315 CHECK_NUMBER (count
);
1317 val
= orig_val
= scan_words (PT
, XINT (count
));
1319 val
= XINT (count
) > 0 ? ZV
: BEGV
;
1321 /* Avoid jumping out of an input field. */
1322 val
= XFASTINT (Fconstrain_to_field (make_number (val
), make_number (PT
),
1326 return val
== orig_val
? Qt
: Qnil
;
1329 Lisp_Object
skip_chars ();
1331 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1332 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1333 STRING is like the inside of a `[...]' in a regular expression
1334 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1335 (but not as the end of a range; quoting is never needed there).
1336 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1337 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1338 Returns the distance traveled, either zero or positive.
1339 Note that char classes, e.g. `[:alpha:]', are not currently supported;
1340 they will be treated as literals. */)
1342 Lisp_Object string
, lim
;
1344 return skip_chars (1, string
, lim
);
1347 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1348 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1349 See `skip-chars-forward' for details.
1350 Returns the distance traveled, either zero or negative. */)
1352 Lisp_Object string
, lim
;
1354 return skip_chars (0, string
, lim
);
1357 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1358 doc
: /* Move point forward across chars in specified syntax classes.
1359 SYNTAX is a string of syntax code characters.
1360 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1361 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1362 This function returns the distance traveled, either zero or positive. */)
1364 Lisp_Object syntax
, lim
;
1366 return skip_syntaxes (1, syntax
, lim
);
1369 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1370 doc
: /* Move point backward across chars in specified syntax classes.
1371 SYNTAX is a string of syntax code characters.
1372 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1373 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1374 This function returns the distance traveled, either zero or negative. */)
1376 Lisp_Object syntax
, lim
;
1378 return skip_syntaxes (0, syntax
, lim
);
1382 skip_chars (forwardp
, string
, lim
)
1384 Lisp_Object string
, lim
;
1386 register unsigned int c
;
1387 unsigned char fastmap
[0400];
1388 /* Store the ranges of non-ASCII characters. */
1390 int n_char_ranges
= 0;
1392 register int i
, i_byte
;
1393 /* Set to 1 if the current buffer is multibyte and the region
1394 contains non-ASCII chars. */
1396 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1398 int string_multibyte
;
1400 const unsigned char *str
;
1403 CHECK_STRING (string
);
1406 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1408 CHECK_NUMBER_COERCE_MARKER (lim
);
1410 /* In any case, don't allow scan outside bounds of buffer. */
1411 if (XINT (lim
) > ZV
)
1412 XSETFASTINT (lim
, ZV
);
1413 if (XINT (lim
) < BEGV
)
1414 XSETFASTINT (lim
, BEGV
);
1416 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1417 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1418 string_multibyte
= SBYTES (string
) > SCHARS (string
);
1420 bzero (fastmap
, sizeof fastmap
);
1422 str
= SDATA (string
);
1423 size_byte
= SBYTES (string
);
1426 if (i_byte
< size_byte
1427 && SREF (string
, 0) == '^')
1429 negate
= 1; i_byte
++;
1432 /* Find the characters specified and set their elements of fastmap.
1433 Handle backslashes and ranges specially.
1435 If STRING contains non-ASCII characters, setup char_ranges for
1436 them and use fastmap only for their leading codes. */
1438 if (! string_multibyte
)
1440 int string_has_eight_bit
= 0;
1442 /* At first setup fastmap. */
1443 while (i_byte
< size_byte
)
1449 if (i_byte
== size_byte
)
1454 if (i_byte
< size_byte
1455 && str
[i_byte
] == '-')
1459 /* Skip over the dash. */
1462 if (i_byte
== size_byte
)
1465 /* Get the end of the range. */
1468 && i_byte
< size_byte
)
1475 if (! ASCII_CHAR_P (c2
))
1476 string_has_eight_bit
= 1;
1482 if (! ASCII_CHAR_P (c
))
1483 string_has_eight_bit
= 1;
1487 /* If the current range is multibyte and STRING contains
1488 eight-bit chars, arrange fastmap and setup char_ranges for
1489 the corresponding multibyte chars. */
1490 if (multibyte
&& string_has_eight_bit
)
1492 unsigned char fastmap2
[0400];
1493 int range_start_byte
, range_start_char
;
1495 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1496 bzero (fastmap
+ 0200, 0200);
1497 /* We are sure that this loop stops. */
1498 for (i
= 0200; ! fastmap2
[i
]; i
++);
1499 c
= unibyte_char_to_multibyte (i
);
1500 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1501 range_start_byte
= i
;
1502 range_start_char
= c
;
1503 char_ranges
= (int *) alloca (sizeof (int) * 128 * 2);
1504 for (i
= 129; i
< 0400; i
++)
1506 c
= unibyte_char_to_multibyte (i
);
1507 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1508 if (i
- range_start_byte
!= c
- range_start_char
)
1510 char_ranges
[n_char_ranges
++] = range_start_char
;
1511 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1512 + range_start_char
);
1513 range_start_byte
= i
;
1514 range_start_char
= c
;
1517 char_ranges
[n_char_ranges
++] = range_start_char
;
1518 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1519 + range_start_char
);
1522 else /* STRING is multibyte */
1524 char_ranges
= (int *) alloca (sizeof (int) * SCHARS (string
) * 2);
1526 while (i_byte
< size_byte
)
1528 unsigned char leading_code
;
1530 leading_code
= str
[i_byte
];
1531 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1536 if (i_byte
== size_byte
)
1539 leading_code
= str
[i_byte
];
1540 c
= STRING_CHAR_AND_LENGTH (str
+i_byte
, size_byte
-i_byte
, len
);
1543 if (i_byte
< size_byte
1544 && str
[i_byte
] == '-')
1547 unsigned char leading_code2
;
1549 /* Skip over the dash. */
1552 if (i_byte
== size_byte
)
1555 /* Get the end of the range. */
1556 leading_code2
= str
[i_byte
];
1557 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1561 && i_byte
< size_byte
)
1563 leading_code2
= str
[i_byte
];
1564 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1570 if (ASCII_CHAR_P (c
))
1572 while (c
<= c2
&& c
< 0x80)
1574 leading_code
= CHAR_LEADING_CODE (c
);
1576 if (! ASCII_CHAR_P (c
))
1578 while (leading_code
<= leading_code2
)
1579 fastmap
[leading_code
++] = 1;
1582 char_ranges
[n_char_ranges
++] = c
;
1583 char_ranges
[n_char_ranges
++] = c2
;
1589 if (ASCII_CHAR_P (c
))
1593 fastmap
[leading_code
] = 1;
1594 char_ranges
[n_char_ranges
++] = c
;
1595 char_ranges
[n_char_ranges
++] = c
;
1600 /* If the current range is unibyte and STRING contains non-ASCII
1601 chars, arrange fastmap for the corresponding unibyte
1604 if (! multibyte
&& n_char_ranges
> 0)
1606 bzero (fastmap
+ 0200, 0200);
1607 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1609 int c1
= char_ranges
[i
];
1610 int c2
= char_ranges
[i
+ 1];
1612 for (; c1
<= c2
; c1
++)
1613 fastmap
[CHAR_TO_BYTE8 (c1
)] = 1;
1618 /* If ^ was the first character, complement the fastmap. */
1622 for (i
= 0; i
< sizeof fastmap
; i
++)
1626 for (i
= 0; i
< 0200; i
++)
1628 /* All non-ASCII chars possibly match. */
1629 for (; i
< sizeof fastmap
; i
++)
1635 int start_point
= PT
;
1637 int pos_byte
= PT_BYTE
;
1638 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1642 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1643 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1647 endp
= CHAR_POS_ADDR (XINT (lim
));
1648 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1668 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1669 if (! ASCII_CHAR_P (c
))
1671 /* As we are looking at a multibyte character, we
1672 must look up the character in the table
1673 CHAR_RANGES. If there's no data in the table,
1674 that character is not what we want to skip. */
1676 /* The following code do the right thing even if
1677 n_char_ranges is zero (i.e. no data in
1679 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1680 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1682 if (!(negate
^ (i
< n_char_ranges
)))
1685 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1699 p
++, pos
++, pos_byte
++;
1707 unsigned char *prev_p
;
1717 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1720 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1721 if (! ASCII_CHAR_P (c
))
1723 /* See the comment in the previous similar code. */
1724 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1725 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1727 if (!(negate
^ (i
< n_char_ranges
)))
1730 pos
--, pos_byte
-= prev_p
- p
;
1742 if (!fastmap
[p
[-1]])
1744 p
--, pos
--, pos_byte
--;
1748 SET_PT_BOTH (pos
, pos_byte
);
1751 return make_number (PT
- start_point
);
1757 skip_syntaxes (forwardp
, string
, lim
)
1759 Lisp_Object string
, lim
;
1761 register unsigned int c
;
1762 unsigned char fastmap
[0400];
1764 register int i
, i_byte
;
1769 CHECK_STRING (string
);
1772 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1774 CHECK_NUMBER_COERCE_MARKER (lim
);
1776 /* In any case, don't allow scan outside bounds of buffer. */
1777 if (XINT (lim
) > ZV
)
1778 XSETFASTINT (lim
, ZV
);
1779 if (XINT (lim
) < BEGV
)
1780 XSETFASTINT (lim
, BEGV
);
1782 if (forwardp
? (PT
>= XFASTINT (lim
)) : (PT
<= XFASTINT (lim
)))
1785 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1786 && (XINT (lim
) - PT
!= CHAR_TO_BYTE (XINT (lim
)) - PT_BYTE
));
1788 bzero (fastmap
, sizeof fastmap
);
1790 if (SBYTES (string
) > SCHARS (string
))
1791 /* As this is very rare case (syntax spec is ASCII only), don't
1792 consider efficiency. */
1793 string
= string_make_unibyte (string
);
1795 str
= SDATA (string
);
1796 size_byte
= SBYTES (string
);
1799 if (i_byte
< size_byte
1800 && SREF (string
, 0) == '^')
1802 negate
= 1; i_byte
++;
1805 /* Find the syntaxes specified and set their elements of fastmap. */
1807 while (i_byte
< size_byte
)
1810 fastmap
[syntax_spec_code
[c
]] = 1;
1813 /* If ^ was the first character, complement the fastmap. */
1815 for (i
= 0; i
< sizeof fastmap
; i
++)
1819 int start_point
= PT
;
1821 int pos_byte
= PT_BYTE
;
1822 unsigned char *p
= PT_ADDR
, *endp
, *stop
;
1826 endp
= (XINT (lim
) == GPT
) ? GPT_ADDR
: CHAR_POS_ADDR (XINT (lim
));
1827 stop
= (pos
< GPT
&& GPT
< XINT (lim
)) ? GPT_ADDR
: endp
;
1831 endp
= CHAR_POS_ADDR (XINT (lim
));
1832 stop
= (pos
>= GPT
&& GPT
> XINT (lim
)) ? GAP_END_ADDR
: endp
;
1836 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1852 c
= STRING_CHAR_AND_LENGTH (p
, MAX_MULTIBYTE_LENGTH
, nbytes
);
1853 if (! fastmap
[(int) SYNTAX (c
)])
1855 p
+= nbytes
, pos
++, pos_byte
+= nbytes
;
1856 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1870 if (! fastmap
[(int) SYNTAX (*p
)])
1872 p
++, pos
++, pos_byte
++;
1873 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1883 unsigned char *prev_p
;
1893 while (--p
>= stop
&& ! CHAR_HEAD_P (*p
));
1894 c
= STRING_CHAR (p
, MAX_MULTIBYTE_LENGTH
);
1895 if (! fastmap
[(int) SYNTAX (c
)])
1897 pos
--, pos_byte
-= prev_p
- p
;
1898 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
1912 if (! fastmap
[(int) SYNTAX (p
[-1])])
1914 p
--, pos
--, pos_byte
--;
1915 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
1920 SET_PT_BOTH (pos
, pos_byte
);
1923 return make_number (PT
- start_point
);
1927 /* Jump over a comment, assuming we are at the beginning of one.
1928 FROM is the current position.
1929 FROM_BYTE is the bytepos corresponding to FROM.
1930 Do not move past STOP (a charpos).
1931 The comment over which we have to jump is of style STYLE
1932 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
1933 NESTING should be positive to indicate the nesting at the beginning
1934 for nested comments and should be zero or negative else.
1935 ST_COMMENT_STYLE cannot be nested.
1936 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
1937 (or 0 If the search cannot start in the middle of a two-character).
1939 If successful, return 1 and store the charpos of the comment's end
1940 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
1941 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
1942 corresponding bytepos into *BYTEPOS_PTR and the current nesting
1943 (as defined for state.incomment) in *INCOMMENT_PTR.
1945 The comment end is the last character of the comment rather than the
1946 character just after the comment.
1948 Global syntax data is assumed to initially be valid for FROM and
1949 remains valid for forward search starting at the returned position. */
1952 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
1953 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
1954 int from
, from_byte
, stop
;
1955 int nesting
, style
, prev_syntax
;
1956 int *charpos_ptr
, *bytepos_ptr
, *incomment_ptr
;
1959 register enum syntaxcode code
;
1960 register int syntax
;
1962 if (nesting
<= 0) nesting
= -1;
1964 /* Enter the loop in the middle so that we find
1965 a 2-char comment ender if we start in the middle of it. */
1966 syntax
= prev_syntax
;
1967 if (syntax
!= 0) goto forw_incomment
;
1973 *incomment_ptr
= nesting
;
1974 *charpos_ptr
= from
;
1975 *bytepos_ptr
= from_byte
;
1978 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1979 syntax
= SYNTAX_WITH_FLAGS (c
);
1980 code
= syntax
& 0xff;
1981 if (code
== Sendcomment
1982 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
1983 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
1984 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
1985 /* we have encountered a comment end of the same style
1986 as the comment sequence which began this comment
1989 if (code
== Scomment_fence
1990 && style
== ST_COMMENT_STYLE
)
1991 /* we have encountered a comment end of the same style
1992 as the comment sequence which began this comment
1997 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
1998 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
1999 /* we have encountered a nested comment of the same style
2000 as the comment sequence which began this comment section */
2002 INC_BOTH (from
, from_byte
);
2003 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2006 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
2007 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
2008 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2009 SYNTAX_COMEND_SECOND (c1
))
2010 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2011 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
2014 /* we have encountered a comment end of the same style
2015 as the comment sequence which began this comment
2020 INC_BOTH (from
, from_byte
);
2021 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2026 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
2027 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2028 SYNTAX_COMMENT_STYLE (c1
) == style
2029 && SYNTAX_COMSTART_SECOND (c1
))
2030 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
2031 SYNTAX_COMMENT_NESTED (c1
)))
2032 /* we have encountered a nested comment of the same style
2033 as the comment sequence which began this comment
2036 INC_BOTH (from
, from_byte
);
2037 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2041 *charpos_ptr
= from
;
2042 *bytepos_ptr
= from_byte
;
2046 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
2048 Move forward across up to COUNT comments. If COUNT is negative, move backward.
2049 Stop scanning if we find something other than a comment or whitespace.
2050 Set point to where scanning stops.
2051 If COUNT comments are found as expected, with nothing except whitespace
2052 between them, return t; otherwise return nil. */)
2060 register enum syntaxcode code
;
2061 int comstyle
= 0; /* style of comment encountered */
2062 int comnested
= 0; /* whether the comment is nestable or not */
2065 int out_charpos
, out_bytepos
;
2068 CHECK_NUMBER (count
);
2069 count1
= XINT (count
);
2070 stop
= count1
> 0 ? ZV
: BEGV
;
2076 from_byte
= PT_BYTE
;
2078 SETUP_SYNTAX_TABLE (from
, count1
);
2087 SET_PT_BOTH (from
, from_byte
);
2091 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2093 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2094 comnested
= SYNTAX_COMMENT_NESTED (c
);
2095 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2096 INC_BOTH (from
, from_byte
);
2097 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2098 if (from
< stop
&& comstart_first
2099 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2100 SYNTAX_COMSTART_SECOND (c1
)))
2102 /* We have encountered a comment start sequence and we
2103 are ignoring all text inside comments. We must record
2104 the comment style this sequence begins so that later,
2105 only a comment end of the same style actually ends
2106 the comment section. */
2108 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2109 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2110 INC_BOTH (from
, from_byte
);
2111 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2114 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2116 if (code
== Scomment_fence
)
2117 comstyle
= ST_COMMENT_STYLE
;
2118 else if (code
!= Scomment
)
2121 DEC_BOTH (from
, from_byte
);
2122 SET_PT_BOTH (from
, from_byte
);
2125 /* We're at the start of a comment. */
2126 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2127 &out_charpos
, &out_bytepos
, &dummy
);
2128 from
= out_charpos
; from_byte
= out_bytepos
;
2132 SET_PT_BOTH (from
, from_byte
);
2135 INC_BOTH (from
, from_byte
);
2136 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2137 /* We have skipped one comment. */
2149 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2154 DEC_BOTH (from
, from_byte
);
2155 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2156 quoted
= char_quoted (from
, from_byte
);
2157 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2160 comnested
= SYNTAX_COMMENT_NESTED (c
);
2161 if (code
== Sendcomment
)
2162 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2163 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2164 && prev_char_comend_first (from
, from_byte
)
2165 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2167 /* We must record the comment style encountered so that
2168 later, we can match only the proper comment begin
2169 sequence of the same style. */
2170 DEC_BOTH (from
, from_byte
);
2172 /* Calling char_quoted, above, set up global syntax position
2173 at the new value of FROM. */
2174 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2175 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2176 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2179 if (code
== Scomment_fence
)
2181 /* Skip until first preceding unquoted comment_fence. */
2182 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2186 DEC_BOTH (from
, from_byte
);
2189 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2190 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2191 if (SYNTAX (c
) == Scomment_fence
2192 && !char_quoted (from
, from_byte
))
2200 from
= ini
; /* Set point to ini + 1. */
2201 from_byte
= ini_byte
;
2205 else if (code
== Sendcomment
)
2207 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2208 &out_charpos
, &out_bytepos
);
2212 /* This end-of-line is not an end-of-comment.
2213 Treat it like a whitespace.
2214 CC-mode (and maybe others) relies on this behavior. */
2218 /* Failure: we should go back to the end of this
2219 not-quite-endcomment. */
2220 if (SYNTAX(c
) != code
)
2221 /* It was a two-char Sendcomment. */
2222 INC_BOTH (from
, from_byte
);
2228 /* We have skipped one comment. */
2229 from
= out_charpos
, from_byte
= out_bytepos
;
2233 else if (code
!= Swhitespace
|| quoted
)
2237 INC_BOTH (from
, from_byte
);
2238 SET_PT_BOTH (from
, from_byte
);
2246 SET_PT_BOTH (from
, from_byte
);
2251 /* Return syntax code of character C if C is an ASCII character
2252 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2254 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2255 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2256 ? SYNTAX (c) : Ssymbol)
2259 scan_lists (from
, count
, depth
, sexpflag
)
2261 int count
, depth
, sexpflag
;
2264 register int stop
= count
> 0 ? ZV
: BEGV
;
2269 register enum syntaxcode code
, temp_code
;
2270 int min_depth
= depth
; /* Err out if depth gets less than this. */
2271 int comstyle
= 0; /* style of comment encountered */
2272 int comnested
= 0; /* whether the comment is nestable or not */
2274 int last_good
= from
;
2277 int out_bytepos
, out_charpos
;
2279 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2281 if (depth
> 0) min_depth
= 0;
2283 if (from
> ZV
) from
= ZV
;
2284 if (from
< BEGV
) from
= BEGV
;
2286 from_byte
= CHAR_TO_BYTE (from
);
2291 SETUP_SYNTAX_TABLE (from
, count
);
2296 int comstart_first
, prefix
;
2297 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2298 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2299 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2300 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2301 comnested
= SYNTAX_COMMENT_NESTED (c
);
2302 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2303 prefix
= SYNTAX_PREFIX (c
);
2304 if (depth
== min_depth
)
2306 INC_BOTH (from
, from_byte
);
2307 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2308 if (from
< stop
&& comstart_first
2309 && SYNTAX_COMSTART_SECOND (FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2310 && parse_sexp_ignore_comments
)
2312 /* we have encountered a comment start sequence and we
2313 are ignoring all text inside comments. We must record
2314 the comment style this sequence begins so that later,
2315 only a comment end of the same style actually ends
2316 the comment section */
2318 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2319 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2320 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2321 INC_BOTH (from
, from_byte
);
2322 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2328 switch (SWITCH_ENUM_CAST (code
))
2332 if (from
== stop
) goto lose
;
2333 INC_BOTH (from
, from_byte
);
2334 /* treat following character as a word constituent */
2337 if (depth
|| !sexpflag
) break;
2338 /* This word counts as a sexp; return at end of it. */
2341 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2343 /* Some compilers can't handle this inside the switch. */
2344 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2345 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2350 INC_BOTH (from
, from_byte
);
2351 if (from
== stop
) goto lose
;
2360 INC_BOTH (from
, from_byte
);
2364 case Scomment_fence
:
2365 comstyle
= ST_COMMENT_STYLE
;
2368 if (!parse_sexp_ignore_comments
) break;
2369 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2370 found
= forw_comment (from
, from_byte
, stop
,
2371 comnested
, comstyle
, 0,
2372 &out_charpos
, &out_bytepos
, &dummy
);
2373 from
= out_charpos
, from_byte
= out_bytepos
;
2380 INC_BOTH (from
, from_byte
);
2381 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2387 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2389 INC_BOTH (from
, from_byte
);
2399 if (!++depth
) goto done
;
2404 if (!--depth
) goto done
;
2405 if (depth
< min_depth
)
2406 Fsignal (Qscan_error
,
2407 Fcons (build_string ("Containing expression ends prematurely"),
2408 Fcons (make_number (last_good
),
2409 Fcons (make_number (from
), Qnil
))));
2414 temp_pos
= dec_bytepos (from_byte
);
2415 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2418 if (from
>= stop
) goto lose
;
2419 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2420 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2423 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2424 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2427 /* Some compilers can't handle this inside the switch. */
2428 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2433 INC_BOTH (from
, from_byte
);
2435 INC_BOTH (from
, from_byte
);
2437 INC_BOTH (from
, from_byte
);
2438 if (!depth
&& sexpflag
) goto done
;
2441 /* Ignore whitespace, punctuation, quote, endcomment. */
2446 /* Reached end of buffer. Error if within object, return nil if between */
2447 if (depth
) goto lose
;
2452 /* End of object reached */
2461 DEC_BOTH (from
, from_byte
);
2462 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2463 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2464 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2465 if (depth
== min_depth
)
2468 comnested
= SYNTAX_COMMENT_NESTED (c
);
2469 if (code
== Sendcomment
)
2470 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2471 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2472 && prev_char_comend_first (from
, from_byte
)
2473 && parse_sexp_ignore_comments
)
2475 /* We must record the comment style encountered so that
2476 later, we can match only the proper comment begin
2477 sequence of the same style. */
2478 DEC_BOTH (from
, from_byte
);
2479 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2481 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2482 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2483 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2486 /* Quoting turns anything except a comment-ender
2487 into a word character. Note that this cannot be true
2488 if we decremented FROM in the if-statement above. */
2489 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2491 DEC_BOTH (from
, from_byte
);
2494 else if (SYNTAX_PREFIX (c
))
2497 switch (SWITCH_ENUM_CAST (code
))
2503 if (depth
|| !sexpflag
) break;
2504 /* This word counts as a sexp; count object finished
2505 after passing it. */
2508 temp_pos
= from_byte
;
2509 if (! NILP (current_buffer
->enable_multibyte_characters
))
2513 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2514 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2515 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2516 /* Don't allow comment-end to be quoted. */
2517 if (temp_code
== Sendcomment
)
2519 quoted
= char_quoted (from
- 1, temp_pos
);
2522 DEC_BOTH (from
, from_byte
);
2523 temp_pos
= dec_bytepos (temp_pos
);
2524 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2526 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2527 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2528 if (! (quoted
|| temp_code
== Sword
2529 || temp_code
== Ssymbol
2530 || temp_code
== Squote
))
2532 DEC_BOTH (from
, from_byte
);
2539 temp_pos
= dec_bytepos (from_byte
);
2540 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2541 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2542 DEC_BOTH (from
, from_byte
);
2551 if (!++depth
) goto done2
;
2556 if (!--depth
) goto done2
;
2557 if (depth
< min_depth
)
2558 Fsignal (Qscan_error
,
2559 Fcons (build_string ("Containing expression ends prematurely"),
2560 Fcons (make_number (last_good
),
2561 Fcons (make_number (from
), Qnil
))));
2565 if (!parse_sexp_ignore_comments
)
2567 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2568 &out_charpos
, &out_bytepos
);
2569 /* FIXME: if found == -1, then it really wasn't a comment-end.
2570 For single-char Sendcomment, we can't do much about it apart
2571 from skipping the char.
2572 For 2-char endcomments, we could try again, taking both
2573 chars as separate entities, but it's a lot of trouble
2574 for very little gain, so we don't bother either. -sm */
2576 from
= out_charpos
, from_byte
= out_bytepos
;
2579 case Scomment_fence
:
2583 DEC_BOTH (from
, from_byte
);
2584 if (from
== stop
) goto lose
;
2585 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2586 if (!char_quoted (from
, from_byte
)
2587 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2588 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2591 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2595 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2598 if (from
== stop
) goto lose
;
2599 temp_pos
= from_byte
;
2600 if (! NILP (current_buffer
->enable_multibyte_characters
))
2604 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2605 if (!char_quoted (from
- 1, temp_pos
)
2606 && stringterm
== (c
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2607 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2609 DEC_BOTH (from
, from_byte
);
2611 DEC_BOTH (from
, from_byte
);
2612 if (!depth
&& sexpflag
) goto done2
;
2615 /* Ignore whitespace, punctuation, quote, endcomment. */
2620 /* Reached start of buffer. Error if within object, return nil if between */
2621 if (depth
) goto lose
;
2632 XSETFASTINT (val
, from
);
2636 Fsignal (Qscan_error
,
2637 Fcons (build_string ("Unbalanced parentheses"),
2638 Fcons (make_number (last_good
),
2639 Fcons (make_number (from
), Qnil
))));
2644 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2645 doc
: /* Scan from character number FROM by COUNT lists.
2646 Returns the character number of the position thus found.
2648 If DEPTH is nonzero, paren depth begins counting from that value,
2649 only places where the depth in parentheses becomes zero
2650 are candidates for stopping; COUNT such places are counted.
2651 Thus, a positive value for DEPTH means go out levels.
2653 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2655 If the beginning or end of (the accessible part of) the buffer is reached
2656 and the depth is wrong, an error is signaled.
2657 If the depth is right but the count is not used up, nil is returned. */)
2658 (from
, count
, depth
)
2659 Lisp_Object from
, count
, depth
;
2661 CHECK_NUMBER (from
);
2662 CHECK_NUMBER (count
);
2663 CHECK_NUMBER (depth
);
2665 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2668 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2669 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2670 If COUNT is negative, scan backwards.
2671 Returns the character number of the position thus found.
2673 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2675 If the beginning or end of (the accessible part of) the buffer is reached
2676 in the middle of a parenthetical grouping, an error is signaled.
2677 If the beginning or end is reached between groupings
2678 but before count is used up, nil is returned. */)
2680 Lisp_Object from
, count
;
2682 CHECK_NUMBER (from
);
2683 CHECK_NUMBER (count
);
2685 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2688 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2690 doc
: /* Move point backward over any number of chars with prefix syntax.
2691 This includes chars with "quote" or "prefix" syntax (' or p). */)
2696 int opoint_byte
= PT_BYTE
;
2698 int pos_byte
= PT_BYTE
;
2703 SET_PT_BOTH (opoint
, opoint_byte
);
2708 SETUP_SYNTAX_TABLE (pos
, -1);
2710 DEC_BOTH (pos
, pos_byte
);
2712 while (!char_quoted (pos
, pos_byte
)
2713 /* Previous statement updates syntax table. */
2714 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2715 || SYNTAX_PREFIX (c
)))
2718 opoint_byte
= pos_byte
;
2721 DEC_BOTH (pos
, pos_byte
);
2724 SET_PT_BOTH (opoint
, opoint_byte
);
2729 /* Parse forward from FROM / FROM_BYTE to END,
2730 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2731 and return a description of the state of the parse at END.
2732 If STOPBEFORE is nonzero, stop at the start of an atom.
2733 If COMMENTSTOP is 1, stop at the start of a comment.
2734 If COMMENTSTOP is -1, stop at the start or end of a comment,
2735 after the beginning of a string, or after the end of a string. */
2738 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2739 stopbefore
, oldstate
, commentstop
)
2740 struct lisp_parse_state
*stateptr
;
2743 int end
, targetdepth
, stopbefore
;
2744 Lisp_Object oldstate
;
2747 struct lisp_parse_state state
;
2749 register enum syntaxcode code
;
2752 struct level
{ int last
, prev
; };
2753 struct level levelstart
[100];
2754 register struct level
*curlevel
= levelstart
;
2755 struct level
*endlevel
= levelstart
+ 100;
2756 register int depth
; /* Paren depth of current scanning location.
2757 level - levelstart equals this except
2758 when the depth becomes negative. */
2759 int mindepth
; /* Lowest DEPTH value seen. */
2760 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2762 int prev_from
; /* Keep one character before FROM. */
2764 int prev_from_syntax
;
2765 int boundary_stop
= commentstop
== -1;
2768 int out_bytepos
, out_charpos
;
2772 prev_from_byte
= from_byte
;
2774 DEC_BOTH (prev_from
, prev_from_byte
);
2776 /* Use this macro instead of `from++'. */
2778 do { prev_from = from; \
2779 prev_from_byte = from_byte; \
2781 = SYNTAX_WITH_FLAGS (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte)); \
2782 INC_BOTH (from, from_byte); \
2784 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2790 if (NILP (oldstate
))
2793 state
.instring
= -1;
2794 state
.incomment
= 0;
2795 state
.comstyle
= 0; /* comment style a by default. */
2796 state
.comstr_start
= -1; /* no comment/string seen. */
2800 tem
= Fcar (oldstate
);
2806 oldstate
= Fcdr (oldstate
);
2807 oldstate
= Fcdr (oldstate
);
2808 oldstate
= Fcdr (oldstate
);
2809 tem
= Fcar (oldstate
);
2810 /* Check whether we are inside string_fence-style string: */
2811 state
.instring
= (!NILP (tem
)
2812 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2815 oldstate
= Fcdr (oldstate
);
2816 tem
= Fcar (oldstate
);
2817 state
.incomment
= (!NILP (tem
)
2818 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
2821 oldstate
= Fcdr (oldstate
);
2822 tem
= Fcar (oldstate
);
2823 start_quoted
= !NILP (tem
);
2825 /* if the eighth element of the list is nil, we are in comment
2826 style a. If it is non-nil, we are in comment style b */
2827 oldstate
= Fcdr (oldstate
);
2828 oldstate
= Fcdr (oldstate
);
2829 tem
= Fcar (oldstate
);
2830 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
2831 ? ST_COMMENT_STYLE
: 1);
2833 oldstate
= Fcdr (oldstate
);
2834 tem
= Fcar (oldstate
);
2835 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2836 oldstate
= Fcdr (oldstate
);
2837 tem
= Fcar (oldstate
);
2838 while (!NILP (tem
)) /* >= second enclosing sexps. */
2840 /* curlevel++->last ran into compiler bug on Apollo */
2841 curlevel
->last
= XINT (Fcar (tem
));
2842 if (++curlevel
== endlevel
)
2843 curlevel
--; /* error ("Nesting too deep for parser"); */
2844 curlevel
->prev
= -1;
2845 curlevel
->last
= -1;
2852 curlevel
->prev
= -1;
2853 curlevel
->last
= -1;
2855 SETUP_SYNTAX_TABLE (prev_from
, 1);
2856 prev_from_syntax
= SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte
));
2857 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2859 /* Enter the loop at a place appropriate for initial state. */
2861 if (state
.incomment
)
2862 goto startincomment
;
2863 if (state
.instring
>= 0)
2865 nofence
= state
.instring
!= ST_STRING_STYLE
;
2867 goto startquotedinstring
;
2870 else if (start_quoted
)
2876 code
= prev_from_syntax
& 0xff;
2878 if (code
== Scomment
)
2880 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
2881 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
2883 state
.comstr_start
= prev_from
;
2885 else if (code
== Scomment_fence
)
2887 /* Record the comment style we have entered so that only
2888 the comment-end sequence of the same style actually
2889 terminates the comment section. */
2890 state
.comstyle
= ST_COMMENT_STYLE
;
2891 state
.incomment
= -1;
2892 state
.comstr_start
= prev_from
;
2895 else if (from
< end
)
2896 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
))
2897 if (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2898 SYNTAX_COMSTART_SECOND (c1
))
2899 /* Duplicate code to avoid a complex if-expression
2900 which causes trouble for the SGI compiler. */
2902 /* Record the comment style we have entered so that only
2903 the comment-end sequence of the same style actually
2904 terminates the comment section. */
2905 state
.comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2906 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
2907 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2908 state
.incomment
= comnested
? 1 : -1;
2909 state
.comstr_start
= prev_from
;
2914 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
2916 switch (SWITCH_ENUM_CAST (code
))
2920 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2921 curlevel
->last
= prev_from
;
2923 if (from
== end
) goto endquoted
;
2926 /* treat following character as a word constituent */
2929 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2930 curlevel
->last
= prev_from
;
2934 /* Some compilers can't handle this inside the switch. */
2935 temp
= SYNTAX (FETCH_CHAR_AS_MULTIBYTE (from_byte
));
2941 if (from
== end
) goto endquoted
;
2953 curlevel
->prev
= curlevel
->last
;
2956 case Scomment_fence
: /* Can't happen because it's handled above. */
2958 if (commentstop
|| boundary_stop
) goto done
;
2960 /* The (from == BEGV) test was to enter the loop in the middle so
2961 that we find a 2-char comment ender even if we start in the
2962 middle of it. We don't want to do that if we're just at the
2963 beginning of the comment (think of (*) ... (*)). */
2964 found
= forw_comment (from
, from_byte
, end
,
2965 state
.incomment
, state
.comstyle
,
2966 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
2967 ? 0 : prev_from_syntax
,
2968 &out_charpos
, &out_bytepos
, &state
.incomment
);
2969 from
= out_charpos
; from_byte
= out_bytepos
;
2970 /* Beware! prev_from and friends are invalid now.
2971 Luckily, the `done' doesn't use them and the INC_FROM
2972 sets them to a sane value without looking at them. */
2973 if (!found
) goto done
;
2975 state
.incomment
= 0;
2976 state
.comstyle
= 0; /* reset the comment style */
2977 if (boundary_stop
) goto done
;
2981 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2983 /* curlevel++->last ran into compiler bug on Apollo */
2984 curlevel
->last
= prev_from
;
2985 if (++curlevel
== endlevel
)
2986 curlevel
--; /* error ("Nesting too deep for parser"); */
2987 curlevel
->prev
= -1;
2988 curlevel
->last
= -1;
2989 if (targetdepth
== depth
) goto done
;
2994 if (depth
< mindepth
)
2996 if (curlevel
!= levelstart
)
2998 curlevel
->prev
= curlevel
->last
;
2999 if (targetdepth
== depth
) goto done
;
3004 state
.comstr_start
= from
- 1;
3005 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
3006 curlevel
->last
= prev_from
;
3007 state
.instring
= (code
== Sstring
3008 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
3010 if (boundary_stop
) goto done
;
3013 nofence
= state
.instring
!= ST_STRING_STYLE
;
3019 if (from
>= end
) goto done
;
3020 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
3021 /* Some compilers can't handle this inside the switch. */
3024 /* Check TEMP here so that if the char has
3025 a syntax-table property which says it is NOT
3026 a string character, it does not end the string. */
3027 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
3033 if (!nofence
) goto string_end
;
3038 startquotedinstring
:
3039 if (from
>= end
) goto endquoted
;
3045 state
.instring
= -1;
3046 curlevel
->prev
= curlevel
->last
;
3048 if (boundary_stop
) goto done
;
3052 /* FIXME: We should do something with it. */
3055 /* Ignore whitespace, punctuation, quote, endcomment. */
3061 stop
: /* Here if stopping before start of sexp. */
3062 from
= prev_from
; /* We have just fetched the char that starts it; */
3063 goto done
; /* but return the position before it. */
3068 state
.depth
= depth
;
3069 state
.mindepth
= mindepth
;
3070 state
.thislevelstart
= curlevel
->prev
;
3071 state
.prevlevelstart
3072 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
3073 state
.location
= from
;
3074 state
.levelstarts
= Qnil
;
3075 while (--curlevel
>= levelstart
)
3076 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
3083 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
3084 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3085 Parsing stops at TO or when certain criteria are met;
3086 point is set to where parsing stops.
3087 If fifth arg OLDSTATE is omitted or nil,
3088 parsing assumes that FROM is the beginning of a function.
3089 Value is a list of ten elements describing final state of parsing:
3091 1. character address of start of innermost containing list; nil if none.
3092 2. character address of start of last complete sexp terminated.
3093 3. non-nil if inside a string.
3094 (it is the character that will terminate the string,
3095 or t if the string should be terminated by a generic string delimiter.)
3096 4. nil if outside a comment, t if inside a non-nestable comment,
3097 else an integer (the current comment nesting).
3098 5. t if following a quote character.
3099 6. the minimum paren-depth encountered during this scan.
3100 7. t if in a comment of style b; symbol `syntax-table' if the comment
3101 should be terminated by a generic comment delimiter.
3102 8. character address of start of comment or string; nil if not in one.
3103 9. Intermediate data for continuation of parsing (subject to change).
3104 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3105 in parentheses becomes equal to TARGETDEPTH.
3106 Fourth arg STOPBEFORE non-nil means stop when come to
3107 any character that starts a sexp.
3108 Fifth arg OLDSTATE is a nine-element list like what this function returns.
3109 It is used to initialize the state of the parse. Elements number 1, 2, 6
3110 and 8 are ignored; you can leave off element 8 (the last) entirely.
3111 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3112 If it is symbol `syntax-table', stop after the start of a comment or a
3113 string, or after end of a comment or a string. */)
3114 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3115 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3117 struct lisp_parse_state state
;
3120 if (!NILP (targetdepth
))
3122 CHECK_NUMBER (targetdepth
);
3123 target
= XINT (targetdepth
);
3126 target
= -100000; /* We won't reach this depth */
3128 validate_region (&from
, &to
);
3129 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3131 target
, !NILP (stopbefore
), oldstate
,
3133 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3135 SET_PT (state
.location
);
3137 return Fcons (make_number (state
.depth
),
3138 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3139 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3140 Fcons (state
.instring
>= 0
3141 ? (state
.instring
== ST_STRING_STYLE
3142 ? Qt
: make_number (state
.instring
)) : Qnil
,
3143 Fcons (state
.incomment
< 0 ? Qt
:
3144 (state
.incomment
== 0 ? Qnil
:
3145 make_number (state
.incomment
)),
3146 Fcons (state
.quoted
? Qt
: Qnil
,
3147 Fcons (make_number (state
.mindepth
),
3148 Fcons ((state
.comstyle
3149 ? (state
.comstyle
== ST_COMMENT_STYLE
3150 ? Qsyntax_table
: Qt
) :
3152 Fcons (((state
.incomment
3153 || (state
.instring
>= 0))
3154 ? make_number (state
.comstr_start
)
3156 Fcons (state
.levelstarts
, Qnil
))))))))));
3165 /* This has to be done here, before we call Fmake_char_table. */
3166 Qsyntax_table
= intern ("syntax-table");
3167 staticpro (&Qsyntax_table
);
3169 /* Intern this now in case it isn't already done.
3170 Setting this variable twice is harmless.
3171 But don't staticpro it here--that is done in alloc.c. */
3172 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3174 /* Create objects which can be shared among syntax tables. */
3175 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3176 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3177 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3178 = Fcons (make_number (i
), Qnil
);
3180 /* Now we are ready to set up this property, so we can
3181 create syntax tables. */
3182 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3184 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3186 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3188 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3189 for (i
= 'a'; i
<= 'z'; i
++)
3190 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3191 for (i
= 'A'; i
<= 'Z'; i
++)
3192 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3193 for (i
= '0'; i
<= '9'; i
++)
3194 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3196 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3197 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3199 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3200 Fcons (make_number (Sopen
), make_number (')')));
3201 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3202 Fcons (make_number (Sclose
), make_number ('(')));
3203 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3204 Fcons (make_number (Sopen
), make_number (']')));
3205 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3206 Fcons (make_number (Sclose
), make_number ('[')));
3207 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3208 Fcons (make_number (Sopen
), make_number ('}')));
3209 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3210 Fcons (make_number (Sclose
), make_number ('{')));
3211 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3212 Fcons (make_number ((int) Sstring
), Qnil
));
3213 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3214 Fcons (make_number ((int) Sescape
), Qnil
));
3216 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3217 for (i
= 0; i
< 10; i
++)
3219 c
= "_-+*/&|<>="[i
];
3220 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3223 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3224 for (i
= 0; i
< 12; i
++)
3226 c
= ".,;:?!#@~^'`"[i
];
3227 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3230 /* All multibyte characters have syntax `word' by default. */
3231 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3232 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3238 Qsyntax_table_p
= intern ("syntax-table-p");
3239 staticpro (&Qsyntax_table_p
);
3241 staticpro (&Vsyntax_code_object
);
3243 Qscan_error
= intern ("scan-error");
3244 staticpro (&Qscan_error
);
3245 Fput (Qscan_error
, Qerror_conditions
,
3246 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3247 Fput (Qscan_error
, Qerror_message
,
3248 build_string ("Scan error"));
3250 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3251 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3253 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3254 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3255 Otherwise, that text property is simply ignored.
3256 See the info node `(elisp)Syntax Properties' for a description of the
3257 `syntax-table' property. */);
3259 words_include_escapes
= 0;
3260 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3261 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3263 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3264 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
3265 multibyte_syntax_as_symbol
= 0;
3267 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3268 &open_paren_in_column_0_is_defun_start
,
3269 doc
: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
3270 open_paren_in_column_0_is_defun_start
= 1;
3273 DEFVAR_LISP ("find-word-boundary-function-table",
3274 &Vfind_word_boundary_function_table
,
3276 Char table of functions to search for the word boundary.
3277 Each function is called with two arguments; POS and LIMIT.
3278 POS and LIMIT are character positions in the current buffer.
3280 If POS is less than LIMIT, POS is at the first character of a word,
3281 and the return value of a function is a position after the last
3282 character of that word.
3284 If POS is not less than LIMIT, POS is at the last character of a word,
3285 and the return value of a function is a position at the first
3286 character of that word.
3288 In both cases, LIMIT bounds the search. */);
3289 Vfind_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3291 defsubr (&Ssyntax_table_p
);
3292 defsubr (&Ssyntax_table
);
3293 defsubr (&Sstandard_syntax_table
);
3294 defsubr (&Scopy_syntax_table
);
3295 defsubr (&Sset_syntax_table
);
3296 defsubr (&Schar_syntax
);
3297 defsubr (&Smatching_paren
);
3298 defsubr (&Sstring_to_syntax
);
3299 defsubr (&Smodify_syntax_entry
);
3300 defsubr (&Sinternal_describe_syntax_value
);
3302 defsubr (&Sforward_word
);
3304 defsubr (&Sskip_chars_forward
);
3305 defsubr (&Sskip_chars_backward
);
3306 defsubr (&Sskip_syntax_forward
);
3307 defsubr (&Sskip_syntax_backward
);
3309 defsubr (&Sforward_comment
);
3310 defsubr (&Sscan_lists
);
3311 defsubr (&Sscan_sexps
);
3312 defsubr (&Sbackward_prefix_chars
);
3313 defsubr (&Sparse_partial_sexp
);