emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Disable tree-sitter font-locking for smaller ranges


From: Yuan Fu
Subject: Re: Disable tree-sitter font-locking for smaller ranges
Date: Mon, 17 Oct 2022 02:00:25 -0700


> On Oct 16, 2022, at 11:33 PM, Theodor Thornhill <theo@thornhill.no> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
>>>> 
>>>> The image you attached looks perfectly fine to me. Do you not want
>>>> to font-lock what’s inside a substitution? I’m not exactly sure what
>>>> result you want to archive.
>>>> 
>>> 
>>> All the parens, braces, equal, semicolons should be white, as they
>>> would in the source file outside of the template string. But the
>>> string outside of the ${...} should be string colored.
>>> 
>> Ah, I finally get it. How about:
>> 
>> (template_string) @font-lock-string-face
>> (template_substitution) @default ; color everything in substitution white
>> (template_substitution ["${" "}"] @font-lock-constant-face)
>> ;; rest font-lock
>> 
> 
> Yes! That's it! Thanks :)
> 
> See attached patch:

Actually, thinking more of it, it working relies on the exact order of which 
these rules are applied:
1. Outer template_string
2. Outer template_substitution
3. Inner template_string
4. Inner template_substitution

Relying on such un-guaranteed fact is a bit uncomfortable, so I just wrote a 
function that did what you suggested initially: to fontify parts of 
template_string that’s not a template_substitution. WDYT? (I just pushed the 
change.)

BTW, if you have time and energy, could you look into separating the queries 
into roughly three levels: minimum, moderate, and full fontification, and mark 
each with the new :feature flag? Or even better, separate them into different 
features (as suggested in the docstring of treesit-font-lock-feature-list).

Yuan






reply via email to

[Prev in Thread] Current Thread [Next in Thread]