From: Eli Zaretskii <eliz@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: yantar92@posteo.net, 70077@debbugs.gnu.org, casouri@gmail.com,
qhong@alum.mit.edu, frederic.bour@lakaban.net,
joaotavora@gmail.com, mail@nicolasgoaziou.fr, acm@muc.de,
stephen_leake@stephe-leake.org, alan.zimm@gmail.com,
phillip.lord@russet.org.uk
Subject: bug#70077: An easier way to track buffer changes
Date: Sat, 30 Mar 2024 09:34:39 +0300 [thread overview]
Message-ID: <86cyrcdy80.fsf@gnu.org> (raw)
In-Reply-To: <jwvle60x4d6.fsf-monnier+emacs@gnu.org> (message from Stefan Monnier on Fri, 29 Mar 2024 14:53:41 -0400)
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: 70077@debbugs.gnu.org, mail@nicolasgoaziou.fr, yantar92@posteo.net,
> acm@muc.de, joaotavora@gmail.com, alan.zimm@gmail.com,
> frederic.bour@lakaban.net, phillip.lord@russet.org.uk,
> stephen_leake@stephe-leake.org, casouri@gmail.com, qhong@alum.mit.edu
> Date: Fri, 29 Mar 2024 14:53:41 -0400
>
> > I cannot imagine how applications would use these APIs. I'm probably
> > missing something, org the above documentation does. Can you show
> > some real-life examples?
>
> Haven't written real code for it yes, no.
> The best I can offer is the sample code in the file:
>
> (defvar my-foo--change-tracker nil)
> (define-minor-mode my-foo-mode
> "Fooing like there's no tomorrow."
> (if (null my-foo-mode)
> (when my-foo--change-tracker
> (track-changes-unregister my-foo--change-tracker)
> (setq my-foo--change-tracker nil))
> (unless my-foo--change-tracker
> (setq my-foo--change-tracker
> (track-changes-register
> (lambda ()
> (track-changes-fetch
> my-foo--change-tracker
> (lambda (beg end before)
> ..DO THE THING..))))))))
>
> Where "DO THE THING" is run similarly to what would happen in an
> `after-change-functions`, except:
>
> - BEFORE is a string holding the content of what was in BEG..END
> instead of being limited to its length.
> - It's run at most once per command, so there's no performance worries.
> - It's run "outside" of the modifications themselves,
> so `inhibit-modification-hooks` is nil and the code can wait, modify
> the buffer, or do any kind of crazy things.
Thanks.
I understand the last point, but that still doesn't explain enough for
me to see the light. (I've also looked at the two real-life uses you
posted, and it didn't help, probably because the important ideas
drowned in the sea of modifications to code I'm not familiar with well
enough to understand what's important and what isn't.) If the last
point, i.e. the problems caused by limitations on what can be safely
done from modification hooks, is basically the main advantage, then I
think I understand the rationale. Otherwise, the above looks like
doing all the job in after-change-functions, and it is not clear to me
how is that better, since if track-changes-fetch will fetch a series
of changes, deciding how to handle them could be much harder than
handling them one by one when each one happens. For example, the
BEGIN..END values no longer reflect the current buffer contents, and
each fetched change refers to a different content of the buffer (so
the same values of BEG..END don't necessarily mean the same places in
the buffer). I think the need for the
eglot--virtual-pos-to-lsp-position function in one of your examples is
the tip of that iceberg.
Also, all of your examples seem to have the signal function just call
track-changes-fetch and do almost nothing else, so I wonder why we
need a separate function for that, and more specifically what would be
a use case where the registered signal function does NOT call
track-changes-fetch, but does something else, and track-changes-fetch
is then called outside of the signal function.
Finally, the doc string of track-changes-register does not describe
the exact place in the buffer-change sequence where the signal
function will be called, which makes it harder to reason about it.
Will it be called where we now call signal_after_change or somewhere
else? And how do you guarantee that the signal function will not be
called again until track-changes-fetch is called?
next prev parent reply other threads:[~2024-03-30 6:34 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 16:15 bug#70077: An easier way to track buffer changes Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-29 18:12 ` Eli Zaretskii
2024-03-29 18:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 6:34 ` Eli Zaretskii [this message]
2024-03-30 14:58 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 16:45 ` Eli Zaretskii
2024-03-31 2:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-01 11:53 ` Ihor Radchenko
2024-04-01 14:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-01 17:49 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-02 14:22 ` Ihor Radchenko
2024-04-02 15:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-02 16:21 ` Ihor Radchenko
2024-04-02 17:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-03 12:34 ` Ihor Radchenko
2024-04-03 12:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-04 17:58 ` Ihor Radchenko
2024-03-30 3:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 5:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-29 22:20 ` phillip.lord
2024-03-29 22:59 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 6:46 ` Eli Zaretskii
2024-03-30 12:06 ` phillip.lord
2024-03-30 13:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 9:51 ` Ihor Radchenko
2024-03-30 12:49 ` Eli Zaretskii
2024-03-30 13:19 ` Ihor Radchenko
2024-03-30 13:31 ` Eli Zaretskii
2024-03-30 14:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-05 22:12 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-06 8:43 ` Eli Zaretskii
2024-04-08 15:24 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 15:53 ` Eli Zaretskii
2024-04-08 17:17 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 17:27 ` Andrea Corallo
2024-04-08 18:36 ` Eli Zaretskii
2024-04-08 20:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-09 4:10 ` Eli Zaretskii
2024-04-08 20:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-09 3:56 ` Eli Zaretskii
2024-04-09 23:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-13 13:44 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-06 17:37 ` Dmitry Gutov
2024-04-06 19:44 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-07 14:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-07 15:47 ` Dmitry Gutov
2024-04-07 14:07 ` Ihor Radchenko
2024-04-08 16:06 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-09 17:35 ` Ihor Radchenko
2024-04-10 2:02 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86cyrcdy80.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=70077@debbugs.gnu.org \
--cc=acm@muc.de \
--cc=alan.zimm@gmail.com \
--cc=casouri@gmail.com \
--cc=frederic.bour@lakaban.net \
--cc=joaotavora@gmail.com \
--cc=mail@nicolasgoaziou.fr \
--cc=monnier@iro.umontreal.ca \
--cc=phillip.lord@russet.org.uk \
--cc=qhong@alum.mit.edu \
--cc=stephen_leake@stephe-leake.org \
--cc=yantar92@posteo.net \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.