Mercurial > hg > xemacs-beta
annotate src/syntax.c @ 5887:6eca500211f4
Prototype for X509_check_host() has changed, detect this in configure.ac
ChangeLog addition:
2015-04-09 Aidan Kehoe <kehoea@parhasard.net>
* configure.ac:
If X509_check_host() is available, check the number of arguments
it takes. Don't use it if it takes any number of arguments other
than five. Also don't use it if <openssl/x509v3.h> does not
declare it, since if that is so there is no portable way to tell
how many arguments it should take, and so we would end up smashing
the stack.
* configure: Regenerate.
src/ChangeLog addition:
2015-04-09 Aidan Kehoe <kehoea@parhasard.net>
* tls.c:
#include <openssl/x509v3.h> for its prototype for
X509_check_host().
* tls.c (tls_open):
Pass the new fifth argument to X509_check_host().
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 09 Apr 2015 14:27:02 +0100 |
parents | 56144c8593a8 |
children |
rev | line source |
---|---|
428 | 1 /* XEmacs routines to deal with syntax tables; also word and list parsing. |
2 Copyright (C) 1985-1994 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
4 Copyright (C) 2001, 2002, 2003, 2010 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5169
diff
changeset
|
8 XEmacs is free software: you can redistribute it and/or modify it |
428 | 9 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5169
diff
changeset
|
10 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5169
diff
changeset
|
11 option) any later version. |
428 | 12 |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5169
diff
changeset
|
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 20 |
21 /* Synched up with: FSF 19.28. */ | |
22 | |
23 /* This file has been Mule-ized. */ | |
24 | |
25 #include <config.h> | |
26 #include "lisp.h" | |
27 | |
28 #include "buffer.h" | |
29 #include "syntax.h" | |
460 | 30 #include "extents.h" |
428 | 31 |
460 | 32 #define ST_COMMENT_STYLE 0x101 |
33 #define ST_STRING_STYLE 0x102 | |
34 | |
35 Lisp_Object Qsyntax_table; | |
36 int lookup_syntax_properties; | |
37 | |
428 | 38 Lisp_Object Qsyntax_table_p; |
39 | |
40 int words_include_escapes; | |
41 | |
42 int parse_sexp_ignore_comments; | |
43 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
44 /* Tell the regex routines not to QUIT. Normally there is a QUIT each |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
45 iteration in re_search_2(). We do it this way rather than change |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
46 the arguments to re_search_2() in an attempt to maintain some call |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
47 compatibility with other versions of the regex code. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
48 #### Surely this is no longer a consideration. Last sync was 19.28! */ |
428 | 49 int no_quit_in_re_search; |
50 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
51 /* The standard syntax table is automatically used in all new buffers. */ |
428 | 52 Lisp_Object Vstandard_syntax_table; |
53 | |
54 Lisp_Object Vsyntax_designator_chars_string; | |
55 | |
826 | 56 Lisp_Object Vtemp_table_for_use_updating_syntax_tables; |
57 | |
1296 | 58 /* A value that is guaranteed not be in a syntax table. */ |
59 Lisp_Object Vbogus_syntax_table_value; | |
60 | |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
61 Lisp_Object Qscan_error; |
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
62 |
826 | 63 static void syntax_cache_table_was_changed (struct buffer *buf); |
64 | |
428 | 65 /* This is the internal form of the parse state used in parse-partial-sexp. */ |
66 | |
67 struct lisp_parse_state | |
68 { | |
69 int depth; /* Depth at end of parsing */ | |
867 | 70 Ichar instring; /* -1 if not within string, else desired terminator */ |
428 | 71 int incomment; /* Nonzero if within a comment at end of parsing */ |
460 | 72 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE */ |
428 | 73 int quoted; /* Nonzero if just after an escape char at end of |
74 parsing */ | |
665 | 75 Charbpos thislevelstart;/* Char number of most recent start-of-expression |
428 | 76 at current level */ |
665 | 77 Charbpos prevlevelstart;/* Char number of start of containing expression */ |
78 Charbpos location; /* Char number at which parsing stopped */ | |
428 | 79 int mindepth; /* Minimum depth seen while scanning */ |
826 | 80 Charbpos comstr_start;/* Position just after last comment/string starter */ |
81 Lisp_Object levelstarts;/* Char numbers of starts-of-expression | |
82 of levels (starting from outermost). */ | |
428 | 83 }; |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
84 |
428 | 85 |
86 /* These variables are a cache for finding the start of a defun. | |
87 find_start_pos is the place for which the defun start was found. | |
88 find_start_value is the defun start position found for it. | |
89 find_start_buffer is the buffer it was found in. | |
90 find_start_begv is the BEGV value when it was found. | |
91 find_start_modiff is the value of MODIFF when it was found. */ | |
92 | |
665 | 93 static Charbpos find_start_pos; |
94 static Charbpos find_start_value; | |
428 | 95 static struct buffer *find_start_buffer; |
665 | 96 static Charbpos find_start_begv; |
428 | 97 static int find_start_modiff; |
98 | |
99 /* Find a defun-start that is the last one before POS (or nearly the last). | |
100 We record what we find, so that another call in the same area | |
101 can return the same value right away. */ | |
102 | |
665 | 103 static Charbpos |
104 find_defun_start (struct buffer *buf, Charbpos pos) | |
428 | 105 { |
665 | 106 Charbpos tem; |
826 | 107 struct syntax_cache *scache; |
108 | |
428 | 109 /* Use previous finding, if it's valid and applies to this inquiry. */ |
110 if (buf == find_start_buffer | |
111 /* Reuse the defun-start even if POS is a little farther on. | |
112 POS might be in the next defun, but that's ok. | |
113 Our value may not be the best possible, but will still be usable. */ | |
114 && pos <= find_start_pos + 1000 | |
115 && pos >= find_start_value | |
116 && BUF_BEGV (buf) == find_start_begv | |
117 && BUF_MODIFF (buf) == find_start_modiff) | |
118 return find_start_value; | |
119 | |
120 /* Back up to start of line. */ | |
121 tem = find_next_newline (buf, pos, -1); | |
122 | |
826 | 123 scache = setup_buffer_syntax_cache (buf, tem, 1); |
428 | 124 while (tem > BUF_BEGV (buf)) |
125 { | |
826 | 126 UPDATE_SYNTAX_CACHE_BACKWARD (scache, tem); |
460 | 127 |
428 | 128 /* Open-paren at start of line means we found our defun-start. */ |
826 | 129 if (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, tem)) == Sopen) |
428 | 130 break; |
131 /* Move to beg of previous line. */ | |
132 tem = find_next_newline (buf, tem, -2); | |
133 } | |
134 | |
135 /* Record what we found, for the next try. */ | |
136 find_start_value = tem; | |
137 find_start_buffer = buf; | |
138 find_start_modiff = BUF_MODIFF (buf); | |
139 find_start_begv = BUF_BEGV (buf); | |
140 find_start_pos = pos; | |
141 | |
142 return find_start_value; | |
143 } | |
144 | |
145 DEFUN ("syntax-table-p", Fsyntax_table_p, 1, 1, 0, /* | |
444 | 146 Return t if OBJECT is a syntax table. |
428 | 147 */ |
444 | 148 (object)) |
428 | 149 { |
444 | 150 return (CHAR_TABLEP (object) |
151 && XCHAR_TABLE_TYPE (object) == CHAR_TABLE_TYPE_SYNTAX) | |
428 | 152 ? Qt : Qnil; |
153 } | |
154 | |
155 static Lisp_Object | |
156 check_syntax_table (Lisp_Object obj, Lisp_Object default_) | |
157 { | |
158 if (NILP (obj)) | |
159 obj = default_; | |
160 while (NILP (Fsyntax_table_p (obj))) | |
161 obj = wrong_type_argument (Qsyntax_table_p, obj); | |
162 return obj; | |
163 } | |
164 | |
165 DEFUN ("syntax-table", Fsyntax_table, 0, 1, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
166 Return the current syntax table of BUFFER. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
167 BUFFER defaults to the current buffer. |
428 | 168 */ |
169 (buffer)) | |
170 { | |
171 return decode_buffer (buffer, 0)->syntax_table; | |
172 } | |
173 | |
826 | 174 #ifdef DEBUG_XEMACS |
175 | |
176 DEFUN ("mirror-syntax-table", Fmirror_syntax_table, 0, 1, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
177 Return the current mirror syntax table of BUFFER. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
178 BUFFER defaults to the current buffer. Only useful in debugging internals. |
826 | 179 */ |
180 (buffer)) | |
181 { | |
182 return decode_buffer (buffer, 0)->mirror_syntax_table; | |
183 } | |
184 | |
185 DEFUN ("syntax-cache-info", Fsyntax_cache_info, 0, 1, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
186 Return a list (START END PREV_CHANGE NEXT_CHANGE) for BUFFER's syntax cache. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
187 BUFFER defaults to the current buffer. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
188 |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
189 The elements correspond to members of struct syntax_cache of the same names. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
190 START and END should be markers. PREV_CHANGE and NEXT_CHANGE are integers. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
191 Only useful in debugging internals. |
826 | 192 */ |
193 (buffer)) | |
194 { | |
195 struct buffer *buf = decode_buffer (buffer, 0); | |
196 struct syntax_cache *cache = buf->syntax_cache; | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
197 return list4 (cache->start, cache->end, make_fixnum (cache->prev_change), |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
198 make_fixnum (cache->next_change)); |
826 | 199 } |
200 | |
201 #endif /* DEBUG_XEMACS */ | |
202 | |
428 | 203 DEFUN ("standard-syntax-table", Fstandard_syntax_table, 0, 0, 0, /* |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
204 Return the standard syntax table, used for new buffers. |
428 | 205 */ |
206 ()) | |
207 { | |
208 return Vstandard_syntax_table; | |
209 } | |
210 | |
211 DEFUN ("copy-syntax-table", Fcopy_syntax_table, 0, 1, 0, /* | |
444 | 212 Return a new syntax table which is a copy of SYNTAX-TABLE. |
213 SYNTAX-TABLE defaults to the standard syntax table. | |
428 | 214 */ |
444 | 215 (syntax_table)) |
428 | 216 { |
217 if (NILP (Vstandard_syntax_table)) | |
218 return Fmake_char_table (Qsyntax); | |
219 | |
444 | 220 syntax_table = check_syntax_table (syntax_table, Vstandard_syntax_table); |
221 return Fcopy_char_table (syntax_table); | |
428 | 222 } |
223 | |
224 DEFUN ("set-syntax-table", Fset_syntax_table, 1, 2, 0, /* | |
444 | 225 Select SYNTAX-TABLE as the new syntax table for BUFFER. |
428 | 226 BUFFER defaults to the current buffer if omitted. |
227 */ | |
444 | 228 (syntax_table, buffer)) |
428 | 229 { |
230 struct buffer *buf = decode_buffer (buffer, 0); | |
444 | 231 syntax_table = check_syntax_table (syntax_table, Qnil); |
232 buf->syntax_table = syntax_table; | |
233 buf->mirror_syntax_table = XCHAR_TABLE (syntax_table)->mirror_table; | |
826 | 234 syntax_cache_table_was_changed (buf); |
428 | 235 /* Indicate that this buffer now has a specified syntax table. */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
236 buf->local_var_flags |= XFIXNUM (buffer_local_flags.syntax_table); |
444 | 237 return syntax_table; |
428 | 238 } |
3252 | 239 |
240 | |
428 | 241 |
3252 | 242 /* |
243 * Syntax caching | |
244 */ | |
245 | |
246 /* syntax_cache object implementation */ | |
247 | |
248 static const struct memory_description syntax_cache_description_1 [] = { | |
249 { XD_LISP_OBJECT, offsetof (struct syntax_cache, object) }, | |
250 { XD_LISP_OBJECT, offsetof (struct syntax_cache, buffer) }, | |
251 { XD_LISP_OBJECT, offsetof (struct syntax_cache, syntax_table) }, | |
252 { XD_LISP_OBJECT, offsetof (struct syntax_cache, mirror_table) }, | |
253 { XD_LISP_OBJECT, offsetof (struct syntax_cache, start) }, | |
254 { XD_LISP_OBJECT, offsetof (struct syntax_cache, end) }, | |
255 { XD_END } | |
256 }; | |
257 | |
258 #ifdef NEW_GC | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
259 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("syntax-cache", syntax_cache, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
260 0, syntax_cache_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
261 Lisp_Syntax_Cache); |
3252 | 262 #else /* not NEW_GC */ |
263 | |
264 const struct sized_memory_description syntax_cache_description = { | |
265 sizeof (struct syntax_cache), | |
266 syntax_cache_description_1 | |
267 }; | |
268 #endif /* not NEW_GC */ | |
269 | |
270 /* static syntax cache utilities */ | |
271 | |
272 static void | |
273 syntax_cache_table_was_changed (struct buffer *buf) | |
274 { | |
275 struct syntax_cache *cache = buf->syntax_cache; | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
276 if (cache->source == syntax_source_buffer_table) |
3252 | 277 { |
278 cache->syntax_table = | |
279 BUFFER_SYNTAX_TABLE (buf); | |
280 cache->mirror_table = | |
281 BUFFER_MIRROR_SYNTAX_TABLE (buf); | |
282 } | |
283 } | |
284 | |
285 static void | |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
286 reset_syntax_cache_range (struct syntax_cache *cache, /* initialized cache */ |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
287 int valid_everywhere) /* non-zero if we can assume |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
288 syntax-table properties |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
289 never need be respected |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
290 in the life of the cache */ |
3252 | 291 { |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
292 if (BUFFERP (cache->object)) |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
293 { |
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
294 /* make known region zero-length and reset insertion behavior */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
295 Fset_marker (cache->start, make_fixnum (1), cache->object); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
296 Fset_marker (cache->end, make_fixnum (1), cache->object); |
5545
69de75c48efa
Alan Mackenzie's syntax cache bounds fix.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
297 Fset_marker_insertion_type (cache->start, Qnil); |
69de75c48efa
Alan Mackenzie's syntax cache bounds fix.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
298 Fset_marker_insertion_type (cache->end, Qt); |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
299 } |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
300 /* #### Should reset "cache->source" here? |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
301 If so, also reset tables. */ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
302 if (valid_everywhere) |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
303 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
304 cache->prev_change = MOST_NEGATIVE_FIXNUM; |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
305 cache->next_change = MOST_POSITIVE_FIXNUM; |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
306 } |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
307 else /* valid nowhere */ |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
308 { |
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
309 cache->prev_change = -1; |
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
310 cache->next_change = -1; |
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
311 } |
3252 | 312 } |
826 | 313 |
314 static void | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
315 init_syntax_cache (struct syntax_cache *cache, /* xzero'ed memory */ |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
316 Lisp_Object object, /* string or buffer */ |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
317 struct buffer *buffer) /* buffer; if OBJECT is a |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
318 buffer, this is the same */ |
826 | 319 { |
320 cache->object = object; | |
321 cache->buffer = buffer; | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
322 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
323 cache->source = syntax_source_buffer_table; |
1296 | 324 cache->syntax_table = |
325 BUFFER_SYNTAX_TABLE (cache->buffer); | |
326 cache->mirror_table = | |
826 | 327 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
328 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
329 /* Qnil avoids GC'ing markers, which are useless for strings. */ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
330 cache->start = BUFFERP (object) ? Fmake_marker () : Qnil; |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
331 cache->end = BUFFERP (object) ? Fmake_marker () : Qnil; |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
332 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
333 reset_syntax_cache_range (cache, 0); |
826 | 334 } |
335 | |
3252 | 336 /* external syntax cache API */ |
337 | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
338 /* At this time (hg rev 5551:dab422055bab) setup_syntax_cache() is called |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
339 directly once in setup_buffer_syntax_cache and twice in regex.c. The |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
340 calls in regex.c are obfuscated, so it's hard to tell, but it looks like |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
341 they can be called with OBJECT being a buffer. |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
342 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
343 "You are in a confusing maze of initializations, all alike." |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
344 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
345 reset_syntax_cache_range (3 uses in setup_syntax_cache, |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
346 signal_syntax_cache_extent_changed, and init_buffer_syntax_cache) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
347 reinitializes: |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
348 1. if BUFFERP(OBJECT), marker positions to 1 (giving a null range) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
349 2. if BUFFERP(OBJECT), marker movement type |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
350 3. cache range per VALID_EVERYWHERE |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
351 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
352 init_syntax_cache (2 uses in init_buffer_syntax_cache and |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
353 setup_syntax_cache) initializes: |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
354 1. source to syntax_source_buffer_table |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
355 2. syntax_table and mirror_syntax table to BUFFER's tables |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
356 3. marker members to BUFFERP(OBJECT) ? markers w/o position : Qnil |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
357 4. cache range with VALID_EVERYWHERE==0 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
358 5. object and buffer to corresponding arguments. |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
359 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
360 init_buffer_syntax_cache (1 use in buffer.c) initializes: |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
361 0. allocation of buffer's cache memory (done by allocator) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
362 1. cache memory to zero (done by allocator) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
363 2. cache to buffer's cache |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
364 3. cache members by init_syntax_cache with object==buffer==BUF. |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
365 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
366 setup_buffer_syntax_cache (1 call in font-lock.c, 1 use in search.c, |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
367 and 7 uses in this file) initializes: |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
368 0. buffer's syntax cache by calling setup_syntax_cache. |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
369 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
370 setup_buffer_syntax_cache and setup_syntax_cache are called by functions |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
371 that analyze text using character syntax. They are called repeatedly on |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
372 the same cache. init_syntax_cache and init_buffer_syntax_cache are |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
373 conceptually called once for each cache. reset_syntax_cache_range may |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
374 be called repeatedly on the same cache. The last three are for internal |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
375 use by the syntax setup code and buffer initialization. */ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
376 |
3250 | 377 struct syntax_cache * /* return CACHE or the cache of OBJECT */ |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
378 setup_syntax_cache (struct syntax_cache *cache, /* may be NULL only if |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
379 OBJECT is a buffer */ |
3250 | 380 Lisp_Object object, /* the object (if any) cache |
381 is associated with */ | |
382 struct buffer *buffer, /* the buffer to use as source | |
383 of the syntax table */ | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
384 Charxpos from, /* initial position of cache */ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
385 int count) /* direction? see code */ |
826 | 386 { |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
387 /* If OBJECT is a buffer, use its cache; else use CACHE and initialize it. |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
388 Invalidate the cache if the syntax-table property is being respected; |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
389 else make it valid for the whole object. */ |
826 | 390 if (BUFFERP (object)) |
3250 | 391 { |
392 cache = XBUFFER (object)->syntax_cache; | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
393 if (!lookup_syntax_properties) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
394 reset_syntax_cache_range (cache, 1); |
3250 | 395 } |
396 else | |
826 | 397 { |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
398 xzero (*cache); |
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
399 init_syntax_cache (cache, object, buffer); |
826 | 400 } |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
401 |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
402 if (lookup_syntax_properties) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
403 { |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
404 if (count <= 0) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
405 { |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
406 --from; |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
407 from = buffer_or_string_clip_to_accessible_char (cache->object, |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
408 from); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
409 } |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
410 /* If lookup_syntax_properties && BUFFERP (object), this |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
411 optimization may matter. */ |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
412 if (!(from >= cache->prev_change && from < cache->next_change)) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
413 update_syntax_cache (cache, from, count); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
414 } |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
415 |
1296 | 416 #ifdef NOT_WORTH_THE_EFFORT |
417 update_mirror_syntax_if_dirty (cache->mirror_table); | |
418 #endif /* NOT_WORTH_THE_EFFORT */ | |
826 | 419 return cache; |
420 } | |
421 | |
422 struct syntax_cache * | |
423 setup_buffer_syntax_cache (struct buffer *buffer, Charxpos from, int count) | |
424 { | |
425 return setup_syntax_cache (NULL, wrap_buffer (buffer), buffer, from, count); | |
426 } | |
427 | |
460 | 428 /* |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
429 Update syntax_cache CACHE to an appropriate setting for position CPOS. |
460 | 430 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
431 The sign of COUNT gives the relative position of CPOS wrt the |
460 | 432 previously valid interval. (not currently used) |
433 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
434 `syntax_cache.*_change' are the next and previous positions at which |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
435 syntax_code and c_s_t will need to be recalculated. |
460 | 436 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
437 #### Currently this code uses `get-char-property', which will return |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
438 the "last smallest" extent at a given position. In cases where |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
439 overlapping extents are defined, this code will simply use whatever |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
440 is returned by get-char-property. */ |
460 | 441 |
442 void | |
2286 | 443 update_syntax_cache (struct syntax_cache *cache, Charxpos cpos, |
444 int UNUSED (count)) | |
460 | 445 { |
446 Lisp_Object tmp_table; | |
826 | 447 Bytexpos pos; |
448 Bytexpos lim; | |
449 Bytexpos next, prev; | |
450 int at_begin = 0, at_end = 0; | |
460 | 451 |
826 | 452 if (NILP (cache->object)) |
453 return; | |
454 | |
455 pos = buffer_or_string_charxpos_to_bytexpos (cache->object, cpos); | |
456 | |
457 tmp_table = get_char_property (pos, Qsyntax_table, cache->object, | |
458 EXTENT_AT_AFTER, 0); | |
2506 | 459 lim = next_previous_single_property_change (pos, Qsyntax_table, |
460 cache->object, -1, 1, 0); | |
826 | 461 if (lim < 0) |
460 | 462 { |
5545
69de75c48efa
Alan Mackenzie's syntax cache bounds fix.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
463 next = buffer_or_string_accessible_end_byte (cache->object); |
826 | 464 at_begin = 1; |
460 | 465 } |
826 | 466 else |
467 next = lim; | |
460 | 468 |
5545
69de75c48efa
Alan Mackenzie's syntax cache bounds fix.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
469 if (pos < buffer_or_string_accessible_end_byte (cache->object)) |
826 | 470 pos = next_bytexpos (cache->object, pos); |
2506 | 471 lim = next_previous_single_property_change (pos, Qsyntax_table, |
472 cache->object, -1, 0, 0); | |
826 | 473 if (lim < 0) |
460 | 474 { |
5545
69de75c48efa
Alan Mackenzie's syntax cache bounds fix.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5544
diff
changeset
|
475 prev = buffer_or_string_accessible_begin_byte (cache->object); |
826 | 476 at_end = 1; |
460 | 477 } |
478 else | |
826 | 479 prev = lim; |
460 | 480 |
826 | 481 cache->prev_change = |
482 buffer_or_string_bytexpos_to_charxpos (cache->object, prev); | |
483 cache->next_change = | |
484 buffer_or_string_bytexpos_to_charxpos (cache->object, next); | |
460 | 485 |
826 | 486 if (BUFFERP (cache->object)) |
487 { | |
488 /* If we are at the beginning or end of buffer, check to see if there's | |
489 a zero-length `syntax-table' extent there (highly unlikely); if not, | |
490 then we can safely make the end closed, so it will take in newly | |
491 inserted text. (If such an extent is inserted, we will be informed | |
3250 | 492 through signal_syntax_cache_extent_changed().) */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
493 Fset_marker (cache->start, make_fixnum (cache->prev_change), cache->object); |
826 | 494 Fset_marker_insertion_type |
495 (cache->start, | |
496 at_begin && NILP (extent_at (prev, cache->object, Qsyntax_table, | |
497 NULL, EXTENT_AT_AT, 0)) | |
498 ? Qnil : Qt); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
499 Fset_marker (cache->end, make_fixnum (cache->next_change), cache->object); |
826 | 500 Fset_marker_insertion_type |
501 (cache->end, | |
502 at_end && NILP (extent_at (next, cache->object, Qsyntax_table, | |
503 NULL, EXTENT_AT_AT, 0)) | |
504 ? Qt : Qnil); | |
505 } | |
506 | |
507 if (!NILP (Fsyntax_table_p (tmp_table))) | |
508 { | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
509 cache->source = syntax_source_property_table; |
1296 | 510 cache->syntax_table = tmp_table; |
511 cache->mirror_table = XCHAR_TABLE (tmp_table)->mirror_table; | |
512 #ifdef NOT_WORTH_THE_EFFORT | |
513 update_mirror_syntax_if_dirty (cache->mirror_table); | |
514 #endif /* NOT_WORTH_THE_EFFORT */ | |
826 | 515 } |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
516 else if (CONSP (tmp_table) && FIXNUMP (XCAR (tmp_table))) |
826 | 517 { |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
518 cache->source = syntax_source_property_code; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
519 cache->syntax_code = XFIXNUM (XCAR (tmp_table)); |
826 | 520 } |
521 else | |
522 { | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
523 cache->source = syntax_source_buffer_table; |
1296 | 524 cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer); |
525 cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); | |
526 #ifdef NOT_WORTH_THE_EFFORT | |
527 update_mirror_syntax_if_dirty (cache->mirror_table); | |
528 #endif /* NOT_WORTH_THE_EFFORT */ | |
460 | 529 } |
530 } | |
3252 | 531 |
532 /* buffer-specific APIs used in buffer.c | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
533 #### Really unclean; the syntax cache should just be a LISP object. */ |
3252 | 534 |
535 void | |
536 mark_buffer_syntax_cache (struct buffer *buf) | |
537 { | |
538 struct syntax_cache *cache = buf->syntax_cache; | |
539 if (!cache) /* Vbuffer_defaults and such don't have caches */ | |
540 return; | |
541 mark_object (cache->object); | |
542 if (cache->buffer) | |
543 mark_object (wrap_buffer (cache->buffer)); | |
544 mark_object (cache->syntax_table); | |
545 mark_object (cache->mirror_table); | |
546 mark_object (cache->start); | |
547 mark_object (cache->end); | |
548 } | |
549 | |
550 void | |
551 init_buffer_syntax_cache (struct buffer *buf) | |
552 { | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
553 struct syntax_cache *cache; |
3252 | 554 #ifdef NEW_GC |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
555 cache = XSYNTAX_CACHE (ALLOC_NORMAL_LISP_OBJECT (syntax_cache)); |
3252 | 556 #else /* not NEW_GC */ |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
557 cache = xnew_and_zero (struct syntax_cache); |
3252 | 558 #endif /* not NEW_GC */ |
5543
fbe90e6f7a43
Initialize start and end properly (to new markers, not Qnil).
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5542
diff
changeset
|
559 |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
560 init_syntax_cache (cache, wrap_buffer (buf), buf); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
561 buf->syntax_cache = cache; |
3252 | 562 } |
563 | |
564 /* finalize the syntax cache for BUF */ | |
565 | |
566 void | |
4710
3a87551bfeb5
Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
Jerry James <james@xemacs.org>
parents:
4653
diff
changeset
|
567 uninit_buffer_syntax_cache (struct buffer *UNUSED_IF_NEW_GC (buf)) |
3252 | 568 { |
4141 | 569 #ifndef NEW_GC |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
570 if (buf->syntax_cache) |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
571 { |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
572 xfree (buf->syntax_cache); |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
573 buf->syntax_cache = 0; |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
574 } |
4141 | 575 #endif /* not NEW_GC */ |
3252 | 576 } |
577 | |
578 /* extent-specific APIs used in extents.c and insdel.c */ | |
579 | |
580 /* The syntax-table property on the range covered by EXTENT may be changing, | |
581 either because EXTENT has a syntax-table property and is being attached | |
582 or detached (this includes having its endpoints changed), or because | |
583 the value of EXTENT's syntax-table property is changing. */ | |
584 | |
585 void | |
586 signal_syntax_cache_extent_changed (EXTENT extent) | |
587 { | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
588 Lisp_Object object = Fextent_object (wrap_extent (extent)); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
589 if (BUFFERP (object)) |
3252 | 590 { |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
591 struct syntax_cache *cache = XBUFFER (object)->syntax_cache; |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
592 Bytexpos extent_start = extent_endpoint_byte (extent, 0); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
593 Bytexpos extent_end = extent_endpoint_byte (extent, 1); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
594 Bytexpos cache_start = byte_marker_position (cache->start); |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
595 Bytexpos cache_end = byte_marker_position (cache->end); |
3252 | 596 /* If the extent is entirely before or entirely after the cache |
597 range, it doesn't overlap. Otherwise, invalidate the range. */ | |
5552
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
598 if (!(extent_end < cache_start || extent_start > cache_end)) |
85210c453a97
Fix performance regression in refactored syntax cache setup.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5545
diff
changeset
|
599 reset_syntax_cache_range (cache, 0); |
3252 | 600 } |
601 } | |
602 | |
603 /* Extents have been adjusted for insertion or deletion, so we need to | |
604 refetch the start and end position of the extent */ | |
605 void | |
606 signal_syntax_cache_extent_adjust (struct buffer *buf) | |
607 { | |
608 struct syntax_cache *cache = buf->syntax_cache; | |
609 /* If the cache was invalid before, leave it that way. We only want | |
610 to update the limits of validity when they were actually valid. */ | |
611 if (cache->prev_change < 0) | |
612 return; | |
613 cache->prev_change = marker_position (cache->start); | |
614 cache->next_change = marker_position (cache->end); | |
615 } | |
616 | |
617 | |
460 | 618 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
619 /* Convert an ASCII character which represents a syntax class |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
620 into the corresponding syntax code. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
621 This is used by (search.c) skip_chars and (regex.c) regex_compile. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
622 regex_compile indexes with `c' of type int, but promises that it |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
623 is positive. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
624 #### skip_chars indexes with an Ichar, a signed type. Presumably |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
625 this is guaranteed non-negative. */ |
428 | 626 |
5542
dab422055bab
Correct array bound for syntax_code_spec.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5402
diff
changeset
|
627 const unsigned char syntax_spec_code[0200] = |
428 | 628 { 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, |
629 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | |
630 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | |
631 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | |
632 (char) Swhitespace, 0377, (char) Sstring, 0377, | |
633 (char) Smath, 0377, 0377, (char) Squote, | |
634 (char) Sopen, (char) Sclose, 0377, 0377, | |
635 0377, (char) Swhitespace, (char) Spunct, (char) Scharquote, | |
636 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | |
637 0377, 0377, 0377, 0377, | |
638 (char) Scomment, 0377, (char) Sendcomment, 0377, | |
639 (char) Sinherit, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* @, A ... */ | |
640 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | |
641 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword, | |
642 0377, 0377, 0377, 0377, (char) Sescape, 0377, 0377, (char) Ssymbol, | |
643 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, /* `, a, ... */ | |
644 0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377, | |
645 0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword, | |
460 | 646 0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377 |
428 | 647 }; |
648 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
649 /* The inverse mapping for syntax_spec_code. */ |
460 | 650 const unsigned char syntax_code_spec[] = " .w_()'\"$\\/<>@!|"; |
428 | 651 |
652 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
653 Return the string of the recognized syntax designator chars. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
654 The chars are indexed by their internal syntax codes, starting at 0. |
428 | 655 */ |
656 ()) | |
657 { | |
658 return Vsyntax_designator_chars_string; | |
659 } | |
660 | |
661 DEFUN ("char-syntax", Fchar_syntax, 1, 2, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
662 Return the syntax code of CHARACTER, designated by a character. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
663 Optional SYNTAX-TABLE defaults to the current buffer's syntax table. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
664 See `modify-syntax-entry' for the designators of the defined syntax codes. |
428 | 665 */ |
444 | 666 (character, syntax_table)) |
428 | 667 { |
826 | 668 Lisp_Object mirrortab; |
428 | 669 |
444 | 670 if (NILP (character)) |
428 | 671 { |
444 | 672 character = make_char ('\000'); |
428 | 673 } |
444 | 674 CHECK_CHAR_COERCE_INT (character); |
826 | 675 syntax_table = check_syntax_table (syntax_table, |
676 current_buffer->syntax_table); | |
677 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table; | |
678 return make_char (syntax_code_spec[(int) SYNTAX (mirrortab, | |
679 XCHAR (character))]); | |
428 | 680 } |
681 | |
682 #ifdef MULE | |
683 | |
684 enum syntaxcode | |
2286 | 685 charset_syntax (struct buffer *UNUSED (buf), Lisp_Object UNUSED (charset), |
686 int *multi_p_out) | |
428 | 687 { |
688 *multi_p_out = 1; | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
689 /* !!#### get this right |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
690 Maybe not worth it until we have Unicode inside. */ |
3152 | 691 return Sword; |
428 | 692 } |
693 | |
694 #endif | |
695 | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
696 /* #### Outside of this file, only used once, in font-lock.c. Make static? |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
697 If so, remove prototype from syntax.h. */ |
428 | 698 Lisp_Object |
867 | 699 syntax_match (Lisp_Object syntax_table, Ichar ch) |
428 | 700 { |
826 | 701 Lisp_Object code = get_char_table (ch, syntax_table); |
428 | 702 Lisp_Object code2 = code; |
703 | |
704 if (CONSP (code)) | |
705 code2 = XCAR (code); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
706 if (SYNTAX_FROM_CODE (XFIXNUM (code2)) == Sinherit) |
826 | 707 code = get_char_table (ch, Vstandard_syntax_table); |
428 | 708 |
709 return CONSP (code) ? XCDR (code) : Qnil; | |
710 } | |
711 | |
712 DEFUN ("matching-paren", Fmatching_paren, 1, 2, 0, /* | |
444 | 713 Return the matching parenthesis of CHARACTER, or nil if none. |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
714 Optional SYNTAX-TABLE defaults to the current buffer's syntax table. |
428 | 715 */ |
444 | 716 (character, syntax_table)) |
428 | 717 { |
826 | 718 Lisp_Object mirrortab; |
1315 | 719 enum syntaxcode code; |
428 | 720 |
444 | 721 CHECK_CHAR_COERCE_INT (character); |
826 | 722 syntax_table = check_syntax_table (syntax_table, |
723 current_buffer->syntax_table); | |
724 mirrortab = XCHAR_TABLE (syntax_table)->mirror_table; | |
444 | 725 code = SYNTAX (mirrortab, XCHAR (character)); |
428 | 726 if (code == Sopen || code == Sclose || code == Sstring) |
444 | 727 return syntax_match (syntax_table, XCHAR (character)); |
428 | 728 return Qnil; |
729 } | |
730 | |
731 | |
732 | |
733 #ifdef MULE | |
734 /* Return 1 if there is a word boundary between two word-constituent | |
735 characters C1 and C2 if they appear in this order, else return 0. | |
736 There is no word boundary between two word-constituent ASCII | |
737 characters. */ | |
738 #define WORD_BOUNDARY_P(c1, c2) \ | |
867 | 739 (!(ichar_ascii_p (c1) && ichar_ascii_p (c2)) \ |
428 | 740 && word_boundary_p (c1, c2)) |
741 #endif | |
742 | |
743 /* Return the position across COUNT words from FROM. | |
744 If that many words cannot be found before the end of the buffer, return 0. | |
745 COUNT negative means scan backward and stop at word beginning. */ | |
746 | |
665 | 747 Charbpos |
748 scan_words (struct buffer *buf, Charbpos from, int count) | |
428 | 749 { |
665 | 750 Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf); |
867 | 751 Ichar ch0, ch1; |
428 | 752 enum syntaxcode code; |
826 | 753 struct syntax_cache *scache = setup_buffer_syntax_cache (buf, from, count); |
460 | 754 |
428 | 755 /* #### is it really worth it to hand expand both cases? JV */ |
756 while (count > 0) | |
757 { | |
758 QUIT; | |
759 | |
760 while (1) | |
761 { | |
762 if (from == limit) | |
763 return 0; | |
764 | |
826 | 765 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 766 ch0 = BUF_FETCH_CHAR (buf, from); |
826 | 767 code = SYNTAX_FROM_CACHE (scache, ch0); |
428 | 768 |
442 | 769 from++; |
428 | 770 if (words_include_escapes |
771 && (code == Sescape || code == Scharquote)) | |
772 break; | |
773 if (code == Sword) | |
774 break; | |
775 } | |
776 | |
777 QUIT; | |
778 | |
779 while (from != limit) | |
780 { | |
826 | 781 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 782 ch1 = BUF_FETCH_CHAR (buf, from); |
826 | 783 code = SYNTAX_FROM_CACHE (scache, ch1); |
428 | 784 if (!(words_include_escapes |
785 && (code == Sescape || code == Scharquote))) | |
786 if (code != Sword | |
787 #ifdef MULE | |
788 || WORD_BOUNDARY_P (ch0, ch1) | |
434 | 789 #endif |
428 | 790 ) |
791 break; | |
792 #ifdef MULE | |
793 ch0 = ch1; | |
434 | 794 #endif |
428 | 795 from++; |
796 } | |
797 count--; | |
798 } | |
799 | |
800 while (count < 0) | |
801 { | |
802 QUIT; | |
803 | |
804 while (1) | |
805 { | |
806 if (from == limit) | |
807 return 0; | |
808 | |
826 | 809 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
428 | 810 ch1 = BUF_FETCH_CHAR (buf, from - 1); |
826 | 811 code = SYNTAX_FROM_CACHE (scache, ch1); |
460 | 812 from--; |
442 | 813 |
428 | 814 if (words_include_escapes |
815 && (code == Sescape || code == Scharquote)) | |
816 break; | |
817 if (code == Sword) | |
818 break; | |
819 } | |
820 | |
821 QUIT; | |
822 | |
823 while (from != limit) | |
824 { | |
826 | 825 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
428 | 826 ch0 = BUF_FETCH_CHAR (buf, from - 1); |
826 | 827 code = SYNTAX_FROM_CACHE (scache, ch0); |
460 | 828 |
428 | 829 if (!(words_include_escapes |
830 && (code == Sescape || code == Scharquote))) | |
831 if (code != Sword | |
832 #ifdef MULE | |
833 || WORD_BOUNDARY_P (ch0, ch1) | |
834 #endif | |
835 ) | |
836 break; | |
837 #ifdef MULE | |
838 ch1 = ch0; | |
839 #endif | |
840 from--; | |
841 } | |
842 count++; | |
843 } | |
844 | |
845 return from; | |
846 } | |
847 | |
446 | 848 DEFUN ("forward-word", Fforward_word, 0, 2, "_p", /* |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
849 Move point forward COUNT words in BUFFER (backward if COUNT is negative). |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
850 COUNT defaults to 1, and BUFFER defaults to the current buffer. |
428 | 851 |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
852 Return t if the motion successfully crosses COUNT words, otherwise nil (if |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
853 the motion would cross the buffer boundary). |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
854 |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
855 The characters that are moved over are added to the region if the region |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
856 is active, the Shift key is held down, a motion key is used to invoke this |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
857 command, and `shifted-motion-keys-select-region' is non-nil; see |
462 | 858 the documentation for this variable for more details. |
428 | 859 */ |
860 (count, buffer)) | |
861 { | |
665 | 862 Charbpos val; |
428 | 863 struct buffer *buf = decode_buffer (buffer, 0); |
446 | 864 EMACS_INT n; |
865 | |
866 if (NILP (count)) | |
867 n = 1; | |
868 else | |
869 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
870 CHECK_FIXNUM (count); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
871 n = XFIXNUM (count); |
446 | 872 } |
428 | 873 |
446 | 874 val = scan_words (buf, BUF_PT (buf), n); |
875 if (val) | |
428 | 876 { |
446 | 877 BUF_SET_PT (buf, val); |
878 return Qt; | |
879 } | |
880 else | |
881 { | |
882 BUF_SET_PT (buf, n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf)); | |
428 | 883 return Qnil; |
884 } | |
885 } | |
886 | |
887 static void scan_sexps_forward (struct buffer *buf, | |
888 struct lisp_parse_state *, | |
665 | 889 Charbpos from, Charbpos end, |
428 | 890 int targetdepth, int stopbefore, |
891 Lisp_Object oldstate, | |
892 int commentstop); | |
893 | |
894 static int | |
665 | 895 find_start_of_comment (struct buffer *buf, Charbpos from, Charbpos stop, |
460 | 896 int comstyle) |
428 | 897 { |
867 | 898 Ichar c; |
428 | 899 enum syntaxcode code; |
900 | |
901 /* Look back, counting the parity of string-quotes, | |
902 and recording the comment-starters seen. | |
903 When we reach a safe place, assume that's not in a string; | |
904 then step the main scan to the earliest comment-starter seen | |
905 an even number of string quotes away from the safe place. | |
906 | |
907 OFROM[I] is position of the earliest comment-starter seen | |
908 which is I+2X quotes from the comment-end. | |
909 PARITY is current parity of quotes from the comment end. */ | |
910 int parity = 0; | |
867 | 911 Ichar my_stringend = 0; |
428 | 912 int string_lossage = 0; |
665 | 913 Charbpos comment_end = from; |
914 Charbpos comstart_pos = 0; | |
428 | 915 int comstart_parity = 0; |
916 int styles_match_p = 0; | |
460 | 917 /* mask to match comment styles against; for ST_COMMENT_STYLE, this |
918 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */ | |
919 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A; | |
826 | 920 struct syntax_cache *scache = buf->syntax_cache; |
428 | 921 |
922 /* At beginning of range to scan, we're outside of strings; | |
923 that determines quote parity to the comment-end. */ | |
924 while (from != stop) | |
925 { | |
460 | 926 int syncode; |
927 | |
428 | 928 /* Move back and examine a character. */ |
929 from--; | |
826 | 930 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
428 | 931 |
932 c = BUF_FETCH_CHAR (buf, from); | |
826 | 933 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
934 code = SYNTAX_FROM_CODE (syncode); | |
428 | 935 |
936 /* is this a 1-char comment end sequence? if so, try | |
937 to see if style matches previously extracted mask */ | |
938 if (code == Sendcomment) | |
939 { | |
940 styles_match_p = | |
460 | 941 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask; |
428 | 942 } |
943 | |
944 /* or are we looking at a 1-char comment start sequence | |
945 of the style matching mask? */ | |
460 | 946 else if (code == Scomment) |
428 | 947 { |
460 | 948 styles_match_p = |
949 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask; | |
428 | 950 } |
951 | |
460 | 952 /* otherwise, is this a 2-char comment end or start sequence? */ |
953 else if (from > stop) | |
954 do | |
955 { | |
956 /* 2-char comment end sequence? */ | |
957 if (SYNTAX_CODE_END_SECOND_P (syncode)) | |
958 { | |
959 int prev_syncode; | |
826 | 960 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
460 | 961 prev_syncode = |
1315 | 962 SYNTAX_CODE_FROM_CACHE (scache, |
963 BUF_FETCH_CHAR (buf, from - 1)); | |
460 | 964 |
965 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) | |
966 { | |
967 code = Sendcomment; | |
968 styles_match_p = | |
826 | 969 SYNTAX_CODES_COMMENT_MASK_END (prev_syncode, |
970 syncode) & mask; | |
460 | 971 from--; |
826 | 972 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
460 | 973 c = BUF_FETCH_CHAR (buf, from); |
974 | |
975 /* Found a comment-end sequence, so skip past the | |
976 check for a comment-start */ | |
977 break; | |
978 } | |
979 } | |
980 | |
981 /* 2-char comment start sequence? */ | |
982 if (SYNTAX_CODE_START_SECOND_P (syncode)) | |
983 { | |
984 int prev_syncode; | |
826 | 985 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
460 | 986 prev_syncode = |
1315 | 987 SYNTAX_CODE_FROM_CACHE (scache, |
988 BUF_FETCH_CHAR (buf, from - 1)); | |
460 | 989 |
990 if (SYNTAX_CODES_START_P (prev_syncode, syncode)) | |
991 { | |
992 code = Scomment; | |
993 styles_match_p = | |
826 | 994 SYNTAX_CODES_COMMENT_MASK_START (prev_syncode, |
995 syncode) & mask; | |
460 | 996 from--; |
826 | 997 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
460 | 998 c = BUF_FETCH_CHAR (buf, from); |
999 } | |
1000 } | |
1001 } while (0); | |
428 | 1002 |
1003 /* Ignore escaped characters. */ | |
1004 if (char_quoted (buf, from)) | |
1005 continue; | |
1006 | |
1007 /* Track parity of quotes. */ | |
1008 if (code == Sstring) | |
1009 { | |
1010 parity ^= 1; | |
1011 if (my_stringend == 0) | |
1012 my_stringend = c; | |
1013 /* If we have two kinds of string delimiters. | |
1014 There's no way to grok this scanning backwards. */ | |
1015 else if (my_stringend != c) | |
1016 string_lossage = 1; | |
1017 } | |
1018 | |
460 | 1019 if (code == Sstring_fence || code == Scomment_fence) |
1020 { | |
1021 parity ^= 1; | |
1022 if (my_stringend == 0) | |
1023 my_stringend = | |
1024 code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE; | |
1025 /* If we have two kinds of string delimiters. | |
1026 There's no way to grok this scanning backwards. */ | |
1027 else if (my_stringend != (code == Sstring_fence | |
1028 ? ST_STRING_STYLE : ST_COMMENT_STYLE)) | |
1029 string_lossage = 1; | |
1030 } | |
1031 | |
428 | 1032 /* Record comment-starters according to that |
1033 quote-parity to the comment-end. */ | |
1034 if (code == Scomment && styles_match_p) | |
1035 { | |
1036 comstart_parity = parity; | |
1037 comstart_pos = from; | |
1038 } | |
1039 | |
1040 /* If we find another earlier comment-ender, | |
1041 any comment-starts earlier than that don't count | |
1042 (because they go with the earlier comment-ender). */ | |
1043 if (code == Sendcomment && styles_match_p) | |
1044 break; | |
1045 | |
1046 /* Assume a defun-start point is outside of strings. */ | |
1047 if (code == Sopen | |
1048 && (from == stop || BUF_FETCH_CHAR (buf, from - 1) == '\n')) | |
1049 break; | |
1050 } | |
1051 | |
1052 if (comstart_pos == 0) | |
1053 from = comment_end; | |
1054 /* If the earliest comment starter | |
1055 is followed by uniform paired string quotes or none, | |
1056 we know it can't be inside a string | |
1057 since if it were then the comment ender would be inside one. | |
1058 So it does start a comment. Skip back to it. */ | |
1059 else if (comstart_parity == 0 && !string_lossage) | |
1060 from = comstart_pos; | |
1061 else | |
1062 { | |
1063 /* We had two kinds of string delimiters mixed up | |
1064 together. Decode this going forwards. | |
1065 Scan fwd from the previous comment ender | |
1066 to the one in question; this records where we | |
1067 last passed a comment starter. */ | |
1068 | |
1069 struct lisp_parse_state state; | |
1070 scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end), | |
1071 comment_end - 1, -10000, 0, Qnil, 0); | |
1072 if (state.incomment) | |
460 | 1073 from = state.comstr_start; |
428 | 1074 else |
1075 /* We can't grok this as a comment; scan it normally. */ | |
1076 from = comment_end; | |
826 | 1077 UPDATE_SYNTAX_CACHE_FORWARD (scache, from - 1); |
428 | 1078 } |
1079 return from; | |
1080 } | |
1081 | |
665 | 1082 static Charbpos |
826 | 1083 find_end_of_comment (struct buffer *buf, Charbpos from, Charbpos stop, |
1084 int comstyle) | |
428 | 1085 { |
1086 int c; | |
460 | 1087 int prev_code; |
1088 /* mask to match comment styles against; for ST_COMMENT_STYLE, this | |
1089 will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */ | |
1090 int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A; | |
826 | 1091 struct syntax_cache *scache = buf->syntax_cache; |
428 | 1092 |
460 | 1093 /* This is only called by functions which have already set up the |
1094 syntax_cache and are keeping it up-to-date */ | |
428 | 1095 while (1) |
1096 { | |
1097 if (from == stop) | |
1098 { | |
1099 return -1; | |
1100 } | |
460 | 1101 |
826 | 1102 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 1103 c = BUF_FETCH_CHAR (buf, from); |
460 | 1104 |
1105 /* Test for generic comments */ | |
1106 if (comstyle == ST_COMMENT_STYLE) | |
1107 { | |
826 | 1108 if (SYNTAX_FROM_CACHE (scache, c) == Scomment_fence) |
460 | 1109 { |
1110 from++; | |
826 | 1111 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 1112 break; |
1113 } | |
1114 from++; | |
1115 continue; /* No need to test other comment styles in a | |
1116 generic comment */ | |
1117 } | |
1118 else | |
1119 | |
826 | 1120 if (SYNTAX_FROM_CACHE (scache, c) == Sendcomment |
460 | 1121 && SYNTAX_CODE_MATCHES_1CHAR_P |
826 | 1122 (SYNTAX_CODE_FROM_CACHE (scache, c), mask)) |
428 | 1123 /* we have encountered a comment end of the same style |
1124 as the comment sequence which began this comment | |
1125 section */ | |
460 | 1126 { |
1127 from++; | |
826 | 1128 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 1129 break; |
1130 } | |
428 | 1131 |
826 | 1132 prev_code = SYNTAX_CODE_FROM_CACHE (scache, c); |
428 | 1133 from++; |
826 | 1134 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 1135 if (from < stop |
460 | 1136 && SYNTAX_CODES_MATCH_END_P |
1137 (prev_code, | |
826 | 1138 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)), |
460 | 1139 mask) |
1140 | |
1141 ) | |
428 | 1142 /* we have encountered a comment end of the same style |
1143 as the comment sequence which began this comment | |
1144 section */ | |
460 | 1145 { |
1146 from++; | |
826 | 1147 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 1148 break; |
1149 } | |
428 | 1150 } |
1151 return from; | |
1152 } | |
1153 | |
1154 | |
1155 /* #### between FSF 19.23 and 19.28 there are some changes to the logic | |
1156 in this function (and minor changes to find_start_of_comment(), | |
1157 above, which is part of Fforward_comment() in FSF). Attempts to port | |
1158 that logic made this function break, so I'm leaving it out. If anyone | |
1159 ever complains about this function not working properly, take a look | |
1160 at those changes. --ben */ | |
1161 | |
446 | 1162 DEFUN ("forward-comment", Fforward_comment, 0, 2, 0, /* |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1163 Move forward across COUNT comments in BUFFER (backwards if COUNT is negative). |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1164 COUNT defaults to 1, and BUFFER defaults to the current buffer. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1165 |
428 | 1166 Stop scanning if we find something other than a comment or whitespace. |
1167 Set point to where scanning stops. | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1168 Return t if the motion successfully crosses COUNT comments, otherwise nil (if |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1169 the motion would cross the buffer boundary or encounters a noncomment token). |
428 | 1170 */ |
444 | 1171 (count, buffer)) |
428 | 1172 { |
665 | 1173 Charbpos from; |
1174 Charbpos stop; | |
867 | 1175 Ichar c; |
428 | 1176 enum syntaxcode code; |
460 | 1177 int syncode; |
444 | 1178 EMACS_INT n; |
428 | 1179 struct buffer *buf = decode_buffer (buffer, 0); |
826 | 1180 struct syntax_cache *scache; |
1181 | |
446 | 1182 if (NILP (count)) |
1183 n = 1; | |
1184 else | |
1185 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1186 CHECK_FIXNUM (count); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1187 n = XFIXNUM (count); |
446 | 1188 } |
428 | 1189 |
1190 from = BUF_PT (buf); | |
1191 | |
826 | 1192 scache = setup_buffer_syntax_cache (buf, from, n); |
444 | 1193 while (n > 0) |
428 | 1194 { |
1195 QUIT; | |
1196 | |
1197 stop = BUF_ZV (buf); | |
1198 while (from < stop) | |
1199 { | |
460 | 1200 int comstyle = 0; /* mask for finding matching comment style */ |
428 | 1201 |
1202 if (char_quoted (buf, from)) | |
1203 { | |
1204 from++; | |
1205 continue; | |
1206 } | |
1207 | |
826 | 1208 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 1209 c = BUF_FETCH_CHAR (buf, from); |
826 | 1210 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1211 code = SYNTAX_FROM_CODE (syncode); | |
428 | 1212 |
1213 if (code == Scomment) | |
1214 { | |
1215 /* we have encountered a single character comment start | |
1216 sequence, and we are ignoring all text inside comments. | |
1217 we must record the comment style this character begins | |
1218 so that later, only a comment end of the same style actually | |
1219 ends the comment section */ | |
460 | 1220 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) |
1221 == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
428 | 1222 } |
1223 | |
460 | 1224 else if (code == Scomment_fence) |
1225 { | |
1226 from++; | |
1227 code = Scomment; | |
1228 comstyle = ST_COMMENT_STYLE; | |
1229 } | |
1230 | |
428 | 1231 else if (from < stop |
460 | 1232 && SYNTAX_CODE_START_FIRST_P (syncode)) |
428 | 1233 { |
460 | 1234 int next_syncode; |
826 | 1235 UPDATE_SYNTAX_CACHE_FORWARD (scache, from + 1); |
460 | 1236 next_syncode = |
826 | 1237 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from + 1)); |
460 | 1238 |
1239 if (SYNTAX_CODES_START_P (syncode, next_syncode)) | |
1240 { | |
1241 /* we have encountered a 2char comment start sequence and we | |
1242 are ignoring all text inside comments. we must record | |
1243 the comment style this sequence begins so that later, | |
1244 only a comment end of the same style actually ends | |
1245 the comment section */ | |
1246 code = Scomment; | |
1247 comstyle = | |
1248 SYNTAX_CODES_COMMENT_MASK_START (syncode, next_syncode) | |
1249 == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
1250 from++; | |
1251 } | |
428 | 1252 } |
1253 | |
1254 if (code == Scomment) | |
1255 { | |
826 | 1256 Charbpos newfrom = find_end_of_comment (buf, from, stop, |
1257 comstyle); | |
428 | 1258 if (newfrom < 0) |
1259 { | |
1260 /* we stopped because from==stop */ | |
1261 BUF_SET_PT (buf, stop); | |
1262 return Qnil; | |
1263 } | |
1264 from = newfrom; | |
1265 | |
1266 /* We have skipped one comment. */ | |
1267 break; | |
1268 } | |
1269 else if (code != Swhitespace | |
1270 && code != Sendcomment | |
1271 && code != Scomment ) | |
1272 { | |
1273 BUF_SET_PT (buf, from); | |
1274 return Qnil; | |
1275 } | |
1276 from++; | |
1277 } | |
1278 | |
1279 /* End of comment reached */ | |
444 | 1280 n--; |
428 | 1281 } |
1282 | |
444 | 1283 while (n < 0) |
428 | 1284 { |
1285 QUIT; | |
1286 | |
1287 stop = BUF_BEGV (buf); | |
1288 while (from > stop) | |
1289 { | |
460 | 1290 int comstyle = 0; /* mask for finding matching comment style */ |
428 | 1291 |
1292 from--; | |
1293 if (char_quoted (buf, from)) | |
1294 { | |
1295 from--; | |
1296 continue; | |
1297 } | |
1298 | |
1299 c = BUF_FETCH_CHAR (buf, from); | |
826 | 1300 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1301 code = SYNTAX_FROM_CODE (syncode); | |
428 | 1302 |
1303 if (code == Sendcomment) | |
1304 { | |
1305 /* we have found a single char end comment. we must record | |
1306 the comment style encountered so that later, we can match | |
1307 only the proper comment begin sequence of the same style */ | |
460 | 1308 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) |
1309 == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
1310 } | |
1311 | |
1312 else if (code == Scomment_fence) | |
1313 { | |
1314 code = Sendcomment; | |
1315 comstyle = ST_COMMENT_STYLE; | |
428 | 1316 } |
1317 | |
1318 else if (from > stop | |
460 | 1319 && SYNTAX_CODE_END_SECOND_P (syncode)) |
428 | 1320 { |
460 | 1321 int prev_syncode; |
826 | 1322 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
460 | 1323 prev_syncode = |
826 | 1324 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1)); |
460 | 1325 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) |
1326 { | |
1327 /* We must record the comment style encountered so that | |
1328 later, we can match only the proper comment begin | |
1329 sequence of the same style. */ | |
1330 code = Sendcomment; | |
1331 comstyle = SYNTAX_CODES_COMMENT_MASK_END | |
1332 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
1333 from--; | |
1334 } | |
428 | 1335 } |
1336 | |
1337 if (code == Sendcomment) | |
1338 { | |
460 | 1339 from = find_start_of_comment (buf, from, stop, comstyle); |
428 | 1340 break; |
1341 } | |
1342 | |
1343 else if (code != Swhitespace | |
460 | 1344 && code != Scomment |
1345 && code != Sendcomment) | |
428 | 1346 { |
1347 BUF_SET_PT (buf, from + 1); | |
1348 return Qnil; | |
1349 } | |
1350 } | |
1351 | |
444 | 1352 n++; |
428 | 1353 } |
1354 | |
1355 BUF_SET_PT (buf, from); | |
1356 return Qt; | |
1357 } | |
1358 | |
1359 | |
1360 Lisp_Object | |
665 | 1361 scan_lists (struct buffer *buf, Charbpos from, int count, int depth, |
444 | 1362 int sexpflag, int noerror) |
428 | 1363 { |
665 | 1364 Charbpos stop; |
867 | 1365 Ichar c; |
428 | 1366 int quoted; |
1367 int mathexit = 0; | |
1368 enum syntaxcode code; | |
460 | 1369 int syncode; |
428 | 1370 int min_depth = depth; /* Err out if depth gets less than this. */ |
826 | 1371 struct syntax_cache *scache; |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1372 Charbpos last_good = from; |
826 | 1373 |
428 | 1374 if (depth > 0) min_depth = 0; |
1375 | |
826 | 1376 scache = setup_buffer_syntax_cache (buf, from, count); |
428 | 1377 while (count > 0) |
1378 { | |
1379 QUIT; | |
1380 | |
1381 stop = BUF_ZV (buf); | |
1382 while (from < stop) | |
1383 { | |
460 | 1384 int comstyle = 0; /* mask for finding matching comment style */ |
428 | 1385 |
826 | 1386 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 1387 c = BUF_FETCH_CHAR (buf, from); |
826 | 1388 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1389 code = SYNTAX_FROM_CODE (syncode); | |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1390 if (depth == min_depth) |
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1391 last_good = from; |
428 | 1392 from++; |
1393 | |
1394 /* a 1-char comment start sequence */ | |
1395 if (code == Scomment && parse_sexp_ignore_comments) | |
1396 { | |
460 | 1397 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) == |
1398 SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
428 | 1399 } |
1400 | |
1401 /* else, a 2-char comment start sequence? */ | |
1402 else if (from < stop | |
460 | 1403 && SYNTAX_CODE_START_FIRST_P (syncode) |
428 | 1404 && parse_sexp_ignore_comments) |
1405 { | |
460 | 1406 int next_syncode; |
826 | 1407 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 1408 next_syncode = |
826 | 1409 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)); |
460 | 1410 |
1411 if (SYNTAX_CODES_START_P (syncode, next_syncode)) | |
1412 { | |
826 | 1413 /* we have encountered a comment start sequence and we |
1414 are ignoring all text inside comments. we must record | |
1415 the comment style this sequence begins so that later, | |
1416 only a comment end of the same style actually ends | |
1417 the comment section */ | |
1418 code = Scomment; | |
460 | 1419 comstyle = SYNTAX_CODES_COMMENT_MASK_START |
1420 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
826 | 1421 from++; |
1422 } | |
428 | 1423 } |
826 | 1424 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 1425 |
460 | 1426 if (SYNTAX_CODE_PREFIX (syncode)) |
428 | 1427 continue; |
1428 | |
1429 switch (code) | |
1430 { | |
1431 case Sescape: | |
1432 case Scharquote: | |
1433 if (from == stop) goto lose; | |
1434 from++; | |
1435 /* treat following character as a word constituent */ | |
1436 case Sword: | |
1437 case Ssymbol: | |
1438 if (depth || !sexpflag) break; | |
1439 /* This word counts as a sexp; return at end of it. */ | |
1440 while (from < stop) | |
1441 { | |
826 | 1442 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
1443 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from))) | |
428 | 1444 { |
1445 case Scharquote: | |
1446 case Sescape: | |
1447 from++; | |
1448 if (from == stop) goto lose; | |
1449 break; | |
1450 case Sword: | |
1451 case Ssymbol: | |
1452 case Squote: | |
1453 break; | |
1454 default: | |
1455 goto done; | |
1456 } | |
1457 from++; | |
1458 } | |
1459 goto done; | |
1460 | |
460 | 1461 case Scomment_fence: |
1462 comstyle = ST_COMMENT_STYLE; | |
428 | 1463 case Scomment: |
1464 if (!parse_sexp_ignore_comments) | |
1465 break; | |
826 | 1466 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 1467 { |
665 | 1468 Charbpos newfrom = |
460 | 1469 find_end_of_comment (buf, from, stop, comstyle); |
428 | 1470 if (newfrom < 0) |
1471 { | |
1472 /* we stopped because from == stop in search forward */ | |
1473 from = stop; | |
1474 if (depth == 0) | |
1475 goto done; | |
1476 goto lose; | |
1477 } | |
1478 from = newfrom; | |
1479 } | |
1480 break; | |
1481 | |
1482 case Smath: | |
1483 if (!sexpflag) | |
1484 break; | |
1485 if (from != stop && c == BUF_FETCH_CHAR (buf, from)) | |
1486 from++; | |
1487 if (mathexit) | |
1488 { | |
1489 mathexit = 0; | |
1490 goto close1; | |
1491 } | |
1492 mathexit = 1; | |
1493 | |
1494 case Sopen: | |
1495 if (!++depth) goto done; | |
1496 break; | |
1497 | |
1498 case Sclose: | |
1499 close1: | |
1500 if (!--depth) goto done; | |
1501 if (depth < min_depth) | |
1502 { | |
444 | 1503 if (noerror) |
428 | 1504 return Qnil; |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1505 signal_error_2 (Qscan_error, |
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1506 "Containing expression ends prematurely", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1507 make_fixnum (last_good), make_fixnum (from)); |
428 | 1508 } |
1509 break; | |
1510 | |
460 | 1511 case Sstring_fence: |
428 | 1512 case Sstring: |
1513 { | |
867 | 1514 Ichar stringterm; |
460 | 1515 |
1516 if (code != Sstring_fence) | |
1517 { | |
826 | 1518 /* XEmacs change: call syntax_match on character */ |
867 | 1519 Ichar ch = BUF_FETCH_CHAR (buf, from - 1); |
460 | 1520 Lisp_Object stermobj = |
1296 | 1521 syntax_match (scache->syntax_table, ch); |
428 | 1522 |
1523 if (CHARP (stermobj)) | |
1524 stringterm = XCHAR (stermobj); | |
1525 else | |
1526 stringterm = ch; | |
460 | 1527 } |
1528 else | |
1529 stringterm = '\0'; /* avoid compiler warnings */ | |
428 | 1530 |
1531 while (1) | |
1532 { | |
1533 if (from >= stop) | |
1534 goto lose; | |
826 | 1535 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 1536 c = BUF_FETCH_CHAR (buf, from); |
1537 if (code == Sstring | |
1538 ? c == stringterm | |
826 | 1539 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence) |
428 | 1540 break; |
460 | 1541 |
826 | 1542 switch (SYNTAX_FROM_CACHE (scache, c)) |
428 | 1543 { |
1544 case Scharquote: | |
1545 case Sescape: | |
1546 from++; | |
1547 break; | |
1548 default: | |
1549 break; | |
1550 } | |
1551 from++; | |
1552 } | |
1553 from++; | |
1554 if (!depth && sexpflag) goto done; | |
1555 break; | |
1556 } | |
1557 | |
1558 default: | |
1559 break; | |
1560 } | |
1561 } | |
1562 | |
1563 /* Reached end of buffer. Error if within object, | |
1564 return nil if between */ | |
1565 if (depth) goto lose; | |
1566 | |
1567 return Qnil; | |
1568 | |
1569 /* End of object reached */ | |
1570 done: | |
1571 count--; | |
1572 } | |
1573 | |
1574 while (count < 0) | |
1575 { | |
1576 QUIT; | |
1577 | |
1578 stop = BUF_BEGV (buf); | |
1579 while (from > stop) | |
1580 { | |
460 | 1581 int comstyle = 0; /* mask for finding matching comment style */ |
428 | 1582 |
1583 from--; | |
826 | 1584 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
428 | 1585 quoted = char_quoted (buf, from); |
1586 if (quoted) | |
460 | 1587 { |
428 | 1588 from--; |
826 | 1589 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
460 | 1590 } |
428 | 1591 |
1592 c = BUF_FETCH_CHAR (buf, from); | |
826 | 1593 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1594 code = SYNTAX_FROM_CODE (syncode); | |
428 | 1595 |
1596 if (code == Sendcomment && parse_sexp_ignore_comments) | |
1597 { | |
1598 /* we have found a single char end comment. we must record | |
1599 the comment style encountered so that later, we can match | |
1600 only the proper comment begin sequence of the same style */ | |
460 | 1601 comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) |
1602 == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
428 | 1603 } |
1604 | |
1605 else if (from > stop | |
460 | 1606 && SYNTAX_CODE_END_SECOND_P (syncode) |
428 | 1607 && !char_quoted (buf, from - 1) |
1608 && parse_sexp_ignore_comments) | |
1609 { | |
460 | 1610 int prev_syncode; |
826 | 1611 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
1612 prev_syncode = | |
1613 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from - 1)); | |
460 | 1614 |
1615 if (SYNTAX_CODES_END_P (prev_syncode, syncode)) | |
1616 { | |
428 | 1617 /* we must record the comment style encountered so that |
1618 later, we can match only the proper comment begin | |
1619 sequence of the same style */ | |
1620 code = Sendcomment; | |
460 | 1621 comstyle = SYNTAX_CODES_COMMENT_MASK_END |
1622 (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
428 | 1623 from--; |
1624 } | |
460 | 1625 } |
428 | 1626 |
460 | 1627 if (SYNTAX_CODE_PREFIX (syncode)) |
428 | 1628 continue; |
1629 | |
434 | 1630 switch (quoted ? Sword : code) |
428 | 1631 { |
1632 case Sword: | |
1633 case Ssymbol: | |
1634 if (depth || !sexpflag) break; | |
1635 /* This word counts as a sexp; count object finished after | |
1636 passing it. */ | |
1637 while (from > stop) | |
1638 { | |
826 | 1639 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from); |
428 | 1640 quoted = char_quoted (buf, from - 1); |
1641 | |
1642 if (quoted) | |
1643 from--; | |
1644 if (! (quoted | |
1645 || (syncode = | |
826 | 1646 SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, |
1647 from - 1))) | |
428 | 1648 == Sword |
1649 || syncode == Ssymbol | |
1650 || syncode == Squote)) | |
1651 goto done2; | |
1652 from--; | |
1653 } | |
1654 goto done2; | |
1655 | |
1656 case Smath: | |
1657 if (!sexpflag) | |
1658 break; | |
1659 if (from != stop && c == BUF_FETCH_CHAR (buf, from - 1)) | |
1660 from--; | |
1661 if (mathexit) | |
1662 { | |
1663 mathexit = 0; | |
1664 goto open2; | |
1665 } | |
1666 mathexit = 1; | |
1667 | |
1668 case Sclose: | |
1669 if (!++depth) goto done2; | |
1670 break; | |
1671 | |
1672 case Sopen: | |
1673 open2: | |
1674 if (!--depth) goto done2; | |
1675 if (depth < min_depth) | |
1676 { | |
444 | 1677 if (noerror) |
428 | 1678 return Qnil; |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1679 signal_error_2 (Qscan_error, |
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1680 "Containing expression ends prematurely", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1681 make_fixnum (last_good), make_fixnum (from)); |
428 | 1682 } |
1683 break; | |
1684 | |
460 | 1685 case Scomment_fence: |
1686 comstyle = ST_COMMENT_STYLE; | |
428 | 1687 case Sendcomment: |
1688 if (parse_sexp_ignore_comments) | |
460 | 1689 from = find_start_of_comment (buf, from, stop, comstyle); |
428 | 1690 break; |
1691 | |
460 | 1692 case Sstring_fence: |
428 | 1693 case Sstring: |
1694 { | |
867 | 1695 Ichar stringterm; |
460 | 1696 |
1697 if (code != Sstring_fence) | |
1698 { | |
428 | 1699 /* XEmacs change: call syntax_match() on character */ |
867 | 1700 Ichar ch = BUF_FETCH_CHAR (buf, from); |
460 | 1701 Lisp_Object stermobj = |
1296 | 1702 syntax_match (scache->syntax_table, ch); |
428 | 1703 |
1704 if (CHARP (stermobj)) | |
1705 stringterm = XCHAR (stermobj); | |
1706 else | |
1707 stringterm = ch; | |
460 | 1708 } |
1709 else | |
1710 stringterm = '\0'; /* avoid compiler warnings */ | |
428 | 1711 |
1712 while (1) | |
1713 { | |
1714 if (from == stop) goto lose; | |
460 | 1715 |
826 | 1716 UPDATE_SYNTAX_CACHE_BACKWARD (scache, from - 1); |
460 | 1717 c = BUF_FETCH_CHAR (buf, from - 1); |
1718 | |
1719 if ((code == Sstring | |
1720 ? c == stringterm | |
826 | 1721 : SYNTAX_FROM_CACHE (scache, c) == Sstring_fence) |
460 | 1722 && !char_quoted (buf, from - 1)) |
1723 { | |
428 | 1724 break; |
460 | 1725 } |
1726 | |
428 | 1727 from--; |
1728 } | |
1729 from--; | |
1730 if (!depth && sexpflag) goto done2; | |
1731 break; | |
1732 } | |
1733 } | |
1734 } | |
1735 | |
1736 /* Reached start of buffer. Error if within object, | |
1737 return nil if between */ | |
1738 if (depth) goto lose; | |
1739 | |
1740 return Qnil; | |
1741 | |
1742 done2: | |
1743 count++; | |
1744 } | |
1745 | |
1746 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1747 return (make_fixnum (from)); |
428 | 1748 |
1749 lose: | |
444 | 1750 if (!noerror) |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
1751 signal_error_2 (Qscan_error, "Unbalanced parentheses", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1752 make_fixnum (last_good), make_fixnum (from)); |
428 | 1753 return Qnil; |
1754 } | |
1755 | |
1756 int | |
665 | 1757 char_quoted (struct buffer *buf, Charbpos pos) |
428 | 1758 { |
1759 enum syntaxcode code; | |
665 | 1760 Charbpos beg = BUF_BEGV (buf); |
428 | 1761 int quoted = 0; |
665 | 1762 Charbpos startpos = pos; |
826 | 1763 struct syntax_cache *scache = buf->syntax_cache; |
460 | 1764 |
1765 while (pos > beg) | |
1766 { | |
826 | 1767 UPDATE_SYNTAX_CACHE_BACKWARD (scache, pos - 1); |
1768 code = SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, pos - 1)); | |
428 | 1769 |
460 | 1770 if (code != Scharquote && code != Sescape) |
1771 break; | |
1772 pos--; | |
1773 quoted = !quoted; | |
1774 } | |
1775 | |
826 | 1776 UPDATE_SYNTAX_CACHE (scache, startpos); |
428 | 1777 return quoted; |
1778 } | |
1779 | |
1780 DEFUN ("scan-lists", Fscan_lists, 3, 5, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1781 Scan from position FROM across COUNT lists starting from nesting DEPTH. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1782 Returns the position thus found. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1783 Optional BUFFER defaults to the current buffer. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1784 If optional NOERROR is non-nil, scan-lists will return nil instead of |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1785 signalling an error when attempting to cross a buffer boundary. |
428 | 1786 |
1787 If DEPTH is nonzero, paren depth begins counting from that value, | |
1788 only places where the depth in parentheses becomes zero | |
1789 are candidates for stopping; COUNT such places are counted. | |
1790 Thus, a positive value for DEPTH means go out levels. | |
1791 | |
1792 Comments are ignored if `parse-sexp-ignore-comments' is non-nil. | |
1793 | |
1794 If the beginning or end of (the accessible part of) the buffer is reached | |
1795 and the depth is wrong, an error is signaled. | |
1796 If the depth is right but the count is not used up, nil is returned. | |
1797 | |
1798 */ | |
444 | 1799 (from, count, depth, buffer, noerror)) |
428 | 1800 { |
1801 struct buffer *buf; | |
1802 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1803 CHECK_FIXNUM (from); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1804 CHECK_FIXNUM (count); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1805 CHECK_FIXNUM (depth); |
428 | 1806 buf = decode_buffer (buffer, 0); |
1807 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1808 return scan_lists (buf, XFIXNUM (from), XFIXNUM (count), XFIXNUM (depth), 0, |
444 | 1809 !NILP (noerror)); |
428 | 1810 } |
1811 | |
1812 DEFUN ("scan-sexps", Fscan_sexps, 2, 4, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1813 Scan from position FROM by COUNT balanced expressions. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1814 Returns the position thus found. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1815 |
428 | 1816 If COUNT is negative, scan backwards. |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1817 Optional BUFFER defaults to the current buffer. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1818 If optional NOERROR is non-nil, scan-sexps will return nil instead of |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1819 signalling an error. |
428 | 1820 |
1821 Comments are ignored if `parse-sexp-ignore-comments' is non-nil. | |
1822 | |
1823 If the beginning or end of (the accessible part of) the buffer is reached | |
1824 in the middle of a parenthetical grouping, an error is signaled. | |
1825 If the beginning or end is reached between groupings | |
1826 but before count is used up, nil is returned. | |
1827 */ | |
444 | 1828 (from, count, buffer, noerror)) |
428 | 1829 { |
1830 struct buffer *buf = decode_buffer (buffer, 0); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1831 CHECK_FIXNUM (from); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1832 CHECK_FIXNUM (count); |
428 | 1833 |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1834 return scan_lists (buf, XFIXNUM (from), XFIXNUM (count), 0, 1, !NILP (noerror)); |
428 | 1835 } |
1836 | |
1837 DEFUN ("backward-prefix-chars", Fbackward_prefix_chars, 0, 1, 0, /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1838 Move point backward over any number of chars with quote or prefix syntax. |
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
1839 Optional BUFFER defaults to the current buffer. |
428 | 1840 */ |
1841 (buffer)) | |
1842 { | |
1843 struct buffer *buf = decode_buffer (buffer, 0); | |
665 | 1844 Charbpos beg = BUF_BEGV (buf); |
1845 Charbpos pos = BUF_PT (buf); | |
867 | 1846 Ichar c = '\0'; /* initialize to avoid compiler warnings */ |
826 | 1847 struct syntax_cache *scache; |
1848 | |
1849 scache = setup_buffer_syntax_cache (buf, pos, -1); | |
428 | 1850 |
1851 while (pos > beg && !char_quoted (buf, pos - 1) | |
460 | 1852 /* Previous statement updates syntax table. */ |
826 | 1853 && (SYNTAX_FROM_CACHE (scache, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote |
1854 || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (scache, c)))) | |
428 | 1855 pos--; |
1856 | |
1857 BUF_SET_PT (buf, pos); | |
1858 | |
1859 return Qnil; | |
1860 } | |
1861 | |
1862 /* Parse forward from FROM to END, | |
1863 assuming that FROM has state OLDSTATE (nil means FROM is start of function), | |
1864 and return a description of the state of the parse at END. | |
1865 If STOPBEFORE is nonzero, stop at the start of an atom. | |
1866 If COMMENTSTOP is nonzero, stop at the start of a comment. */ | |
1867 | |
1868 static void | |
1869 scan_sexps_forward (struct buffer *buf, struct lisp_parse_state *stateptr, | |
665 | 1870 Charbpos from, Charbpos end, |
428 | 1871 int targetdepth, int stopbefore, |
1872 Lisp_Object oldstate, | |
1873 int commentstop) | |
1874 { | |
1875 struct lisp_parse_state state; | |
1876 | |
1877 enum syntaxcode code; | |
1878 struct level { int last, prev; }; | |
1879 struct level levelstart[100]; | |
1880 struct level *curlevel = levelstart; | |
1881 struct level *endlevel = levelstart + 100; | |
1882 int depth; /* Paren depth of current scanning location. | |
1883 level - levelstart equals this except | |
1884 when the depth becomes negative. */ | |
1885 int mindepth; /* Lowest DEPTH value seen. */ | |
1886 int start_quoted = 0; /* Nonzero means starting after a char quote */ | |
460 | 1887 int boundary_stop = commentstop == -1; |
428 | 1888 Lisp_Object tem; |
826 | 1889 struct syntax_cache *scache; |
1890 | |
1891 scache = setup_buffer_syntax_cache (buf, from, 1); | |
428 | 1892 if (NILP (oldstate)) |
1893 { | |
1894 depth = 0; | |
1895 state.instring = -1; | |
1896 state.incomment = 0; | |
1897 state.comstyle = 0; /* comment style a by default */ | |
460 | 1898 state.comstr_start = -1; /* no comment/string seen. */ |
428 | 1899 } |
1900 else | |
1901 { | |
1902 tem = Fcar (oldstate); /* elt 0, depth */ | |
1903 if (!NILP (tem)) | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1904 depth = XFIXNUM (tem); |
428 | 1905 else |
1906 depth = 0; | |
1907 | |
1908 oldstate = Fcdr (oldstate); | |
1909 oldstate = Fcdr (oldstate); | |
1910 oldstate = Fcdr (oldstate); | |
1911 tem = Fcar (oldstate); /* elt 3, instring */ | |
460 | 1912 state.instring = ( !NILP (tem) |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1913 ? ( FIXNUMP (tem) ? XFIXNUM (tem) : ST_STRING_STYLE) |
460 | 1914 : -1); |
428 | 1915 |
460 | 1916 oldstate = Fcdr (oldstate); |
1917 tem = Fcar (oldstate); /* elt 4, incomment */ | |
428 | 1918 state.incomment = !NILP (tem); |
1919 | |
1920 oldstate = Fcdr (oldstate); | |
1921 tem = Fcar (oldstate); /* elt 5, follows-quote */ | |
1922 start_quoted = !NILP (tem); | |
1923 | |
1924 /* if the eighth element of the list is nil, we are in comment style | |
3025 | 1925 a; if it is t, we are in comment style b; if it is `syntax-table', |
460 | 1926 we are in a generic comment */ |
428 | 1927 oldstate = Fcdr (oldstate); |
1928 oldstate = Fcdr (oldstate); | |
460 | 1929 tem = Fcar (oldstate); /* elt 7, comment style a/b/fence */ |
1930 state.comstyle = NILP (tem) ? 0 : ( EQ (tem, Qsyntax_table) | |
1931 ? ST_COMMENT_STYLE : 1 ); | |
1932 | |
1933 oldstate = Fcdr (oldstate); /* elt 8, start of last comment/string */ | |
1934 tem = Fcar (oldstate); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1935 state.comstr_start = NILP (tem) ? -1 : XFIXNUM (tem); |
460 | 1936 |
1937 /* elt 9, char numbers of starts-of-expression of levels | |
1938 (starting from outermost). */ | |
1939 oldstate = Fcdr (oldstate); | |
1940 tem = Fcar (oldstate); /* elt 9, intermediate data for | |
1941 continuation of parsing (subject | |
1942 to change). */ | |
1943 while (!NILP (tem)) /* >= second enclosing sexps. */ | |
1944 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1945 curlevel->last = XFIXNUM (Fcar (tem)); |
460 | 1946 if (++curlevel == endlevel) |
826 | 1947 stack_overflow ("Nesting too deep for parser", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
1948 make_fixnum (curlevel - levelstart)); |
460 | 1949 curlevel->prev = -1; |
1950 curlevel->last = -1; | |
1951 tem = Fcdr (tem); | |
1952 } | |
428 | 1953 } |
1954 state.quoted = 0; | |
1955 mindepth = depth; | |
1956 | |
1957 curlevel->prev = -1; | |
1958 curlevel->last = -1; | |
1959 | |
1960 /* Enter the loop at a place appropriate for initial state. */ | |
1961 | |
1962 if (state.incomment) goto startincomment; | |
1963 if (state.instring >= 0) | |
1964 { | |
1965 if (start_quoted) goto startquotedinstring; | |
1966 goto startinstring; | |
1967 } | |
1968 if (start_quoted) goto startquoted; | |
1969 | |
1970 while (from < end) | |
1971 { | |
867 | 1972 Ichar c; |
460 | 1973 int syncode; |
1974 | |
428 | 1975 QUIT; |
1976 | |
826 | 1977 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 1978 c = BUF_FETCH_CHAR (buf, from); |
826 | 1979 syncode = SYNTAX_CODE_FROM_CACHE (scache, c); |
1980 code = SYNTAX_FROM_CODE (syncode); | |
428 | 1981 from++; |
1982 | |
1983 /* record the comment style we have entered so that only the | |
1984 comment-ender sequence (or single char) of the same style | |
1985 actually terminates the comment section. */ | |
460 | 1986 if (code == Scomment) |
1987 { | |
1988 state.comstyle = | |
1989 SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) | |
1990 == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
1991 state.comstr_start = from - 1; | |
1992 } | |
1993 | |
1994 /* a generic comment delimiter? */ | |
1995 else if (code == Scomment_fence) | |
1996 { | |
1997 state.comstyle = ST_COMMENT_STYLE; | |
1998 state.comstr_start = from - 1; | |
1999 code = Scomment; | |
428 | 2000 } |
2001 | |
2002 else if (from < end && | |
460 | 2003 SYNTAX_CODE_START_FIRST_P (syncode)) |
428 | 2004 { |
460 | 2005 int next_syncode; |
826 | 2006 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 2007 next_syncode = |
826 | 2008 SYNTAX_CODE_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from)); |
460 | 2009 |
2010 if (SYNTAX_CODES_START_P (syncode, next_syncode)) | |
2011 { | |
428 | 2012 code = Scomment; |
460 | 2013 state.comstyle = SYNTAX_CODES_COMMENT_MASK_START |
2014 (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1; | |
2015 state.comstr_start = from - 1; | |
428 | 2016 from++; |
826 | 2017 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 2018 } |
428 | 2019 } |
2020 | |
460 | 2021 if (SYNTAX_CODE_PREFIX (syncode)) |
428 | 2022 continue; |
2023 switch (code) | |
2024 { | |
2025 case Sescape: | |
2026 case Scharquote: | |
2027 if (stopbefore) goto stop; /* this arg means stop at sexp start */ | |
2028 curlevel->last = from - 1; | |
2029 startquoted: | |
2030 if (from == end) goto endquoted; | |
2031 from++; | |
2032 goto symstarted; | |
2033 /* treat following character as a word constituent */ | |
2034 case Sword: | |
2035 case Ssymbol: | |
2036 if (stopbefore) goto stop; /* this arg means stop at sexp start */ | |
2037 curlevel->last = from - 1; | |
2038 symstarted: | |
2039 while (from < end) | |
2040 { | |
826 | 2041 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
2042 switch (SYNTAX_FROM_CACHE (scache, BUF_FETCH_CHAR (buf, from))) | |
428 | 2043 { |
2044 case Scharquote: | |
2045 case Sescape: | |
2046 from++; | |
2047 if (from == end) goto endquoted; | |
2048 break; | |
2049 case Sword: | |
2050 case Ssymbol: | |
2051 case Squote: | |
2052 break; | |
2053 default: | |
2054 goto symdone; | |
2055 } | |
2056 from++; | |
2057 } | |
2058 symdone: | |
2059 curlevel->prev = curlevel->last; | |
2060 break; | |
2061 | |
2062 case Scomment: | |
2063 state.incomment = 1; | |
460 | 2064 if (commentstop || boundary_stop) goto done; |
428 | 2065 startincomment: |
460 | 2066 if (commentstop == 1) |
428 | 2067 goto done; |
826 | 2068 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
428 | 2069 { |
826 | 2070 Charbpos newfrom = find_end_of_comment (buf, from, end, |
2071 state.comstyle); | |
428 | 2072 if (newfrom < 0) |
2073 { | |
2074 /* we terminated search because from == end */ | |
2075 from = end; | |
2076 goto done; | |
2077 } | |
2078 from = newfrom; | |
2079 } | |
2080 state.incomment = 0; | |
2081 state.comstyle = 0; /* reset the comment style */ | |
460 | 2082 if (boundary_stop) goto done; |
428 | 2083 break; |
2084 | |
2085 case Sopen: | |
2086 if (stopbefore) goto stop; /* this arg means stop at sexp start */ | |
2087 depth++; | |
2088 curlevel->last = from - 1; | |
2089 if (++curlevel == endlevel) | |
826 | 2090 stack_overflow ("Nesting too deep for parser", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2091 make_fixnum (curlevel - levelstart)); |
428 | 2092 curlevel->prev = -1; |
2093 curlevel->last = -1; | |
2094 if (targetdepth == depth) goto done; | |
2095 break; | |
2096 | |
2097 case Sclose: | |
2098 depth--; | |
2099 if (depth < mindepth) | |
2100 mindepth = depth; | |
2101 if (curlevel != levelstart) | |
2102 curlevel--; | |
2103 curlevel->prev = curlevel->last; | |
2104 if (targetdepth == depth) goto done; | |
2105 break; | |
2106 | |
2107 case Sstring: | |
460 | 2108 case Sstring_fence: |
2109 state.comstr_start = from - 1; | |
428 | 2110 if (stopbefore) goto stop; /* this arg means stop at sexp start */ |
2111 curlevel->last = from - 1; | |
460 | 2112 if (code == Sstring_fence) |
428 | 2113 { |
460 | 2114 state.instring = ST_STRING_STYLE; |
2115 } | |
2116 else | |
2117 { | |
2118 /* XEmacs change: call syntax_match() on character */ | |
867 | 2119 Ichar ch = BUF_FETCH_CHAR (buf, from - 1); |
460 | 2120 Lisp_Object stermobj = |
1296 | 2121 syntax_match (scache->syntax_table, ch); |
428 | 2122 |
2123 if (CHARP (stermobj)) | |
2124 state.instring = XCHAR (stermobj); | |
2125 else | |
2126 state.instring = ch; | |
2127 } | |
460 | 2128 if (boundary_stop) goto done; |
428 | 2129 startinstring: |
2130 while (1) | |
2131 { | |
460 | 2132 enum syntaxcode temp_code; |
2133 | |
428 | 2134 if (from >= end) goto done; |
460 | 2135 |
826 | 2136 UPDATE_SYNTAX_CACHE_FORWARD (scache, from); |
460 | 2137 c = BUF_FETCH_CHAR (buf, from); |
826 | 2138 temp_code = SYNTAX_FROM_CACHE (scache, c); |
460 | 2139 |
2140 if ( | |
2141 state.instring != ST_STRING_STYLE && | |
2142 temp_code == Sstring && | |
2143 c == state.instring) break; | |
2144 | |
2145 switch (temp_code) | |
428 | 2146 { |
460 | 2147 case Sstring_fence: |
2148 if (state.instring == ST_STRING_STYLE) | |
2149 goto string_end; | |
2150 break; | |
428 | 2151 case Scharquote: |
2152 case Sescape: | |
2153 { | |
2154 from++; | |
2155 startquotedinstring: | |
2156 if (from >= end) goto endquoted; | |
2157 break; | |
2158 } | |
2159 default: | |
2160 break; | |
2161 } | |
2162 from++; | |
2163 } | |
460 | 2164 string_end: |
428 | 2165 state.instring = -1; |
2166 curlevel->prev = curlevel->last; | |
2167 from++; | |
460 | 2168 if (boundary_stop) goto done; |
428 | 2169 break; |
2170 | |
2171 case Smath: | |
2172 break; | |
2173 | |
2174 case Swhitespace: | |
2175 case Spunct: | |
2176 case Squote: | |
2177 case Sendcomment: | |
460 | 2178 case Scomment_fence: |
428 | 2179 case Sinherit: |
2180 case Smax: | |
2181 break; | |
2182 } | |
2183 } | |
2184 goto done; | |
2185 | |
2186 stop: /* Here if stopping before start of sexp. */ | |
2187 from--; /* We have just fetched the char that starts it; */ | |
2188 goto done; /* but return the position before it. */ | |
2189 | |
2190 endquoted: | |
2191 state.quoted = 1; | |
2192 done: | |
2193 state.depth = depth; | |
2194 state.mindepth = mindepth; | |
2195 state.thislevelstart = curlevel->prev; | |
2196 state.prevlevelstart | |
2197 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last; | |
2198 state.location = from; | |
460 | 2199 state.levelstarts = Qnil; |
2200 while (--curlevel >= levelstart) | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2201 state.levelstarts = Fcons (make_fixnum (curlevel->last), |
460 | 2202 state.levelstarts); |
428 | 2203 |
2204 *stateptr = state; | |
2205 } | |
2206 | |
2207 DEFUN ("parse-partial-sexp", Fparse_partial_sexp, 2, 7, 0, /* | |
2208 Parse Lisp syntax starting at FROM until TO; return status of parse at TO. | |
2209 Parsing stops at TO or when certain criteria are met; | |
2210 point is set to where parsing stops. | |
444 | 2211 If fifth arg OLDSTATE is omitted or nil, |
428 | 2212 parsing assumes that FROM is the beginning of a function. |
460 | 2213 Value is a list of nine elements describing final state of parsing: |
428 | 2214 0. depth in parens. |
2215 1. character address of start of innermost containing list; nil if none. | |
2216 2. character address of start of last complete sexp terminated. | |
2217 3. non-nil if inside a string. | |
460 | 2218 (It is the character that will terminate the string, |
2219 or t if the string should be terminated by an explicit | |
2220 `syntax-table' property.) | |
428 | 2221 4. t if inside a comment. |
2222 5. t if following a quote character. | |
2223 6. the minimum paren-depth encountered during this scan. | |
460 | 2224 7. nil if in comment style a, or not in a comment; t if in comment style b; |
2225 `syntax-table' if given by an explicit `syntax-table' property. | |
2226 8. character address of start of last comment or string; nil if none. | |
2227 9. Intermediate data for continuation of parsing (subject to change). | |
428 | 2228 If third arg TARGETDEPTH is non-nil, parsing stops if the depth |
2229 in parentheses becomes equal to TARGETDEPTH. | |
2230 Fourth arg STOPBEFORE non-nil means stop when come to | |
2231 any character that starts a sexp. | |
460 | 2232 Fifth arg OLDSTATE is a nine-element list like what this function returns. |
428 | 2233 It is used to initialize the state of the parse. Its second and third |
2234 elements are ignored. | |
460 | 2235 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. If it |
2236 is `syntax-table', stop after the start of a comment or a string, or after | |
2237 the end of a comment or string. | |
826 | 2238 Seventh arg BUFFER specifies the buffer to do the parsing in, and defaults |
2239 to the current buffer. | |
428 | 2240 */ |
2241 (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer)) | |
2242 { | |
2243 struct lisp_parse_state state; | |
2244 int target; | |
665 | 2245 Charbpos start, end; |
428 | 2246 struct buffer *buf = decode_buffer (buffer, 0); |
2247 Lisp_Object val; | |
2248 | |
2249 if (!NILP (targetdepth)) | |
2250 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2251 CHECK_FIXNUM (targetdepth); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2252 target = XFIXNUM (targetdepth); |
428 | 2253 } |
2254 else | |
2255 target = -100000; /* We won't reach this depth */ | |
2256 | |
2257 get_buffer_range_char (buf, from, to, &start, &end, 0); | |
2258 scan_sexps_forward (buf, &state, start, end, | |
2259 target, !NILP (stopbefore), oldstate, | |
460 | 2260 (NILP (commentstop) |
2261 ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1))); | |
428 | 2262 BUF_SET_PT (buf, state.location); |
2263 | |
2264 /* reverse order */ | |
2265 val = Qnil; | |
460 | 2266 val = Fcons (state.levelstarts, val); |
2267 val = Fcons ((state.incomment || (state.instring >= 0)) | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2268 ? make_fixnum (state.comstr_start) : Qnil, val); |
460 | 2269 val = Fcons (state.comstyle ? (state.comstyle == ST_COMMENT_STYLE |
2270 ? Qsyntax_table : Qt) : Qnil, val); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2271 val = Fcons (make_fixnum (state.mindepth), val); |
428 | 2272 val = Fcons (state.quoted ? Qt : Qnil, val); |
2273 val = Fcons (state.incomment ? Qt : Qnil, val); | |
460 | 2274 val = Fcons (state.instring < 0 |
2275 ? Qnil | |
2276 : (state.instring == ST_STRING_STYLE | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2277 ? Qt : make_fixnum (state.instring)), val); |
826 | 2278 val = Fcons (state.thislevelstart < 0 ? Qnil : |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2279 make_fixnum (state.thislevelstart), val); |
826 | 2280 val = Fcons (state.prevlevelstart < 0 ? Qnil : |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2281 make_fixnum (state.prevlevelstart), val); |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2282 val = Fcons (make_fixnum (state.depth), val); |
428 | 2283 |
2284 return val; | |
2285 } | |
2286 | |
2287 | |
2288 /* Updating of the mirror syntax table. | |
2289 | |
1296 | 2290 Each syntax table has a corresponding mirror table in it. Whenever we |
2291 make a change to a syntax table, we set a dirty flag. When accessing a | |
2292 value from the mirror table and the table is dirty, we call | |
2293 update_syntax_table() to clean it up. | |
428 | 2294 |
2295 #### We really only need to map over the changed range. | |
2296 | |
2297 If we change the standard syntax table, we need to map over | |
2298 all tables because any of them could be inheriting from the | |
2299 standard syntax table. | |
2300 | |
2301 When `set-syntax-table' is called, we set the buffer's mirror | |
2302 syntax table as well. | |
2303 */ | |
2304 | |
826 | 2305 static int |
2286 | 2306 copy_to_mirrortab (struct chartab_range *range, Lisp_Object UNUSED (table), |
826 | 2307 Lisp_Object val, void *arg) |
428 | 2308 { |
5013 | 2309 Lisp_Object mirrortab = GET_LISP_FROM_VOID (arg); |
428 | 2310 |
2311 if (CONSP (val)) | |
2312 val = XCAR (val); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2313 if (SYNTAX_FROM_CODE (XFIXNUM (val)) != Sinherit) |
826 | 2314 put_char_table (mirrortab, range, val); |
2315 return 0; | |
2316 } | |
2317 | |
2318 static int | |
2286 | 2319 copy_if_not_already_present (struct chartab_range *range, |
2320 Lisp_Object UNUSED (table), | |
826 | 2321 Lisp_Object val, void *arg) |
2322 { | |
5013 | 2323 Lisp_Object mirrortab = GET_LISP_FROM_VOID (arg); |
826 | 2324 if (CONSP (val)) |
2325 val = XCAR (val); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2326 if (SYNTAX_FROM_CODE (XFIXNUM (val)) != Sinherit) |
826 | 2327 { |
2328 Lisp_Object existing = | |
1296 | 2329 updating_mirror_get_range_char_table (range, mirrortab, |
2330 Vbogus_syntax_table_value); | |
826 | 2331 if (NILP (existing)) |
2332 /* nothing at all */ | |
1296 | 2333 put_char_table (mirrortab, range, val); |
2334 else if (!EQ (existing, Vbogus_syntax_table_value)) | |
826 | 2335 /* full */ |
2336 ; | |
2337 else | |
2338 { | |
2339 Freset_char_table (Vtemp_table_for_use_updating_syntax_tables); | |
2340 copy_char_table_range | |
1296 | 2341 (mirrortab, Vtemp_table_for_use_updating_syntax_tables, range); |
2342 put_char_table (mirrortab, range, val); | |
826 | 2343 copy_char_table_range |
1296 | 2344 (Vtemp_table_for_use_updating_syntax_tables, mirrortab, range); |
826 | 2345 } |
428 | 2346 } |
826 | 2347 |
428 | 2348 return 0; |
2349 } | |
2350 | |
2351 static void | |
826 | 2352 update_just_this_syntax_table (Lisp_Object table) |
428 | 2353 { |
2354 struct chartab_range range; | |
826 | 2355 Lisp_Object mirrortab = XCHAR_TABLE (table)->mirror_table; |
2356 | |
1296 | 2357 assert (!XCHAR_TABLE (table)->mirror_table_p); |
826 | 2358 range.type = CHARTAB_RANGE_ALL; |
2359 Freset_char_table (mirrortab); | |
1296 | 2360 |
826 | 2361 /* First, copy the tables values other than inherit into the mirror |
2362 table. Then, for tables other than the standard syntax table, map | |
2363 over the standard table, copying values into the mirror table only if | |
2364 entries don't already exist in that table. (The copying step requires | |
2365 another mapping.) | |
2366 */ | |
428 | 2367 |
5013 | 2368 map_char_table (table, &range, copy_to_mirrortab, STORE_LISP_IN_VOID (mirrortab)); |
826 | 2369 /* second clause catches bootstrapping problems when initializing the |
2370 standard syntax table */ | |
2371 if (!EQ (table, Vstandard_syntax_table) && !NILP (Vstandard_syntax_table)) | |
1296 | 2372 map_char_table (Vstandard_syntax_table, &range, |
5013 | 2373 copy_if_not_already_present, STORE_LISP_IN_VOID (mirrortab)); |
3152 | 2374 /* The resetting made the default be Qnil. Put it back to Sword. */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2375 set_char_table_default (mirrortab, make_fixnum (Sword)); |
1296 | 2376 XCHAR_TABLE (mirrortab)->dirty = 0; |
428 | 2377 } |
2378 | |
2379 /* Called from chartab.c when a change is made to a syntax table. | |
2380 If this is the standard syntax table, we need to recompute | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
2381 *all* syntax tables. Otherwise we just recompute this one. */ |
428 | 2382 |
2383 void | |
826 | 2384 update_syntax_table (Lisp_Object table) |
428 | 2385 { |
1296 | 2386 Lisp_Object nonmirror = XCHAR_TABLE (table)->mirror_table; |
2387 assert (XCHAR_TABLE (table)->mirror_table_p); | |
2388 if (EQ (nonmirror, Vstandard_syntax_table)) | |
428 | 2389 { |
2390 Lisp_Object syntab; | |
2391 | |
2392 for (syntab = Vall_syntax_tables; !NILP (syntab); | |
2393 syntab = XCHAR_TABLE (syntab)->next_table) | |
826 | 2394 update_just_this_syntax_table (syntab); |
428 | 2395 } |
2396 else | |
1296 | 2397 update_just_this_syntax_table (nonmirror); |
428 | 2398 } |
2399 | |
2400 | |
2401 /************************************************************************/ | |
2402 /* initialization */ | |
2403 /************************************************************************/ | |
2404 | |
2405 void | |
2406 syms_of_syntax (void) | |
2407 { | |
3092 | 2408 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
2409 INIT_LISP_OBJECT (syntax_cache); |
3092 | 2410 #endif /* NEW_GC */ |
563 | 2411 DEFSYMBOL (Qsyntax_table_p); |
2412 DEFSYMBOL (Qsyntax_table); | |
428 | 2413 |
2414 DEFSUBR (Fsyntax_table_p); | |
2415 DEFSUBR (Fsyntax_table); | |
826 | 2416 #ifdef DEBUG_XEMACS |
2417 DEFSUBR (Fmirror_syntax_table); | |
2418 DEFSUBR (Fsyntax_cache_info); | |
2419 #endif /* DEBUG_XEMACS */ | |
428 | 2420 DEFSUBR (Fstandard_syntax_table); |
2421 DEFSUBR (Fcopy_syntax_table); | |
2422 DEFSUBR (Fset_syntax_table); | |
2423 DEFSUBR (Fsyntax_designator_chars); | |
2424 DEFSUBR (Fchar_syntax); | |
2425 DEFSUBR (Fmatching_paren); | |
2426 /* DEFSUBR (Fmodify_syntax_entry); now in Lisp. */ | |
2427 /* DEFSUBR (Fdescribe_syntax); now in Lisp. */ | |
2428 | |
2429 DEFSUBR (Fforward_word); | |
2430 | |
2431 DEFSUBR (Fforward_comment); | |
2432 DEFSUBR (Fscan_lists); | |
2433 DEFSUBR (Fscan_sexps); | |
2434 DEFSUBR (Fbackward_prefix_chars); | |
2435 DEFSUBR (Fparse_partial_sexp); | |
4912
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
2436 |
e99033b7e05c
use more specific `scan-error' in scan-lists to be GNU compatible
Ben Wing <ben@xemacs.org>
parents:
4759
diff
changeset
|
2437 DEFERROR_STANDARD (Qscan_error, Qsyntax_error); |
428 | 2438 } |
2439 | |
2440 void | |
2441 vars_of_syntax (void) | |
2442 { | |
2443 DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments /* | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
2444 If non-nil, `forward-sexp' etc. treat comments as whitespace. |
428 | 2445 */ ); |
434 | 2446 parse_sexp_ignore_comments = 0; |
428 | 2447 |
460 | 2448 DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /* |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
2449 If non-nil, `forward-sexp' etc. respect the `syntax-table' text property. |
826 | 2450 This property can be placed on buffers or strings and can be used to explicitly |
2451 specify the syntax table to be used for looking up the syntax of the chars | |
2452 having this property, or to directly specify the syntax of the chars. | |
2453 | |
460 | 2454 The value of this property should be either a syntax table, or a cons |
2455 of the form (SYNTAXCODE . MATCHCHAR), SYNTAXCODE being the numeric | |
2456 syntax code, MATCHCHAR being nil or the character to match (which is | |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
2457 relevant only when the syntax code is of an open or close type). |
460 | 2458 */ ); |
2459 lookup_syntax_properties = 1; | |
2460 | |
428 | 2461 DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /* |
5544
c2301b2c88c8
Improve documentation of syntax table internals.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
5543
diff
changeset
|
2462 If non-nil, `forward-word' etc. treat escape characters as parts of words. |
428 | 2463 */ ); |
434 | 2464 words_include_escapes = 0; |
428 | 2465 |
2466 no_quit_in_re_search = 0; | |
1296 | 2467 |
2468 Vbogus_syntax_table_value = make_float (0.0); | |
2469 staticpro (&Vbogus_syntax_table_value); | |
428 | 2470 } |
2471 | |
2472 static void | |
3540 | 2473 define_standard_syntax (const UExtbyte *p, enum syntaxcode syn) |
428 | 2474 { |
2475 for (; *p; p++) | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2476 Fput_char_table (make_char (*p), make_fixnum (syn), Vstandard_syntax_table); |
428 | 2477 } |
2478 | |
2479 void | |
2480 complex_vars_of_syntax (void) | |
2481 { | |
867 | 2482 Ichar i; |
3540 | 2483 const UExtbyte *p; /* Latin-1, not internal format. */ |
2484 | |
2485 #define SET_RANGE_SYNTAX(start, end, syntax) \ | |
2486 do { \ | |
2487 for (i = start; i <= end; i++) \ | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2488 Fput_char_table(make_char(i), make_fixnum(syntax), \ |
3540 | 2489 Vstandard_syntax_table); \ |
2490 } while (0) | |
2491 | |
2492 /* Set this now, so first buffer creation can refer to it. | |
2493 | |
2494 Make it nil before calling copy-syntax-table so that copy-syntax-table | |
2495 will know not to try to copy from garbage */ | |
428 | 2496 Vstandard_syntax_table = Qnil; |
2497 Vstandard_syntax_table = Fcopy_syntax_table (Qnil); | |
2498 staticpro (&Vstandard_syntax_table); | |
2499 | |
826 | 2500 Vtemp_table_for_use_updating_syntax_tables = Fmake_char_table (Qgeneric); |
2501 staticpro (&Vtemp_table_for_use_updating_syntax_tables); | |
2502 | |
428 | 2503 Vsyntax_designator_chars_string = make_string_nocopy (syntax_code_spec, |
2504 Smax); | |
2505 staticpro (&Vsyntax_designator_chars_string); | |
2506 | |
3540 | 2507 /* Default character syntax is word. */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2508 set_char_table_default (Vstandard_syntax_table, make_fixnum (Sword)); |
428 | 2509 |
3540 | 2510 /* Control 0; treat as punctuation */ |
2511 SET_RANGE_SYNTAX(0, 32, Spunct); | |
428 | 2512 |
3544 | 2513 /* The whitespace--overwriting some of the above changes. |
2514 | |
2515 String literals are const char *s, not const unsigned char *s. */ | |
4653
25e5e5346d31
?\012 is whitespace, as it always should have been, thank you Karl Kleinpaste.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4141
diff
changeset
|
2516 define_standard_syntax((const UExtbyte *)" \t\015\014\012", Swhitespace); |
3540 | 2517 |
2518 /* DEL plus Control 1 */ | |
2519 SET_RANGE_SYNTAX(127, 159, Spunct); | |
2520 | |
3544 | 2521 define_standard_syntax ((const UExtbyte *)"\"", Sstring); |
2522 define_standard_syntax ((const UExtbyte *)"\\", Sescape); | |
2523 define_standard_syntax ((const UExtbyte *)"_-+*/&|<>=", Ssymbol); | |
2524 define_standard_syntax ((const UExtbyte *)".,;:?!#@~^'`", Spunct); | |
428 | 2525 |
3544 | 2526 for (p = (const UExtbyte *)"()[]{}"; *p; p+=2) |
428 | 2527 { |
2528 Fput_char_table (make_char (p[0]), | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2529 Fcons (make_fixnum (Sopen), make_char (p[1])), |
428 | 2530 Vstandard_syntax_table); |
2531 Fput_char_table (make_char (p[1]), | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5552
diff
changeset
|
2532 Fcons (make_fixnum (Sclose), make_char (p[0])), |
428 | 2533 Vstandard_syntax_table); |
2534 } | |
3540 | 2535 |
2536 /* Latin 1 "symbols." This contrasts with the FSF, where they're word | |
2537 constituents. */ | |
2538 SET_RANGE_SYNTAX(0240, 0277, Ssymbol); | |
2539 | |
2540 /* The guillemets. These are not parentheses, in contrast to what the old | |
2541 code did. */ | |
3569 | 2542 define_standard_syntax((const UExtbyte *)"\253\273", Spunct); |
3540 | 2543 |
2544 /* The inverted exclamation mark, and the multiplication and division | |
2545 signs. */ | |
3544 | 2546 define_standard_syntax((const UExtbyte *)"\241\327\367", Spunct); |
3540 | 2547 |
2548 #undef SET_RANGE_SYNTAX | |
428 | 2549 } |