all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS
@ 2022-10-22  2:34 Matt Armstrong
  2022-10-22  3:06 ` Matt Armstrong
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Armstrong @ 2022-10-22  2:34 UTC (permalink / raw)
  To: 58703; +Cc: stefan monnier

X-Debbugs-CC: Stefan Monnier <monnier@iro.umontreal.ca>

This bug pertains to the feature/noverlay branch.

The following test passes on master but fails on noverlay:

(ert-deftest test-overlays-at-narrow-to-region-end ()
  (with-temp-buffer
   (insert (make-string 30 ?x))
   (make-overlay 10 11)
   (narrow-to-region 10 10)
   (should (equal
            '((10 11))
            (sorted-overlays-at 10)))))

I've got a patch to fix and will post it once I get a bug number.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS
  2022-10-22  2:34 bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS Matt Armstrong
@ 2022-10-22  3:06 ` Matt Armstrong
  2022-10-24 19:22   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Armstrong @ 2022-10-22  3:06 UTC (permalink / raw)
  To: 58703; +Cc: stefan monnier

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

Matt Armstrong <matt@rfc20.org> writes:

> I've got a patch to fix and will post it once I get a bug number.

...attached and also at the scratch/matta/for_stefan branch at
https://git.sr.ht/~matta/emacs (log link:
https://git.sr.ht/~matta/emacs/log/scratch/matta/for_stefan)

I am not happy with adding a new arg to 'overlays_in', but it appears we
really do have three distinct "modes" that can't be covered by simply
passing a half-open [beg,end) range.  It isn't an issue on master
because 'overlays_at' doesn't call 'overlays_in' there.  The fact that
the code wasn't shared probably allowed this subtle behavior difference
to slip through -- who knows if any callers rely on this.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-handling-of-overlays-that-begin-at-END-in-overla.patch --]
[-- Type: text/x-diff, Size: 4836 bytes --]

From a2fde77b5cc15ec5a1c29ca72c97c806204818a9 Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Fri, 21 Oct 2022 16:07:08 -0700
Subject: [PATCH] Fix handling of overlays that begin at END in 'overlays_in'

When passed EMPTY, 'overlays_in' should return empty overlays at END.
It was doing so, but it was also returning any other overlay that
happened to begin at END.

bug#58672

* src/buffer.c (overlays_in): Don't return overlays at END unless they
are empty overlays.
(disable_line_numbers_overlay_at_eob): Pass 'false' instead of 'NULL'
for the bool 'empty' arg.
* test/src/buffer-tests.el (sorted-overlays-in): New helper function.
(test-overlays-in-empty-range): New test exhaustively covering these
edge conditions.
(test-overlays-in-empty-range-bug58672): Simple test for one case.
---
 src/buffer.c             | 11 ++++++----
 test/src/buffer-tests.el | 45 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c
