Subject: bug#60467: 30.0.50; primitive-undo: Changes to be undone by function different from announced

From: Gregory Heytings <[email-masked]>
Date: Mon, 02 Jan 2023 01:50:23 +0000

>
> If it's an Emacs bug, which is possible, it's in combine-change-calls.
>

A few more details on the bug.  It's still unclear to me whether the bug 
is in Org or in Emacs.

When the file is opened we start with buffer-undo-list = nil.

The (org-with-limited-levels (org-map-tree 'org-promote)) body in 
org-promote-subtree, called inside a combine-change-calls, adds four 
entries to buffer-undo-list:

("** " . 6) <timestamp> (9 . 11) <timestamp>

which means that three characters have been removed and two have been 
added in the buffer, which seems correct, although the (9 . 11) entry 
looks a bit suspicious.  Perhaps (6 . 8) would have been expected there? 
However, this change does not happen outside the region on which 
combine-change-calls is called, which is 6-11.

Upon returning from combine-change-calls, buffer-undo-list contains four 
elements, when a single element would have been expected, if I understand 
its docstring correctly:

(apply 1 6 10 #'undo--wrap-and-run-primitive-undo 6 10 (("** " . 6))) <timestamp> (9 . 11) <timestamp>