GNU bug report logs - #74276
30.0.90; undo does not account for overlays now that markers are not used

Previous Next

Package: emacs;

Reported by: James Thomas <jimjoe <at> gmx.net>

Date: Sat, 9 Nov 2024 06:43:02 UTC

Severity: normal

Found in version 30.0.90

Full log


Message #17 received at 74276 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: karthikchikmagalur <at> gmail.com, 74276 <at> debbugs.gnu.org, jimjoe <at> gmx.net
Subject: Re: bug#74276: 30.0.90; undo does not account for overlays now that
 markers are not used
Date: Thu, 14 Nov 2024 10:36:22 -0500
>> > Stefan, does undo restore overlays, and if so, how?
>> No, I don't think `undo` has ever tried to restore overlays.
>> But it does attempt to restore marker positions, so I guess there can be
>> cases where the switch to itree has caused overlays' boundaries to be
>> restored less well than before.
> Well, in this particular recipe Emacs 29 and 30 behave exactly like
> Emacs 25, do at least in this case there was no regression.

Which suggests that maybe the code we have to save/restore the position of
markers in `buffer-undo-list` doesn't(didn't?) really do its job.

> But maybe we should add to undo the capability of restoring the
> overlays.

Maybe.


        Stefan


PS: Reading the `record_marker_adjustments` in Emacs-28, it seems that
this code would happily add to the `buffer-undo-list` markers that were
"internal" to overlays.  That reminds me of a discussion many years ago
where I suggested we add functions to return the begin/end markers of an
overlay so that ELisp code could use `set-marker-insertion-type` to
change the insertion type of the beginning/end of an overlay (which is
currently otherwise fixed at creation).  This was rejected because
exposing such internals would be undesirable (e.g. making
backward-incompatible the change we implemented in Emacs-29) and risky
(allowing inconsistencies like overlays whose beg and end don't point to
the same buffer).  It turns out that such functions could have been
hacked all along in ELisp by (ab)using this `record_marker_adjustments`
code:

    (defun overlay-markers (ol)
      "Return the two markers of an overlay as (BEG . END)."
      (with-temp-buffer
        (insert "aa")
        (let ((beg (point))
              (_ (insert "bbb"))
              (end (point)))
          (insert "cccc")
          (move-overlay ol beg end (current-buffer))
          (let ((buffer-undo-list ()))
            (delete-region (point-min) (point-max))
            (cons (car (rassq -2 buffer-undo-list))
                  (car (rassq -5 buffer-undo-list)))))))

🙂





This bug report was last modified 212 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.