all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: casouri@gmail.com, 65451@debbugs.gnu.org
Subject: bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made
Date: Wed, 23 Aug 2023 20:58:14 +0300	[thread overview]
Message-ID: <83y1i1r689.fsf@gnu.org> (raw)
In-Reply-To: <874jkq87jl.fsf@localhost> (message from Ihor Radchenko on Wed, 23 Aug 2023 08:52:30 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: casouri@gmail.com, 65451@debbugs.gnu.org
> Date: Wed, 23 Aug 2023 08:52:30 +0000
> 
> To update the old AST we need to know which regions in the old AST (and
> old buffer text) were edited and their change in length. Then, we (1)
> remove elements in AST that are structurally affected by the edit;
> (2) shift elements after the edit that are not structurally affected but
> whose boundaries must be adjusted to accommodate for the buffer length
> being changed; (3) re-parse buffer text (after the edit) and fill the
> gap in the AST.
> 
> For step (1), it is critical to have information about changed regions
> in the same order the edits happen. And, in theory, we might utilize
> before-change-functions to obtain this information (assuming that
> before-change-functions are always called in the same order the edits
> happen). But, unfortunately, before-change-functions are too noisy for
> this purpose because, for example, simply altering text properties also
> triggers before-change-functions, while no actual change in buffer text
> occurs in such scenario and re-parsing AST is unnecessary. So, we
> instead have to use after-change-functions and work out the original
> changed region boundaties using
> beg_changed end_changed pre-change_lentgh ->
> beg_before_change = beg_changed;
> end_before_change = end_changed - pre-change_length
> This calculation of the original changed region becomes incorrect when
> the order of after-change-functions is not the same as the editing order
> - this bug report.

If these measures still don't help you enough, perhaps the conclusion
is that it isn't feasible to implement text parsers in Lisp, at least
as long as you want all those micro-optimizations of knowing exactly
which parts of the buffer text were modified (as opposed to only know
how many characters at the beginning and at the end of the buffer
remain unchanged, and reparse the rest).  Maybe it must be done in C,
if we want Emacs to remain a relatively safe environment.

> Indeed. As I tried to explain, the problem for me is not the granularity
> of changes, but their ordering.

I still don't understand why the ordering matters, but I do know that
you cannot rely on it, and I hope I explained why.





  reply	other threads:[~2023-08-23 17:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22  9:30 bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made Ihor Radchenko
2023-08-22 12:22 ` Eli Zaretskii
2023-08-22 12:42   ` Ihor Radchenko
2023-08-22 12:58     ` Eli Zaretskii
2023-08-22 13:41       ` Ihor Radchenko
2023-08-22 16:02         ` Eli Zaretskii
2023-08-23  8:52           ` Ihor Radchenko
2023-08-23 17:58             ` Eli Zaretskii [this message]
2023-08-24  7:46               ` Ihor Radchenko
2023-08-24  8:08                 ` Eli Zaretskii
2023-08-24 11:24                   ` Ihor Radchenko
2023-08-24 12:08                     ` Eli Zaretskii
2023-08-24 13:27                       ` Ihor Radchenko
2023-08-24 14:53                         ` Eli Zaretskii
2023-08-25  6:37                           ` Eli Zaretskii
2023-08-25  9:09                             ` Ihor Radchenko
2023-08-26  7:10                               ` Eli Zaretskii
2023-08-27  8:13                                 ` Ihor Radchenko
2023-08-27  8:29                                   ` Eli Zaretskii
2023-08-29  7:39                                     ` Ihor Radchenko
2023-08-25  8:09                           ` Ihor Radchenko
2023-08-25 10:25                             ` Eli Zaretskii
2023-08-25 10:49                               ` Ihor Radchenko
2024-03-30 13:51   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 14:11     ` Eli Zaretskii
2024-03-30 15:38       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 16:47         ` Eli Zaretskii
2024-03-31  3:04           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-31  3:02     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-31  6:06       ` Eli Zaretskii
2024-03-31 13:57         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-07 18:19       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 19:10         ` Ihor Radchenko
2024-04-07 18:19       ` 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=83y1i1r689.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=65451@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --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.