From: Matt Armstrong <matt@rfc20.org>
To: 58703@debbugs.gnu.org
Cc: stefan monnier <monnier@iro.umontreal.ca>
Subject: bug#58703: 29.0.50; [noverlay] overlays-at misses overlays starting at POS
Date: Fri, 21 Oct 2022 20:06:15 -0700 [thread overview]
Message-ID: <87h6zw4kwo.fsf@rfc20.org> (raw)
In-Reply-To: <87lep84md5.fsf@rfc20.org>
[-- 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
next prev parent reply other threads:[~2022-10-22 3:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h6zw4kwo.fsf@rfc20.org \
--to=matt@rfc20.org \
--cc=58703@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.