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: Undo complex command Date: Tue, 23 Mar 2021 09:55:42 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="428"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: "emacs-devel@gnu.org" To: scame Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 23 15:07:35 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 1lOhh0-000AXl-0J for ged-emacs-devel@m.gmane-mx.org; Tue, 23 Mar 2021 15:07:34 +0100 Original-Received: from localhost ([::1]:48796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOhgz-0001D3-2e for ged-emacs-devel@m.gmane-mx.org; Tue, 23 Mar 2021 10:07:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOhVj-0003nT-6h for emacs-devel@gnu.org; Tue, 23 Mar 2021 09:55:55 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOhVg-00065N-VW for emacs-devel@gnu.org; Tue, 23 Mar 2021 09:55:54 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 09CBF440436; Tue, 23 Mar 2021 09:55:51 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A6201440345; Tue, 23 Mar 2021 09:55:49 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1616507749; bh=pwxQZFQyU5GM9YRGHQjN+JAjzololMKFOFXrFeJGS+4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=KdnwthW6c74VjfXvuJ9D+nf7LsVmzruaKnJD3LYIenQjEAAAnzpYZYJofxi7AOHH9 qW6Rj6iJZAf8dvMwf+iusKtsm5lbwcwOcHXGQN0R2MT9Gwv/nVlTMa6O/XhXn2tLm+ YL0G6fbopHifK02/gK5NcQMVHM9kAF6HHPLGbgT2Jd2TCGYwgj7uu9q1LO6SQr/Jna FbLiouwzzzaZOrlqNBw+evXGYFi0OLPscaIN4MEwzHJTbIpx1juQ41kmOoPmf5erB1 almbFING9v4FGLy3ecsw2rwUZywqOTRophMvgs6tkxPPdzpQNZvfUQmqGuLpok1SYP ir4f9fLGOvhcQ== Original-Received: from alfajor (unknown [216.154.43.249]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1820D12047D; Tue, 23 Mar 2021 09:55:49 -0400 (EDT) In-Reply-To: (scame's message of "Tue, 23 Mar 2021 07:05:50 +0000") 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.23 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:266874 Archived-At: > I use repeat complex command often (BTW, why doesn't the built in > version have completion? It's much better that way.) and It's always better with completion, indeed. The reason why there is currently no completion for it is simple: you just forgot to include the patch for it in your message. But don't worry, it happens to the best of us. Just include it in your next message and all will be forgiven. > Then if I want to revert a particular change, I could say > M-x undo-complex-change, select a command from the undo > list and then I'd get its diff in a buffer and then I > could revert any hunk or the whole diff altogether. (Like > with regular diffs the diff can be applied as long as the > text did not change significantly since then.) > > What do you think? Could it be a useful feature? Sounds like a great idea, and it could be used with all commands (tho you'd probably want to weed out the trivial `self-insert-command`s and `delete-char`s). I don't think you need to store the diff, because you can (re)create the diff from the current undo info. Here's how I imagine you could implement it: 1- copy the current `buffer-string` along with the `buffer-undo-list` to a new buffer. 2- save that buffer's content to a temp file. 3- call undo in that temp buffer 4- run a diff between the temp file and the current content of the temp buffer 5- display it to the user 6- if the user hits M-p (or something like that) you go back to 2. 7- else you try to apply that diff to the main buffer's contents (e.g. using diff-apply-hunk). In step 1 you'll probably want to filter out all the marker updates from the `buffer-undo-list`. And at step 6 you'll probably want to allow M-n. Results would be better if the undo log included some information you could show to the user such as the command name, but currently that's not available. Stefan