From: Mauro Aranda <maurooaranda@gmail.com>
To: 18@debbugs.gnu.org
Subject: bug#18: Fine-grained revert-buffer
Date: Sat, 27 Apr 2019 12:10:45 -0300 [thread overview]
Message-ID: <CABczVwfE1dpqGXZ4ukGn2Z_NKthAV3oYaR_vccb3MWjgJDdMvQ@mail.gmail.com> (raw)
In-Reply-To: <83d0l7x5og.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 4416 bytes --]
Eli and Martin, thanks for your answers.
Eli Zaretskii <eliz@gnu.org> writes:
> 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.
I didn't know of replace-buffer-contents, so I took a look at it. Nice
that its documentation even mentions the problem when a marker is
inside a hunk, because of the delete + insert thing (just like Martin
mentions). IMO, it does most of the things required, but here is one
problem I notice with respect to the expected functionality of
revert-buffer-by-hunks (as I've understood it):
It only calls Fundo_boundary before starting the whole set of
modifications, and thus after replacing the contents (in my tests, the
whole buffer), a single C-/ brings all the changes back, much like
revert-buffer. And since it binds inhibit-modification-hooks to t, I
think I can't bind locally after-change-functions to an expression that
calls undo-boundary, to do the trick.
Perhaps an optional call to Fundo_boundary in the while loop could be
enough, but I'm not sure how much it will impact on the speed of
replace-buffer-contents. Or more, if it is justified to add that call.
Please, point out to me if I'm not seeing this right.
Other than that, it looks like a perfect candidate to use (at least to me)
to get the functionality wanted.
> 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?
I haven't timed it yet. I didn't know if it would be considered good
enough, to time it. For a week, I've been testing it manually with some
of the changes in the Emacs sources, and the experience has been
satisfactory. Are there, by any chance, such tests for
replace-buffer-contents? I could use them, for comparison purposes.
I will try in the following days to define some parameters (such as
buffer size), and time revert-buffer-by-hunks, to provide some numbers.
Provided it is fast enough, I think something like replacing by hunks a
region would be a good fallback to replace-buffer-contents. I sure hope
so.
>> 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.
I agree. If using diff.el, it makes total sense to use those
variables. Of course, that means the patch-buffer function should
be modified to work on the different diff output formats (I think --context
and --unified should be enough). For the record, I don't propose to use
diff-apply-hunk and other diff-mode.el functions, because when I used
that, I ended up with markers at (point-min), I don't know why. But if
it is desired to reuse those functions instead of repeating code, I
think I will need time (and help, perhaps), to understand why that
happened.
martin rudalics <rudalics@gmx.at> writes:
> What we probably need is an extra step to scan the buffer for markers
> and save their textual context before reverting and a step to restore
> them according to their textual context after reverting. But if your
When I bumped into the problem of the marker being sent to the
beginning of the hunk, I started looking for something to get the
markers of the buffer, but didn't found anything at the Lisp level.
> method allows to easily determine which hunks remain unchanged, we
> could avoid such textual search for markers in unchanged hunks and,
> depending on the approach used for replacing text, simply restore
> these markers from their offsets from the beginning of the hunk they
> belong to.
Yes, I believe that by getting the diff output and with the line-offset
handling in the patch-buffer function, it would be easy to determine the
unchanged regions.
Thanks again to both of you.
Best regards,
Mauro.
[-- Attachment #2: Type: text/html, Size: 5232 bytes --]
next prev parent reply other threads:[~2019-04-27 15:10 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <jwvpruii0xr.fsf@iro.umontreal.ca>
2013-12-17 3:16 ` bug#18: Fine-grained revert-buffer Dmitry Gutov
2013-12-17 13:32 ` Stefan Monnier
2018-04-12 6:21 ` Toon Claes
2018-04-12 12:18 ` Stefan Monnier
2018-04-14 7:00 ` Toon Claes
2018-04-14 14:14 ` Stefan Monnier
2019-04-26 22:42 ` Mauro Aranda
2019-04-27 7:34 ` Eli Zaretskii
2019-04-27 15:10 ` Mauro Aranda [this message]
2019-04-27 16:30 ` Eli Zaretskii
2019-04-27 17:46 ` Mauro Aranda
2019-04-29 12:49 ` martin rudalics
2019-05-02 15:54 ` Basil L. Contovounesios
2019-05-02 16:20 ` Glenn Morris
2019-05-02 16:23 ` Basil L. Contovounesios
2019-05-02 21:27 ` Richard Stallman
2019-05-03 14:05 ` Basil L. Contovounesios
2019-05-05 22:41 ` Richard Stallman
2019-04-27 8:31 ` martin rudalics
2019-04-28 2:47 ` Richard Stallman
2019-04-29 23:32 ` Mauro Aranda
2019-04-30 0:17 ` Mauro Aranda
2019-05-15 23:10 ` Mauro Aranda
2020-09-19 23:08 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABczVwfE1dpqGXZ4ukGn2Z_NKthAV3oYaR_vccb3MWjgJDdMvQ@mail.gmail.com \
--to=maurooaranda@gmail.com \
--cc=18@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).