diff --git a/src/buffer.c b/src/buffer.c index 3d85d784f1c..1129d178c7b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3082,14 +3082,13 @@ overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend, { ptrdiff_t idx = 0; ptrdiff_t len = *len_ptr; - ptrdiff_t next = ZV; + ptrdiff_t next = Z; Lisp_Object *vec = *vec_ptr; struct itree_node *node; - /* Extend the search range if overlays beginning at ZV are - wanted. */ - ptrdiff_t search_end = ZV; - if (end >= ZV && (empty || trailing)) + /* Extend the search range if overlays beginning at Z are wanted. */ + ptrdiff_t search_end = Z; + if (end >= Z && (empty || trailing)) ++search_end; ITREE_FOREACH (node, current_buffer->overlays, beg, search_end, @@ -3103,7 +3102,7 @@ overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend, else if (node->begin == end) { next = node->begin; - if ((! empty || end < ZV) && beg < end) + if ((! empty || end < Z) && beg < end) break; if (empty && node->begin != node->end) continue; @@ -3125,7 +3124,7 @@ overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend, idx++; } if (next_ptr) - *next_ptr = next ? next : ZV; + *next_ptr = next ? next : Z; return idx; } diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 5f534ed513a..f4654e90bce 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -1060,7 +1060,9 @@ should evaporate overlays in both." (should-length 2 (overlays-in 1 (point-max))) (should-length 1 (overlays-in (point-max) (point-max))) (narrow-to-region 1 50) - (should-length 1 (overlays-in 1 (point-max))) + ;; We only count empty overlays in narrowed buffers excluding the + ;; real EOB when the region is confined to `point-max'. + (should-length 0 (overlays-in 1 (point-max))) (should-length 1 (overlays-in (point-max) (point-max)))))) @@ -8375,8 +8377,11 @@ dicta sunt, explicabo. ")) (should (= (length (overlays-in 1 2)) 0)) (narrow-to-region 1 2) ;; We've now narrowed, so the zero-length overlay is at the end of - ;; the (accessible part of the) buffer. - (should (= (length (overlays-in 1 2)) 1)) + ;; the (accessible part of the) buffer, but we only count it when + ;; the region is confined to `point-max'. + (should (= (length (overlays-in 1 2)) 0)) + (should (= (length (overlays-in 2 2)) 1)) + (should (= (length (overlays-in (point-max) (point-max))) 1)) (remove-overlays) (should (= (length (overlays-in (point-min) (point-max))) 0))))