summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorMatt Armstrong <matt@rfc20.org>2022-10-21 19:45:13 -0700
committerMatt Armstrong <matt@rfc20.org>2022-10-21 19:58:34 -0700
commitf2a51774a934f29848c5796b46faa5e3b022c401 (patch)
tree2205718ca742e3bba9790ace881373a3d540d3d2 /src/buffer.c
parenta2fde77b5cc15ec5a1c29ca72c97c806204818a9 (diff)
downloademacs-f2a51774a934f29848c5796b46faa5e3b022c401.tar.gz
emacs-f2a51774a934f29848c5796b46faa5e3b022c401.tar.bz2
emacs-f2a51774a934f29848c5796b46faa5e3b022c401.zip
Fix a narrow-to-region vs. overlays-at bug
See bug#58703. * src/buffer.c (overlays_in): Add a new TRAILING arg expressing the behavior wanted by `overlays-at', namely to include all overlays beginning at the POS passed to `overlays-at', even if POS is the end of the narrowed region. Pass true and the search range is extended to ZV+1 if END is greater than ZV, just as is done for EMPTY. (overlays_at): Pass 'true' for the new trailing arg. At present this is the only caller passing 'true'. (mouse_face_overlay_overlaps): Pass 'false' for the new trailing arg. (disable_line_numbers_overlay_at_eob): ditto. (Foverlays_in): ditto. * src/editfns.c (overlays_around): ditto. * test/src/buffer-tests.el (sorted-overlays): Add a spot test for this.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/buffer.c b/src/buffer.c
index fe6b515493e..dcb3c3944b7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2943,6 +2943,10 @@ the normal hook `change-major-mode-hook'. */)
END, provided END denotes the position at the end of the accessible
part of the buffer.
+ If TRAILING is true, include overlays that begin at END, provided
+ END denotes the position at the end of the accessible part of the
+ buffer.
+
Return the number found, and store them in a vector in *VEC_PTR.
Store in *LEN_PTR the size allocated for the vector.
Store in *NEXT_PTR the next position after POS where an overlay starts,
@@ -2959,7 +2963,8 @@ the normal hook `change-major-mode-hook'. */)
ptrdiff_t
overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend,
- Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, bool empty,
+ Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
+ bool empty, bool trailing,
ptrdiff_t *next_ptr)
{
ptrdiff_t idx = 0;
@@ -2968,9 +2973,14 @@ overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend,
Lisp_Object *vec = *vec_ptr;
struct itree_node *node;
- ITREE_FOREACH (node, current_buffer->overlays, beg,
- /* Find empty OV at ZV ? */
- (end >= ZV && empty) ? ZV + 1 : ZV, ASCENDING)
+ /* Extend the search range if overlays beginning at ZV are
+ wanted. */
+ ptrdiff_t search_end = ZV;
+ if (end >= ZV && (empty || trailing))
+ ++search_end;
+
+ ITREE_FOREACH (node, current_buffer->overlays, beg, search_end,
+ ASCENDING)
{
if (node->begin > end)
{
@@ -3022,7 +3032,8 @@ overlays_at (ptrdiff_t pos, bool extend,
Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
ptrdiff_t *next_ptr)
{
- return overlays_in (pos, pos + 1, extend, vec_ptr, len_ptr, false, next_ptr);
+ return overlays_in (pos, pos + 1, extend, vec_ptr, len_ptr,
+ false, true, next_ptr);
}
ptrdiff_t
@@ -3085,11 +3096,11 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
size = ARRAYELTS (vbuf);
v = vbuf;
- n = overlays_in (start, end, 0, &v, &size, true, NULL);
+ n = overlays_in (start, end, 0, &v, &size, true, false, NULL);
if (n > size)
{
SAFE_NALLOCA (v, 1, n);
- overlays_in (start, end, 0, &v, &n, true, NULL);
+ overlays_in (start, end, 0, &v, &n, true, false, NULL);
}
for (i = 0; i < n; ++i)
@@ -3114,11 +3125,11 @@ disable_line_numbers_overlay_at_eob (void)
size = ARRAYELTS (vbuf);
v = vbuf;
- n = overlays_in (ZV, ZV, 0, &v, &size, false, NULL);
+ n = overlays_in (ZV, ZV, 0, &v, &size, false, false, NULL);
if (n > size)
{
SAFE_NALLOCA (v, 1, n);
- overlays_in (ZV, ZV, 0, &v, &n, false, NULL);
+ overlays_in (ZV, ZV, 0, &v, &n, false, false, NULL);
}
for (i = 0; i < n; ++i)
@@ -3798,7 +3809,7 @@ end of the accessible part of the buffer. */)
/* Put all the overlays we want in a vector in overlay_vec.
Store the length in len. */
noverlays = overlays_in (XFIXNUM (beg), XFIXNUM (end), 1, &overlay_vec, &len,
- true, NULL);
+ true, false, NULL);
/* Make a list of them all. */
result = Flist (noverlays, overlay_vec);