commit 7caaa017aa4cfc5243178618a88633525a8e18b3 Author: Campbell Barton Date: Sun Nov 7 19:39:29 2021 +1100 Add 'with-undo-amalgamate-change-group' macro This allows commands to be made without adding undo-barriers, e.g. kmacro-exec-ring-item. diff --git a/lisp/subr.el b/lisp/subr.el index f6dbd00532..945aaa8fef 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3542,6 +3542,25 @@ atomic-change-group (accept-change-group ,handle) (cancel-change-group ,handle)))))) +(defmacro with-undo-amalgamate-change-group (&rest body) + "Like `progn' but perform BODY with amalgamated undo barriers. + +This allows multiple operations to be undone in a single step." + (declare (indent 0) (debug t)) + (let ((handle (make-symbol "--change-group-handle--"))) + `(let ((,handle (prepare-change-group)) + ;; Don't truncate any undo data in the middle of this. + (undo-outer-limit nil) + (undo-limit most-positive-fixnum) + (undo-strong-limit most-positive-fixnum)) + (unwind-protect + (progn + (activate-change-group ,handle) + ,@body) + (progn + (accept-change-group ,handle) + (undo-amalgamate-change-group ,handle)))))) + (defun prepare-change-group (&optional buffer) "Return a handle for the current buffer's state, for a change group. If you specify BUFFER, make a handle for BUFFER's state instead.