1

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 ()
  (interactive)
  (insert "toto")
  (undo-boundary)
  (insert "titi"))

(defun test-collapse ()
  (interactive)
  (with-undo-collapse
    (insert "toto")
    (undo-boundary)
    (insert "titi")))
Gabriele Nicolardi
  • 1,199
  • 8
  • 17

2 Answers2

3

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")
    (undo-boundary)
    (insert "titi")
    (undo-amalgamate-change-group cg)))
Stefan
  • 26,154
  • 3
  • 46
  • 84
  • Could you please post a concrete example of usage of this function using the above`test-collapse` code? I have some difficulty understanding the `undo-amalgamate-change-group` usage. – Gabriele Nicolardi Mar 01 '19 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 '19 at 07:37
0

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

ideasman42
  • 8,375
  • 1
  • 28
  • 105