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 the beginning of every line 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 /* Use previous finding, if it's valid and applies to this inquiry. */
358 if (current_buffer
== find_start_buffer
359 /* Reuse the defun-start even if POS is a little farther on.
360 POS might be in the next defun, but that's ok.
361 Our value may not be the best possible, but will still be usable. */
362 && pos
<= find_start_pos
+ 1000
363 && pos
>= find_start_value
364 && BEGV
== find_start_begv
365 && MODIFF
== find_start_modiff
)
366 return find_start_value
;
368 /* Back up to start of line. */
369 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
371 /* We optimize syntax-table lookup for rare updates. Thus we accept
372 only those `^\s(' which are good in global _and_ text-property
374 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
375 gl_state
.use_global
= 0;
376 if (open_paren_in_column_0_is_defun_start
)
380 /* Open-paren at start of line means we may have found our
382 if (SYNTAX (FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
)) == Sopen
)
384 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
385 if (SYNTAX (FETCH_CHAR_AS_MULTIBYTE (PT_BYTE
)) == Sopen
)
387 /* Now fallback to the default value. */
388 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
389 gl_state
.use_global
= 0;
391 /* Move to beg of previous line. */
392 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
396 /* Record what we found, for the next try. */
397 find_start_value
= PT
;
398 find_start_value_byte
= PT_BYTE
;
399 find_start_buffer
= current_buffer
;
400 find_start_modiff
= MODIFF
;
401 find_start_begv
= BEGV
;
402 find_start_pos
= pos
;
404 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
406 return find_start_value
;
409 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
412 prev_char_comend_first (pos
, pos_byte
)
417 DEC_BOTH (pos
, pos_byte
);
418 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
419 c
= FETCH_CHAR (pos_byte
);
420 val
= SYNTAX_COMEND_FIRST (c
);
421 UPDATE_SYNTAX_TABLE_FORWARD (pos
+ 1);
425 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
428 * prev_char_comstart_first (pos, pos_byte)
433 * DEC_BOTH (pos, pos_byte);
434 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
435 * c = FETCH_CHAR (pos_byte);
436 * val = SYNTAX_COMSTART_FIRST (c);
437 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
441 /* Checks whether charpos FROM is at the end of a comment.
442 FROM_BYTE is the bytepos corresponding to FROM.
443 Do not move back before STOP.
445 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
448 If successful, store the charpos of the comment's beginning
449 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
451 Global syntax data remains valid for backward search starting at
452 the returned value (or at FROM, if the search was not successful). */
455 back_comment (from
, from_byte
, stop
, comnested
, comstyle
, charpos_ptr
, bytepos_ptr
)
456 int from
, from_byte
, stop
;
457 int comnested
, comstyle
;
458 int *charpos_ptr
, *bytepos_ptr
;
460 /* Look back, counting the parity of string-quotes,
461 and recording the comment-starters seen.
462 When we reach a safe place, assume that's not in a string;
463 then step the main scan to the earliest comment-starter seen
464 an even number of string quotes away from the safe place.
466 OFROM[I] is position of the earliest comment-starter seen
467 which is I+2X quotes from the comment-end.
468 PARITY is current parity of quotes from the comment end. */
469 int string_style
= -1; /* Presumed outside of any string. */
470 int string_lossage
= 0;
471 /* Not a real lossage: indicates that we have passed a matching comment
472 starter plus an non-matching comment-ender, meaning that any matching
473 comment-starter we might see later could be a false positive (hidden
474 inside another comment).
475 Test case: { a (* b } c (* d *) */
476 int comment_lossage
= 0;
477 int comment_end
= from
;
478 int comment_end_byte
= from_byte
;
479 int comstart_pos
= 0;
481 /* Place where the containing defun starts,
482 or 0 if we didn't come across it yet. */
484 int defun_start_byte
= 0;
485 register enum syntaxcode code
;
486 int nesting
= 1; /* current comment nesting */
490 /* FIXME: A }} comment-ender style leads to incorrect behavior
491 in the case of {{ c }}} because we ignore the last two chars which are
492 assumed to be comment-enders although they aren't. */
494 /* At beginning of range to scan, we're outside of strings;
495 that determines quote parity to the comment-end. */
498 int temp_byte
, prev_syntax
;
499 int com2start
, com2end
;
501 /* Move back and examine a character. */
502 DEC_BOTH (from
, from_byte
);
503 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
505 prev_syntax
= syntax
;
506 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
507 syntax
= SYNTAX_WITH_FLAGS (c
);
510 /* Check for 2-char comment markers. */
511 com2start
= (SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
512 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax
)
513 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax
)
514 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
515 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
);
516 com2end
= (SYNTAX_FLAGS_COMEND_FIRST (syntax
)
517 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax
));
519 /* Nasty cases with overlapping 2-char comment markers:
520 - snmp-mode: -- c -- foo -- c --
528 /* If a 2-char comment sequence partly overlaps with another,
529 we don't try to be clever. */
530 if (from
> stop
&& (com2end
|| com2start
))
532 int next
= from
, next_byte
= from_byte
, next_c
, next_syntax
;
533 DEC_BOTH (next
, next_byte
);
534 UPDATE_SYNTAX_TABLE_BACKWARD (next
);
535 next_c
= FETCH_CHAR_AS_MULTIBYTE (next_byte
);
536 next_syntax
= SYNTAX_WITH_FLAGS (next_c
);
537 if (((com2start
|| comnested
)
538 && SYNTAX_FLAGS_COMEND_SECOND (syntax
)
539 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax
))
540 || ((com2end
|| comnested
)
541 && SYNTAX_FLAGS_COMSTART_SECOND (syntax
)
542 && comstyle
== SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
543 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax
)))
545 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
548 if (com2start
&& comstart_pos
== 0)
549 /* We're looking at a comment starter. But it might be a comment
550 ender as well (see snmp-mode). The first time we see one, we
551 need to consider it as a comment starter,
552 and the subsequent times as a comment ender. */
555 /* Turn a 2-char comment sequences into the appropriate syntax. */
560 /* Ignore comment starters of a different style. */
561 else if (code
== Scomment
562 && (comstyle
!= SYNTAX_FLAGS_COMMENT_STYLE (syntax
)
563 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
) != comnested
))
566 /* Ignore escaped characters, except comment-enders. */
567 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
574 c
= (code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
);
576 /* Track parity of quotes. */
577 if (string_style
== -1)
578 /* Entering a string. */
580 else if (string_style
== c
)
581 /* Leaving the string. */
584 /* If we have two kinds of string delimiters.
585 There's no way to grok this scanning backwards. */
590 /* We've already checked that it is the relevant comstyle. */
591 if (string_style
!= -1 || comment_lossage
|| string_lossage
)
592 /* There are odd string quotes involved, so let's be careful.
593 Test case in Pascal: " { " a { " } */
598 /* Record best comment-starter so far. */
600 comstart_byte
= from_byte
;
602 else if (--nesting
<= 0)
603 /* nested comments have to be balanced, so we don't need to
604 keep looking for earlier ones. We use here the same (slightly
605 incorrect) reasoning as below: since it is followed by uniform
606 paired string quotes, this comment-start has to be outside of
607 strings, else the comment-end itself would be inside a string. */
612 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == comstyle
613 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax
)
614 || SYNTAX_FLAGS_COMMENT_NESTED (syntax
)) == comnested
)
615 /* This is the same style of comment ender as ours. */
620 /* Anything before that can't count because it would match
621 this comment-ender rather than ours. */
622 from
= stop
; /* Break out of the loop. */
624 else if (comstart_pos
!= 0 || c
!= '\n')
625 /* We're mixing comment styles here, so we'd better be careful.
626 The (comstart_pos != 0 || c != '\n') check is not quite correct
627 (we should just always set comment_lossage), but removing it
628 would imply that any multiline comment in C would go through
629 lossage, which seems overkill.
630 The failure should only happen in the rare cases such as
636 /* Assume a defun-start point is outside of strings. */
637 if (open_paren_in_column_0_is_defun_start
639 || (temp_byte
= dec_bytepos (from_byte
),
640 FETCH_CHAR (temp_byte
) == '\n')))
643 defun_start_byte
= from_byte
;
644 from
= stop
; /* Break out of the loop. */
653 if (comstart_pos
== 0)
656 from_byte
= comment_end_byte
;
657 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
659 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
660 or `done'), then we've found the beginning of the non-nested comment. */
661 else if (1) /* !comnested */
664 from_byte
= comstart_byte
;
665 /* Globals are correct now. */
669 struct lisp_parse_state state
;
671 /* We had two kinds of string delimiters mixed up
672 together. Decode this going forwards.
673 Scan fwd from a known safe place (beginning-of-defun)
674 to the one in question; this records where we
675 last passed a comment starter. */
676 /* If we did not already find the defun start, find it now. */
677 if (defun_start
== 0)
679 defun_start
= find_defun_start (comment_end
, comment_end_byte
);
680 defun_start_byte
= find_start_value_byte
;
684 scan_sexps_forward (&state
,
685 defun_start
, defun_start_byte
,
686 comment_end
, -10000, 0, Qnil
, 0);
687 defun_start
= comment_end
;
688 if (state
.incomment
== (comnested
? 1 : -1)
689 && state
.comstyle
== comstyle
)
690 from
= state
.comstr_start
;
695 /* If comment_end is inside some other comment, maybe ours
696 is nested, so we need to try again from within the
697 surrounding comment. Example: { a (* " *) */
699 /* FIXME: We should advance by one or two chars. */
700 defun_start
= state
.comstr_start
+ 2;
701 defun_start_byte
= CHAR_TO_BYTE (defun_start
);
704 } while (defun_start
< comment_end
);
706 from_byte
= CHAR_TO_BYTE (from
);
707 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
712 *bytepos_ptr
= from_byte
;
714 return (from
== comment_end
) ? -1 : from
;
717 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
718 doc
: /* Return t if OBJECT is a syntax table.
719 Currently, any char-table counts as a syntax table. */)
723 if (CHAR_TABLE_P (object
)
724 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
730 check_syntax_table (obj
)
733 if (!(CHAR_TABLE_P (obj
)
734 && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
)))
735 wrong_type_argument (Qsyntax_table_p
, obj
);
738 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
739 doc
: /* Return the current syntax table.
740 This is the one specified by the current buffer. */)
743 return current_buffer
->syntax_table
;
746 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
747 Sstandard_syntax_table
, 0, 0, 0,
748 doc
: /* Return the standard syntax table.
749 This is the one used for new buffers. */)
752 return Vstandard_syntax_table
;
755 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
756 doc
: /* Construct a new syntax table and return it.
757 It is a copy of the TABLE, which defaults to the standard syntax table. */)
764 check_syntax_table (table
);
766 table
= Vstandard_syntax_table
;
768 copy
= Fcopy_sequence (table
);
770 /* Only the standard syntax table should have a default element.
771 Other syntax tables should inherit from parents instead. */
772 XCHAR_TABLE (copy
)->defalt
= Qnil
;
774 /* Copied syntax tables should all have parents.
775 If we copied one with no parent, such as the standard syntax table,
776 use the standard syntax table as the copy's parent. */
777 if (NILP (XCHAR_TABLE (copy
)->parent
))
778 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
782 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
783 doc
: /* Select a new syntax table for the current buffer.
784 One argument, a syntax table. */)
789 check_syntax_table (table
);
790 current_buffer
->syntax_table
= table
;
791 /* Indicate that this buffer now has a specified syntax table. */
792 idx
= PER_BUFFER_VAR_IDX (syntax_table
);
793 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 1);
797 /* Convert a letter which signifies a syntax code
798 into the code it signifies.
799 This is used by modify-syntax-entry, and other things. */
801 unsigned char syntax_spec_code
[0400] =
802 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
803 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
804 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
805 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
806 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
807 (char) Smath
, 0377, 0377, (char) Squote
,
808 (char) Sopen
, (char) Sclose
, 0377, 0377,
809 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
810 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
811 0377, 0377, 0377, 0377,
812 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
813 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
814 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
815 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
816 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
817 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
818 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
819 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
820 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
823 /* Indexed by syntax code, give the letter that describes it. */
825 char syntax_code_spec
[16] =
827 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
831 /* Indexed by syntax code, give the object (cons of syntax code and
832 nil) to be stored in syntax table. Since these objects can be
833 shared among syntax tables, we generate them in advance. By
834 sharing objects, the function `describe-syntax' can give a more
836 static Lisp_Object Vsyntax_code_object
;
839 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
840 doc
: /* Return the syntax code of CHARACTER, described by a character.
841 For example, if CHARACTER is a word constituent,
842 the character `w' is returned.
843 The characters that correspond to various syntax codes
844 are listed in the documentation of `modify-syntax-entry'. */)
846 Lisp_Object character
;
849 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
851 gl_state
.use_global
= 0;
852 CHECK_NUMBER (character
);
853 char_int
= XINT (character
);
854 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
857 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
858 doc
: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
860 Lisp_Object character
;
863 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
864 gl_state
.use_global
= 0;
865 CHECK_NUMBER (character
);
866 char_int
= XINT (character
);
867 code
= SYNTAX (char_int
);
868 if (code
== Sopen
|| code
== Sclose
)
869 return SYNTAX_MATCH (char_int
);
873 DEFUN ("string-to-syntax", Fstring_to_syntax
, Sstring_to_syntax
, 1, 1, 0,
874 doc
: /* Convert a syntax specification STRING into syntax cell form.
875 STRING should be a string as it is allowed as argument of
876 `modify-syntax-entry'. Value is the equivalent cons cell
877 (CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
882 register unsigned char *p
;
883 register enum syntaxcode code
;
887 CHECK_STRING (string
);
889 p
= XSTRING (string
)->data
;
890 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
891 if (((int) code
& 0377) == 0377)
892 error ("invalid syntax description letter: %c", p
[-1]);
894 if (code
== Sinherit
)
900 int character
= (STRING_CHAR_AND_LENGTH
901 (p
, STRING_BYTES (XSTRING (string
)) - 1, len
));
902 XSETINT (match
, character
);
903 if (XFASTINT (match
) == ' ')
943 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
944 return XVECTOR (Vsyntax_code_object
)->contents
[val
];
946 /* Since we can't use a shared object, let's make a new one. */
947 return Fcons (make_number (val
), match
);
950 /* I really don't know why this is interactive
951 help-form should at least be made useful whilst reading the second arg. */
952 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
953 "cSet syntax for character: \nsSet syntax for %s to: ",
954 doc
: /* Set syntax for character CHAR according to string NEWENTRY.
955 The syntax is changed only for table SYNTAX_TABLE, which defaults to
956 the current buffer's syntax table.
957 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
958 in the range MIN and MAX are changed.
959 The first character of NEWENTRY should be one of the following:
960 Space or - whitespace syntax. w word constituent.
961 _ symbol constituent. . punctuation.
962 ( open-parenthesis. ) close-parenthesis.
963 " string quote. \\ escape.
964 $ paired delimiter. ' expression quote or prefix operator.
965 < comment starter. > comment ender.
966 / character-quote. @ inherit from `standard-syntax-table'.
967 | generic string fence. ! generic comment fence.
969 Only single-character comment start and end sequences are represented thus.
970 Two-character sequences are represented as described below.
971 The second character of NEWENTRY is the matching parenthesis,
972 used only if the first character is `(' or `)'.
973 Any additional characters are flags.
974 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
975 1 means CHAR is the start of a two-char comment start sequence.
976 2 means CHAR is the second character of such a sequence.
977 3 means CHAR is the start of a two-char comment end sequence.
978 4 means CHAR is the second character of such a sequence.
980 There can be up to two orthogonal comment sequences. This is to support
981 language modes such as C++. By default, all comment sequences are of style
982 a, but you can set the comment sequence style to b (on the second character
983 of a comment-start, or the first character of a comment-end sequence) using
985 b means CHAR is part of comment sequence b.
986 n means CHAR is part of a nestable comment sequence.
988 p means CHAR is a prefix character for `backward-prefix-chars';
989 such characters are treated as whitespace when they occur
991 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
992 (c
, newentry
, syntax_table
)
993 Lisp_Object c
, newentry
, syntax_table
;
997 CHECK_CHARACTER (XCAR (c
));
998 CHECK_CHARACTER (XCDR (c
));
1001 CHECK_CHARACTER (c
);
1003 if (NILP (syntax_table
))
1004 syntax_table
= current_buffer
->syntax_table
;
1006 check_syntax_table (syntax_table
);
1008 newentry
= Fstring_to_syntax (newentry
);
1010 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table
, c
, newentry
);
1012 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
1016 /* Dump syntax table to buffer in human-readable format */
1018 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value
,
1019 Sinternal_describe_syntax_value
, 1, 1, 0,
1020 doc
: /* Insert a description of the internal syntax description SYNTAX at point. */)
1024 register enum syntaxcode code
;
1025 char desc
, start1
, start2
, end1
, end2
, prefix
, comstyle
, comnested
;
1027 Lisp_Object first
, match_lisp
, value
= syntax
;
1031 insert_string ("default");
1035 if (CHAR_TABLE_P (value
))
1037 insert_string ("deeper char-table ...");
1043 insert_string ("invalid");
1047 first
= XCAR (value
);
1048 match_lisp
= XCDR (value
);
1050 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
1052 insert_string ("invalid");
1056 code
= (enum syntaxcode
) (XINT (first
) & 0377);
1057 start1
= (XINT (first
) >> 16) & 1;
1058 start2
= (XINT (first
) >> 17) & 1;
1059 end1
= (XINT (first
) >> 18) & 1;
1060 end2
= (XINT (first
) >> 19) & 1;
1061 prefix
= (XINT (first
) >> 20) & 1;
1062 comstyle
= (XINT (first
) >> 21) & 1;
1063 comnested
= (XINT (first
) >> 22) & 1;
1065 if ((int) code
< 0 || (int) code
>= (int) Smax
)
1067 insert_string ("invalid");
1070 desc
= syntax_code_spec
[(int) code
];
1072 str
[0] = desc
, str
[1] = 0;
1075 if (NILP (match_lisp
))
1078 insert_char (XINT (match_lisp
));
1097 insert_string ("\twhich means: ");
1099 switch (SWITCH_ENUM_CAST (code
))
1102 insert_string ("whitespace"); break;
1104 insert_string ("punctuation"); break;
1106 insert_string ("word"); break;
1108 insert_string ("symbol"); break;
1110 insert_string ("open"); break;
1112 insert_string ("close"); break;
1114 insert_string ("prefix"); break;
1116 insert_string ("string"); break;
1118 insert_string ("math"); break;
1120 insert_string ("escape"); break;
1122 insert_string ("charquote"); break;
1124 insert_string ("comment"); break;
1126 insert_string ("endcomment"); break;
1128 insert_string ("inherit"); break;
1129 case Scomment_fence
:
1130 insert_string ("comment fence"); break;
1132 insert_string ("string fence"); break;
1134 insert_string ("invalid");
1138 if (!NILP (match_lisp
))
1140 insert_string (", matches ");
1141 insert_char (XINT (match_lisp
));
1145 insert_string (",\n\t is the first character of a comment-start sequence");
1147 insert_string (",\n\t is the second character of a comment-start sequence");
1150 insert_string (",\n\t is the first character of a comment-end sequence");
1152 insert_string (",\n\t is the second character of a comment-end sequence");
1154 insert_string (" (comment style b)");
1156 insert_string (" (nestable)");
1159 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
1164 int parse_sexp_ignore_comments
;
1166 Lisp_Object Vnext_word_boundary_function_table
;
1168 /* Return the position across COUNT words from FROM.
1169 If that many words cannot be found before the end of the buffer, return 0.
1170 COUNT negative means scan backward and stop at word beginning. */
1173 scan_words (from
, count
)
1174 register int from
, count
;
1176 register int beg
= BEGV
;
1177 register int end
= ZV
;
1178 register int from_byte
= CHAR_TO_BYTE (from
);
1179 register enum syntaxcode code
;
1185 SETUP_SYNTAX_TABLE (from
, count
);
1198 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1199 ch0
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1200 code
= SYNTAX (ch0
);
1201 INC_BOTH (from
, from_byte
);
1202 if (words_include_escapes
1203 && (code
== Sescape
|| code
== Scharquote
))
1208 /* Now CH0 is a character which begins a word and FROM is the
1209 position of the next character. */
1210 func
= CHAR_TABLE_REF (Vnext_word_boundary_function_table
, ch0
);
1211 if (! NILP (Ffboundp (func
)))
1215 pos
= call2 (func
, make_number (from
- 1), make_number (end
));
1217 from_byte
= CHAR_TO_BYTE (from
);
1223 script
= CHAR_TABLE_REF (Vchar_script_table
, ch0
);
1226 if (from
== end
) break;
1227 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1228 ch1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
1229 code
= SYNTAX (ch1
);
1231 && (! words_include_escapes
1232 || (code
!= Sescape
&& code
!= Scharquote
)))
1233 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch1
), script
))
1235 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 (Vnext_word_boundary_function_table
, ch1
);
1266 if (! NILP (Ffboundp (func
)))
1270 pos
= call2 (func
, make_number (from
), make_number (beg
));
1272 from_byte
= CHAR_TO_BYTE (from
);
1278 script
= CHAR_TABLE_REF (Vchar_script_table
, ch1
);
1285 temp_byte
= dec_bytepos (from_byte
);
1286 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1287 ch0
= FETCH_CHAR_AS_MULTIBYTE (temp_byte
);
1288 code
= SYNTAX (ch0
);
1290 && (! words_include_escapes
1291 || (code
!= Sescape
&& code
!= Scharquote
)))
1292 || ! EQ (CHAR_TABLE_REF (Vchar_script_table
, ch0
), script
))
1294 DEC_BOTH (from
, from_byte
);
1306 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 1, 1, "p",
1307 doc
: /* Move point forward ARG words (backward if ARG is negative).
1309 If an edge of the buffer or a field boundary is reached, point is left there
1310 and the function returns nil. Field boundaries are not noticed if
1311 `inhibit-field-text-motion' is non-nil. */)
1316 CHECK_NUMBER (count
);
1318 val
= orig_val
= scan_words (PT
, XINT (count
));
1320 val
= XINT (count
) > 0 ? ZV
: BEGV
;
1322 /* Avoid jumping out of an input field. */
1323 val
= XFASTINT (Fconstrain_to_field (make_number (val
), make_number (PT
),
1327 return val
== orig_val
? Qt
: Qnil
;
1330 Lisp_Object
skip_chars ();
1332 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1333 doc
: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1334 STRING is like the inside of a `[...]' in a regular expression
1335 except that `]' is never special and `\\' quotes `^', `-' or `\\'
1336 (but not as the end of a range; quoting is never needed there).
1337 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
1338 With arg "^a-zA-Z", skips nonletters stopping before first letter.
1339 Returns the distance traveled, either zero or positive. */)
1341 Lisp_Object string
, lim
;
1343 return skip_chars (1, string
, lim
);
1346 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1347 doc
: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
1348 See `skip-chars-forward' for details.
1349 Returns the distance traveled, either zero or negative. */)
1351 Lisp_Object string
, lim
;
1353 return skip_chars (0, string
, lim
);
1356 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1357 doc
: /* Move point forward across chars in specified syntax classes.
1358 SYNTAX is a string of syntax code characters.
1359 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
1360 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1361 This function returns the distance traveled, either zero or positive. */)
1363 Lisp_Object syntax
, lim
;
1365 return skip_syntaxes (1, syntax
, lim
);
1368 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1369 doc
: /* Move point backward across chars in specified syntax classes.
1370 SYNTAX is a string of syntax code characters.
1371 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
1372 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
1373 This function returns the distance traveled, either zero or negative. */)
1375 Lisp_Object syntax
, lim
;
1377 return skip_syntaxes (0, syntax
, lim
);
1381 skip_chars (forwardp
, string
, lim
)
1383 Lisp_Object string
, lim
;
1385 register unsigned int c
;
1386 unsigned char fastmap
[0400];
1387 /* Store the ranges of non-ASCII characters. */
1389 int n_char_ranges
= 0;
1391 register int i
, i_byte
;
1392 /* Set to 1 if the current buffer is multibyte and the region
1393 contains non-ASCII chars. */
1395 /* Set to 1 if STRING is multibyte and it contains non-ASCII
1397 int string_multibyte
;
1402 CHECK_STRING (string
);
1405 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1407 CHECK_NUMBER_COERCE_MARKER (lim
);
1409 /* In any case, don't allow scan outside bounds of buffer. */
1410 if (XINT (lim
) > ZV
)
1411 XSETFASTINT (lim
, ZV
);
1412 if (XINT (lim
) < BEGV
)
1413 XSETFASTINT (lim
, BEGV
);
1415 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1416 && (lim
- PT
!= CHAR_TO_BYTE (lim
) - PT_BYTE
));
1417 string_multibyte
= STRING_BYTES (XSTRING (string
)) > XSTRING (string
)->size
;
1419 bzero (fastmap
, sizeof fastmap
);
1421 char_ranges
= (int *) alloca (XSTRING (string
)->size
* (sizeof (int)) * 2);
1423 str
= XSTRING (string
)->data
;
1424 size_byte
= STRING_BYTES (XSTRING (string
));
1427 if (i_byte
< size_byte
1428 && XSTRING (string
)->data
[0] == '^')
1430 negate
= 1; i_byte
++;
1433 /* Find the characters specified and set their elements of fastmap.
1434 Handle backslashes and ranges specially.
1436 If STRING contains non-ASCII characters, setup char_ranges for
1437 them and use fastmap only for their leading codes. */
1439 if (! string_multibyte
)
1441 int string_has_eight_bit
= 0;
1443 /* At first setup fastmap. */
1444 while (i_byte
< size_byte
)
1450 if (i_byte
== size_byte
)
1455 if (i_byte
< size_byte
1456 && str
[i_byte
] == '-')
1460 /* Skip over the dash. */
1463 if (i_byte
== size_byte
)
1466 /* Get the end of the range. */
1469 && i_byte
< size_byte
)
1474 if (! ASCII_CHAR_P (c2
))
1475 string_has_eight_bit
= 1;
1480 if (! ASCII_CHAR_P (c
))
1481 string_has_eight_bit
= 1;
1485 /* If the current range is multibyte and STRING contains
1486 eight-bit chars, arrange fastmap and setup char_ranges for
1487 the corresponding multibyte chars. */
1488 if (multibyte
&& string_has_eight_bit
)
1490 unsigned char fastmap2
[0400];
1491 int range_start_byte
, range_start_char
;
1493 bcopy (fastmap2
+ 0200, fastmap
+ 0200, 0200);
1494 bzero (fastmap
+ 0200, 0200);
1495 /* We are sure that this loop stops. */
1496 for (i
= 0200; ! fastmap2
[i
]; i
++);
1497 c
= unibyte_char_to_multibyte (i
);
1498 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1499 range_start_byte
= i
;
1500 range_start_char
= c
;
1501 for (i
= 129; i
< 0400; i
++)
1503 c
= unibyte_char_to_multibyte (i
);
1504 fastmap
[CHAR_LEADING_CODE (c
)] = 1;
1505 if (i
- range_start_byte
!= c
- range_start_char
)
1507 char_ranges
[n_char_ranges
++] = range_start_char
;
1508 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1509 + range_start_char
);
1510 range_start_byte
= i
;
1511 range_start_char
= c
;
1514 char_ranges
[n_char_ranges
++] = range_start_char
;
1515 char_ranges
[n_char_ranges
++] = ((i
- 1 - range_start_byte
)
1516 + range_start_char
);
1521 while (i_byte
< size_byte
)
1523 unsigned char leading_code
;
1525 leading_code
= str
[i_byte
];
1526 c
= STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1531 if (i_byte
== size_byte
)
1534 leading_code
= str
[i_byte
];
1535 c
= STRING_CHAR_AND_LENGTH (str
+i_byte
, size_byte
-i_byte
, len
);
1538 if (i_byte
< size_byte
1539 && str
[i_byte
] == '-')
1542 unsigned char leading_code2
;
1544 /* Skip over the dash. */
1547 if (i_byte
== size_byte
)
1550 /* Get the end of the range. */
1551 leading_code2
= str
[i_byte
];
1552 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1556 && i_byte
< size_byte
)
1558 leading_code2
= str
[i_byte
];
1559 c2
=STRING_CHAR_AND_LENGTH (str
+ i_byte
, size_byte
-i_byte
, len
);
1563 if (ASCII_CHAR_P (c
))
1565 while (c
<= c2
&& c
< 0x80)
1567 leading_code
= CHAR_LEADING_CODE (c
);
1569 if (! ASCII_CHAR_P (c
))
1571 while (leading_code
<= leading_code2
)
1572 fastmap
[leading_code
++] = 1;
1575 char_ranges
[n_char_ranges
++] = c
;
1576 char_ranges
[n_char_ranges
++] = c2
;
1582 if (ASCII_CHAR_P (c
))
1586 fastmap
[leading_code
] = 1;
1587 char_ranges
[n_char_ranges
++] = c
;
1588 char_ranges
[n_char_ranges
++] = c
;
1593 /* If the current range is unibyte and STRING contains non-ASCII
1594 chars, arrange fastmap for the corresponding unibyte
1597 if (! multibyte
&& n_char_ranges
> 0)
1599 bzero (fastmap
+ 0200, 0200);
1600 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1602 int c1
= char_ranges
[i
];
1603 int c2
= char_ranges
[i
+ 1];
1605 for (; c1
<= c2
; c1
++)
1606 fastmap
[CHAR_TO_BYTE8 (c1
)] = 1;
1611 /* If ^ was the first character, complement the fastmap. */
1615 for (i
= 0; i
< sizeof fastmap
; i
++)
1619 for (i
= 0; i
< 0200; i
++)
1621 /* All non-ASCII chars possibly match. */
1622 for (; i
< sizeof fastmap
; i
++)
1628 int start_point
= PT
;
1630 int pos_byte
= PT_BYTE
;
1636 while (pos
< XINT (lim
))
1638 c
= FETCH_BYTE (pos_byte
);
1641 if (! ASCII_CHAR_P (c
))
1643 c
= FETCH_MULTIBYTE_CHAR (pos_byte
);
1644 /* As we are looking at a multibyte character, we
1645 must look up the character in the table
1646 CHAR_RANGES. If there's no data in the table,
1647 that character is not what we want to skip. */
1649 /* The following code do the right thing even if
1650 n_char_ranges is zero (i.e. no data in
1652 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1653 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1655 if (!(negate
^ (i
< n_char_ranges
)))
1658 /* Since we already checked for multibyteness, avoid
1659 using INC_BOTH which checks again. */
1665 while (pos
< XINT (lim
) && fastmap
[FETCH_BYTE (pos_byte
)])
1672 while (pos
> XINT (lim
))
1674 int prev_pos_byte
= pos_byte
;
1676 DEC_POS (prev_pos_byte
);
1677 c
= FETCH_BYTE (prev_pos_byte
);
1680 if (! ASCII_CHAR_P (c
))
1682 c
= FETCH_MULTIBYTE_CHAR (prev_pos_byte
);
1683 /* See the comment in the previous similar code. */
1684 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1685 if (c
>= char_ranges
[i
] && c
<= char_ranges
[i
+ 1])
1687 if (!(negate
^ (i
< n_char_ranges
)))
1691 pos_byte
= prev_pos_byte
;
1695 while (pos
> XINT (lim
) && fastmap
[FETCH_BYTE (pos_byte
- 1)])
1700 SET_PT_BOTH (pos
, pos_byte
);
1703 return make_number (PT
- start_point
);
1709 skip_syntaxes (forwardp
, string
, lim
)
1711 Lisp_Object string
, lim
;
1713 register unsigned int c
;
1714 unsigned char fastmap
[0400];
1716 register int i
, i_byte
;
1721 CHECK_STRING (string
);
1724 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1726 CHECK_NUMBER_COERCE_MARKER (lim
);
1728 /* In any case, don't allow scan outside bounds of buffer. */
1729 if (XINT (lim
) > ZV
)
1730 XSETFASTINT (lim
, ZV
);
1731 if (XINT (lim
) < BEGV
)
1732 XSETFASTINT (lim
, BEGV
);
1734 multibyte
= (!NILP (current_buffer
->enable_multibyte_characters
)
1735 && (lim
- PT
!= CHAR_TO_BYTE (lim
) - PT_BYTE
));
1737 bzero (fastmap
, sizeof fastmap
);
1739 if (STRING_BYTES (XSTRING (string
)) > XSTRING (string
)->size
)
1740 /* As this is very rare case, don't consider efficiency. */
1741 string
= string_make_unibyte (string
);
1743 str
= XSTRING (string
)->data
;
1744 size_byte
= STRING_BYTES (XSTRING (string
));
1747 if (i_byte
< size_byte
1748 && XSTRING (string
)->data
[0] == '^')
1750 negate
= 1; i_byte
++;
1753 /* Find the syntaxes specified and set their elements of fastmap. */
1755 while (i_byte
< size_byte
)
1758 fastmap
[syntax_spec_code
[c
]] = 1;
1761 /* If ^ was the first character, complement the fastmap. */
1763 for (i
= 0; i
< sizeof fastmap
; i
++)
1767 int start_point
= PT
;
1769 int pos_byte
= PT_BYTE
;
1772 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1777 if (pos
< XINT (lim
))
1778 while (fastmap
[(int) SYNTAX (FETCH_CHAR (pos_byte
))])
1780 /* Since we already checked for multibyteness,
1781 avoid using INC_BOTH which checks again. */
1784 if (pos
>= XINT (lim
))
1786 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1791 while (pos
< XINT (lim
))
1793 c
= FETCH_BYTE (pos_byte
);
1794 MAKE_CHAR_MULTIBYTE (c
);
1795 if (! fastmap
[(int) SYNTAX (c
)])
1798 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1806 while (pos
> XINT (lim
))
1808 int savepos
= pos_byte
;
1809 /* Since we already checked for multibyteness,
1810 avoid using DEC_BOTH which checks again. */
1813 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
1814 if (!fastmap
[(int) SYNTAX (FETCH_CHAR (pos_byte
))])
1824 if (pos
> XINT (lim
))
1827 c
= FETCH_BYTE (pos_byte
- 1);
1828 MAKE_CHAR_MULTIBYTE (c
);
1829 if (! fastmap
[(int) SYNTAX (c
)])
1832 if (pos
<= XINT (lim
))
1834 UPDATE_SYNTAX_TABLE_BACKWARD (pos
- 1);
1839 SET_PT_BOTH (pos
, pos_byte
);
1842 return make_number (PT
- start_point
);
1846 /* Jump over a comment, assuming we are at the beginning of one.
1847 FROM is the current position.
1848 FROM_BYTE is the bytepos corresponding to FROM.
1849 Do not move past STOP (a charpos).
1850 The comment over which we have to jump is of style STYLE
1851 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
1852 NESTING should be positive to indicate the nesting at the beginning
1853 for nested comments and should be zero or negative else.
1854 ST_COMMENT_STYLE cannot be nested.
1855 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
1856 (or 0 If the search cannot start in the middle of a two-character).
1858 If successful, return 1 and store the charpos of the comment's end
1859 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
1860 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
1861 corresponding bytepos into *BYTEPOS_PTR and the current nesting
1862 (as defined for state.incomment) in *INCOMMENT_PTR.
1864 The comment end is the last character of the comment rather than the
1865 character just after the comment.
1867 Global syntax data is assumed to initially be valid for FROM and
1868 remains valid for forward search starting at the returned position. */
1871 forw_comment (from
, from_byte
, stop
, nesting
, style
, prev_syntax
,
1872 charpos_ptr
, bytepos_ptr
, incomment_ptr
)
1873 int from
, from_byte
, stop
;
1874 int nesting
, style
, prev_syntax
;
1875 int *charpos_ptr
, *bytepos_ptr
, *incomment_ptr
;
1878 register enum syntaxcode code
;
1879 register int syntax
;
1881 if (nesting
<= 0) nesting
= -1;
1883 /* Enter the loop in the middle so that we find
1884 a 2-char comment ender if we start in the middle of it. */
1885 syntax
= prev_syntax
;
1886 if (syntax
!= 0) goto forw_incomment
;
1892 *incomment_ptr
= nesting
;
1893 *charpos_ptr
= from
;
1894 *bytepos_ptr
= from_byte
;
1897 c
= FETCH_CHAR (from_byte
);
1898 syntax
= SYNTAX_WITH_FLAGS (c
);
1899 code
= syntax
& 0xff;
1900 if (code
== Sendcomment
1901 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
1902 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ?
1903 (nesting
> 0 && --nesting
== 0) : nesting
< 0))
1904 /* we have encountered a comment end of the same style
1905 as the comment sequence which began this comment
1908 if (code
== Scomment_fence
1909 && style
== ST_COMMENT_STYLE
)
1910 /* we have encountered a comment end of the same style
1911 as the comment sequence which began this comment
1916 && SYNTAX_FLAGS_COMMENT_NESTED (syntax
)
1917 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
)
1918 /* we have encountered a nested comment of the same style
1919 as the comment sequence which began this comment section */
1921 INC_BOTH (from
, from_byte
);
1922 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1925 if (from
< stop
&& SYNTAX_FLAGS_COMEND_FIRST (syntax
)
1926 && SYNTAX_FLAGS_COMMENT_STYLE (syntax
) == style
1927 && (c1
= FETCH_CHAR (from_byte
),
1928 SYNTAX_COMEND_SECOND (c1
))
1929 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
1930 SYNTAX_COMMENT_NESTED (c1
)) ? nesting
> 0 : nesting
< 0))
1933 /* we have encountered a comment end of the same style
1934 as the comment sequence which began this comment
1939 INC_BOTH (from
, from_byte
);
1940 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1945 && SYNTAX_FLAGS_COMSTART_FIRST (syntax
)
1946 && (c1
= FETCH_CHAR (from_byte
),
1947 SYNTAX_COMMENT_STYLE (c1
) == style
1948 && SYNTAX_COMSTART_SECOND (c1
))
1949 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax
) ||
1950 SYNTAX_COMMENT_NESTED (c1
)))
1951 /* we have encountered a nested comment of the same style
1952 as the comment sequence which began this comment
1955 INC_BOTH (from
, from_byte
);
1956 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1960 *charpos_ptr
= from
;
1961 *bytepos_ptr
= from_byte
;
1965 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
1966 doc
: /* Move forward across up to N comments. If N is negative, move backward.
1967 Stop scanning if we find something other than a comment or whitespace.
1968 Set point to where scanning stops.
1969 If N comments are found as expected, with nothing except whitespace
1970 between them, return t; otherwise return nil. */)
1978 register enum syntaxcode code
;
1979 int comstyle
= 0; /* style of comment encountered */
1980 int comnested
= 0; /* whether the comment is nestable or not */
1983 int out_charpos
, out_bytepos
;
1986 CHECK_NUMBER (count
);
1987 count1
= XINT (count
);
1988 stop
= count1
> 0 ? ZV
: BEGV
;
1994 from_byte
= PT_BYTE
;
1996 SETUP_SYNTAX_TABLE (from
, count1
);
2005 SET_PT_BOTH (from
, from_byte
);
2009 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2011 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2012 comnested
= SYNTAX_COMMENT_NESTED (c
);
2013 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2014 INC_BOTH (from
, from_byte
);
2015 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2016 if (from
< stop
&& comstart_first
2017 && (c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2018 SYNTAX_COMSTART_SECOND (c1
)))
2020 /* We have encountered a comment start sequence and we
2021 are ignoring all text inside comments. We must record
2022 the comment style this sequence begins so that later,
2023 only a comment end of the same style actually ends
2024 the comment section. */
2026 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2027 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2028 INC_BOTH (from
, from_byte
);
2029 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2032 while (code
== Swhitespace
|| (code
== Sendcomment
&& c
== '\n'));
2034 if (code
== Scomment_fence
)
2035 comstyle
= ST_COMMENT_STYLE
;
2036 else if (code
!= Scomment
)
2039 DEC_BOTH (from
, from_byte
);
2040 SET_PT_BOTH (from
, from_byte
);
2043 /* We're at the start of a comment. */
2044 found
= forw_comment (from
, from_byte
, stop
, comnested
, comstyle
, 0,
2045 &out_charpos
, &out_bytepos
, &dummy
);
2046 from
= out_charpos
; from_byte
= out_bytepos
;
2050 SET_PT_BOTH (from
, from_byte
);
2053 INC_BOTH (from
, from_byte
);
2054 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2055 /* We have skipped one comment. */
2067 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
2072 DEC_BOTH (from
, from_byte
);
2073 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
2074 quoted
= char_quoted (from
, from_byte
);
2075 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2078 comnested
= SYNTAX_COMMENT_NESTED (c
);
2079 if (code
== Sendcomment
)
2080 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2081 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2082 && prev_char_comend_first (from
, from_byte
)
2083 && !char_quoted (from
- 1, dec_bytepos (from_byte
)))
2085 /* We must record the comment style encountered so that
2086 later, we can match only the proper comment begin
2087 sequence of the same style. */
2088 DEC_BOTH (from
, from_byte
);
2090 /* Calling char_quoted, above, set up global syntax position
2091 at the new value of FROM. */
2092 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2093 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2094 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2097 if (code
== Scomment_fence
)
2099 /* Skip until first preceding unquoted comment_fence. */
2100 int found
= 0, ini
= from
, ini_byte
= from_byte
;
2104 DEC_BOTH (from
, from_byte
);
2107 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2108 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2109 if (SYNTAX (c
) == Scomment_fence
2110 && !char_quoted (from
, from_byte
))
2118 from
= ini
; /* Set point to ini + 1. */
2119 from_byte
= ini_byte
;
2123 else if (code
== Sendcomment
)
2125 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2126 &out_charpos
, &out_bytepos
);
2130 /* This end-of-line is not an end-of-comment.
2131 Treat it like a whitespace.
2132 CC-mode (and maybe others) relies on this behavior. */
2136 /* Failure: we should go back to the end of this
2137 not-quite-endcomment. */
2138 if (SYNTAX(c
) != code
)
2139 /* It was a two-char Sendcomment. */
2140 INC_BOTH (from
, from_byte
);
2146 /* We have skipped one comment. */
2147 from
= out_charpos
, from_byte
= out_bytepos
;
2151 else if (code
!= Swhitespace
|| quoted
)
2155 INC_BOTH (from
, from_byte
);
2156 SET_PT_BOTH (from
, from_byte
);
2164 SET_PT_BOTH (from
, from_byte
);
2169 /* Return syntax code of character C if C is an ASCII character
2170 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
2172 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
2173 ((ASCII_CHAR_P (c) || !multibyte_symbol_p) \
2174 ? SYNTAX (c) : Ssymbol)
2177 scan_lists (from
, count
, depth
, sexpflag
)
2179 int count
, depth
, sexpflag
;
2182 register int stop
= count
> 0 ? ZV
: BEGV
;
2187 register enum syntaxcode code
, temp_code
;
2188 int min_depth
= depth
; /* Err out if depth gets less than this. */
2189 int comstyle
= 0; /* style of comment encountered */
2190 int comnested
= 0; /* whether the comment is nestable or not */
2192 int last_good
= from
;
2195 int out_bytepos
, out_charpos
;
2197 int multibyte_symbol_p
= sexpflag
&& multibyte_syntax_as_symbol
;
2199 if (depth
> 0) min_depth
= 0;
2201 if (from
> ZV
) from
= ZV
;
2202 if (from
< BEGV
) from
= BEGV
;
2204 from_byte
= CHAR_TO_BYTE (from
);
2209 SETUP_SYNTAX_TABLE (from
, count
);
2214 int comstart_first
, prefix
;
2215 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2216 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2217 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2218 comstart_first
= SYNTAX_COMSTART_FIRST (c
);
2219 comnested
= SYNTAX_COMMENT_NESTED (c
);
2220 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2221 prefix
= SYNTAX_PREFIX (c
);
2222 if (depth
== min_depth
)
2224 INC_BOTH (from
, from_byte
);
2225 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2226 if (from
< stop
&& comstart_first
2227 && SYNTAX_COMSTART_SECOND (FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2228 && parse_sexp_ignore_comments
)
2230 /* we have encountered a comment start sequence and we
2231 are ignoring all text inside comments. We must record
2232 the comment style this sequence begins so that later,
2233 only a comment end of the same style actually ends
2234 the comment section */
2236 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2237 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2238 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2239 INC_BOTH (from
, from_byte
);
2240 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2246 switch (SWITCH_ENUM_CAST (code
))
2250 if (from
== stop
) goto lose
;
2251 INC_BOTH (from
, from_byte
);
2252 /* treat following character as a word constituent */
2255 if (depth
|| !sexpflag
) break;
2256 /* This word counts as a sexp; return at end of it. */
2259 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2261 /* Some compilers can't handle this inside the switch. */
2262 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2263 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2268 INC_BOTH (from
, from_byte
);
2269 if (from
== stop
) goto lose
;
2278 INC_BOTH (from
, from_byte
);
2282 case Scomment_fence
:
2283 comstyle
= ST_COMMENT_STYLE
;
2286 if (!parse_sexp_ignore_comments
) break;
2287 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2288 found
= forw_comment (from
, from_byte
, stop
,
2289 comnested
, comstyle
, 0,
2290 &out_charpos
, &out_bytepos
, &dummy
);
2291 from
= out_charpos
, from_byte
= out_bytepos
;
2298 INC_BOTH (from
, from_byte
);
2299 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2305 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (from_byte
))
2307 INC_BOTH (from
, from_byte
);
2317 if (!++depth
) goto done
;
2322 if (!--depth
) goto done
;
2323 if (depth
< min_depth
)
2324 Fsignal (Qscan_error
,
2325 Fcons (build_string ("Containing expression ends prematurely"),
2326 Fcons (make_number (last_good
),
2327 Fcons (make_number (from
), Qnil
))));
2332 temp_pos
= dec_bytepos (from_byte
);
2333 stringterm
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2336 if (from
>= stop
) goto lose
;
2337 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2338 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2341 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2342 : SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring_fence
)
2345 /* Some compilers can't handle this inside the switch. */
2346 temp
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2351 INC_BOTH (from
, from_byte
);
2353 INC_BOTH (from
, from_byte
);
2355 INC_BOTH (from
, from_byte
);
2356 if (!depth
&& sexpflag
) goto done
;
2361 /* Reached end of buffer. Error if within object, return nil if between */
2362 if (depth
) goto lose
;
2367 /* End of object reached */
2376 DEC_BOTH (from
, from_byte
);
2377 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2378 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2379 code
= SYNTAX_WITH_MULTIBYTE_CHECK (c
);
2380 if (depth
== min_depth
)
2383 comnested
= SYNTAX_COMMENT_NESTED (c
);
2384 if (code
== Sendcomment
)
2385 comstyle
= SYNTAX_COMMENT_STYLE (c
);
2386 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
2387 && prev_char_comend_first (from
, from_byte
)
2388 && parse_sexp_ignore_comments
)
2390 /* We must record the comment style encountered so that
2391 later, we can match only the proper comment begin
2392 sequence of the same style. */
2393 DEC_BOTH (from
, from_byte
);
2394 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2396 c1
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2397 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
2398 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2401 /* Quoting turns anything except a comment-ender
2402 into a word character. Note that this cannot be true
2403 if we decremented FROM in the if-statement above. */
2404 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
2406 else if (SYNTAX_PREFIX (c
))
2409 switch (SWITCH_ENUM_CAST (code
))
2415 if (depth
|| !sexpflag
) break;
2416 /* This word counts as a sexp; count object finished
2417 after passing it. */
2420 temp_pos
= from_byte
;
2421 if (! NILP (current_buffer
->enable_multibyte_characters
))
2425 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2426 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2427 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2428 /* Don't allow comment-end to be quoted. */
2429 if (temp_code
== Sendcomment
)
2431 quoted
= char_quoted (from
- 1, temp_pos
);
2434 DEC_BOTH (from
, from_byte
);
2435 temp_pos
= dec_bytepos (temp_pos
);
2436 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2438 c1
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
);
2439 temp_code
= SYNTAX_WITH_MULTIBYTE_CHECK (c1
);
2440 if (! (quoted
|| temp_code
== Sword
2441 || temp_code
== Ssymbol
2442 || temp_code
== Squote
))
2444 DEC_BOTH (from
, from_byte
);
2451 temp_pos
= dec_bytepos (from_byte
);
2452 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2453 if (from
!= stop
&& c
== FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2454 DEC_BOTH (from
, from_byte
);
2463 if (!++depth
) goto done2
;
2468 if (!--depth
) goto done2
;
2469 if (depth
< min_depth
)
2470 Fsignal (Qscan_error
,
2471 Fcons (build_string ("Containing expression ends prematurely"),
2472 Fcons (make_number (last_good
),
2473 Fcons (make_number (from
), Qnil
))));
2477 if (!parse_sexp_ignore_comments
)
2479 found
= back_comment (from
, from_byte
, stop
, comnested
, comstyle
,
2480 &out_charpos
, &out_bytepos
);
2481 /* FIXME: if found == -1, then it really wasn't a comment-end.
2482 For single-char Sendcomment, we can't do much about it apart
2483 from skipping the char.
2484 For 2-char endcomments, we could try again, taking both
2485 chars as separate entities, but it's a lot of trouble
2486 for very little gain, so we don't bother either. -sm */
2488 from
= out_charpos
, from_byte
= out_bytepos
;
2491 case Scomment_fence
:
2495 DEC_BOTH (from
, from_byte
);
2496 if (from
== stop
) goto lose
;
2497 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2498 if (!char_quoted (from
, from_byte
)
2499 && (c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
),
2500 SYNTAX_WITH_MULTIBYTE_CHECK (c
) == code
))
2503 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2507 stringterm
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2510 if (from
== stop
) goto lose
;
2511 temp_pos
= from_byte
;
2512 if (! NILP (current_buffer
->enable_multibyte_characters
))
2516 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2517 if (!char_quoted (from
- 1, temp_pos
)
2518 && stringterm
== (c
= FETCH_CHAR_AS_MULTIBYTE (temp_pos
))
2519 && SYNTAX_WITH_MULTIBYTE_CHECK (c
) == Sstring
)
2521 DEC_BOTH (from
, from_byte
);
2523 DEC_BOTH (from
, from_byte
);
2524 if (!depth
&& sexpflag
) goto done2
;
2529 /* Reached start of buffer. Error if within object, return nil if between */
2530 if (depth
) goto lose
;
2541 XSETFASTINT (val
, from
);
2545 Fsignal (Qscan_error
,
2546 Fcons (build_string ("Unbalanced parentheses"),
2547 Fcons (make_number (last_good
),
2548 Fcons (make_number (from
), Qnil
))));
2553 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2554 doc
: /* Scan from character number FROM by COUNT lists.
2555 Returns the character number of the position thus found.
2557 If DEPTH is nonzero, paren depth begins counting from that value,
2558 only places where the depth in parentheses becomes zero
2559 are candidates for stopping; COUNT such places are counted.
2560 Thus, a positive value for DEPTH means go out levels.
2562 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2564 If the beginning or end of (the accessible part of) the buffer is reached
2565 and the depth is wrong, an error is signaled.
2566 If the depth is right but the count is not used up, nil is returned. */)
2567 (from
, count
, depth
)
2568 Lisp_Object from
, count
, depth
;
2570 CHECK_NUMBER (from
);
2571 CHECK_NUMBER (count
);
2572 CHECK_NUMBER (depth
);
2574 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2577 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2578 doc
: /* Scan from character number FROM by COUNT balanced expressions.
2579 If COUNT is negative, scan backwards.
2580 Returns the character number of the position thus found.
2582 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
2584 If the beginning or end of (the accessible part of) the buffer is reached
2585 in the middle of a parenthetical grouping, an error is signaled.
2586 If the beginning or end is reached between groupings
2587 but before count is used up, nil is returned. */)
2589 Lisp_Object from
, count
;
2591 CHECK_NUMBER (from
);
2592 CHECK_NUMBER (count
);
2594 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2597 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2599 doc
: /* Move point backward over any number of chars with prefix syntax.
2600 This includes chars with "quote" or "prefix" syntax (' or p). */)
2605 int opoint_byte
= PT_BYTE
;
2607 int pos_byte
= PT_BYTE
;
2612 SET_PT_BOTH (opoint
, opoint_byte
);
2617 SETUP_SYNTAX_TABLE (pos
, -1);
2619 DEC_BOTH (pos
, pos_byte
);
2621 while (!char_quoted (pos
, pos_byte
)
2622 /* Previous statement updates syntax table. */
2623 && ((c
= FETCH_CHAR_AS_MULTIBYTE (pos_byte
), SYNTAX (c
) == Squote
)
2624 || SYNTAX_PREFIX (c
)))
2627 opoint_byte
= pos_byte
;
2630 DEC_BOTH (pos
, pos_byte
);
2633 SET_PT_BOTH (opoint
, opoint_byte
);
2638 /* Parse forward from FROM / FROM_BYTE to END,
2639 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2640 and return a description of the state of the parse at END.
2641 If STOPBEFORE is nonzero, stop at the start of an atom.
2642 If COMMENTSTOP is 1, stop at the start of a comment.
2643 If COMMENTSTOP is -1, stop at the start or end of a comment,
2644 after the beginning of a string, or after the end of a string. */
2647 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2648 stopbefore
, oldstate
, commentstop
)
2649 struct lisp_parse_state
*stateptr
;
2652 int end
, targetdepth
, stopbefore
;
2653 Lisp_Object oldstate
;
2656 struct lisp_parse_state state
;
2658 register enum syntaxcode code
;
2661 struct level
{ int last
, prev
; };
2662 struct level levelstart
[100];
2663 register struct level
*curlevel
= levelstart
;
2664 struct level
*endlevel
= levelstart
+ 100;
2665 register int depth
; /* Paren depth of current scanning location.
2666 level - levelstart equals this except
2667 when the depth becomes negative. */
2668 int mindepth
; /* Lowest DEPTH value seen. */
2669 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2671 int prev_from
; /* Keep one character before FROM. */
2673 int prev_from_syntax
;
2674 int boundary_stop
= commentstop
== -1;
2677 int out_bytepos
, out_charpos
;
2681 prev_from_byte
= from_byte
;
2683 DEC_BOTH (prev_from
, prev_from_byte
);
2685 /* Use this macro instead of `from++'. */
2687 do { prev_from = from; \
2688 prev_from_byte = from_byte; \
2690 = SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte)); \
2691 INC_BOTH (from, from_byte); \
2692 UPDATE_SYNTAX_TABLE_FORWARD (from); \
2698 if (NILP (oldstate
))
2701 state
.instring
= -1;
2702 state
.incomment
= 0;
2703 state
.comstyle
= 0; /* comment style a by default. */
2704 state
.comstr_start
= -1; /* no comment/string seen. */
2708 tem
= Fcar (oldstate
);
2714 oldstate
= Fcdr (oldstate
);
2715 oldstate
= Fcdr (oldstate
);
2716 oldstate
= Fcdr (oldstate
);
2717 tem
= Fcar (oldstate
);
2718 /* Check whether we are inside string_fence-style string: */
2719 state
.instring
= (!NILP (tem
)
2720 ? (INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2723 oldstate
= Fcdr (oldstate
);
2724 tem
= Fcar (oldstate
);
2725 state
.incomment
= (!NILP (tem
)
2726 ? (INTEGERP (tem
) ? XINT (tem
) : -1)
2729 oldstate
= Fcdr (oldstate
);
2730 tem
= Fcar (oldstate
);
2731 start_quoted
= !NILP (tem
);
2733 /* if the eighth element of the list is nil, we are in comment
2734 style a. If it is non-nil, we are in comment style b */
2735 oldstate
= Fcdr (oldstate
);
2736 oldstate
= Fcdr (oldstate
);
2737 tem
= Fcar (oldstate
);
2738 state
.comstyle
= NILP (tem
) ? 0 : (EQ (tem
, Qsyntax_table
)
2739 ? ST_COMMENT_STYLE
: 1);
2741 oldstate
= Fcdr (oldstate
);
2742 tem
= Fcar (oldstate
);
2743 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2744 oldstate
= Fcdr (oldstate
);
2745 tem
= Fcar (oldstate
);
2746 while (!NILP (tem
)) /* >= second enclosing sexps. */
2748 /* curlevel++->last ran into compiler bug on Apollo */
2749 curlevel
->last
= XINT (Fcar (tem
));
2750 if (++curlevel
== endlevel
)
2751 curlevel
--; /* error ("Nesting too deep for parser"); */
2752 curlevel
->prev
= -1;
2753 curlevel
->last
= -1;
2760 curlevel
->prev
= -1;
2761 curlevel
->last
= -1;
2763 SETUP_SYNTAX_TABLE (prev_from
, 1);
2764 prev_from_syntax
= SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte
));
2765 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2767 /* Enter the loop at a place appropriate for initial state. */
2769 if (state
.incomment
)
2770 goto startincomment
;
2771 if (state
.instring
>= 0)
2773 nofence
= state
.instring
!= ST_STRING_STYLE
;
2775 goto startquotedinstring
;
2778 else if (start_quoted
)
2781 #if 0 /* This seems to be redundant with the identical code above. */
2782 SETUP_SYNTAX_TABLE (prev_from
, 1);
2783 prev_from_syntax
= SYNTAX_WITH_FLAGS (FETCH_CHAR (prev_from_byte
));
2784 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2790 code
= prev_from_syntax
& 0xff;
2792 if (code
== Scomment
)
2794 state
.comstyle
= SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax
);
2795 state
.incomment
= (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
) ?
2797 state
.comstr_start
= prev_from
;
2799 else if (code
== Scomment_fence
)
2801 /* Record the comment style we have entered so that only
2802 the comment-end sequence of the same style actually
2803 terminates the comment section. */
2804 state
.comstyle
= ST_COMMENT_STYLE
;
2805 state
.incomment
= -1;
2806 state
.comstr_start
= prev_from
;
2809 else if (from
< end
)
2810 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax
))
2811 if (c1
= FETCH_CHAR (from_byte
),
2812 SYNTAX_COMSTART_SECOND (c1
))
2813 /* Duplicate code to avoid a complex if-expression
2814 which causes trouble for the SGI compiler. */
2816 /* Record the comment style we have entered so that only
2817 the comment-end sequence of the same style actually
2818 terminates the comment section. */
2819 state
.comstyle
= SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
));
2820 comnested
= SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax
);
2821 comnested
= comnested
|| SYNTAX_COMMENT_NESTED (c1
);
2822 state
.incomment
= comnested
? 1 : -1;
2823 state
.comstr_start
= prev_from
;
2828 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax
))
2830 switch (SWITCH_ENUM_CAST (code
))
2834 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2835 curlevel
->last
= prev_from
;
2837 if (from
== end
) goto endquoted
;
2840 /* treat following character as a word constituent */
2843 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2844 curlevel
->last
= prev_from
;
2848 /* Some compilers can't handle this inside the switch. */
2849 temp
= SYNTAX (FETCH_CHAR_AS_MULTIBYTE (from_byte
));
2855 if (from
== end
) goto endquoted
;
2867 curlevel
->prev
= curlevel
->last
;
2871 if (commentstop
|| boundary_stop
) goto done
;
2873 /* The (from == BEGV) test was to enter the loop in the middle so
2874 that we find a 2-char comment ender even if we start in the
2875 middle of it. We don't want to do that if we're just at the
2876 beginning of the comment (think of (*) ... (*)). */
2877 found
= forw_comment (from
, from_byte
, end
,
2878 state
.incomment
, state
.comstyle
,
2879 (from
== BEGV
|| from
< state
.comstr_start
+ 3)
2880 ? 0 : prev_from_syntax
,
2881 &out_charpos
, &out_bytepos
, &state
.incomment
);
2882 from
= out_charpos
; from_byte
= out_bytepos
;
2883 /* Beware! prev_from and friends are invalid now.
2884 Luckily, the `done' doesn't use them and the INC_FROM
2885 sets them to a sane value without looking at them. */
2886 if (!found
) goto done
;
2888 state
.incomment
= 0;
2889 state
.comstyle
= 0; /* reset the comment style */
2890 if (boundary_stop
) goto done
;
2894 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2896 /* curlevel++->last ran into compiler bug on Apollo */
2897 curlevel
->last
= prev_from
;
2898 if (++curlevel
== endlevel
)
2899 curlevel
--; /* error ("Nesting too deep for parser"); */
2900 curlevel
->prev
= -1;
2901 curlevel
->last
= -1;
2902 if (targetdepth
== depth
) goto done
;
2907 if (depth
< mindepth
)
2909 if (curlevel
!= levelstart
)
2911 curlevel
->prev
= curlevel
->last
;
2912 if (targetdepth
== depth
) goto done
;
2917 state
.comstr_start
= from
- 1;
2918 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2919 curlevel
->last
= prev_from
;
2920 state
.instring
= (code
== Sstring
2921 ? (FETCH_CHAR_AS_MULTIBYTE (prev_from_byte
))
2923 if (boundary_stop
) goto done
;
2926 nofence
= state
.instring
!= ST_STRING_STYLE
;
2932 if (from
>= end
) goto done
;
2933 c
= FETCH_CHAR_AS_MULTIBYTE (from_byte
);
2934 /* Some compilers can't handle this inside the switch. */
2937 /* Check TEMP here so that if the char has
2938 a syntax-table property which says it is NOT
2939 a string character, it does not end the string. */
2940 if (nofence
&& c
== state
.instring
&& temp
== Sstring
)
2946 if (!nofence
) goto string_end
;
2951 startquotedinstring
:
2952 if (from
>= end
) goto endquoted
;
2958 state
.instring
= -1;
2959 curlevel
->prev
= curlevel
->last
;
2961 if (boundary_stop
) goto done
;
2970 stop
: /* Here if stopping before start of sexp. */
2971 from
= prev_from
; /* We have just fetched the char that starts it; */
2972 goto done
; /* but return the position before it. */
2977 state
.depth
= depth
;
2978 state
.mindepth
= mindepth
;
2979 state
.thislevelstart
= curlevel
->prev
;
2980 state
.prevlevelstart
2981 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
2982 state
.location
= from
;
2983 state
.levelstarts
= Qnil
;
2984 while (--curlevel
>= levelstart
)
2985 state
.levelstarts
= Fcons (make_number (curlevel
->last
),
2992 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
2993 doc
: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
2994 Parsing stops at TO or when certain criteria are met;
2995 point is set to where parsing stops.
2996 If fifth arg OLDSTATE is omitted or nil,
2997 parsing assumes that FROM is the beginning of a function.
2998 Value is a list of ten elements describing final state of parsing:
3000 1. character address of start of innermost containing list; nil if none.
3001 2. character address of start of last complete sexp terminated.
3002 3. non-nil if inside a string.
3003 (it is the character that will terminate the string,
3004 or t if the string should be terminated by a generic string delimiter.)
3005 4. nil if outside a comment, t if inside a non-nestable comment,
3006 else an integer (the current comment nesting).
3007 5. t if following a quote character.
3008 6. the minimum paren-depth encountered during this scan.
3009 7. t if in a comment of style b; symbol `syntax-table' if the comment
3010 should be terminated by a generic comment delimiter.
3011 8. character address of start of comment or string; nil if not in one.
3012 9. Intermediate data for continuation of parsing (subject to change).
3013 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3014 in parentheses becomes equal to TARGETDEPTH.
3015 Fourth arg STOPBEFORE non-nil means stop when come to
3016 any character that starts a sexp.
3017 Fifth arg OLDSTATE is a nine-element list like what this function returns.
3018 It is used to initialize the state of the parse. Elements number 1, 2, 6
3019 and 8 are ignored; you can leave off element 8 (the last) entirely.
3020 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3021 If it is symbol `syntax-table', stop after the start of a comment or a
3022 string, or after end of a comment or a string. */)
3023 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
3024 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
3026 struct lisp_parse_state state
;
3029 if (!NILP (targetdepth
))
3031 CHECK_NUMBER (targetdepth
);
3032 target
= XINT (targetdepth
);
3035 target
= -100000; /* We won't reach this depth */
3037 validate_region (&from
, &to
);
3038 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
3040 target
, !NILP (stopbefore
), oldstate
,
3042 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
3044 SET_PT (state
.location
);
3046 return Fcons (make_number (state
.depth
),
3047 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
3048 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
3049 Fcons (state
.instring
>= 0
3050 ? (state
.instring
== ST_STRING_STYLE
3051 ? Qt
: make_number (state
.instring
)) : Qnil
,
3052 Fcons (state
.incomment
< 0 ? Qt
:
3053 (state
.incomment
== 0 ? Qnil
:
3054 make_number (state
.incomment
)),
3055 Fcons (state
.quoted
? Qt
: Qnil
,
3056 Fcons (make_number (state
.mindepth
),
3057 Fcons ((state
.comstyle
3058 ? (state
.comstyle
== ST_COMMENT_STYLE
3059 ? Qsyntax_table
: Qt
) :
3061 Fcons (((state
.incomment
3062 || (state
.instring
>= 0))
3063 ? make_number (state
.comstr_start
)
3065 Fcons (state
.levelstarts
, Qnil
))))))))));
3074 /* This has to be done here, before we call Fmake_char_table. */
3075 Qsyntax_table
= intern ("syntax-table");
3076 staticpro (&Qsyntax_table
);
3078 /* Intern this now in case it isn't already done.
3079 Setting this variable twice is harmless.
3080 But don't staticpro it here--that is done in alloc.c. */
3081 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
3083 /* Create objects which can be shared among syntax tables. */
3084 Vsyntax_code_object
= Fmake_vector (make_number (Smax
), Qnil
);
3085 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
3086 XVECTOR (Vsyntax_code_object
)->contents
[i
]
3087 = Fcons (make_number (i
), Qnil
);
3089 /* Now we are ready to set up this property, so we can
3090 create syntax tables. */
3091 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
3093 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
3095 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
3097 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3098 for (i
= 'a'; i
<= 'z'; i
++)
3099 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3100 for (i
= 'A'; i
<= 'Z'; i
++)
3101 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3102 for (i
= '0'; i
<= '9'; i
++)
3103 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
3105 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
3106 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
3108 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
3109 Fcons (make_number (Sopen
), make_number (')')));
3110 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
3111 Fcons (make_number (Sclose
), make_number ('(')));
3112 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
3113 Fcons (make_number (Sopen
), make_number (']')));
3114 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
3115 Fcons (make_number (Sclose
), make_number ('[')));
3116 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
3117 Fcons (make_number (Sopen
), make_number ('}')));
3118 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
3119 Fcons (make_number (Sclose
), make_number ('{')));
3120 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
3121 Fcons (make_number ((int) Sstring
), Qnil
));
3122 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
3123 Fcons (make_number ((int) Sescape
), Qnil
));
3125 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
3126 for (i
= 0; i
< 10; i
++)
3128 c
= "_-+*/&|<>="[i
];
3129 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3132 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
3133 for (i
= 0; i
< 12; i
++)
3135 c
= ".,;:?!#@~^'`"[i
];
3136 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
3139 /* All multibyte characters have syntax `word' by default. */
3140 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
3141 char_table_set_range (Vstandard_syntax_table
, 0x80, MAX_CHAR
, temp
);
3147 Qsyntax_table_p
= intern ("syntax-table-p");
3148 staticpro (&Qsyntax_table_p
);
3150 staticpro (&Vsyntax_code_object
);
3152 Qscan_error
= intern ("scan-error");
3153 staticpro (&Qscan_error
);
3154 Fput (Qscan_error
, Qerror_conditions
,
3155 Fcons (Qscan_error
, Fcons (Qerror
, Qnil
)));
3156 Fput (Qscan_error
, Qerror_message
,
3157 build_string ("Scan error"));
3159 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
3160 doc
: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
3162 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
3163 doc
: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
3164 Otherwise, that text property is simply ignored.
3165 See the info node `(elisp)Syntax Properties' for a description of the
3166 `syntax-table' property. */);
3168 words_include_escapes
= 0;
3169 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
3170 doc
: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
3172 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol
,
3173 doc
: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol constituents. */);
3174 multibyte_syntax_as_symbol
= 0;
3176 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
3177 &open_paren_in_column_0_is_defun_start
,
3178 doc
: /* Non-nil means an open paren in column 0 denotes the start of a defun. */);
3179 open_paren_in_column_0_is_defun_start
= 1;
3181 DEFVAR_LISP ("next-word-boundary-function-table",
3182 &Vnext_word_boundary_function_table
,
3184 Char table of functions to search for the next word boundary.
3185 Each function is called with two arguments; POS and LIMIT.
3186 POS and LIMIT are character positions in the current buffer.
3188 If POS is less than LIMIT, POS is at the first character of a word,
3189 and the return value of a function is a position after the last
3190 character of that word.
3192 If POS is not less than LIMIT, POS is at the last character of a word,
3193 and the return value of a function is a position at the first
3194 character of that word.
3196 In both cases, LIMIT bounds the search. */);
3197 Vnext_word_boundary_function_table
= Fmake_char_table (Qnil
, Qnil
);
3199 defsubr (&Ssyntax_table_p
);
3200 defsubr (&Ssyntax_table
);
3201 defsubr (&Sstandard_syntax_table
);
3202 defsubr (&Scopy_syntax_table
);
3203 defsubr (&Sset_syntax_table
);
3204 defsubr (&Schar_syntax
);
3205 defsubr (&Smatching_paren
);
3206 defsubr (&Sstring_to_syntax
);
3207 defsubr (&Smodify_syntax_entry
);
3208 defsubr (&Sinternal_describe_syntax_value
);
3210 defsubr (&Sforward_word
);
3212 defsubr (&Sskip_chars_forward
);
3213 defsubr (&Sskip_chars_backward
);
3214 defsubr (&Sskip_syntax_forward
);
3215 defsubr (&Sskip_syntax_backward
);
3217 defsubr (&Sforward_comment
);
3218 defsubr (&Sscan_lists
);
3219 defsubr (&Sscan_sexps
);
3220 defsubr (&Sbackward_prefix_chars
);
3221 defsubr (&Sparse_partial_sexp
);