emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 5d7b1d5 2/2: Make overlays-in treat zero-length overlays at point


From: Lars Ingebrigtsen
Subject: master 5d7b1d5 2/2: Make overlays-in treat zero-length overlays at point-max consistently
Date: Mon, 16 Aug 2021 09:41:40 -0400 (EDT)

branch: master
commit 5d7b1d5fc75752a986ed19d3fd333167ddc29d4e
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make overlays-in treat zero-length overlays at point-max consistently
    
    * doc/lispref/display.texi (Finding Overlays): Adjust documentation.
    
    * src/buffer.c (overlays_in): Treat the end of the buffer and the
    end of the narrowed-to buffer the same (bug#19422).
    (Foverlays_in): Adjust doc string.
---
 doc/lispref/display.texi |  3 ++-
 etc/NEWS                 |  8 ++++++++
 src/buffer.c             |  5 +++--
 test/src/buffer-tests.el | 23 ++++++++++++++++++++++-
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 13d0a1b..79fb72a 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -1917,7 +1917,8 @@ This function returns a list of the overlays that overlap 
the region
 contains one or more characters in the region; empty overlays
 (@pxref{Managing Overlays, empty overlay}) overlap if they are at
 @var{beg}, strictly between @var{beg} and @var{end}, or at @var{end}
-when @var{end} denotes the position at the end of the buffer.
+when @var{end} denotes the position at the end of the accessible part
+of the buffer.
 @end defun
 
 @defun next-overlay-change pos
diff --git a/etc/NEWS b/etc/NEWS
index 54168e8..3ccef66 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3080,6 +3080,14 @@ This is to keep the same behavior as Eshell.
 
 * Incompatible Lisp Changes in Emacs 28.1
 
++++
+** 'overlays-in' now handles zero-length overlays slightly differently.
+Previosly, zero-length overlays at the end of the buffer were included
+in the result (if the region queried for stopped at that position).
+The same was not the case if the buffer had been narrowed to exclude
+the real end of the buffer.  This has now been changed, and
+zero-length overlays at `point-max' are always included in the results.
+
 ---
 ** 'replace-match' now runs modification hooks slightly later.
 The function is documented to leave point after the replacement text,
diff --git a/src/buffer.c b/src/buffer.c
index b177c5e..7e4c849 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2995,7 +2995,7 @@ overlays_in (EMACS_INT beg, EMACS_INT end, bool extend,
   ptrdiff_t next = ZV;
   ptrdiff_t prev = BEGV;
   bool inhibit_storing = 0;
-  bool end_is_Z = end == Z;
+  bool end_is_Z = end == ZV;
 
   for (struct Lisp_Overlay *tail = current_buffer->overlays_before;
        tail; tail = tail->next)
@@ -4268,9 +4268,10 @@ DEFUN ("overlays-in", Foverlays_in, Soverlays_in, 2, 2, 
0,
        doc: /* Return a list of the overlays that overlap the region BEG ... 
END.
 Overlap means that at least one character is contained within the overlay
 and also contained within the specified region.
+
 Empty overlays are included in the result if they are located at BEG,
 between BEG and END, or at END provided END denotes the position at the
-end of the buffer.  */)
+end of the accessible part of the buffer.  */)
   (Lisp_Object beg, Lisp_Object end)
 {
   ptrdiff_t len, noverlays;
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el
index 11f842e..118311c 100644
--- a/test/src/buffer-tests.el
+++ b/test/src/buffer-tests.el
@@ -754,7 +754,7 @@ with parameters from the *Messages* buffer modification."
       (should-length 2 (overlays-in 1 (point-max)))
       (should-length 1 (overlays-in (point-max) (point-max)))
       (narrow-to-region 1 50)
-      (should-length 0 (overlays-in 1 (point-max)))
+      (should-length 1 (overlays-in 1 (point-max)))
       (should-length 1 (overlays-in (point-max) (point-max))))))
 
 
@@ -1399,4 +1399,25 @@ with parameters from the *Messages* buffer modification."
       (should (memq long-overlay (overlays-in 3 3)))
       (should (memq zero-overlay (overlays-in 3 3))))))
 
+(ert-deftest test-remove-overlays ()
+  (with-temp-buffer
+    (insert "foo")
+    (make-overlay (point) (point))
+    (should (= (length (overlays-in (point-min) (point-max))) 1))
+    (remove-overlays)
+    (should (= (length (overlays-in (point-min) (point-max))) 0)))
+
+  (with-temp-buffer
+    (insert "foo")
+    (goto-char 2)
+    (make-overlay (point) (point))
+    ;; We only count zero-length overlays at the end of the buffer.
+    (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))
+    (remove-overlays)
+    (should (= (length (overlays-in (point-min) (point-max))) 0))))
+
 ;;; buffer-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]