From: Gregory Heytings <gregory@heytings.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 60467@debbugs.gnu.org, yantar92@posteo.net,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#60467: 30.0.50; primitive-undo: Changes to be undone by function different from announced
Date: Tue, 03 Jan 2023 13:44:01 +0000 [thread overview]
Message-ID: <ecc7317ec92f7450cdd2@heytings.org> (raw)
In-Reply-To: <838rij23by.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1129 bytes --]
>> Patch attached.
>
> Hmm... scary, even if this is intended for the master branch. Could you
> at least keep the few comments which were in the original code, and
> perhaps also add comments explaining all those tricky tests with consp,
> equality to t and to old-bul, the significance of (car ptr) and (caar
> ptr), etc.? This would make the code more maintainer-friendly, as the
> need to constantly consult the spec of the various undo-list elements
> (and hope the spec is complete and accurate ;-) would be avoided.
>
Is the attached patch better in that respect?
>
> I'd prefer to fix this in Emacs 29 if feasible, but unless the changes
> are much simpler and/or more clearly documented, so that it becomes
> possible to assess their risks, I don't see how that could happen.
>
I don't see how the changes could be made simpler, sorry, but now they are
documented. Feel free to ask further questions if something is still
unclear.
>
> I presume that all the undo tests we have still pass?
>
They do.
>
> If so, how about adding a test for this bug?
>
I'll see if I can do that, but it seems tricky.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix-combine-change-call.patch --]
[-- Type: text/x-diff; name=Fix-combine-change-call.patch, Size: 3207 bytes --]
From 8f65a74ec1b86b3f5f295972c99b0b461cc7bd28 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Tue, 3 Jan 2023 13:29:06 +0000
Subject: [PATCH] Fix combine-change-call
* lisp/subr.el (combine-change-calls-1): Rewrite the part which
creates the undo-list element. Fixes bug#60467.
---
lisp/subr.el | 56 +++++++++++++++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 25 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 9087f9a404..da105d3474 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4934,31 +4934,37 @@ combine-change-calls-1
(kill-local-variable 'before-change-functions))
(if local-acf (setq after-change-functions acf)
(kill-local-variable 'after-change-functions))))
- (when (not (eq buffer-undo-list t))
- (let ((ap-elt
- (list 'apply
- (- end end-marker)
- beg
- (marker-position end-marker)
- #'undo--wrap-and-run-primitive-undo
- beg (marker-position end-marker) buffer-undo-list))
- (ptr buffer-undo-list))
- (if (not (eq buffer-undo-list old-bul))
- (progn
- (while (and (not (eq (cdr ptr) old-bul))
- ;; In case garbage collection has removed OLD-BUL.
- (cdr ptr)
- ;; Don't include a timestamp entry.
- (not (and (consp (cdr ptr))
- (consp (cadr ptr))
- (eq (caadr ptr) t)
- (setq old-bul (cdr ptr)))))
- (setq ptr (cdr ptr)))
- (unless (cdr ptr)
- (message "combine-change-calls: buffer-undo-list broken"))
- (setcdr ptr nil)
- (push ap-elt buffer-undo-list)
- (setcdr buffer-undo-list old-bul)))))
+ ;; If buffer-undo-list is neither t (in which case undo
+ ;; information is not recorded) nor equal to buffer-undo-list
+ ;; before body was evaluated (in which case evaluating body
+ ;; did not add items to buffer-undo-list) ...
+ (when (and (not (eq buffer-undo-list t))
+ (not (eq buffer-undo-list old-bul)))
+ (let ((ptr buffer-undo-list) body-undo-list)
+ ;; ... then loop over buffer-undo-list, until the head of
+ ;; buffer-undo-list before body was evaluated is found ...
+ (while (not (eq ptr old-bul))
+ ;; ... and add the entries to body-undo-list, unless
+ ;; they are of the form (t . <something>), which are
+ ;; entries that record buffer modification timestamps.
+ (unless (and (consp (car ptr))
+ (eq (caar ptr) t))
+ (push (car ptr) body-undo-list))
+ (setq ptr (cdr ptr)))
+ (setq body-undo-list (nreverse body-undo-list))
+ ;; Add an (apply ...) entry to buffer-undo-list, using
+ ;; body-undo-list ...
+ (push (list 'apply
+ (- end end-marker)
+ beg
+ (marker-position end-marker)
+ #'undo--wrap-and-run-primitive-undo
+ beg (marker-position end-marker)
+ body-undo-list)
+ buffer-undo-list)
+ ;; ... and set the cdr of buffer-undo-list to
+ ;; buffer-undo-list before body was evaluated.
+ (setcdr buffer-undo-list old-bul)))
(if (not inhibit-modification-hooks)
(run-hook-with-args 'after-change-functions
beg (marker-position end-marker)
--
2.39.0
next prev parent reply other threads:[~2023-01-03 13:44 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-01 13:40 bug#60467: 30.0.50; primitive-undo: Changes to be undone by function different from announced Ihor Radchenko
2023-01-01 14:38 ` Eli Zaretskii
2023-01-02 0:46 ` Gregory Heytings
2023-01-02 1:50 ` Gregory Heytings
2023-01-02 9:31 ` Ihor Radchenko
2023-01-03 9:41 ` Gregory Heytings
2023-01-03 12:46 ` Eli Zaretskii
2023-01-03 13:44 ` Gregory Heytings [this message]
2023-01-03 14:48 ` Eli Zaretskii
2023-01-03 15:05 ` Gregory Heytings
2023-01-03 16:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-03 16:33 ` Gregory Heytings
2023-01-03 16:51 ` Gregory Heytings
2023-01-04 0:16 ` Gregory Heytings
2023-01-04 2:49 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-04 9:24 ` Gregory Heytings
2023-01-04 10:50 ` Gregory Heytings
2023-01-04 14:39 ` Eli Zaretskii
2023-01-04 14:43 ` Gregory Heytings
2023-01-04 14:36 ` Eli Zaretskii
2023-01-04 14:39 ` Gregory Heytings
2023-01-04 18:02 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-04 18:16 ` Gregory Heytings
2023-01-04 18:42 ` Eli Zaretskii
2023-01-04 21:04 ` Gregory Heytings
2023-01-03 14:56 ` Gregory Heytings
2023-01-03 15:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-03 15:29 ` Gregory Heytings
2023-01-03 16:32 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-08 15:43 ` Alan Mackenzie
2023-01-09 6:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-09 12:16 ` Eli Zaretskii
2023-01-13 22:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-14 7:06 ` Eli Zaretskii
2023-01-02 9:27 ` Ihor Radchenko
2023-06-22 19:28 ` bug#60467: New problem introduced Frédéric Giquel via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-23 11:01 ` bug#60467: 30.0.50; primitive-undo: Changes to be undone by function different from announced Eli Zaretskii
2023-06-23 13:06 ` Gregory Heytings
2023-06-26 14:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-26 14:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-26 15:18 ` Gregory Heytings
2023-06-26 15:30 ` Eli Zaretskii
2023-07-01 14:14 ` Gregory Heytings
2023-07-01 14:27 ` Eli Zaretskii
2023-07-15 7:46 ` Eli Zaretskii
2023-08-03 7:38 ` Eli Zaretskii
2023-08-10 11:28 ` Gregory Heytings
2023-08-10 13:41 ` Eli Zaretskii
2023-08-10 13:55 ` Gregory Heytings
2023-08-12 7:09 ` Eli Zaretskii
2023-08-16 16:09 ` Gregory Heytings
[not found] <3eea0a7dff2915453876fc3a2b628886c78a4d4b.camel@laposte.net>
2023-07-04 0:03 ` sbaugh
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=ecc7317ec92f7450cdd2@heytings.org \
--to=gregory@heytings.org \
--cc=60467@debbugs.gnu.org \
--cc=eliz@gnu.org \
--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).