bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18: Fine-grained revert-buffer


From: Eli Zaretskii
Subject: bug#18: Fine-grained revert-buffer
Date: Sat, 27 Apr 2019 10:34:23 +0300

> From: Mauro Aranda <maurooaranda@gmail.com>
> 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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]