From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#18: Fine-grained revert-buffer Date: Sat, 27 Apr 2019 10:34:23 +0300 Message-ID: <83d0l7x5og.fsf@gnu.org> References: Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="128890"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 18@debbugs.gnu.org To: Mauro Aranda Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 27 09:50:39 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hKI6Y-000XPk-P1 for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Apr 2019 09:50:38 +0200 Original-Received: from localhost ([127.0.0.1]:56894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKI6X-0006U5-Nw for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Apr 2019 03:50:37 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKI6O-0006Dk-VK for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 03:50:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hKHrS-00035Q-JZ for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 03:35:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hKHrS-000352-Fa for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 03:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hKHrS-0006XO-2x for bug-gnu-emacs@gnu.org; Sat, 27 Apr 2019 03:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Apr 2019 07:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18 X-GNU-PR-Package: emacs Original-Received: via spool by 18-submit@debbugs.gnu.org id=B18.155635048625100 (code B ref 18); Sat, 27 Apr 2019 07:35:02 +0000 Original-Received: (at 18) by debbugs.gnu.org; 27 Apr 2019 07:34:46 +0000 Original-Received: from localhost ([127.0.0.1]:34192 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hKHrC-0006Wm-8i for submit@debbugs.gnu.org; Sat, 27 Apr 2019 03:34:46 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51041) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hKHrA-0006WZ-I5 for 18@debbugs.gnu.org; Sat, 27 Apr 2019 03:34:45 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:42429) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hKHr5-0002pE-9r; Sat, 27 Apr 2019 03:34:39 -0400 Original-Received: from [176.228.60.248] (port=1357 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hKHr4-0000XC-Hh; Sat, 27 Apr 2019 03:34:38 -0400 In-reply-to: (message from Mauro Aranda on Fri, 26 Apr 2019 19:42:02 -0300) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158325 Archived-At: > From: Mauro Aranda > Date: Fri, 26 Apr 2019 19:42:02 -0300 > > For a while now, I've been wanting to contribute to Emacs by doing > something more than reporting bugs and try to provide trivial fixes for > the bugs I found. So I looked into emacs-devel, to read about > recomendations for beginning to contribute. Based on some of the mails > I found [1], it looks like working on some wishlist items or minor bugs > would be good. So I said to myself: OK, let's see what is the oldest > one still open. And here I am. Thanks! > The wish is to have a command that would act like 'revert-buffer' > (e.g., modifying the buffer rightaway), but that tries to do a better job > preserving markers. Also, it is desirable that undo info is preserved. > It is known that 'revert-buffer' preserves undo info nowadays, but what I > understand is that it would be good to keep undo info of parts of the > total reverted change, so the undo of the reverted action can be made by > steps, and not as a single undo operation. > > I think that the alternatives proposed after the report [2] do not > fulfill the wish because they do not modify the buffer immediately. I'm > not sure how they act in regards to preserving markers and the undo > info, though. > > AFAIK, the functionality wanted is still not present, so I'd guess it's > still relevant to work in this matter. Sounds correct to me. > So for a week or so now, I've been working in a command that does what I > think it is wanted. The command is called 'revert-buffer-by-hunks' > (I've added 'rbbh' as a prefix for sending the file for you to > see/test), because it calls 'diff' and then with the output patches the > buffer. > > At first, I wrote a command that used diff-mode under the hood, but I've > been having troubles with preserving markers. So I took a step back, > and wrote a new function that patches the buffer with the contents of > the file visited on disk. With that done, I think it is time for me to > show what I've written so far, in order to: > > 1) Know if the functionality is present (I don't think so, but I believe > this is the first thing to know in order to advance). > 2) There's still interest in having this command. > 3) Know if working on this subject would be appreciated, or should I > move on to other things. > 4) Receieve feedback, suggestions, fixes on things I'm sure I'm missing. Please take a look at replace-buffer-contents, which is new with Emacs 26. It might allow you to implement this functionality in a much simpler way, as it already contains an internal implementation of a Diff-like comparison algorithm, and doesn't require the Diff program to be installed. One caveat: replace-buffer-contents can be very slow when the buffer is large and reverting it requires a large number of small changes. It will fall back to a simpler algorithm for large numbers of changes, and could give up entirely if making the changes takes too much time, see its doc string. Perhaps in those cases we should fall back to a different code, like the one you wrote. Did you time your code? How long does it take to revert buffers of different sizes with different amounts of changes? > a) What variables would you think should be customizable? The name of the Diff command should be customizable. Or maybe just use diff-command already provided by diff.el. Same with Diff switches.