From 79cce3f2364019ca04f34857e01c76c4e7b39004 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 30 Sep 2011 16:06:51 -0700 Subject: [PATCH] * buffer.c (Fmove_overlay): Delete an evaporating overlay if it becomes empty after its bounds are adjusted to fit within its buffer. Without this fix, in a nonempty buffer (let ((o (make-overlay 1 2))) (overlay-put o 'evaporate t) (move-overlay o 0 1)) yields an empty overlay that has the evaporate property, which is not supposed to happen. (Bug#9642) --- src/ChangeLog | 6 ++++++ src/buffer.c | 33 ++++++++++++++------------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 790ae712476..bd20439ccc7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -43,6 +43,12 @@ (Foverlays_at, Fnext_overlay_change, Fprevious_overlay_change): Omit pointer cast, which isn't needed anyway, and doesn't work after the EMACS_INT -> ptrdiff_t change. + (Fmove_overlay): Delete an evaporating overlay + if it becomes empty after its bounds are adjusted to fit within + its buffer. Without this fix, in a nonempty buffer (let ((o + (make-overlay 1 2))) (overlay-put o 'evaporate t) (move-overlay o 0 1)) + yields an empty overlay that has the evaporate property, which is + not supposed to happen. (Bug#9642) * buffer.h: Adjust decls to match defn changes elsewhere. (struct buffer_text, struct buffer): Use ptrdiff_t, not EMACS_INT, where ptrdiff_t is wide enough. diff --git a/src/buffer.c b/src/buffer.c index 2c7b426be84..3f278eb807b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3672,6 +3672,7 @@ buffer. */) struct buffer *b, *ob; Lisp_Object obuffer; ptrdiff_t count = SPECPDL_INDEX (); + ptrdiff_t n_beg, n_end; CHECK_OVERLAY (overlay); if (NILP (buffer)) @@ -3696,16 +3697,18 @@ buffer. */) temp = beg; beg = end; end = temp; } - b = XBUFFER (buffer); - if (! (BUF_BEGV (b) <= XINT (beg) && XINT (end) <= BUF_ZV (b))) - args_out_of_range (beg, end); + Fset_marker (OVERLAY_START (overlay), beg, buffer); + Fset_marker (OVERLAY_END (overlay), end, buffer); + n_beg = marker_position (OVERLAY_START (overlay)); + n_end = marker_position (OVERLAY_END (overlay)); - if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate))) + if (n_beg == n_end && ! NILP (Foverlay_get (overlay, Qevaporate))) return Fdelete_overlay (overlay); specbind (Qinhibit_quit, Qt); obuffer = Fmarker_buffer (OVERLAY_START (overlay)); + b = XBUFFER (buffer); ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0; /* If the overlay has changed buffers, do a thorough redisplay. */ @@ -3724,7 +3727,7 @@ buffer. */) } /* Redisplay where the overlay is going to be. */ - modify_overlay (b, XINT (beg), XINT (end)); + modify_overlay (b, n_beg, n_end); } else /* Redisplay the area the overlay has just left, or just enclosed. */ @@ -3734,16 +3737,12 @@ buffer. */) o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); - if (o_beg == XINT (beg)) - modify_overlay (b, o_end, XINT (end)); - else if (o_end == XINT (end)) - modify_overlay (b, o_beg, XINT (beg)); + if (o_beg == n_beg) + modify_overlay (b, o_end, n_end); + else if (o_end == n_end) + modify_overlay (b, o_beg, n_beg); else - { - if (XINT (beg) < o_beg) o_beg = XINT (beg); - if (XINT (end) > o_end) o_end = XINT (end); - modify_overlay (b, o_beg, o_end); - } + modify_overlay (b, min (o_beg, n_beg), max (o_end, n_end)); } if (!NILP (obuffer)) @@ -3755,12 +3754,8 @@ buffer. */) eassert (XOVERLAY (overlay)->next == NULL); } - Fset_marker (OVERLAY_START (overlay), beg, buffer); - Fset_marker (OVERLAY_END (overlay), end, buffer); - /* Put the overlay on the wrong list. */ - end = OVERLAY_END (overlay); - if (OVERLAY_POSITION (end) < b->overlay_center) + if (n_end < b->overlay_center) { XOVERLAY (overlay)->next = b->overlays_after; b->overlays_after = XOVERLAY (overlay); -- 2.39.2