From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Brian Leung Newsgroups: gmane.emacs.help Subject: How to amalgamate changes across multiple buffers into a single undo entry Date: Thu, 23 Jul 2020 06:14:38 +0200 (CEST) Message-ID: <906746352.441036.1595477678356@ichabod.co-bxl> Reply-To: Brian Leung Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24678"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 23 09:40:55 2020 Return-path: Envelope-to: geh-help-gnu-emacs@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 1jyVqY-0006KM-Sk for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jul 2020 09:40:54 +0200 Original-Received: from localhost ([::1]:33116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyVqX-00079x-TM for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jul 2020 03:40:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jySd6-0007iY-Qc for help-gnu-emacs@gnu.org; Thu, 23 Jul 2020 00:14:49 -0400 Original-Received: from wilbur.contactoffice.com ([212.3.242.68]:41182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jySd3-0007XX-5l for help-gnu-emacs@gnu.org; Thu, 23 Jul 2020 00:14:48 -0400 Original-Received: from ichabod.co-bxl (ichabod.co-bxl [10.2.0.36]) by wilbur.contactoffice.com (Postfix) with ESMTP id 94269C35 for ; Thu, 23 Jul 2020 06:14:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailfence.com; s=20160819-nLV10XS2; t=1595477680; bh=DH6bVZzixlPS1XL7vNKjl/PoUgjYBECe0BC35ke5dwQ=; h=Date:Subject:Reply-To:From:To:From; b=lPvimtJaB8MBS3cxTIC1TaXBECBSdv/rHT9sE6iZv+yf1CetDrFGJYdddGK+jAXOT Yd8eyb0cNm3aajfXy5fAg1FO1ji9zgLCaW/iw+jvWCt+vs+jb4FQBwxjwwTBbbEdgu HZ4dmjHLyjSd/R2tuFwTzI5Ddlq0H27EZTwvDZ9oRzLDJXbL61leI9b1PvRKQ4IGHQ J+dMoYtbozLNMQESFeUYC5WcBv1FFeHvAlfpsBdtw6PohCjhP65NS7q1b+8X0p5u5h rX83etardF/CBi5iR9kU5wvFhtTUpXh5iNeLFMpJ7+2t77S3m+m3hhUMs5aFV+OKoz 8JlcPnHEY5k1A== X-Priority: 3 X-Mailer: ContactOffice Mail X-ContactOffice-Account: com:225491745 Received-SPF: pass client-ip=212.3.242.68; envelope-from=leungbk@mailfence.com; helo=wilbur.contactoffice.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 00:14:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 23 Jul 2020 03:40:27 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:123572 Archived-At: 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. But I can't figure out how to amalgamate the buffer changes properly. This is what I've got: (defmacro my/with-single-undo (curr-buf &rest body) "Within CURR-BUF, execute BODY as a single undo step." (declare (indent 1)) (let ((marker (cl-gensym "marker"))) `(let ((,marker (nconc (prepare-change-group ,curr-buf) (prepare-change-group (get-buffer-create "b.txt"))))) (unwind-protect (progn ,@body) (undo-amalgamate-change-group ,marker))))) (defun my/insert-some-stuff (&rest _args) (interactive) (my/with-single-undo (current-buffer) (insert "apple banana caterpillar\n") (with-current-buffer (get-buffer-create "b.txt") (insert "xylophone yak zebra")))) I test by making "a.txt" and "b.txt" files, opening both up, and then executing M-x my/insert-some-stuff from within a.txt. Right now, undo is only undoing changes within the buffer in which I execute it. I'd appreciate any help on this. Best, Brian