unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Matt Armstrong <matt@rfc20.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Ihor Radchenko" <yantar92@posteo.net>,
	"Eason Huang" <aqua0210@foxmail.com>,
	58928@debbugs.gnu.org, "Gerd Möllmann" <gerd.moellmann@gmail.com>,
	"Eli Zaretskii" <eliz@gnu.org>, "Eli Qian" <eli.q.qian@gmail.com>
Subject: bug#58928: 29.0.50; overlays in org-mode are disrupted after call `org-capture`
Date: Fri, 04 Nov 2022 15:47:55 -0700	[thread overview]
Message-ID: <87tu3ewd44.fsf@rfc20.org> (raw)
In-Reply-To: <jwveduivh85.fsf-monnier+emacs@gnu.org>

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

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

>> See attached fix to fix the bug found by Eason's steps quoted above.
>> The bug was that we ignored the "before markers" part of
>> `insert-before-markers'.
>
> I pushed a similar fix a few hours earlier, sorry :-)

Your fix was better!  ;)


>> Stefan, this and a couple other minor patches are in
>> https://git.sr.ht/~matta/emacs/log/scratch/matta/for_stefan
>
> Could you rebase the remaining minor patches?

Done (patches here and at my sr.ht).  Basically, I rewrote the test in a
way that was clearer, at lest for me, and more exhaustive.  Moved them
down to the other tests related to inserting and moving overlays.  Used
explicit buffer positions instead of (point) as a relative reference
(which confused me and seemed unrelated, since neither
`insert-before-markers` nor the overlay code is ever concerned with
(point).  If you don't like that, we I think we should still tweak the
one new test to not attempt (goto-char (2+ (point))) when point is at
eob.  :-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Tweak-the-overlay-related-insert-before-markers-test.patch --]
[-- Type: text/x-diff, Size: 4378 bytes --]

From 4e66e39cdcd27d04f21d2459516d36ea22727bca Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Fri, 4 Nov 2022 15:02:17 -0700
Subject: [PATCH 1/2] Tweak the overlay related `insert-before-markers' tests

* test/src/buffer-tests.el (test-overlay-insert-before-markers-empty):
Move code down to the other tests related to insertion.  Test all
front/rear insert combinations.  To make the test more clear, at least
to me, hard code all character positions.
(test-overlay-insert-before-markers-at-start): For both front-advance
modes verify that `insert-before-markers' at and overlay's start
advances it.
(test-overlay-insert-before-markers-at-end): For both rear-advance
modes test that `insert-before-markers' at an overlay's end advances
it.
(test-overlay-insert-before-markers-non-empty): Delete, replaced by
the two tests above.
---
 test/src/buffer-tests.el | 61 +++++++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 22 deletions(-)

diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el
index a39d7d51de1..0e9e84ef7a1 100644
--- a/test/src/buffer-tests.el
+++ b/test/src/buffer-tests.el
@@ -528,28 +528,6 @@ K
 (deftest-overlay-start/end-1 L (1 0) (1 1))
 (deftest-overlay-start/end-1 M (0 0) (1 1))
 
-(ert-deftest test-overlay-insert-before-markers-empty ()
-  (with-temp-buffer
-    (insert "1234")
-    (goto-char (1+ (point-min)))
-    (let ((overlay (make-overlay (point) (point))))
-      (insert-before-markers "x")
-      (should (equal (point) (overlay-end overlay)))
-      (should (equal (point) (overlay-start overlay))))))
-
-(ert-deftest test-overlay-insert-before-markers-non-empty ()
-  (with-temp-buffer
-    (insert "1234")
-    (goto-char (+ 2 (point)))
-    (let ((overlay (make-overlay (1- (point)) (point))))
-      (insert-before-markers "x")
-      (should (equal (point) (overlay-end overlay)))
-      (should (equal (- (point) 2) (overlay-start overlay)))
-      (forward-char -2)
-      (insert-before-markers "y")
-      (should (equal (+ 2 (point)) (overlay-end overlay)))
-      (should (equal (point) (overlay-start overlay))))))
-
 (ert-deftest test-overlay-start/end-2 ()
   (should-not (overlay-start (with-temp-buffer (make-overlay 1 1))))
   (should-not (overlay-end (with-temp-buffer (make-overlay 1 1)))))
@@ -1315,7 +1293,46 @@ test-moving-insert-2
       (delete-overlay left)
       (should (= 2 (length (overlays-in 1 (point-max))))))))
 
+;; +==========================================================================+
+;; | Moving overlays with insert-before-markers
+;; +==========================================================================+
 