index 3286cd338ff..fe6b515493e 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2940,7 +2940,8 @@ DEFUN ("kill-all-local-variables", Fkill_all_local_variables,
    [BEG, END).
 
    If EMPTY is true, include empty overlays in that range and also at
-   END, provided END denotes the position at the end of the buffer.
+   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.
@@ -2968,7 +2969,7 @@ overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend,
   struct itree_node *node;
 
   ITREE_FOREACH (node, current_buffer->overlays, beg,
-                 /* Find empty OV at Z ? */
+                 /* Find empty OV at ZV ? */
                  (end >= ZV && empty) ? ZV + 1 : ZV, ASCENDING)
     {
       if (node->begin > end)
@@ -2985,6 +2986,8 @@ overlays_in (ptrdiff_t beg, ptrdiff_t end, bool extend,
               ITREE_FOREACH_ABORT ();
               break;
             }
+          if (empty && node->begin != node->end)
+            continue;
         }
 
       if (! empty && node->begin == node->end)
@@ -3111,11 +3114,11 @@ disable_line_numbers_overlay_at_eob (void)
 
   size = ARRAYELTS (vbuf);
   v = vbuf;
-  n = overlays_in (ZV, ZV, 0, &v, &size, NULL, NULL);
+  n = overlays_in (ZV, ZV, 0, &v, &size, false, NULL);
   if (n > size)
     {
       SAFE_NALLOCA (v, 1, n);
-      overlays_in (ZV, ZV, 0, &v, &n, NULL, NULL);
+      overlays_in (ZV, ZV, 0, &v, &n, false, NULL);
     }
 
   for (i = 0; i < n; ++i)
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el
index 3833f88c5c8..6d5d9913a01 100644
--- a/test/src/buffer-tests.el
+++ b/test/src/buffer-tests.el
@@ -937,6 +937,51 @@ ad
 (deftest-overlays-in-1 ae 9 11 (a) (a 10 10))
 (deftest-overlays-in-1 af 10 11 (a) (a 10 10))
 
+(defun sorted-overlays-in (beg end)
+  (sort
+   (mapcar (lambda (overlay)
+             (list (overlay-start overlay)
+                   (overlay-end overlay)))
+           (overlays-in beg end))
+   (lambda (first second)
+     (cl-loop for a in first
+              for b in second
+              thereis (< a b)
+              until (> a b)))))
+
+;; behavior for empty range
+(ert-deftest test-overlays-in-empty-range ()
+    (with-temp-buffer
+      (insert (make-string 4 ?x))
+      (cl-loop for start from (point-min) to (point-max)
+               do (cl-loop for end from start to (point-max)
+                           do (when (<= start end)
+                                (make-overlay start end))))
+
+      (cl-loop for pos from (point-min) to (point-max)
+               do (ert-info ((format "after (overlay-recenter %d)" pos))
+                    (overlay-recenter pos)
+                    (should (equal
+                             '((1 1))
+                             (sorted-overlays-in (point-min) (point-min))))
+                    (should (equal
+                             '((1 3) (1 4) (1 5) (2 2))
+                             (sorted-overlays-in 2 2)))
+                    (should (equal
+                             '((1 4) (1 5) (2 4) (2 5) (3 3))
+                             (sorted-overlays-in 3 3)))
+                    (should (equal
+                             '((1 5) (2 5) (3 5) (4 4))
+                             (sorted-overlays-in 4 4)))
+                    (should (equal
+                             '((5 5))
+                             (sorted-overlays-in (point-max) (point-max))))))))
+
+(ert-deftest test-overlays-in-empty-range-bug58672 ()
+  (with-temp-buffer
+    (insert (make-string 10 ?=))
+    (make-overlay 5 7 nil nil t)
+    (should (equal nil (overlays-in 5 5)))))
 
 ;; behavior at point-max
 (ert-deftest test-overlays-in-2 ()
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS
  2022-10-22  3:06 ` Matt Armstrong
@ 2022-10-24 19:22   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-11-12 20:58     ` Stefan Kangas
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-10-24 19:22 UTC (permalink / raw)
  To: Matt Armstrong; +Cc: 58703

> ...attached and also at the scratch/matta/for_stefan branch at
> https://git.sr.ht/~matta/emacs (log link:
> https://git.sr.ht/~matta/emacs/log/scratch/matta/for_stefan)

Thanks, merged,


        Stefan






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS
  2022-10-24 19:22   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-11-12 20:58     ` Stefan Kangas
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Kangas @ 2022-11-12 20:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Matt Armstrong, 58703-done

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> ...attached and also at the scratch/matta/for_stefan branch at
>> https://git.sr.ht/~matta/emacs (log link:
>> https://git.sr.ht/~matta/emacs/log/scratch/matta/for_stefan)
>
> Thanks, merged,

Bug was left open, so I'm closing it now.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-12 20:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-22  2:34 bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS Matt Armstrong
2022-10-22  3:06 ` Matt Armstrong
2022-10-24 19:22   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-12 20:58     ` Stefan Kangas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.