Subject: Re: bug#64329: 29.0.92; treesit/fill-paragraph syntax highlighting problem

From: Eli Zaretskii <[email-masked]>
Date: Thu, 29 Jun 2023 08:10:05 +0300

> From: Yuan Fu <[email-masked]>
> Date: Wed, 28 Jun 2023 14:23:41 -0700
> Cc: [email-masked],
>  Eli Zaretskii <[email-masked]>
> 
> The culprit is the subst-char-in-region function used by the filling function. It has a branch:
> 
> if (xxx)
>   {
> 	replace_range (pos, pos + 1, string, ...);
>   }
> else
>   {
> 	for (i = 0; i < len; i++) *p++ = tostr[i];
>   }
> 
> I overlooked the else branch and thought subst-char-in-region always calls replace_range. replace_range notifies tree-sitter of the change it makes; but when subst-char-in-region manually replaces the text in the else branch, those edits are not notified to tree-sitter.
> 
> Please see the attached patch. Eli, is it more preferable to add a subroutine in insdel.c that does what "for (i = 0; i < len; i++) *p++ = tostr[I];” does, plus calling treesit_record_change, and make subst-char-in-region call that subroutine? (This way editfns.c don’t need to include treesit.h and call treesit_record_change itself.)

I'd prefer to install the patch you show on the emacs-29 branch, and
then clean it up with a subroutine in insdel.c on master.

We could also leave this on master without adding a subroutine:
casefiddle.c already does something similar, so it's not like
including treesit.h is known to cause trouble or something.

Thanks.