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: Emanuel Berg
Subject: Re: How to amalgamate changes across multiple buffers into a single undo entry
Date: Fri, 24 Jul 2020 03:44:40 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Brian Leung wrote:

> 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 [...]

Well, first, what do you mean exactly by "at once"?
You mean it should appear to the user as an atomic
event, right? (Or, correspondingly, if it is to be
invoked from Lisp, it should just require a single
invocation for both buffers?)

Well, yeah, I suppose that can be automated - just
iterate the buffers and `undo' in each and every one.

Like, for example, like this:

(require 'cl-lib)
(defun undo-in-two-buffers (msg bfr-a bfr-b)
  (let ((buff-a (get-buffer-create bfr-a))
        (buff-b (get-buffer-create bfr-b)) )
    (cl-dolist (buff (list buff-a buff-b))
      (with-current-buffer buff
        (insert msg) ))
    (cl-dolist (buff (list buff-a buff-b))
      (with-current-buffer buff
        (undo) ))))
;; (undo-in-two-buffers "undo me two times" "test-bfr-1" "test-bfr-2")

But... I don't like the idea of that use of `undo'.
Humans should use that as a part of the interactive
edit and muscle memory/finger habits. But it doesn't
feel right that program rely on it. Maybe I'm wrong
here, I don't know. In all my Elisp, I never used
`undo'.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

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