GNU bug report logs - #63840
29.0.91; c-ts-mode fails to fontify common C extension

Previous Next

Package: emacs;

Reported by: Po Lu <luangruo <at> yahoo.com>

Date: Fri, 2 Jun 2023 12:12:01 UTC

Severity: normal

Tags: notabug

Found in version 29.0.91

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #38 received at 63840 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Po Lu <luangruo <at> yahoo.com>, 63840 <at> debbugs.gnu.org,
 Theodor Thornhill <theo <at> thornhill.no>
Subject: Re: bug#63840: 29.0.91; c-ts-mode fails to fontify common C extension
Date: Tue, 27 Jun 2023 18:46:24 -0700

> On Jun 27, 2023, at 4:05 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Mon, 26 Jun 2023 22:54:16 -0700
>> Cc: Theodor Thornhill <theo <at> thornhill.no>,
>> Po Lu <luangruo <at> yahoo.com>,
>> 63840 <at> debbugs.gnu.org
>> 
>> 
>> 
>>> On Jun 19, 2023, at 9:23 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
>>> 
>>>> From: Yuan Fu <casouri <at> gmail.com>
>>>> Date: Sun, 18 Jun 2023 23:43:51 -0700
>>>> Cc: Theodor Thornhill <theo <at> thornhill.no>,
>>>> Po Lu <luangruo <at> yahoo.com>,
>>>> 63840 <at> debbugs.gnu.org
>>>> 
>>>>> On Jun 15, 2023, at 11:31 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
>>>>> 
>>>>>> From: Yuan Fu <casouri <at> gmail.com>
>>>>>> Date: Thu, 15 Jun 2023 22:05:33 -0700
>>>>>> Cc: Theodor Thornhill <theo <at> thornhill.no>,
>>>>>> Po Lu <luangruo <at> yahoo.com>,
>>>>>> 63840 <at> debbugs.gnu.org
>>>>>> 
>>>>>>> Ping!  Any progress with this?
>>>>>> 
>>>>>> The best option is to ask tree-sitter-c to recognize $. I see a PR for it but the author closed it shortly after posting, not sure what was going on[1].
>>>>> 
>>>>> Any hope of re-opening it, or at least asking why it was closed
>>>>> without fixing?
>>>> 
>>>> I asked on GitHub.
>>>> 
>>>>> 
>>>>>> Fixing it ourselves involves checking every identifier during fontification. Is that something we want to do?
>>>>> 
>>>>> How would that work?  Can you describe how could this be implemented?
>>>>> It is hard to decide whether it's something we want to do without
>>>>> knowing the implications.
>>>> 
>>>> I was going to write a demo implementation, but that actually would change quite some lines. So let me just describe it for now. In c-ts-mode--font-lock-settings, I would replace all the different types of faces used for all the identifiers to a function. (If you search for identifier in c-ts-mode--font-lock-settings, there are quite a few of them.) This function would obviously receive the beg and end of the identifier tree-sitter detects, and it would check if there are $ right before or after the given range, if there is, it would extend the range fontified.
>>>> 
>>>> For example, for a code like abc$de, tree-sitter might consider abc as an identifier, and $ de to be error. The function I mentioned would look at abc’s beg and end, and see that c is immediately followed by a $, so it would extend the fontification range to include abc$de.
>>> 
>>> Thanks.  This sounds like a lot of hair, so let's first see how the
>>> developers of the tree-sitter-c grammar respond.
>> 
>> Cool. (Not surprisingly) I didn’t get any reply on GitHub as for now. It would be nice if tree-sitter-c (and other grammars) can have a separate maintainer other than tree-sitter’s author. He seems to be heavily overloaded right now (tree-sitter, a dozen grammars, Zed editor).
> 
> Would it be possible for you or someone else of the interested Emacs
> users to submit a patch for the grammar library to support $, either
> as an option or as an extension?  IOW, is it hard to modify the
> TS grammar definitions for such relatively simple and straightforward
> extensions?

There is a PR for it on GitHub (under which I left a comment). Judging from the PR, it’s simple to add support for $.

Yuan



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

Previous Next


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