Subject: Re: bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made

From: Ihor Radchenko <[email-masked]>
Date: Thu, 24 Aug 2023 13:27:02 +0000

Eli Zaretskii <[email-masked]> writes:

>> Would it be acceptable to accumulate treesit_record_change transactions
>> into a queue, combine them later, and run the Elisp hook only when it is
>> safe (around the same place `after-change-functions' is called, but only
>> when actual edit is made to the buffer text)?
>> 
>> That way, we can have a hook that will run strictly less frequently
>> compared to `after-change-functions'.
>
> When exactly do you need this to run?  At the same time as
> after-change-functions doesn't sound like a good idea to me, but I
> think you don't need to run it there.  What about running just before
> redisplay kicks in?

Usually, we need to update AST when some other Elisp code needs Org
element API. And we update AST on idle timer to speed things up.

What if we use no hooks at all? Instead, the edit transactions are
accumulated in a list that can be examined and processed by Elisp code
as needed.

Elements of the list will be like
[:buffer-chars-modified-tick :region-beginning :region-end-before-edit :region-end-after-edit]

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>