From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.help Subject: Re: How to amalgamate changes across multiple buffers into a single undo entry Date: Sun, 26 Jul 2020 18:30:19 +0800 Message-ID: <87365epo04.fsf@localhost> References: <906746352.441036.1595477678356@ichabod.co-bxl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10992"; mail-complaints-to="usenet@ciao.gmane.io" To: Brian Leung , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 26 12:31:22 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 1jzdw9-0002mZ-Jv for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 26 Jul 2020 12:31:21 +0200 Original-Received: from localhost ([::1]:43776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jzdw8-0001JN-Je for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 26 Jul 2020 06:31:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jzdvo-0001JF-Pm for help-gnu-emacs@gnu.org; Sun, 26 Jul 2020 06:31:00 -0400 Original-Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]:35711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jzdvn-0001Mf-5r for help-gnu-emacs@gnu.org; Sun, 26 Jul 2020 06:31:00 -0400 Original-Received: by mail-qk1-x72b.google.com with SMTP id 11so12767333qkn.2 for ; Sun, 26 Jul 2020 03:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=JpSF/0poTiAu6HVUSEaSGkutNNGLNCWNq4LMGGHi0k0=; b=ks92yoTS/bqxuXS1Aq/xBw0HZQSl8jO+O3Dtyfhns1dxyGeZSzuEVSeTCCMAwGKDs4 5XWY7R7IJV79l++ACWBFu1+2gStc8OKYr+sL1Ir6g2H40uveQSLYdW4ojXsxRBKdJNIx uNU6/gbu6++D26GiXJuuVW4xqgHOqehq1RHuYfOL/sAjX35QAasg/L0WSmRzXh3LoJ4K 9kdbStvl7Ztj6Jtzo/B12srtuDs7jsdbCDtygbamoDZDCm2ShwYj2pEwSmNk+2UrM8Uh LFXivLVCUOYVkSbNbGGEGNYTmIPVSyjRX9gnOJZukkFcAiSUbYZaE6sbFKv+XgiJcwmw Uvig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=JpSF/0poTiAu6HVUSEaSGkutNNGLNCWNq4LMGGHi0k0=; b=CIwwL/fRJCeK4PwdyzMi3lYjbv1aqkv0VL18WnLgsVNyuQpJM8Yv3u2b1+PHup30fj L2XHeMyqO0WhAMDZi8SgQ7wqwHveh3z5KKeXe5BWVcf0YY6KfvXBgrWlebAv3fIxsLmC LFAx0xetXaGe5shK5s1KU2IryIFymIZkvLhRgkkIm1afZivI8a5qtJ1T+dTSj0zs3hTU Kn1ej4RkK+eDEf56hTT3LM7C9HpzoiMRa4clb4/Bc3RuH+PvWlRIQNPAWxFaxy8MZOQm B28BVSZZXfDstey1cKl/As9PPmjyi5n806EMY6lqWFbPtzwf52cwvxUTaz5nddX4axrf JWjw== X-Gm-Message-State: AOAM532tUxX5mPSHvsFWR65x2TIa8YV0+ErHtYtOahjcDr7gwXkFr/q5 CoQFsjFdHdeIG6l4uW/pOGQ= X-Google-Smtp-Source: ABdhPJyqdXs1oZlzOogFLVE1+RqtJMcpJF6lOlqiyDv2fDaQO6Md68eDuYQ7c/IEQ08Xucv651qhNQ== X-Received: by 2002:a37:b141:: with SMTP id a62mr16960221qkf.201.1595759458122; Sun, 26 Jul 2020 03:30:58 -0700 (PDT) Original-Received: from localhost ([208.167.241.222]) by smtp.gmail.com with ESMTPSA id d198sm13300945qke.129.2020.07.26.03.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2020 03:30:57 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::72b; envelope-from=yantar92@gmail.com; helo=mail-qk1-x72b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:123589 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: You might try to look into org-agenda-undo. It implements something similar I think. Best, Ihor Brian Leung writes: > 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 > -- Ihor Radchenko, PhD, Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg