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 00:46:17 +0000

>
> I am not sure if it is Emacs bug, but I have difficulty understanding 
> the origin of the following error:
>
> 1. Create /tmp/bug.org with the following contents
>
> * h1
> ** h2
>
> 2. emacs -Q /tmp/bug.org
> 3. Move point to h2
> 4. M-x org-promote-subtree
> 5. M-x undo
> 6. Observe "Changes to be undone by function different from announced" error
>

The culprit is 85e0a69567 (in the Org repository), and the bug is fixed 
by:

diff --git a/lisp/org.el b/lisp/org.el
index a98a7f5a0..becb302e1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6554,8 +6554,7 @@ See also `org-promote'."
    (interactive)
    (save-excursion
      (org-back-to-heading t)
-    (combine-change-calls (point) (save-excursion (org-end-of-subtree t))
-      (org-with-limited-levels (org-map-tree 'org-promote))))
+    (org-with-limited-levels (org-map-tree 'org-promote)))
    (org-fix-position-after-promote))

  (defun org-demote-subtree ()
@@ -6564,8 +6563,7 @@ See `org-demote' and `org-promote'."
    (interactive)
    (save-excursion
      (org-back-to-heading t)
-    (combine-change-calls (point) (save-excursion (org-end-of-subtree t))
-      (org-with-limited-levels (org-map-tree 'org-demote))))
+    (org-with-limited-levels (org-map-tree 'org-demote)))
    (org-fix-position-after-promote))

  (defun org-do-promote ()

Perhaps another better fix exists.  If it's an Emacs bug, which is 
possible, it's in combine-change-calls.