+(ert-deftest test-overlay-insert-before-markers-at-start ()
+  "`insert-before-markers' always advances an overlay's start.
+Test both front-advance and non-front-advance overlays."
+  (dolist (front-advance '(nil t))
+    (ert-info ((format "front-advance %S" front-advance))
+      (with-temp-buffer
+        (insert "1234")
+        (let ((overlay (make-overlay 2 3 nil front-advance nil)))
+          (goto-char 2)
+          (insert-before-markers "x")
+          (should (equal 3 (overlay-start overlay)))
+          (should (equal 4 (overlay-end overlay))))))))
+
+(ert-deftest test-overlay-insert-before-markers-at-end ()
+  "`insert-before-markers' always advances an overlay's end.
+Test both rear-advance and non-rear-advance overlays."
+  (dolist (rear-advance '(nil t))
+    (ert-info ((format "rear-advance %S" rear-advance))
+      (with-temp-buffer
+        (insert "1234")
+        (let ((overlay (make-overlay 2 3 nil nil rear-advance)))
+          (goto-char 3)
+          (insert-before-markers "x")
+          (should (equal 2 (overlay-start overlay)))
+          (should (equal 4 (overlay-end overlay))))))))
+
+(ert-deftest test-overlay-insert-before-markers-empty ()
+  (dolist (advance-args '((nil nil) (t nil) (nil t) (t t)))
+    (ert-info ((format "advance args %S" advance-args))
+      (with-temp-buffer
+        (insert "1234")
+        (let ((overlay (apply #'make-overlay 2 2 nil advance-args)))
+          (goto-char 2)
+          (insert-before-markers "x")
+          (should (equal 3 (overlay-start overlay)))
+          (should (equal 3 (overlay-end overlay))))))))
 
 ;; +==========================================================================+
 ;; | Moving by deletions
-- 
2.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Minor-tweaks-to-the-fix-for-insert-before-markers-ov.patch --]
[-- Type: text/x-diff, Size: 1598 bytes --]

From e7e66c30430b4e331a9285159851492fd4c78c3c Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Fri, 4 Nov 2022 15:24:40 -0700
Subject: [PATCH 2/2] Minor tweaks to the fix for `insert-before-markers'
 overlay fix

(bug#58928)

* src/buffer.c (adjust_overlays_for_insert): wrap to less than 80
chars.
* src/itree.c: document BEFORE_MARKERS.
---
 src/buffer.c | 3 ++-
 src/itree.c  | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c
index 745e62f53f7..390ccff5c8a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -3467,7 +3467,8 @@ adjust_overlays_for_insert (ptrdiff_t pos, ptrdiff_t length, bool before_markers
       itree_insert_gap (base->overlays, pos, length, before_markers);
       FOR_EACH_LIVE_BUFFER (tail, other)
         if (XBUFFER (other)->base_buffer == base)
-          itree_insert_gap (XBUFFER (other)->overlays, pos, length, before_markers);
+	  itree_insert_gap (XBUFFER (other)->overlays, pos, length,
+			    before_markers);
     }
 }
 
diff --git a/src/itree.c b/src/itree.c
index cd37da18b89..b744b8423a2 100644
--- a/src/itree.c
+++ b/src/itree.c
@@ -1183,7 +1183,10 @@ itree_iterator_finish (struct itree_iterator *iter)
 
 /* Insert a gap at POS of length LENGTH expanding all intervals
    intersecting it, while respecting their rear_advance and
-   front_advance setting. */
+   front_advance setting.
+
+   When BEFORE_MARKERS, all overlays beginning/ending at POS are
+   treated as if their front_advance/rear_advance was true. */
 
 void
 itree_insert_gap (struct itree_tree *tree,
-- 
2.35.1


  reply	other threads:[~2022-11-04 22:47 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 13:58 bug#58928: 29.0.50; overlays in org-mode are disrupted after call `org-capture` Eli Qian
2022-11-01  6:14 ` Eli Zaretskii
2022-11-01  7:01   ` Gerd Möllmann
     [not found]     ` <87sfj3gmsx.fsf@gmail.com>
2022-11-01  7:50       ` Gerd Möllmann
2022-11-01  8:08         ` Gerd Möllmann
2022-11-01  9:07         ` Ihor Radchenko
2022-11-01  9:20           ` Gerd Möllmann
2022-11-01 22:36             ` Matt Armstrong
2022-11-01 23:25               ` Matt Armstrong
2022-11-02  1:39             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-02  2:49               ` Matt Armstrong
2022-11-02  4:53               ` Gerd Möllmann
2022-11-03 13:10               ` Eason Huang
2022-11-03 14:25                 ` Gerd Möllmann
2022-11-03 14:57                   ` Eason Huang
2022-11-03 15:18                     ` Gerd Möllmann
2022-11-03 15:41                       ` Eason Huang
2022-11-03 15:02                   ` Eason Huang
2022-11-03 15:45                     ` Eason Huang
2022-11-03 16:12                       ` Gerd Möllmann
2022-11-03 22:51                     ` Matt Armstrong
2022-11-04  2:49                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-04  4:33                       ` Matt Armstrong
2022-11-04 16:05                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-04 22:47                           ` Matt Armstrong [this message]
2022-11-04 22:58                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-05  6:28                             ` Eli Zaretskii
2022-11-04  3:47                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-04 18:06                       ` Matt Armstrong
2022-11-05  2:45                         ` Ihor Radchenko

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tu3ewd44.fsf@rfc20.org \
    --to=matt@rfc20.org \
    --cc=58928@debbugs.gnu.org \
    --cc=aqua0210@foxmail.com \
    --cc=eli.q.qian@gmail.com \
    --cc=eliz@gnu.org \
    --cc=gerd.moellmann@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=yantar92@posteo.net \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).