help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to amalgamate changes across multiple buffers into a single undo


From: Ihor Radchenko
Subject: Re: How to amalgamate changes across multiple buffers into a single undo entry
Date: Sun, 26 Jul 2020 18:30:19 +0800

> Suppose one action causes a change in two buffers. I'd like a way of 
> performing an undo operation so that both buffers will be undone at once. But 
> I can't figure out how to amalgamate the buffer changes properly. This is 
> what I've got:

You might try to look into org-agenda-undo. It implements something
similar I think.

Best,
Ihor

Brian Leung <leungbk@mailfence.com> writes:

> Suppose one action causes a change in two buffers. I'd like a way of 
> performing an undo operation so that both buffers will be undone at once. But 
> I can't figure out how to amalgamate the buffer changes properly. This is 
> what I've got:
>
> (defmacro my/with-single-undo (curr-buf &rest body)
>   "Within CURR-BUF, execute BODY as a single undo step."
>   (declare (indent 1))
>   (let ((marker (cl-gensym "marker")))
>     `(let ((,marker
>             (nconc (prepare-change-group ,curr-buf)
>                    (prepare-change-group (get-buffer-create "b.txt")))))
>        (unwind-protect
>            (progn ,@body)
>          (undo-amalgamate-change-group ,marker)))))
>
> (defun my/insert-some-stuff (&rest _args)
>   (interactive)
>   (my/with-single-undo (current-buffer)
>     (insert "apple banana caterpillar\n")
>     (with-current-buffer (get-buffer-create "b.txt")
>       (insert "xylophone yak zebra"))))
>
> I test by making "a.txt" and "b.txt" files, opening both up, and then 
> executing M-x my/insert-some-stuff from within a.txt. Right now, undo is only 
> undoing changes within the buffer in which I execute it.
>
> I'd appreciate any help on this.
>
> Best,
> Brian
>

-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong 
University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]