unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Brian Leung <leungbk@mailfence.com>, help-gnu-emacs@gnu.org
Subject: Re: How to amalgamate changes across multiple buffers into a single undo entry
Date: Sun, 26 Jul 2020 18:30:19 +0800	[thread overview]
Message-ID: <87365epo04.fsf@localhost> (raw)
In-Reply-To: <mailman.353.1595490028.24492.help-gnu-emacs@gnu.org>

> 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



      parent reply	other threads:[~2020-07-26 10:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23  4:14 How to amalgamate changes across multiple buffers into a single undo entry Brian Leung
2020-07-23 21:55 ` Michael Heerdegen
2020-07-23 22:11   ` Michael Heerdegen
2020-07-24  1:44 ` Emanuel Berg via Users list for the GNU Emacs text editor
     [not found] ` <mailman.353.1595490028.24492.help-gnu-emacs@gnu.org>
2020-07-26 10:30   ` Ihor Radchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87365epo04.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=leungbk@mailfence.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).