From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Support for undo-amalgamate in a version of the atomic-change-group macro (with patch) Date: Mon, 08 Nov 2021 08:40:12 -0500 Message-ID: References: <2d2efa59-cf88-5238-0db6-58d55e6c5c98@gmail.com> <87v913b6g7.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3880"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Lars Ingebrigtsen , Emacs developers To: Campbell Barton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 08 14:42:31 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mk4us-0000ii-6x for ged-emacs-devel@m.gmane-mx.org; Mon, 08 Nov 2021 14:42:30 +0100 Original-Received: from localhost ([::1]:32808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mk4uq-0004Vw-Ge for ged-emacs-devel@m.gmane-mx.org; Mon, 08 Nov 2021 08:42:28 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mk4sx-0003K3-Cm for emacs-devel@gnu.org; Mon, 08 Nov 2021 08:40:36 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54285) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mk4ss-0000tK-Gv for emacs-devel@gnu.org; Mon, 08 Nov 2021 08:40:30 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 7B569440877; Mon, 8 Nov 2021 08:40:16 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 75DB4440885; Mon, 8 Nov 2021 08:40:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1636378814; bh=1qrqVHvYx5h0Ms8WhYsnEvjJVKGpFI/PM/L8XZwHWog=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=VHwA5FOzaI6nHDqdek2eZw9mbgC1l0ZBC6944ZidF0otg2CO6DpZSWgBLsZB3frlI ENG9OemgS2Xwboz8yhD2KhUPvVJAFYWpqE1EAmccELLql37yHYEi5Clta2Lawen8aL mDNRbVcmIt/6bTfKflmsIGA+3r8B/YKacxaHiQihQZzeJGQvEI80bk1TKXNq8sp+3j kDIAky3SRVQjWqWmeXdPWOyBg6q7b64dkNVzg5dLFALXV8Yt0rCvw1GvYuPWnLItE0 PQVw3CdAsN5Gm7EczvCY8KqG1GS2jgdYBMK1+OvFWb6vh8EQdSlu3wAYDeYcyEOLxL aI9L0dNxm8xHw== Original-Received: from pastel (unknown [45.72.241.23]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 41EF6120376; Mon, 8 Nov 2021 08:40:14 -0500 (EST) In-Reply-To: (Campbell Barton's message of "Mon, 8 Nov 2021 16:41:48 +1100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:279037 Archived-At: > Updated the patch, for what it's worth - I'm not so keen on the name > `with-single-undo'. Fair enough. Besides, I believe it would be slightly misleading because it doesn't guarantee that this makes exactly one undo step (it might be include changes performed before/after). I pushed your change as below. Please note the changes in the commit message format to follow our conventions, and the documentation that should ideally come with such patches. Stefan commit 5861b8d027382ecbd4c0d3dffc283b8ac95b5692 Author: Campbell Barton Date: Mon Nov 8 16:33:39 2021 +1100 * lisp/subr.el (with-undo-amalgamate): New macro This allows commands to be made without adding undo-barriers, e.g. kmacro-exec-ring-item. diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index fa1135b8026..937680c200d 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -1506,6 +1506,11 @@ Undo This function does not bind @code{undo-in-progress}. @end defun +@defmac with-undo-amalgamate body@dots{} +This macro removes all the undo boundaries inserted during the +execution of @var{body} so that it can be undone as a single step. +@end defmac + Some commands leave the region active after execution in such a way that it interferes with selective undo of that command. To make @code{undo} ignore the active region when invoked immediately after such a command, diff --git a/etc/NEWS b/etc/NEWS index a297948a11a..874af33c752 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -598,6 +598,10 @@ Use 'exif-parse-file' and 'exif-field' instead. * Lisp Changes in Emacs 29.1 ++++ +*** New macro 'with-undo-amalgamate' +It records a particular sequence of operations as a single undo step + +++ *** New command 'yank-media'. This command supports yanking non-plain-text media like images and diff --git a/lisp/subr.el b/lisp/subr.el index f6dbd00532e..5a5842d4287 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3542,6 +3542,29 @@ atomic-change-group (accept-change-group ,handle) (cancel-change-group ,handle)))))) +(defmacro with-undo-amalgamate (&rest body) + "Like `progn' but perform BODY with amalgamated undo barriers. + +This allows multiple operations to be undone in a single step. +When undo is disabled this behaves like `progn'." + (declare (indent 0) (debug t)) + (let ((handle (make-symbol "--change-group-handle--"))) + `(let ((,handle (prepare-change-group)) + ;; Don't truncate any undo data in the middle of this, + ;; otherwise Emacs might truncate part of the resulting + ;; undo step: we want to mimic the behavior we'd get if the + ;; undo-boundaries were never added in the first place. + (undo-outer-limit nil) + (undo-limit most-positive-fixnum) + (undo-strong-limit most-positive-fixnum)) + (unwind-protect + (progn + (activate-change-group ,handle) + ,@body) + (progn + (accept-change-group ,handle) + (undo-amalgamate-change-group ,handle)))))) + (defun prepare-change-group (&optional buffer) "Return a handle for the current buffer's state, for a change group. If you specify BUFFER, make a handle for BUFFER's state instead.