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