emacs-devel
[Top][All Lists]
Advanced

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

Re: Status update of tree-sitter features


From: Yuan Fu
Subject: Re: Status update of tree-sitter features
Date: Fri, 30 Dec 2022 03:16:59 -0800


> On Dec 29, 2022, at 8:38 AM, Dmitry Gutov <dgutov@yandex.ru> wrote:
> 
> On 29/12/2022 11:21, Yuan Fu wrote:
> 
>>>>> If it's only about calls, maybe call this category funcall?
>>>> Function, property and variable are for every occurrence of them (the 
>>>> touted “consistent highlighting”). So there will be a bit of overlap 
>>>> between function, variable, and definition.
>>> 
>>> By "overlap", do you mean that font-lock rules should also have entries for 
>>> variable/function definitions with category 'variable'/'function'?
>>> 
>>> In case somebody removes 'definition' from their list of enabled features 
>>> but keeps 'variable' and 'function' there?
>> Basically, if you enable definition alone, you get highlight for 
>> function/variable/class definition. If you enable function/variable alone, 
>> you get highlight for all occurrence of function/variable identifiers, which 
>> would includ what definition highlights. Definition can be seen as the union 
>> of subsets of function & variable feature.
> 
> Yes, but is that classification useful enough to justify the duplication in 
> the font-lock rules' definitions?
> 
> FWIW, I "broke" python-ts-mode in 8503b370be1, according to this definition. 
> Sorry?
> 
> But what do we get by this particular classification?
> 
> The user will be able to disable 'definitions' and still have all function 
> definitions highlighted? But not, say, variable definitions?
> 
> That doesn't strike me as particularly more useful than e.g. disabling 
> 'definitions' and having all function references highlighted (but not 
> definitions). Which we would make possible by limiting 'function' to 
> non-definitions.

Right now you can choose to highlight:
1. Only definition identifiers, be it function, variable, class, etc
2. All function identifiers
3. All variable identifiers

There could be better features, but the existing ones still have their merits. 
If you want a feature that highlights only funcalls, maybe we can add them, if 
there are enough time & interest.

>>>>>> variable                every variable identifier
>>>>> 
>>>>> 'variable', so far, seems like the least useful. When enabled, it lights 
>>>>> up every bit of text that remained from other matchers -- because 
>>>>> identifier are everywhere.
>>>> Yes, but apparently people want it ;-)
>>> 
>>> Well, if they really do.
>>> 
>>> I figured that people who added this maybe haven't tested this thoroughly. 
>>> And that maybe they expected the effect of that "local variables 
>>> highlights" feature that some editors showcase already.
>> The purpose of the standard list is to regulate features, so if a major mode 
>> wants to support a feature in the list, it uses the definition and name from 
>> that list (rather than creating a feature with same definition but different 
>> name, or same name but different definition). If a major mode really want 
>> variable feature, they can add it, if not, they don’t have to.
> 
> Okay, I also have a different, somewhat related question.
> 
> Certain languages have a special syntax for "variables".
> 
> Ruby has @instance_variable and $global_variable -- the @ and $ are used both 
> during assignment and for later reference.
> 
> Perl has $var and @array_var.
> 
> PHP has $local_var.
> 
> Up until now we've highlighted those with font-lock-variable-name-face. 
> Except for @array_var in Perl, which has separate derived face. Either way, 
> we did highlight them.
> 
> What category should we use for them in ts-based modes? If it's 'variable', 
> then won't be highlighted by default.
> 
> If 'variable' matchers in other existing ts modes didn't include all 
> identifiers everywhere, we could put 'variable' into level 3.
> 
> Or we could add a separate category for all those, I guess.

If a major mode thinks highlighting all variables is the best default behavior, 
it can support the variable feature and put it at level 3. The standard list is 
just a guideline.

> 
>>>>> For Emacs 29, though, I would discourage the use of 'variable’.
>>>> It’s on level 4, meaning not enabled by default, so I think it’s fine.
>>> 
>>> Fair enough. If someone wants function/property but not variable, they 
>>> could fine-tune the list.
>> Right. All the features in level 4 are pretty over-the-top IMO, so simply 
>> bumping to level 4 and enable everything is probably not the way to go.
> 
> I actually considered having level 4 enabled. The punctuation faces look like 
> 'default' without customization anyway, so it doesn't turn into angry fruit 
> salad right away. One can stop at customizing the "brackets" face, for 
> example.
> 
> Though I'd probably also want 'function' and 'property' highlights to use 
> other faces, distinct from 'function-name' and 'variable-name’.

You could use level 4 and remove unwanted features, yes. I guess that works too 
:-)

Yuan




reply via email to

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