Recently emacs has a feature undo-amalgamate-change-group
which can be used to merge multiple actions into a single undo step.
How can this be used to make a with-undo-collapse
macro similar to this one, which:
- Handles errors.
- Forwards the result of the body of the macro.
This is a basic version, however I'm not sure how it should work when there is an error in the body of the code which runs in this block.
(defmacro with-undo-collapse (&rest body)
"Execute body, then collapse any resulting undo boundaries."
(declare (indent 0))
`(let ((cg (prepare-change-group)))
(progn ,@body)
(undo-amalgamate-change-group cg)))