From: Joost Kremers <joostkremers@fastmail.fm>
To: Michael Heerdegen <michael_heerdegen@web.de>
Subject: Re: Editing change groups
Date: Fri, 9 Nov 2018 09:39:51 +0100 [thread overview]
Message-ID: <20181109083951.GA2677@Swift> (raw)
In-Reply-To: <87sh0an0wf.fsf@web.de>
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
next prev parent reply other threads:[~2018-11-09 8:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-09 7:52 Editing change groups Michael Heerdegen
2018-11-09 8:39 ` Joost Kremers [this message]
2018-11-09 11:58 ` Noam Postavsky
2018-11-09 12:39 ` Michael Heerdegen
2018-11-09 13:14 ` Eli Zaretskii
2018-11-09 13:12 ` Michael Heerdegen
2018-11-09 13:52 ` Stefan Monnier
2018-11-10 4:53 ` Michael Heerdegen
2018-11-10 13:15 ` Stefan Monnier
2018-11-10 16:23 ` Michael Heerdegen
2018-11-10 18:07 ` Stefan Monnier
2018-11-11 8:01 ` Michael Heerdegen
[not found] <mailman.3697.1541749970.1284.help-gnu-emacs@gnu.org>
2018-11-09 11:41 ` Ben Bacarisse
2018-11-09 12:10 ` Michael Heerdegen
[not found] ` <mailman.3721.1541765458.1284.help-gnu-emacs@gnu.org>
2018-11-09 13:36 ` Ben Bacarisse
2018-11-09 13:58 ` Michael Heerdegen
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181109083951.GA2677@Swift \
--to=joostkremers@fastmail.fm \
--cc=michael_heerdegen@web.de \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.