Mercurial > hg > xemacs-beta
comparison src/syntax.c @ 826:6728e641994e
[xemacs-hg @ 2002-05-05 11:30:15 by ben]
syntax cache, 8-bit-format, lots of code cleanup
README.packages: Update info about --package-path.
i.c: Create an inheritable event and pass it on to XEmacs, so that ^C
can be handled properly. Intercept ^C and signal the event.
"Stop Build" in VC++ now works.
bytecomp-runtime.el: Doc string changes.
compat.el: Some attempts to redo this to
make it truly useful and fix the "multiple versions interacting
with each other" problem. Not yet done. Currently doesn't work.
files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code.
xemacs.mak: Split up CFLAGS into a version without flags specifying the C
library. The problem seems to be that minitar depends on zlib,
which depends specifically on libc.lib, not on any of the other C
libraries. Unless you compile with libc.lib, you get errors --
specifically, no _errno in the other libraries, which must make it
something other than an int. (#### But this doesn't seem to obtain
in XEmacs, which also uses zlib, and can be linked with any of the
C libraries. Maybe zlib is used differently and doesn't need
errno, or maybe XEmacs provides an int errno; ... I don't
understand.
Makefile.in.in: Fix so that packages are around when testing.
abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch.
-- FUNCTIONALITY CHANGES:
add partial support for 8-bit-fixed, 16-bit-fixed, and
32-bit-fixed formats. not quite done yet. (in particular, needs
functions to actually convert the buffer.) NOTE: lots of changes
to regex.c here. also, many new *_fmt() inline funs that take an
Internal_Format argument.
redo syntax cache code. make the cache per-buffer; keep the cache
valid across calls to functions that use it. also keep it valid
across insertions/deletions and extent changes, as much as is
possible. eliminate the junky regex-reentrancy code by passing in
the relevant lisp info to the regex routines as local vars.
add general mechanism in extents code for signalling extent changes.
fix numerous problems with the case-table implementation; yoshiki
never properly transferred many algorithms from old-style to
new-style case tables.
redo char tables to support a default argument, so that mapping
only occurs over changed args. change many chartab functions to
accept Lisp_Object instead of Lisp_Char_Table *.
comment out the code in font-lock.c by default, because
font-lock.el no longer uses it. we should consider eliminating it
entirely.
Don't output bell as ^G in console-stream when not a TTY.
add -mswindows-termination-handle to interface with i.c, so we can
properly kill a build.
add more error-checking to buffer/string macros.
add some additional buffer_or_string_() funs.
-- INTERFACE CHANGES AFFECTING MORE CODE:
switch the arguments of write_c_string and friends to be
consistent with write_fmt_string, which must have printcharfun
first.
change BI_* macros to BYTE_* for increased clarity; similarly for
bi_* local vars.
change VOID_TO_LISP to be a one-argument function. eliminate
no-longer-needed CVOID_TO_LISP.
-- char/string macro changes:
rename MAKE_CHAR() to make_emchar() for slightly less confusion
with make_char(). (The former generates an Emchar, the latter a
Lisp object. Conceivably we should rename make_char() -> wrap_char()
and similarly for make_int(), make_float().)
Similar changes for other *CHAR* macros -- we now consistently use
names with `emchar' whenever we are working with Emchars. Any
remaining name with just `char' always refers to a Lisp object.
rename macros with XSTRING_* to string_* except for those that
reference actual fields in the Lisp_String object, following
conventions used elsewhere.
rename set_string_{data,length} macros (the only ones to work with
a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_*
to make the difference clear.
try to be consistent about caps vs. lowercase in macro/inline-fun
names for chars and such, which wasn't the case before. we now
reserve caps either for XFOO_ macros that reference object fields
(e.g. XSTRING_DATA) or for things that have non-function semantics,
e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an
arg (any arg) more than once. otherwise, use lowercase.
here is a summary of most of the macros/inline funs changed by all
of the above changes:
BYTE_*_P -> byte_*_p
XSTRING_BYTE -> string_byte
set_string_data/length -> set_lispstringp_data/length
XSTRING_CHAR_LENGTH -> string_char_length
XSTRING_CHAR -> string_emchar
INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p
INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p
charptr_copy_char -> charptr_copy_emchar
LEADING_BYTE_* -> leading_byte_*
CHAR_* -> EMCHAR_*
*_CHAR_* -> *_EMCHAR_*
*_CHAR -> *_EMCHAR
CHARSET_BY_ -> charset_by_*
BYTE_SHIFT_JIS* -> byte_shift_jis*
BYTE_BIG5* -> byte_big5*
REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte
char_to_unicode -> emchar_to_unicode
valid_char_p -> valid_emchar_p
Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality).
-- INTERFACE CHANGES AFFECTING LESS CODE:
use DECLARE_INLINE_HEADER in various places.
remove '#ifdef emacs' from XEmacs-only files.
eliminate CHAR_TABLE_VALUE(), which duplicated the functionality
of get_char_table().
add BUFFER_TEXT_LOOP to simplify iterations over buffer text.
define typedefs for signed and unsigned types of fixed sizes
(INT_32_BIT, UINT_32_BIT, etc.).
create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE;
fix code to use it.
add charptr_emchar_len to return the text length of the character
pointed to by a ptr; use it in place of
charcount_to_bytecount(..., 1). add emchar_len to return the text
length of a given character.
add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount
and Charbpos/Charcount, in code (particularly, the extents code
and redisplay code) that works with either kind of index. rename
redisplay struct params with names such as `charbpos' to
e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos.
eliminate xxDEFUN in place of DEFUN; no longer necessary with
changes awhile back to doc.c.
split up big ugly combined list of EXFUNs in lisp.h on a
file-by-file basis, since other prototypes are similarly split.
rewrite some "*_UNSAFE" macros as inline funs and eliminate the
_UNSAFE suffix.
move most string code from lisp.h to text.h; the string code and
text.h code is now intertwined in such a fashion that they need
to be in the same place and partially interleaved. (you can't
create forward references for inline funs)
automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in
batch mode.
Fix up some problems in lisp-tests/symbol-tests that were
causing spurious failures.
author | ben |
---|---|
date | Sun, 05 May 2002 11:33:57 +0000 |
parents | 943eaba38521 |
children | 804517e16990 |
comparison
equal
deleted
inserted
replaced
825:eb3bc15a6e0f | 826:6728e641994e |
---|---|
1 /* XEmacs routines to deal with syntax tables; also word and list parsing. | 1 /* XEmacs routines to deal with syntax tables; also word and list parsing. |
2 Copyright (C) 1985-1994 Free Software Foundation, Inc. | 2 Copyright (C) 1985-1994 Free Software Foundation, Inc. |
3 Copyright (C) 1995 Sun Microsystems, Inc. | 3 Copyright (C) 1995 Sun Microsystems, Inc. |
4 Copyright (C) 2001 Ben Wing. | 4 Copyright (C) 2001, 2002 Ben Wing. |
5 | 5 |
6 This file is part of XEmacs. | 6 This file is part of XEmacs. |
7 | 7 |
8 XEmacs is free software; you can redistribute it and/or modify it | 8 XEmacs is free software; you can redistribute it and/or modify it |
9 under the terms of the GNU General Public License as published by the | 9 under the terms of the GNU General Public License as published by the |
76 | 76 |
77 /* Tell the regex routines not to QUIT. Normally there is a QUIT | 77 /* Tell the regex routines not to QUIT. Normally there is a QUIT |
78 each iteration in re_search_2(). */ | 78 each iteration in re_search_2(). */ |
79 int no_quit_in_re_search; | 79 int no_quit_in_re_search; |
80 | 80 |
81 /* Tell the regex routines which buffer to access for SYNTAX() lookups | 81 /* The standard syntax table is stored where it will automatically |
82 and the like. */ | 82 be used in all new buffers. */ |
83 struct buffer *regex_emacs_buffer; | |
84 | |
85 /* In Emacs, this is the string or buffer in which we | |
86 are matching. It is used for looking up syntax properties. */ | |
87 Lisp_Object regex_match_object; | |
88 | |
89 Lisp_Object Vstandard_syntax_table; | 83 Lisp_Object Vstandard_syntax_table; |
90 | 84 |
91 Lisp_Object Vsyntax_designator_chars_string; | 85 Lisp_Object Vsyntax_designator_chars_string; |
86 | |
87 Lisp_Object Vtemp_table_for_use_updating_syntax_tables; | |
88 | |
89 static void syntax_cache_table_was_changed (struct buffer *buf); | |
92 | 90 |
93 /* This is the internal form of the parse state used in parse-partial-sexp. */ | 91 /* This is the internal form of the parse state used in parse-partial-sexp. */ |
94 | 92 |
95 struct lisp_parse_state | 93 struct lisp_parse_state |
96 { | 94 { |
103 Charbpos thislevelstart;/* Char number of most recent start-of-expression | 101 Charbpos thislevelstart;/* Char number of most recent start-of-expression |
104 at current level */ | 102 at current level */ |
105 Charbpos prevlevelstart;/* Char number of start of containing expression */ | 103 Charbpos prevlevelstart;/* Char number of start of containing expression */ |
106 Charbpos location; /* Char number at which parsing stopped */ | 104 Charbpos location; /* Char number at which parsing stopped */ |
107 int mindepth; /* Minimum depth seen while scanning */ | 105 int mindepth; /* Minimum depth seen while scanning */ |
108 Charbpos comstr_start; /* Position just after last comment/string starter */ | 106 Charbpos comstr_start;/* Position just after last comment/string starter */ |
109 Lisp_Object levelstarts; /* Char numbers of starts-of-expression | 107 Lisp_Object levelstarts;/* Char numbers of starts-of-expression |
110 of levels (starting from outermost). */ | 108 of levels (starting from outermost). */ |
111 }; | 109 }; |
112 | 110 |
113 /* These variables are a cache for finding the start of a defun. | 111 /* These variables are a cache for finding the start of a defun. |
114 find_start_pos is the place for which the defun start was found. | 112 find_start_pos is the place for which the defun start was found. |
115 find_start_value is the defun start position found for it. | 113 find_start_value is the defun start position found for it. |
129 | 127 |
130 static Charbpos | 128 static Charbpos |
131 find_defun_start (struct buffer *buf, Charbpos pos) | 129 find_defun_start (struct buffer *buf, Charbpos pos) |
132 { | 130 { |
133 Charbpos tem; | 131 Charbpos tem; |
134 | 132 struct syntax_cache *scache; |
133 | |
135 /* Use previous finding, if it's valid and applies to this inquiry. */ | 134 /* Use previous finding, if it's valid and applies to this inquiry. */ |
136 if (buf == find_start_buffer | 135 if (buf == find_start_buffer |
137 /* Reuse the defun-start even if POS is a little farther on. | 136 /* Reuse the defun-start even if POS is a little farther on. |
138 POS might be in the next defun, but that's ok. | 137 POS might be in the next defun, but that's ok. |
139 Our value may not be the best possible, but will still be usable. */ | 138 Our value may not be the best possible, but will still be usable. */ |
144 return find_start_value; | 143 return find_start_value; |
145 | 144 |
146 /* Back up to start of line. */ | 145 /* Back up to start of line. */ |
147 tem = find_next_newline (buf, pos, -1); | 146 tem = find_next_newline (buf, pos, -1); |
148 | 147 |
149 SETUP_SYNTAX_CACHE (tem, 1); | 148 scache = setup_buffer_syntax_cache (buf, tem, 1); |
150 while (tem > BUF_BEGV (buf)) | 149 while (tem > BUF_BEGV (buf)) |
151 { | 150 { |
152 UPDATE_SYNTAX_CACHE_BACKWARD(tem); | 151 UPDATE_SYNTAX_CACHE_BACKWARD (scache, tem); |
153 | 152 |
154 /* Open-paren at start of line means we found our defun-start. */ | 153 /* Open-paren at start of line means we found our defun-start. */ |
155 if (SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, tem)) == Sopen) | 154 if (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, tem)) == Sopen) |
156 break; | 155 break; |
157 /* Move to beg of previous line. */ | 156 /* Move to beg of previous line. */ |
158 tem = find_next_newline (buf, tem, -2); | 157 tem = find_next_newline (buf, tem, -2); |
159 } | 158 } |
160 | 159 |
197 (buffer)) | 196 (buffer)) |
198 { | 197 { |
199 return decode_buffer (buffer, 0)->syntax_table; | 198 return decode_buffer (buffer, 0)->syntax_table; |
200 } | 199 } |
201 | 200 |
201 #ifdef DEBUG_XEMACS | |
202 | |
203 DEFUN ("mirror-syntax-table", Fmirror_syntax_table, 0, 1, 0, /* | |
204 Return the current mirror syntax table, for debugging purposes. | |
205 This is the one specified by the current buffer, or by BUFFER if it | |
206 is non-nil. | |
207 */ | |
208 (buffer)) | |
209 { | |
210 return decode_buffer (buffer, 0)->mirror_syntax_table; | |
211 } | |
212 | |
213 DEFUN ("syntax-cache-info", Fsyntax_cache_info, 0, 1, 0, /* | |
214 Return info about the syntax cache in BUFFER. | |
215 BUFFER defaults to the current buffer if nil. | |
216 */ | |
217 (buffer)) | |
218 { | |
219 struct buffer *buf = decode_buffer (buffer, 0); | |
220 struct syntax_cache *cache = buf->syntax_cache; | |
221 return list4 (cache->start, cache->end, make_int (cache->prev_change), | |
222 make_int (cache->next_change)); | |
223 } | |
224 | |
225 #endif /* DEBUG_XEMACS */ | |
226 | |
202 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /* | 227 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /* |
203 Return the standard syntax table. | 228 Return the standard syntax table. |
204 This is the one used for new buffers. | 229 This is the one used for new buffers. |
205 */ | 230 */ |
206 ()) | 231 ()) |
229 { | 254 { |
230 struct buffer *buf = decode_buffer (buffer, 0); | 255 struct buffer *buf = decode_buffer (buffer, 0); |
231 syntax_table = check_syntax_table (syntax_table, Qnil); | 256 syntax_table = check_syntax_table (syntax_table, Qnil); |
232 buf->syntax_table = syntax_table; | 257 buf->syntax_table = syntax_table; |
233 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table; | 258 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table; |
259 syntax_cache_table_was_changed (buf); | |
234 /* Indicate that this buffer now has a specified syntax table. */ | 260 /* Indicate that this buffer now has a specified syntax table. */ |
235 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table); | 261 buf->local_var_flags |= XINT (buffer_local_flags.syntax_table); |
236 return syntax_table; | 262 return syntax_table; |
237 } | 263 } |
238 | 264 |
239 /* The current syntax state */ | 265 |
240 struct syntax_cache syntax_cache; | 266 static void |
241 | 267 init_syntax_cache (struct syntax_cache *cache, Lisp_Object object, |
268 struct buffer *buffer, int infinite) | |
269 { | |
270 xzero (*cache); | |
271 cache->object = object; | |
272 cache->buffer = buffer; | |
273 cache->no_syntax_table_prop = 1; | |
274 cache->current_syntax_table = | |
275 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); | |
276 cache->start = Qnil; | |
277 cache->end = Qnil; | |
278 if (infinite) | |
279 { | |
280 cache->prev_change = EMACS_INT_MIN; | |
281 cache->next_change = EMACS_INT_MAX; | |
282 } | |
283 else | |
284 { | |
285 cache->prev_change = -1; | |
286 cache->next_change = -1; | |
287 } | |
288 } | |
289 | |
290 struct syntax_cache * | |
291 setup_syntax_cache (struct syntax_cache *cache, Lisp_Object object, | |
292 struct buffer *buffer, Charxpos from, int count) | |
293 { | |
294 if (BUFFERP (object)) | |
295 cache = XBUFFER (object)->syntax_cache; | |
296 if (!lookup_syntax_properties) | |
297 init_syntax_cache (cache, object, buffer, 1); | |
298 else if (!BUFFERP (object)) | |
299 init_syntax_cache (cache, object, buffer, 0); | |
300 if (lookup_syntax_properties) | |
301 { | |
302 if (count <= 0) | |
303 { | |
304 from--; | |
305 from = buffer_or_string_clip_to_accessible_byte (cache->object, | |
306 from); | |
307 } | |
308 if (!(from >= cache->prev_change && from < cache->next_change)) | |
309 update_syntax_cache (cache, from, count); | |
310 } | |
311 return cache; | |
312 } | |
313 | |
314 struct syntax_cache * | |
315 setup_buffer_syntax_cache (struct buffer *buffer, Charxpos from, int count) | |
316 { | |
317 return setup_syntax_cache (NULL, wrap_buffer (buffer), buffer, from, count); | |
318 } | |
319 | |
320 void | |
321 mark_buffer_syntax_cache (struct buffer *buf) | |
322 { | |
323 struct syntax_cache *cache = buf->syntax_cache; | |
324 if (!cache) /* Vbuffer_defaults and such don't have caches */ | |
325 return; | |
326 mark_object (cache->object); | |
327 if (cache->buffer) | |
328 mark_object (wrap_buffer (cache->buffer)); | |
329 mark_object (cache->current_syntax_table); | |
330 mark_object (cache->start); | |
331 mark_object (cache->end); | |
332 } | |
333 | |
334 static void | |
335 reset_buffer_cache_range (struct syntax_cache *cache, Lisp_Object buffer) | |
336 { | |
337 Fset_marker (cache->start, make_int (1), buffer); | |
338 Fset_marker (cache->end, make_int (1), buffer); | |
339 Fset_marker_insertion_type (cache->start, Qt); | |
340 Fset_marker_insertion_type (cache->end, Qnil); | |
341 cache->prev_change = -1; | |
342 cache->next_change = -1; | |
343 } | |
344 | |
345 void | |
346 init_buffer_syntax_cache (struct buffer *buf) | |
347 { | |
348 struct syntax_cache *cache; | |
349 buf->syntax_cache = xnew_and_zero (struct syntax_cache); | |
350 cache = buf->syntax_cache; | |
351 cache->object = wrap_buffer (buf); | |
352 cache->buffer = buf; | |
353 cache->no_syntax_table_prop = 1; | |
354 cache->current_syntax_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); | |
355 cache->start = Fmake_marker (); | |
356 cache->end = Fmake_marker (); | |
357 reset_buffer_cache_range (cache, cache->object); | |
358 } | |
359 | |
360 void | |
361 uninit_buffer_syntax_cache (struct buffer *buf) | |
362 { | |
363 xfree (buf->syntax_cache); | |
364 buf->syntax_cache = 0; | |
365 } | |
366 | |
367 | |
368 static void | |
369 syntax_cache_table_was_changed (struct buffer *buf) | |
370 { | |
371 struct syntax_cache *cache = buf->syntax_cache; | |
372 if (cache->no_syntax_table_prop) | |
373 cache->current_syntax_table = | |
374 BUFFER_MIRROR_SYNTAX_TABLE (buf); | |
375 } | |
376 | |
377 /* The syntax-table property on the range covered by EXTENT may be changing, | |
378 either because EXTENT has a syntax-table property and is being attached | |
379 or detached (this includes having its endpoints changed), or because | |
380 the value of EXTENT's syntax-table property is changing. */ | |
381 | |
382 void | |
383 signal_syntax_table_extent_changed (EXTENT extent) | |
384 { | |
385 Lisp_Object buffer = extent_object (extent); | |
386 if (BUFFERP (buffer)) | |
387 { | |
388 struct syntax_cache *cache = XBUFFER (buffer)->syntax_cache; | |
389 Bytexpos start = extent_endpoint_byte (extent, 0); | |
390 Bytexpos end = extent_endpoint_byte (extent, 1); | |
391 Bytexpos start2 = byte_marker_position (cache->start); | |
392 Bytexpos end2 = byte_marker_position (cache->end); | |
393 /* If the extent is entirely before or entirely after the cache range, | |
394 it doesn't overlap. Otherwise, invalidate the range. */ | |
395 if (!(end < start2 || start > end2)) | |
396 reset_buffer_cache_range (cache, buffer); | |
397 } | |
398 } | |
399 | |
400 /* Extents have been adjusted for insertion or deletion, so we need to | |
401 refetch the start and end position of the extent */ | |
402 void | |
403 signal_syntax_table_extent_adjust (struct buffer *buf) | |
404 { | |
405 struct syntax_cache *cache = buf->syntax_cache; | |
406 /* If the cache was invalid before, leave it that way. We only want | |
407 to update the limits of validity when they were actually valid. */ | |
408 if (cache->prev_change < 0) | |
409 return; | |
410 cache->prev_change = marker_position (cache->start); | |
411 cache->next_change = marker_position (cache->end); | |
412 } | |
242 | 413 |
243 /* | 414 /* |
244 Update syntax_cache to an appropriate setting for position POS | 415 Update syntax_cache to an appropriate setting for position POS |
245 | 416 |
246 The sign of COUNT gives the relative position of POS wrt the | 417 The sign of COUNT gives the relative position of POS wrt the |
253 return the "last smallest" extent at a given position. In cases | 424 return the "last smallest" extent at a given position. In cases |
254 where overlapping extents are defined, this code will simply use | 425 where overlapping extents are defined, this code will simply use |
255 whatever is returned by get-char-property. | 426 whatever is returned by get-char-property. |
256 | 427 |
257 It might be worth it at some point to merge provided syntax tables | 428 It might be worth it at some point to merge provided syntax tables |
258 outward to the current buffer. */ | 429 outward to the current buffer (#### rewrite in English please?!). */ |
259 | 430 |
260 void | 431 void |
261 update_syntax_cache (int pos, int count, int init) | 432 update_syntax_cache (struct syntax_cache *cache, Charxpos cpos, int count) |
262 { | 433 { |
263 Lisp_Object tmp_table; | 434 Lisp_Object tmp_table; |
264 | 435 Bytexpos pos; |
265 if (init) | 436 Bytexpos lim; |
266 { | 437 Bytexpos next, prev; |
267 syntax_cache.prev_change = -1; | 438 int at_begin = 0, at_end = 0; |
268 syntax_cache.next_change = -1; | 439 |
269 } | 440 if (NILP (cache->object)) |
270 | 441 return; |
271 if (pos > syntax_cache.prev_change && | 442 |
272 pos < syntax_cache.next_change) | 443 pos = buffer_or_string_charxpos_to_bytexpos (cache->object, cpos); |
273 { | 444 |
274 /* do nothing */ | 445 tmp_table = get_char_property (pos, Qsyntax_table, cache->object, |
446 EXTENT_AT_AFTER, 0); | |
447 lim = next_single_property_change (pos, Qsyntax_table, cache->object, | |
448 -1); | |
449 if (lim < 0) | |
450 { | |
451 next = buffer_or_string_absolute_end_byte (cache->object); | |
452 at_begin = 1; | |
275 } | 453 } |
276 else | 454 else |
277 { | 455 next = lim; |
278 if (NILP (syntax_cache.object) || EQ (syntax_cache.object, Qt)) | 456 |
279 { | 457 if (pos < buffer_or_string_absolute_end_byte (cache->object)) |
280 int get_change_before = pos + 1; | 458 pos = next_bytexpos (cache->object, pos); |
281 | 459 lim = previous_single_property_change (pos, Qsyntax_table, cache->object, |
282 tmp_table = Fget_char_property (make_int(pos), Qsyntax_table, | 460 -1); |
283 wrap_buffer (syntax_cache.buffer), Qnil); | 461 if (lim < 0) |
284 syntax_cache.next_change = | 462 { |
285 XINT (Fnext_extent_change (make_int (pos > 0 ? pos : 1), | 463 prev = buffer_or_string_absolute_begin_byte (cache->object); |
286 wrap_buffer (syntax_cache.buffer))); | 464 at_end = 1; |
287 | 465 } |
288 if (get_change_before < 1) | 466 else |
289 get_change_before = 1; | 467 prev = lim; |
290 else if (get_change_before > BUF_ZV (syntax_cache.buffer)) | 468 |
291 get_change_before = BUF_ZV (syntax_cache.buffer); | 469 cache->prev_change = |
292 | 470 buffer_or_string_bytexpos_to_charxpos (cache->object, prev); |
293 syntax_cache.prev_change = | 471 cache->next_change = |
294 XINT (Fprevious_extent_change (make_int (get_change_before), | 472 buffer_or_string_bytexpos_to_charxpos (cache->object, next); |
295 wrap_buffer (syntax_cache.buffer))); | 473 |
296 } | 474 if (BUFFERP (cache->object)) |
297 else | 475 { |
298 { | 476 /* If we are at the beginning or end of buffer, check to see if there's |
299 int get_change_before = pos + 1; | 477 a zero-length `syntax-table' extent there (highly unlikely); if not, |
300 | 478 then we can safely make the end closed, so it will take in newly |
301 tmp_table = Fget_char_property (make_int(pos), Qsyntax_table, | 479 inserted text. (If such an extent is inserted, we will be informed |
302 syntax_cache.object, Qnil); | 480 through signal_syntax_table_extent_changed().) */ |
303 syntax_cache.next_change = | 481 Fset_marker (cache->start, make_int (cache->prev_change), cache->object); |
304 XINT (Fnext_extent_change (make_int (pos >= 0 ? pos : 0), | 482 Fset_marker_insertion_type |
305 syntax_cache.object)); | 483 (cache->start, |
306 | 484 at_begin && NILP (extent_at (prev, cache->object, Qsyntax_table, |
307 if (get_change_before < 0) | 485 NULL, EXTENT_AT_AT, 0)) |
308 get_change_before = 0; | 486 ? Qnil : Qt); |
309 else if (get_change_before > XSTRING_LENGTH(syntax_cache.object)) | 487 Fset_marker (cache->end, make_int (cache->next_change), cache->object); |
310 get_change_before = XSTRING_LENGTH(syntax_cache.object); | 488 Fset_marker_insertion_type |
311 | 489 (cache->end, |
312 syntax_cache.prev_change = | 490 at_end && NILP (extent_at (next, cache->object, Qsyntax_table, |
313 XINT (Fprevious_extent_change (make_int (pos >= 0 ? pos : 0), | 491 NULL, EXTENT_AT_AT, 0)) |
314 syntax_cache.object)); | 492 ? Qt : Qnil); |
315 } | 493 } |
316 | 494 |
317 if (EQ (Fsyntax_table_p (tmp_table), Qt)) | 495 if (!NILP (Fsyntax_table_p (tmp_table))) |
318 { | 496 { |
319 syntax_cache.use_code = 0; | 497 cache->use_code = 0; |
320 syntax_cache.current_syntax_table = | 498 cache->current_syntax_table = |
321 XCHAR_TABLE (tmp_table)->mirror_table; | 499 XCHAR_TABLE (tmp_table)->mirror_table; |
322 } | 500 cache->no_syntax_table_prop = 0; |
323 else if (CONSP (tmp_table) && INTP (XCAR (tmp_table))) | 501 } |
324 { | 502 else if (CONSP (tmp_table) && INTP (XCAR (tmp_table))) |
325 syntax_cache.use_code = 1; | 503 { |
326 syntax_cache.syntax_code = XINT (XCAR(tmp_table)); | 504 cache->use_code = 1; |
327 } | 505 cache->syntax_code = XINT (XCAR (tmp_table)); |
328 else | 506 cache->no_syntax_table_prop = 0; |
329 { | 507 } |
330 syntax_cache.use_code = 0; | 508 else |
331 syntax_cache.current_syntax_table = | 509 { |
332 syntax_cache.buffer->mirror_syntax_table; | 510 cache->use_code = 0; |
333 } | 511 cache->no_syntax_table_prop = 1; |
512 cache->current_syntax_table = | |
513 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); | |
334 } | 514 } |
335 } | 515 } |
336 | 516 |
337 /* Convert a letter which signifies a syntax code | 517 /* Convert a letter which signifies a syntax code |
338 into the code it signifies. | 518 into the code it signifies. |
381 Optional second argument SYNTAX-TABLE defaults to the current buffer's | 561 Optional second argument SYNTAX-TABLE defaults to the current buffer's |
382 syntax table. | 562 syntax table. |
383 */ | 563 */ |
384 (character, syntax_table)) | 564 (character, syntax_table)) |
385 { | 565 { |
386 Lisp_Char_Table *mirrortab; | 566 Lisp_Object mirrortab; |
387 | 567 |
388 if (NILP (character)) | 568 if (NILP (character)) |
389 { | 569 { |
390 character = make_char ('\000'); | 570 character = make_char ('\000'); |
391 } | 571 } |
392 CHECK_CHAR_COERCE_INT (character); | 572 CHECK_CHAR_COERCE_INT (character); |
393 syntax_table = check_syntax_table (syntax_table, current_buffer->syntax_table); | 573 syntax_table = check_syntax_table (syntax_table, |
394 mirrortab = XCHAR_TABLE (XCHAR_TABLE (syntax_table)->mirror_table); | 574 current_buffer->syntax_table); |
395 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, XCHAR (character))]); | 575 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table; |
576 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, | |
577 XCHAR (character))]); | |
396 } | 578 } |
397 | 579 |
398 #ifdef MULE | 580 #ifdef MULE |
399 | 581 |
400 enum syntaxcode | 582 enum syntaxcode |
401 charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out) | 583 charset_syntax (struct buffer *buf, Lisp_Object charset, int *multi_p_out) |
402 { | 584 { |
403 *multi_p_out = 1; | 585 *multi_p_out = 1; |
404 /* #### get this right */ | 586 /* !!#### get this right */ |
405 return Spunct; | 587 return Spunct; |
406 } | 588 } |
407 | 589 |
408 #endif | 590 #endif |
409 | 591 |
410 Lisp_Object | 592 Lisp_Object |
411 syntax_match (Lisp_Object syntax_table, Emchar ch) | 593 syntax_match (Lisp_Object syntax_table, Emchar ch) |
412 { | 594 { |
413 Lisp_Object code = XCHAR_TABLE_VALUE_UNSAFE (syntax_table, ch); | 595 Lisp_Object code = get_char_table (ch, syntax_table); |
414 Lisp_Object code2 = code; | 596 Lisp_Object code2 = code; |
415 | 597 |
416 if (CONSP (code)) | 598 if (CONSP (code)) |
417 code2 = XCAR (code); | 599 code2 = XCAR (code); |
418 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit) | 600 if (SYNTAX_FROM_CODE (XINT (code2)) == Sinherit) |
419 code = XCHAR_TABLE_VALUE_UNSAFE (Vstandard_syntax_table, ch); | 601 code = get_char_table (ch, Vstandard_syntax_table); |
420 | 602 |
421 return CONSP (code) ? XCDR (code) : Qnil; | 603 return CONSP (code) ? XCDR (code) : Qnil; |
422 } | 604 } |
423 | 605 |
424 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /* | 606 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /* |
426 Optional second argument SYNTAX-TABLE defaults to the current buffer's | 608 Optional second argument SYNTAX-TABLE defaults to the current buffer's |
427 syntax table. | 609 syntax table. |
428 */ | 610 */ |
429 (character, syntax_table)) | 611 (character, syntax_table)) |
430 { | 612 { |
431 Lisp_Char_Table *mirrortab; | 613 Lisp_Object mirrortab; |
432 int code; | 614 int code; |
433 | 615 |
434 CHECK_CHAR_COERCE_INT (character); | 616 CHECK_CHAR_COERCE_INT (character); |
435 syntax_table = check_syntax_table (syntax_table, current_buffer->syntax_table); | 617 syntax_table = check_syntax_table (syntax_table, |
436 mirrortab = XCHAR_TABLE (XCHAR_TABLE (syntax_table)->mirror_table); | 618 current_buffer->syntax_table); |
619 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table; | |
437 code = SYNTAX (mirrortab, XCHAR (character)); | 620 code = SYNTAX (mirrortab, XCHAR (character)); |
438 if (code == Sopen || code == Sclose || code == Sstring) | 621 if (code == Sopen || code == Sclose || code == Sstring) |
439 return syntax_match (syntax_table, XCHAR (character)); | 622 return syntax_match (syntax_table, XCHAR (character)); |
440 return Qnil; | 623 return Qnil; |
441 } | 624 } |
446 /* Return 1 if there is a word boundary between two word-constituent | 629 /* Return 1 if there is a word boundary between two word-constituent |
447 characters C1 and C2 if they appear in this order, else return 0. | 630 characters C1 and C2 if they appear in this order, else return 0. |
448 There is no word boundary between two word-constituent ASCII | 631 There is no word boundary between two word-constituent ASCII |
449 characters. */ | 632 characters. */ |
450 #define WORD_BOUNDARY_P(c1, c2) \ | 633 #define WORD_BOUNDARY_P(c1, c2) \ |
451 (!(CHAR_ASCII_P (c1) && CHAR_ASCII_P (c2)) \ | 634 (!(emchar_ascii_p (c1) && emchar_ascii_p (c2)) \ |
452 && word_boundary_p (c1, c2)) | 635 && word_boundary_p (c1, c2)) |
453 | |
454 extern int word_boundary_p (Emchar c1, Emchar c2); | |
455 #endif | 636 #endif |
456 | 637 |
457 /* Return the position across COUNT words from FROM. | 638 /* Return the position across COUNT words from FROM. |
458 If that many words cannot be found before the end of the buffer, return 0. | 639 If that many words cannot be found before the end of the buffer, return 0. |
459 COUNT negative means scan backward and stop at word beginning. */ | 640 COUNT negative means scan backward and stop at word beginning. */ |
462 scan_words (struct buffer *buf, Charbpos from, int count) | 643 scan_words (struct buffer *buf, Charbpos from, int count) |
463 { | 644 { |
464 Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf); | 645 Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf); |
465 Emchar ch0, ch1; | 646 Emchar ch0, ch1; |
466 enum syntaxcode code; | 647 enum syntaxcode code; |
467 | 648 struct syntax_cache *scache = setup_buffer_syntax_cache (buf, from, count); |
468 SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, from, count); | |
469 | 649 |
470 /* #### is it really worth it to hand expand both cases? JV */ | 650 /* #### is it really worth it to hand expand both cases? JV */ |
471 while (count > 0) | 651 while (count > 0) |
472 { | 652 { |
473 QUIT; | 653 QUIT; |
475 while (1) | 655 while (1) |
476 { | 656 { |
477 if (from == limit) | 657 if (from == limit) |
478 return 0; | 658 return 0; |
479 | 659 |
480 UPDATE_SYNTAX_CACHE_FORWARD (from); | 660 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
481 ch0 = BUF_FETCH_CHAR (buf, from); | 661 ch0 = BUF_FETCH_CHAR (buf, from); |
482 code = SYNTAX_FROM_CACHE (mirrortab, ch0); | 662 code = SYNTAX_FROM_CACHE (scache, ch0); |
483 | 663 |
484 from++; | 664 from++; |
485 if (words_include_escapes | 665 if (words_include_escapes |
486 && (code == Sescape || code == Scharquote)) | 666 && (code == Sescape || code == Scharquote)) |
487 break; | 667 break; |
491 | 671 |
492 QUIT; | 672 QUIT; |
493 | 673 |
494 while (from != limit) | 674 while (from != limit) |
495 { | 675 { |
496 UPDATE_SYNTAX_CACHE_FORWARD (from); | 676 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
497 ch1 = BUF_FETCH_CHAR (buf, from); | 677 ch1 = BUF_FETCH_CHAR (buf, from); |
498 code = SYNTAX_FROM_CACHE (mirrortab, ch1); | 678 code = SYNTAX_FROM_CACHE (scache, ch1); |
499 if (!(words_include_escapes | 679 if (!(words_include_escapes |
500 && (code == Sescape || code == Scharquote))) | 680 && (code == Sescape || code == Scharquote))) |
501 if (code != Sword | 681 if (code != Sword |
502 #ifdef MULE | 682 #ifdef MULE |
503 || WORD_BOUNDARY_P (ch0, ch1) | 683 || WORD_BOUNDARY_P (ch0, ch1) |
519 while (1) | 699 while (1) |
520 { | 700 { |
521 if (from == limit) | 701 if (from == limit) |
522 return 0; | 702 return 0; |
523 | 703 |
524 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 704 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
525 ch1 = BUF_FETCH_CHAR (buf, from - 1); | 705 ch1 = BUF_FETCH_CHAR (buf, from - 1); |
526 code = SYNTAX_FROM_CACHE (mirrortab, ch1); | 706 code = SYNTAX_FROM_CACHE (scache, ch1); |
527 from--; | 707 from--; |
528 | 708 |
529 if (words_include_escapes | 709 if (words_include_escapes |
530 && (code == Sescape || code == Scharquote)) | 710 && (code == Sescape || code == Scharquote)) |
531 break; | 711 break; |
535 | 715 |
536 QUIT; | 716 QUIT; |
537 | 717 |
538 while (from != limit) | 718 while (from != limit) |
539 { | 719 { |
540 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 720 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
541 ch0 = BUF_FETCH_CHAR (buf, from - 1); | 721 ch0 = BUF_FETCH_CHAR (buf, from - 1); |
542 code = SYNTAX_FROM_CACHE (mirrortab, ch0); | 722 code = SYNTAX_FROM_CACHE (scache, ch0); |
543 | 723 |
544 if (!(words_include_escapes | 724 if (!(words_include_escapes |
545 && (code == Sescape || code == Scharquote))) | 725 && (code == Sescape || code == Scharquote))) |
546 if (code != Sword | 726 if (code != Sword |
547 #ifdef MULE | 727 #ifdef MULE |
630 int comstart_parity = 0; | 810 int comstart_parity = 0; |
631 int styles_match_p = 0; | 811 int styles_match_p = 0; |
632 /* mask to match comment styles against; for ST_COMMENT_STYLE, this | 812 /* mask to match comment styles against; for ST_COMMENT_STYLE, this |
633 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */ | 813 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */ |
634 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A; | 814 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A; |
815 struct syntax_cache *scache = buf->syntax_cache; | |
635 | 816 |
636 /* At beginning of range to scan, we're outside of strings; | 817 /* At beginning of range to scan, we're outside of strings; |
637 that determines quote parity to the comment-end. */ | 818 that determines quote parity to the comment-end. */ |
638 while (from != stop) | 819 while (from != stop) |
639 { | 820 { |
640 int syncode; | 821 int syncode; |
641 | 822 |
642 /* Move back and examine a character. */ | 823 /* Move back and examine a character. */ |
643 from--; | 824 from--; |
644 UPDATE_SYNTAX_CACHE_BACKWARD (from); | 825 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
645 | 826 |
646 c = BUF_FETCH_CHAR (buf, from); | 827 c = BUF_FETCH_CHAR (buf, from); |
647 code = SYNTAX_FROM_CACHE (mirrortab, c); | 828 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
648 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 829 code = SYNTAX_FROM_CODE (syncode); |
649 | 830 |
650 /* is this a 1-char comment end sequence? if so, try | 831 /* is this a 1-char comment end sequence? if so, try |
651 to see if style matches previously extracted mask */ | 832 to see if style matches previously extracted mask */ |
652 if (code == Sendcomment) | 833 if (code == Sendcomment) |
653 { | 834 { |
669 { | 850 { |
670 /* 2-char comment end sequence? */ | 851 /* 2-char comment end sequence? */ |
671 if (SYNTAX_CODE_END_SECOND_P (syncode)) | 852 if (SYNTAX_CODE_END_SECOND_P (syncode)) |
672 { | 853 { |
673 int prev_syncode; | 854 int prev_syncode; |
674 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 855 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
675 prev_syncode = | 856 prev_syncode = |
676 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from - 1)); | 857 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1)); |
677 | 858 |
678 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) | 859 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) |
679 { | 860 { |
680 code = Sendcomment; | 861 code = Sendcomment; |
681 styles_match_p = | 862 styles_match_p = |
682 SYNTAX_CODES_COMMENT_MASK_END (prev_syncode, syncode) & mask; | 863 SYNTAX_CODES_COMMENT_MASK_END (prev_syncode, |
864 syncode) & mask; | |
683 from--; | 865 from--; |
684 UPDATE_SYNTAX_CACHE_BACKWARD (from); | 866 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
685 c = BUF_FETCH_CHAR (buf, from); | 867 c = BUF_FETCH_CHAR (buf, from); |
686 | 868 |
687 /* Found a comment-end sequence, so skip past the | 869 /* Found a comment-end sequence, so skip past the |
688 check for a comment-start */ | 870 check for a comment-start */ |
689 break; | 871 break; |
692 | 874 |
693 /* 2-char comment start sequence? */ | 875 /* 2-char comment start sequence? */ |
694 if (SYNTAX_CODE_START_SECOND_P (syncode)) | 876 if (SYNTAX_CODE_START_SECOND_P (syncode)) |
695 { | 877 { |
696 int prev_syncode; | 878 int prev_syncode; |
697 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 879 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
698 prev_syncode = | 880 prev_syncode = |
699 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from - 1)); | 881 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1)); |
700 | 882 |
701 if (SYNTAX_CODES_START_P (prev_syncode, syncode)) | 883 if (SYNTAX_CODES_START_P (prev_syncode, syncode)) |
702 { | 884 { |
703 code = Scomment; | 885 code = Scomment; |
704 styles_match_p = | 886 styles_match_p = |
705 SYNTAX_CODES_COMMENT_MASK_START (prev_syncode, syncode) & mask; | 887 SYNTAX_CODES_COMMENT_MASK_START (prev_syncode, |
888 syncode) & mask; | |
706 from--; | 889 from--; |
707 UPDATE_SYNTAX_CACHE_BACKWARD (from); | 890 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
708 c = BUF_FETCH_CHAR (buf, from); | 891 c = BUF_FETCH_CHAR (buf, from); |
709 } | 892 } |
710 } | 893 } |
711 } while (0); | 894 } while (0); |
712 | 895 |
782 if (state.incomment) | 965 if (state.incomment) |
783 from = state.comstr_start; | 966 from = state.comstr_start; |
784 else | 967 else |
785 /* We can't grok this as a comment; scan it normally. */ | 968 /* We can't grok this as a comment; scan it normally. */ |
786 from = comment_end; | 969 from = comment_end; |
787 UPDATE_SYNTAX_CACHE_FORWARD (from - 1); | 970 UPDATE_SYNTAX_CACHE_FORWARD (scache, from - 1); |
788 } | 971 } |
789 return from; | 972 return from; |
790 } | 973 } |
791 | 974 |
792 static Charbpos | 975 static Charbpos |
793 find_end_of_comment (struct buffer *buf, Charbpos from, Charbpos stop, int comstyle) | 976 find_end_of_comment (struct buffer *buf, Charbpos from, Charbpos stop, |
977 int comstyle) | |
794 { | 978 { |
795 int c; | 979 int c; |
796 int prev_code; | 980 int prev_code; |
797 /* mask to match comment styles against; for ST_COMMENT_STYLE, this | 981 /* mask to match comment styles against; for ST_COMMENT_STYLE, this |
798 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */ | 982 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */ |
799 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A; | 983 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A; |
984 struct syntax_cache *scache = buf->syntax_cache; | |
800 | 985 |
801 /* This is only called by functions which have already set up the | 986 /* This is only called by functions which have already set up the |
802 syntax_cache and are keeping it up-to-date */ | 987 syntax_cache and are keeping it up-to-date */ |
803 while (1) | 988 while (1) |
804 { | 989 { |
805 if (from == stop) | 990 if (from == stop) |
806 { | 991 { |
807 return -1; | 992 return -1; |
808 } | 993 } |
809 | 994 |
810 UPDATE_SYNTAX_CACHE_FORWARD (from); | 995 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
811 c = BUF_FETCH_CHAR (buf, from); | 996 c = BUF_FETCH_CHAR (buf, from); |
812 | 997 |
813 /* Test for generic comments */ | 998 /* Test for generic comments */ |
814 if (comstyle == ST_COMMENT_STYLE) | 999 if (comstyle == ST_COMMENT_STYLE) |
815 { | 1000 { |
816 if (SYNTAX_FROM_CACHE (mirrortab, c) == Scomment_fence) | 1001 if (SYNTAX_FROM_CACHE (scache, c) == Scomment_fence) |
817 { | 1002 { |
818 from++; | 1003 from++; |
819 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1004 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
820 break; | 1005 break; |
821 } | 1006 } |
822 from++; | 1007 from++; |
823 continue; /* No need to test other comment styles in a | 1008 continue; /* No need to test other comment styles in a |
824 generic comment */ | 1009 generic comment */ |
825 } | 1010 } |
826 else | 1011 else |
827 | 1012 |
828 if (SYNTAX_FROM_CACHE (mirrortab, c) == Sendcomment | 1013 if (SYNTAX_FROM_CACHE (scache, c) == Sendcomment |
829 && SYNTAX_CODE_MATCHES_1CHAR_P | 1014 && SYNTAX_CODE_MATCHES_1CHAR_P |
830 (SYNTAX_CODE_FROM_CACHE (mirrortab, c), mask)) | 1015 (SYNTAX_CODE_FROM_CACHE (scache, c), mask)) |
831 /* we have encountered a comment end of the same style | 1016 /* we have encountered a comment end of the same style |
832 as the comment sequence which began this comment | 1017 as the comment sequence which began this comment |
833 section */ | 1018 section */ |
834 { | 1019 { |
835 from++; | 1020 from++; |
836 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1021 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
837 break; | 1022 break; |
838 } | 1023 } |
839 | 1024 |
840 prev_code = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 1025 prev_code = SYNTAX_CODE_FROM_CACHE (scache, c); |
841 from++; | 1026 from++; |
842 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1027 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
843 if (from < stop | 1028 if (from < stop |
844 && SYNTAX_CODES_MATCH_END_P | 1029 && SYNTAX_CODES_MATCH_END_P |
845 (prev_code, | 1030 (prev_code, |
846 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)), | 1031 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)), |
847 mask) | 1032 mask) |
848 | 1033 |
849 ) | 1034 ) |
850 /* we have encountered a comment end of the same style | 1035 /* we have encountered a comment end of the same style |
851 as the comment sequence which began this comment | 1036 as the comment sequence which began this comment |
852 section */ | 1037 section */ |
853 { | 1038 { |
854 from++; | 1039 from++; |
855 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1040 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
856 break; | 1041 break; |
857 } | 1042 } |
858 } | 1043 } |
859 return from; | 1044 return from; |
860 } | 1045 } |
883 Emchar c; | 1068 Emchar c; |
884 enum syntaxcode code; | 1069 enum syntaxcode code; |
885 int syncode; | 1070 int syncode; |
886 EMACS_INT n; | 1071 EMACS_INT n; |
887 struct buffer *buf = decode_buffer (buffer, 0); | 1072 struct buffer *buf = decode_buffer (buffer, 0); |
888 | 1073 struct syntax_cache *scache; |
1074 | |
889 if (NILP (count)) | 1075 if (NILP (count)) |
890 n = 1; | 1076 n = 1; |
891 else | 1077 else |
892 { | 1078 { |
893 CHECK_INT (count); | 1079 CHECK_INT (count); |
894 n = XINT (count); | 1080 n = XINT (count); |
895 } | 1081 } |
896 | 1082 |
897 from = BUF_PT (buf); | 1083 from = BUF_PT (buf); |
898 | 1084 |
899 SETUP_SYNTAX_CACHE (from, n); | 1085 scache = setup_buffer_syntax_cache (buf, from, n); |
900 while (n > 0) | 1086 while (n > 0) |
901 { | 1087 { |
902 QUIT; | 1088 QUIT; |
903 | 1089 |
904 stop = BUF_ZV (buf); | 1090 stop = BUF_ZV (buf); |
910 { | 1096 { |
911 from++; | 1097 from++; |
912 continue; | 1098 continue; |
913 } | 1099 } |
914 | 1100 |
915 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1101 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
916 c = BUF_FETCH_CHAR (buf, from); | 1102 c = BUF_FETCH_CHAR (buf, from); |
917 code = SYNTAX_FROM_CACHE (mirrortab, c); | 1103 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
918 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 1104 code = SYNTAX_FROM_CODE (syncode); |
919 | 1105 |
920 if (code == Scomment) | 1106 if (code == Scomment) |
921 { | 1107 { |
922 /* we have encountered a single character comment start | 1108 /* we have encountered a single character comment start |
923 sequence, and we are ignoring all text inside comments. | 1109 sequence, and we are ignoring all text inside comments. |
937 | 1123 |
938 else if (from < stop | 1124 else if (from < stop |
939 && SYNTAX_CODE_START_FIRST_P (syncode)) | 1125 && SYNTAX_CODE_START_FIRST_P (syncode)) |
940 { | 1126 { |
941 int next_syncode; | 1127 int next_syncode; |
942 UPDATE_SYNTAX_CACHE_FORWARD (from + 1); | 1128 UPDATE_SYNTAX_CACHE_FORWARD (scache, from + 1); |
943 next_syncode = | 1129 next_syncode = |
944 SYNTAX_CODE_FROM_CACHE (mirrortab, | 1130 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from + 1)); |
945 BUF_FETCH_CHAR (buf, from + 1)); | |
946 | 1131 |
947 if (SYNTAX_CODES_START_P (syncode, next_syncode)) | 1132 if (SYNTAX_CODES_START_P (syncode, next_syncode)) |
948 { | 1133 { |
949 /* we have encountered a 2char comment start sequence and we | 1134 /* we have encountered a 2char comment start sequence and we |
950 are ignoring all text inside comments. we must record | 1135 are ignoring all text inside comments. we must record |
959 } | 1144 } |
960 } | 1145 } |
961 | 1146 |
962 if (code == Scomment) | 1147 if (code == Scomment) |
963 { | 1148 { |
964 Charbpos newfrom = find_end_of_comment (buf, from, stop, comstyle); | 1149 Charbpos newfrom = find_end_of_comment (buf, from, stop, |
1150 comstyle); | |
965 if (newfrom < 0) | 1151 if (newfrom < 0) |
966 { | 1152 { |
967 /* we stopped because from==stop */ | 1153 /* we stopped because from==stop */ |
968 BUF_SET_PT (buf, stop); | 1154 BUF_SET_PT (buf, stop); |
969 return Qnil; | 1155 return Qnil; |
1002 from--; | 1188 from--; |
1003 continue; | 1189 continue; |
1004 } | 1190 } |
1005 | 1191 |
1006 c = BUF_FETCH_CHAR (buf, from); | 1192 c = BUF_FETCH_CHAR (buf, from); |
1007 code = SYNTAX_FROM_CACHE (mirrortab, c); | 1193 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1008 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 1194 code = SYNTAX_FROM_CODE (syncode); |
1009 | 1195 |
1010 if (code == Sendcomment) | 1196 if (code == Sendcomment) |
1011 { | 1197 { |
1012 /* we have found a single char end comment. we must record | 1198 /* we have found a single char end comment. we must record |
1013 the comment style encountered so that later, we can match | 1199 the comment style encountered so that later, we can match |
1024 | 1210 |
1025 else if (from > stop | 1211 else if (from > stop |
1026 && SYNTAX_CODE_END_SECOND_P (syncode)) | 1212 && SYNTAX_CODE_END_SECOND_P (syncode)) |
1027 { | 1213 { |
1028 int prev_syncode; | 1214 int prev_syncode; |
1029 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 1215 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
1030 prev_syncode = | 1216 prev_syncode = |
1031 SYNTAX_CODE_FROM_CACHE (mirrortab, | 1217 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1)); |
1032 BUF_FETCH_CHAR (buf, from - 1)); | |
1033 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) | 1218 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) |
1034 { | 1219 { |
1035 /* We must record the comment style encountered so that | 1220 /* We must record the comment style encountered so that |
1036 later, we can match only the proper comment begin | 1221 later, we can match only the proper comment begin |
1037 sequence of the same style. */ | 1222 sequence of the same style. */ |
1074 int quoted; | 1259 int quoted; |
1075 int mathexit = 0; | 1260 int mathexit = 0; |
1076 enum syntaxcode code; | 1261 enum syntaxcode code; |
1077 int syncode; | 1262 int syncode; |
1078 int min_depth = depth; /* Err out if depth gets less than this. */ | 1263 int min_depth = depth; /* Err out if depth gets less than this. */ |
1079 | 1264 struct syntax_cache *scache; |
1265 | |
1080 if (depth > 0) min_depth = 0; | 1266 if (depth > 0) min_depth = 0; |
1081 | 1267 |
1082 SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, from, count); | 1268 scache = setup_buffer_syntax_cache (buf, from, count); |
1083 while (count > 0) | 1269 while (count > 0) |
1084 { | 1270 { |
1085 QUIT; | 1271 QUIT; |
1086 | 1272 |
1087 stop = BUF_ZV (buf); | 1273 stop = BUF_ZV (buf); |
1088 while (from < stop) | 1274 while (from < stop) |
1089 { | 1275 { |
1090 int comstyle = 0; /* mask for finding matching comment style */ | 1276 int comstyle = 0; /* mask for finding matching comment style */ |
1091 | 1277 |
1092 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1278 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1093 c = BUF_FETCH_CHAR (buf, from); | 1279 c = BUF_FETCH_CHAR (buf, from); |
1094 code = SYNTAX_FROM_CACHE (mirrortab, c); | 1280 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1095 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 1281 code = SYNTAX_FROM_CODE (syncode); |
1096 from++; | 1282 from++; |
1097 | 1283 |
1098 /* a 1-char comment start sequence */ | 1284 /* a 1-char comment start sequence */ |
1099 if (code == Scomment && parse_sexp_ignore_comments) | 1285 if (code == Scomment && parse_sexp_ignore_comments) |
1100 { | 1286 { |
1106 else if (from < stop | 1292 else if (from < stop |
1107 && SYNTAX_CODE_START_FIRST_P (syncode) | 1293 && SYNTAX_CODE_START_FIRST_P (syncode) |
1108 && parse_sexp_ignore_comments) | 1294 && parse_sexp_ignore_comments) |
1109 { | 1295 { |
1110 int next_syncode; | 1296 int next_syncode; |
1111 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1297 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1112 next_syncode = | 1298 next_syncode = |
1113 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)); | 1299 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)); |
1114 | 1300 |
1115 if (SYNTAX_CODES_START_P (syncode, next_syncode)) | 1301 if (SYNTAX_CODES_START_P (syncode, next_syncode)) |
1116 { | 1302 { |
1117 /* we have encountered a comment start sequence and we | 1303 /* we have encountered a comment start sequence and we |
1118 are ignoring all text inside comments. we must record | 1304 are ignoring all text inside comments. we must record |
1119 the comment style this sequence begins so that later, | 1305 the comment style this sequence begins so that later, |
1120 only a comment end of the same style actually ends | 1306 only a comment end of the same style actually ends |
1121 the comment section */ | 1307 the comment section */ |
1122 code = Scomment; | 1308 code = Scomment; |
1123 comstyle = SYNTAX_CODES_COMMENT_MASK_START | 1309 comstyle = SYNTAX_CODES_COMMENT_MASK_START |
1124 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | 1310 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; |
1125 from++; | 1311 from++; |
1312 } | |
1126 } | 1313 } |
1127 } | 1314 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1128 UPDATE_SYNTAX_CACHE_FORWARD (from); | |
1129 | 1315 |
1130 if (SYNTAX_CODE_PREFIX (syncode)) | 1316 if (SYNTAX_CODE_PREFIX (syncode)) |
1131 continue; | 1317 continue; |
1132 | 1318 |
1133 switch (code) | 1319 switch (code) |
1141 case Ssymbol: | 1327 case Ssymbol: |
1142 if (depth || !sexpflag) break; | 1328 if (depth || !sexpflag) break; |
1143 /* This word counts as a sexp; return at end of it. */ | 1329 /* This word counts as a sexp; return at end of it. */ |
1144 while (from < stop) | 1330 while (from < stop) |
1145 { | 1331 { |
1146 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1332 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1147 switch (SYNTAX_FROM_CACHE (mirrortab, | 1333 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from))) |
1148 BUF_FETCH_CHAR (buf, from))) | |
1149 { | 1334 { |
1150 case Scharquote: | 1335 case Scharquote: |
1151 case Sescape: | 1336 case Sescape: |
1152 from++; | 1337 from++; |
1153 if (from == stop) goto lose; | 1338 if (from == stop) goto lose; |
1166 case Scomment_fence: | 1351 case Scomment_fence: |
1167 comstyle = ST_COMMENT_STYLE; | 1352 comstyle = ST_COMMENT_STYLE; |
1168 case Scomment: | 1353 case Scomment: |
1169 if (!parse_sexp_ignore_comments) | 1354 if (!parse_sexp_ignore_comments) |
1170 break; | 1355 break; |
1171 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1356 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1172 { | 1357 { |
1173 Charbpos newfrom = | 1358 Charbpos newfrom = |
1174 find_end_of_comment (buf, from, stop, comstyle); | 1359 find_end_of_comment (buf, from, stop, comstyle); |
1175 if (newfrom < 0) | 1360 if (newfrom < 0) |
1176 { | 1361 { |
1205 if (!--depth) goto done; | 1390 if (!--depth) goto done; |
1206 if (depth < min_depth) | 1391 if (depth < min_depth) |
1207 { | 1392 { |
1208 if (noerror) | 1393 if (noerror) |
1209 return Qnil; | 1394 return Qnil; |
1210 signal_error (Qsyntax_error, "Containing expression ends prematurely", Qunbound); | 1395 syntax_error ("Containing expression ends prematurely", |
1396 Qunbound); | |
1211 } | 1397 } |
1212 break; | 1398 break; |
1213 | 1399 |
1214 case Sstring_fence: | 1400 case Sstring_fence: |
1215 case Sstring: | 1401 case Sstring: |
1216 { | 1402 { |
1217 Emchar stringterm; | 1403 Emchar stringterm; |
1218 | 1404 |
1219 if (code != Sstring_fence) | 1405 if (code != Sstring_fence) |
1220 { | 1406 { |
1221 /* XEmacs change: call syntax_match on character */ | 1407 /* XEmacs change: call syntax_match on character */ |
1222 Emchar ch = BUF_FETCH_CHAR (buf, from - 1); | 1408 Emchar ch = BUF_FETCH_CHAR (buf, from - 1); |
1223 Lisp_Object stermobj = | 1409 Lisp_Object stermobj = |
1224 syntax_match (syntax_cache.current_syntax_table, ch); | 1410 syntax_match (scache->current_syntax_table, ch); |
1225 | 1411 |
1226 if (CHARP (stermobj)) | 1412 if (CHARP (stermobj)) |
1227 stringterm = XCHAR (stermobj); | 1413 stringterm = XCHAR (stermobj); |
1228 else | 1414 else |
1229 stringterm = ch; | 1415 stringterm = ch; |
1233 | 1419 |
1234 while (1) | 1420 while (1) |
1235 { | 1421 { |
1236 if (from >= stop) | 1422 if (from >= stop) |
1237 goto lose; | 1423 goto lose; |
1238 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1424 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1239 c = BUF_FETCH_CHAR (buf, from); | 1425 c = BUF_FETCH_CHAR (buf, from); |
1240 if (code == Sstring | 1426 if (code == Sstring |
1241 ? c == stringterm | 1427 ? c == stringterm |
1242 : SYNTAX_FROM_CACHE (mirrortab, c) == Sstring_fence) | 1428 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence) |
1243 break; | 1429 break; |
1244 | 1430 |
1245 switch (SYNTAX_FROM_CACHE (mirrortab, c)) | 1431 switch (SYNTAX_FROM_CACHE (scache, c)) |
1246 { | 1432 { |
1247 case Scharquote: | 1433 case Scharquote: |
1248 case Sescape: | 1434 case Sescape: |
1249 from++; | 1435 from++; |
1250 break; | 1436 break; |
1282 while (from > stop) | 1468 while (from > stop) |
1283 { | 1469 { |
1284 int comstyle = 0; /* mask for finding matching comment style */ | 1470 int comstyle = 0; /* mask for finding matching comment style */ |
1285 | 1471 |
1286 from--; | 1472 from--; |
1287 UPDATE_SYNTAX_CACHE_BACKWARD (from); | 1473 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
1288 quoted = char_quoted (buf, from); | 1474 quoted = char_quoted (buf, from); |
1289 if (quoted) | 1475 if (quoted) |
1290 { | 1476 { |
1291 from--; | 1477 from--; |
1292 UPDATE_SYNTAX_CACHE_BACKWARD (from); | 1478 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
1293 } | 1479 } |
1294 | 1480 |
1295 c = BUF_FETCH_CHAR (buf, from); | 1481 c = BUF_FETCH_CHAR (buf, from); |
1296 code = SYNTAX_FROM_CACHE (mirrortab, c); | 1482 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1297 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 1483 code = SYNTAX_FROM_CODE (syncode); |
1298 | 1484 |
1299 if (code == Sendcomment && parse_sexp_ignore_comments) | 1485 if (code == Sendcomment && parse_sexp_ignore_comments) |
1300 { | 1486 { |
1301 /* we have found a single char end comment. we must record | 1487 /* we have found a single char end comment. we must record |
1302 the comment style encountered so that later, we can match | 1488 the comment style encountered so that later, we can match |
1309 && SYNTAX_CODE_END_SECOND_P (syncode) | 1495 && SYNTAX_CODE_END_SECOND_P (syncode) |
1310 && !char_quoted (buf, from - 1) | 1496 && !char_quoted (buf, from - 1) |
1311 && parse_sexp_ignore_comments) | 1497 && parse_sexp_ignore_comments) |
1312 { | 1498 { |
1313 int prev_syncode; | 1499 int prev_syncode; |
1314 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 1500 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
1315 prev_syncode = SYNTAX_CODE_FROM_CACHE | 1501 prev_syncode = |
1316 (mirrortab, BUF_FETCH_CHAR (buf, from - 1)); | 1502 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1)); |
1317 | 1503 |
1318 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) | 1504 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) |
1319 { | 1505 { |
1320 /* we must record the comment style encountered so that | 1506 /* we must record the comment style encountered so that |
1321 later, we can match only the proper comment begin | 1507 later, we can match only the proper comment begin |
1337 if (depth || !sexpflag) break; | 1523 if (depth || !sexpflag) break; |
1338 /* This word counts as a sexp; count object finished after | 1524 /* This word counts as a sexp; count object finished after |
1339 passing it. */ | 1525 passing it. */ |
1340 while (from > stop) | 1526 while (from > stop) |
1341 { | 1527 { |
1342 UPDATE_SYNTAX_CACHE_BACKWARD (from); | 1528 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
1343 quoted = char_quoted (buf, from - 1); | 1529 quoted = char_quoted (buf, from - 1); |
1344 | 1530 |
1345 if (quoted) | 1531 if (quoted) |
1346 from--; | 1532 from--; |
1347 if (! (quoted | 1533 if (! (quoted |
1348 || (syncode = | 1534 || (syncode = |
1349 SYNTAX_FROM_CACHE (mirrortab, | 1535 SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, |
1350 BUF_FETCH_CHAR (buf, from - 1))) | 1536 from - 1))) |
1351 == Sword | 1537 == Sword |
1352 || syncode == Ssymbol | 1538 || syncode == Ssymbol |
1353 || syncode == Squote)) | 1539 || syncode == Squote)) |
1354 goto done2; | 1540 goto done2; |
1355 from--; | 1541 from--; |
1377 if (!--depth) goto done2; | 1563 if (!--depth) goto done2; |
1378 if (depth < min_depth) | 1564 if (depth < min_depth) |
1379 { | 1565 { |
1380 if (noerror) | 1566 if (noerror) |
1381 return Qnil; | 1567 return Qnil; |
1382 signal_error (Qsyntax_error, "Containing expression ends prematurely", Qunbound); | 1568 syntax_error ("Containing expression ends prematurely", |
1569 Qunbound); | |
1383 } | 1570 } |
1384 break; | 1571 break; |
1385 | 1572 |
1386 case Scomment_fence: | 1573 case Scomment_fence: |
1387 comstyle = ST_COMMENT_STYLE; | 1574 comstyle = ST_COMMENT_STYLE; |
1398 if (code != Sstring_fence) | 1585 if (code != Sstring_fence) |
1399 { | 1586 { |
1400 /* XEmacs change: call syntax_match() on character */ | 1587 /* XEmacs change: call syntax_match() on character */ |
1401 Emchar ch = BUF_FETCH_CHAR (buf, from); | 1588 Emchar ch = BUF_FETCH_CHAR (buf, from); |
1402 Lisp_Object stermobj = | 1589 Lisp_Object stermobj = |
1403 syntax_match (syntax_cache.current_syntax_table, ch); | 1590 syntax_match (scache->current_syntax_table, ch); |
1404 | 1591 |
1405 if (CHARP (stermobj)) | 1592 if (CHARP (stermobj)) |
1406 stringterm = XCHAR (stermobj); | 1593 stringterm = XCHAR (stermobj); |
1407 else | 1594 else |
1408 stringterm = ch; | 1595 stringterm = ch; |
1412 | 1599 |
1413 while (1) | 1600 while (1) |
1414 { | 1601 { |
1415 if (from == stop) goto lose; | 1602 if (from == stop) goto lose; |
1416 | 1603 |
1417 UPDATE_SYNTAX_CACHE_BACKWARD (from - 1); | 1604 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
1418 c = BUF_FETCH_CHAR (buf, from - 1); | 1605 c = BUF_FETCH_CHAR (buf, from - 1); |
1419 | 1606 |
1420 if ((code == Sstring | 1607 if ((code == Sstring |
1421 ? c == stringterm | 1608 ? c == stringterm |
1422 : SYNTAX_FROM_CACHE (mirrortab, c) == Sstring_fence) | 1609 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence) |
1423 && !char_quoted (buf, from - 1)) | 1610 && !char_quoted (buf, from - 1)) |
1424 { | 1611 { |
1425 break; | 1612 break; |
1426 } | 1613 } |
1427 | 1614 |
1447 | 1634 |
1448 return (make_int (from)); | 1635 return (make_int (from)); |
1449 | 1636 |
1450 lose: | 1637 lose: |
1451 if (!noerror) | 1638 if (!noerror) |
1452 signal_error (Qsyntax_error, "Unbalanced parentheses", Qunbound); | 1639 syntax_error ("Unbalanced parentheses", Qunbound); |
1453 return Qnil; | 1640 return Qnil; |
1454 } | 1641 } |
1455 | 1642 |
1456 int | 1643 int |
1457 char_quoted (struct buffer *buf, Charbpos pos) | 1644 char_quoted (struct buffer *buf, Charbpos pos) |
1458 { | 1645 { |
1459 enum syntaxcode code; | 1646 enum syntaxcode code; |
1460 Charbpos beg = BUF_BEGV (buf); | 1647 Charbpos beg = BUF_BEGV (buf); |
1461 int quoted = 0; | 1648 int quoted = 0; |
1462 Charbpos startpos = pos; | 1649 Charbpos startpos = pos; |
1650 struct syntax_cache *scache = buf->syntax_cache; | |
1463 | 1651 |
1464 while (pos > beg) | 1652 while (pos > beg) |
1465 { | 1653 { |
1466 UPDATE_SYNTAX_CACHE_BACKWARD (pos - 1); | 1654 UPDATE_SYNTAX_CACHE_BACKWARD (scache, pos - 1); |
1467 code = SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)); | 1655 code = SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, pos - 1)); |
1468 | 1656 |
1469 if (code != Scharquote && code != Sescape) | 1657 if (code != Scharquote && code != Sescape) |
1470 break; | 1658 break; |
1471 pos--; | 1659 pos--; |
1472 quoted = !quoted; | 1660 quoted = !quoted; |
1473 } | 1661 } |
1474 | 1662 |
1475 UPDATE_SYNTAX_CACHE (startpos); | 1663 UPDATE_SYNTAX_CACHE (scache, startpos); |
1476 return quoted; | 1664 return quoted; |
1477 } | 1665 } |
1478 | 1666 |
1479 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /* | 1667 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /* |
1480 Scan from character number FROM by COUNT lists. | 1668 Scan from character number FROM by COUNT lists. |
1546 (buffer)) | 1734 (buffer)) |
1547 { | 1735 { |
1548 struct buffer *buf = decode_buffer (buffer, 0); | 1736 struct buffer *buf = decode_buffer (buffer, 0); |
1549 Charbpos beg = BUF_BEGV (buf); | 1737 Charbpos beg = BUF_BEGV (buf); |
1550 Charbpos pos = BUF_PT (buf); | 1738 Charbpos pos = BUF_PT (buf); |
1551 #ifndef emacs | |
1552 Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table); | |
1553 #endif | |
1554 Emchar c = '\0'; /* initialize to avoid compiler warnings */ | 1739 Emchar c = '\0'; /* initialize to avoid compiler warnings */ |
1555 | 1740 struct syntax_cache *scache; |
1556 | 1741 |
1557 SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, pos, -1); | 1742 scache = setup_buffer_syntax_cache (buf, pos, -1); |
1558 | 1743 |
1559 while (pos > beg && !char_quoted (buf, pos - 1) | 1744 while (pos > beg && !char_quoted (buf, pos - 1) |
1560 /* Previous statement updates syntax table. */ | 1745 /* Previous statement updates syntax table. */ |
1561 && (SYNTAX_FROM_CACHE (mirrortab, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote | 1746 && (SYNTAX_FROM_CACHE (scache, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote |
1562 || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (mirrortab, c)))) | 1747 || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (scache, c)))) |
1563 pos--; | 1748 pos--; |
1564 | 1749 |
1565 BUF_SET_PT (buf, pos); | 1750 BUF_SET_PT (buf, pos); |
1566 | 1751 |
1567 return Qnil; | 1752 return Qnil; |
1592 when the depth becomes negative. */ | 1777 when the depth becomes negative. */ |
1593 int mindepth; /* Lowest DEPTH value seen. */ | 1778 int mindepth; /* Lowest DEPTH value seen. */ |
1594 int start_quoted = 0; /* Nonzero means starting after a char quote */ | 1779 int start_quoted = 0; /* Nonzero means starting after a char quote */ |
1595 int boundary_stop = commentstop == -1; | 1780 int boundary_stop = commentstop == -1; |
1596 Lisp_Object tem; | 1781 Lisp_Object tem; |
1597 | 1782 struct syntax_cache *scache; |
1598 SETUP_SYNTAX_CACHE (from, 1); | 1783 |
1784 scache = setup_buffer_syntax_cache (buf, from, 1); | |
1599 if (NILP (oldstate)) | 1785 if (NILP (oldstate)) |
1600 { | 1786 { |
1601 depth = 0; | 1787 depth = 0; |
1602 state.instring = -1; | 1788 state.instring = -1; |
1603 state.incomment = 0; | 1789 state.incomment = 0; |
1649 to change). */ | 1835 to change). */ |
1650 while (!NILP (tem)) /* >= second enclosing sexps. */ | 1836 while (!NILP (tem)) /* >= second enclosing sexps. */ |
1651 { | 1837 { |
1652 curlevel->last = XINT (Fcar (tem)); | 1838 curlevel->last = XINT (Fcar (tem)); |
1653 if (++curlevel == endlevel) | 1839 if (++curlevel == endlevel) |
1654 signal_error (Qstack_overflow, "Nesting too deep for parser", Qunbound); | 1840 stack_overflow ("Nesting too deep for parser", |
1841 make_int (curlevel - levelstart)); | |
1655 curlevel->prev = -1; | 1842 curlevel->prev = -1; |
1656 curlevel->last = -1; | 1843 curlevel->last = -1; |
1657 tem = Fcdr (tem); | 1844 tem = Fcdr (tem); |
1658 } | 1845 } |
1659 } | 1846 } |
1678 Emchar c; | 1865 Emchar c; |
1679 int syncode; | 1866 int syncode; |
1680 | 1867 |
1681 QUIT; | 1868 QUIT; |
1682 | 1869 |
1683 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1870 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1684 c = BUF_FETCH_CHAR (buf, from); | 1871 c = BUF_FETCH_CHAR (buf, from); |
1685 code = SYNTAX_FROM_CACHE (mirrortab, c); | 1872 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1686 syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c); | 1873 code = SYNTAX_FROM_CODE (syncode); |
1687 from++; | 1874 from++; |
1688 | 1875 |
1689 /* record the comment style we have entered so that only the | 1876 /* record the comment style we have entered so that only the |
1690 comment-ender sequence (or single char) of the same style | 1877 comment-ender sequence (or single char) of the same style |
1691 actually terminates the comment section. */ | 1878 actually terminates the comment section. */ |
1707 | 1894 |
1708 else if (from < end && | 1895 else if (from < end && |
1709 SYNTAX_CODE_START_FIRST_P (syncode)) | 1896 SYNTAX_CODE_START_FIRST_P (syncode)) |
1710 { | 1897 { |
1711 int next_syncode; | 1898 int next_syncode; |
1712 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1899 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1713 next_syncode = | 1900 next_syncode = |
1714 SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)); | 1901 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)); |
1715 | 1902 |
1716 if (SYNTAX_CODES_START_P (syncode, next_syncode)) | 1903 if (SYNTAX_CODES_START_P (syncode, next_syncode)) |
1717 { | 1904 { |
1718 code = Scomment; | 1905 code = Scomment; |
1719 state.comstyle = SYNTAX_CODES_COMMENT_MASK_START | 1906 state.comstyle = SYNTAX_CODES_COMMENT_MASK_START |
1720 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | 1907 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; |
1721 state.comstr_start = from - 1; | 1908 state.comstr_start = from - 1; |
1722 from++; | 1909 from++; |
1723 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1910 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1724 } | 1911 } |
1725 } | 1912 } |
1726 | 1913 |
1727 if (SYNTAX_CODE_PREFIX (syncode)) | 1914 if (SYNTAX_CODE_PREFIX (syncode)) |
1728 continue; | 1915 continue; |
1742 if (stopbefore) goto stop; /* this arg means stop at sexp start */ | 1929 if (stopbefore) goto stop; /* this arg means stop at sexp start */ |
1743 curlevel->last = from - 1; | 1930 curlevel->last = from - 1; |
1744 symstarted: | 1931 symstarted: |
1745 while (from < end) | 1932 while (from < end) |
1746 { | 1933 { |
1747 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1934 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1748 switch (SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from))) | 1935 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from))) |
1749 { | 1936 { |
1750 case Scharquote: | 1937 case Scharquote: |
1751 case Sescape: | 1938 case Sescape: |
1752 from++; | 1939 from++; |
1753 if (from == end) goto endquoted; | 1940 if (from == end) goto endquoted; |
1769 state.incomment = 1; | 1956 state.incomment = 1; |
1770 if (commentstop || boundary_stop) goto done; | 1957 if (commentstop || boundary_stop) goto done; |
1771 startincomment: | 1958 startincomment: |
1772 if (commentstop == 1) | 1959 if (commentstop == 1) |
1773 goto done; | 1960 goto done; |
1774 UPDATE_SYNTAX_CACHE_FORWARD (from); | 1961 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1775 { | 1962 { |
1776 Charbpos newfrom = find_end_of_comment (buf, from, end, state.comstyle); | 1963 Charbpos newfrom = find_end_of_comment (buf, from, end, |
1964 state.comstyle); | |
1777 if (newfrom < 0) | 1965 if (newfrom < 0) |
1778 { | 1966 { |
1779 /* we terminated search because from == end */ | 1967 /* we terminated search because from == end */ |
1780 from = end; | 1968 from = end; |
1781 goto done; | 1969 goto done; |
1791 if (stopbefore) goto stop; /* this arg means stop at sexp start */ | 1979 if (stopbefore) goto stop; /* this arg means stop at sexp start */ |
1792 depth++; | 1980 depth++; |
1793 /* curlevel++->last ran into compiler bug on Apollo */ | 1981 /* curlevel++->last ran into compiler bug on Apollo */ |
1794 curlevel->last = from - 1; | 1982 curlevel->last = from - 1; |
1795 if (++curlevel == endlevel) | 1983 if (++curlevel == endlevel) |
1796 signal_error (Qstack_overflow, "Nesting too deep for parser", Qunbound); | 1984 stack_overflow ("Nesting too deep for parser", |
1985 make_int (curlevel - levelstart)); | |
1797 curlevel->prev = -1; | 1986 curlevel->prev = -1; |
1798 curlevel->last = -1; | 1987 curlevel->last = -1; |
1799 if (targetdepth == depth) goto done; | 1988 if (targetdepth == depth) goto done; |
1800 break; | 1989 break; |
1801 | 1990 |
1821 else | 2010 else |
1822 { | 2011 { |
1823 /* XEmacs change: call syntax_match() on character */ | 2012 /* XEmacs change: call syntax_match() on character */ |
1824 Emchar ch = BUF_FETCH_CHAR (buf, from - 1); | 2013 Emchar ch = BUF_FETCH_CHAR (buf, from - 1); |
1825 Lisp_Object stermobj = | 2014 Lisp_Object stermobj = |
1826 syntax_match (syntax_cache.current_syntax_table, ch); | 2015 syntax_match (scache->current_syntax_table, ch); |
1827 | 2016 |
1828 if (CHARP (stermobj)) | 2017 if (CHARP (stermobj)) |
1829 state.instring = XCHAR (stermobj); | 2018 state.instring = XCHAR (stermobj); |
1830 else | 2019 else |
1831 state.instring = ch; | 2020 state.instring = ch; |
1836 { | 2025 { |
1837 enum syntaxcode temp_code; | 2026 enum syntaxcode temp_code; |
1838 | 2027 |
1839 if (from >= end) goto done; | 2028 if (from >= end) goto done; |
1840 | 2029 |
1841 UPDATE_SYNTAX_CACHE_FORWARD (from); | 2030 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1842 c = BUF_FETCH_CHAR (buf, from); | 2031 c = BUF_FETCH_CHAR (buf, from); |
1843 temp_code = SYNTAX_FROM_CACHE (mirrortab, c); | 2032 temp_code = SYNTAX_FROM_CACHE (scache, c); |
1844 | 2033 |
1845 if ( | 2034 if ( |
1846 state.instring != ST_STRING_STYLE && | 2035 state.instring != ST_STRING_STYLE && |
1847 temp_code == Sstring && | 2036 temp_code == Sstring && |
1848 c == state.instring) break; | 2037 c == state.instring) break; |
1938 It is used to initialize the state of the parse. Its second and third | 2127 It is used to initialize the state of the parse. Its second and third |
1939 elements are ignored. | 2128 elements are ignored. |
1940 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. If it | 2129 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. If it |
1941 is `syntax-table', stop after the start of a comment or a string, or after | 2130 is `syntax-table', stop after the start of a comment or a string, or after |
1942 the end of a comment or string. | 2131 the end of a comment or string. |
2132 Seventh arg BUFFER specifies the buffer to do the parsing in, and defaults | |
2133 to the current buffer. | |
1943 */ | 2134 */ |
1944 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer)) | 2135 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer)) |
1945 { | 2136 { |
1946 struct lisp_parse_state state; | 2137 struct lisp_parse_state state; |
1947 int target; | 2138 int target; |
1976 val = Fcons (state.incomment ? Qt : Qnil, val); | 2167 val = Fcons (state.incomment ? Qt : Qnil, val); |
1977 val = Fcons (state.instring < 0 | 2168 val = Fcons (state.instring < 0 |
1978 ? Qnil | 2169 ? Qnil |
1979 : (state.instring == ST_STRING_STYLE | 2170 : (state.instring == ST_STRING_STYLE |
1980 ? Qt : make_int (state.instring)), val); | 2171 ? Qt : make_int (state.instring)), val); |
1981 val = Fcons (state.thislevelstart < 0 ? Qnil : make_int (state.thislevelstart), val); | 2172 val = Fcons (state.thislevelstart < 0 ? Qnil : |
1982 val = Fcons (state.prevlevelstart < 0 ? Qnil : make_int (state.prevlevelstart), val); | 2173 make_int (state.thislevelstart), val); |
2174 val = Fcons (state.prevlevelstart < 0 ? Qnil : | |
2175 make_int (state.prevlevelstart), val); | |
1983 val = Fcons (make_int (state.depth), val); | 2176 val = Fcons (make_int (state.depth), val); |
1984 | 2177 |
1985 return val; | 2178 return val; |
1986 } | 2179 } |
1987 | 2180 |
2000 | 2193 |
2001 When `set-syntax-table' is called, we set the buffer's mirror | 2194 When `set-syntax-table' is called, we set the buffer's mirror |
2002 syntax table as well. | 2195 syntax table as well. |
2003 */ | 2196 */ |
2004 | 2197 |
2005 struct cmst_arg | |
2006 { | |
2007 Lisp_Object mirrortab; | |
2008 int check_inherit; | |
2009 }; | |
2010 | |
2011 static int | 2198 static int |
2012 cmst_mapfun (struct chartab_range *range, Lisp_Object val, void *arg) | 2199 copy_to_mirrortab (struct chartab_range *range, Lisp_Object table, |
2013 { | 2200 Lisp_Object val, void *arg) |
2014 struct cmst_arg *closure = (struct cmst_arg *) arg; | 2201 { |
2202 Lisp_Object mirrortab = VOID_TO_LISP (arg); | |
2015 | 2203 |
2016 if (CONSP (val)) | 2204 if (CONSP (val)) |
2017 val = XCAR (val); | 2205 val = XCAR (val); |
2018 if (SYNTAX_FROM_CODE (XINT (val)) == Sinherit | 2206 if (SYNTAX_FROM_CODE (XINT (val)) != Sinherit) |
2019 && closure->check_inherit) | 2207 put_char_table (mirrortab, range, val); |
2020 { | |
2021 struct cmst_arg recursive; | |
2022 | |
2023 recursive.mirrortab = closure->mirrortab; | |
2024 recursive.check_inherit = 0; | |
2025 map_char_table (XCHAR_TABLE (Vstandard_syntax_table), range, | |
2026 cmst_mapfun, &recursive); | |
2027 } | |
2028 else | |
2029 put_char_table (XCHAR_TABLE (closure->mirrortab), range, val); | |
2030 return 0; | 2208 return 0; |
2031 } | 2209 } |
2032 | 2210 |
2211 struct cinap | |
2212 { | |
2213 Lisp_Object mirrortab; | |
2214 Lisp_Object bogus; | |
2215 }; | |
2216 | |
2217 static int | |
2218 copy_if_not_already_present (struct chartab_range *range, Lisp_Object table, | |
2219 Lisp_Object val, void *arg) | |
2220 { | |
2221 struct cinap *a = (struct cinap *) arg; | |
2222 | |
2223 if (CONSP (val)) | |
2224 val = XCAR (val); | |
2225 if (SYNTAX_FROM_CODE (XINT (val)) != Sinherit) | |
2226 { | |
2227 Lisp_Object existing = | |
2228 get_range_char_table (range, a->mirrortab, a->bogus); | |
2229 if (NILP (existing)) | |
2230 /* nothing at all */ | |
2231 put_char_table (a->mirrortab, range, val); | |
2232 else if (!EQ (existing, a->bogus)) | |
2233 /* full */ | |
2234 ; | |
2235 else | |
2236 { | |
2237 Freset_char_table (Vtemp_table_for_use_updating_syntax_tables); | |
2238 copy_char_table_range | |
2239 (a->mirrortab, | |
2240 Vtemp_table_for_use_updating_syntax_tables, | |
2241 range); | |
2242 put_char_table (a->mirrortab, range, val); | |
2243 copy_char_table_range | |
2244 (Vtemp_table_for_use_updating_syntax_tables, | |
2245 a->mirrortab, range); | |
2246 } | |
2247 } | |
2248 | |
2249 return 0; | |
2250 } | |
2251 | |
2033 static void | 2252 static void |
2034 update_just_this_syntax_table (Lisp_Char_Table *ct) | 2253 update_just_this_syntax_table (Lisp_Object table) |
2035 { | 2254 { |
2036 struct chartab_range range; | 2255 struct chartab_range range; |
2037 struct cmst_arg arg; | 2256 Lisp_Object mirrortab = XCHAR_TABLE (table)->mirror_table; |
2038 | 2257 |
2039 arg.mirrortab = ct->mirror_table; | |
2040 arg.check_inherit = (CHAR_TABLEP (Vstandard_syntax_table) | |
2041 && ct != XCHAR_TABLE (Vstandard_syntax_table)); | |
2042 range.type = CHARTAB_RANGE_ALL; | 2258 range.type = CHARTAB_RANGE_ALL; |
2043 map_char_table (ct, &range, cmst_mapfun, &arg); | 2259 Freset_char_table (mirrortab); |
2260 /* First, copy the tables values other than inherit into the mirror | |
2261 table. Then, for tables other than the standard syntax table, map | |
2262 over the standard table, copying values into the mirror table only if | |
2263 entries don't already exist in that table. (The copying step requires | |
2264 another mapping.) | |
2265 */ | |
2266 | |
2267 map_char_table (table, &range, copy_to_mirrortab, LISP_TO_VOID (mirrortab)); | |
2268 /* second clause catches bootstrapping problems when initializing the | |
2269 standard syntax table */ | |
2270 if (!EQ (table, Vstandard_syntax_table) && !NILP (Vstandard_syntax_table)) | |
2271 { | |
2272 struct cinap cinap; | |
2273 struct gcpro gcpro1; | |
2274 cinap.mirrortab = mirrortab; | |
2275 /* Something that won't be in the table. */ | |
2276 cinap.bogus = make_float (0.0); | |
2277 GCPRO1 (cinap.bogus); | |
2278 map_char_table (Vstandard_syntax_table, &range, | |
2279 copy_if_not_already_present, &cinap); | |
2280 UNGCPRO; | |
2281 } | |
2282 /* The resetting made the default be Qnil. Put it back to Spunct. */ | |
2283 set_char_table_default (mirrortab, make_int (Spunct)); | |
2044 } | 2284 } |
2045 | 2285 |
2046 /* Called from chartab.c when a change is made to a syntax table. | 2286 /* Called from chartab.c when a change is made to a syntax table. |
2047 If this is the standard syntax table, we need to recompute | 2287 If this is the standard syntax table, we need to recompute |
2048 *all* syntax tables (yuck). Otherwise we just recompute this | 2288 *all* syntax tables (yuck). Otherwise we just recompute this |
2049 one. */ | 2289 one. */ |
2050 | 2290 |
2051 void | 2291 void |
2052 update_syntax_table (Lisp_Char_Table *ct) | 2292 update_syntax_table (Lisp_Object table) |
2053 { | 2293 { |
2054 /* Don't be stymied at startup. */ | 2294 if (EQ (table, Vstandard_syntax_table)) |
2055 if (CHAR_TABLEP (Vstandard_syntax_table) | |
2056 && ct == XCHAR_TABLE (Vstandard_syntax_table)) | |
2057 { | 2295 { |
2058 Lisp_Object syntab; | 2296 Lisp_Object syntab; |
2059 | 2297 |
2060 for (syntab = Vall_syntax_tables; !NILP (syntab); | 2298 for (syntab = Vall_syntax_tables; !NILP (syntab); |
2061 syntab = XCHAR_TABLE (syntab)->next_table) | 2299 syntab = XCHAR_TABLE (syntab)->next_table) |
2062 update_just_this_syntax_table (XCHAR_TABLE (syntab)); | 2300 update_just_this_syntax_table (syntab); |
2063 } | 2301 } |
2064 else | 2302 else |
2065 update_just_this_syntax_table (ct); | 2303 update_just_this_syntax_table (table); |
2066 } | 2304 } |
2067 | 2305 |
2068 | 2306 |
2069 /************************************************************************/ | 2307 /************************************************************************/ |
2070 /* initialization */ | 2308 /* initialization */ |
2076 DEFSYMBOL (Qsyntax_table_p); | 2314 DEFSYMBOL (Qsyntax_table_p); |
2077 DEFSYMBOL (Qsyntax_table); | 2315 DEFSYMBOL (Qsyntax_table); |
2078 | 2316 |
2079 DEFSUBR (Fsyntax_table_p); | 2317 DEFSUBR (Fsyntax_table_p); |
2080 DEFSUBR (Fsyntax_table); | 2318 DEFSUBR (Fsyntax_table); |
2319 #ifdef DEBUG_XEMACS | |
2320 DEFSUBR (Fmirror_syntax_table); | |
2321 DEFSUBR (Fsyntax_cache_info); | |
2322 #endif /* DEBUG_XEMACS */ | |
2081 DEFSUBR (Fstandard_syntax_table); | 2323 DEFSUBR (Fstandard_syntax_table); |
2082 DEFSUBR (Fcopy_syntax_table); | 2324 DEFSUBR (Fcopy_syntax_table); |
2083 DEFSUBR (Fset_syntax_table); | 2325 DEFSUBR (Fset_syntax_table); |
2084 DEFSUBR (Fsyntax_designator_chars); | 2326 DEFSUBR (Fsyntax_designator_chars); |
2085 DEFSUBR (Fchar_syntax); | 2327 DEFSUBR (Fchar_syntax); |
2103 Non-nil means `forward-sexp', etc., should treat comments as whitespace. | 2345 Non-nil means `forward-sexp', etc., should treat comments as whitespace. |
2104 */ ); | 2346 */ ); |
2105 parse_sexp_ignore_comments = 0; | 2347 parse_sexp_ignore_comments = 0; |
2106 | 2348 |
2107 DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /* | 2349 DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /* |
2108 Non-nil means `forward-sexp', etc., grant `syntax-table' property. | 2350 Non-nil means `forward-sexp', etc., respect the `syntax-table' property. |
2351 This property can be placed on buffers or strings and can be used to explicitly | |
2352 specify the syntax table to be used for looking up the syntax of the chars | |
2353 having this property, or to directly specify the syntax of the chars. | |
2354 | |
2109 The value of this property should be either a syntax table, or a cons | 2355 The value of this property should be either a syntax table, or a cons |
2110 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric | 2356 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric |
2111 syntax code, MATCHCHAR being nil or the character to match (which is | 2357 syntax code, MATCHCHAR being nil or the character to match (which is |
2112 relevant only for open/close type. | 2358 relevant only when the syntax code is open/close-type). |
2113 */ ); | 2359 */ ); |
2114 lookup_syntax_properties = 1; | 2360 lookup_syntax_properties = 1; |
2115 | 2361 |
2116 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /* | 2362 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /* |
2117 Non-nil means `forward-word', etc., should treat escape chars part of words. | 2363 Non-nil means `forward-word', etc., should treat escape chars part of words. |
2138 so that copy-syntax-table will know not to try to copy from garbage */ | 2384 so that copy-syntax-table will know not to try to copy from garbage */ |
2139 Vstandard_syntax_table = Qnil; | 2385 Vstandard_syntax_table = Qnil; |
2140 Vstandard_syntax_table = Fcopy_syntax_table (Qnil); | 2386 Vstandard_syntax_table = Fcopy_syntax_table (Qnil); |
2141 staticpro (&Vstandard_syntax_table); | 2387 staticpro (&Vstandard_syntax_table); |
2142 | 2388 |
2389 Vtemp_table_for_use_updating_syntax_tables = Fmake_char_table (Qgeneric); | |
2390 staticpro (&Vtemp_table_for_use_updating_syntax_tables); | |
2391 | |
2143 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec, | 2392 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec, |
2144 Smax); | 2393 Smax); |
2145 staticpro (&Vsyntax_designator_chars_string); | 2394 staticpro (&Vsyntax_designator_chars_string); |
2146 | 2395 |
2147 fill_char_table (XCHAR_TABLE (Vstandard_syntax_table), make_int (Spunct)); | 2396 set_char_table_default (Vstandard_syntax_table, make_int (Spunct)); |
2148 | 2397 |
2149 for (i = 0; i <= 32; i++) /* Control 0 plus SPACE */ | 2398 for (i = 0; i <= 32; i++) /* Control 0 plus SPACE */ |
2150 Fput_char_table (make_char (i), make_int (Swhitespace), | 2399 Fput_char_table (make_char (i), make_int (Swhitespace), |
2151 Vstandard_syntax_table); | 2400 Vstandard_syntax_table); |
2152 for (i = 127; i <= 159; i++) /* DEL plus Control 1 */ | 2401 for (i = 127; i <= 159; i++) /* DEL plus Control 1 */ |