From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Editing change groups Date: Fri, 9 Nov 2018 09:39:51 +0100 Message-ID: <20181109083951.GA2677@Swift> References: <87sh0an0wf.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: blaine.gmane.org 1541753918 31742 195.159.176.226 (9 Nov 2018 08:58:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Nov 2018 08:58:38 +0000 (UTC) User-Agent: Mutt/1.9.4 (2018-02-28) To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 09 09:58:34 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gL2cb-00086b-0A for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Nov 2018 09:58:33 +0100 Original-Received: from localhost ([::1]:60962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL2eh-0004xW-Fc for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Nov 2018 04:00:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL2eA-0004xJ-Dk for help-gnu-emacs@gnu.org; Fri, 09 Nov 2018 04:00:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gL2e5-0008N5-6n for help-gnu-emacs@gnu.org; Fri, 09 Nov 2018 04:00:10 -0500 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:45217) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gL2e4-00067r-Q5 for help-gnu-emacs@gnu.org; Fri, 09 Nov 2018 04:00:05 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 355ACC21 for ; Fri, 9 Nov 2018 03:59:31 -0500 (EST) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 09 Nov 2018 03:59:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= resent-from:resent-date:resent-message-id:resent-to:date:from:to :subject:message-id:references:mime-version:content-type :in-reply-to; s=fm1; bh=8fGMaWFv1diX9xIASUVXj8AcGWuguPET5Ytvy0ZA 9zo=; b=jiUWKj5oJ/r8lZf8MD8FtdcnfnvqByBiMhoKbEQyStWGcTHXFoVah889 RxbBrg48Q9XjJWroAsI/V0kacUSQ1SduLA9b2GEHrjMBm6PV7HnukopYw9kO7VWg omJZHPECG7PV8CBJSr0mArQQrAwgq+ELOsidVJVRfl/c/Als3DbKyWdq2KB4vs/D WNc3bSykJNZOJlm14fm9lhBeiSBVEM7x4pIT3txEUlJYyDhVLFqdCMLtGtp0lXAH a2aP0pxZizOxo/yoJjA8tx8X7xvEHj9Um7C4YGsrzXZQF8fnn0FiD7k2ttaebvle uV6NYncyQO7kPsk6mHFBh9Ql6adkBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:resent-date:resent-from :resent-message-id:resent-to:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=8fGMaWFv1diX9xIAS UVXj8AcGWuguPET5Ytvy0ZA9zo=; b=Y1PrZfiXHGWBzh5aIxMuAZZmC3lE4aVLt 5214Uoiw9lHDVlhTQNzFni3eYCv2XyOdiTLsD5xKJ+JovNDjNsSIY4aeBdXY+TAL OXeRXihk7PWlHWVyZ1DCaJ/Xolb51CPxpT9udySSduNxRtSPZERMDBxYCFxAhg0G cdznhcaMy7r0c48rOmhAE17BUAO5C3lqI4oxLtjvdbTUK8kjTdQFRH5Q9THuSeZE CdWgKh5SU1I6IMjJKfDFB1A1kkJld5J0uWPHWBIDYsSl9tXydH0OREYFFcCu6coF Jrl+vViCgyNgnzT5ff66ic51VnKmfbNpc+fAXnRdYvmlhz7OxxdRg== X-ME-Sender: X-ME-Proxy: Original-Received: from Swift (freund-druck.geistwis.uni-wuppertal.de [132.195.204.212]) by mail.messagingengine.com (Postfix) with ESMTPA id 4E29F102E8 for ; Fri, 9 Nov 2018 03:59:30 -0500 (EST) Resent-From: Joost Kremers Resent-Date: Fri, 9 Nov 2018 09:59:28 +0100 Resent-Message-ID: <20181109085928.GA5002@Swift> Resent-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87sh0an0wf.fsf@web.de> X-Editor: Emacs of course! X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.123.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118606 Archived-At: 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