GNU bug report logs - #65451
30.0.50; `after-change-functions' are not triggered in the same order the changes are made

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Tue, 22 Aug 2023 09:31:01 UTC

Severity: normal

Found in version 30.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 65451 <at> debbugs.gnu.org
Subject: bug#65451: 30.0.50; `after-change-functions' are not triggered in the same order the changes are made
Date: Tue, 22 Aug 2023 12:42:18 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

>> The order of after-change notifications thus do not correspond to the
>> order of buffer changes. Org mode is relying upon the correct change
>> order to update parser cache with buffer modifications.
>
> I think Org mode is relying on something it should not.

Then, I'd like to point back to the previous discussion where I asked to
expose to Elisp information about buffer changes available to
tree-sitter.
https://yhetil.org/emacs-devel/83tu8jq2vl.fsf <at> gnu.org/

If there is no guarantee that buffer modifications are not signaled in
order, on-the-fly updates of the parsed AST will become impossible for
Org, even if using markers (as you suggested in the linked thread).

In fact, I am not sure if tree-sitter will behave correctly if it is
signaled changes in incorrect order.

https://tree-sitter.github.io/tree-sitter/using-parsers#advanced-parsing
says

    In applications like text editors, you often need to re-parse a file
    after its source code has changed. Tree-sitter is designed to support
    this use case efficiently. There are two steps required. First, you must
    edit the syntax tree, which adjusts the ranges of its nodes so that they
    stay in sync with the code.
    
    typedef struct {
      uint32_t start_byte;
      uint32_t old_end_byte;
      uint32_t new_end_byte;
      TSPoint start_point;
      TSPoint old_end_point;
      TSPoint new_end_point;
    } TSInputEdit;
    
    void ts_tree_edit(TSTree *, const TSInputEdit *);

Note how the API is similar to `after-change-functions' - it expects
edited region boundaries before/after the edit.

If Emacs feeds the following to tree-sitter
⛔ Warning (emacs): After: 1278 1288 delta: 0
⛔ Warning (emacs): After: 1278 1288 delta: 7
, the first "edit" query will apply to wrong range in the cached AST.

-- 
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>




This bug report was last modified 1 year and 104 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.