163
|
1 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
|
64770
|
2 Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2002,
|
68651
|
3 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
|
163
|
4
|
|
5 This file is part of GNU Emacs.
|
|
6
|
|
7 GNU Emacs is free software; you can redistribute it and/or modify
|
|
8 it under the terms of the GNU General Public License as published by
|
726
|
9 the Free Software Foundation; either version 2, or (at your option)
|
163
|
10 any later version.
|
|
11
|
|
12 GNU Emacs is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with GNU Emacs; see the file COPYING. If not, write to
|
64084
|
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
20 Boston, MA 02110-1301, USA. */
|
163
|
21
|
|
22
|
4696
|
23 #include <config.h>
|
163
|
24 #include <ctype.h>
|
|
25 #include "lisp.h"
|
|
26 #include "commands.h"
|
|
27 #include "buffer.h"
|
17044
|
28 #include "charset.h"
|
39748
|
29 #include "keymap.h"
|
56088
|
30 #include "regex.h"
|
17464
|
31
|
|
32 /* Make syntax table lookup grant data in gl_state. */
|
|
33 #define SYNTAX_ENTRY_VIA_PROPERTY
|
|
34
|
163
|
35 #include "syntax.h"
|
17464
|
36 #include "intervals.h"
|
|
37
|
|
38 /* We use these constants in place for comment-style and
|
|
39 string-ender-char to distinguish comments/strings started by
|
|
40 comment_fence and string_fence codes. */
|
|
41
|
|
42 #define ST_COMMENT_STYLE (256 + 1)
|
|
43 #define ST_STRING_STYLE (256 + 2)
|
17044
|
44 #include "category.h"
|
163
|
45
|
16992
|
46 Lisp_Object Qsyntax_table_p, Qsyntax_table, Qscan_error;
|
163
|
47
|
|
48 int words_include_escapes;
|
17464
|
49 int parse_sexp_lookup_properties;
|
163
|
50
|
27812
|
51 /* Nonzero means `scan-sexps' treat all multibyte characters as symbol. */
|
|
52 int multibyte_syntax_as_symbol;
|
|
53
|
13144
|
54 /* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
|
|
55 if not compiled with GCC. No need to mark it, since it is used
|
|
56 only very temporarily. */
|
|
57 Lisp_Object syntax_temp;
|
|
58
|
28302
|
59 /* Non-zero means an open parenthesis in column 0 is always considered
|
|
60 to be the start of a defun. Zero means an open parenthesis in
|
|
61 column 0 has no special meaning. */
|
|
62
|
|
63 int open_paren_in_column_0_is_defun_start;
|
|
64
|
1085
|
65 /* This is the internal form of the parse state used in parse-partial-sexp. */
|
|
66
|
|
67 struct lisp_parse_state
|
|
68 {
|
17464
|
69 int depth; /* Depth at end of parsing. */
|
|
70 int instring; /* -1 if not within string, else desired terminator. */
|
25445
|
71 int incomment; /* -1 if in unnestable comment else comment nesting */
|
17464
|
72 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */
|
1085
|
73 int quoted; /* Nonzero if just after an escape char at end of parsing */
|
|
74 int thislevelstart; /* Char number of most recent start-of-expression at current level */
|
|
75 int prevlevelstart; /* Char number of start of containing expression */
|
17464
|
76 int location; /* Char number at which parsing stopped. */
|
1085
|
77 int mindepth; /* Minimum depth seen while scanning. */
|
17464
|
78 int comstr_start; /* Position just after last comment/string starter. */
|
22394
|
79 Lisp_Object levelstarts; /* Char numbers of starts-of-expression
|
|
80 of levels (starting from outermost). */
|
1085
|
81 };
|
|
82
|
1167
|
83 /* These variables are a cache for finding the start of a defun.
|
|
84 find_start_pos is the place for which the defun start was found.
|
|
85 find_start_value is the defun start position found for it.
|
20546
|
86 find_start_value_byte is the corresponding byte position.
|
1167
|
87 find_start_buffer is the buffer it was found in.
|
|
88 find_start_begv is the BEGV value when it was found.
|
|
89 find_start_modiff is the value of MODIFF when it was found. */
|
|
90
|
|
91 static int find_start_pos;
|
|
92 static int find_start_value;
|
20546
|
93 static int find_start_value_byte;
|
1167
|
94 static struct buffer *find_start_buffer;
|
|
95 static int find_start_begv;
|
|
96 static int find_start_modiff;
|
20546
|
97
|
|
98
|
|
99 static int find_defun_start P_ ((int, int));
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
100 static int back_comment P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int, int,
|
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
101 EMACS_INT *, EMACS_INT *));
|
20546
|
102 static int char_quoted P_ ((int, int));
|
56088
|
103 static Lisp_Object skip_chars P_ ((int, int, Lisp_Object, Lisp_Object, int));
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
104 static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int));
|
20546
|
105 static void scan_sexps_forward P_ ((struct lisp_parse_state *,
|
|
106 int, int, int, int,
|
|
107 int, Lisp_Object, int));
|
56088
|
108 static int in_classes P_ ((int, Lisp_Object));
|
17464
|
109
|
1167
|
110
|
17464
|
111 struct gl_state_s gl_state; /* Global state of syntax parser. */
|
|
112
|
|
113 INTERVAL interval_of ();
|
|
114 #define INTERVALS_AT_ONCE 10 /* 1 + max-number of intervals
|
|
115 to scan to property-change. */
|
|
116
|
20546
|
117 /* Update gl_state to an appropriate interval which contains CHARPOS. The
|
|
118 sign of COUNT give the relative position of CHARPOS wrt the previously
|
17464
|
119 valid interval. If INIT, only [be]_property fields of gl_state are
|
20546
|
120 valid at start, the rest is filled basing on OBJECT.
|
17464
|
121
|
20546
|
122 `gl_state.*_i' are the intervals, and CHARPOS is further in the search
|
17464
|
123 direction than the intervals - or in an interval. We update the
|
|
124 current syntax-table basing on the property of this interval, and
|
20546
|
125 update the interval to start further than CHARPOS - or be
|
17464
|
126 NULL_INTERVAL. We also update lim_property to be the next value of
|
20546
|
127 charpos to call this subroutine again - or be before/after the
|
17464
|
128 start/end of OBJECT. */
|
|
129
|
|
130 void
|
20546
|
131 update_syntax_table (charpos, count, init, object)
|
|
132 int charpos, count, init;
|
17464
|
133 Lisp_Object object;
|
|
134 {
|
|
135 Lisp_Object tmp_table;
|
25771
|
136 int cnt = 0, invalidate = 1;
|
65215
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
137 INTERVAL i;
|
17464
|
138
|
|
139 if (init)
|
|
140 {
|
39796
|
141 gl_state.old_prop = Qnil;
|
17464
|
142 gl_state.start = gl_state.b_property;
|
|
143 gl_state.stop = gl_state.e_property;
|
39796
|
144 i = interval_of (charpos, object);
|
|
145 gl_state.backward_i = gl_state.forward_i = i;
|
17464
|
146 invalidate = 0;
|
|
147 if (NULL_INTERVAL_P (i))
|
|
148 return;
|
22370
|
149 /* interval_of updates only ->position of the return value, so
|
21011
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
150 update the parents manually to speed up update_interval. */
|
39796
|
151 while (!NULL_PARENT (i))
|
21011
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
152 {
|
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
153 if (AM_RIGHT_CHILD (i))
|
28269
fd13be8ae190
Changes towards better type safety regarding intervals, primarily
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
154 INTERVAL_PARENT (i)->position = i->position
|
21011
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
155 - LEFT_TOTAL_LENGTH (i) + TOTAL_LENGTH (i) /* right end */
|
28269
fd13be8ae190
Changes towards better type safety regarding intervals, primarily
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
156 - TOTAL_LENGTH (INTERVAL_PARENT (i))
|
fd13be8ae190
Changes towards better type safety regarding intervals, primarily
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
157 + LEFT_TOTAL_LENGTH (INTERVAL_PARENT (i));
|
21011
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
158 else
|
28269
fd13be8ae190
Changes towards better type safety regarding intervals, primarily
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
159 INTERVAL_PARENT (i)->position = i->position - LEFT_TOTAL_LENGTH (i)
|
21011
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
160 + TOTAL_LENGTH (i);
|
28269
fd13be8ae190
Changes towards better type safety regarding intervals, primarily
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
161 i = INTERVAL_PARENT (i);
|
21011
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
162 }
|
ceb05db73a63
(update_syntax_table): Properly update `position' field of used intervals.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
163 i = gl_state.forward_i;
|
39796
|
164 gl_state.b_property = i->position - gl_state.offset;
|
20956
|
165 gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
|
17464
|
166 goto update;
|
|
167 }
|
65215
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
168 i = count > 0 ? gl_state.forward_i : gl_state.backward_i;
|
17464
|
169
|
37532
|
170 /* We are guaranteed to be called with CHARPOS either in i,
|
20546
|
171 or further off. */
|
17464
|
172 if (NULL_INTERVAL_P (i))
|
|
173 error ("Error in syntax_table logic for to-the-end intervals");
|
20546
|
174 else if (charpos < i->position) /* Move left. */
|
17464
|
175 {
|
|
176 if (count > 0)
|
22370
|
177 error ("Error in syntax_table logic for intervals <-");
|
17464
|
178 /* Update the interval. */
|
20546
|
179 i = update_interval (i, charpos);
|
39796
|
180 if (INTERVAL_LAST_POS (i) != gl_state.b_property)
|
17464
|
181 {
|
|
182 invalidate = 0;
|
|
183 gl_state.forward_i = i;
|
20956
|
184 gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
|
17464
|
185 }
|
37532
|
186 }
|
20546
|
187 else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right. */
|
17464
|
188 {
|
|
189 if (count < 0)
|
22370
|
190 error ("Error in syntax_table logic for intervals ->");
|
17464
|
191 /* Update the interval. */
|
20546
|
192 i = update_interval (i, charpos);
|
39796
|
193 if (i->position != gl_state.e_property)
|
17464
|
194 {
|
|
195 invalidate = 0;
|
|
196 gl_state.backward_i = i;
|
39796
|
197 gl_state.b_property = i->position - gl_state.offset;
|
17464
|
198 }
|
|
199 }
|
|
200
|
|
201 update:
|
|
202 tmp_table = textget (i->plist, Qsyntax_table);
|
|
203
|
|
204 if (invalidate)
|
|
205 invalidate = !EQ (tmp_table, gl_state.old_prop); /* Need to invalidate? */
|
47942
|
206
|
37532
|
207 if (invalidate) /* Did not get to adjacent interval. */
|
|
208 { /* with the same table => */
|
|
209 /* invalidate the old range. */
|
17464
|
210 if (count > 0)
|
|
211 {
|
|
212 gl_state.backward_i = i;
|
39796
|
213 gl_state.b_property = i->position - gl_state.offset;
|
|
214 }
|
|
215 else
|
17464
|
216 {
|
39796
|
217 gl_state.forward_i = i;
|
20956
|
218 gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
|
17464
|
219 }
|
|
220 }
|
|
221
|
39796
|
222 if (!EQ (tmp_table, gl_state.old_prop))
|
17464
|
223 {
|
39796
|
224 gl_state.current_syntax_table = tmp_table;
|
|
225 gl_state.old_prop = tmp_table;
|
|
226 if (EQ (Fsyntax_table_p (tmp_table), Qt))
|
|
227 {
|
|
228 gl_state.use_global = 0;
|
47942
|
229 }
|
39796
|
230 else if (CONSP (tmp_table))
|
|
231 {
|
|
232 gl_state.use_global = 1;
|
|
233 gl_state.global_code = tmp_table;
|
|
234 }
|
47942
|
235 else
|
39796
|
236 {
|
|
237 gl_state.use_global = 0;
|
|
238 gl_state.current_syntax_table = current_buffer->syntax_table;
|
|
239 }
|
17464
|
240 }
|
|
241
|
|
242 while (!NULL_INTERVAL_P (i))
|
|
243 {
|
|
244 if (cnt && !EQ (tmp_table, textget (i->plist, Qsyntax_table)))
|
|
245 {
|
|
246 if (count > 0)
|
39796
|
247 {
|
|
248 gl_state.e_property = i->position - gl_state.offset;
|
|
249 gl_state.forward_i = i;
|
|
250 }
|
|
251 else
|
|
252 {
|
65215
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
253 gl_state.b_property
|
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
254 = i->position + LENGTH (i) - gl_state.offset;
|
39796
|
255 gl_state.backward_i = i;
|
|
256 }
|
|
257 return;
|
17464
|
258 }
|
47942
|
259 else if (cnt == INTERVALS_AT_ONCE)
|
17464
|
260 {
|
|
261 if (count > 0)
|
39796
|
262 {
|
65215
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
263 gl_state.e_property
|
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
264 = i->position + LENGTH (i) - gl_state.offset
|
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
265 /* e_property at EOB is not set to ZV but to ZV+1, so that
|
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
266 we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
|
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
267 having to check eob between the two. */
|
c37b7f6542ec
(update_syntax_table): Properly reproduce the special +1
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
268 + (NULL_INTERVAL_P (next_interval (i)) ? 1 : 0);
|
39796
|
269 gl_state.forward_i = i;
|
|
270 }
|
|
271 else
|
|
272 {
|
|
273 gl_state.b_property = i->position - gl_state.offset;
|
|
274 gl_state.backward_i = i;
|
|
275 }
|
|
276 return;
|
17464
|
277 }
|
|
278 cnt++;
|
|
279 i = count > 0 ? next_interval (i) : previous_interval (i);
|
|
280 }
|
39796
|
281 eassert (NULL_INTERVAL_P (i)); /* This property goes to the end. */
|
|
282 if (count > 0)
|
|
283 gl_state.e_property = gl_state.stop;
|
|
284 else
|
|
285 gl_state.b_property = gl_state.start;
|
17464
|
286 }
|
|
287
|
20546
|
288 /* Returns TRUE if char at CHARPOS is quoted.
|
|
289 Global syntax-table data should be set up already to be good at CHARPOS
|
|
290 or after. On return global syntax data is good for lookup at CHARPOS. */
|
17464
|
291
|
|
292 static int
|
20546
|
293 char_quoted (charpos, bytepos)
|
|
294 register int charpos, bytepos;
|
17464
|
295 {
|
|
296 register enum syntaxcode code;
|
|
297 register int beg = BEGV;
|
|
298 register int quoted = 0;
|
20546
|
299 int orig = charpos;
|
|
300
|
|
301 DEC_BOTH (charpos, bytepos);
|
|
302
|
56719
|
303 while (charpos >= beg)
|
20546
|
304 {
|
56067
|
305 int c;
|
|
306
|
20546
|
307 UPDATE_SYNTAX_TABLE_BACKWARD (charpos);
|
56067
|
308 c = FETCH_CHAR (bytepos);
|
|
309 code = SYNTAX (c);
|
20546
|
310 if (! (code == Scharquote || code == Sescape))
|
|
311 break;
|
|
312
|
|
313 DEC_BOTH (charpos, bytepos);
|
|
314 quoted = !quoted;
|
|
315 }
|
|
316
|
|
317 UPDATE_SYNTAX_TABLE (orig);
|
|
318 return quoted;
|
|
319 }
|
17464
|
320
|
20546
|
321 /* Return the bytepos one character after BYTEPOS.
|
|
322 We assume that BYTEPOS is not at the end of the buffer. */
|
|
323
|
|
324 INLINE int
|
|
325 inc_bytepos (bytepos)
|
|
326 int bytepos;
|
|
327 {
|
20905
|
328 if (NILP (current_buffer->enable_multibyte_characters))
|
|
329 return bytepos + 1;
|
|
330
|
20546
|
331 INC_POS (bytepos);
|
|
332 return bytepos;
|
|
333 }
|
|
334
|
|
335 /* Return the bytepos one character before BYTEPOS.
|
|
336 We assume that BYTEPOS is not at the start of the buffer. */
|
|
337
|
|
338 INLINE int
|
|
339 dec_bytepos (bytepos)
|
|
340 int bytepos;
|
|
341 {
|
20905
|
342 if (NILP (current_buffer->enable_multibyte_characters))
|
|
343 return bytepos - 1;
|
|
344
|
20546
|
345 DEC_POS (bytepos);
|
|
346 return bytepos;
|
17464
|
347 }
|
|
348
|
39195
|
349 /* Return a defun-start position before before POS and not too far before.
|
|
350 It should be the last one before POS, or nearly the last.
|
|
351
|
|
352 When open_paren_in_column_0_is_defun_start is nonzero,
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
353 only the beginning of the buffer is treated as a defun-start.
|
39195
|
354
|
|
355 We record the information about where the scan started
|
|
356 and what its result was, so that another call in the same area
|
|
357 can return the same value very quickly.
|
17464
|
358
|
|
359 There is no promise at which position the global syntax data is
|
|
360 valid on return from the subroutine, so the caller should explicitly
|
|
361 update the global data. */
|
1167
|
362
|
|
363 static int
|
20546
|
364 find_defun_start (pos, pos_byte)
|
|
365 int pos, pos_byte;
|
1167
|
366 {
|
20546
|
367 int opoint = PT, opoint_byte = PT_BYTE;
|
1167
|
368
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
369 if (!open_paren_in_column_0_is_defun_start)
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
370 {
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
371 find_start_value_byte = BEGV_BYTE;
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
372 return BEGV;
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
373 }
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
374
|
1167
|
375 /* Use previous finding, if it's valid and applies to this inquiry. */
|
|
376 if (current_buffer == find_start_buffer
|
|
377 /* Reuse the defun-start even if POS is a little farther on.
|
|
378 POS might be in the next defun, but that's ok.
|
|
379 Our value may not be the best possible, but will still be usable. */
|
|
380 && pos <= find_start_pos + 1000
|
|
381 && pos >= find_start_value
|
|
382 && BEGV == find_start_begv
|
|
383 && MODIFF == find_start_modiff)
|
|
384 return find_start_value;
|
|
385
|
|
386 /* Back up to start of line. */
|
20546
|
387 scan_newline (pos, pos_byte, BEGV, BEGV_BYTE, -1, 1);
|
1167
|
388
|
17464
|
389 /* We optimize syntax-table lookup for rare updates. Thus we accept
|
|
390 only those `^\s(' which are good in global _and_ text-property
|
|
391 syntax-tables. */
|
|
392 gl_state.current_syntax_table = current_buffer->syntax_table;
|
|
393 gl_state.use_global = 0;
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
394 while (PT > BEGV)
|
1167
|
395 {
|
56067
|
396 int c;
|
|
397
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
398 /* Open-paren at start of line means we may have found our
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
399 defun-start. */
|
56067
|
400 c = FETCH_CHAR (PT_BYTE);
|
|
401 if (SYNTAX (c) == Sopen)
|
17464
|
402 {
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
403 SETUP_SYNTAX_TABLE (PT + 1, -1); /* Try again... */
|
56067
|
404 c = FETCH_CHAR (PT_BYTE);
|
|
405 if (SYNTAX (c) == Sopen)
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
406 break;
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
407 /* Now fallback to the default value. */
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
408 gl_state.current_syntax_table = current_buffer->syntax_table;
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
409 gl_state.use_global = 0;
|
17464
|
410 }
|
51036
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
411 /* Move to beg of previous line. */
|
5a30d8fb640c
(find_defun_start): When open_paren_in_column_0_is_defun_start,
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
412 scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -2, 1);
|
1167
|
413 }
|
|
414
|
|
415 /* Record what we found, for the next try. */
|
20546
|
416 find_start_value = PT;
|
|
417 find_start_value_byte = PT_BYTE;
|
1167
|
418 find_start_buffer = current_buffer;
|
|
419 find_start_modiff = MODIFF;
|
|
420 find_start_begv = BEGV;
|
|
421 find_start_pos = pos;
|
|
422
|
20546
|
423 TEMP_SET_PT_BOTH (opoint, opoint_byte);
|
|
424
|
1167
|
425 return find_start_value;
|
|
426 }
|
|
427
|
22370
|
428 /* Return the SYNTAX_COMEND_FIRST of the character before POS, POS_BYTE. */
|
|
429
|
|
430 static int
|
|
431 prev_char_comend_first (pos, pos_byte)
|
|
432 int pos, pos_byte;
|
|
433 {
|
|
434 int c, val;
|
|
435
|
|
436 DEC_BOTH (pos, pos_byte);
|
|
437 UPDATE_SYNTAX_TABLE_BACKWARD (pos);
|
|
438 c = FETCH_CHAR (pos_byte);
|
|
439 val = SYNTAX_COMEND_FIRST (c);
|
|
440 UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
|
|
441 return val;
|
|
442 }
|
|
443
|
|
444 /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */
|
|
445
|
32087
|
446 /* static int
|
|
447 * prev_char_comstart_first (pos, pos_byte)
|
|
448 * int pos, pos_byte;
|
|
449 * {
|
|
450 * int c, val;
|
47942
|
451 *
|
32087
|
452 * DEC_BOTH (pos, pos_byte);
|
|
453 * UPDATE_SYNTAX_TABLE_BACKWARD (pos);
|
|
454 * c = FETCH_CHAR (pos_byte);
|
|
455 * val = SYNTAX_COMSTART_FIRST (c);
|
|
456 * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1);
|
|
457 * return val;
|
|
458 * } */
|
22370
|
459
|
20546
|
460 /* Checks whether charpos FROM is at the end of a comment.
|
|
461 FROM_BYTE is the bytepos corresponding to FROM.
|
|
462 Do not move back before STOP.
|
|
463
|
|
464 Return a positive value if we find a comment ending at FROM/FROM_BYTE;
|
|
465 return -1 otherwise.
|
|
466
|
|
467 If successful, store the charpos of the comment's beginning
|
|
468 into *CHARPOS_PTR, and the bytepos into *BYTEPOS_PTR.
|
20330
|
469
|
|
470 Global syntax data remains valid for backward search starting at
|
|
471 the returned value (or at FROM, if the search was not successful). */
|
17464
|
472
|
|
473 static int
|
25445
|
474 back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_ptr)
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
475 EMACS_INT from, from_byte, stop;
|
25445
|
476 int comnested, comstyle;
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
477 EMACS_INT *charpos_ptr, *bytepos_ptr;
|
17464
|
478 {
|
|
479 /* Look back, counting the parity of string-quotes,
|
|
480 and recording the comment-starters seen.
|
|
481 When we reach a safe place, assume that's not in a string;
|
|
482 then step the main scan to the earliest comment-starter seen
|
|
483 an even number of string quotes away from the safe place.
|
|
484
|
|
485 OFROM[I] is position of the earliest comment-starter seen
|
|
486 which is I+2X quotes from the comment-end.
|
|
487 PARITY is current parity of quotes from the comment end. */
|
29835
|
488 int string_style = -1; /* Presumed outside of any string. */
|
17464
|
489 int string_lossage = 0;
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
490 /* Not a real lossage: indicates that we have passed a matching comment
|
47942
|
491 starter plus a non-matching comment-ender, meaning that any matching
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
492 comment-starter we might see later could be a false positive (hidden
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
493 inside another comment).
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
494 Test case: { a (* b } c (* d *) */
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
495 int comment_lossage = 0;
|
17464
|
496 int comment_end = from;
|
20546
|
497 int comment_end_byte = from_byte;
|
17464
|
498 int comstart_pos = 0;
|
20766
|
499 int comstart_byte;
|
|
500 /* Place where the containing defun starts,
|
|
501 or 0 if we didn't come across it yet. */
|
|
502 int defun_start = 0;
|
|
503 int defun_start_byte = 0;
|
17464
|
504 register enum syntaxcode code;
|
25445
|
505 int nesting = 1; /* current comment nesting */
|
18079
|
506 int c;
|
32087
|
507 int syntax = 0;
|
|
508
|
|
509 /* FIXME: A }} comment-ender style leads to incorrect behavior
|
|
510 in the case of {{ c }}} because we ignore the last two chars which are
|
|
511 assumed to be comment-enders although they aren't. */
|
17464
|
512
|
|
513 /* At beginning of range to scan, we're outside of strings;
|
|
514 that determines quote parity to the comment-end. */
|
|
515 while (from != stop)
|
|
516 {
|
32087
|
517 int temp_byte, prev_syntax;
|
|
518 int com2start, com2end;
|
20546
|
519
|
17464
|
520 /* Move back and examine a character. */
|
20546
|
521 DEC_BOTH (from, from_byte);
|
17464
|
522 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
|
523
|
32087
|
524 prev_syntax = syntax;
|
20546
|
525 c = FETCH_CHAR (from_byte);
|
32087
|
526 syntax = SYNTAX_WITH_FLAGS (c);
|
17464
|
527 code = SYNTAX (c);
|
|
528
|
32087
|
529 /* Check for 2-char comment markers. */
|
|
530 com2start = (SYNTAX_FLAGS_COMSTART_FIRST (syntax)
|
|
531 && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax)
|
|
532 && comstyle == SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax)
|
|
533 && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax)
|
|
534 || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested);
|
|
535 com2end = (SYNTAX_FLAGS_COMEND_FIRST (syntax)
|
|
536 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax));
|
|
537
|
|
538 /* Nasty cases with overlapping 2-char comment markers:
|
|
539 - snmp-mode: -- c -- foo -- c --
|
|
540 --- c --
|
|
541 ------ c --
|
|
542 - c-mode: *||*
|
|
543 |* *|* *|
|
|
544 |*| |* |*|
|
|
545 /// */
|
|
546
|
|
547 /* If a 2-char comment sequence partly overlaps with another,
|
|
548 we don't try to be clever. */
|
|
549 if (from > stop && (com2end || com2start))
|
17464
|
550 {
|
32087
|
551 int next = from, next_byte = from_byte, next_c, next_syntax;
|
|
552 DEC_BOTH (next, next_byte);
|
|
553 UPDATE_SYNTAX_TABLE_BACKWARD (next);
|
|
554 next_c = FETCH_CHAR (next_byte);
|
|
555 next_syntax = SYNTAX_WITH_FLAGS (next_c);
|
|
556 if (((com2start || comnested)
|
|
557 && SYNTAX_FLAGS_COMEND_SECOND (syntax)
|
|
558 && SYNTAX_FLAGS_COMEND_FIRST (next_syntax))
|
|
559 || ((com2end || comnested)
|
|
560 && SYNTAX_FLAGS_COMSTART_SECOND (syntax)
|
|
561 && comstyle == SYNTAX_FLAGS_COMMENT_STYLE (syntax)
|
|
562 && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax)))
|
|
563 goto lossage;
|
|
564 /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */
|
17464
|
565 }
|
32087
|
566
|
|
567 if (com2start && comstart_pos == 0)
|
|
568 /* We're looking at a comment starter. But it might be a comment
|
|
569 ender as well (see snmp-mode). The first time we see one, we
|
|
570 need to consider it as a comment starter,
|
|
571 and the subsequent times as a comment ender. */
|
|
572 com2end = 0;
|
|
573
|
|
574 /* Turn a 2-char comment sequences into the appropriate syntax. */
|
|
575 if (com2end)
|
|
576 code = Sendcomment;
|
|
577 else if (com2start)
|
|
578 code = Scomment;
|
|
579 /* Ignore comment starters of a different style. */
|
|
580 else if (code == Scomment
|
|
581 && (comstyle != SYNTAX_FLAGS_COMMENT_STYLE (syntax)
|
|
582 || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested))
|
27698
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
583 continue;
|
17464
|
584
|
20674
|
585 /* Ignore escaped characters, except comment-enders. */
|
|
586 if (code != Sendcomment && char_quoted (from, from_byte))
|
17464
|
587 continue;
|
|
588
|
29835
|
589 switch (code)
|
17464
|
590 {
|
29835
|
591 case Sstring_fence:
|
|
592 case Scomment_fence:
|
|
593 c = (code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE);
|
|
594 case Sstring:
|
|
595 /* Track parity of quotes. */
|
|
596 if (string_style == -1)
|
|
597 /* Entering a string. */
|
|
598 string_style = c;
|
|
599 else if (string_style == c)
|
|
600 /* Leaving the string. */
|
|
601 string_style = -1;
|
|
602 else
|
|
603 /* If we have two kinds of string delimiters.
|
|
604 There's no way to grok this scanning backwards. */
|
17464
|
605 string_lossage = 1;
|
29835
|
606 break;
|
47942
|
607
|
29835
|
608 case Scomment:
|
|
609 /* We've already checked that it is the relevant comstyle. */
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
610 if (string_style != -1 || comment_lossage || string_lossage)
|
29835
|
611 /* There are odd string quotes involved, so let's be careful.
|
|
612 Test case in Pascal: " { " a { " } */
|
|
613 goto lossage;
|
17464
|
614
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
615 if (!comnested)
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
616 {
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
617 /* Record best comment-starter so far. */
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
618 comstart_pos = from;
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
619 comstart_byte = from_byte;
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
620 }
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
621 else if (--nesting <= 0)
|
25445
|
622 /* nested comments have to be balanced, so we don't need to
|
|
623 keep looking for earlier ones. We use here the same (slightly
|
|
624 incorrect) reasoning as below: since it is followed by uniform
|
|
625 paired string quotes, this comment-start has to be outside of
|
|
626 strings, else the comment-end itself would be inside a string. */
|
|
627 goto done;
|
29835
|
628 break;
|
|
629
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
630 case Sendcomment:
|
32087
|
631 if (SYNTAX_FLAGS_COMMENT_STYLE (syntax) == comstyle
|
49971
afbb2d6d2f07
(back_comment): Only check nestedness of 2nd char if needed.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
632 && ((com2end && SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax))
|
32087
|
633 || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested)
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
634 /* This is the same style of comment ender as ours. */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
635 {
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
636 if (comnested)
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
637 nesting++;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
638 else
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
639 /* Anything before that can't count because it would match
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
640 this comment-ender rather than ours. */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
641 from = stop; /* Break out of the loop. */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
642 }
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
643 else if (comstart_pos != 0 || c != '\n')
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
644 /* We're mixing comment styles here, so we'd better be careful.
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
645 The (comstart_pos != 0 || c != '\n') check is not quite correct
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
646 (we should just always set comment_lossage), but removing it
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
647 would imply that any multiline comment in C would go through
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
648 lossage, which seems overkill.
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
649 The failure should only happen in the rare cases such as
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
650 { (* } *) */
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
651 comment_lossage = 1;
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
652 break;
|
17464
|
653
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
654 case Sopen:
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
655 /* Assume a defun-start point is outside of strings. */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
656 if (open_paren_in_column_0_is_defun_start
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
657 && (from == stop
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
658 || (temp_byte = dec_bytepos (from_byte),
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
659 FETCH_CHAR (temp_byte) == '\n')))
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
660 {
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
661 defun_start = from;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
662 defun_start_byte = from_byte;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
663 from = stop; /* Break out of the loop. */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
664 }
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
665 break;
|
17464
|
666
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
667 default:
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
668 break;
|
20766
|
669 }
|
17464
|
670 }
|
|
671
|
|
672 if (comstart_pos == 0)
|
|
673 {
|
|
674 from = comment_end;
|
20546
|
675 from_byte = comment_end_byte;
|
17464
|
676 UPDATE_SYNTAX_TABLE_FORWARD (comment_end - 1);
|
|
677 }
|
31209
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
678 /* If comstart_pos is set and we get here (ie. didn't jump to `lossage'
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
679 or `done'), then we've found the beginning of the non-nested comment. */
|
00943ea58fd1
(back_comment): Detect cases where a comment-starter is
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
680 else if (1) /* !comnested */
|
17464
|
681 {
|
|
682 from = comstart_pos;
|
20546
|
683 from_byte = comstart_byte;
|
56720
|
684 UPDATE_SYNTAX_TABLE_FORWARD (from - 1);
|
17464
|
685 }
|
|
686 else
|
|
687 {
|
29835
|
688 struct lisp_parse_state state;
|
|
689 lossage:
|
17464
|
690 /* We had two kinds of string delimiters mixed up
|
|
691 together. Decode this going forwards.
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
692 Scan fwd from a known safe place (beginning-of-defun)
|
17464
|
693 to the one in question; this records where we
|
|
694 last passed a comment starter. */
|
20766
|
695 /* If we did not already find the defun start, find it now. */
|
|
696 if (defun_start == 0)
|
|
697 {
|
|
698 defun_start = find_defun_start (comment_end, comment_end_byte);
|
|
699 defun_start_byte = find_start_value_byte;
|
|
700 }
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
701 do
|
17464
|
702 {
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
703 scan_sexps_forward (&state,
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
704 defun_start, defun_start_byte,
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
705 comment_end, -10000, 0, Qnil, 0);
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
706 defun_start = comment_end;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
707 if (state.incomment == (comnested ? 1 : -1)
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
708 && state.comstyle == comstyle)
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
709 from = state.comstr_start;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
710 else
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
711 {
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
712 from = comment_end;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
713 if (state.incomment)
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
714 /* If comment_end is inside some other comment, maybe ours
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
715 is nested, so we need to try again from within the
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
716 surrounding comment. Example: { a (* " *) */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
717 {
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
718 /* FIXME: We should advance by one or two chars. */
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
719 defun_start = state.comstr_start + 2;
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
720 defun_start_byte = CHAR_TO_BYTE (defun_start);
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
721 }
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
722 }
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
723 } while (defun_start < comment_end);
|
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
724
|
20546
|
725 from_byte = CHAR_TO_BYTE (from);
|
17464
|
726 UPDATE_SYNTAX_TABLE_FORWARD (from - 1);
|
|
727 }
|
47942
|
728
|
25445
|
729 done:
|
20546
|
730 *charpos_ptr = from;
|
|
731 *bytepos_ptr = from_byte;
|
|
732
|
27698
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
733 return (from == comment_end) ? -1 : from;
|
17464
|
734 }
|
|
735
|
163
|
736 DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0,
|
40103
|
737 doc: /* Return t if OBJECT is a syntax table.
|
|
738 Currently, any char-table counts as a syntax table. */)
|
|
739 (object)
|
14087
1709d9f11c66
(Fsyntax_table_p, Fchar_syntax, Fmatching_paren, Fmodify_syntax_entry):
Erik Naggum <erik@naggum.no>
diff
changeset
|
740 Lisp_Object object;
|
163
|
741 {
|
14087
1709d9f11c66
(Fsyntax_table_p, Fchar_syntax, Fmatching_paren, Fmodify_syntax_entry):
Erik Naggum <erik@naggum.no>
diff
changeset
|
742 if (CHAR_TABLE_P (object)
|
18113
|
743 && EQ (XCHAR_TABLE (object)->purpose, Qsyntax_table))
|
163
|
744 return Qt;
|
|
745 return Qnil;
|
|
746 }
|
|
747
|
13144
|
748 static void
|
163
|
749 check_syntax_table (obj)
|
|
750 Lisp_Object obj;
|
|
751 {
|
71843
|
752 CHECK_TYPE (CHAR_TABLE_P (obj) && EQ (XCHAR_TABLE (obj)->purpose, Qsyntax_table),
|
|
753 Qsyntax_table_p, obj);
|
47942
|
754 }
|
163
|
755
|
|
756 DEFUN ("syntax-table", Fsyntax_table, Ssyntax_table, 0, 0, 0,
|
40103
|
757 doc: /* Return the current syntax table.
|
|
758 This is the one specified by the current buffer. */)
|
|
759 ()
|
163
|
760 {
|
|
761 return current_buffer->syntax_table;
|
|
762 }
|
|
763
|
|
764 DEFUN ("standard-syntax-table", Fstandard_syntax_table,
|
|
765 Sstandard_syntax_table, 0, 0, 0,
|
40103
|
766 doc: /* Return the standard syntax table.
|
|
767 This is the one used for new buffers. */)
|
|
768 ()
|
163
|
769 {
|
|
770 return Vstandard_syntax_table;
|
|
771 }
|
|
772
|
|
773 DEFUN ("copy-syntax-table", Fcopy_syntax_table, Scopy_syntax_table, 0, 1, 0,
|
40103
|
774 doc: /* Construct a new syntax table and return it.
|
|
775 It is a copy of the TABLE, which defaults to the standard syntax table. */)
|
|
776 (table)
|
163
|
777 Lisp_Object table;
|
|
778 {
|
13144
|
779 Lisp_Object copy;
|
|
780
|
485
|
781 if (!NILP (table))
|
13144
|
782 check_syntax_table (table);
|
|
783 else
|
|
784 table = Vstandard_syntax_table;
|
163
|
785
|
13144
|
786 copy = Fcopy_sequence (table);
|
14661
|
787
|
|
788 /* Only the standard syntax table should have a default element.
|
|
789 Other syntax tables should inherit from parents instead. */
|
|
790 XCHAR_TABLE (copy)->defalt = Qnil;
|
|
791
|
|
792 /* Copied syntax tables should all have parents.
|
|
793 If we copied one with no parent, such as the standard syntax table,
|
|
794 use the standard syntax table as the copy's parent. */
|
|
795 if (NILP (XCHAR_TABLE (copy)->parent))
|
|
796 Fset_char_table_parent (copy, Vstandard_syntax_table);
|
13144
|
797 return copy;
|
163
|
798 }
|
|
799
|
|
800 DEFUN ("set-syntax-table", Fset_syntax_table, Sset_syntax_table, 1, 1, 0,
|
40103
|
801 doc: /* Select a new syntax table for the current buffer.
|
|
802 One argument, a syntax table. */)
|
|
803 (table)
|
163
|
804 Lisp_Object table;
|
|
805 {
|
28313
|
806 int idx;
|
13144
|
807 check_syntax_table (table);
|
163
|
808 current_buffer->syntax_table = table;
|
|
809 /* Indicate that this buffer now has a specified syntax table. */
|
28351
|
810 idx = PER_BUFFER_VAR_IDX (syntax_table);
|
|
811 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1);
|
163
|
812 return table;
|
|
813 }
|
|
814
|
|
815 /* Convert a letter which signifies a syntax code
|
|
816 into the code it signifies.
|
17464
|
817 This is used by modify-syntax-entry, and other things. */
|
163
|
818
|
|
819 unsigned char syntax_spec_code[0400] =
|
|
820 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
821 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
822 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
823 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
17464
|
824 (char) Swhitespace, (char) Scomment_fence, (char) Sstring, 0377,
|
163
|
825 (char) Smath, 0377, 0377, (char) Squote,
|
|
826 (char) Sopen, (char) Sclose, 0377, 0377,
|
|
827 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote,
|
|
828 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
829 0377, 0377, 0377, 0377,
|
|
830 (char) Scomment, 0377, (char) Sendcomment, 0377,
|
5442
|
831 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */
|
163
|
832 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
833 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
|
|
834 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol,
|
|
835 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */
|
|
836 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
|
|
837 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
|
17464
|
838 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377
|
163
|
839 };
|
|
840
|
17464
|
841 /* Indexed by syntax code, give the letter that describes it. */
|
163
|
842
|
17464
|
843 char syntax_code_spec[16] =
|
163
|
844 {
|
17464
|
845 ' ', '.', 'w', '_', '(', ')', '\'', '\"', '$', '\\', '/', '<', '>', '@',
|
|
846 '!', '|'
|
163
|
847 };
|
17044
|
848
|
|
849 /* Indexed by syntax code, give the object (cons of syntax code and
|
|
850 nil) to be stored in syntax table. Since these objects can be
|
|
851 shared among syntax tables, we generate them in advance. By
|
|
852 sharing objects, the function `describe-syntax' can give a more
|
|
853 compact listing. */
|
|
854 static Lisp_Object Vsyntax_code_object;
|
|
855
|
163
|
856
|
13144
|
857 /* Look up the value for CHARACTER in syntax table TABLE's parent
|
|
858 and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil
|
|
859 for CHARACTER. It's actually used only when not compiled with GCC. */
|
|
860
|
|
861 Lisp_Object
|
|
862 syntax_parent_lookup (table, character)
|
|
863 Lisp_Object table;
|
|
864 int character;
|
|
865 {
|
|
866 Lisp_Object value;
|
|
867
|
|
868 while (1)
|
|
869 {
|
|
870 table = XCHAR_TABLE (table)->parent;
|
|
871 if (NILP (table))
|
|
872 return Qnil;
|
|
873
|
|
874 value = XCHAR_TABLE (table)->contents[character];
|
|
875 if (!NILP (value))
|
|
876 return value;
|
|
877 }
|
|
878 }
|
|
879
|
163
|
880 DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0,
|
40103
|
881 doc: /* Return the syntax code of CHARACTER, described by a character.
|
|
882 For example, if CHARACTER is a word constituent,
|
|
883 the character `w' is returned.
|
|
884 The characters that correspond to various syntax codes
|
|
885 are listed in the documentation of `modify-syntax-entry'. */)
|
|
886 (character)
|
14087
1709d9f11c66
(Fsyntax_table_p, Fchar_syntax, Fmatching_paren, Fmodify_syntax_entry):
Erik Naggum <erik@naggum.no>
diff
changeset
|
887 Lisp_Object character;
|
163
|
888 {
|
13144
|
889 int char_int;
|
17464
|
890 gl_state.current_syntax_table = current_buffer->syntax_table;
|
|
891
|
|
892 gl_state.use_global = 0;
|
40656
|
893 CHECK_NUMBER (character);
|
14087
1709d9f11c66
(Fsyntax_table_p, Fchar_syntax, Fmatching_paren, Fmodify_syntax_entry):
Erik Naggum <erik@naggum.no>
diff
changeset
|
894 char_int = XINT (character);
|
13144
|
895 return make_number (syntax_code_spec[(int) SYNTAX (char_int)]);
|
7968
|
896 }
|
|
897
|
|
898 DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0,
|
40103
|
899 doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
|
|
900 (character)
|
14087
1709d9f11c66
(Fsyntax_table_p, Fchar_syntax, Fmatching_paren, Fmodify_syntax_entry):
Erik Naggum <erik@naggum.no>
diff
changeset
|
901 Lisp_Object character;
|
7968
|
902 {
|
13144
|
903 int char_int, code;
|
17464
|
904 gl_state.current_syntax_table = current_buffer->syntax_table;
|
|
905 gl_state.use_global = 0;
|
40656
|
906 CHECK_NUMBER (character);
|
14087
1709d9f11c66
(Fsyntax_table_p, Fchar_syntax, Fmatching_paren, Fmodify_syntax_entry):
Erik Naggum <erik@naggum.no>
diff
changeset
|
907 char_int = XINT (character);
|
13144
|
908 code = SYNTAX (char_int);
|
7975
|
909 if (code == Sopen || code == Sclose)
|
18613
|
910 return SYNTAX_MATCH (char_int);
|
7968
|
911 return Qnil;
|
163
|
912 }
|
|
913
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
914 DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0,
|
40103
|
915 doc: /* Convert a syntax specification STRING into syntax cell form.
|
|
916 STRING should be a string as it is allowed as argument of
|
|
917 `modify-syntax-entry'. Value is the equivalent cons cell
|
|
918 (CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
|
|
919 text property. */)
|
|
920 (string)
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
921 Lisp_Object string;
|
163
|
922 {
|
46555
|
923 register const unsigned char *p;
|
163
|
924 register enum syntaxcode code;
|
9333
|
925 int val;
|
13144
|
926 Lisp_Object match;
|
163
|
927
|
40656
|
928 CHECK_STRING (string);
|
13144
|
929
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
930 p = SDATA (string);
|
163
|
931 code = (enum syntaxcode) syntax_spec_code[*p++];
|
|
932 if (((int) code & 0377) == 0377)
|
63703
|
933 error ("Invalid syntax description letter: %c", p[-1]);
|
163
|
934
|
13144
|
935 if (code == Sinherit)
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
936 return Qnil;
|
163
|
937
|
13144
|
938 if (*p)
|
13513
|
939 {
|
17044
|
940 int len;
|
22547
|
941 int character = (STRING_CHAR_AND_LENGTH
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
942 (p, SBYTES (string) - 1, len));
|
17044
|
943 XSETINT (match, character);
|
13513
|
944 if (XFASTINT (match) == ' ')
|
|
945 match = Qnil;
|
17044
|
946 p += len;
|
13513
|
947 }
|
|
948 else
|
13144
|
949 match = Qnil;
|
|
950
|
|
951 val = (int) code;
|
163
|
952 while (*p)
|
|
953 switch (*p++)
|
|
954 {
|
|
955 case '1':
|
9333
|
956 val |= 1 << 16;
|
163
|
957 break;
|
|
958
|
|
959 case '2':
|
9333
|
960 val |= 1 << 17;
|
163
|
961 break;
|
|
962
|
|
963 case '3':
|
9333
|
964 val |= 1 << 18;
|
163
|
965 break;
|
|
966
|
|
967 case '4':
|
9333
|
968 val |= 1 << 19;
|
163
|
969 break;
|
|
970
|
|
971 case 'p':
|
9333
|
972 val |= 1 << 20;
|
163
|
973 break;
|
1085
|
974
|
|
975 case 'b':
|
9333
|
976 val |= 1 << 21;
|
1085
|
977 break;
|
25445
|
978
|
|
979 case 'n':
|
|
980 val |= 1 << 22;
|
|
981 break;
|
163
|
982 }
|
47942
|
983
|
17044
|
984 if (val < XVECTOR (Vsyntax_code_object)->size && NILP (match))
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
985 return XVECTOR (Vsyntax_code_object)->contents[val];
|
17044
|
986 else
|
|
987 /* Since we can't use a shared object, let's make a new one. */
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
988 return Fcons (make_number (val), match);
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
989 }
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
990
|
40103
|
991 /* I really don't know why this is interactive
|
40286
|
992 help-form should at least be made useful whilst reading the second arg. */
|
47942
|
993 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3,
|
40103
|
994 "cSet syntax for character: \nsSet syntax for %s to: ",
|
40205
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
995 doc: /* Set syntax for character CHAR according to string NEWENTRY.
|
55423
|
996 The syntax is changed only for table SYNTAX-TABLE, which defaults to
|
40103
|
997 the current buffer's syntax table.
|
|
998 The first character of NEWENTRY should be one of the following:
|
|
999 Space or - whitespace syntax. w word constituent.
|
|
1000 _ symbol constituent. . punctuation.
|
|
1001 ( open-parenthesis. ) close-parenthesis.
|
|
1002 " string quote. \\ escape.
|
|
1003 $ paired delimiter. ' expression quote or prefix operator.
|
|
1004 < comment starter. > comment ender.
|
|
1005 / character-quote. @ inherit from `standard-syntax-table'.
|
|
1006 | generic string fence. ! generic comment fence.
|
163
|
1007
|
40103
|
1008 Only single-character comment start and end sequences are represented thus.
|
|
1009 Two-character sequences are represented as described below.
|
|
1010 The second character of NEWENTRY is the matching parenthesis,
|
|
1011 used only if the first character is `(' or `)'.
|
|
1012 Any additional characters are flags.
|
|
1013 Defined flags are the characters 1, 2, 3, 4, b, p, and n.
|
40205
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1014 1 means CHAR is the start of a two-char comment start sequence.
|
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1015 2 means CHAR is the second character of such a sequence.
|
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1016 3 means CHAR is the start of a two-char comment end sequence.
|
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1017 4 means CHAR is the second character of such a sequence.
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1018
|
40103
|
1019 There can be up to two orthogonal comment sequences. This is to support
|
|
1020 language modes such as C++. By default, all comment sequences are of style
|
|
1021 a, but you can set the comment sequence style to b (on the second character
|
|
1022 of a comment-start, or the first character of a comment-end sequence) using
|
|
1023 this flag:
|
40205
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1024 b means CHAR is part of comment sequence b.
|
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1025 n means CHAR is part of a nestable comment sequence.
|
40103
|
1026
|
40205
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1027 p means CHAR is a prefix character for `backward-prefix-chars';
|
40103
|
1028 such characters are treated as whitespace when they occur
|
40205
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1029 between expressions.
|
d13b14b50715
(modify-syntax-entry): Fix argument names (use CHAR instead of C) and usage.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
1030 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
|
40103
|
1031 (c, newentry, syntax_table)
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1032 Lisp_Object c, newentry, syntax_table;
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1033 {
|
40656
|
1034 CHECK_NUMBER (c);
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1035
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1036 if (NILP (syntax_table))
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1037 syntax_table = current_buffer->syntax_table;
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1038 else
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1039 check_syntax_table (syntax_table);
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1040
|
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1041 SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Fstring_to_syntax (newentry));
|
72945
|
1042
|
|
1043 /* We clear the regexp cache, since character classes can now have
|
|
1044 different values from those in the compiled regexps.*/
|
|
1045 clear_regexp_cache ();
|
|
1046
|
163
|
1047 return Qnil;
|
|
1048 }
|
|
1049
|
|
1050 /* Dump syntax table to buffer in human-readable format */
|
|
1051
|
40663
|
1052 DEFUN ("internal-describe-syntax-value", Finternal_describe_syntax_value,
|
|
1053 Sinternal_describe_syntax_value, 1, 1, 0,
|
|
1054 doc: /* Insert a description of the internal syntax description SYNTAX at point. */)
|
|
1055 (syntax)
|
|
1056 Lisp_Object syntax;
|
163
|
1057 {
|
|
1058 register enum syntaxcode code;
|
29821
|
1059 char desc, start1, start2, end1, end2, prefix, comstyle, comnested;
|
163
|
1060 char str[2];
|
40663
|
1061 Lisp_Object first, match_lisp, value = syntax;
|
163
|
1062
|
13144
|
1063 if (NILP (value))
|
|
1064 {
|
40663
|
1065 insert_string ("default");
|
|
1066 return syntax;
|
13144
|
1067 }
|
|
1068
|
17109
|
1069 if (CHAR_TABLE_P (value))
|
|
1070 {
|
40663
|
1071 insert_string ("deeper char-table ...");
|
|
1072 return syntax;
|
17109
|
1073 }
|
|
1074
|
13144
|
1075 if (!CONSP (value))
|
163
|
1076 {
|
40663
|
1077 insert_string ("invalid");
|
|
1078 return syntax;
|
163
|
1079 }
|
|
1080
|
25663
|
1081 first = XCAR (value);
|
|
1082 match_lisp = XCDR (value);
|
13144
|
1083
|
|
1084 if (!INTEGERP (first) || !(NILP (match_lisp) || INTEGERP (match_lisp)))
|
|
1085 {
|
40663
|
1086 insert_string ("invalid");
|
|
1087 return syntax;
|
13144
|
1088 }
|
|
1089
|
18113
|
1090 code = (enum syntaxcode) (XINT (first) & 0377);
|
13144
|
1091 start1 = (XINT (first) >> 16) & 1;
|
|
1092 start2 = (XINT (first) >> 17) & 1;
|
|
1093 end1 = (XINT (first) >> 18) & 1;
|
|
1094 end2 = (XINT (first) >> 19) & 1;
|
|
1095 prefix = (XINT (first) >> 20) & 1;
|
|
1096 comstyle = (XINT (first) >> 21) & 1;
|
29821
|
1097 comnested = (XINT (first) >> 22) & 1;
|
163
|
1098
|
|
1099 if ((int) code < 0 || (int) code >= (int) Smax)
|
|
1100 {
|
|
1101 insert_string ("invalid");
|
40663
|
1102 return syntax;
|
163
|
1103 }
|
|
1104 desc = syntax_code_spec[(int) code];
|
|
1105
|
|
1106 str[0] = desc, str[1] = 0;
|
|
1107 insert (str, 1);
|
|
1108
|
17044
|
1109 if (NILP (match_lisp))
|
|
1110 insert (" ", 1);
|
|
1111 else
|
|
1112 insert_char (XINT (match_lisp));
|
163
|
1113
|
|
1114 if (start1)
|
|
1115 insert ("1", 1);
|
|
1116 if (start2)
|
|
1117 insert ("2", 1);
|
|
1118
|
|
1119 if (end1)
|
|
1120 insert ("3", 1);
|
|
1121 if (end2)
|
|
1122 insert ("4", 1);
|
|
1123
|
|
1124 if (prefix)
|
|
1125 insert ("p", 1);
|
1085
|
1126 if (comstyle)
|
|
1127 insert ("b", 1);
|
29821
|
1128 if (comnested)
|
|
1129 insert ("n", 1);
|
163
|
1130
|
|
1131 insert_string ("\twhich means: ");
|
|
1132
|
10457
2ab3bd0288a9
Change all occurences of SWITCH_ENUM_BUG to use SWITCH_ENUM_CAST instead.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1133 switch (SWITCH_ENUM_CAST (code))
|
163
|
1134 {
|
|
1135 case Swhitespace:
|
|
1136 insert_string ("whitespace"); break;
|
|
1137 case Spunct:
|
|
1138 insert_string ("punctuation"); break;
|
|
1139 case Sword:
|
|
1140 insert_string ("word"); break;
|
|
1141 case Ssymbol:
|
|
1142 insert_string ("symbol"); break;
|
|
1143 case Sopen:
|
|
1144 insert_string ("open"); break;
|
|
1145 case Sclose:
|
|
1146 insert_string ("close"); break;
|
|
1147 case Squote:
|
32508
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1148 insert_string ("prefix"); break;
|
163
|
1149 case Sstring:
|
|
1150 insert_string ("string"); break;
|
|
1151 case Smath:
|
|
1152 insert_string ("math"); break;
|
|
1153 case Sescape:
|
|
1154 insert_string ("escape"); break;
|
|
1155 case Scharquote:
|
|
1156 insert_string ("charquote"); break;
|
|
1157 case Scomment:
|
|
1158 insert_string ("comment"); break;
|
|
1159 case Sendcomment:
|
|
1160 insert_string ("endcomment"); break;
|
32508
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1161 case Sinherit:
|
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1162 insert_string ("inherit"); break;
|
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1163 case Scomment_fence:
|
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1164 insert_string ("comment fence"); break;
|
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1165 case Sstring_fence:
|
d371f8c371bd
(describe_syntax): Add code for comment and string fences.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1166 insert_string ("string fence"); break;
|
163
|
1167 default:
|
|
1168 insert_string ("invalid");
|
40663
|
1169 return syntax;
|
163
|
1170 }
|
|
1171
|
13144
|
1172 if (!NILP (match_lisp))
|
163
|
1173 {
|
|
1174 insert_string (", matches ");
|
13144
|
1175 insert_char (XINT (match_lisp));
|
163
|
1176 }
|
|
1177
|
|
1178 if (start1)
|
|
1179 insert_string (",\n\t is the first character of a comment-start sequence");
|
|
1180 if (start2)
|
|
1181 insert_string (",\n\t is the second character of a comment-start sequence");
|
|
1182
|
|
1183 if (end1)
|
|
1184 insert_string (",\n\t is the first character of a comment-end sequence");
|
|
1185 if (end2)
|
|
1186 insert_string (",\n\t is the second character of a comment-end sequence");
|
1085
|
1187 if (comstyle)
|
|
1188 insert_string (" (comment style b)");
|
29821
|
1189 if (comnested)
|
|
1190 insert_string (" (nestable)");
|
1085
|
1191
|
163
|
1192 if (prefix)
|
|
1193 insert_string (",\n\t is a prefix character for `backward-prefix-chars'");
|
|
1194
|
40663
|
1195 return syntax;
|
|
1196 }
|
163
|
1197
|
17464
|
1198 int parse_sexp_ignore_comments;
|
|
1199
|
163
|
1200 /* Return the position across COUNT words from FROM.
|
|
1201 If that many words cannot be found before the end of the buffer, return 0.
|
|
1202 COUNT negative means scan backward and stop at word beginning. */
|
|
1203
|
21514
|
1204 int
|
163
|
1205 scan_words (from, count)
|
|
1206 register int from, count;
|
|
1207 {
|
|
1208 register int beg = BEGV;
|
|
1209 register int end = ZV;
|
20546
|
1210 register int from_byte = CHAR_TO_BYTE (from);
|
17044
|
1211 register enum syntaxcode code;
|
|
1212 int ch0, ch1;
|
163
|
1213
|
|
1214 immediate_quit = 1;
|
|
1215 QUIT;
|
|
1216
|
17464
|
1217 SETUP_SYNTAX_TABLE (from, count);
|
|
1218
|
163
|
1219 while (count > 0)
|
|
1220 {
|
|
1221 while (1)
|
|
1222 {
|
|
1223 if (from == end)
|
|
1224 {
|
|
1225 immediate_quit = 0;
|
|
1226 return 0;
|
|
1227 }
|
17464
|
1228 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
20546
|
1229 ch0 = FETCH_CHAR (from_byte);
|
17044
|
1230 code = SYNTAX (ch0);
|
20546
|
1231 INC_BOTH (from, from_byte);
|
163
|
1232 if (words_include_escapes
|
|
1233 && (code == Sescape || code == Scharquote))
|
|
1234 break;
|
|
1235 if (code == Sword)
|
|
1236 break;
|
|
1237 }
|
17044
|
1238 /* Now CH0 is a character which begins a word and FROM is the
|
|
1239 position of the next character. */
|
163
|
1240 while (1)
|
|
1241 {
|
|
1242 if (from == end) break;
|
17464
|
1243 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
20546
|
1244 ch1 = FETCH_CHAR (from_byte);
|
17044
|
1245 code = SYNTAX (ch1);
|
163
|
1246 if (!(words_include_escapes
|
|
1247 && (code == Sescape || code == Scharquote)))
|
17044
|
1248 if (code != Sword || WORD_BOUNDARY_P (ch0, ch1))
|
163
|
1249 break;
|
20546
|
1250 INC_BOTH (from, from_byte);
|
17044
|
1251 ch0 = ch1;
|
163
|
1252 }
|
|
1253 count--;
|
|
1254 }
|
|
1255 while (count < 0)
|
|
1256 {
|
|
1257 while (1)
|
|
1258 {
|
|
1259 if (from == beg)
|
|
1260 {
|
|
1261 immediate_quit = 0;
|
|
1262 return 0;
|
|
1263 }
|
20546
|
1264 DEC_BOTH (from, from_byte);
|
17464
|
1265 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
20546
|
1266 ch1 = FETCH_CHAR (from_byte);
|
17044
|
1267 code = SYNTAX (ch1);
|
163
|
1268 if (words_include_escapes
|
|
1269 && (code == Sescape || code == Scharquote))
|
|
1270 break;
|
|
1271 if (code == Sword)
|
|
1272 break;
|
|
1273 }
|
17044
|
1274 /* Now CH1 is a character which ends a word and FROM is the
|
|
1275 position of it. */
|
163
|
1276 while (1)
|
|
1277 {
|
20546
|
1278 int temp_byte;
|
|
1279
|
|
1280 if (from == beg)
|
|
1281 break;
|
|
1282 temp_byte = dec_bytepos (from_byte);
|
17464
|
1283 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
20546
|
1284 ch0 = FETCH_CHAR (temp_byte);
|
17044
|
1285 code = SYNTAX (ch0);
|
163
|
1286 if (!(words_include_escapes
|
|
1287 && (code == Sescape || code == Scharquote)))
|
17044
|
1288 if (code != Sword || WORD_BOUNDARY_P (ch0, ch1))
|
163
|
1289 break;
|
20546
|
1290 DEC_BOTH (from, from_byte);
|
17044
|
1291 ch1 = ch0;
|
163
|
1292 }
|
|
1293 count++;
|
|
1294 }
|
|
1295
|
|
1296 immediate_quit = 0;
|
|
1297
|
|
1298 return from;
|
|
1299 }
|
|
1300
|
52213
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1301 DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "p",
|
40103
|
1302 doc: /* Move point forward ARG words (backward if ARG is negative).
|
|
1303 Normally returns t.
|
|
1304 If an edge of the buffer or a field boundary is reached, point is left there
|
|
1305 and the function returns nil. Field boundaries are not noticed if
|
|
1306 `inhibit-field-text-motion' is non-nil. */)
|
52213
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1307 (arg)
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1308 Lisp_Object arg;
|
163
|
1309 {
|
58897
98e94b29b59b
(Fforward_word): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1310 Lisp_Object tmp;
|
26391
|
1311 int orig_val, val;
|
52213
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1312
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1313 if (NILP (arg))
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1314 XSETFASTINT (arg, 1);
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1315 else
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1316 CHECK_NUMBER (arg);
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1317
|
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1318 val = orig_val = scan_words (PT, XINT (arg));
|
26391
|
1319 if (! orig_val)
|
52213
d8341603541c
(Fforward_word): Argument changed to optional. Set default value to 1.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1320 val = XINT (arg) > 0 ? ZV : BEGV;
|
25401
|
1321
|
26060
|
1322 /* Avoid jumping out of an input field. */
|
58897
98e94b29b59b
(Fforward_word): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1323 tmp = Fconstrain_to_field (make_number (val), make_number (PT),
|
98e94b29b59b
(Fforward_word): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1324 Qt, Qnil, Qnil);
|
98e94b29b59b
(Fforward_word): Avoid non-idempotent side-effects in macro arguments.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1325 val = XFASTINT (tmp);
|
47942
|
1326
|
163
|
1327 SET_PT (val);
|
27079
|
1328 return val == orig_val ? Qt : Qnil;
|
163
|
1329 }
|
|
1330
|
17464
|
1331 Lisp_Object skip_chars ();
|
|
1332
|
|
1333 DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0,
|
40103
|
1334 doc: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
|
|
1335 STRING is like the inside of a `[...]' in a regular expression
|
|
1336 except that `]' is never special and `\\' quotes `^', `-' or `\\'
|
|
1337 (but not as the end of a range; quoting is never needed there).
|
|
1338 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
|
|
1339 With arg "^a-zA-Z", skips nonletters stopping before first letter.
|
56088
|
1340 Char classes, e.g. `[:alpha:]', are supported.
|
|
1341
|
|
1342 Returns the distance traveled, either zero or positive. */)
|
40103
|
1343 (string, lim)
|
17464
|
1344 Lisp_Object string, lim;
|
|
1345 {
|
56088
|
1346 return skip_chars (1, 0, string, lim, 1);
|
17464
|
1347 }
|
|
1348
|
|
1349 DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0,
|
40103
|
1350 doc: /* Move point backward, stopping after a char not in STRING, or at pos LIM.
|
|
1351 See `skip-chars-forward' for details.
|
|
1352 Returns the distance traveled, either zero or negative. */)
|
|
1353 (string, lim)
|
17464
|
1354 Lisp_Object string, lim;
|
|
1355 {
|
56088
|
1356 return skip_chars (0, 0, string, lim, 1);
|
17464
|
1357 }
|
|
1358
|
|
1359 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0,
|
40103
|
1360 doc: /* Move point forward across chars in specified syntax classes.
|
|
1361 SYNTAX is a string of syntax code characters.
|
|
1362 Stop before a char whose syntax is not in SYNTAX, or at position LIM.
|
|
1363 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
|
|
1364 This function returns the distance traveled, either zero or positive. */)
|
|
1365 (syntax, lim)
|
17464
|
1366 Lisp_Object syntax, lim;
|
|
1367 {
|
56088
|
1368 return skip_chars (1, 1, syntax, lim, 0);
|
17464
|
1369 }
|
|
1370
|
|
1371 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, Sskip_syntax_backward, 1, 2, 0,
|
40103
|
1372 doc: /* Move point backward across chars in specified syntax classes.
|
|
1373 SYNTAX is a string of syntax code characters.
|
|
1374 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM.
|
|
1375 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
|
|
1376 This function returns the distance traveled, either zero or negative. */)
|
|
1377 (syntax, lim)
|
17464
|
1378 Lisp_Object syntax, lim;
|
|
1379 {
|
56088
|
1380 return skip_chars (0, 1, syntax, lim, 0);
|
17464
|
1381 }
|
|
1382
|
20546
|
1383 static Lisp_Object
|
56088
|
1384 skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes)
|
17464
|
1385 int forwardp, syntaxp;
|
|
1386 Lisp_Object string, lim;
|
56088
|
1387 int handle_iso_classes;
|
17464
|
1388 {
|
|
1389 register unsigned int c;
|
|
1390 unsigned char fastmap[0400];
|
17564
|
1391 /* If SYNTAXP is 0, STRING may contain multi-byte form of characters
|
31944
|
1392 of which codes don't fit in FASTMAP. In that case, set the
|
|
1393 ranges of characters in CHAR_RANGES. */
|
20292
|
1394 int *char_ranges;
|
17564
|
1395 int n_char_ranges = 0;
|
17464
|
1396 int negate = 0;
|
20626
|
1397 register int i, i_byte;
|
17564
|
1398 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
|
22486
a28020246db1
(skip_chars): Don't examine STRING before verifying that it is a string.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1399 int string_multibyte;
|
a28020246db1
(skip_chars): Don't examine STRING before verifying that it is a string.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1400 int size_byte;
|
46555
|
1401 const unsigned char *str;
|
30596
|
1402 int len;
|
56088
|
1403 Lisp_Object iso_classes;
|
17464
|
1404
|
40656
|
1405 CHECK_STRING (string);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1406 char_ranges = (int *) alloca (SCHARS (string) * (sizeof (int)) * 2);
|
22486
a28020246db1
(skip_chars): Don't examine STRING before verifying that it is a string.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1407 string_multibyte = STRING_MULTIBYTE (string);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1408 str = SDATA (string);
|
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1409 size_byte = SBYTES (string);
|
56088
|
1410 iso_classes = Qnil;
|
17464
|
1411
|
30596
|
1412 /* Adjust the multibyteness of the string to that of the buffer. */
|
|
1413 if (multibyte != string_multibyte)
|
|
1414 {
|
|
1415 int nbytes;
|
|
1416
|
|
1417 if (multibyte)
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1418 nbytes = count_size_as_multibyte (SDATA (string),
|
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1419 SCHARS (string));
|
30596
|
1420 else
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1421 nbytes = SCHARS (string);
|
30596
|
1422 if (nbytes != size_byte)
|
|
1423 {
|
46555
|
1424 unsigned char *tmp = (unsigned char *) alloca (nbytes);
|
|
1425 copy_text (SDATA (string), tmp, size_byte,
|
30596
|
1426 string_multibyte, multibyte);
|
|
1427 size_byte = nbytes;
|
46555
|
1428 str = tmp;
|
30596
|
1429 }
|
|
1430 }
|
|
1431
|
17464
|
1432 if (NILP (lim))
|
|
1433 XSETINT (lim, forwardp ? ZV : BEGV);
|
|
1434 else
|
40656
|
1435 CHECK_NUMBER_COERCE_MARKER (lim);
|
17464
|
1436
|
|
1437 /* In any case, don't allow scan outside bounds of buffer. */
|
|
1438 if (XINT (lim) > ZV)
|
|
1439 XSETFASTINT (lim, ZV);
|
|
1440 if (XINT (lim) < BEGV)
|
|
1441 XSETFASTINT (lim, BEGV);
|
|
1442
|
|
1443 bzero (fastmap, sizeof fastmap);
|
|
1444
|
30596
|
1445 i_byte = 0;
|
20626
|
1446
|
22130
|
1447 if (i_byte < size_byte
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1448 && SREF (string, 0) == '^')
|
17464
|
1449 {
|
30596
|
1450 negate = 1; i_byte++;
|
17464
|
1451 }
|
|
1452
|
|
1453 /* Find the characters specified and set their elements of fastmap.
|
|
1454 If syntaxp, each character counts as itself.
|
|
1455 Otherwise, handle backslashes and ranges specially. */
|
|
1456
|
22130
|
1457 while (i_byte < size_byte)
|
17464
|
1458 {
|
30596
|
1459 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len);
|
|
1460 i_byte += len;
|
20626
|
1461
|
17464
|
1462 if (syntaxp)
|
20626
|
1463 fastmap[syntax_spec_code[c & 0377]] = 1;
|
17464
|
1464 else
|
|
1465 {
|
56088
|
1466 if (handle_iso_classes && c == '['
|
|
1467 && i_byte < size_byte
|
|
1468 && STRING_CHAR (str + i_byte, size_byte - i_byte) == ':')
|
|
1469 {
|
|
1470 const unsigned char *class_beg = str + i_byte + 1;
|
|
1471 const unsigned char *class_end = class_beg;
|
56116
|
1472 const unsigned char *class_limit = str + size_byte - 2;
|
56088
|
1473 /* Leave room for the null. */
|
|
1474 unsigned char class_name[CHAR_CLASS_MAX_LENGTH + 1];
|
|
1475 re_wctype_t cc;
|
|
1476
|
|
1477 if (class_limit - class_beg > CHAR_CLASS_MAX_LENGTH)
|
|
1478 class_limit = class_beg + CHAR_CLASS_MAX_LENGTH;
|
|
1479
|
56116
|
1480 while (class_end < class_limit
|
|
1481 && *class_end >= 'a' && *class_end <= 'z')
|
56088
|
1482 class_end++;
|
|
1483
|
56116
|
1484 if (class_end == class_beg
|
|
1485 || *class_end != ':' || class_end[1] != ']')
|
|
1486 goto not_a_class_name;
|
56088
|
1487
|
|
1488 bcopy (class_beg, class_name, class_end - class_beg);
|
|
1489 class_name[class_end - class_beg] = 0;
|
|
1490
|
|
1491 cc = re_wctype (class_name);
|
|
1492 if (cc == 0)
|
|
1493 error ("Invalid ISO C character class");
|
|
1494
|
|
1495 iso_classes = Fcons (make_number (cc), iso_classes);
|
|
1496
|
|
1497 i_byte = class_end + 2 - str;
|
|
1498 continue;
|
|
1499 }
|
|
1500
|
56116
|
1501 not_a_class_name:
|
17464
|
1502 if (c == '\\')
|
|
1503 {
|
22130
|
1504 if (i_byte == size_byte)
|
20626
|
1505 break;
|
|
1506
|
53508
|
1507 c = STRING_CHAR_AND_LENGTH (str + i_byte,
|
|
1508 size_byte - i_byte, len);
|
30596
|
1509 i_byte += len;
|
17464
|
1510 }
|
53508
|
1511 /* Treat `-' as range character only if another character
|
|
1512 follows. */
|
|
1513 if (i_byte + 1 < size_byte
|
30596
|
1514 && str[i_byte] == '-')
|
17464
|
1515 {
|
31944
|
1516 unsigned int c2;
|
20626
|
1517
|
|
1518 /* Skip over the dash. */
|
30596
|
1519 i_byte++;
|
20626
|
1520
|
|
1521 /* Get the end of the range. */
|
53508
|
1522 c2 = STRING_CHAR_AND_LENGTH (str + i_byte,
|
|
1523 size_byte - i_byte, len);
|
30596
|
1524 i_byte += len;
|
20626
|
1525
|
|
1526 if (SINGLE_BYTE_CHAR_P (c))
|
22116
|
1527 {
|
|
1528 if (! SINGLE_BYTE_CHAR_P (c2))
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1529 {
|
32794
|
1530 /* Handle a range starting with a character of
|
|
1531 less than 256, and ending with a character of
|
|
1532 not less than 256. Split that into two
|
|
1533 ranges, the low one ending at 0377, and the
|
|
1534 high one starting at the smallest character
|
|
1535 in the charset of C2 and ending at C2. */
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1536 int charset = CHAR_CHARSET (c2);
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1537 int c1 = MAKE_CHAR (charset, 0, 0);
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1538
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1539 char_ranges[n_char_ranges++] = c1;
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1540 char_ranges[n_char_ranges++] = c2;
|
32399
3819d0d851cb
(skip_chars): Change the way of handling a range from unibyte char to
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1541 c2 = 0377;
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1542 }
|
22116
|
1543 while (c <= c2)
|
|
1544 {
|
|
1545 fastmap[c] = 1;
|
|
1546 c++;
|
|
1547 }
|
|
1548 }
|
31944
|
1549 else if (c <= c2) /* Both C and C2 are multibyte char. */
|
17464
|
1550 {
|
31944
|
1551 char_ranges[n_char_ranges++] = c;
|
|
1552 char_ranges[n_char_ranges++] = c2;
|
17464
|
1553 }
|
|
1554 }
|
|
1555 else
|
17564
|
1556 {
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1557 if (SINGLE_BYTE_CHAR_P (c))
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1558 fastmap[c] = 1;
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1559 else
|
17564
|
1560 {
|
20626
|
1561 char_ranges[n_char_ranges++] = c;
|
|
1562 char_ranges[n_char_ranges++] = c;
|
17564
|
1563 }
|
|
1564 }
|
17464
|
1565 }
|
|
1566 }
|
|
1567
|
31944
|
1568 /* If ^ was the first character, complement the fastmap. */
|
17464
|
1569 if (negate)
|
|
1570 for (i = 0; i < sizeof fastmap; i++)
|
31944
|
1571 fastmap[i] ^= 1;
|
17464
|
1572
|
|
1573 {
|
|
1574 int start_point = PT;
|
|
1575 int pos = PT;
|
20546
|
1576 int pos_byte = PT_BYTE;
|
50675
|
1577 unsigned char *p = PT_ADDR, *endp, *stop;
|
|
1578
|
|
1579 if (forwardp)
|
|
1580 {
|
|
1581 endp = (XINT (lim) == GPT) ? GPT_ADDR : CHAR_POS_ADDR (XINT (lim));
|
55423
|
1582 stop = (pos < GPT && GPT < XINT (lim)) ? GPT_ADDR : endp;
|
50675
|
1583 }
|
|
1584 else
|
|
1585 {
|
|
1586 endp = CHAR_POS_ADDR (XINT (lim));
|
55423
|
1587 stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp;
|
50675
|
1588 }
|
17464
|
1589
|
|
1590 immediate_quit = 1;
|
|
1591 if (syntaxp)
|
|
1592 {
|
|
1593 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1);
|
|
1594 if (forwardp)
|
|
1595 {
|
17564
|
1596 if (multibyte)
|
50675
|
1597 while (1)
|
|
1598 {
|
|
1599 int nbytes;
|
|
1600
|
|
1601 if (p >= stop)
|
20956
|
1602 {
|
50675
|
1603 if (p >= endp)
|
|
1604 break;
|
|
1605 p = GAP_END_ADDR;
|
|
1606 stop = endp;
|
20956
|
1607 }
|
50675
|
1608 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes);
|
|
1609 if (! fastmap[(int) SYNTAX (c)])
|
|
1610 break;
|
|
1611 p += nbytes, pos++, pos_byte += nbytes;
|
|
1612 UPDATE_SYNTAX_TABLE_FORWARD (pos);
|
|
1613 }
|
17564
|
1614 else
|
50675
|
1615 while (1)
|
|
1616 {
|
|
1617 if (p >= stop)
|
|
1618 {
|
|
1619 if (p >= endp)
|
|
1620 break;
|
|
1621 p = GAP_END_ADDR;
|
|
1622 stop = endp;
|
|
1623 }
|
|
1624 if (! fastmap[(int) SYNTAX (*p)])
|
|
1625 break;
|
|
1626 p++, pos++;
|
|
1627 UPDATE_SYNTAX_TABLE_FORWARD (pos);
|
|
1628 }
|
17464
|
1629 }
|
|
1630 else
|
|
1631 {
|
17564
|
1632 if (multibyte)
|
50675
|
1633 while (1)
|
|
1634 {
|
|
1635 unsigned char *prev_p;
|
|
1636 int nbytes;
|
|
1637
|
|
1638 if (p <= stop)
|
|
1639 {
|
|
1640 if (p <= endp)
|
17564
|
1641 break;
|
50675
|
1642 p = GPT_ADDR;
|
|
1643 stop = endp;
|
|
1644 }
|
|
1645 prev_p = p;
|
|
1646 while (--p >= stop && ! CHAR_HEAD_P (*p));
|
|
1647 PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes);
|
|
1648 if (prev_p - p > nbytes)
|
|
1649 p = prev_p - 1, c = *p, nbytes = 1;
|
|
1650 else
|
|
1651 c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
|
|
1652 pos--, pos_byte -= nbytes;
|
|
1653 UPDATE_SYNTAX_TABLE_BACKWARD (pos);
|
|
1654 if (! fastmap[(int) SYNTAX (c)])
|
|
1655 {
|
|
1656 pos++;
|
|
1657 pos_byte += nbytes;
|
|
1658 break;
|
|
1659 }
|
|
1660 }
|
17564
|
1661 else
|
50675
|
1662 while (1)
|
|
1663 {
|
|
1664 if (p <= stop)
|
20956
|
1665 {
|
50675
|
1666 if (p <= endp)
|
17585
|
1667 break;
|
50675
|
1668 p = GPT_ADDR;
|
|
1669 stop = endp;
|
20956
|
1670 }
|
50675
|
1671 if (! fastmap[(int) SYNTAX (p[-1])])
|
|
1672 break;
|
|
1673 p--, pos--;
|
|
1674 UPDATE_SYNTAX_TABLE_BACKWARD (pos - 1);
|
|
1675 }
|
17464
|
1676 }
|
|
1677 }
|
|
1678 else
|
|
1679 {
|
|
1680 if (forwardp)
|
|
1681 {
|
17564
|
1682 if (multibyte)
|
50675
|
1683 while (1)
|
17564
|
1684 {
|
50675
|
1685 int nbytes;
|
|
1686
|
|
1687 if (p >= stop)
|
|
1688 {
|
|
1689 if (p >= endp)
|
|
1690 break;
|
|
1691 p = GAP_END_ADDR;
|
|
1692 stop = endp;
|
|
1693 }
|
|
1694 c = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, nbytes);
|
56088
|
1695
|
|
1696 if (! NILP (iso_classes) && in_classes (c, iso_classes))
|
|
1697 {
|
|
1698 if (negate)
|
|
1699 break;
|
|
1700 else
|
|
1701 goto fwd_ok;
|
|
1702 }
|
|
1703
|
31944
|
1704 if (SINGLE_BYTE_CHAR_P (c))
|
17564
|
1705 {
|
31944
|
1706 if (!fastmap[c])
|
|
1707 break;
|
|
1708 }
|
|
1709 else
|
|
1710 {
|
|
1711 /* If we are looking at a multibyte character,
|
|
1712 we must look up the character in the table
|
|
1713 CHAR_RANGES. If there's no data in the
|
|
1714 table, that character is not what we want to
|
|
1715 skip. */
|
|
1716
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1717 /* The following code do the right thing even if
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1718 n_char_ranges is zero (i.e. no data in
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1719 CHAR_RANGES). */
|
17564
|
1720 for (i = 0; i < n_char_ranges; i += 2)
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1721 if (c >= char_ranges[i] && c <= char_ranges[i + 1])
|
17564
|
1722 break;
|
|
1723 if (!(negate ^ (i < n_char_ranges)))
|
|
1724 break;
|
|
1725 }
|
56088
|
1726 fwd_ok:
|
50675
|
1727 p += nbytes, pos++, pos_byte += nbytes;
|
17564
|
1728 }
|
|
1729 else
|
50675
|
1730 while (1)
|
|
1731 {
|
|
1732 if (p >= stop)
|
|
1733 {
|
|
1734 if (p >= endp)
|
|
1735 break;
|
|
1736 p = GAP_END_ADDR;
|
|
1737 stop = endp;
|
|
1738 }
|
56088
|
1739
|
|
1740 if (!NILP (iso_classes) && in_classes (*p, iso_classes))
|
|
1741 {
|
|
1742 if (negate)
|
|
1743 break;
|
|
1744 else
|
56724
|
1745 goto fwd_unibyte_ok;
|
56088
|
1746 }
|
|
1747
|
50697
|
1748 if (!fastmap[*p])
|
50675
|
1749 break;
|
56724
|
1750 fwd_unibyte_ok:
|
50675
|
1751 p++, pos++;
|
|
1752 }
|
17464
|
1753 }
|
|
1754 else
|
|
1755 {
|
17564
|
1756 if (multibyte)
|
50675
|
1757 while (1)
|
17564
|
1758 {
|
50675
|
1759 unsigned char *prev_p;
|
|
1760 int nbytes;
|
|
1761
|
|
1762 if (p <= stop)
|
|
1763 {
|
|
1764 if (p <= endp)
|
|
1765 break;
|
|
1766 p = GPT_ADDR;
|
|
1767 stop = endp;
|
|
1768 }
|
|
1769 prev_p = p;
|
|
1770 while (--p >= stop && ! CHAR_HEAD_P (*p));
|
|
1771 PARSE_MULTIBYTE_SEQ (p, MAX_MULTIBYTE_LENGTH, nbytes);
|
|
1772 if (prev_p - p > nbytes)
|
|
1773 p = prev_p - 1, c = *p, nbytes = 1;
|
|
1774 else
|
|
1775 c = STRING_CHAR (p, MAX_MULTIBYTE_LENGTH);
|
56088
|
1776
|
|
1777 if (! NILP (iso_classes) && in_classes (c, iso_classes))
|
|
1778 {
|
|
1779 if (negate)
|
|
1780 break;
|
|
1781 else
|
|
1782 goto back_ok;
|
|
1783 }
|
|
1784
|
31944
|
1785 if (SINGLE_BYTE_CHAR_P (c))
|
17564
|
1786 {
|
31944
|
1787 if (!fastmap[c])
|
|
1788 break;
|
|
1789 }
|
|
1790 else
|
|
1791 {
|
|
1792 /* See the comment in the previous similar code. */
|
30626
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1793 for (i = 0; i < n_char_ranges; i += 2)
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1794 if (c >= char_ranges[i] && c <= char_ranges[i + 1])
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1795 break;
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1796 if (!(negate ^ (i < n_char_ranges)))
|
9d47c133b357
* syntax.c (skip_chars): Fix previous change. Make the handling of
Kenichi Handa <handa@m17n.org>
diff
changeset
|
1797 break;
|
17564
|
1798 }
|
56088
|
1799 back_ok:
|
50675
|
1800 pos--, pos_byte -= nbytes;
|
17564
|
1801 }
|
|
1802 else
|
50675
|
1803 while (1)
|
|
1804 {
|
|
1805 if (p <= stop)
|
|
1806 {
|
|
1807 if (p <= endp)
|
|
1808 break;
|
|
1809 p = GPT_ADDR;
|
|
1810 stop = endp;
|
|
1811 }
|
56088
|
1812
|
|
1813 if (! NILP (iso_classes) && in_classes (p[-1], iso_classes))
|
|
1814 {
|
|
1815 if (negate)
|
|
1816 break;
|
|
1817 else
|
56724
|
1818 goto back_unibyte_ok;
|
56088
|
1819 }
|
|
1820
|
50697
|
1821 if (!fastmap[p[-1]])
|
50675
|
1822 break;
|
56724
|
1823 back_unibyte_ok:
|
50675
|
1824 p--, pos--;
|
|
1825 }
|
17464
|
1826 }
|
|
1827 }
|
17564
|
1828
|
20546
|
1829 #if 0 /* Not needed now that a position in mid-character
|
|
1830 cannot be specified in Lisp. */
|
17564
|
1831 if (multibyte
|
|
1832 /* INC_POS or DEC_POS might have moved POS over LIM. */
|
|
1833 && (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim))))
|
|
1834 pos = XINT (lim);
|
20546
|
1835 #endif
|
17564
|
1836
|
20546
|
1837 if (! multibyte)
|
|
1838 pos_byte = pos;
|
|
1839
|
|
1840 SET_PT_BOTH (pos, pos_byte);
|
17464
|
1841 immediate_quit = 0;
|
|
1842
|
|
1843 return make_number (PT - start_point);
|
|
1844 }
|
|
1845 }
|
56088
|
1846
|
|
1847 /* Return 1 if character C belongs to one of the ISO classes
|
|
1848 in the list ISO_CLASSES. Each class is represented by an
|
|
1849 integer which is its type according to re_wctype. */
|
|
1850
|
|
1851 static int
|
|
1852 in_classes (c, iso_classes)
|
|
1853 int c;
|
|
1854 Lisp_Object iso_classes;
|
|
1855 {
|
|
1856 int fits_class = 0;
|
|
1857
|
|
1858 while (! NILP (iso_classes))
|
|
1859 {
|
|
1860 Lisp_Object elt;
|
|
1861 elt = XCAR (iso_classes);
|
|
1862 iso_classes = XCDR (iso_classes);
|
|
1863
|
|
1864 if (re_iswctype (c, XFASTINT (elt)))
|
|
1865 fits_class = 1;
|
|
1866 }
|
|
1867
|
|
1868 return fits_class;
|
|
1869 }
|
17464
|
1870
|
25445
|
1871 /* Jump over a comment, assuming we are at the beginning of one.
|
|
1872 FROM is the current position.
|
|
1873 FROM_BYTE is the bytepos corresponding to FROM.
|
|
1874 Do not move past STOP (a charpos).
|
|
1875 The comment over which we have to jump is of style STYLE
|
|
1876 (either SYNTAX_COMMENT_STYLE(foo) or ST_COMMENT_STYLE).
|
|
1877 NESTING should be positive to indicate the nesting at the beginning
|
|
1878 for nested comments and should be zero or negative else.
|
|
1879 ST_COMMENT_STYLE cannot be nested.
|
|
1880 PREV_SYNTAX is the SYNTAX_WITH_FLAGS of the previous character
|
|
1881 (or 0 If the search cannot start in the middle of a two-character).
|
|
1882
|
|
1883 If successful, return 1 and store the charpos of the comment's end
|
|
1884 into *CHARPOS_PTR and the corresponding bytepos into *BYTEPOS_PTR.
|
|
1885 Else, return 0 and store the charpos STOP into *CHARPOS_PTR, the
|
|
1886 corresponding bytepos into *BYTEPOS_PTR and the current nesting
|
|
1887 (as defined for state.incomment) in *INCOMMENT_PTR.
|
|
1888
|
|
1889 The comment end is the last character of the comment rather than the
|
|
1890 character just after the comment.
|
|
1891
|
|
1892 Global syntax data is assumed to initially be valid for FROM and
|
|
1893 remains valid for forward search starting at the returned position. */
|
|
1894
|
|
1895 static int
|
|
1896 forw_comment (from, from_byte, stop, nesting, style, prev_syntax,
|
|
1897 charpos_ptr, bytepos_ptr, incomment_ptr)
|
71787
7e302766894f
(forw_comment): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1898 EMACS_INT from, from_byte, stop;
|
25445
|
1899 int nesting, style, prev_syntax;
|
71787
7e302766894f
(forw_comment): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1900 EMACS_INT *charpos_ptr, *bytepos_ptr;
|
7e302766894f
(forw_comment): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1901 int *incomment_ptr;
|
25445
|
1902 {
|
|
1903 register int c, c1;
|
|
1904 register enum syntaxcode code;
|
|
1905 register int syntax;
|
|
1906
|
|
1907 if (nesting <= 0) nesting = -1;
|
|
1908
|
|
1909 /* Enter the loop in the middle so that we find
|
|
1910 a 2-char comment ender if we start in the middle of it. */
|
|
1911 syntax = prev_syntax;
|
|
1912 if (syntax != 0) goto forw_incomment;
|
|
1913
|
|
1914 while (1)
|
|
1915 {
|
|
1916 if (from == stop)
|
|
1917 {
|
|
1918 *incomment_ptr = nesting;
|
|
1919 *charpos_ptr = from;
|
|
1920 *bytepos_ptr = from_byte;
|
|
1921 return 0;
|
|
1922 }
|
|
1923 c = FETCH_CHAR (from_byte);
|
|
1924 syntax = SYNTAX_WITH_FLAGS (c);
|
|
1925 code = syntax & 0xff;
|
|
1926 if (code == Sendcomment
|
|
1927 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
|
32086
|
1928 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
|
|
1929 (nesting > 0 && --nesting == 0) : nesting < 0))
|
25445
|
1930 /* we have encountered a comment end of the same style
|
|
1931 as the comment sequence which began this comment
|
|
1932 section */
|
|
1933 break;
|
|
1934 if (code == Scomment_fence
|
|
1935 && style == ST_COMMENT_STYLE)
|
|
1936 /* we have encountered a comment end of the same style
|
|
1937 as the comment sequence which began this comment
|
|
1938 section. */
|
|
1939 break;
|
|
1940 if (nesting > 0
|
|
1941 && code == Scomment
|
32086
|
1942 && SYNTAX_FLAGS_COMMENT_NESTED (syntax)
|
25445
|
1943 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style)
|
|
1944 /* we have encountered a nested comment of the same style
|
|
1945 as the comment sequence which began this comment section */
|
|
1946 nesting++;
|
|
1947 INC_BOTH (from, from_byte);
|
|
1948 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
47942
|
1949
|
25445
|
1950 forw_incomment:
|
|
1951 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax)
|
|
1952 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style
|
|
1953 && (c1 = FETCH_CHAR (from_byte),
|
32086
|
1954 SYNTAX_COMEND_SECOND (c1))
|
|
1955 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
|
|
1956 SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0))
|
25771
|
1957 {
|
|
1958 if (--nesting <= 0)
|
|
1959 /* we have encountered a comment end of the same style
|
|
1960 as the comment sequence which began this comment
|
|
1961 section */
|
|
1962 break;
|
|
1963 else
|
|
1964 {
|
|
1965 INC_BOTH (from, from_byte);
|
|
1966 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
|
1967 }
|
|
1968 }
|
25445
|
1969 if (nesting > 0
|
|
1970 && from < stop
|
|
1971 && SYNTAX_FLAGS_COMSTART_FIRST (syntax)
|
|
1972 && (c1 = FETCH_CHAR (from_byte),
|
|
1973 SYNTAX_COMMENT_STYLE (c1) == style
|
32086
|
1974 && SYNTAX_COMSTART_SECOND (c1))
|
|
1975 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ||
|
|
1976 SYNTAX_COMMENT_NESTED (c1)))
|
25445
|
1977 /* we have encountered a nested comment of the same style
|
|
1978 as the comment sequence which began this comment
|
|
1979 section */
|
|
1980 {
|
|
1981 INC_BOTH (from, from_byte);
|
|
1982 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
|
1983 nesting++;
|
|
1984 }
|
|
1985 }
|
|
1986 *charpos_ptr = from;
|
|
1987 *bytepos_ptr = from_byte;
|
|
1988 return 1;
|
|
1989 }
|
|
1990
|
1998
|
1991 DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0,
|
49600
|
1992 doc: /*
|
48089
|
1993 Move forward across up to COUNT comments. If COUNT is negative, move backward.
|
40103
|
1994 Stop scanning if we find something other than a comment or whitespace.
|
|
1995 Set point to where scanning stops.
|
48089
|
1996 If COUNT comments are found as expected, with nothing except whitespace
|
40103
|
1997 between them, return t; otherwise return nil. */)
|
|
1998 (count)
|
3095
|
1999 Lisp_Object count;
|
1998
|
2000 {
|
71739
|
2001 register EMACS_INT from;
|
|
2002 EMACS_INT from_byte;
|
|
2003 register EMACS_INT stop;
|
13144
|
2004 register int c, c1;
|
1998
|
2005 register enum syntaxcode code;
|
|
2006 int comstyle = 0; /* style of comment encountered */
|
25445
|
2007 int comnested = 0; /* whether the comment is nestable or not */
|
3087
|
2008 int found;
|
71739
|
2009 EMACS_INT count1;
|
|
2010 EMACS_INT out_charpos, out_bytepos;
|
25445
|
2011 int dummy;
|
3095
|
2012
|
40656
|
2013 CHECK_NUMBER (count);
|
3095
|
2014 count1 = XINT (count);
|
17464
|
2015 stop = count1 > 0 ? ZV : BEGV;
|
1998
|
2016
|
|
2017 immediate_quit = 1;
|
|
2018 QUIT;
|
|
2019
|
|
2020 from = PT;
|
20546
|
2021 from_byte = PT_BYTE;
|
1998
|
2022
|
17464
|
2023 SETUP_SYNTAX_TABLE (from, count1);
|
3095
|
2024 while (count1 > 0)
|
1998
|
2025 {
|
6142
|
2026 do
|
1998
|
2027 {
|
22370
|
2028 int comstart_first;
|
|
2029
|
6142
|
2030 if (from == stop)
|
|
2031 {
|
20905
|
2032 SET_PT_BOTH (from, from_byte);
|
10947
|
2033 immediate_quit = 0;
|
6142
|
2034 return Qnil;
|
|
2035 }
|
20546
|
2036 c = FETCH_CHAR (from_byte);
|
1998
|
2037 code = SYNTAX (c);
|
22370
|
2038 comstart_first = SYNTAX_COMSTART_FIRST (c);
|
25445
|
2039 comnested = SYNTAX_COMMENT_NESTED (c);
|
29821
|
2040 comstyle = SYNTAX_COMMENT_STYLE (c);
|
20546
|
2041 INC_BOTH (from, from_byte);
|
22370
|
2042 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
|
2043 if (from < stop && comstart_first
|
20546
|
2044 && (c1 = FETCH_CHAR (from_byte),
|
13144
|
2045 SYNTAX_COMSTART_SECOND (c1)))
|
1998
|
2046 {
|
47942
|
2047 /* We have encountered a comment start sequence and we
|
4953
|
2048 are ignoring all text inside comments. We must record
|
1998
|
2049 the comment style this sequence begins so that later,
|
|
2050 only a comment end of the same style actually ends
|
4953
|
2051 the comment section. */
|
1998
|
2052 code = Scomment;
|
13144
|
2053 comstyle = SYNTAX_COMMENT_STYLE (c1);
|
25445
|
2054 comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
|
20546
|
2055 INC_BOTH (from, from_byte);
|
25445
|
2056 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
1998
|
2057 }
|
6142
|
2058 }
|
32086
|
2059 while (code == Swhitespace || (code == Sendcomment && c == '\n'));
|
20546
|
2060
|
25290
|
2061 if (code == Scomment_fence)
|
|
2062 comstyle = ST_COMMENT_STYLE;
|
|
2063 else if (code != Scomment)
|
6142
|
2064 {
|
|
2065 immediate_quit = 0;
|
20546
|
2066 DEC_BOTH (from, from_byte);
|
20905
|
2067 SET_PT_BOTH (from, from_byte);
|
6142
|
2068 return Qnil;
|
|
2069 }
|
|
2070 /* We're at the start of a comment. */
|
25445
|
2071 found = forw_comment (from, from_byte, stop, comnested, comstyle, 0,
|
|
2072 &out_charpos, &out_bytepos, &dummy);
|
|
2073 from = out_charpos; from_byte = out_bytepos;
|
|
2074 if (!found)
|
6142
|
2075 {
|
25445
|
2076 immediate_quit = 0;
|
|
2077 SET_PT_BOTH (from, from_byte);
|
|
2078 return Qnil;
|
1998
|
2079 }
|
25445
|
2080 INC_BOTH (from, from_byte);
|
|
2081 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
6142
|
2082 /* We have skipped one comment. */
|
3095
|
2083 count1--;
|
1998
|
2084 }
|
|
2085
|
3095
|
2086 while (count1 < 0)
|
1998
|
2087 {
|
18938
444939f3c18f
(Fforward_comment): When count1 is negative, return nil if FROM reaches STOP.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2088 while (1)
|
1998
|
2089 {
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2090 int quoted;
|
22370
|
2091
|
18938
444939f3c18f
(Fforward_comment): When count1 is negative, return nil if FROM reaches STOP.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2092 if (from <= stop)
|
444939f3c18f
(Fforward_comment): When count1 is negative, return nil if FROM reaches STOP.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2093 {
|
20546
|
2094 SET_PT_BOTH (BEGV, BEGV_BYTE);
|
18938
444939f3c18f
(Fforward_comment): When count1 is negative, return nil if FROM reaches STOP.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2095 immediate_quit = 0;
|
444939f3c18f
(Fforward_comment): When count1 is negative, return nil if FROM reaches STOP.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2096 return Qnil;
|
444939f3c18f
(Fforward_comment): When count1 is negative, return nil if FROM reaches STOP.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2097 }
|
1998
|
2098
|
20546
|
2099 DEC_BOTH (from, from_byte);
|
22370
|
2100 /* char_quoted does UPDATE_SYNTAX_TABLE_BACKWARD (from). */
|
20546
|
2101 quoted = char_quoted (from, from_byte);
|
|
2102 c = FETCH_CHAR (from_byte);
|
1998
|
2103 code = SYNTAX (c);
|
|
2104 comstyle = 0;
|
25445
|
2105 comnested = SYNTAX_COMMENT_NESTED (c);
|
4953
|
2106 if (code == Sendcomment)
|
|
2107 comstyle = SYNTAX_COMMENT_STYLE (c);
|
1998
|
2108 if (from > stop && SYNTAX_COMEND_SECOND (c)
|
22370
|
2109 && prev_char_comend_first (from, from_byte)
|
22432
ac339ec4a12a
(Fforward_comment): Properly compute BYTEPOS arg to char_quoted.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2110 && !char_quoted (from - 1, dec_bytepos (from_byte)))
|
1998
|
2111 {
|
4953
|
2112 /* We must record the comment style encountered so that
|
1998
|
2113 later, we can match only the proper comment begin
|
4953
|
2114 sequence of the same style. */
|
22370
|
2115 DEC_BOTH (from, from_byte);
|
1998
|
2116 code = Sendcomment;
|
22370
|
2117 /* Calling char_quoted, above, set up global syntax position
|
|
2118 at the new value of FROM. */
|
25445
|
2119 c1 = FETCH_CHAR (from_byte);
|
|
2120 comstyle = SYNTAX_COMMENT_STYLE (c1);
|
|
2121 comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
|
1998
|
2122 }
|
|
2123
|
17464
|
2124 if (code == Scomment_fence)
|
|
2125 {
|
|
2126 /* Skip until first preceding unquoted comment_fence. */
|
20546
|
2127 int found = 0, ini = from, ini_byte = from_byte;
|
47942
|
2128
|
20546
|
2129 while (1)
|
17464
|
2130 {
|
20546
|
2131 DEC_BOTH (from, from_byte);
|
17464
|
2132 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
20546
|
2133 c = FETCH_CHAR (from_byte);
|
|
2134 if (SYNTAX (c) == Scomment_fence
|
47942
|
2135 && !char_quoted (from, from_byte))
|
17464
|
2136 {
|
47942
|
2137 found = 1;
|
17464
|
2138 break;
|
|
2139 }
|
70317
48f9beb0cfdc
(Fforward_comment): Detect generic comment at beginning of
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2140 else if (from == stop)
|
48f9beb0cfdc
(Fforward_comment): Detect generic comment at beginning of
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2141 break;
|
17464
|
2142 }
|
|
2143 if (found == 0)
|
|
2144 {
|
|
2145 from = ini; /* Set point to ini + 1. */
|
20546
|
2146 from_byte = ini_byte;
|
17464
|
2147 goto leave;
|
|
2148 }
|
70291
e4dbfbc6b5c6
(Fforward_comment): Don't forget to break out of the loop
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2149 else
|
e4dbfbc6b5c6
(Fforward_comment): Don't forget to break out of the loop
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2150 /* We have skipped one comment. */
|
e4dbfbc6b5c6
(Fforward_comment): Don't forget to break out of the loop
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2151 break;
|
17464
|
2152 }
|
|
2153 else if (code == Sendcomment)
|
1998
|
2154 {
|
25445
|
2155 found = back_comment (from, from_byte, stop, comnested, comstyle,
|
20546
|
2156 &out_charpos, &out_bytepos);
|
27698
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2157 if (found == -1)
|
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2158 {
|
32086
|
2159 if (c == '\n')
|
|
2160 /* This end-of-line is not an end-of-comment.
|
|
2161 Treat it like a whitespace.
|
|
2162 CC-mode (and maybe others) relies on this behavior. */
|
|
2163 ;
|
|
2164 else
|
|
2165 {
|
|
2166 /* Failure: we should go back to the end of this
|
|
2167 not-quite-endcomment. */
|
|
2168 if (SYNTAX(c) != code)
|
|
2169 /* It was a two-char Sendcomment. */
|
|
2170 INC_BOTH (from, from_byte);
|
|
2171 goto leave;
|
|
2172 }
|
27698
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2173 }
|
27719
73926d5a4d9f
(Fforward_comment): Undo the previous change, since cc-mode
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2174 else
|
32086
|
2175 {
|
|
2176 /* We have skipped one comment. */
|
|
2177 from = out_charpos, from_byte = out_bytepos;
|
|
2178 break;
|
|
2179 }
|
1998
|
2180 }
|
39796
|
2181 else if (code != Swhitespace || quoted)
|
1998
|
2182 {
|
17464
|
2183 leave:
|
1998
|
2184 immediate_quit = 0;
|
20546
|
2185 INC_BOTH (from, from_byte);
|
20905
|
2186 SET_PT_BOTH (from, from_byte);
|
1998
|
2187 return Qnil;
|
|
2188 }
|
|
2189 }
|
|
2190
|
3095
|
2191 count1++;
|
1998
|
2192 }
|
|
2193
|
20905
|
2194 SET_PT_BOTH (from, from_byte);
|
1998
|
2195 immediate_quit = 0;
|
|
2196 return Qt;
|
|
2197 }
|
|
2198
|
27812
|
2199 /* Return syntax code of character C if C is a single byte character
|
38047
|
2200 or `multibyte_symbol_p' is zero. Otherwise, return Ssymbol. */
|
27812
|
2201
|
|
2202 #define SYNTAX_WITH_MULTIBYTE_CHECK(c) \
|
|
2203 ((SINGLE_BYTE_CHAR_P (c) || !multibyte_symbol_p) \
|
|
2204 ? SYNTAX (c) : Ssymbol)
|
|
2205
|
20546
|
2206 static Lisp_Object
|
163
|
2207 scan_lists (from, count, depth, sexpflag)
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2208 register EMACS_INT from;
|
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2209 EMACS_INT count, depth;
|
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2210 int sexpflag;
|
163
|
2211 {
|
|
2212 Lisp_Object val;
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2213 register EMACS_INT stop = count > 0 ? ZV : BEGV;
|
17044
|
2214 register int c, c1;
|
|
2215 int stringterm;
|
163
|
2216 int quoted;
|
|
2217 int mathexit = 0;
|
17044
|
2218 register enum syntaxcode code, temp_code;
|
17464
|
2219 int min_depth = depth; /* Err out if depth gets less than this. */
|
1085
|
2220 int comstyle = 0; /* style of comment encountered */
|
25445
|
2221 int comnested = 0; /* whether the comment is nestable or not */
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2222 EMACS_INT temp_pos;
|
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2223 EMACS_INT last_good = from;
|
17464
|
2224 int found;
|
71740
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2225 EMACS_INT from_byte;
|
df55df8eb062
(back_comment, scan_lists): Also use EMACS_INT for buffer positions.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2226 EMACS_INT out_bytepos, out_charpos;
|
25445
|
2227 int temp, dummy;
|
27812
|
2228 int multibyte_symbol_p = sexpflag && multibyte_syntax_as_symbol;
|
163
|
2229
|
|
2230 if (depth > 0) min_depth = 0;
|
|
2231
|
23404
|
2232 if (from > ZV) from = ZV;
|
|
2233 if (from < BEGV) from = BEGV;
|
|
2234
|
|
2235 from_byte = CHAR_TO_BYTE (from);
|
|
2236
|
163
|
2237 immediate_quit = 1;
|
|
2238 QUIT;
|
|
2239
|
17464
|
2240 SETUP_SYNTAX_TABLE (from, count);
|
163
|
2241 while (count > 0)
|
|
2242 {
|
|
2243 while (from < stop)
|
|
2244 {
|
22370
|
2245 int comstart_first, prefix;
|
17464
|
2246 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
20546
|
2247 c = FETCH_CHAR (from_byte);
|
27812
|
2248 code = SYNTAX_WITH_MULTIBYTE_CHECK (c);
|
22370
|
2249 comstart_first = SYNTAX_COMSTART_FIRST (c);
|
25445
|
2250 comnested = SYNTAX_COMMENT_NESTED (c);
|
29821
|
2251 comstyle = SYNTAX_COMMENT_STYLE (c);
|
22370
|
2252 prefix = SYNTAX_PREFIX (c);
|
16992
|
2253 if (depth == min_depth)
|
|
2254 last_good = from;
|
20546
|
2255 INC_BOTH (from, from_byte);
|
17464
|
2256 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
22370
|
2257 if (from < stop && comstart_first
|
56067
|
2258 && (c = FETCH_CHAR (from_byte), SYNTAX_COMSTART_SECOND (c))
|
163
|
2259 && parse_sexp_ignore_comments)
|
1085
|
2260 {
|
47942
|
2261 /* we have encountered a comment start sequence and we
|
17464
|
2262 are ignoring all text inside comments. We must record
|
1085
|
2263 the comment style this sequence begins so that later,
|
|
2264 only a comment end of the same style actually ends
|
|
2265 the comment section */
|
|
2266 code = Scomment;
|
25445
|
2267 c1 = FETCH_CHAR (from_byte);
|
|
2268 comstyle = SYNTAX_COMMENT_STYLE (c1);
|
|
2269 comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
|
20546
|
2270 INC_BOTH (from, from_byte);
|
22370
|
2271 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
1085
|
2272 }
|
47942
|
2273
|
22370
|
2274 if (prefix)
|
163
|
2275 continue;
|
|
2276
|
10457
2ab3bd0288a9
Change all occurences of SWITCH_ENUM_BUG to use SWITCH_ENUM_CAST instead.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2277 switch (SWITCH_ENUM_CAST (code))
|
163
|
2278 {
|
|
2279 case Sescape:
|
|
2280 case Scharquote:
|
|
2281 if (from == stop) goto lose;
|
20546
|
2282 INC_BOTH (from, from_byte);
|
163
|
2283 /* treat following character as a word constituent */
|
|
2284 case Sword:
|
|
2285 case Ssymbol:
|
|
2286 if (depth || !sexpflag) break;
|
17464
|
2287 /* This word counts as a sexp; return at end of it. */
|
163
|
2288 while (from < stop)
|
|
2289 {
|
17464
|
2290 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
22006
|
2291
|
|
2292 /* Some compilers can't handle this inside the switch. */
|
27812
|
2293 c = FETCH_CHAR (from_byte);
|
|
2294 temp = SYNTAX_WITH_MULTIBYTE_CHECK (c);
|
22006
|
2295 switch (temp)
|
163
|
2296 {
|
|
2297 case Scharquote:
|
|
2298 case Sescape:
|
20546
|
2299 INC_BOTH (from, from_byte);
|
163
|
2300 if (from == stop) goto lose;
|
|
2301 break;
|
|
2302 case Sword:
|
|
2303 case Ssymbol:
|
|
2304 case Squote:
|
|
2305 break;
|
|
2306 default:
|
|
2307 goto done;
|
|
2308 }
|
20546
|
2309 INC_BOTH (from, from_byte);
|
163
|
2310 }
|
|
2311 goto done;
|
|
2312
|
25445
|
2313 case Scomment_fence:
|
|
2314 comstyle = ST_COMMENT_STYLE;
|
|
2315 /* FALLTHROUGH */
|
163
|
2316 case Scomment:
|
|
2317 if (!parse_sexp_ignore_comments) break;
|
25445
|
2318 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
|
2319 found = forw_comment (from, from_byte, stop,
|
|
2320 comnested, comstyle, 0,
|
|
2321 &out_charpos, &out_bytepos, &dummy);
|
|
2322 from = out_charpos, from_byte = out_bytepos;
|
|
2323 if (!found)
|
163
|
2324 {
|
25445
|
2325 if (depth == 0)
|
|
2326 goto done;
|
|
2327 goto lose;
|
163
|
2328 }
|
25445
|
2329 INC_BOTH (from, from_byte);
|
|
2330 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
163
|
2331 break;
|
|
2332
|
|
2333 case Smath:
|
|
2334 if (!sexpflag)
|
|
2335 break;
|
20546
|
2336 if (from != stop && c == FETCH_CHAR (from_byte))
|
|
2337 {
|
|
2338 INC_BOTH (from, from_byte);
|
|
2339 }
|
163
|
2340 if (mathexit)
|
|
2341 {
|
|
2342 mathexit = 0;
|
|
2343 goto close1;
|
|
2344 }
|
|
2345 mathexit = 1;
|
|
2346
|
|
2347 case Sopen:
|
|
2348 if (!++depth) goto done;
|
|
2349 break;
|
|
2350
|
|
2351 case Sclose:
|
|
2352 close1:
|
|
2353 if (!--depth) goto done;
|
|
2354 if (depth < min_depth)
|
71988
|
2355 xsignal3 (Qscan_error,
|
|
2356 build_string ("Containing expression ends prematurely"),
|
|
2357 make_number (last_good), make_number (from));
|
163
|
2358 break;
|
|
2359
|
|
2360 case Sstring:
|
17464
|
2361 case Sstring_fence:
|
20905
|
2362 temp_pos = dec_bytepos (from_byte);
|
17044
|
2363 stringterm = FETCH_CHAR (temp_pos);
|
163
|
2364 while (1)
|
|
2365 {
|
|
2366 if (from >= stop) goto lose;
|
17464
|
2367 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
27812
|
2368 c = FETCH_CHAR (from_byte);
|
34398
|
2369 if (code == Sstring
|
|
2370 ? (c == stringterm
|
|
2371 && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring)
|
27812
|
2372 : SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring_fence)
|
17464
|
2373 break;
|
22006
|
2374
|
|
2375 /* Some compilers can't handle this inside the switch. */
|
27812
|
2376 temp = SYNTAX_WITH_MULTIBYTE_CHECK (c);
|
22006
|
2377 switch (temp)
|
163
|
2378 {
|
|
2379 case Scharquote:
|
|
2380 case Sescape:
|
20546
|
2381 INC_BOTH (from, from_byte);
|
163
|
2382 }
|
20546
|
2383 INC_BOTH (from, from_byte);
|
163
|
2384 }
|
20546
|
2385 INC_BOTH (from, from_byte);
|
163
|
2386 if (!depth && sexpflag) goto done;
|
|
2387 break;
|
47872
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2388 default:
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2389 /* Ignore whitespace, punctuation, quote, endcomment. */
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2390 break;
|
163
|
2391 }
|
|
2392 }
|
|
2393
|
|
2394 /* Reached end of buffer. Error if within object, return nil if between */
|
|
2395 if (depth) goto lose;
|
|
2396
|
|
2397 immediate_quit = 0;
|
|
2398 return Qnil;
|
|
2399
|
|
2400 /* End of object reached */
|
|
2401 done:
|
|
2402 count--;
|
|
2403 }
|
|
2404
|
|
2405 while (count < 0)
|
|
2406 {
|
|
2407 while (from > stop)
|
|
2408 {
|
20546
|
2409 DEC_BOTH (from, from_byte);
|
17464
|
2410 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
20546
|
2411 c = FETCH_CHAR (from_byte);
|
27812
|
2412 code = SYNTAX_WITH_MULTIBYTE_CHECK (c);
|
16992
|
2413 if (depth == min_depth)
|
|
2414 last_good = from;
|
4953
|
2415 comstyle = 0;
|
25445
|
2416 comnested = SYNTAX_COMMENT_NESTED (c);
|
4953
|
2417 if (code == Sendcomment)
|
|
2418 comstyle = SYNTAX_COMMENT_STYLE (c);
|
163
|
2419 if (from > stop && SYNTAX_COMEND_SECOND (c)
|
22486
a28020246db1
(skip_chars): Don't examine STRING before verifying that it is a string.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2420 && prev_char_comend_first (from, from_byte)
|
163
|
2421 && parse_sexp_ignore_comments)
|
1085
|
2422 {
|
22370
|
2423 /* We must record the comment style encountered so that
|
1085
|
2424 later, we can match only the proper comment begin
|
22370
|
2425 sequence of the same style. */
|
|
2426 DEC_BOTH (from, from_byte);
|
|
2427 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
1085
|
2428 code = Sendcomment;
|
25445
|
2429 c1 = FETCH_CHAR (from_byte);
|
|
2430 comstyle = SYNTAX_COMMENT_STYLE (c1);
|
|
2431 comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
|
1085
|
2432 }
|
47942
|
2433
|
20674
|
2434 /* Quoting turns anything except a comment-ender
|
29821
|
2435 into a word character. Note that this cannot be true
|
22370
|
2436 if we decremented FROM in the if-statement above. */
|
20674
|
2437 if (code != Sendcomment && char_quoted (from, from_byte))
|
47872
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2438 {
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2439 DEC_BOTH (from, from_byte);
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2440 code = Sword;
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2441 }
|
20674
|
2442 else if (SYNTAX_PREFIX (c))
|
163
|
2443 continue;
|
|
2444
|
20674
|
2445 switch (SWITCH_ENUM_CAST (code))
|
163
|
2446 {
|
|
2447 case Sword:
|
|
2448 case Ssymbol:
|
20674
|
2449 case Sescape:
|
|
2450 case Scharquote:
|
163
|
2451 if (depth || !sexpflag) break;
|
17464
|
2452 /* This word counts as a sexp; count object finished
|
|
2453 after passing it. */
|
163
|
2454 while (from > stop)
|
|
2455 {
|
20546
|
2456 temp_pos = from_byte;
|
20905
|
2457 if (! NILP (current_buffer->enable_multibyte_characters))
|
|
2458 DEC_POS (temp_pos);
|
|
2459 else
|
|
2460 temp_pos--;
|
20546
|
2461 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1);
|
20674
|
2462 c1 = FETCH_CHAR (temp_pos);
|
27812
|
2463 temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1);
|
20674
|
2464 /* Don't allow comment-end to be quoted. */
|
|
2465 if (temp_code == Sendcomment)
|
|
2466 goto done2;
|
20546
|
2467 quoted = char_quoted (from - 1, temp_pos);
|
163
|
2468 if (quoted)
|
17044
|
2469 {
|
20546
|
2470 DEC_BOTH (from, from_byte);
|
20905
|
2471 temp_pos = dec_bytepos (temp_pos);
|
20546
|
2472 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1);
|
17044
|
2473 }
|
|
2474 c1 = FETCH_CHAR (temp_pos);
|
27812
|
2475 temp_code = SYNTAX_WITH_MULTIBYTE_CHECK (c1);
|
17044
|
2476 if (! (quoted || temp_code == Sword
|
|
2477 || temp_code == Ssymbol
|
|
2478 || temp_code == Squote))
|
163
|
2479 goto done2;
|
20546
|
2480 DEC_BOTH (from, from_byte);
|
163
|
2481 }
|
|
2482 goto done2;
|
|
2483
|
|
2484 case Smath:
|
|
2485 if (!sexpflag)
|
|
2486 break;
|
20905
|
2487 temp_pos = dec_bytepos (from_byte);
|
20546
|
2488 UPDATE_SYNTAX_TABLE_BACKWARD (from - 1);
|
17044
|
2489 if (from != stop && c == FETCH_CHAR (temp_pos))
|
20546
|
2490 DEC_BOTH (from, from_byte);
|
163
|
2491 if (mathexit)
|
|
2492 {
|
|
2493 mathexit = 0;
|
|
2494 goto open2;
|
|
2495 }
|
|
2496 mathexit = 1;
|
|
2497
|
|
2498 case Sclose:
|
|
2499 if (!++depth) goto done2;
|
|
2500 break;
|
|
2501
|
|
2502 case Sopen:
|
|
2503 open2:
|
|
2504 if (!--depth) goto done2;
|
|
2505 if (depth < min_depth)
|
71988
|
2506 xsignal3 (Qscan_error,
|
|
2507 build_string ("Containing expression ends prematurely"),
|
|
2508 make_number (last_good), make_number (from));
|
163
|
2509 break;
|
|
2510
|
|
2511 case Sendcomment:
|
|
2512 if (!parse_sexp_ignore_comments)
|
|
2513 break;
|
25445
|
2514 found = back_comment (from, from_byte, stop, comnested, comstyle,
|
20546
|
2515 &out_charpos, &out_bytepos);
|
27698
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2516 /* FIXME: if found == -1, then it really wasn't a comment-end.
|
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2517 For single-char Sendcomment, we can't do much about it apart
|
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2518 from skipping the char.
|
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2519 For 2-char endcomments, we could try again, taking both
|
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2520 chars as separate entities, but it's a lot of trouble
|
9c61956399b2
(back_comment): Make sure we only consider comment-starters
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2521 for very little gain, so we don't bother either. -sm */
|
20546
|
2522 if (found != -1)
|
|
2523 from = out_charpos, from_byte = out_bytepos;
|
163
|
2524 break;
|
|
2525
|
17464
|
2526 case Scomment_fence:
|
|
2527 case Sstring_fence:
|
|
2528 while (1)
|
|
2529 {
|
54849
|
2530 if (from == stop) goto lose;
|
20546
|
2531 DEC_BOTH (from, from_byte);
|
17464
|
2532 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
47942
|
2533 if (!char_quoted (from, from_byte)
|
27812
|
2534 && (c = FETCH_CHAR (from_byte),
|
|
2535 SYNTAX_WITH_MULTIBYTE_CHECK (c) == code))
|
17464
|
2536 break;
|
|
2537 }
|
|
2538 if (code == Sstring_fence && !depth && sexpflag) goto done2;
|
|
2539 break;
|
47942
|
2540
|
163
|
2541 case Sstring:
|
20546
|
2542 stringterm = FETCH_CHAR (from_byte);
|
163
|
2543 while (1)
|
|
2544 {
|
|
2545 if (from == stop) goto lose;
|
54849
|
2546 DEC_BOTH (from, from_byte);
|
|
2547 UPDATE_SYNTAX_TABLE_BACKWARD (from);
|
|
2548 if (!char_quoted (from, from_byte)
|
|
2549 && stringterm == (c = FETCH_CHAR (from_byte))
|
34398
|
2550 && SYNTAX_WITH_MULTIBYTE_CHECK (c) == Sstring)
|
163
|
2551 break;
|
|
2552 }
|
|
2553 if (!depth && sexpflag) goto done2;
|
|
2554 break;
|
47872
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2555 default:
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2556 /* Ignore whitespace, punctuation, quote, endcomment. */
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2557 break;
|
163
|
2558 }
|
|
2559 }
|
|
2560
|
|
2561 /* Reached start of buffer. Error if within object, return nil if between */
|
|
2562 if (depth) goto lose;
|
|
2563
|
|
2564 immediate_quit = 0;
|
|
2565 return Qnil;
|
|
2566
|
|
2567 done2:
|
|
2568 count++;
|
|
2569 }
|
|
2570
|
|
2571
|
|
2572 immediate_quit = 0;
|
9320
4be3f8f9f090
(Fcopy_syntax_table, Fmodify_syntax_entry, scan_lists, init_syntax_once):
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2573 XSETFASTINT (val, from);
|
163
|
2574 return val;
|
|
2575
|
|
2576 lose:
|
71988
|
2577 xsignal3 (Qscan_error,
|
|
2578 build_string ("Unbalanced parentheses"),
|
|
2579 make_number (last_good), make_number (from));
|
163
|
2580 }
|
|
2581
|
|
2582 DEFUN ("scan-lists", Fscan_lists, Sscan_lists, 3, 3, 0,
|
40103
|
2583 doc: /* Scan from character number FROM by COUNT lists.
|
|
2584 Returns the character number of the position thus found.
|
|
2585
|
|
2586 If DEPTH is nonzero, paren depth begins counting from that value,
|
|
2587 only places where the depth in parentheses becomes zero
|
|
2588 are candidates for stopping; COUNT such places are counted.
|
|
2589 Thus, a positive value for DEPTH means go out levels.
|
|
2590
|
|
2591 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
|
|
2592
|
|
2593 If the beginning or end of (the accessible part of) the buffer is reached
|
|
2594 and the depth is wrong, an error is signaled.
|
|
2595 If the depth is right but the count is not used up, nil is returned. */)
|
|
2596 (from, count, depth)
|
163
|
2597 Lisp_Object from, count, depth;
|
|
2598 {
|
40656
|
2599 CHECK_NUMBER (from);
|
|
2600 CHECK_NUMBER (count);
|
|
2601 CHECK_NUMBER (depth);
|
163
|
2602
|
|
2603 return scan_lists (XINT (from), XINT (count), XINT (depth), 0);
|
|
2604 }
|
|
2605
|
|
2606 DEFUN ("scan-sexps", Fscan_sexps, Sscan_sexps, 2, 2, 0,
|
40103
|
2607 doc: /* Scan from character number FROM by COUNT balanced expressions.
|
|
2608 If COUNT is negative, scan backwards.
|
|
2609 Returns the character number of the position thus found.
|
|
2610
|
|
2611 Comments are ignored if `parse-sexp-ignore-comments' is non-nil.
|
|
2612
|
|
2613 If the beginning or end of (the accessible part of) the buffer is reached
|
|
2614 in the middle of a parenthetical grouping, an error is signaled.
|
|
2615 If the beginning or end is reached between groupings
|
|
2616 but before count is used up, nil is returned. */)
|
|
2617 (from, count)
|
163
|
2618 Lisp_Object from, count;
|
|
2619 {
|
40656
|
2620 CHECK_NUMBER (from);
|
|
2621 CHECK_NUMBER (count);
|
163
|
2622
|
|
2623 return scan_lists (XINT (from), XINT (count), 0, 1);
|
|
2624 }
|
|
2625
|
|
2626 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, Sbackward_prefix_chars,
|
40103
|
2627 0, 0, 0,
|
|
2628 doc: /* Move point backward over any number of chars with prefix syntax.
|
|
2629 This includes chars with "quote" or "prefix" syntax (' or p). */)
|
|
2630 ()
|
163
|
2631 {
|
|
2632 int beg = BEGV;
|
20546
|
2633 int opoint = PT;
|
|
2634 int opoint_byte = PT_BYTE;
|
16039
|
2635 int pos = PT;
|
20546
|
2636 int pos_byte = PT_BYTE;
|
17044
|
2637 int c;
|
163
|
2638
|
47942
|
2639 if (pos <= beg)
|
17464
|
2640 {
|
22370
|
2641 SET_PT_BOTH (opoint, opoint_byte);
|
|
2642
|
|
2643 return Qnil;
|
17464
|
2644 }
|
20546
|
2645
|
22370
|
2646 SETUP_SYNTAX_TABLE (pos, -1);
|
|
2647
|
20546
|
2648 DEC_BOTH (pos, pos_byte);
|
17044
|
2649
|
21207
|
2650 while (!char_quoted (pos, pos_byte)
|
17464
|
2651 /* Previous statement updates syntax table. */
|
20546
|
2652 && ((c = FETCH_CHAR (pos_byte), SYNTAX (c) == Squote)
|
17044
|
2653 || SYNTAX_PREFIX (c)))
|
|
2654 {
|
21207
|
2655 opoint = pos;
|
|
2656 opoint_byte = pos_byte;
|
|
2657
|
|
2658 if (pos + 1 > beg)
|
|
2659 DEC_BOTH (pos, pos_byte);
|
17044
|
2660 }
|
163
|
2661
|
20546
|
2662 SET_PT_BOTH (opoint, opoint_byte);
|
163
|
2663
|
|
2664 return Qnil;
|
|
2665 }
|
|
2666
|
20546
|
2667 /* Parse forward from FROM / FROM_BYTE to END,
|
1085
|
2668 assuming that FROM has state OLDSTATE (nil means FROM is start of function),
|
|
2669 and return a description of the state of the parse at END.
|
3568
|
2670 If STOPBEFORE is nonzero, stop at the start of an atom.
|
20475
|
2671 If COMMENTSTOP is 1, stop at the start of a comment.
|
|
2672 If COMMENTSTOP is -1, stop at the start or end of a comment,
|
|
2673 after the beginning of a string, or after the end of a string. */
|
163
|
2674
|
3720
|
2675 static void
|
20546
|
2676 scan_sexps_forward (stateptr, from, from_byte, end, targetdepth,
|
3568
|
2677 stopbefore, oldstate, commentstop)
|
1085
|
2678 struct lisp_parse_state *stateptr;
|
163
|
2679 register int from;
|
48324
|
2680 int end, targetdepth, stopbefore, from_byte;
|
163
|
2681 Lisp_Object oldstate;
|
3568
|
2682 int commentstop;
|
163
|
2683 {
|
|
2684 struct lisp_parse_state state;
|
|
2685
|
|
2686 register enum syntaxcode code;
|
25445
|
2687 int c1;
|
|
2688 int comnested;
|
163
|
2689 struct level { int last, prev; };
|
|
2690 struct level levelstart[100];
|
|
2691 register struct level *curlevel = levelstart;
|
|
2692 struct level *endlevel = levelstart + 100;
|
|
2693 register int depth; /* Paren depth of current scanning location.
|
|
2694 level - levelstart equals this except
|
|
2695 when the depth becomes negative. */
|
|
2696 int mindepth; /* Lowest DEPTH value seen. */
|
|
2697 int start_quoted = 0; /* Nonzero means starting after a char quote */
|
|
2698 Lisp_Object tem;
|
17044
|
2699 int prev_from; /* Keep one character before FROM. */
|
20546
|
2700 int prev_from_byte;
|
21207
|
2701 int prev_from_syntax;
|
17464
|
2702 int boundary_stop = commentstop == -1;
|
|
2703 int nofence;
|
25445
|
2704 int found;
|
71867
|
2705 EMACS_INT out_bytepos, out_charpos;
|
22006
|
2706 int temp;
|
17044
|
2707
|
|
2708 prev_from = from;
|
20546
|
2709 prev_from_byte = from_byte;
|
|
2710 if (from != BEGV)
|
|
2711 DEC_BOTH (prev_from, prev_from_byte);
|
17044
|
2712
|
|
2713 /* Use this macro instead of `from++'. */
|
20546
|
2714 #define INC_FROM \
|
|
2715 do { prev_from = from; \
|
|
2716 prev_from_byte = from_byte; \
|
56067
|
2717 temp = FETCH_CHAR (prev_from_byte); \
|
|
2718 prev_from_syntax = SYNTAX_WITH_FLAGS (temp); \
|
20905
|
2719 INC_BOTH (from, from_byte); \
|
48266
|
2720 if (from < end) \
|
|
2721 UPDATE_SYNTAX_TABLE_FORWARD (from); \
|
20546
|
2722 } while (0)
|
163
|
2723
|
|
2724 immediate_quit = 1;
|
|
2725 QUIT;
|
|
2726
|
485
|
2727 if (NILP (oldstate))
|
163
|
2728 {
|
|
2729 depth = 0;
|
|
2730 state.instring = -1;
|
|
2731 state.incomment = 0;
|
17464
|
2732 state.comstyle = 0; /* comment style a by default. */
|
|
2733 state.comstr_start = -1; /* no comment/string seen. */
|
163
|
2734 }
|
|
2735 else
|
|
2736 {
|
|
2737 tem = Fcar (oldstate);
|
485
|
2738 if (!NILP (tem))
|
163
|
2739 depth = XINT (tem);
|
|
2740 else
|
|
2741 depth = 0;
|
|
2742
|
|
2743 oldstate = Fcdr (oldstate);
|
|
2744 oldstate = Fcdr (oldstate);
|
|
2745 oldstate = Fcdr (oldstate);
|
|
2746 tem = Fcar (oldstate);
|
17464
|
2747 /* Check whether we are inside string_fence-style string: */
|
47942
|
2748 state.instring = (!NILP (tem)
|
|
2749 ? (INTEGERP (tem) ? XINT (tem) : ST_STRING_STYLE)
|
26272
|
2750 : -1);
|
163
|
2751
|
|
2752 oldstate = Fcdr (oldstate);
|
|
2753 tem = Fcar (oldstate);
|
26272
|
2754 state.incomment = (!NILP (tem)
|
|
2755 ? (INTEGERP (tem) ? XINT (tem) : -1)
|
25445
|
2756 : 0);
|
163
|
2757
|
|
2758 oldstate = Fcdr (oldstate);
|
|
2759 tem = Fcar (oldstate);
|
485
|
2760 start_quoted = !NILP (tem);
|
1085
|
2761
|
25445
|
2762 /* if the eighth element of the list is nil, we are in comment
|
17464
|
2763 style a. If it is non-nil, we are in comment style b */
|
1085
|
2764 oldstate = Fcdr (oldstate);
|
|
2765 oldstate = Fcdr (oldstate);
|
|
2766 tem = Fcar (oldstate);
|
47942
|
2767 state.comstyle = NILP (tem) ? 0 : (EQ (tem, Qsyntax_table)
|
26272
|
2768 ? ST_COMMENT_STYLE : 1);
|
17464
|
2769
|
|
2770 oldstate = Fcdr (oldstate);
|
|
2771 tem = Fcar (oldstate);
|
|
2772 state.comstr_start = NILP (tem) ? -1 : XINT (tem) ;
|
22394
|
2773 oldstate = Fcdr (oldstate);
|
|
2774 tem = Fcar (oldstate);
|
|
2775 while (!NILP (tem)) /* >= second enclosing sexps. */
|
|
2776 {
|
|
2777 /* curlevel++->last ran into compiler bug on Apollo */
|
|
2778 curlevel->last = XINT (Fcar (tem));
|
|
2779 if (++curlevel == endlevel)
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2780 curlevel--; /* error ("Nesting too deep for parser"); */
|
22394
|
2781 curlevel->prev = -1;
|
|
2782 curlevel->last = -1;
|
|
2783 tem = Fcdr (tem);
|
|
2784 }
|
163
|
2785 }
|
|
2786 state.quoted = 0;
|
|
2787 mindepth = depth;
|
|
2788
|
|
2789 curlevel->prev = -1;
|
|
2790 curlevel->last = -1;
|
|
2791
|
22994
|
2792 SETUP_SYNTAX_TABLE (prev_from, 1);
|
56067
|
2793 temp = FETCH_CHAR (prev_from_byte);
|
|
2794 prev_from_syntax = SYNTAX_WITH_FLAGS (temp);
|
48266
|
2795 UPDATE_SYNTAX_TABLE_FORWARD (from);
|
22994
|
2796
|
17464
|
2797 /* Enter the loop at a place appropriate for initial state. */
|
163
|
2798
|
22994
|
2799 if (state.incomment)
|
|
2800 goto startincomment;
|
163
|
2801 if (state.instring >= 0)
|
|
2802 {
|
17464
|
2803 nofence = state.instring != ST_STRING_STYLE;
|
22994
|
2804 if (start_quoted)
|
|
2805 goto startquotedinstring;
|
163
|
2806 goto startinstring;
|
|
2807 }
|
22994
|
2808 else if (start_quoted)
|
|
2809 goto startquoted;
|
21207
|
2810
|
163
|
2811 while (from < end)
|
|
2812 {
|
17044
|
2813 INC_FROM;
|
21207
|
2814 code = prev_from_syntax & 0xff;
|
18491
|
2815
|
57756
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2816 if (from < end
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2817 && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2818 && (c1 = FETCH_CHAR (from_byte),
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2819 SYNTAX_COMSTART_SECOND (c1)))
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2820 /* Duplicate code to avoid a complex if-expression
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2821 which causes trouble for the SGI compiler. */
|
25445
|
2822 {
|
57756
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2823 /* Record the comment style we have entered so that only
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2824 the comment-end sequence of the same style actually
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2825 terminates the comment section. */
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2826 state.comstyle = SYNTAX_COMMENT_STYLE (c1);
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2827 comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax);
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2828 comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2829 state.incomment = comnested ? 1 : -1;
|
25445
|
2830 state.comstr_start = prev_from;
|
57756
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2831 INC_FROM;
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2832 code = Scomment;
|
25445
|
2833 }
|
18491
|
2834 else if (code == Scomment_fence)
|
1085
|
2835 {
|
|
2836 /* Record the comment style we have entered so that only
|
|
2837 the comment-end sequence of the same style actually
|
|
2838 terminates the comment section. */
|
25445
|
2839 state.comstyle = ST_COMMENT_STYLE;
|
|
2840 state.incomment = -1;
|
17464
|
2841 state.comstr_start = prev_from;
|
1085
|
2842 code = Scomment;
|
|
2843 }
|
57756
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2844 else if (code == Scomment)
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2845 {
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2846 state.comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax);
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2847 state.incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ?
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2848 1 : -1);
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2849 state.comstr_start = prev_from;
|
a8bc01ac68d0
(scan_sexps_forward): Prefer 2-char comment-starter over a 1-char one.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2850 }
|
1085
|
2851
|
21207
|
2852 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax))
|
163
|
2853 continue;
|
10457
2ab3bd0288a9
Change all occurences of SWITCH_ENUM_BUG to use SWITCH_ENUM_CAST instead.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2854 switch (SWITCH_ENUM_CAST (code))
|
163
|
2855 {
|
|
2856 case Sescape:
|
|
2857 case Scharquote:
|
|
2858 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
17044
|
2859 curlevel->last = prev_from;
|
163
|
2860 startquoted:
|
|
2861 if (from == end) goto endquoted;
|
17044
|
2862 INC_FROM;
|
163
|
2863 goto symstarted;
|
|
2864 /* treat following character as a word constituent */
|
|
2865 case Sword:
|
|
2866 case Ssymbol:
|
|
2867 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
17044
|
2868 curlevel->last = prev_from;
|
163
|
2869 symstarted:
|
|
2870 while (from < end)
|
|
2871 {
|
22006
|
2872 /* Some compilers can't handle this inside the switch. */
|
56067
|
2873 temp = FETCH_CHAR (from_byte);
|
|
2874 temp = SYNTAX (temp);
|
22006
|
2875 switch (temp)
|
163
|
2876 {
|
|
2877 case Scharquote:
|
|
2878 case Sescape:
|
17044
|
2879 INC_FROM;
|
163
|
2880 if (from == end) goto endquoted;
|
|
2881 break;
|
|
2882 case Sword:
|
|
2883 case Ssymbol:
|
|
2884 case Squote:
|
|
2885 break;
|
|
2886 default:
|
|
2887 goto symdone;
|
|
2888 }
|
17044
|
2889 INC_FROM;
|
163
|
2890 }
|
|
2891 symdone:
|
|
2892 curlevel->prev = curlevel->last;
|
|
2893 break;
|
|
2894
|
47872
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2895 case Scomment_fence: /* Can't happen because it's handled above. */
|
29823
|
2896 case Scomment:
|
|
2897 if (commentstop || boundary_stop) goto done;
|
9475
|
2898 startincomment:
|
29823
|
2899 /* The (from == BEGV) test was to enter the loop in the middle so
|
25445
|
2900 that we find a 2-char comment ender even if we start in the
|
29821
|
2901 middle of it. We don't want to do that if we're just at the
|
29823
|
2902 beginning of the comment (think of (*) ... (*)). */
|
25445
|
2903 found = forw_comment (from, from_byte, end,
|
|
2904 state.incomment, state.comstyle,
|
29821
|
2905 (from == BEGV || from < state.comstr_start + 3)
|
|
2906 ? 0 : prev_from_syntax,
|
25445
|
2907 &out_charpos, &out_bytepos, &state.incomment);
|
|
2908 from = out_charpos; from_byte = out_bytepos;
|
|
2909 /* Beware! prev_from and friends are invalid now.
|
|
2910 Luckily, the `done' doesn't use them and the INC_FROM
|
|
2911 sets them to a sane value without looking at them. */
|
|
2912 if (!found) goto done;
|
29823
|
2913 INC_FROM;
|
163
|
2914 state.incomment = 0;
|
1085
|
2915 state.comstyle = 0; /* reset the comment style */
|
17464
|
2916 if (boundary_stop) goto done;
|
163
|
2917 break;
|
|
2918
|
|
2919 case Sopen:
|
|
2920 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
|
2921 depth++;
|
|
2922 /* curlevel++->last ran into compiler bug on Apollo */
|
17044
|
2923 curlevel->last = prev_from;
|
163
|
2924 if (++curlevel == endlevel)
|
30156
f59021679260
(back_comment): Use one switch rather than a few `if's.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2925 curlevel--; /* error ("Nesting too deep for parser"); */
|
163
|
2926 curlevel->prev = -1;
|
|
2927 curlevel->last = -1;
|
12894
|
2928 if (targetdepth == depth) goto done;
|
163
|
2929 break;
|
|
2930
|
|
2931 case Sclose:
|
|
2932 depth--;
|
|
2933 if (depth < mindepth)
|
|
2934 mindepth = depth;
|
|
2935 if (curlevel != levelstart)
|
|
2936 curlevel--;
|
|
2937 curlevel->prev = curlevel->last;
|
12894
|
2938 if (targetdepth == depth) goto done;
|
163
|
2939 break;
|
|
2940
|
|
2941 case Sstring:
|
17464
|
2942 case Sstring_fence:
|
|
2943 state.comstr_start = from - 1;
|
163
|
2944 if (stopbefore) goto stop; /* this arg means stop at sexp start */
|
17044
|
2945 curlevel->last = prev_from;
|
47942
|
2946 state.instring = (code == Sstring
|
20546
|
2947 ? (FETCH_CHAR (prev_from_byte))
|
17464
|
2948 : ST_STRING_STYLE);
|
|
2949 if (boundary_stop) goto done;
|
163
|
2950 startinstring:
|
17464
|
2951 {
|
20475
|
2952 nofence = state.instring != ST_STRING_STYLE;
|
47942
|
2953
|
20475
|
2954 while (1)
|
|
2955 {
|
|
2956 int c;
|
17044
|
2957
|
20475
|
2958 if (from >= end) goto done;
|
20546
|
2959 c = FETCH_CHAR (from_byte);
|
22006
|
2960 /* Some compilers can't handle this inside the switch. */
|
|
2961 temp = SYNTAX (c);
|
24148
|
2962
|
|
2963 /* Check TEMP here so that if the char has
|
|
2964 a syntax-table property which says it is NOT
|
|
2965 a string character, it does not end the string. */
|
|
2966 if (nofence && c == state.instring && temp == Sstring)
|
|
2967 break;
|
|
2968
|
22006
|
2969 switch (temp)
|
20475
|
2970 {
|
|
2971 case Sstring_fence:
|
|
2972 if (!nofence) goto string_end;
|
|
2973 break;
|
|
2974 case Scharquote:
|
|
2975 case Sescape:
|
|
2976 INC_FROM;
|
|
2977 startquotedinstring:
|
|
2978 if (from >= end) goto endquoted;
|
17464
|
2979 }
|
20475
|
2980 INC_FROM;
|
|
2981 }
|
17464
|
2982 }
|
|
2983 string_end:
|
163
|
2984 state.instring = -1;
|
|
2985 curlevel->prev = curlevel->last;
|
17044
|
2986 INC_FROM;
|
17464
|
2987 if (boundary_stop) goto done;
|
163
|
2988 break;
|
|
2989
|
|
2990 case Smath:
|
47872
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2991 /* FIXME: We should do something with it. */
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2992 break;
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2993 default:
|
e5d59debb925
(scan_lists): Don't get fooled by a symbol ending with a backslash-quoted char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2994 /* Ignore whitespace, punctuation, quote, endcomment. */
|
163
|
2995 break;
|
|
2996 }
|
|
2997 }
|
|
2998 goto done;
|
|
2999
|
|
3000 stop: /* Here if stopping before start of sexp. */
|
17044
|
3001 from = prev_from; /* We have just fetched the char that starts it; */
|
163
|
3002 goto done; /* but return the position before it. */
|
|
3003
|
|
3004 endquoted:
|
|
3005 state.quoted = 1;
|
|
3006 done:
|
|
3007 state.depth = depth;
|
|
3008 state.mindepth = mindepth;
|
|
3009 state.thislevelstart = curlevel->prev;
|
|
3010 state.prevlevelstart
|
|
3011 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
|
|
3012 state.location = from;
|
22394
|
3013 state.levelstarts = Qnil;
|
|
3014 while (--curlevel >= levelstart)
|
|
3015 state.levelstarts = Fcons (make_number (curlevel->last),
|
|
3016 state.levelstarts);
|
163
|
3017 immediate_quit = 0;
|
|
3018
|
1085
|
3019 *stateptr = state;
|
163
|
3020 }
|
|
3021
|
3568
|
3022 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 6, 0,
|
40103
|
3023 doc: /* Parse Lisp syntax starting at FROM until TO; return status of parse at TO.
|
|
3024 Parsing stops at TO or when certain criteria are met;
|
|
3025 point is set to where parsing stops.
|
|
3026 If fifth arg OLDSTATE is omitted or nil,
|
|
3027 parsing assumes that FROM is the beginning of a function.
|
66525
|
3028 Value is a list of elements describing final state of parsing:
|
40103
|
3029 0. depth in parens.
|
|
3030 1. character address of start of innermost containing list; nil if none.
|
|
3031 2. character address of start of last complete sexp terminated.
|
|
3032 3. non-nil if inside a string.
|
|
3033 (it is the character that will terminate the string,
|
|
3034 or t if the string should be terminated by a generic string delimiter.)
|
47942
|
3035 4. nil if outside a comment, t if inside a non-nestable comment,
|
40103
|
3036 else an integer (the current comment nesting).
|
|
3037 5. t if following a quote character.
|
|
3038 6. the minimum paren-depth encountered during this scan.
|
|
3039 7. t if in a comment of style b; symbol `syntax-table' if the comment
|
|
3040 should be terminated by a generic comment delimiter.
|
|
3041 8. character address of start of comment or string; nil if not in one.
|
|
3042 9. Intermediate data for continuation of parsing (subject to change).
|
|
3043 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
|
|
3044 in parentheses becomes equal to TARGETDEPTH.
|
|
3045 Fourth arg STOPBEFORE non-nil means stop when come to
|
|
3046 any character that starts a sexp.
|
66525
|
3047 Fifth arg OLDSTATE is a list like what this function returns.
|
40103
|
3048 It is used to initialize the state of the parse. Elements number 1, 2, 6
|
|
3049 and 8 are ignored; you can leave off element 8 (the last) entirely.
|
|
3050 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
|
|
3051 If it is symbol `syntax-table', stop after the start of a comment or a
|
|
3052 string, or after end of a comment or a string. */)
|
|
3053 (from, to, targetdepth, stopbefore, oldstate, commentstop)
|
3568
|
3054 Lisp_Object from, to, targetdepth, stopbefore, oldstate, commentstop;
|
163
|
3055 {
|
|
3056 struct lisp_parse_state state;
|
|
3057 int target;
|
|
3058
|
485
|
3059 if (!NILP (targetdepth))
|
163
|
3060 {
|
40656
|
3061 CHECK_NUMBER (targetdepth);
|
163
|
3062 target = XINT (targetdepth);
|
|
3063 }
|
|
3064 else
|
|
3065 target = -100000; /* We won't reach this depth */
|
|
3066
|
|
3067 validate_region (&from, &to);
|
20546
|
3068 scan_sexps_forward (&state, XINT (from), CHAR_TO_BYTE (XINT (from)),
|
|
3069 XINT (to),
|
3568
|
3070 target, !NILP (stopbefore), oldstate,
|
47942
|
3071 (NILP (commentstop)
|
17464
|
3072 ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1)));
|
163
|
3073
|
|
3074 SET_PT (state.location);
|
47942
|
3075
|
163
|
3076 return Fcons (make_number (state.depth),
|
|
3077 Fcons (state.prevlevelstart < 0 ? Qnil : make_number (state.prevlevelstart),
|
|
3078 Fcons (state.thislevelstart < 0 ? Qnil : make_number (state.thislevelstart),
|
47942
|
3079 Fcons (state.instring >= 0
|
|
3080 ? (state.instring == ST_STRING_STYLE
|
17464
|
3081 ? Qt : make_number (state.instring)) : Qnil,
|
25445
|
3082 Fcons (state.incomment < 0 ? Qt :
|
|
3083 (state.incomment == 0 ? Qnil :
|
|
3084 make_number (state.incomment)),
|
163
|
3085 Fcons (state.quoted ? Qt : Qnil,
|
20486
|
3086 Fcons (make_number (state.mindepth),
|
47942
|
3087 Fcons ((state.comstyle
|
20486
|
3088 ? (state.comstyle == ST_COMMENT_STYLE
|
|
3089 ? Qsyntax_table : Qt) :
|
|
3090 Qnil),
|
24728
|
3091 Fcons (((state.incomment
|
|
3092 || (state.instring >= 0))
|
20486
|
3093 ? make_number (state.comstr_start)
|
|
3094 : Qnil),
|
22394
|
3095 Fcons (state.levelstarts, Qnil))))))))));
|
163
|
3096 }
|
|
3097
|
21514
|
3098 void
|
163
|
3099 init_syntax_once ()
|
|
3100 {
|
17126
|
3101 register int i, c;
|
13144
|
3102 Lisp_Object temp;
|
|
3103
|
13218
|
3104 /* This has to be done here, before we call Fmake_char_table. */
|
|
3105 Qsyntax_table = intern ("syntax-table");
|
|
3106 staticpro (&Qsyntax_table);
|
|
3107
|
|
3108 /* Intern this now in case it isn't already done.
|
|
3109 Setting this variable twice is harmless.
|
|
3110 But don't staticpro it here--that is done in alloc.c. */
|
|
3111 Qchar_table_extra_slots = intern ("char-table-extra-slots");
|
|
3112
|
17044
|
3113 /* Create objects which can be shared among syntax tables. */
|
34398
|
3114 Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil);
|
17044
|
3115 for (i = 0; i < XVECTOR (Vsyntax_code_object)->size; i++)
|
|
3116 XVECTOR (Vsyntax_code_object)->contents[i]
|
|
3117 = Fcons (make_number (i), Qnil);
|
|
3118
|
13218
|
3119 /* Now we are ready to set up this property, so we can
|
|
3120 create syntax tables. */
|
|
3121 Fput (Qsyntax_table, Qchar_table_extra_slots, make_number (0));
|
|
3122
|
17044
|
3123 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace];
|
13144
|
3124
|
13218
|
3125 Vstandard_syntax_table = Fmake_char_table (Qsyntax_table, temp);
|
163
|
3126
|
71395
|
3127 /* Control characters should not be whitespace. */
|
|
3128 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct];
|
|
3129 for (i = 0; i <= ' ' - 1; i++)
|
|
3130 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);
|
|
3131 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 0177, temp);
|
|
3132
|
|
3133 /* Except that a few really are whitespace. */
|
|
3134 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Swhitespace];
|
|
3135 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ' ', temp);
|
|
3136 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\t', temp);
|
|
3137 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\n', temp);
|
|
3138 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 015, temp);
|
|
3139 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, 014, temp);
|
|
3140
|
17044
|
3141 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword];
|
163
|
3142 for (i = 'a'; i <= 'z'; i++)
|
13144
|
3143 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);
|
163
|
3144 for (i = 'A'; i <= 'Z'; i++)
|
13144
|
3145 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);
|
163
|
3146 for (i = '0'; i <= '9'; i++)
|
13144
|
3147 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, i, temp);
|
|
3148
|
|
3149 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '$', temp);
|
|
3150 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '%', temp);
|
163
|
3151
|
13144
|
3152 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '(',
|
|
3153 Fcons (make_number (Sopen), make_number (')')));
|
|
3154 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ')',
|
|
3155 Fcons (make_number (Sclose), make_number ('(')));
|
|
3156 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '[',
|
|
3157 Fcons (make_number (Sopen), make_number (']')));
|
|
3158 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, ']',
|
|
3159 Fcons (make_number (Sclose), make_number ('[')));
|
|
3160 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '{',
|
|
3161 Fcons (make_number (Sopen), make_number ('}')));
|
|
3162 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '}',
|
|
3163 Fcons (make_number (Sclose), make_number ('{')));
|
|
3164 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '"',
|
|
3165 Fcons (make_number ((int) Sstring), Qnil));
|
|
3166 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, '\\',
|
|
3167 Fcons (make_number ((int) Sescape), Qnil));
|
163
|
3168
|
17044
|
3169 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Ssymbol];
|
163
|
3170 for (i = 0; i < 10; i++)
|
17126
|
3171 {
|
|
3172 c = "_-+*/&|<>="[i];
|
|
3173 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp);
|
|
3174 }
|
163
|
3175
|
17044
|
3176 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Spunct];
|
163
|
3177 for (i = 0; i < 12; i++)
|
17126
|
3178 {
|
|
3179 c = ".,;:?!#@~^'`"[i];
|
|
3180 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp);
|
|
3181 }
|
27812
|
3182
|
|
3183 /* All multibyte characters have syntax `word' by default. */
|
|
3184 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword];
|
|
3185 for (i = CHAR_TABLE_SINGLE_BYTE_SLOTS; i < CHAR_TABLE_ORDINARY_SLOTS; i++)
|
|
3186 XCHAR_TABLE (Vstandard_syntax_table)->contents[i] = temp;
|
163
|
3187 }
|
|
3188
|
21514
|
3189 void
|
163
|
3190 syms_of_syntax ()
|
|
3191 {
|
|
3192 Qsyntax_table_p = intern ("syntax-table-p");
|
|
3193 staticpro (&Qsyntax_table_p);
|
|
3194
|
17044
|
3195 staticpro (&Vsyntax_code_object);
|
|
3196
|
64319
|
3197 staticpro (&gl_state.object);
|
|
3198 staticpro (&gl_state.global_code);
|
|
3199 staticpro (&gl_state.current_syntax_table);
|
|
3200 staticpro (&gl_state.old_prop);
|
|
3201
|
|
3202 /* Defined in regex.c */
|
|
3203 staticpro (&re_match_object);
|
|
3204
|
16992
|
3205 Qscan_error = intern ("scan-error");
|
|
3206 staticpro (&Qscan_error);
|
|
3207 Fput (Qscan_error, Qerror_conditions,
|
23503
|
3208 Fcons (Qscan_error, Fcons (Qerror, Qnil)));
|
16992
|
3209 Fput (Qscan_error, Qerror_message,
|
|
3210 build_string ("Scan error"));
|
|
3211
|
163
|
3212 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments,
|
40103
|
3213 doc: /* Non-nil means `forward-sexp', etc., should treat comments as whitespace. */);
|
163
|
3214
|
17464
|
3215 DEFVAR_BOOL ("parse-sexp-lookup-properties", &parse_sexp_lookup_properties,
|
40103
|
3216 doc: /* Non-nil means `forward-sexp', etc., obey `syntax-table' property.
|
|
3217 Otherwise, that text property is simply ignored.
|
|
3218 See the info node `(elisp)Syntax Properties' for a description of the
|
|
3219 `syntax-table' property. */);
|
17464
|
3220
|
163
|
3221 words_include_escapes = 0;
|
|
3222 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes,
|
40103
|
3223 doc: /* Non-nil means `forward-word', etc., should treat escape chars part of words. */);
|
163
|
3224
|
27812
|
3225 DEFVAR_BOOL ("multibyte-syntax-as-symbol", &multibyte_syntax_as_symbol,
|
40103
|
3226 doc: /* Non-nil means `scan-sexps' treats all multibyte characters as symbol. */);
|
27812
|
3227 multibyte_syntax_as_symbol = 0;
|
|
3228
|
28302
|
3229 DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
|
|
3230 &open_paren_in_column_0_is_defun_start,
|
49551
|
3231 doc: /* *Non-nil means an open paren in column 0 denotes the start of a defun. */);
|
28302
|
3232 open_paren_in_column_0_is_defun_start = 1;
|
|
3233
|
163
|
3234 defsubr (&Ssyntax_table_p);
|
|
3235 defsubr (&Ssyntax_table);
|
|
3236 defsubr (&Sstandard_syntax_table);
|
|
3237 defsubr (&Scopy_syntax_table);
|
|
3238 defsubr (&Sset_syntax_table);
|
|
3239 defsubr (&Schar_syntax);
|
7968
|
3240 defsubr (&Smatching_paren);
|
32506
a85522b7799c
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
3241 defsubr (&Sstring_to_syntax);
|
163
|
3242 defsubr (&Smodify_syntax_entry);
|
40663
|
3243 defsubr (&Sinternal_describe_syntax_value);
|
163
|
3244
|
|
3245 defsubr (&Sforward_word);
|
|
3246
|
17464
|
3247 defsubr (&Sskip_chars_forward);
|
|
3248 defsubr (&Sskip_chars_backward);
|
|
3249 defsubr (&Sskip_syntax_forward);
|
|
3250 defsubr (&Sskip_syntax_backward);
|
|
3251
|
1998
|
3252 defsubr (&Sforward_comment);
|
163
|
3253 defsubr (&Sscan_lists);
|
|
3254 defsubr (&Sscan_sexps);
|
|
3255 defsubr (&Sbackward_prefix_chars);
|
|
3256 defsubr (&Sparse_partial_sexp);
|
|
3257 }
|
52401
|
3258
|
|
3259 /* arch-tag: 3e297b9f-088e-4b64-8f4c-fb0b3443e412
|
|
3260 (do not change this comment) */
|