annotate src/syntax.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 9d177e8d4150
children abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* XEmacs routines to deal with syntax tables; also word and list parsing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985-1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.28. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* This file has been Mule-ized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 /* Here is a comment from Ken'ichi HANDA <handa@etl.go.jp>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 explaining the purpose of the Sextword syntax category:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 Japanese words are not separated by spaces, which makes finding word
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 boundaries very difficult. Theoretically it's impossible without
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 using natural language processing techniques. But, by defining
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 pseudo-words as below (much simplified for letting you understand it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 easily) for Japanese, we can have a convenient forward-word function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 for Japanese.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 A Japanese word is a sequence of characters that consists of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 zero or more Kanji characters followed by zero or more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Hiragana characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Then, the problem is that now we can't say that a sequence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 word-constituents makes up a WORD. For instance, both Hiragana "A"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 and Kanji "KAN" are word-constituents but the sequence of these two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 letters can't be a single word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 So, we introduced Sextword for Japanese letters. A character of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 Sextword is a word-constituent but a word boundary may exist between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 two such characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 /* Mule 2.4 doesn't seem to have Sextword - I'm removing it -- mrb */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 /* Recovered by tomo */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Lisp_Object Qsyntax_table_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 int words_include_escapes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 int parse_sexp_ignore_comments;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 /* The following two variables are provided to tell additional information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 to the regex routines. We do it this way rather than change the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 arguments to re_search_2() in an attempt to maintain some call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 compatibility with other versions of the regex code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 /* Tell the regex routines not to QUIT. Normally there is a QUIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 each iteration in re_search_2(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 int no_quit_in_re_search;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 /* Tell the regex routines which buffer to access for SYNTAX() lookups
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 and the like. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 struct buffer *regex_emacs_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 Lisp_Object Vstandard_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Lisp_Object Vsyntax_designator_chars_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 /* This is the internal form of the parse state used in parse-partial-sexp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 struct lisp_parse_state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 int depth; /* Depth at end of parsing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 Emchar instring; /* -1 if not within string, else desired terminator */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 int incomment; /* Nonzero if within a comment at end of parsing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 int comstyle; /* comment style a=0, or b=1 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 int quoted; /* Nonzero if just after an escape char at end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 parsing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 Bufpos thislevelstart;/* Char number of most recent start-of-expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 at current level */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 Bufpos prevlevelstart;/* Char number of start of containing expression */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Bufpos location; /* Char number at which parsing stopped */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 int mindepth; /* Minimum depth seen while scanning */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 Bufpos comstart; /* Position just after last comment starter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 /* These variables are a cache for finding the start of a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 find_start_pos is the place for which the defun start was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 find_start_value is the defun start position found for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 find_start_buffer is the buffer it was found in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 find_start_begv is the BEGV value when it was found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 find_start_modiff is the value of MODIFF when it was found. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 static Bufpos find_start_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 static Bufpos find_start_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 static struct buffer *find_start_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 static Bufpos find_start_begv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 static int find_start_modiff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 /* Find a defun-start that is the last one before POS (or nearly the last).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 We record what we find, so that another call in the same area
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 can return the same value right away. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 static Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 find_defun_start (struct buffer *buf, Bufpos pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 Bufpos tem;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
120 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 /* Use previous finding, if it's valid and applies to this inquiry. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 if (buf == find_start_buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 /* Reuse the defun-start even if POS is a little farther on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 POS might be in the next defun, but that's ok.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 Our value may not be the best possible, but will still be usable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 && pos <= find_start_pos + 1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 && pos >= find_start_value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 && BUF_BEGV (buf) == find_start_begv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 && BUF_MODIFF (buf) == find_start_modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 return find_start_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 /* Back up to start of line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 tem = find_next_newline (buf, pos, -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 while (tem > BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 /* Open-paren at start of line means we found our defun-start. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 if (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, tem)) == Sopen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 /* Move to beg of previous line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 tem = find_next_newline (buf, tem, -2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 /* Record what we found, for the next try. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 find_start_value = tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 find_start_buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 find_start_modiff = BUF_MODIFF (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 find_start_begv = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 find_start_pos = pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 return find_start_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 Return t if ARG is a syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 Any vector of 256 elements will do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 return CHAR_TABLEP (obj) && XCHAR_TABLE_TYPE (obj) == CHAR_TABLE_TYPE_SYNTAX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 check_syntax_table (Lisp_Object obj, Lisp_Object default_)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 if (NILP (obj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 obj = default_;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 while (NILP (Fsyntax_table_p (obj)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 obj = wrong_type_argument (Qsyntax_table_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 return obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 Return the current syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 This is the one specified by the current buffer, or by BUFFER if it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 return decode_buffer (buffer, 0)->syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 Return the standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 This is the one used for new buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 return Vstandard_syntax_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 Construct a new syntax table and return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 It is a copy of the TABLE, which defaults to the standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 if (NILP (Vstandard_syntax_table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 return Fmake_char_table (Qsyntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 table = check_syntax_table (table, Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 return Fcopy_char_table (table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 Select a new syntax table for BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 One argument, a syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 BUFFER defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (table, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 table = check_syntax_table (table, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 buf->syntax_table = table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 buf->mirror_syntax_table = XCHAR_TABLE (table)->mirror_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 /* Indicate that this buffer now has a specified syntax table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 return table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /* Convert a letter which signifies a syntax code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 into the code it signifies.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 This is used by modify-syntax-entry, and other things. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 CONST unsigned char syntax_spec_code[0400] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (char) Swhitespace, 0377, (char) Sstring, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (char) Smath, 0377, 0377, (char) Squote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (char) Sopen, (char) Sclose, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (char) Scomment, 0377, (char) Sendcomment, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 CONST unsigned char syntax_code_spec[] = " .w_()'\"$\\/<>@";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 Return a string of the recognized syntax designator chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 The chars are ordered by their internal syntax codes, which are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 numbered starting at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 return Vsyntax_designator_chars_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 Return the syntax code of CHAR, described by a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 For example, if CHAR is a word constituent, the character `?w' is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 The characters that correspond to various syntax codes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 are listed in the documentation of `modify-syntax-entry'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 Optional second argument TABLE defaults to the current buffer's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (ch, table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
271 Lisp_Char_Table *mirrortab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 if (NILP(ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 ch = make_char('\000');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 CHECK_CHAR_COERCE_INT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 table = check_syntax_table (table, current_buffer->syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 mirrortab = XCHAR_TABLE (XCHAR_TABLE (table)->mirror_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, XCHAR (ch))]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 enum syntaxcode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 *multi_p_out = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 /* #### get this right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 return Spunct;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 syntax_match (Lisp_Object table, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 Lisp_Object code = CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (table), ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 Lisp_Object code2 = code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 if (CONSP (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 code2 = XCAR (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 code = CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE (Vstandard_syntax_table),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 return CONSP (code) ? XCDR (code) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 Return the matching parenthesis of CHAR, or nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 Optional second argument TABLE defaults to the current buffer's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (ch, table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
317 Lisp_Char_Table *mirrortab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 int code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 CHECK_CHAR_COERCE_INT (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 table = check_syntax_table (table, current_buffer->syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 mirrortab = XCHAR_TABLE (XCHAR_TABLE (table)->mirror_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 code = SYNTAX (mirrortab, XCHAR (ch));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 if (code == Sopen || code == Sclose || code == Sstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 return syntax_match (table, XCHAR (ch));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 /* Return 1 if there is a word boundary between two word-constituent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 characters C1 and C2 if they appear in this order, else return 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 There is no word boundary between two word-constituent ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 #define WORD_BOUNDARY_P(c1, c2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (!(CHAR_ASCII_P (c1) && CHAR_ASCII_P (c2)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 && word_boundary_p (c1, c2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 extern int word_boundary_p (Emchar c1, Emchar c2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 /* Return the position across COUNT words from FROM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 If that many words cannot be found before the end of the buffer, return 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 COUNT negative means scan backward and stop at word beginning. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 scan_words (struct buffer *buf, Bufpos from, int count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 Bufpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
351 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 Emchar ch0, ch1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 /* #### is it really worth it to hand expand both cases? JV */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 while (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 if (from == limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 ch0 = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 code = SYNTAX_UNSAFE (mirrortab, ch0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 if (words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 && (code == Sescape || code == Scharquote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 if (code == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 while (from != limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 ch1 = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 code = SYNTAX_UNSAFE (mirrortab, ch1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 if (!(words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 && (code == Sescape || code == Scharquote)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 if (code != Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 || WORD_BOUNDARY_P (ch0, ch1)
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
388 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 ch0 = ch1;
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
393 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 if (from == limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 ch1 = BUF_FETCH_CHAR (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 code = SYNTAX_UNSAFE (mirrortab, ch1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 if (words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 && (code == Sescape || code == Scharquote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 if (code == Sword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 while (from != limit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 ch0 = BUF_FETCH_CHAR (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 code = SYNTAX_UNSAFE (mirrortab, ch0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 if (!(words_include_escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 && (code == Sescape || code == Scharquote)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 if (code != Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 || WORD_BOUNDARY_P (ch0, ch1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ch1 = ch0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 DEFUN ("forward-word", Fforward_word, 1, 2, "_p", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 Move point forward COUNT words (backward if COUNT is negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 Normally returns t.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 If an edge of the buffer is reached, point is left there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 and nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (count, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 Bufpos val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 if (!(val = scan_words (buf, BUF_PT (buf), XINT (count))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 BUF_SET_PT (buf, XINT (count) > 0 ? BUF_ZV (buf) : BUF_BEGV (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 BUF_SET_PT (buf, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 static void scan_sexps_forward (struct buffer *buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 struct lisp_parse_state *,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 Bufpos from, Bufpos end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 int targetdepth, int stopbefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 Lisp_Object oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 int commentstop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 find_start_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int mask)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 enum syntaxcode code;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
479 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 /* Look back, counting the parity of string-quotes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 and recording the comment-starters seen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 When we reach a safe place, assume that's not in a string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 then step the main scan to the earliest comment-starter seen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 an even number of string quotes away from the safe place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 OFROM[I] is position of the earliest comment-starter seen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 which is I+2X quotes from the comment-end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 PARITY is current parity of quotes from the comment end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 int parity = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 Emchar my_stringend = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 int string_lossage = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 Bufpos comment_end = from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 Bufpos comstart_pos = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 int comstart_parity = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 int styles_match_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 /* At beginning of range to scan, we're outside of strings;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 that determines quote parity to the comment-end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 while (from != stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 /* Move back and examine a character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 c = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 code = SYNTAX_UNSAFE (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 /* is this a 1-char comment end sequence? if so, try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 to see if style matches previously extracted mask */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 styles_match_p = SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 /* otherwise, is this a 2-char comment end sequence? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 else if (from >= stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 && SYNTAX_END_P (mirrortab, c, BUF_FETCH_CHAR (buf, from+1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 code = Sendcomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 styles_match_p =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 SYNTAX_STYLES_MATCH_END_P (mirrortab, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 BUF_FETCH_CHAR (buf, from+1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 /* or are we looking at a 1-char comment start sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 of the style matching mask? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 else if (code == Scomment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 && SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 styles_match_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 /* or possibly, a 2-char comment start sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 else if (from >= stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 && SYNTAX_STYLES_MATCH_START_P (mirrortab, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 BUF_FETCH_CHAR (buf, from+1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 code = Scomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 styles_match_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 /* Ignore escaped characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 /* Track parity of quotes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 if (code == Sstring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 parity ^= 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 if (my_stringend == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 my_stringend = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 /* If we have two kinds of string delimiters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 There's no way to grok this scanning backwards. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 else if (my_stringend != c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 string_lossage = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 /* Record comment-starters according to that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 quote-parity to the comment-end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 if (code == Scomment && styles_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 comstart_parity = parity;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 comstart_pos = from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 /* If we find another earlier comment-ender,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 any comment-starts earlier than that don't count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (because they go with the earlier comment-ender). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 if (code == Sendcomment && styles_match_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 /* Assume a defun-start point is outside of strings. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 if (code == Sopen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 && (from == stop || BUF_FETCH_CHAR (buf, from - 1) == '\n'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 if (comstart_pos == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 from = comment_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 /* If the earliest comment starter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 is followed by uniform paired string quotes or none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 we know it can't be inside a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 since if it were then the comment ender would be inside one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 So it does start a comment. Skip back to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 else if (comstart_parity == 0 && !string_lossage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 from = comstart_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 /* We had two kinds of string delimiters mixed up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 together. Decode this going forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 Scan fwd from the previous comment ender
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 to the one in question; this records where we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 last passed a comment starter. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 comment_end - 1, -10000, 0, Qnil, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 if (state.incomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 from = state.comstart;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 /* We can't grok this as a comment; scan it normally. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 from = comment_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 static Bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 find_end_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int mask)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 int c;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
613 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 if (from == stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 c = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 if (SYNTAX_UNSAFE (mirrortab, c) == Sendcomment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 && SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 /* we have encountered a comment end of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 as the comment sequence which began this comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 if (from < stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 && SYNTAX_STYLES_MATCH_END_P (mirrortab, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 BUF_FETCH_CHAR (buf, from), mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 /* we have encountered a comment end of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 as the comment sequence which began this comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 { from++; break; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 return from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 /* #### between FSF 19.23 and 19.28 there are some changes to the logic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 in this function (and minor changes to find_start_of_comment(),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 above, which is part of Fforward_comment() in FSF). Attempts to port
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 that logic made this function break, so I'm leaving it out. If anyone
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 ever complains about this function not working properly, take a look
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 at those changes. --ben */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 DEFUN ("forward-comment", Fforward_comment, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 Move forward across up to N comments. If N is negative, move backward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 Stop scanning if we find something other than a comment or whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 Set point to where scanning stops.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 If N comments are found as expected, with nothing except whitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 between them, return t; otherwise return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 Point is set in either case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 Optional argument BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (n, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 Bufpos from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 Bufpos stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 EMACS_INT count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 struct buffer *buf = decode_buffer (buffer, 0);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
666 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 CHECK_INT (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 count = XINT (n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 from = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 while (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 stop = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 int mask = 0; /* mask for finding matching comment style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 c = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 code = SYNTAX (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 /* we have encountered a single character comment start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 sequence, and we are ignoring all text inside comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 we must record the comment style this character begins
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 so that later, only a comment end of the same style actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 ends the comment section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 else if (from < stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 && SYNTAX_START_P (mirrortab, c, BUF_FETCH_CHAR (buf, from+1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 /* we have encountered a 2char comment start sequence and we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 are ignoring all text inside comments. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 the comment style this sequence begins so that later,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 only a comment end of the same style actually ends
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 the comment section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 code = Scomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 mask = SYNTAX_COMMENT_MASK_START (mirrortab, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 BUF_FETCH_CHAR (buf, from+1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 Bufpos newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 newfrom = find_end_of_comment (buf, from, stop, mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 /* we stopped because from==stop */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 BUF_SET_PT (buf, stop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 /* We have skipped one comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 else if (code != Swhitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 && code != Sendcomment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 && code != Scomment )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 BUF_SET_PT (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 /* End of comment reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 stop = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 int mask = 0; /* mask for finding matching comment style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 if (char_quoted (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 c = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 code = SYNTAX (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* we have found a single char end comment. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 the comment style encountered so that later, we can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 only the proper comment begin sequence of the same style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 else if (from > stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 && SYNTAX_END_P (mirrortab, BUF_FETCH_CHAR (buf, from - 1), c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 && !char_quoted (buf, from - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 /* We must record the comment style encountered so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 later, we can match only the proper comment begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 sequence of the same style. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 code = Sendcomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 mask = SYNTAX_COMMENT_MASK_END (mirrortab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 BUF_FETCH_CHAR (buf, from - 1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 if (code == Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 from = find_start_of_comment (buf, from, stop, mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 else if (code != Swhitespace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 && SYNTAX (mirrortab, c) != Scomment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 && SYNTAX (mirrortab, c) != Sendcomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 BUF_SET_PT (buf, from + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 BUF_SET_PT (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 scan_lists (struct buffer *buf, Bufpos from, int count, int depth,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 int sexpflag, int no_error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 Bufpos stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 Emchar c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 int quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 int mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 int min_depth = depth; /* Err out if depth gets less than this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 Lisp_Object syntaxtab = buf->syntax_table;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
820 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 if (depth > 0) min_depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 while (count > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 stop = BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 int mask = 0; /* mask for finding matching comment style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 c = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 code = SYNTAX_UNSAFE (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 /* a 1-char comment start sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 if (code == Scomment && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 /* else, a 2-char comment start sequence? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 else if (from < stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 && SYNTAX_START_P (mirrortab, c, BUF_FETCH_CHAR (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 /* we have encountered a comment start sequence and we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 are ignoring all text inside comments. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 the comment style this sequence begins so that later,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 only a comment end of the same style actually ends
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 the comment section */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 code = Scomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 mask = SYNTAX_COMMENT_MASK_START (mirrortab, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 BUF_FETCH_CHAR (buf, from));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 if (SYNTAX_PREFIX_UNSAFE (mirrortab, c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 switch (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 /* treat following character as a word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 if (depth || !sexpflag) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 /* This word counts as a sexp; return at end of it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 while (from < stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 if (!parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 Bufpos newfrom = find_end_of_comment (buf, from, stop, mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 /* we stopped because from == stop in search forward */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 from = stop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 if (depth == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 if (!sexpflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 if (from != stop && c == BUF_FETCH_CHAR (buf, from))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 if (mathexit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 goto close1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 mathexit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 if (!++depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 close1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 if (!--depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 if (depth < min_depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 if (no_error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 error ("Containing expression ends prematurely");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 /* XEmacs change: call syntax_match on character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 Emchar ch = BUF_FETCH_CHAR (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 Lisp_Object stermobj = syntax_match (syntaxtab, ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 Emchar stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 stringterm = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 stringterm = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 if (from >= stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 if (BUF_FETCH_CHAR (buf, from) == stringterm)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 if (!depth && sexpflag) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 /* Reached end of buffer. Error if within object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 return nil if between */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 if (depth) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 /* End of object reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 while (count < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 stop = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 int mask = 0; /* mask for finding matching comment style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 quoted = char_quoted (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 if (quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 c = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 code = SYNTAX_UNSAFE (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 if (code == Sendcomment && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 /* we have found a single char end comment. we must record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 the comment style encountered so that later, we can match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 only the proper comment begin sequence of the same style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 else if (from > stop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 && SYNTAX_END_P (mirrortab, BUF_FETCH_CHAR (buf, from-1), c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 && !char_quoted (buf, from - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 && parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 /* we must record the comment style encountered so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 later, we can match only the proper comment begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 sequence of the same style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 code = Sendcomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 mask = SYNTAX_COMMENT_MASK_END (mirrortab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 BUF_FETCH_CHAR (buf, from - 1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 if (SYNTAX_PREFIX_UNSAFE (mirrortab, c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1030 switch (quoted ? Sword : code)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 if (depth || !sexpflag) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 /* This word counts as a sexp; count object finished after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 passing it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 while (from > stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 enum syntaxcode syncode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 quoted = char_quoted (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 if (quoted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 if (! (quoted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 || (syncode =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from - 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 == Sword
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 || syncode == Ssymbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 || syncode == Squote))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 if (!sexpflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 if (from != stop && c == BUF_FETCH_CHAR (buf, from - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 if (mathexit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 mathexit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 goto open2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 mathexit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 if (!++depth) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 open2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 if (!--depth) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 if (depth < min_depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 if (no_error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 error ("Containing expression ends prematurely");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 case Sendcomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 if (parse_sexp_ignore_comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 from = find_start_of_comment (buf, from, stop, mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 /* XEmacs change: call syntax_match() on character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 Emchar ch = BUF_FETCH_CHAR (buf, from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 Lisp_Object stermobj = syntax_match (syntaxtab, ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 Emchar stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 stringterm = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 stringterm = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 if (from == stop) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 if (!char_quoted (buf, from - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 && stringterm == BUF_FETCH_CHAR (buf, from - 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 from--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 if (!depth && sexpflag) goto done2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 /* Reached start of buffer. Error if within object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 return nil if between */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 if (depth) goto lose;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 done2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 return (make_int (from));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 lose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 if (!no_error)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 error ("Unbalanced parentheses");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 char_quoted (struct buffer *buf, Bufpos pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 Bufpos beg = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 int quoted = 0;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1139 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 while (pos > beg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 && ((code = SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 == Scharquote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 || code == Sescape))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 pos--, quoted = !quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 return quoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 Scan from character number FROM by COUNT lists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 Returns the character number of the position thus found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 If DEPTH is nonzero, paren depth begins counting from that value,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 only places where the depth in parentheses becomes zero
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 are candidates for stopping; COUNT such places are counted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 Thus, a positive value for DEPTH means go out levels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 If the beginning or end of (the accessible part of) the buffer is reached
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 and the depth is wrong, an error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 If the depth is right but the count is not used up, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 of in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 If optional arg NOERROR is non-nil, scan-lists will return nil instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 signalling an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 (from, count, depth, buffer, no_error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 struct buffer *buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 CHECK_INT (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 CHECK_INT (depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 return scan_lists (buf, XINT (from), XINT (count), XINT (depth), 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 !NILP (no_error));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 Scan from character number FROM by COUNT balanced expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 If COUNT is negative, scan backwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 Returns the character number of the position thus found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 If the beginning or end of (the accessible part of) the buffer is reached
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 in the middle of a parenthetical grouping, an error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 If the beginning or end is reached between groupings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 but before count is used up, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 If optional arg BUFFER is non-nil, scanning occurs in that buffer instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 of in the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 If optional arg NOERROR is non-nil, scan-sexps will return nil instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 signalling an error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (from, count, buffer, no_error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 CHECK_INT (from);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 CHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 return scan_lists (buf, XINT (from), XINT (count), 0, 1, !NILP (no_error));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 Move point backward over any number of chars with prefix syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 This includes chars with "quote" or "prefix" syntax (' or p).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 Optional arg BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 Bufpos beg = BUF_BEGV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 Bufpos pos = BUF_PT (buf);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1221 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 while (pos > beg && !char_quoted (buf, pos - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 && (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)) == Squote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 || SYNTAX_PREFIX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 pos--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 BUF_SET_PT (buf, pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 /* Parse forward from FROM to END,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 and return a description of the state of the parse at END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 If STOPBEFORE is nonzero, stop at the start of an atom.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 If COMMENTSTOP is nonzero, stop at the start of a comment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 scan_sexps_forward (struct buffer *buf, struct lisp_parse_state *stateptr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 Bufpos from, Bufpos end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 int targetdepth, int stopbefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 Lisp_Object oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 int commentstop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 enum syntaxcode code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 struct level { int last, prev; };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 struct level levelstart[100];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 struct level *curlevel = levelstart;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 struct level *endlevel = levelstart + 100;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 int depth; /* Paren depth of current scanning location.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 level - levelstart equals this except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 when the depth becomes negative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 int mindepth; /* Lowest DEPTH value seen. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 int start_quoted = 0; /* Nonzero means starting after a char quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 int mask; /* comment mask */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 Lisp_Object syntaxtab = buf->syntax_table;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1261 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 if (NILP (oldstate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 state.instring = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 state.incomment = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 state.comstyle = 0; /* comment style a by default */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 mask = SYNTAX_COMMENT_STYLE_A;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 tem = Fcar (oldstate); /* elt 0, depth */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 if (!NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 depth = XINT (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 depth = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 tem = Fcar (oldstate); /* elt 3, instring */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 state.instring = !NILP (tem) ? XINT (tem) : -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 oldstate = Fcdr (oldstate); /* elt 4, incomment */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 tem = Fcar (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 state.incomment = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 tem = Fcar (oldstate); /* elt 5, follows-quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 start_quoted = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 /* if the eighth element of the list is nil, we are in comment style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 a. if it is non-nil, we are in comment style b */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 oldstate = Fcdr (oldstate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 tem = Fcar (oldstate); /* elt 8, comment style a */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 state.comstyle = !NILP (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 mask = state.comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 state.quoted = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 mindepth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 curlevel->prev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 curlevel->last = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 /* Enter the loop at a place appropriate for initial state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 if (state.incomment) goto startincomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 if (state.instring >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 if (start_quoted) goto startquotedinstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 goto startinstring;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 if (start_quoted) goto startquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 while (from < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 code = SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 if (code == Scomment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 /* record the comment style we have entered so that only the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 comment-ender sequence (or single char) of the same style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 actually terminates the comment section. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 BUF_FETCH_CHAR (buf, from-1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 state.comstyle = (mask == SYNTAX_COMMENT_STYLE_B);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 state.comstart = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 else if (from < end &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 SYNTAX_START_P (mirrortab, BUF_FETCH_CHAR (buf, from-1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 BUF_FETCH_CHAR (buf, from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 /* Record the comment style we have entered so that only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 the comment-end sequence of the same style actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 terminates the comment section. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 code = Scomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 mask = SYNTAX_COMMENT_MASK_START (mirrortab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 BUF_FETCH_CHAR (buf, from-1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 BUF_FETCH_CHAR (buf, from));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 state.comstyle = (mask == SYNTAX_COMMENT_STYLE_B);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 state.comstart = from-1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 if (SYNTAX_PREFIX (mirrortab, BUF_FETCH_CHAR (buf, from - 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 switch (code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 startquoted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 if (from == end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 goto symstarted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 /* treat following character as a word constituent */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 symstarted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 while (from < end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 if (from == end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 case Sword:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 case Ssymbol:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 goto symdone;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 symdone:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 state.incomment = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 startincomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 if (commentstop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 Bufpos newfrom = find_end_of_comment (buf, from, end, mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 if (newfrom < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 /* we terminated search because from == end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 from = end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 from = newfrom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 state.incomment = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 state.comstyle = 0; /* reset the comment style */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 mask = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 depth++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 /* curlevel++->last ran into compiler bug on Apollo */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 if (++curlevel == endlevel)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 error ("Nesting too deep for parser");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 curlevel->prev = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 curlevel->last = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 if (targetdepth == depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 depth--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 if (depth < mindepth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 mindepth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 if (curlevel != levelstart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 curlevel--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 if (targetdepth == depth) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 Emchar ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 if (stopbefore) goto stop; /* this arg means stop at sexp start */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 curlevel->last = from - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 /* XEmacs change: call syntax_match() on character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 ch = BUF_FETCH_CHAR (buf, from - 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 Lisp_Object stermobj = syntax_match (syntaxtab, ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 if (CHARP (stermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 state.instring = XCHAR (stermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 state.instring = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 startinstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 if (from >= end) goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 if (BUF_FETCH_CHAR (buf, from) == state.instring) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 case Scharquote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 startquotedinstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 if (from >= end) goto endquoted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 state.instring = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 curlevel->prev = curlevel->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 from++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 case Smath:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 case Swhitespace:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 case Spunct:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 case Squote:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 case Sendcomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 case Sinherit:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 case Smax:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 goto done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 stop: /* Here if stopping before start of sexp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 from--; /* We have just fetched the char that starts it; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 goto done; /* but return the position before it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 endquoted:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 state.quoted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 state.depth = depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 state.mindepth = mindepth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 state.thislevelstart = curlevel->prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 state.prevlevelstart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 state.location = from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 *stateptr = state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 Parsing stops at TO or when certain criteria are met;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 point is set to where parsing stops.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 If fifth arg STATE is omitted or nil,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 parsing assumes that FROM is the beginning of a function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 Value is a list of eight elements describing final state of parsing:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 0. depth in parens.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 1. character address of start of innermost containing list; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 2. character address of start of last complete sexp terminated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 3. non-nil if inside a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (It is the character that will terminate the string.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 4. t if inside a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 5. t if following a quote character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 6. the minimum paren-depth encountered during this scan.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 7. nil if in comment style a, or not in a comment; t if in comment style b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 in parentheses becomes equal to TARGETDEPTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 Fourth arg STOPBEFORE non-nil means stop when come to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 any character that starts a sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 Fifth arg STATE is an eight-element list like what this function returns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 It is used to initialize the state of the parse. Its second and third
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 elements are ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 struct lisp_parse_state state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 int target;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 Bufpos start, end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 Lisp_Object val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 if (!NILP (targetdepth))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 CHECK_INT (targetdepth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 target = XINT (targetdepth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 target = -100000; /* We won't reach this depth */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 get_buffer_range_char (buf, from, to, &start, &end, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 scan_sexps_forward (buf, &state, start, end,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 target, !NILP (stopbefore), oldstate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 !NILP (commentstop));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 BUF_SET_PT (buf, state.location);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 /* reverse order */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 val = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 val = Fcons (state.comstyle ? Qt : Qnil, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 val = Fcons (make_int (state.mindepth), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 val = Fcons (state.quoted ? Qt : Qnil, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 val = Fcons (state.incomment ? Qt : Qnil, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 val = Fcons (state.instring < 0 ? Qnil : make_int (state.instring), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 val = Fcons (state.thislevelstart < 0 ? Qnil : make_int (state.thislevelstart), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 val = Fcons (state.prevlevelstart < 0 ? Qnil : make_int (state.prevlevelstart), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 val = Fcons (make_int (state.depth), val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 /* Updating of the mirror syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 Each syntax table has a corresponding mirror table in it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 Whenever we make a change to a syntax table, we call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 update_syntax_table() on it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 #### We really only need to map over the changed range.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 If we change the standard syntax table, we need to map over
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 all tables because any of them could be inheriting from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 standard syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 When `set-syntax-table' is called, we set the buffer's mirror
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 syntax table as well.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 struct cmst_arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 Lisp_Object mirrortab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 int check_inherit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 cmst_mapfun (struct chartab_range *range, Lisp_Object val, void *arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 struct cmst_arg *closure = (struct cmst_arg *) arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 if (CONSP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 val = XCAR (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 if (SYNTAX_FROM_CODE (XINT (val)) == Sinherit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 && closure->check_inherit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 struct cmst_arg recursive;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 recursive.mirrortab = closure->mirrortab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 recursive.check_inherit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 map_char_table (XCHAR_TABLE (Vstandard_syntax_table), range,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 cmst_mapfun, &recursive);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 put_char_table (XCHAR_TABLE (closure->mirrortab), range, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 static void
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1614 update_just_this_syntax_table (Lisp_Char_Table *ct)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 struct chartab_range range;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 struct cmst_arg arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 arg.mirrortab = ct->mirror_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 arg.check_inherit = (CHAR_TABLEP (Vstandard_syntax_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 && ct != XCHAR_TABLE (Vstandard_syntax_table));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 range.type = CHARTAB_RANGE_ALL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 map_char_table (ct, &range, cmst_mapfun, &arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 /* Called from chartab.c when a change is made to a syntax table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 If this is the standard syntax table, we need to recompute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 *all* syntax tables (yuck). Otherwise we just recompute this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 void
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1632 update_syntax_table (Lisp_Char_Table *ct)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 /* Don't be stymied at startup. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 if (CHAR_TABLEP (Vstandard_syntax_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 && ct == XCHAR_TABLE (Vstandard_syntax_table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 Lisp_Object syntab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 for (syntab = Vall_syntax_tables; !NILP (syntab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 syntab = XCHAR_TABLE (syntab)->next_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 update_just_this_syntax_table (XCHAR_TABLE (syntab));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 update_just_this_syntax_table (ct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 syms_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 defsymbol (&Qsyntax_table_p, "syntax-table-p");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 DEFSUBR (Fsyntax_table_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 DEFSUBR (Fsyntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 DEFSUBR (Fstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 DEFSUBR (Fcopy_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 DEFSUBR (Fset_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 DEFSUBR (Fsyntax_designator_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 DEFSUBR (Fchar_syntax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 DEFSUBR (Fmatching_paren);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 DEFSUBR (Fforward_word);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 DEFSUBR (Fforward_comment);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 DEFSUBR (Fscan_lists);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 DEFSUBR (Fscan_sexps);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 DEFSUBR (Fbackward_prefix_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 DEFSUBR (Fparse_partial_sexp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 vars_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 Non-nil means `forward-sexp', etc., should treat comments as whitespace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 */ );
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1684 parse_sexp_ignore_comments = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 Non-nil means `forward-word', etc., should treat escape chars part of words.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 */ );
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1689 words_include_escapes = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 no_quit_in_re_search = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 define_standard_syntax (CONST char *p, enum syntaxcode syn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 for (; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 Fput_char_table (make_char (*p), make_int (syn), Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 complex_vars_of_syntax (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 Emchar i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 CONST char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 /* Set this now, so first buffer creation can refer to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 /* Make it nil before calling copy-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 so that copy-syntax-table will know not to try to copy from garbage */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 Vstandard_syntax_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 Vstandard_syntax_table = Fcopy_syntax_table (Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 staticpro (&Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 Smax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 staticpro (&Vsyntax_designator_chars_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 fill_char_table (XCHAR_TABLE (Vstandard_syntax_table), make_int (Spunct));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 for (i = 0; i <= 32; i++) /* Control 0 plus SPACE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 Fput_char_table (make_char (i), make_int (Swhitespace),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 for (i = 127; i <= 159; i++) /* DEL plus Control 1 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 Fput_char_table (make_char (i), make_int (Swhitespace),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 define_standard_syntax ("abcdefghijklmnopqrstuvwxyz"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 "0123456789"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 "$%", Sword);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 define_standard_syntax ("\"", Sstring);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 define_standard_syntax ("\\", Sescape);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 define_standard_syntax ("_-+*/&|<>=", Ssymbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 define_standard_syntax (".,;:?!#@~^'`", Spunct);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 for (p = "()[]{}"; *p; p+=2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 Fput_char_table (make_char (p[0]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 Fcons (make_int (Sopen), make_char (p[1])),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 Fput_char_table (make_char (p[1]),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 Fcons (make_int (Sclose), make_char (p[0])),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 Vstandard_syntax_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 }