From 4f4515c8d044c43d46f980a99994857d8e418ed4 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Fri, 14 Mar 2025 22:56:18 -0700 Subject: [PATCH] Update tree-sitter subroutine in Fsubst_char_in_region Some explanation: Fsubst_char_in_region used to have a branch, one branch path calls replace_range, one branch path modifies the buffer directly. replace_range already calls treesit_record_change within it, so we needed to make sure we only call treesit_record_change in the other branch path. After I added the call to treesit_record_change, some changes are made to Fsubst_char_in_region, and the branch was removed. So no wonder Stefan had the confusion and wrote the FIXME note. Now that the branch is gone, we can indeed call treesit_record_change in the end like signal_after_change. * src/editfns.c (Fsubst_char_in_region): Move to end. (cherry picked from commit 3c47139b8f602286a8c5c5ca72431b933b4f2a23) --- src/editfns.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/editfns.c b/src/editfns.c index c4f23ccbe5b..e6d8e278c12 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2396,10 +2396,6 @@ Both characters must have the same length of multi-byte form. */) record_change (pos, 1); for (i = 0; i < len; i++) *p++ = tostr[i]; -#ifdef HAVE_TREE_SITTER - /* FIXME: Why not do it when we `signal_after_change`? */ - treesit_record_change (pos_byte, pos_byte + len, pos_byte + len); -#endif last_changed = pos + 1; } pos_byte = pos_byte_next; @@ -2408,6 +2404,9 @@ Both characters must have the same length of multi-byte form. */) if (changed > 0) { +#ifdef HAVE_TREE_SITTER + treesit_record_change (changed, last_changed, last_changed); +#endif signal_after_change (changed, last_changed - changed, last_changed - changed); update_compositions (changed, last_changed, CHECK_ALL); -- 2.39.5