1 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
2 Copyright (C) 1985, 87, 93, 94, 95, 1997 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. */
29 /* Make syntax table lookup grant data in gl_state. */
30 #define SYNTAX_ENTRY_VIA_PROPERTY
33 #include "intervals.h"
35 /* We use these constants in place for comment-style and
36 string-ender-char to distinguish comments/strings started by
37 comment_fence and string_fence codes. */
39 #define ST_COMMENT_STYLE (256 + 1)
40 #define ST_STRING_STYLE (256 + 2)
43 Lisp_Object Qsyntax_table_p
, Qsyntax_table
, Qscan_error
;
45 int words_include_escapes
;
46 int parse_sexp_lookup_properties
;
48 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
49 if not compiled with GCC. No need to mark it, since it is used
50 only very temporarily. */
51 Lisp_Object syntax_temp
;
53 /* This is the internal form of the parse state used in parse-partial-sexp. */
55 struct lisp_parse_state
57 int depth
; /* Depth at end of parsing. */
58 int instring
; /* -1 if not within string, else desired terminator. */
59 int incomment
; /* Nonzero if within a comment at end of parsing. */
60 int comstyle
; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
61 int quoted
; /* Nonzero if just after an escape char at end of parsing */
62 int thislevelstart
; /* Char number of most recent start-of-expression at current level */
63 int prevlevelstart
; /* Char number of start of containing expression */
64 int location
; /* Char number at which parsing stopped. */
65 int mindepth
; /* Minimum depth seen while scanning. */
66 int comstr_start
; /* Position just after last comment/string starter. */
69 /* These variables are a cache for finding the start of a defun.
70 find_start_pos is the place for which the defun start was found.
71 find_start_value is the defun start position found for it.
72 find_start_value_byte is the corresponding byte position.
73 find_start_buffer is the buffer it was found in.
74 find_start_begv is the BEGV value when it was found.
75 find_start_modiff is the value of MODIFF when it was found. */
77 static int find_start_pos
;
78 static int find_start_value
;
79 static int find_start_value_byte
;
80 static struct buffer
*find_start_buffer
;
81 static int find_start_begv
;
82 static int find_start_modiff
;
85 static int find_defun_start
P_ ((int, int));
86 static int back_comment
P_ ((int, int, int, int, int *, int *));
87 static int char_quoted
P_ ((int, int));
88 static Lisp_Object skip_chars
P_ ((int, int, Lisp_Object
, Lisp_Object
));
89 static Lisp_Object scan_lists
P_ ((int, int, int, int));
90 static void scan_sexps_forward
P_ ((struct lisp_parse_state
*,
92 int, Lisp_Object
, int));
95 struct gl_state_s gl_state
; /* Global state of syntax parser. */
97 INTERVAL
interval_of ();
98 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
99 to scan to property-change. */
101 /* Update gl_state to an appropriate interval which contains CHARPOS. The
102 sign of COUNT give the relative position of CHARPOS wrt the previously
103 valid interval. If INIT, only [be]_property fields of gl_state are
104 valid at start, the rest is filled basing on OBJECT.
106 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
107 direction than the intervals - or in an interval. We update the
108 current syntax-table basing on the property of this interval, and
109 update the interval to start further than CHARPOS - or be
110 NULL_INTERVAL. We also update lim_property to be the next value of
111 charpos to call this subroutine again - or be before/after the
112 start/end of OBJECT. */
115 update_syntax_table (charpos
, count
, init
, object
)
116 int charpos
, count
, init
;
119 Lisp_Object tmp_table
;
120 int cnt
= 0, doing_extra
= 0, invalidate
= 1;
125 gl_state
.start
= gl_state
.b_property
;
126 gl_state
.stop
= gl_state
.e_property
;
127 gl_state
.forward_i
= interval_of (charpos
, object
);
128 i
= gl_state
.backward_i
= gl_state
.forward_i
;
129 gl_state
.left_ok
= gl_state
.right_ok
= 1;
131 if (NULL_INTERVAL_P (i
))
133 gl_state
.b_property
= i
->position
- 1;
134 gl_state
.e_property
= INTERVAL_LAST_POS (i
);
137 oldi
= i
= count
> 0 ? gl_state
.forward_i
: gl_state
.backward_i
;
139 /* We are guarantied to be called with CHARPOS either in i,
141 if (NULL_INTERVAL_P (i
))
142 error ("Error in syntax_table logic for to-the-end intervals");
143 else if (charpos
< i
->position
) /* Move left. */
146 error ("Error in syntax_table logic for intervals <-.");
147 /* Update the interval. */
148 i
= update_interval (i
, charpos
);
149 if (oldi
->position
!= INTERVAL_LAST_POS (i
))
152 gl_state
.right_ok
= 1; /* Invalidate the other end. */
153 gl_state
.forward_i
= i
;
154 gl_state
.e_property
= INTERVAL_LAST_POS (i
);
157 else if (charpos
>= INTERVAL_LAST_POS (i
)) /* Move right. */
160 error ("Error in syntax_table logic for intervals ->.");
161 /* Update the interval. */
162 i
= update_interval (i
, charpos
);
163 if (i
->position
!= INTERVAL_LAST_POS (oldi
))
166 gl_state
.left_ok
= 1; /* Invalidate the other end. */
167 gl_state
.backward_i
= i
;
168 gl_state
.b_property
= i
->position
- 1;
171 else if (count
> 0 ? gl_state
.right_ok
: gl_state
.left_ok
)
173 /* We do not need to recalculate tmp_table. */
174 tmp_table
= gl_state
.old_prop
;
178 tmp_table
= textget (i
->plist
, Qsyntax_table
);
181 invalidate
= !EQ (tmp_table
, gl_state
.old_prop
); /* Need to invalidate? */
183 if (invalidate
) /* Did not get to adjacent interval. */
184 { /* with the same table => */
185 /* invalidate the old range. */
188 gl_state
.backward_i
= i
;
189 gl_state
.left_ok
= 1; /* Invalidate the other end. */
190 gl_state
.b_property
= i
->position
- 1;
194 gl_state
.forward_i
= i
;
195 gl_state
.right_ok
= 1; /* Invalidate the other end. */
196 gl_state
.e_property
= INTERVAL_LAST_POS (i
);
200 gl_state
.current_syntax_table
= tmp_table
;
201 gl_state
.old_prop
= tmp_table
;
202 if (EQ (Fsyntax_table_p (tmp_table
), Qt
))
204 gl_state
.use_global
= 0;
206 else if (CONSP (tmp_table
))
208 gl_state
.use_global
= 1;
209 gl_state
.global_code
= tmp_table
;
213 gl_state
.use_global
= 0;
214 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
217 while (!NULL_INTERVAL_P (i
))
219 if (cnt
&& !EQ (tmp_table
, textget (i
->plist
, Qsyntax_table
)))
222 gl_state
.right_ok
= 0;
224 gl_state
.left_ok
= 0;
227 else if (cnt
== INTERVALS_AT_ONCE
)
230 gl_state
.right_ok
= 1;
232 gl_state
.left_ok
= 1;
236 i
= count
> 0 ? next_interval (i
) : previous_interval (i
);
238 if (NULL_INTERVAL_P (i
))
239 { /* This property goes to the end. */
241 gl_state
.e_property
= gl_state
.stop
;
243 gl_state
.b_property
= gl_state
.start
;
249 gl_state
.e_property
= i
->position
;
250 gl_state
.forward_i
= i
;
254 gl_state
.b_property
= i
->position
+ LENGTH (i
) - 1;
255 gl_state
.backward_i
= i
;
260 /* Returns TRUE if char at CHARPOS is quoted.
261 Global syntax-table data should be set up already to be good at CHARPOS
262 or after. On return global syntax data is good for lookup at CHARPOS. */
265 char_quoted (charpos
, bytepos
)
266 register int charpos
, bytepos
;
268 register enum syntaxcode code
;
269 register int beg
= BEGV
;
270 register int quoted
= 0;
273 DEC_BOTH (charpos
, bytepos
);
275 while (bytepos
>= beg
)
277 UPDATE_SYNTAX_TABLE_BACKWARD (charpos
);
278 code
= SYNTAX (FETCH_CHAR (bytepos
));
279 if (! (code
== Scharquote
|| code
== Sescape
))
282 DEC_BOTH (charpos
, bytepos
);
286 UPDATE_SYNTAX_TABLE (orig
);
290 /* Return the bytepos one character after BYTEPOS.
291 We assume that BYTEPOS is not at the end of the buffer. */
294 inc_bytepos (bytepos
)
301 /* Return the bytepos one character before BYTEPOS.
302 We assume that BYTEPOS is not at the start of the buffer. */
305 dec_bytepos (bytepos
)
312 /* Find a defun-start that is the last one before POS (or nearly the last).
313 We record what we find, so that another call in the same area
314 can return the same value right away.
316 There is no promise at which position the global syntax data is
317 valid on return from the subroutine, so the caller should explicitly
318 update the global data. */
321 find_defun_start (pos
, pos_byte
)
326 int opoint
= PT
, opoint_byte
= PT_BYTE
;
328 /* Use previous finding, if it's valid and applies to this inquiry. */
329 if (current_buffer
== find_start_buffer
330 /* Reuse the defun-start even if POS is a little farther on.
331 POS might be in the next defun, but that's ok.
332 Our value may not be the best possible, but will still be usable. */
333 && pos
<= find_start_pos
+ 1000
334 && pos
>= find_start_value
335 && BEGV
== find_start_begv
336 && MODIFF
== find_start_modiff
)
337 return find_start_value
;
339 /* Back up to start of line. */
340 scan_newline (pos
, pos_byte
, BEGV
, BEGV_BYTE
, -1, 1);
342 /* We optimize syntax-table lookup for rare updates. Thus we accept
343 only those `^\s(' which are good in global _and_ text-property
345 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
346 gl_state
.use_global
= 0;
349 /* Open-paren at start of line means we found our defun-start. */
350 if (SYNTAX (FETCH_CHAR (PT_BYTE
)) == Sopen
)
352 SETUP_SYNTAX_TABLE (PT
+ 1, -1); /* Try again... */
353 if (SYNTAX (FETCH_CHAR (PT_BYTE
)) == Sopen
)
355 /* Now fallback to the default value. */
356 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
357 gl_state
.use_global
= 0;
359 /* Move to beg of previous line. */
360 scan_newline (PT
, PT_BYTE
, BEGV
, BEGV_BYTE
, -2, 1);
363 /* Record what we found, for the next try. */
364 find_start_value
= PT
;
365 find_start_value_byte
= PT_BYTE
;
366 find_start_buffer
= current_buffer
;
367 find_start_modiff
= MODIFF
;
368 find_start_begv
= BEGV
;
369 find_start_pos
= pos
;
371 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
373 return find_start_value
;
376 /* Checks whether charpos FROM is at the end of a comment.
377 FROM_BYTE is the bytepos corresponding to FROM.
378 Do not move back before STOP.
380 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
383 If successful, store the charpos of the comment's beginning
384 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
386 Global syntax data remains valid for backward search starting at
387 the returned value (or at FROM, if the search was not successful). */
390 back_comment (from
, from_byte
, stop
, comstyle
, charpos_ptr
, bytepos_ptr
)
391 int from
, from_byte
, stop
;
393 int *charpos_ptr
, *bytepos_ptr
;
395 /* Look back, counting the parity of string-quotes,
396 and recording the comment-starters seen.
397 When we reach a safe place, assume that's not in a string;
398 then step the main scan to the earliest comment-starter seen
399 an even number of string quotes away from the safe place.
401 OFROM[I] is position of the earliest comment-starter seen
402 which is I+2X quotes from the comment-end.
403 PARITY is current parity of quotes from the comment end. */
405 int my_stringend
= 0;
406 int string_lossage
= 0;
407 int comment_end
= from
;
408 int comment_end_byte
= from_byte
;
409 int comstart_pos
= 0;
410 int comstart_parity
= 0;
412 int scanstart
= from
- 1;
413 register enum syntaxcode code
;
416 /* At beginning of range to scan, we're outside of strings;
417 that determines quote parity to the comment-end. */
422 /* Move back and examine a character. */
423 DEC_BOTH (from
, from_byte
);
424 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
426 c
= FETCH_CHAR (from_byte
);
429 /* If this char is the second of a 2-char comment end sequence,
430 back up and give the pair the appropriate syntax. */
431 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
432 && (temp_byte
= dec_bytepos (from_byte
),
433 SYNTAX_COMEND_FIRST (FETCH_CHAR (temp_byte
))))
436 DEC_BOTH (from
, from_byte
);
437 /* This is apparently the best we can do: */
438 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
439 c
= FETCH_CHAR (from_byte
);
442 /* If this char starts a 2-char comment start sequence,
443 treat it like a 1-char comment starter. */
444 if (from
< scanstart
&& SYNTAX_COMSTART_FIRST (c
)
445 && (temp_byte
= inc_bytepos (from_byte
),
446 (SYNTAX_COMSTART_SECOND (FETCH_CHAR (temp_byte
))
447 && comstyle
== SYNTAX_COMMENT_STYLE (FETCH_CHAR (temp_byte
)))))
450 /* Ignore escaped characters, except comment-enders. */
451 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
454 /* Track parity of quotes. */
458 if (my_stringend
== 0)
460 /* If we have two kinds of string delimiters.
461 There's no way to grok this scanning backwards. */
462 else if (my_stringend
!= c
)
466 if (code
== Sstring_fence
|| code
== Scomment_fence
)
469 if (my_stringend
== 0)
471 = code
== Sstring_fence
? ST_STRING_STYLE
: ST_COMMENT_STYLE
;
472 /* If we have two kinds of string delimiters.
473 There's no way to grok this scanning backwards. */
474 else if (my_stringend
!= (code
== Sstring_fence
475 ? ST_STRING_STYLE
: ST_COMMENT_STYLE
))
479 /* Record comment-starters according to that
480 quote-parity to the comment-end. */
481 if (code
== Scomment
)
483 comstart_parity
= parity
;
485 comstart_byte
= from_byte
;
488 /* If we find another earlier comment-ender,
489 any comment-starts earlier than that don't count
490 (because they go with the earlier comment-ender). */
491 if (code
== Sendcomment
492 && SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
)) == comstyle
)
495 /* Assume a defun-start point is outside of strings. */
498 || (temp_byte
= dec_bytepos (from_byte
),
499 FETCH_CHAR (temp_byte
) == '\n')))
503 if (comstart_pos
== 0)
506 from_byte
= comment_end_byte
;
507 UPDATE_SYNTAX_TABLE_FORWARD (comment_end
- 1);
509 /* If the earliest comment starter
510 is followed by uniform paired string quotes or none,
511 we know it can't be inside a string
512 since if it were then the comment ender would be inside one.
513 So it does start a comment. Skip back to it. */
514 else if (comstart_parity
== 0 && !string_lossage
)
517 from_byte
= comstart_byte
;
518 /* Globals are correct now. */
522 /* We had two kinds of string delimiters mixed up
523 together. Decode this going forwards.
524 Scan fwd from the previous comment ender
525 to the one in question; this records where we
526 last passed a comment starter. */
527 struct lisp_parse_state state
;
528 scan_sexps_forward (&state
,
529 find_defun_start (comment_end
, comment_end_byte
),
530 find_start_value_byte
,
531 comment_end
- 1, -10000, 0, Qnil
, 0);
534 /* scan_sexps_forward changed the direction of search in
535 global variables, so we need to update it completely. */
537 from
= state
.comstr_start
;
543 from_byte
= CHAR_TO_BYTE (from
);
544 UPDATE_SYNTAX_TABLE_FORWARD (from
- 1);
548 *bytepos_ptr
= from_byte
;
553 DEFUN ("syntax-table-p", Fsyntax_table_p
, Ssyntax_table_p
, 1, 1, 0,
554 "Return t if OBJECT is a syntax table.\n\
555 Currently, any char-table counts as a syntax table.")
559 if (CHAR_TABLE_P (object
)
560 && EQ (XCHAR_TABLE (object
)->purpose
, Qsyntax_table
))
566 check_syntax_table (obj
)
569 if (!(CHAR_TABLE_P (obj
)
570 && EQ (XCHAR_TABLE (obj
)->purpose
, Qsyntax_table
)))
571 wrong_type_argument (Qsyntax_table_p
, obj
);
574 DEFUN ("syntax-table", Fsyntax_table
, Ssyntax_table
, 0, 0, 0,
575 "Return the current syntax table.\n\
576 This is the one specified by the current buffer.")
579 return current_buffer
->syntax_table
;
582 DEFUN ("standard-syntax-table", Fstandard_syntax_table
,
583 Sstandard_syntax_table
, 0, 0, 0,
584 "Return the standard syntax table.\n\
585 This is the one used for new buffers.")
588 return Vstandard_syntax_table
;
591 DEFUN ("copy-syntax-table", Fcopy_syntax_table
, Scopy_syntax_table
, 0, 1, 0,
592 "Construct a new syntax table and return it.\n\
593 It is a copy of the TABLE, which defaults to the standard syntax table.")
600 check_syntax_table (table
);
602 table
= Vstandard_syntax_table
;
604 copy
= Fcopy_sequence (table
);
606 /* Only the standard syntax table should have a default element.
607 Other syntax tables should inherit from parents instead. */
608 XCHAR_TABLE (copy
)->defalt
= Qnil
;
610 /* Copied syntax tables should all have parents.
611 If we copied one with no parent, such as the standard syntax table,
612 use the standard syntax table as the copy's parent. */
613 if (NILP (XCHAR_TABLE (copy
)->parent
))
614 Fset_char_table_parent (copy
, Vstandard_syntax_table
);
618 DEFUN ("set-syntax-table", Fset_syntax_table
, Sset_syntax_table
, 1, 1, 0,
619 "Select a new syntax table for the current buffer.\n\
620 One argument, a syntax table.")
624 check_syntax_table (table
);
625 current_buffer
->syntax_table
= table
;
626 /* Indicate that this buffer now has a specified syntax table. */
627 current_buffer
->local_var_flags
628 |= XFASTINT (buffer_local_flags
.syntax_table
);
632 /* Convert a letter which signifies a syntax code
633 into the code it signifies.
634 This is used by modify-syntax-entry, and other things. */
636 unsigned char syntax_spec_code
[0400] =
637 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
638 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
639 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
640 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
641 (char) Swhitespace
, (char) Scomment_fence
, (char) Sstring
, 0377,
642 (char) Smath
, 0377, 0377, (char) Squote
,
643 (char) Sopen
, (char) Sclose
, 0377, 0377,
644 0377, (char) Swhitespace
, (char) Spunct
, (char) Scharquote
,
645 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
646 0377, 0377, 0377, 0377,
647 (char) Scomment
, 0377, (char) Sendcomment
, 0377,
648 (char) Sinherit
, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
649 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
650 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
651 0377, 0377, 0377, 0377, (char) Sescape
, 0377, 0377, (char) Ssymbol
,
652 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
653 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
654 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword
,
655 0377, 0377, 0377, 0377, (char) Sstring_fence
, 0377, 0377, 0377
658 /* Indexed by syntax code, give the letter that describes it. */
660 char syntax_code_spec
[16] =
662 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
666 /* Indexed by syntax code, give the object (cons of syntax code and
667 nil) to be stored in syntax table. Since these objects can be
668 shared among syntax tables, we generate them in advance. By
669 sharing objects, the function `describe-syntax' can give a more
671 static Lisp_Object Vsyntax_code_object
;
674 /* Look up the value for CHARACTER in syntax table TABLE's parent
675 and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil
676 for CHARACTER. It's actually used only when not compiled with GCC. */
679 syntax_parent_lookup (table
, character
)
687 table
= XCHAR_TABLE (table
)->parent
;
691 value
= XCHAR_TABLE (table
)->contents
[character
];
697 DEFUN ("char-syntax", Fchar_syntax
, Schar_syntax
, 1, 1, 0,
698 "Return the syntax code of CHARACTER, described by a character.\n\
699 For example, if CHARACTER is a word constituent,\n\
700 the character `w' is returned.\n\
701 The characters that correspond to various syntax codes\n\
702 are listed in the documentation of `modify-syntax-entry'.")
704 Lisp_Object character
;
707 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
709 gl_state
.use_global
= 0;
710 CHECK_NUMBER (character
, 0);
711 char_int
= XINT (character
);
712 return make_number (syntax_code_spec
[(int) SYNTAX (char_int
)]);
715 DEFUN ("matching-paren", Fmatching_paren
, Smatching_paren
, 1, 1, 0,
716 "Return the matching parenthesis of CHARACTER, or nil if none.")
718 Lisp_Object character
;
721 gl_state
.current_syntax_table
= current_buffer
->syntax_table
;
722 gl_state
.use_global
= 0;
723 CHECK_NUMBER (character
, 0);
724 char_int
= XINT (character
);
725 code
= SYNTAX (char_int
);
726 if (code
== Sopen
|| code
== Sclose
)
727 return SYNTAX_MATCH (char_int
);
731 /* This comment supplies the doc string for modify-syntax-entry,
732 for make-docfile to see. We cannot put this in the real DEFUN
733 due to limits in the Unix cpp.
735 DEFUN ("modify-syntax-entry", foo, bar, 2, 3, 0,
736 "Set syntax for character CHAR according to string S.\n\
737 The syntax is changed only for table TABLE, which defaults to\n\
738 the current buffer's syntax table.\n\
739 The first character of S should be one of the following:\n\
740 Space or - whitespace syntax. w word constituent.\n\
741 _ symbol constituent. . punctuation.\n\
742 ( open-parenthesis. ) close-parenthesis.\n\
743 \" string quote. \\ escape.\n\
744 $ paired delimiter. ' expression quote or prefix operator.\n\
745 < comment starter. > comment ender.\n\
746 / character-quote. @ inherit from `standard-syntax-table'.\n\
748 Only single-character comment start and end sequences are represented thus.\n\
749 Two-character sequences are represented as described below.\n\
750 The second character of S is the matching parenthesis,\n\
751 used only if the first character is `(' or `)'.\n\
752 Any additional characters are flags.\n\
753 Defined flags are the characters 1, 2, 3, 4, b, and p.\n\
754 1 means CHAR is the start of a two-char comment start sequence.\n\
755 2 means CHAR is the second character of such a sequence.\n\
756 3 means CHAR is the start of a two-char comment end sequence.\n\
757 4 means CHAR is the second character of such a sequence.\n\
759 There can be up to two orthogonal comment sequences. This is to support\n\
760 language modes such as C++. By default, all comment sequences are of style\n\
761 a, but you can set the comment sequence style to b (on the second character\n\
762 of a comment-start, or the first character of a comment-end sequence) using\n\
764 b means CHAR is part of comment sequence b.\n\
766 p means CHAR is a prefix character for `backward-prefix-chars';\n\
767 such characters are treated as whitespace when they occur\n\
768 between expressions.")
772 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry
, Smodify_syntax_entry
, 2, 3,
773 /* I really don't know why this is interactive
774 help-form should at least be made useful whilst reading the second arg
776 "cSet syntax for character: \nsSet syntax for %s to: ",
777 0 /* See immediately above */)
778 (c
, newentry
, syntax_table
)
779 Lisp_Object c
, newentry
, syntax_table
;
781 register unsigned char *p
;
782 register enum syntaxcode code
;
787 CHECK_STRING (newentry
, 1);
789 if (NILP (syntax_table
))
790 syntax_table
= current_buffer
->syntax_table
;
792 check_syntax_table (syntax_table
);
794 p
= XSTRING (newentry
)->data
;
795 code
= (enum syntaxcode
) syntax_spec_code
[*p
++];
796 if (((int) code
& 0377) == 0377)
797 error ("invalid syntax description letter: %c", p
[-1]);
799 if (code
== Sinherit
)
801 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), Qnil
);
808 int character
= STRING_CHAR_AND_LENGTH (p
, XSTRING (newentry
)->size
- 1,
810 XSETINT (match
, character
);
811 if (XFASTINT (match
) == ' ')
847 if (val
< XVECTOR (Vsyntax_code_object
)->size
&& NILP (match
))
848 newentry
= XVECTOR (Vsyntax_code_object
)->contents
[val
];
850 /* Since we can't use a shared object, let's make a new one. */
851 newentry
= Fcons (make_number (val
), match
);
853 SET_RAW_SYNTAX_ENTRY (syntax_table
, XINT (c
), newentry
);
858 /* Dump syntax table to buffer in human-readable format */
861 describe_syntax (value
)
864 register enum syntaxcode code
;
865 char desc
, match
, start1
, start2
, end1
, end2
, prefix
, comstyle
;
867 Lisp_Object first
, match_lisp
;
869 Findent_to (make_number (16), make_number (1));
873 insert_string ("default\n");
877 if (CHAR_TABLE_P (value
))
879 insert_string ("deeper char-table ...\n");
885 insert_string ("invalid\n");
889 first
= XCONS (value
)->car
;
890 match_lisp
= XCONS (value
)->cdr
;
892 if (!INTEGERP (first
) || !(NILP (match_lisp
) || INTEGERP (match_lisp
)))
894 insert_string ("invalid\n");
898 code
= (enum syntaxcode
) (XINT (first
) & 0377);
899 start1
= (XINT (first
) >> 16) & 1;
900 start2
= (XINT (first
) >> 17) & 1;
901 end1
= (XINT (first
) >> 18) & 1;
902 end2
= (XINT (first
) >> 19) & 1;
903 prefix
= (XINT (first
) >> 20) & 1;
904 comstyle
= (XINT (first
) >> 21) & 1;
906 if ((int) code
< 0 || (int) code
>= (int) Smax
)
908 insert_string ("invalid");
911 desc
= syntax_code_spec
[(int) code
];
913 str
[0] = desc
, str
[1] = 0;
916 if (NILP (match_lisp
))
919 insert_char (XINT (match_lisp
));
936 insert_string ("\twhich means: ");
938 switch (SWITCH_ENUM_CAST (code
))
941 insert_string ("whitespace"); break;
943 insert_string ("punctuation"); break;
945 insert_string ("word"); break;
947 insert_string ("symbol"); break;
949 insert_string ("open"); break;
951 insert_string ("close"); break;
953 insert_string ("quote"); break;
955 insert_string ("string"); break;
957 insert_string ("math"); break;
959 insert_string ("escape"); break;
961 insert_string ("charquote"); break;
963 insert_string ("comment"); break;
965 insert_string ("endcomment"); break;
967 insert_string ("invalid");
971 if (!NILP (match_lisp
))
973 insert_string (", matches ");
974 insert_char (XINT (match_lisp
));
978 insert_string (",\n\t is the first character of a comment-start sequence");
980 insert_string (",\n\t is the second character of a comment-start sequence");
983 insert_string (",\n\t is the first character of a comment-end sequence");
985 insert_string (",\n\t is the second character of a comment-end sequence");
987 insert_string (" (comment style b)");
990 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
992 insert_string ("\n");
996 describe_syntax_1 (vector
)
999 struct buffer
*old
= current_buffer
;
1000 set_buffer_internal (XBUFFER (Vstandard_output
));
1001 describe_vector (vector
, Qnil
, describe_syntax
, 0, Qnil
, Qnil
, (int *) 0, 0);
1002 while (! NILP (XCHAR_TABLE (vector
)->parent
))
1004 vector
= XCHAR_TABLE (vector
)->parent
;
1005 insert_string ("\nThe parent syntax table is:");
1006 describe_vector (vector
, Qnil
, describe_syntax
, 0, Qnil
, Qnil
,
1010 call0 (intern ("help-mode"));
1011 set_buffer_internal (old
);
1015 DEFUN ("describe-syntax", Fdescribe_syntax
, Sdescribe_syntax
, 0, 0, "",
1016 "Describe the syntax specifications in the syntax table.\n\
1017 The descriptions are inserted in a buffer, which is then displayed.")
1020 internal_with_output_to_temp_buffer
1021 ("*Help*", describe_syntax_1
, current_buffer
->syntax_table
);
1026 int parse_sexp_ignore_comments
;
1028 /* Return the position across COUNT words from FROM.
1029 If that many words cannot be found before the end of the buffer, return 0.
1030 COUNT negative means scan backward and stop at word beginning. */
1032 scan_words (from
, count
)
1033 register int from
, count
;
1035 register int beg
= BEGV
;
1036 register int end
= ZV
;
1037 register int from_byte
= CHAR_TO_BYTE (from
);
1038 register enum syntaxcode code
;
1044 SETUP_SYNTAX_TABLE (from
, count
);
1055 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1056 ch0
= FETCH_CHAR (from_byte
);
1057 code
= SYNTAX (ch0
);
1058 INC_BOTH (from
, from_byte
);
1059 if (words_include_escapes
1060 && (code
== Sescape
|| code
== Scharquote
))
1065 /* Now CH0 is a character which begins a word and FROM is the
1066 position of the next character. */
1069 if (from
== end
) break;
1070 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1071 ch1
= FETCH_CHAR (from_byte
);
1072 code
= SYNTAX (ch1
);
1073 if (!(words_include_escapes
1074 && (code
== Sescape
|| code
== Scharquote
)))
1075 if (code
!= Sword
|| WORD_BOUNDARY_P (ch0
, ch1
))
1077 INC_BOTH (from
, from_byte
);
1091 DEC_BOTH (from
, from_byte
);
1092 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1093 ch1
= FETCH_CHAR (from_byte
);
1094 code
= SYNTAX (ch1
);
1095 if (words_include_escapes
1096 && (code
== Sescape
|| code
== Scharquote
))
1101 /* Now CH1 is a character which ends a word and FROM is the
1109 temp_byte
= dec_bytepos (from_byte
);
1110 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1111 ch0
= FETCH_CHAR (temp_byte
);
1112 code
= SYNTAX (ch0
);
1113 if (!(words_include_escapes
1114 && (code
== Sescape
|| code
== Scharquote
)))
1115 if (code
!= Sword
|| WORD_BOUNDARY_P (ch0
, ch1
))
1117 DEC_BOTH (from
, from_byte
);
1128 DEFUN ("forward-word", Fforward_word
, Sforward_word
, 1, 1, "p",
1129 "Move point forward ARG words (backward if ARG is negative).\n\
1130 Normally returns t.\n\
1131 If an edge of the buffer is reached, point is left there\n\
1132 and nil is returned.")
1137 CHECK_NUMBER (count
, 0);
1139 if (!(val
= scan_words (PT
, XINT (count
))))
1141 SET_PT (XINT (count
) > 0 ? ZV
: BEGV
);
1148 Lisp_Object
skip_chars ();
1150 DEFUN ("skip-chars-forward", Fskip_chars_forward
, Sskip_chars_forward
, 1, 2, 0,
1151 "Move point forward, stopping before a char not in STRING, or at pos LIM.\n\
1152 STRING is like the inside of a `[...]' in a regular expression\n\
1153 except that `]' is never special and `\\' quotes `^', `-' or `\\'.\n\
1154 Thus, with arg \"a-zA-Z\", this skips letters stopping before first nonletter.\n\
1155 With arg \"^a-zA-Z\", skips nonletters stopping before first letter.\n\
1156 Returns the distance traveled, either zero or positive.")
1158 Lisp_Object string
, lim
;
1160 return skip_chars (1, 0, string
, lim
);
1163 DEFUN ("skip-chars-backward", Fskip_chars_backward
, Sskip_chars_backward
, 1, 2, 0,
1164 "Move point backward, stopping after a char not in STRING, or at pos LIM.\n\
1165 See `skip-chars-forward' for details.\n\
1166 Returns the distance traveled, either zero or negative.")
1168 Lisp_Object string
, lim
;
1170 return skip_chars (0, 0, string
, lim
);
1173 DEFUN ("skip-syntax-forward", Fskip_syntax_forward
, Sskip_syntax_forward
, 1, 2, 0,
1174 "Move point forward across chars in specified syntax classes.\n\
1175 SYNTAX is a string of syntax code characters.\n\
1176 Stop before a char whose syntax is not in SYNTAX, or at position LIM.\n\
1177 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.\n\
1178 This function returns the distance traveled, either zero or positive.")
1180 Lisp_Object syntax
, lim
;
1182 return skip_chars (1, 1, syntax
, lim
);
1185 DEFUN ("skip-syntax-backward", Fskip_syntax_backward
, Sskip_syntax_backward
, 1, 2, 0,
1186 "Move point backward across chars in specified syntax classes.\n\
1187 SYNTAX is a string of syntax code characters.\n\
1188 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.\n\
1189 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.\n\
1190 This function returns the distance traveled, either zero or negative.")
1192 Lisp_Object syntax
, lim
;
1194 return skip_chars (0, 1, syntax
, lim
);
1198 skip_chars (forwardp
, syntaxp
, string
, lim
)
1199 int forwardp
, syntaxp
;
1200 Lisp_Object string
, lim
;
1202 register unsigned char *p
, *pend
;
1203 register unsigned int c
;
1205 unsigned char fastmap
[0400];
1206 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters
1207 of which codes don't fit in FASTMAP. In that case, we set the
1208 first byte of multibyte form (i.e. base leading-code) in FASTMAP
1209 and set the actual ranges of characters in CHAR_RANGES. In the
1210 form "X-Y" of STRING, both X and Y must belong to the same
1211 character set because a range striding across character sets is
1214 int n_char_ranges
= 0;
1216 register int i
, i_byte
;
1217 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
1218 int string_multibyte
= STRING_MULTIBYTE (string
);
1220 CHECK_STRING (string
, 0);
1221 char_ranges
= (int *) alloca (XSTRING (string
)->size
* (sizeof (int)) * 2);
1224 XSETINT (lim
, forwardp
? ZV
: BEGV
);
1226 CHECK_NUMBER_COERCE_MARKER (lim
, 0);
1228 /* In any case, don't allow scan outside bounds of buffer. */
1229 if (XINT (lim
) > ZV
)
1230 XSETFASTINT (lim
, ZV
);
1231 if (XINT (lim
) < BEGV
)
1232 XSETFASTINT (lim
, BEGV
);
1234 bzero (fastmap
, sizeof fastmap
);
1238 if (i
< XSTRING (string
)->size
1239 && XSTRING (string
)->data
[0] == '^')
1241 negate
= 1; i
++, i_byte
++;
1244 /* Find the characters specified and set their elements of fastmap.
1245 If syntaxp, each character counts as itself.
1246 Otherwise, handle backslashes and ranges specially. */
1248 while (i
< XSTRING (string
)->size
)
1252 if (string_multibyte
)
1254 c_leading_code
= XSTRING (string
)->data
[i_byte
];
1255 FETCH_STRING_CHAR_ADVANCE (c
, string
, i
, i_byte
);
1258 c
= c_leading_code
= XSTRING (string
)->data
[i
++];
1260 /* Convert multibyteness between what the string has
1261 and what the buffer has. */
1264 if (c
>= 0200 && c
< 0400)
1265 c
+= nonascii_insert_offset
;
1271 fastmap
[syntax_spec_code
[c
& 0377]] = 1;
1276 if (i
== XSTRING (string
)->size
)
1279 if (string_multibyte
)
1280 FETCH_STRING_CHAR_ADVANCE (c
, string
, i
, i_byte
);
1282 c
= XSTRING (string
)->data
[i
++];
1284 if (i
< XSTRING (string
)->size
&& XSTRING (string
)->data
[i
] == '-')
1288 /* Skip over the dash. */
1291 if (i
== XSTRING (string
)->size
)
1294 /* Get the end of the range. */
1295 if (string_multibyte
)
1296 FETCH_STRING_CHAR_ADVANCE (c2
, string
, i
, i_byte
);
1298 c2
= XSTRING (string
)->data
[i
++];
1300 if (SINGLE_BYTE_CHAR_P (c
))
1308 fastmap
[c_leading_code
] = 1;
1311 char_ranges
[n_char_ranges
++] = c
;
1312 char_ranges
[n_char_ranges
++] = c2
;
1318 fastmap
[c_leading_code
] = 1;
1319 if (!SINGLE_BYTE_CHAR_P (c
))
1321 char_ranges
[n_char_ranges
++] = c
;
1322 char_ranges
[n_char_ranges
++] = c
;
1328 /* If ^ was the first character, complement the fastmap. In
1329 addition, as all multibyte characters have possibility of
1330 matching, set all entries for base leading codes, which is
1331 harmless even if SYNTAXP is 1. */
1334 for (i
= 0; i
< sizeof fastmap
; i
++)
1336 if (!multibyte
|| !BASE_LEADING_CODE_P (i
))
1343 int start_point
= PT
;
1345 int pos_byte
= PT_BYTE
;
1350 SETUP_SYNTAX_TABLE (pos
, forwardp
? 1 : -1);
1355 while (pos
< XINT (lim
)
1356 && fastmap
[(int) SYNTAX (FETCH_CHAR (pos_byte
))])
1358 INC_BOTH (pos
, pos_byte
);
1359 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1364 while (pos
< XINT (lim
)
1365 && fastmap
[(int) SYNTAX (FETCH_BYTE (pos
))])
1368 UPDATE_SYNTAX_TABLE_FORWARD (pos
);
1376 while (pos
> XINT (lim
))
1378 int savepos
= pos_byte
;
1379 DEC_BOTH (pos
, pos_byte
);
1380 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
1381 if (!fastmap
[(int) SYNTAX (FETCH_CHAR (pos_byte
))])
1391 while (pos
> XINT (lim
))
1394 UPDATE_SYNTAX_TABLE_BACKWARD (pos
);
1395 if (!fastmap
[(int) SYNTAX (FETCH_BYTE (pos
))])
1409 while (pos
< XINT (lim
) && fastmap
[(c
= FETCH_BYTE (pos_byte
))])
1411 if (!BASE_LEADING_CODE_P (c
))
1412 INC_BOTH (pos
, pos_byte
);
1413 else if (n_char_ranges
)
1415 /* We much check CHAR_RANGES for a multibyte
1417 ch
= FETCH_MULTIBYTE_CHAR (pos_byte
);
1418 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1419 if ((ch
>= char_ranges
[i
] && ch
<= char_ranges
[i
+ 1]))
1421 if (!(negate
^ (i
< n_char_ranges
)))
1424 INC_BOTH (pos
, pos_byte
);
1429 INC_BOTH (pos
, pos_byte
);
1433 while (pos
< XINT (lim
) && fastmap
[FETCH_BYTE (pos
)])
1439 while (pos
> XINT (lim
))
1441 int savepos
= pos_byte
;
1442 DEC_BOTH (pos
, pos_byte
);
1443 if (fastmap
[(c
= FETCH_BYTE (pos_byte
))])
1445 if (!BASE_LEADING_CODE_P (c
))
1447 else if (n_char_ranges
)
1449 /* We much check CHAR_RANGES for a multibyte
1451 ch
= FETCH_MULTIBYTE_CHAR (pos_byte
);
1452 for (i
= 0; i
< n_char_ranges
; i
+= 2)
1453 if (ch
>= char_ranges
[i
] && ch
<= char_ranges
[i
+ 1])
1455 if (!(negate
^ (i
< n_char_ranges
)))
1478 while (pos
> XINT (lim
) && fastmap
[FETCH_BYTE (pos
- 1)])
1483 #if 0 /* Not needed now that a position in mid-character
1484 cannot be specified in Lisp. */
1486 /* INC_POS or DEC_POS might have moved POS over LIM. */
1487 && (forwardp
? (pos
> XINT (lim
)) : (pos
< XINT (lim
))))
1494 SET_PT_BOTH (pos
, pos_byte
);
1497 return make_number (PT
- start_point
);
1501 DEFUN ("forward-comment", Fforward_comment
, Sforward_comment
, 1, 1, 0,
1502 "Move forward across up to N comments. If N is negative, move backward.\n\
1503 Stop scanning if we find something other than a comment or whitespace.\n\
1504 Set point to where scanning stops.\n\
1505 If N comments are found as expected, with nothing except whitespace\n\
1506 between them, return t; otherwise return nil.")
1514 register enum syntaxcode code
;
1515 int comstyle
= 0; /* style of comment encountered */
1519 int out_charpos
, out_bytepos
;
1521 CHECK_NUMBER (count
, 0);
1522 count1
= XINT (count
);
1523 stop
= count1
> 0 ? ZV
: BEGV
;
1529 from_byte
= PT_BYTE
;
1531 SETUP_SYNTAX_TABLE (from
, count1
);
1538 if (! NILP (current_buffer
->enable_multibyte_characters
))
1539 SET_PT_BOTH (from
, from_byte
);
1541 SET_PT_BOTH (from_byte
, from_byte
);
1545 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1546 c
= FETCH_CHAR (from_byte
);
1548 INC_BOTH (from
, from_byte
);
1550 if (from
< stop
&& SYNTAX_COMSTART_FIRST (c
)
1551 && (c1
= FETCH_CHAR (from_byte
),
1552 SYNTAX_COMSTART_SECOND (c1
)))
1554 /* We have encountered a comment start sequence and we
1555 are ignoring all text inside comments. We must record
1556 the comment style this sequence begins so that later,
1557 only a comment end of the same style actually ends
1558 the comment section. */
1560 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
1561 INC_BOTH (from
, from_byte
);
1564 while (code
== Swhitespace
|| code
== Sendcomment
);
1566 if (code
!= Scomment
&& code
!= Scomment_fence
)
1569 DEC_BOTH (from
, from_byte
);
1570 if (! NILP (current_buffer
->enable_multibyte_characters
))
1571 SET_PT_BOTH (from
, from_byte
);
1573 SET_PT_BOTH (from_byte
, from_byte
);
1576 /* We're at the start of a comment. */
1582 if (! NILP (current_buffer
->enable_multibyte_characters
))
1583 SET_PT_BOTH (from
, from_byte
);
1585 SET_PT_BOTH (from_byte
, from_byte
);
1588 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1589 c
= FETCH_CHAR (from_byte
);
1590 INC_BOTH (from
, from_byte
);
1591 if (SYNTAX (c
) == Sendcomment
1592 && SYNTAX_COMMENT_STYLE (c
) == comstyle
)
1593 /* we have encountered a comment end of the same style
1594 as the comment sequence which began this comment
1597 if (SYNTAX (c
) == Scomment_fence
1598 && comstyle
== ST_COMMENT_STYLE
)
1599 /* we have encountered a comment end of the same style
1600 as the comment sequence which began this comment
1603 if (from
< stop
&& SYNTAX_COMEND_FIRST (c
)
1604 && (c1
= FETCH_CHAR (from_byte
),
1605 SYNTAX_COMEND_SECOND (c1
))
1606 && SYNTAX_COMMENT_STYLE (c
) == comstyle
)
1607 /* we have encountered a comment end of the same style
1608 as the comment sequence which began this comment
1611 INC_BOTH (from
, from_byte
);
1615 /* We have skipped one comment. */
1626 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
1631 DEC_BOTH (from
, from_byte
);
1632 quoted
= char_quoted (from
, from_byte
);
1635 DEC_BOTH (from
, from_byte
);
1638 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1639 c
= FETCH_CHAR (from_byte
);
1642 if (code
== Sendcomment
)
1643 comstyle
= SYNTAX_COMMENT_STYLE (c
);
1644 temp_pos
= from_byte
;
1646 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
1647 && (c1
= FETCH_CHAR (temp_pos
),
1648 SYNTAX_COMEND_FIRST (c1
))
1649 && !char_quoted (from
- 1, temp_pos
))
1651 /* We must record the comment style encountered so that
1652 later, we can match only the proper comment begin
1653 sequence of the same style. */
1655 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
1656 DEC_BOTH (from
, from_byte
);
1658 if (from
> stop
&& SYNTAX_COMSTART_SECOND (c
)
1659 && (c1
= FETCH_CHAR (temp_pos
),
1660 SYNTAX_COMSTART_FIRST (c1
))
1661 && !char_quoted (from
- 1, temp_pos
))
1663 /* We must record the comment style encountered so that
1664 later, we can match only the proper comment begin
1665 sequence of the same style. */
1667 DEC_BOTH (from
, from_byte
);
1670 if (code
== Scomment_fence
)
1672 /* Skip until first preceding unquoted comment_fence. */
1673 int found
= 0, ini
= from
, ini_byte
= from_byte
;
1677 DEC_BOTH (from
, from_byte
);
1680 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1681 c
= FETCH_CHAR (from_byte
);
1682 if (SYNTAX (c
) == Scomment_fence
1683 && !char_quoted (from
, from_byte
))
1691 from
= ini
; /* Set point to ini + 1. */
1692 from_byte
= ini_byte
;
1696 else if (code
== Sendcomment
)
1698 found
= back_comment (from
, from_byte
, stop
, comstyle
,
1699 &out_charpos
, &out_bytepos
);
1701 from
= out_charpos
, from_byte
= out_bytepos
;
1702 /* We have skipped one comment. */
1705 else if (code
!= Swhitespace
&& code
!= Scomment
)
1709 INC_BOTH (from
, from_byte
);
1710 if (! NILP (current_buffer
->enable_multibyte_characters
))
1711 SET_PT_BOTH (from
, from_byte
);
1713 SET_PT_BOTH (from_byte
, from_byte
);
1721 if (! NILP (current_buffer
->enable_multibyte_characters
))
1722 SET_PT_BOTH (from
, from_byte
);
1724 SET_PT_BOTH (from_byte
, from_byte
);
1730 scan_lists (from
, count
, depth
, sexpflag
)
1732 int count
, depth
, sexpflag
;
1735 register int stop
= count
> 0 ? ZV
: BEGV
;
1740 register enum syntaxcode code
, temp_code
;
1741 int min_depth
= depth
; /* Err out if depth gets less than this. */
1742 int comstyle
= 0; /* style of comment encountered */
1744 int last_good
= from
;
1746 int from_byte
= CHAR_TO_BYTE (from
);
1747 int out_bytepos
, out_charpos
;
1749 if (depth
> 0) min_depth
= 0;
1754 SETUP_SYNTAX_TABLE (from
, count
);
1759 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1760 c
= FETCH_CHAR (from_byte
);
1762 if (depth
== min_depth
)
1764 INC_BOTH (from
, from_byte
);
1765 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1766 if (from
< stop
&& SYNTAX_COMSTART_FIRST (c
)
1767 && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from_byte
))
1768 && parse_sexp_ignore_comments
)
1770 /* we have encountered a comment start sequence and we
1771 are ignoring all text inside comments. We must record
1772 the comment style this sequence begins so that later,
1773 only a comment end of the same style actually ends
1774 the comment section */
1776 comstyle
= SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
));
1777 INC_BOTH (from
, from_byte
);
1780 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1781 if (SYNTAX_PREFIX (c
))
1784 switch (SWITCH_ENUM_CAST (code
))
1788 if (from
== stop
) goto lose
;
1789 INC_BOTH (from
, from_byte
);
1790 /* treat following character as a word constituent */
1793 if (depth
|| !sexpflag
) break;
1794 /* This word counts as a sexp; return at end of it. */
1797 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1798 switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte
))))
1802 INC_BOTH (from
, from_byte
);
1803 if (from
== stop
) goto lose
;
1812 INC_BOTH (from
, from_byte
);
1817 case Scomment_fence
:
1818 if (!parse_sexp_ignore_comments
) break;
1827 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1828 c
= FETCH_CHAR (from_byte
);
1829 if (code
== Scomment
1830 ? (SYNTAX (c
) == Sendcomment
1831 && SYNTAX_COMMENT_STYLE (c
) == comstyle
)
1832 : (SYNTAX (c
) == Scomment_fence
))
1833 /* we have encountered a comment end of the same style
1834 as the comment sequence which began this comment
1837 INC_BOTH (from
, from_byte
);
1838 if (from
< stop
&& SYNTAX_COMEND_FIRST (c
)
1839 && SYNTAX_COMEND_SECOND (FETCH_CHAR (from_byte
))
1840 && SYNTAX_COMMENT_STYLE (c
) == comstyle
1841 && code
== Scomment
)
1842 /* we have encountered a comment end of the same style
1843 as the comment sequence which began this comment
1846 INC_BOTH (from
, from_byte
);
1855 if (from
!= stop
&& c
== FETCH_CHAR (from_byte
))
1857 INC_BOTH (from
, from_byte
);
1867 if (!++depth
) goto done
;
1872 if (!--depth
) goto done
;
1873 if (depth
< min_depth
)
1874 Fsignal (Qscan_error
,
1875 Fcons (build_string ("Containing expression ends prematurely"),
1876 Fcons (make_number (last_good
),
1877 Fcons (make_number (from
), Qnil
))));
1882 temp_pos
= from_byte
;
1884 stringterm
= FETCH_CHAR (temp_pos
);
1887 if (from
>= stop
) goto lose
;
1888 UPDATE_SYNTAX_TABLE_FORWARD (from
);
1890 ? (FETCH_CHAR (from_byte
) == stringterm
)
1891 : SYNTAX (FETCH_CHAR (from_byte
)) == Sstring_fence
)
1893 switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte
))))
1897 INC_BOTH (from
, from_byte
);
1899 INC_BOTH (from
, from_byte
);
1901 INC_BOTH (from
, from_byte
);
1902 if (!depth
&& sexpflag
) goto done
;
1907 /* Reached end of buffer. Error if within object, return nil if between */
1908 if (depth
) goto lose
;
1913 /* End of object reached */
1922 DEC_BOTH (from
, from_byte
);
1923 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
1924 c
= FETCH_CHAR (from_byte
);
1926 if (depth
== min_depth
)
1929 if (code
== Sendcomment
)
1930 comstyle
= SYNTAX_COMMENT_STYLE (c
);
1931 temp_pos
= from_byte
;
1933 if (from
> stop
&& SYNTAX_COMEND_SECOND (c
)
1934 && (c1
= FETCH_CHAR (temp_pos
), SYNTAX_COMEND_FIRST (c1
))
1935 && parse_sexp_ignore_comments
)
1937 /* we must record the comment style encountered so that
1938 later, we can match only the proper comment begin
1939 sequence of the same style */
1941 comstyle
= SYNTAX_COMMENT_STYLE (c1
);
1942 DEC_BOTH (from
, from_byte
);
1945 /* Quoting turns anything except a comment-ender
1946 into a word character. */
1947 if (code
!= Sendcomment
&& char_quoted (from
, from_byte
))
1949 else if (SYNTAX_PREFIX (c
))
1952 switch (SWITCH_ENUM_CAST (code
))
1958 if (depth
|| !sexpflag
) break;
1959 /* This word counts as a sexp; count object finished
1960 after passing it. */
1963 temp_pos
= from_byte
;
1965 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
1966 c1
= FETCH_CHAR (temp_pos
);
1967 temp_code
= SYNTAX (c1
);
1968 /* Don't allow comment-end to be quoted. */
1969 if (temp_code
== Sendcomment
)
1971 quoted
= char_quoted (from
- 1, temp_pos
);
1974 DEC_BOTH (from
, from_byte
);
1976 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
1978 c1
= FETCH_CHAR (temp_pos
);
1979 temp_code
= SYNTAX (c1
);
1980 if (! (quoted
|| temp_code
== Sword
1981 || temp_code
== Ssymbol
1982 || temp_code
== Squote
))
1984 DEC_BOTH (from
, from_byte
);
1991 temp_pos
= from_byte
;
1993 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
1994 if (from
!= stop
&& c
== FETCH_CHAR (temp_pos
))
1995 DEC_BOTH (from
, from_byte
);
2004 if (!++depth
) goto done2
;
2009 if (!--depth
) goto done2
;
2010 if (depth
< min_depth
)
2011 Fsignal (Qscan_error
,
2012 Fcons (build_string ("Containing expression ends prematurely"),
2013 Fcons (make_number (last_good
),
2014 Fcons (make_number (from
), Qnil
))));
2018 if (!parse_sexp_ignore_comments
)
2020 found
= back_comment (from
, from_byte
, stop
, comstyle
,
2021 &out_charpos
, &out_bytepos
);
2023 from
= out_charpos
, from_byte
= out_bytepos
;
2026 case Scomment_fence
:
2030 DEC_BOTH (from
, from_byte
);
2031 if (from
== stop
) goto lose
;
2032 UPDATE_SYNTAX_TABLE_BACKWARD (from
);
2033 if (!char_quoted (from
, from_byte
)
2034 && SYNTAX (FETCH_CHAR (from_byte
)) == code
)
2037 if (code
== Sstring_fence
&& !depth
&& sexpflag
) goto done2
;
2041 stringterm
= FETCH_CHAR (from_byte
);
2044 if (from
== stop
) goto lose
;
2045 temp_pos
= from_byte
;
2047 UPDATE_SYNTAX_TABLE_BACKWARD (from
- 1);
2048 if (!char_quoted (from
- 1, temp_pos
)
2049 && stringterm
== FETCH_CHAR (temp_pos
))
2051 DEC_BOTH (from
, from_byte
);
2053 DEC_BOTH (from
, from_byte
);
2054 if (!depth
&& sexpflag
) goto done2
;
2059 /* Reached start of buffer. Error if within object, return nil if between */
2060 if (depth
) goto lose
;
2071 XSETFASTINT (val
, from
);
2075 Fsignal (Qscan_error
,
2076 Fcons (build_string ("Unbalanced parentheses"),
2077 Fcons (make_number (last_good
),
2078 Fcons (make_number (from
), Qnil
))));
2083 DEFUN ("scan-lists", Fscan_lists
, Sscan_lists
, 3, 3, 0,
2084 "Scan from character number FROM by COUNT lists.\n\
2085 Returns the character number of the position thus found.\n\
2087 If DEPTH is nonzero, paren depth begins counting from that value,\n\
2088 only places where the depth in parentheses becomes zero\n\
2089 are candidates for stopping; COUNT such places are counted.\n\
2090 Thus, a positive value for DEPTH means go out levels.\n\
2092 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.\n\
2094 If the beginning or end of (the accessible part of) the buffer is reached\n\
2095 and the depth is wrong, an error is signaled.\n\
2096 If the depth is right but the count is not used up, nil is returned.")
2097 (from
, count
, depth
)
2098 Lisp_Object from
, count
, depth
;
2100 CHECK_NUMBER (from
, 0);
2101 CHECK_NUMBER (count
, 1);
2102 CHECK_NUMBER (depth
, 2);
2104 return scan_lists (XINT (from
), XINT (count
), XINT (depth
), 0);
2107 DEFUN ("scan-sexps", Fscan_sexps
, Sscan_sexps
, 2, 2, 0,
2108 "Scan from character number FROM by COUNT balanced expressions.\n\
2109 If COUNT is negative, scan backwards.\n\
2110 Returns the character number of the position thus found.\n\
2112 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.\n\
2114 If the beginning or end of (the accessible part of) the buffer is reached\n\
2115 in the middle of a parenthetical grouping, an error is signaled.\n\
2116 If the beginning or end is reached between groupings\n\
2117 but before count is used up, nil is returned.")
2119 Lisp_Object from
, count
;
2121 CHECK_NUMBER (from
, 0);
2122 CHECK_NUMBER (count
, 1);
2124 return scan_lists (XINT (from
), XINT (count
), 0, 1);
2127 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars
, Sbackward_prefix_chars
,
2129 "Move point backward over any number of chars with prefix syntax.\n\
2130 This includes chars with \"quote\" or \"prefix\" syntax (' or p).")
2135 int opoint_byte
= PT_BYTE
;
2137 int pos_byte
= PT_BYTE
;
2142 SETUP_SYNTAX_TABLE (pos
, -1);
2145 DEC_BOTH (pos
, pos_byte
);
2147 while (pos
+ 1 > beg
&& !char_quoted (pos
, pos_byte
)
2148 /* Previous statement updates syntax table. */
2149 && ((c
= FETCH_CHAR (pos_byte
), SYNTAX (c
) == Squote
)
2150 || SYNTAX_PREFIX (c
)))
2152 DEC_BOTH (pos
, pos_byte
);
2155 SET_PT_BOTH (opoint
, opoint_byte
);
2160 /* Parse forward from FROM / FROM_BYTE to END,
2161 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
2162 and return a description of the state of the parse at END.
2163 If STOPBEFORE is nonzero, stop at the start of an atom.
2164 If COMMENTSTOP is 1, stop at the start of a comment.
2165 If COMMENTSTOP is -1, stop at the start or end of a comment,
2166 after the beginning of a string, or after the end of a string. */
2169 scan_sexps_forward (stateptr
, from
, from_byte
, end
, targetdepth
,
2170 stopbefore
, oldstate
, commentstop
)
2171 struct lisp_parse_state
*stateptr
;
2173 int end
, targetdepth
, stopbefore
;
2174 Lisp_Object oldstate
;
2177 struct lisp_parse_state state
;
2179 register enum syntaxcode code
;
2180 struct level
{ int last
, prev
; };
2181 struct level levelstart
[100];
2182 register struct level
*curlevel
= levelstart
;
2183 struct level
*endlevel
= levelstart
+ 100;
2185 register int depth
; /* Paren depth of current scanning location.
2186 level - levelstart equals this except
2187 when the depth becomes negative. */
2188 int mindepth
; /* Lowest DEPTH value seen. */
2189 int start_quoted
= 0; /* Nonzero means starting after a char quote */
2191 int prev_from
; /* Keep one character before FROM. */
2193 int boundary_stop
= commentstop
== -1;
2197 prev_from_byte
= from_byte
;
2199 DEC_BOTH (prev_from
, prev_from_byte
);
2201 /* Use this macro instead of `from++'. */
2203 do { prev_from = from; \
2204 prev_from_byte = from_byte; \
2206 INC_POS (from_byte); \
2212 SETUP_SYNTAX_TABLE (from
, 1);
2214 if (NILP (oldstate
))
2217 state
.instring
= -1;
2218 state
.incomment
= 0;
2219 state
.comstyle
= 0; /* comment style a by default. */
2220 state
.comstr_start
= -1; /* no comment/string seen. */
2224 tem
= Fcar (oldstate
);
2230 oldstate
= Fcdr (oldstate
);
2231 oldstate
= Fcdr (oldstate
);
2232 oldstate
= Fcdr (oldstate
);
2233 tem
= Fcar (oldstate
);
2234 /* Check whether we are inside string_fence-style string: */
2235 state
.instring
= ( !NILP (tem
)
2236 ? ( INTEGERP (tem
) ? XINT (tem
) : ST_STRING_STYLE
)
2239 oldstate
= Fcdr (oldstate
);
2240 tem
= Fcar (oldstate
);
2241 state
.incomment
= !NILP (tem
);
2243 oldstate
= Fcdr (oldstate
);
2244 tem
= Fcar (oldstate
);
2245 start_quoted
= !NILP (tem
);
2247 /* if the eight element of the list is nil, we are in comment
2248 style a. If it is non-nil, we are in comment style b */
2249 oldstate
= Fcdr (oldstate
);
2250 oldstate
= Fcdr (oldstate
);
2251 tem
= Fcar (oldstate
);
2252 state
.comstyle
= NILP (tem
) ? 0 : ( EQ (tem
, Qsyntax_table
)
2253 ? ST_COMMENT_STYLE
: 1 );
2255 oldstate
= Fcdr (oldstate
);
2256 tem
= Fcar (oldstate
);
2257 state
.comstr_start
= NILP (tem
) ? -1 : XINT (tem
) ;
2262 curlevel
->prev
= -1;
2263 curlevel
->last
= -1;
2265 /* Enter the loop at a place appropriate for initial state. */
2267 if (state
.incomment
) goto startincomment
;
2268 if (state
.instring
>= 0)
2270 nofence
= state
.instring
!= ST_STRING_STYLE
;
2271 if (start_quoted
) goto startquotedinstring
;
2274 if (start_quoted
) goto startquoted
;
2278 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2279 code
= SYNTAX (FETCH_CHAR (from_byte
));
2282 if (code
== Scomment
)
2283 state
.comstr_start
= prev_from
;
2284 else if (code
== Scomment_fence
)
2286 /* Record the comment style we have entered so that only
2287 the comment-end sequence of the same style actually
2288 terminates the comment section. */
2289 state
.comstyle
= ( code
== Scomment_fence
2291 : SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
)));
2292 state
.comstr_start
= prev_from
;
2293 if (code
!= Scomment_fence
) INC_FROM
;
2296 else if (from
< end
)
2297 if (SYNTAX_COMSTART_FIRST (FETCH_CHAR (prev_from_byte
)))
2298 if (SYNTAX_COMSTART_SECOND (FETCH_CHAR (from_byte
)))
2299 /* Duplicate code to avoid a very complex if-expression
2300 which causes trouble for the SGI compiler. */
2302 /* Record the comment style we have entered so that only
2303 the comment-end sequence of the same style actually
2304 terminates the comment section. */
2305 state
.comstyle
= ( code
== Scomment_fence
2307 : SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte
)));
2308 state
.comstr_start
= prev_from
;
2309 if (code
!= Scomment_fence
) INC_FROM
;
2313 if (SYNTAX_PREFIX (FETCH_CHAR (prev_from_byte
)))
2315 switch (SWITCH_ENUM_CAST (code
))
2319 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2320 curlevel
->last
= prev_from
;
2322 if (from
== end
) goto endquoted
;
2325 /* treat following character as a word constituent */
2328 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2329 curlevel
->last
= prev_from
;
2333 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2334 switch (SWITCH_ENUM_CAST (SYNTAX (FETCH_CHAR (from_byte
))))
2339 if (from
== end
) goto endquoted
;
2351 curlevel
->prev
= curlevel
->last
;
2355 if (commentstop
== 1)
2359 /* Enter the loop in the middle so that we find
2360 a 2-char comment ender if we start in the middle of it. */
2361 prev
= FETCH_CHAR (prev_from_byte
);
2362 goto startincomment_1
;
2364 /* At beginning of buffer, enter the loop the ordinary way. */
2365 state
.incomment
= 1;
2369 state
.incomment
= 1;
2370 if (commentstop
|| boundary_stop
) goto done
;
2374 if (from
== end
) goto done
;
2375 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2376 prev
= FETCH_CHAR (from_byte
);
2377 if (SYNTAX (prev
) == Sendcomment
2378 && SYNTAX_COMMENT_STYLE (prev
) == state
.comstyle
)
2379 /* Only terminate the comment section if the endcomment
2380 of the same style as the start sequence has been
2383 if (state
.comstyle
== ST_COMMENT_STYLE
2384 && SYNTAX (prev
) == Scomment_fence
)
2388 if (from
< end
&& SYNTAX_COMEND_FIRST (prev
)
2389 && SYNTAX_COMEND_SECOND (FETCH_CHAR (from_byte
))
2390 && SYNTAX_COMMENT_STYLE (prev
) == state
.comstyle
)
2391 /* Only terminate the comment section if the end-comment
2392 sequence of the same style as the start sequence has
2393 been encountered. */
2397 state
.incomment
= 0;
2398 state
.comstyle
= 0; /* reset the comment style */
2399 if (boundary_stop
) goto done
;
2403 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2405 /* curlevel++->last ran into compiler bug on Apollo */
2406 curlevel
->last
= prev_from
;
2407 if (++curlevel
== endlevel
)
2408 error ("Nesting too deep for parser");
2409 curlevel
->prev
= -1;
2410 curlevel
->last
= -1;
2411 if (targetdepth
== depth
) goto done
;
2416 if (depth
< mindepth
)
2418 if (curlevel
!= levelstart
)
2420 curlevel
->prev
= curlevel
->last
;
2421 if (targetdepth
== depth
) goto done
;
2426 state
.comstr_start
= from
- 1;
2427 if (stopbefore
) goto stop
; /* this arg means stop at sexp start */
2428 curlevel
->last
= prev_from
;
2429 state
.instring
= (code
== Sstring
2430 ? (FETCH_CHAR (prev_from_byte
))
2432 if (boundary_stop
) goto done
;
2435 nofence
= state
.instring
!= ST_STRING_STYLE
;
2441 if (from
>= end
) goto done
;
2442 c
= FETCH_CHAR (from_byte
);
2443 if (nofence
&& c
== state
.instring
) break;
2444 UPDATE_SYNTAX_TABLE_FORWARD (from
);
2445 switch (SWITCH_ENUM_CAST (SYNTAX (c
)))
2448 if (!nofence
) goto string_end
;
2453 startquotedinstring
:
2454 if (from
>= end
) goto endquoted
;
2460 state
.instring
= -1;
2461 curlevel
->prev
= curlevel
->last
;
2463 if (boundary_stop
) goto done
;
2472 stop
: /* Here if stopping before start of sexp. */
2473 from
= prev_from
; /* We have just fetched the char that starts it; */
2474 goto done
; /* but return the position before it. */
2479 state
.depth
= depth
;
2480 state
.mindepth
= mindepth
;
2481 state
.thislevelstart
= curlevel
->prev
;
2482 state
.prevlevelstart
2483 = (curlevel
== levelstart
) ? -1 : (curlevel
- 1)->last
;
2484 state
.location
= from
;
2490 /* This comment supplies the doc string for parse-partial-sexp,
2491 for make-docfile to see. We cannot put this in the real DEFUN
2492 due to limits in the Unix cpp.
2494 DEFUN ("parse-partial-sexp", Ffoo, Sfoo, 2, 6, 0,
2495 "Parse Lisp syntax starting at FROM until TO; return status of parse at TO.\n\
2496 Parsing stops at TO or when certain criteria are met;\n\
2497 point is set to where parsing stops.\n\
2498 If fifth arg STATE is omitted or nil,\n\
2499 parsing assumes that FROM is the beginning of a function.\n\
2500 Value is a list of nine elements describing final state of parsing:\n\
2501 0. depth in parens.\n\
2502 1. character address of start of innermost containing list; nil if none.\n\
2503 2. character address of start of last complete sexp terminated.\n\
2504 3. non-nil if inside a string.\n\
2505 (it is the character that will terminate the string,\n\
2506 or t if the string should be terminated by a generic string delimiter.)\n\
2507 4. t if inside a comment.\n\
2508 5. t if following a quote character.\n\
2509 6. the minimum paren-depth encountered during this scan.\n\
2510 7. t if in a comment of style b; `syntax-table' if the comment\n\
2511 should be terminated by a generic comment delimiter.\n\
2512 8. character address of start of comment or string; nil if not in one.\n\
2513 If third arg TARGETDEPTH is non-nil, parsing stops if the depth\n\
2514 in parentheses becomes equal to TARGETDEPTH.\n\
2515 Fourth arg STOPBEFORE non-nil means stop when come to\n\
2516 any character that starts a sexp.\n\
2517 Fifth arg STATE is a nine-element list like what this function returns.\n\
2518 It is used to initialize the state of the parse. Elements number 1, 2, 6\n\
2519 and 8 are ignored; you can leave off element 8 (the last) entirely.\n\
2520 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.\n\
2521 If it is `syntax-table', stop after the start of a comment or a string,\n\
2522 or after end of a comment or a string.")
2523 (from, to, targetdepth, stopbefore, state, commentstop)
2526 DEFUN ("parse-partial-sexp", Fparse_partial_sexp
, Sparse_partial_sexp
, 2, 6, 0,
2527 0 /* See immediately above */)
2528 (from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
)
2529 Lisp_Object from
, to
, targetdepth
, stopbefore
, oldstate
, commentstop
;
2531 struct lisp_parse_state state
;
2534 if (!NILP (targetdepth
))
2536 CHECK_NUMBER (targetdepth
, 3);
2537 target
= XINT (targetdepth
);
2540 target
= -100000; /* We won't reach this depth */
2542 validate_region (&from
, &to
);
2543 scan_sexps_forward (&state
, XINT (from
), CHAR_TO_BYTE (XINT (from
)),
2545 target
, !NILP (stopbefore
), oldstate
,
2547 ? 0 : (EQ (commentstop
, Qsyntax_table
) ? -1 : 1)));
2549 SET_PT (state
.location
);
2551 return Fcons (make_number (state
.depth
),
2552 Fcons (state
.prevlevelstart
< 0 ? Qnil
: make_number (state
.prevlevelstart
),
2553 Fcons (state
.thislevelstart
< 0 ? Qnil
: make_number (state
.thislevelstart
),
2554 Fcons (state
.instring
>= 0
2555 ? (state
.instring
== ST_STRING_STYLE
2556 ? Qt
: make_number (state
.instring
)) : Qnil
,
2557 Fcons (state
.incomment
? Qt
: Qnil
,
2558 Fcons (state
.quoted
? Qt
: Qnil
,
2559 Fcons (make_number (state
.mindepth
),
2560 Fcons ((state
.comstyle
2561 ? (state
.comstyle
== ST_COMMENT_STYLE
2562 ? Qsyntax_table
: Qt
) :
2564 Fcons ((state
.incomment
|| state
.instring
2565 ? make_number (state
.comstr_start
)
2575 /* This has to be done here, before we call Fmake_char_table. */
2576 Qsyntax_table
= intern ("syntax-table");
2577 staticpro (&Qsyntax_table
);
2579 /* Intern this now in case it isn't already done.
2580 Setting this variable twice is harmless.
2581 But don't staticpro it here--that is done in alloc.c. */
2582 Qchar_table_extra_slots
= intern ("char-table-extra-slots");
2584 /* Create objects which can be shared among syntax tables. */
2585 Vsyntax_code_object
= Fmake_vector (make_number (13), Qnil
);
2586 for (i
= 0; i
< XVECTOR (Vsyntax_code_object
)->size
; i
++)
2587 XVECTOR (Vsyntax_code_object
)->contents
[i
]
2588 = Fcons (make_number (i
), Qnil
);
2590 /* Now we are ready to set up this property, so we can
2591 create syntax tables. */
2592 Fput (Qsyntax_table
, Qchar_table_extra_slots
, make_number (0));
2594 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Swhitespace
];
2596 Vstandard_syntax_table
= Fmake_char_table (Qsyntax_table
, temp
);
2598 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Sword
];
2599 for (i
= 'a'; i
<= 'z'; i
++)
2600 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
2601 for (i
= 'A'; i
<= 'Z'; i
++)
2602 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
2603 for (i
= '0'; i
<= '9'; i
++)
2604 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, i
, temp
);
2606 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '$', temp
);
2607 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '%', temp
);
2609 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '(',
2610 Fcons (make_number (Sopen
), make_number (')')));
2611 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ')',
2612 Fcons (make_number (Sclose
), make_number ('(')));
2613 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '[',
2614 Fcons (make_number (Sopen
), make_number (']')));
2615 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, ']',
2616 Fcons (make_number (Sclose
), make_number ('[')));
2617 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '{',
2618 Fcons (make_number (Sopen
), make_number ('}')));
2619 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '}',
2620 Fcons (make_number (Sclose
), make_number ('{')));
2621 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '"',
2622 Fcons (make_number ((int) Sstring
), Qnil
));
2623 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, '\\',
2624 Fcons (make_number ((int) Sescape
), Qnil
));
2626 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Ssymbol
];
2627 for (i
= 0; i
< 10; i
++)
2629 c
= "_-+*/&|<>="[i
];
2630 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
2633 temp
= XVECTOR (Vsyntax_code_object
)->contents
[(int) Spunct
];
2634 for (i
= 0; i
< 12; i
++)
2636 c
= ".,;:?!#@~^'`"[i
];
2637 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table
, c
, temp
);
2643 Qsyntax_table_p
= intern ("syntax-table-p");
2644 staticpro (&Qsyntax_table_p
);
2646 staticpro (&Vsyntax_code_object
);
2648 Qscan_error
= intern ("scan-error");
2649 staticpro (&Qscan_error
);
2650 Fput (Qscan_error
, Qerror_conditions
,
2651 Fcons (Qerror
, Qnil
));
2652 Fput (Qscan_error
, Qerror_message
,
2653 build_string ("Scan error"));
2655 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments
,
2656 "Non-nil means `forward-sexp', etc., should treat comments as whitespace.");
2658 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties
,
2659 "Non-nil means `forward-sexp', etc., grant `syntax-table' property.\n\
2660 The value of this property should be either a syntax table, or a cons\n\
2661 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric\n\
2662 syntax code, MATCHCHAR being nil or the character to match (which is\n\
2663 relevant only for open/close type.");
2665 words_include_escapes
= 0;
2666 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes
,
2667 "Non-nil means `forward-word', etc., should treat escape chars part of words.");
2669 defsubr (&Ssyntax_table_p
);
2670 defsubr (&Ssyntax_table
);
2671 defsubr (&Sstandard_syntax_table
);
2672 defsubr (&Scopy_syntax_table
);
2673 defsubr (&Sset_syntax_table
);
2674 defsubr (&Schar_syntax
);
2675 defsubr (&Smatching_paren
);
2676 defsubr (&Smodify_syntax_entry
);
2677 defsubr (&Sdescribe_syntax
);
2679 defsubr (&Sforward_word
);
2681 defsubr (&Sskip_chars_forward
);
2682 defsubr (&Sskip_chars_backward
);
2683 defsubr (&Sskip_syntax_forward
);
2684 defsubr (&Sskip_syntax_backward
);
2686 defsubr (&Sforward_comment
);
2687 defsubr (&Sscan_lists
);
2688 defsubr (&Sscan_sexps
);
2689 defsubr (&Sbackward_prefix_chars
);
2690 defsubr (&Sparse_partial_sexp
);