diff options
author | Yuan Fu <casouri@gmail.com> | 2023-02-02 17:22:22 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-02-02 18:31:19 -0800 |
commit | 8a6bdf88b4b665916cf74dee3a30e9136a9b6df8 (patch) | |
tree | 8deeefbb73149fdf3e5efd4a80321be98f62127e /src/insdel.c | |
parent | a2b77c79dcca64b5e0ae58862206e7cc29640944 (diff) | |
download | emacs-8a6bdf88b4b665916cf74dee3a30e9136a9b6df8.tar.gz emacs-8a6bdf88b4b665916cf74dee3a30e9136a9b6df8.tar.bz2 emacs-8a6bdf88b4b665916cf74dee3a30e9136a9b6df8.zip |
Call treesit_record_change in insert_from_gap_1
Before this change, insert_from_gap calls treesit_record_change but
insert_from_gap_1 doesn't. However, insert_from_gap_1 is a public
function and is called in many other places outside of insdel.c. This
could lead to tree-sitter's parse tree becoming out-of-sync with the
buffer content.
This change might fix bug#60650.
* src/insdel.c (insert_from_gap_1): Call treesit_record_change.
(insert_from_gap): Remove call to treesit_record_change.
* admin/notes/tree-sitter/treesit_record_change: New file.
Diffstat (limited to 'src/insdel.c')
-rw-r--r-- | src/insdel.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/insdel.c b/src/insdel.c index 0e1e98664b3..e459d0cfa17 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1101,6 +1101,10 @@ insert_from_gap_1 (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) eassert (NILP (BVAR (current_buffer, enable_multibyte_characters)) ? nchars == nbytes : nchars <= nbytes); +#ifdef HAVE_TREE_SITTER + ptrdiff_t ins_bytepos = GPT_BYTE; +#endif + GAP_SIZE -= nbytes; if (! text_at_gap_tail) { @@ -1115,6 +1119,12 @@ insert_from_gap_1 (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) /* Put an anchor to ensure multi-byte form ends at gap. */ if (GAP_SIZE > 0) *(GPT_ADDR) = 0; eassert (GPT <= GPT_BYTE); + +#ifdef HAVE_TREE_SITTER + eassert (nbytes >= 0); + eassert (ins_bytepos >= 0); + treesit_record_change (ins_bytepos, ins_bytepos, ins_bytepos + nbytes); +#endif } /* Insert a sequence of NCHARS chars which occupy NBYTES bytes @@ -1150,12 +1160,6 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) current_buffer, 0); } -#ifdef HAVE_TREE_SITTER - eassert (nbytes >= 0); - eassert (ins_bytepos >= 0); - treesit_record_change (ins_bytepos, ins_bytepos, ins_bytepos + nbytes); -#endif - if (ins_charpos < PT) adjust_point (nchars, nbytes); @@ -1191,6 +1195,9 @@ insert_from_buffer (struct buffer *buf, #endif } +/* NOTE: If we ever make insert_from_buffer_1 public, make sure to + move the call to treesit_record_change into it. */ + static void insert_from_buffer_1 (struct buffer *buf, ptrdiff_t from, ptrdiff_t nchars, bool inherit) |