comparison src/buffer.c @ 51824:9f5665eb77bd

(reset_buffer, recenter_overlay_lists) (adjust_overlays_for_insert, adjust_overlays_for_delete) (fix_overlays_in_range, Fmake_overlay, Fmove_overlay) (evaporate_overlays, init_buffer_once): Update use of overlay_center. (overlays_at, evaporate_overlays, recenter_overlay_lists) (overlay_strings, fix_overlays_before): Use EMACS_INT for positions.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 08 Jul 2003 21:47:55 +0000
parents 3b58843e8f3f
children 8f62ae8e410c
comparison
equal deleted inserted replaced
51823:01bf5601e788 51824:9f5665eb77bd
30 #ifndef USE_CRT_DLL 30 #ifndef USE_CRT_DLL
31 extern int errno; 31 extern int errno;
32 #endif 32 #endif
33 33
34 #ifndef MAXPATHLEN 34 #ifndef MAXPATHLEN
35 /* in 4.1, param.h fails to define this. */ 35 /* in 4.1 [probably SunOS? -stef] , param.h fails to define this. */
36 #define MAXPATHLEN 1024 36 #define MAXPATHLEN 1024
37 #endif /* not MAXPATHLEN */ 37 #endif /* not MAXPATHLEN */
38 38
39 #ifdef HAVE_UNISTD_H 39 #ifdef HAVE_UNISTD_H
40 #include <unistd.h> 40 #include <unistd.h>
646 b->auto_save_failure_time = -1; 646 b->auto_save_failure_time = -1;
647 b->auto_save_file_name = Qnil; 647 b->auto_save_file_name = Qnil;
648 b->read_only = Qnil; 648 b->read_only = Qnil;
649 b->overlays_before = Qnil; 649 b->overlays_before = Qnil;
650 b->overlays_after = Qnil; 650 b->overlays_after = Qnil;
651 XSETFASTINT (b->overlay_center, 1); 651 b->overlay_center = BEG;
652 b->mark_active = Qnil; 652 b->mark_active = Qnil;
653 b->point_before_scroll = Qnil; 653 b->point_before_scroll = Qnil;
654 b->file_format = Qnil; 654 b->file_format = Qnil;
655 b->last_selected_window = Qnil; 655 b->last_selected_window = Qnil;
656 XSETINT (b->display_count, 0); 656 XSETINT (b->display_count, 0);
2418 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the 2418 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2419 default (BEGV or ZV). */ 2419 default (BEGV or ZV). */
2420 2420
2421 int 2421 int
2422 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr, change_req) 2422 overlays_at (pos, extend, vec_ptr, len_ptr, next_ptr, prev_ptr, change_req)
2423 int pos; 2423 EMACS_INT pos;
2424 int extend; 2424 int extend;
2425 Lisp_Object **vec_ptr; 2425 Lisp_Object **vec_ptr;
2426 int *len_ptr; 2426 int *len_ptr;
2427 int *next_ptr; 2427 int *next_ptr;
2428 int *prev_ptr; 2428 int *prev_ptr;
2940 PSTR, if that variable is non-null. The string may be overwritten by 2940 PSTR, if that variable is non-null. The string may be overwritten by
2941 subsequent calls. */ 2941 subsequent calls. */
2942 2942
2943 int 2943 int
2944 overlay_strings (pos, w, pstr) 2944 overlay_strings (pos, w, pstr)
2945 int pos; 2945 EMACS_INT pos;
2946 struct window *w; 2946 struct window *w;
2947 unsigned char **pstr; 2947 unsigned char **pstr;
2948 { 2948 {
2949 Lisp_Object ov, overlay, window, str; 2949 Lisp_Object ov, overlay, window, str;
2950 int startpos, endpos; 2950 int startpos, endpos;
2953 overlay_heads.used = overlay_heads.bytes = 0; 2953 overlay_heads.used = overlay_heads.bytes = 0;
2954 overlay_tails.used = overlay_tails.bytes = 0; 2954 overlay_tails.used = overlay_tails.bytes = 0;
2955 for (ov = current_buffer->overlays_before; CONSP (ov); ov = XCDR (ov)) 2955 for (ov = current_buffer->overlays_before; CONSP (ov); ov = XCDR (ov))
2956 { 2956 {
2957 overlay = XCAR (ov); 2957 overlay = XCAR (ov);
2958 if (!OVERLAYP (overlay)) 2958 eassert (OVERLAYP (overlay));
2959 abort ();
2960 2959
2961 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 2960 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2962 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 2961 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2963 if (endpos < pos) 2962 if (endpos < pos)
2964 break; 2963 break;
2982 endpos - startpos); 2981 endpos - startpos);
2983 } 2982 }
2984 for (ov = current_buffer->overlays_after; CONSP (ov); ov = XCDR (ov)) 2983 for (ov = current_buffer->overlays_after; CONSP (ov); ov = XCDR (ov))
2985 { 2984 {
2986 overlay = XCAR (ov); 2985 overlay = XCAR (ov);
2987 if (!OVERLAYP (overlay)) 2986 eassert (!OVERLAYP (overlay));
2988 abort ();
2989 2987
2990 startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); 2988 startpos = OVERLAY_POSITION (OVERLAY_START (overlay));
2991 endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); 2989 endpos = OVERLAY_POSITION (OVERLAY_END (overlay));
2992 if (startpos > pos) 2990 if (startpos > pos)
2993 break; 2991 break;
3068 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */ 3066 /* Shift overlays in BUF's overlay lists, to center the lists at POS. */
3069 3067
3070 void 3068 void
3071 recenter_overlay_lists (buf, pos) 3069 recenter_overlay_lists (buf, pos)
3072 struct buffer *buf; 3070 struct buffer *buf;
3073 int pos; 3071 EMACS_INT pos;
3074 { 3072 {
3075 Lisp_Object overlay, tail, next, prev, beg, end; 3073 Lisp_Object overlay, tail, next, prev, beg, end;
3076 3074
3077 /* See if anything in overlays_before should move to overlays_after. */ 3075 /* See if anything in overlays_before should move to overlays_after. */
3078 3076
3125 other_prev = other, other = XCDR (other)) 3123 other_prev = other, other = XCDR (other))
3126 { 3124 {
3127 Lisp_Object otherbeg, otheroverlay; 3125 Lisp_Object otherbeg, otheroverlay;
3128 3126
3129 otheroverlay = XCAR (other); 3127 otheroverlay = XCAR (other);
3130 if (! OVERLAY_VALID (otheroverlay)) 3128 eassert (! OVERLAY_VALID (otheroverlay));
3131 abort ();
3132 3129
3133 otherbeg = OVERLAY_START (otheroverlay); 3130 otherbeg = OVERLAY_START (otheroverlay);
3134 if (OVERLAY_POSITION (otherbeg) >= where) 3131 if (OVERLAY_POSITION (otherbeg) >= where)
3135 break; 3132 break;
3136 } 3133 }
3202 other_prev = other, other = XCDR (other)) 3199 other_prev = other, other = XCDR (other))
3203 { 3200 {
3204 Lisp_Object otherend, otheroverlay; 3201 Lisp_Object otherend, otheroverlay;
3205 3202
3206 otheroverlay = XCAR (other); 3203 otheroverlay = XCAR (other);
3207 if (! OVERLAY_VALID (otheroverlay)) 3204 eassert (! OVERLAY_VALID (otheroverlay));
3208 abort ();
3209 3205
3210 otherend = OVERLAY_END (otheroverlay); 3206 otherend = OVERLAY_END (otheroverlay);
3211 if (OVERLAY_POSITION (otherend) <= where) 3207 if (OVERLAY_POSITION (otherend) <= where)
3212 break; 3208 break;
3213 } 3209 }
3220 buf->overlays_before = tail; 3216 buf->overlays_before = tail;
3221 tail = prev; 3217 tail = prev;
3222 } 3218 }
3223 } 3219 }
3224 3220
3225 XSETFASTINT (buf->overlay_center, pos); 3221 buf->overlay_center = pos;
3226 } 3222 }
3227 3223
3228 void 3224 void
3229 adjust_overlays_for_insert (pos, length) 3225 adjust_overlays_for_insert (pos, length)
3230 int pos; 3226 EMACS_INT pos;
3231 int length; 3227 EMACS_INT length;
3232 { 3228 {
3233 /* After an insertion, the lists are still sorted properly, 3229 /* After an insertion, the lists are still sorted properly,
3234 but we may need to update the value of the overlay center. */ 3230 but we may need to update the value of the overlay center. */
3235 if (XFASTINT (current_buffer->overlay_center) >= pos) 3231 if (current_buffer->overlay_center >= pos)
3236 XSETFASTINT (current_buffer->overlay_center, 3232 current_buffer->overlay_center += length;
3237 XFASTINT (current_buffer->overlay_center) + length);
3238 } 3233 }
3239 3234
3240 void 3235 void
3241 adjust_overlays_for_delete (pos, length) 3236 adjust_overlays_for_delete (pos, length)
3242 int pos; 3237 EMACS_INT pos;
3243 int length; 3238 EMACS_INT length;
3244 { 3239 {
3245 if (XFASTINT (current_buffer->overlay_center) < pos) 3240 if (current_buffer->overlay_center < pos)
3246 /* The deletion was to our right. No change needed; the before- and 3241 /* The deletion was to our right. No change needed; the before- and
3247 after-lists are still consistent. */ 3242 after-lists are still consistent. */
3248 ; 3243 ;
3249 else if (XFASTINT (current_buffer->overlay_center) > pos + length) 3244 else if (current_buffer->overlay_center > pos + length)
3250 /* The deletion was to our left. We need to adjust the center value 3245 /* The deletion was to our left. We need to adjust the center value
3251 to account for the change in position, but the lists are consistent 3246 to account for the change in position, but the lists are consistent
3252 given the new value. */ 3247 given the new value. */
3253 XSETFASTINT (current_buffer->overlay_center, 3248 current_buffer->overlay_center -= length;
3254 XFASTINT (current_buffer->overlay_center) - length);
3255 else 3249 else
3256 /* We're right in the middle. There might be things on the after-list 3250 /* We're right in the middle. There might be things on the after-list
3257 that now belong on the before-list. Recentering will move them, 3251 that now belong on the before-list. Recentering will move them,
3258 and also update the center point. */ 3252 and also update the center point. */
3259 recenter_overlay_lists (current_buffer, pos); 3253 recenter_overlay_lists (current_buffer, pos);
3309 Qnil); 3303 Qnil);
3310 tem = startpos; startpos = endpos; endpos = tem; 3304 tem = startpos; startpos = endpos; endpos = tem;
3311 } 3305 }
3312 /* Add it to the end of the wrong list. Later on, 3306 /* Add it to the end of the wrong list. Later on,
3313 recenter_overlay_lists will move it to the right place. */ 3307 recenter_overlay_lists will move it to the right place. */
3314 if (endpos < XINT (current_buffer->overlay_center)) 3308 if (endpos < current_buffer->overlay_center)
3315 { 3309 {
3316 if (NILP (afterp)) 3310 if (NILP (afterp))
3317 after_list = tail; 3311 after_list = tail;
3318 else 3312 else
3319 XSETCDR (afterp, tail); 3313 XSETCDR (afterp, tail);
3353 Qnil); 3347 Qnil);
3354 Fset_marker (OVERLAY_END (overlay), make_number (startpos), 3348 Fset_marker (OVERLAY_END (overlay), make_number (startpos),
3355 Qnil); 3349 Qnil);
3356 tem = startpos; startpos = endpos; endpos = tem; 3350 tem = startpos; startpos = endpos; endpos = tem;
3357 } 3351 }
3358 if (endpos < XINT (current_buffer->overlay_center)) 3352 if (endpos < current_buffer->overlay_center)
3359 { 3353 {
3360 if (NILP (afterp)) 3354 if (NILP (afterp))
3361 after_list = tail; 3355 after_list = tail;
3362 else 3356 else
3363 XSETCDR (afterp, tail); 3357 XSETCDR (afterp, tail);
3386 if (!NILP (beforep)) 3380 if (!NILP (beforep))
3387 { 3381 {
3388 XSETCDR (beforep, current_buffer->overlays_before); 3382 XSETCDR (beforep, current_buffer->overlays_before);
3389 current_buffer->overlays_before = before_list; 3383 current_buffer->overlays_before = before_list;
3390 } 3384 }
3391 recenter_overlay_lists (current_buffer, 3385 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3392 XINT (current_buffer->overlay_center));
3393 3386
3394 if (!NILP (afterp)) 3387 if (!NILP (afterp))
3395 { 3388 {
3396 XSETCDR (afterp, current_buffer->overlays_after); 3389 XSETCDR (afterp, current_buffer->overlays_after);
3397 current_buffer->overlays_after = after_list; 3390 current_buffer->overlays_after = after_list;
3398 } 3391 }
3399 recenter_overlay_lists (current_buffer, 3392 recenter_overlay_lists (current_buffer, current_buffer->overlay_center);
3400 XINT (current_buffer->overlay_center));
3401 } 3393 }
3402 3394
3403 /* We have two types of overlay: the one whose ending marker is 3395 /* We have two types of overlay: the one whose ending marker is
3404 after-insertion-marker (this is the usual case) and the one whose 3396 after-insertion-marker (this is the usual case) and the one whose
3405 ending marker is before-insertion-marker. When `overlays_before' 3397 ending marker is before-insertion-marker. When `overlays_before'
3413 was at PREV, and now is at POS. */ 3405 was at PREV, and now is at POS. */
3414 3406
3415 void 3407 void
3416 fix_overlays_before (bp, prev, pos) 3408 fix_overlays_before (bp, prev, pos)
3417 struct buffer *bp; 3409 struct buffer *bp;
3418 int prev, pos; 3410 EMACS_INT prev, pos;
3419 { 3411 {
3420 /* If parent is nil, replace overlays_before; otherwise, XCDR(parent). */ 3412 /* If parent is nil, replace overlays_before; otherwise, XCDR(parent). */
3421 Lisp_Object tail = bp->overlays_before, parent = Qnil; 3413 Lisp_Object tail = bp->overlays_before, parent = Qnil;
3422 Lisp_Object right_pair; 3414 Lisp_Object right_pair;
3423 int end; 3415 EMACS_INT end;
3424 3416
3425 /* After the insertion, the several overlays may be in incorrect 3417 /* After the insertion, the several overlays may be in incorrect
3426 order. The possibility is that, in the list `overlays_before', 3418 order. The possibility is that, in the list `overlays_before',
3427 an overlay which ends at POS appears after an overlay which ends 3419 an overlay which ends at POS appears after an overlay which ends
3428 at PREV. Since POS is greater than PREV, we must fix the 3420 at PREV. Since POS is greater than PREV, we must fix the
3552 XOVERLAY (overlay)->end = end; 3544 XOVERLAY (overlay)->end = end;
3553 XOVERLAY (overlay)->plist = Qnil; 3545 XOVERLAY (overlay)->plist = Qnil;
3554 3546
3555 /* Put the new overlay on the wrong list. */ 3547 /* Put the new overlay on the wrong list. */
3556 end = OVERLAY_END (overlay); 3548 end = OVERLAY_END (overlay);
3557 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) 3549 if (OVERLAY_POSITION (end) < b->overlay_center)
3558 b->overlays_after = Fcons (overlay, b->overlays_after); 3550 b->overlays_after = Fcons (overlay, b->overlays_after);
3559 else 3551 else
3560 b->overlays_before = Fcons (overlay, b->overlays_before); 3552 b->overlays_before = Fcons (overlay, b->overlays_before);
3561 3553
3562 /* This puts it in the right list, and in the right order. */ 3554 /* This puts it in the right list, and in the right order. */
3563 recenter_overlay_lists (b, XINT (b->overlay_center)); 3555 recenter_overlay_lists (b, b->overlay_center);
3564 3556
3565 /* We don't need to redisplay the region covered by the overlay, because 3557 /* We don't need to redisplay the region covered by the overlay, because
3566 the overlay has no properties at the moment. */ 3558 the overlay has no properties at the moment. */
3567 3559
3568 return overlay; 3560 return overlay;
3571 /* Mark a section of BUF as needing redisplay because of overlays changes. */ 3563 /* Mark a section of BUF as needing redisplay because of overlays changes. */
3572 3564
3573 static void 3565 static void
3574 modify_overlay (buf, start, end) 3566 modify_overlay (buf, start, end)
3575 struct buffer *buf; 3567 struct buffer *buf;
3576 int start, end; 3568 EMACS_INT start, end;
3577 { 3569 {
3578 if (start > end) 3570 if (start > end)
3579 { 3571 {
3580 int temp = start; 3572 int temp = start;
3581 start = end; 3573 start = end;
3689 Fset_marker (OVERLAY_START (overlay), beg, buffer); 3681 Fset_marker (OVERLAY_START (overlay), beg, buffer);
3690 Fset_marker (OVERLAY_END (overlay), end, buffer); 3682 Fset_marker (OVERLAY_END (overlay), end, buffer);
3691 3683
3692 /* Put the overlay on the wrong list. */ 3684 /* Put the overlay on the wrong list. */
3693 end = OVERLAY_END (overlay); 3685 end = OVERLAY_END (overlay);
3694 if (OVERLAY_POSITION (end) < XINT (b->overlay_center)) 3686 if (OVERLAY_POSITION (end) < b->overlay_center)
3695 b->overlays_after = Fcons (overlay, b->overlays_after); 3687 b->overlays_after = Fcons (overlay, b->overlays_after);
3696 else 3688 else
3697 b->overlays_before = Fcons (overlay, b->overlays_before); 3689 b->overlays_before = Fcons (overlay, b->overlays_before);
3698 3690
3699 /* This puts it in the right list, and in the right order. */ 3691 /* This puts it in the right list, and in the right order. */
3700 recenter_overlay_lists (b, XINT (b->overlay_center)); 3692 recenter_overlay_lists (b, b->overlay_center);
3701 3693
3702 return unbind_to (count, overlay); 3694 return unbind_to (count, overlay);
3703 } 3695 }
3704 3696
3705 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, 3697 DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
4239 4231
4240 /* Delete any zero-sized overlays at position POS, if the `evaporate' 4232 /* Delete any zero-sized overlays at position POS, if the `evaporate'
4241 property is set. */ 4233 property is set. */
4242 void 4234 void
4243 evaporate_overlays (pos) 4235 evaporate_overlays (pos)
4244 int pos; 4236 EMACS_INT pos;
4245 { 4237 {
4246 Lisp_Object tail, overlay, hit_list; 4238 Lisp_Object tail, overlay, hit_list;
4247 4239
4248 hit_list = Qnil; 4240 hit_list = Qnil;
4249 if (pos <= XFASTINT (current_buffer->overlay_center)) 4241 if (pos <= current_buffer->overlay_center)
4250 for (tail = current_buffer->overlays_before; CONSP (tail); 4242 for (tail = current_buffer->overlays_before; CONSP (tail);
4251 tail = XCDR (tail)) 4243 tail = XCDR (tail))
4252 { 4244 {
4253 int endpos; 4245 int endpos;
4254 overlay = XCAR (tail); 4246 overlay = XCAR (tail);
4904 buffer_defaults.undo_list = Qnil; 4896 buffer_defaults.undo_list = Qnil;
4905 buffer_defaults.mark_active = Qnil; 4897 buffer_defaults.mark_active = Qnil;
4906 buffer_defaults.file_format = Qnil; 4898 buffer_defaults.file_format = Qnil;
4907 buffer_defaults.overlays_before = Qnil; 4899 buffer_defaults.overlays_before = Qnil;
4908 buffer_defaults.overlays_after = Qnil; 4900 buffer_defaults.overlays_after = Qnil;
4909 XSETFASTINT (buffer_defaults.overlay_center, BEG); 4901 buffer_defaults.overlay_center = BEG;
4910 4902
4911 XSETFASTINT (buffer_defaults.tab_width, 8); 4903 XSETFASTINT (buffer_defaults.tab_width, 8);
4912 buffer_defaults.truncate_lines = Qnil; 4904 buffer_defaults.truncate_lines = Qnil;
4913 buffer_defaults.ctl_arrow = Qt; 4905 buffer_defaults.ctl_arrow = Qt;
4914 buffer_defaults.direction_reversed = Qnil; 4906 buffer_defaults.direction_reversed = Qnil;