I wondered why the jch's with-undo-collapse macro (or something like that) isn't an emacs built-in yet.

Is it safe enough? Is there a built-in alternative?

I mean something that can be applied like in the jcs's example of usage:

(defun test-no-collapse ()
  (insert "toto")
  (insert "titi"))

(defun test-collapse ()
    (insert "toto")
    (insert "titi")))
  • 2
    M-x report-emacs-bug as a feature request. Things don't get built-in if no one asks for them.
    – phils
    Mar 1, 2019 at 6:16
  • @phils Thank you. I'll do it soon. Mar 1, 2019 at 6:50

2 Answers 2


There is undo-amalgamate-change-group nowadays. Used for instance in the function viper-adjust-undo in the file lisp/emulators/viper-cmd.el:

(defun test-collapse ()
  (let ((cg (prepare-change-group)))
    (insert "toto")
    (insert "titi")
    (undo-amalgamate-change-group cg)))
  • Could you please post a concrete example of usage of this function using the abovetest-collapse code? I have some difficulty understanding the undo-amalgamate-change-group usage. Mar 1, 2019 at 15:41
  • It would be nice to write an with-undo-collapse macro that uses undo-amalgamate-change-group, since it's more verbose with explicit change-group references.
    – ideasman42
    Dec 16, 2019 at 7:37

Emacs 28 has a built-in macro with-undo-amalgamate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.