Mercurial > hg > xemacs-beta
comparison src/syntax.c @ 3250:2b8bb4938bb4
[xemacs-hg @ 2006-02-21 11:33:41 by stephent]
Commit syntax-cache fixes. <87oe11ne10.fsf@tleepslib.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Tue, 21 Feb 2006 11:33:46 +0000 |
parents | b85f5d7d9d82 |
children | a66d0a29e183 |
comparison
equal
deleted
inserted
replaced
3249:7a5e3aea74e3 | 3250:2b8bb4938bb4 |
---|---|
252 BUFFER_SYNTAX_TABLE (cache->buffer); | 252 BUFFER_SYNTAX_TABLE (cache->buffer); |
253 cache->mirror_table = | 253 cache->mirror_table = |
254 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); | 254 BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); |
255 cache->start = Qnil; | 255 cache->start = Qnil; |
256 cache->end = Qnil; | 256 cache->end = Qnil; |
257 /* #### I'm not sure what INFINITE is for, but it's apparently needed by | |
258 setup_syntax_cache(). It looks like it's supposed to guarantee that | |
259 the test for POS outside of cache-valid range will never succeed, so | |
260 that update_syntax_cache won't get called, but it's hard to be sure. | |
261 Cf reset_buffer_syntax_cache_range. -- sjt */ | |
257 if (infinite) | 262 if (infinite) |
258 { | 263 { |
259 cache->prev_change = EMACS_INT_MIN; | 264 cache->prev_change = EMACS_INT_MIN; |
260 cache->next_change = EMACS_INT_MAX; | 265 cache->next_change = EMACS_INT_MAX; |
261 } | 266 } |
264 cache->prev_change = -1; | 269 cache->prev_change = -1; |
265 cache->next_change = -1; | 270 cache->next_change = -1; |
266 } | 271 } |
267 } | 272 } |
268 | 273 |
269 struct syntax_cache * | 274 /* #### This function and associated logic still needs work, and especially |
270 setup_syntax_cache (struct syntax_cache *cache, Lisp_Object object, | 275 documentation. */ |
271 struct buffer *buffer, Charxpos from, int count) | 276 struct syntax_cache * /* return CACHE or the cache of OBJECT */ |
272 { | 277 setup_syntax_cache (struct syntax_cache *cache, /* syntax cache, may be NULL |
278 if OBJECT is a buffer */ | |
279 Lisp_Object object, /* the object (if any) cache | |
280 is associated with */ | |
281 struct buffer *buffer, /* the buffer to use as source | |
282 of the syntax table */ | |
283 Charxpos from, /* initial position of cache */ | |
284 int count) /* direction? see code */ | |
285 { | |
286 /* If OBJECT is a buffer, use its cache. Initialize cache. Make it valid | |
287 for the whole buffer if the syntax-table property is not being respected. | |
288 Else if OBJECT is not a buffer, initialize the cache passed in CACHE. | |
289 If the syntax-table property is being respected, update the cache. */ | |
273 if (BUFFERP (object)) | 290 if (BUFFERP (object)) |
274 cache = XBUFFER (object)->syntax_cache; | 291 { |
275 if (!lookup_syntax_properties) | 292 cache = XBUFFER (object)->syntax_cache; |
276 init_syntax_cache (cache, object, buffer, 1); | 293 if (!lookup_syntax_properties) |
277 else if (!BUFFERP (object)) | 294 reset_buffer_syntax_cache_range (cache, object, 1); |
295 } | |
296 else | |
278 init_syntax_cache (cache, object, buffer, 0); | 297 init_syntax_cache (cache, object, buffer, 0); |
279 if (lookup_syntax_properties) | 298 if (lookup_syntax_properties) |
280 { | 299 { |
281 if (count <= 0) | 300 if (count <= 0) |
282 { | 301 { |
337 mark_object (cache->start); | 356 mark_object (cache->start); |
338 mark_object (cache->end); | 357 mark_object (cache->end); |
339 } | 358 } |
340 | 359 |
341 static void | 360 static void |
342 reset_buffer_cache_range (struct syntax_cache *cache, Lisp_Object buffer) | 361 reset_buffer_syntax_cache_range (struct syntax_cache *cache, |
362 Lisp_Object buffer, int infinite) | |
343 { | 363 { |
344 Fset_marker (cache->start, make_int (1), buffer); | 364 Fset_marker (cache->start, make_int (1), buffer); |
345 Fset_marker (cache->end, make_int (1), buffer); | 365 Fset_marker (cache->end, make_int (1), buffer); |
346 Fset_marker_insertion_type (cache->start, Qt); | 366 Fset_marker_insertion_type (cache->start, Qt); |
347 Fset_marker_insertion_type (cache->end, Qnil); | 367 Fset_marker_insertion_type (cache->end, Qnil); |
348 cache->prev_change = -1; | 368 /* #### Should we "cache->no_syntax_table_prop = 1;" here? */ |
349 cache->next_change = -1; | 369 /* #### Cf comment on INFINITE in init_syntax_cache. -- sjt */ |
370 if (infinite) | |
371 { | |
372 cache->prev_change = EMACS_INT_MIN; | |
373 cache->next_change = EMACS_INT_MAX; | |
374 } | |
375 else | |
376 { | |
377 cache->prev_change = -1; | |
378 cache->next_change = -1; | |
379 } | |
350 } | 380 } |
351 | 381 |
352 void | 382 void |
353 init_buffer_syntax_cache (struct buffer *buf) | 383 init_buffer_syntax_cache (struct buffer *buf) |
354 { | 384 { |
365 cache->no_syntax_table_prop = 1; | 395 cache->no_syntax_table_prop = 1; |
366 cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer); | 396 cache->syntax_table = BUFFER_SYNTAX_TABLE (cache->buffer); |
367 cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); | 397 cache->mirror_table = BUFFER_MIRROR_SYNTAX_TABLE (cache->buffer); |
368 cache->start = Fmake_marker (); | 398 cache->start = Fmake_marker (); |
369 cache->end = Fmake_marker (); | 399 cache->end = Fmake_marker (); |
370 reset_buffer_cache_range (cache, cache->object); | 400 reset_buffer_syntax_cache_range (cache, cache->object, 0); |
371 } | 401 } |
372 | 402 |
403 /* finalize the syntax cache for BUF */ | |
373 void | 404 void |
374 uninit_buffer_syntax_cache (struct buffer *buf) | 405 uninit_buffer_syntax_cache (struct buffer *buf) |
375 { | 406 { |
376 #ifdef NEW_GC | 407 #ifdef NEW_GC |
377 mc_free (buf->syntax_cache); | 408 mc_free (buf->syntax_cache); |
399 either because EXTENT has a syntax-table property and is being attached | 430 either because EXTENT has a syntax-table property and is being attached |
400 or detached (this includes having its endpoints changed), or because | 431 or detached (this includes having its endpoints changed), or because |
401 the value of EXTENT's syntax-table property is changing. */ | 432 the value of EXTENT's syntax-table property is changing. */ |
402 | 433 |
403 void | 434 void |
404 signal_syntax_table_extent_changed (EXTENT extent) | 435 signal_syntax_cache_extent_changed (EXTENT extent) |
405 { | 436 { |
406 Lisp_Object buffer = Fextent_object (wrap_extent (extent)); | 437 Lisp_Object buffer = Fextent_object (wrap_extent (extent)); |
407 if (BUFFERP (buffer)) | 438 if (BUFFERP (buffer)) |
408 { | 439 { |
440 /* This was getting called with the buffer's start and end null, eg in | |
441 cperl mode, which triggers an assert in byte_marker_position. Cf | |
442 thread rooted at <yxz7j7xzk97.fsf@gimli.holgi.priv> on xemacs-beta. | |
443 <yxzfymklb6p.fsf@gimli.holgi.priv> has a recipe, but you also need | |
444 to delete or type SPC to get the crash. | |
445 #### Delete this comment when setup_syntax_cache is made sane. */ | |
409 struct syntax_cache *cache = XBUFFER (buffer)->syntax_cache; | 446 struct syntax_cache *cache = XBUFFER (buffer)->syntax_cache; |
447 /* #### would this be slower or less accurate in character terms? */ | |
410 Bytexpos start = extent_endpoint_byte (extent, 0); | 448 Bytexpos start = extent_endpoint_byte (extent, 0); |
411 Bytexpos end = extent_endpoint_byte (extent, 1); | 449 Bytexpos end = extent_endpoint_byte (extent, 1); |
412 Bytexpos start2 = byte_marker_position (cache->start); | 450 Bytexpos start2 = byte_marker_position (cache->start); |
413 Bytexpos end2 = byte_marker_position (cache->end); | 451 Bytexpos end2 = byte_marker_position (cache->end); |
414 /* If the extent is entirely before or entirely after the cache range, | 452 /* If the extent is entirely before or entirely after the cache |
415 it doesn't overlap. Otherwise, invalidate the range. */ | 453 range, it doesn't overlap. Otherwise, invalidate the range. */ |
416 if (!(end < start2 || start > end2)) | 454 if (!(end < start2 || start > end2)) |
417 reset_buffer_cache_range (cache, buffer); | 455 reset_buffer_syntax_cache_range (cache, buffer, 0); |
418 } | 456 } |
419 } | 457 } |
420 | 458 |
421 /* Extents have been adjusted for insertion or deletion, so we need to | 459 /* Extents have been adjusted for insertion or deletion, so we need to |
422 refetch the start and end position of the extent */ | 460 refetch the start and end position of the extent */ |
423 void | 461 void |
424 signal_syntax_table_extent_adjust (struct buffer *buf) | 462 signal_syntax_cache_extent_adjust (struct buffer *buf) |
425 { | 463 { |
426 struct syntax_cache *cache = buf->syntax_cache; | 464 struct syntax_cache *cache = buf->syntax_cache; |
427 /* If the cache was invalid before, leave it that way. We only want | 465 /* If the cache was invalid before, leave it that way. We only want |
428 to update the limits of validity when they were actually valid. */ | 466 to update the limits of validity when they were actually valid. */ |
429 if (cache->prev_change < 0) | 467 if (cache->prev_change < 0) |
497 { | 535 { |
498 /* If we are at the beginning or end of buffer, check to see if there's | 536 /* If we are at the beginning or end of buffer, check to see if there's |
499 a zero-length `syntax-table' extent there (highly unlikely); if not, | 537 a zero-length `syntax-table' extent there (highly unlikely); if not, |
500 then we can safely make the end closed, so it will take in newly | 538 then we can safely make the end closed, so it will take in newly |
501 inserted text. (If such an extent is inserted, we will be informed | 539 inserted text. (If such an extent is inserted, we will be informed |
502 through signal_syntax_table_extent_changed().) */ | 540 through signal_syntax_cache_extent_changed().) */ |
503 Fset_marker (cache->start, make_int (cache->prev_change), cache->object); | 541 Fset_marker (cache->start, make_int (cache->prev_change), cache->object); |
504 Fset_marker_insertion_type | 542 Fset_marker_insertion_type |
505 (cache->start, | 543 (cache->start, |
506 at_begin && NILP (extent_at (prev, cache->object, Qsyntax_table, | 544 at_begin && NILP (extent_at (prev, cache->object, Qsyntax_table, |
507 NULL, EXTENT_AT_AT, 0)) | 545 NULL, EXTENT_AT_AT, 0)) |