[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Editing change groups
From: |
Joost Kremers |
Subject: |
Re: Editing change groups |
Date: |
Fri, 9 Nov 2018 09:39:51 +0100 |
User-agent: |
Mutt/1.9.4 (2018-02-28) |
On Fri, Nov 09, 2018 at 08:52:16AM +0100, Michael Heerdegen wrote:
> Hello,
>
> I have the following requirement for a user interface: if the user hits
> a key, something in the buffer is replaced with something else. Doing
> this potentially involves several editing operations. If the user hits
> the same key again, the old contents are restored.
>
> My question is: are change groups, as described in (info "(elisp) Atomic
> Changes"), a suitable tool to do this?
>From the description in the manual, it would seem they're not: you can only
>finish the change group once, so once the change has been accepted (and
>becomes visible for the user), they cannot be undone as a group.
The purpose of atomic change groups seems to be to make changes that can be
undone as a group when an error occurs *while the changes are being made*. You
want to be able for a group of editing operations to be undone as a group.
> AFAIK it works, but I must admit
> I don't understand the implementation of change groups. I tried to use
> an example like
>
> (defun my-test-change-groups ()
> (interactive)
> (insert "0\n")
> (let ((g (prepare-change-group)))
> (insert "a\n")
> (activate-change-group g)
> (insert "b\n")
> (insert "c\n")
> (cancel-change-group g)))
>
> to see how things work but that doesn't work as I expected: calling the
> command leaves all insertions intact as if the change group G hadn't
> been canceled.
That's something I cannot make sense of. Looks like a bug, though might very
well not be.
> OTOH, if I remove the first insertion (insert "0\n")
> from the example, calling the function causes nothing to be inserted at
> all.
Because the change group is being undone. ;-) Try adding an insert after the
cancel-change-group:
```
(defun my-test-change-groups ()
(interactive)
(let ((g (prepare-change-group)))
(insert "a\n")
(activate-change-group g)
(insert "b\n")
(insert "c\n")
(cancel-change-group g)
(insert "d\n")))
```
You'll see "d" inserted in the buffer.
--
Joost Kremers
Life has its moments