emacs-devel
[Top][All Lists]
Advanced

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

Re: Treesitter query question, matching only substring of a node


From: Yuan Fu
Subject: Re: Treesitter query question, matching only substring of a node
Date: Wed, 7 Dec 2022 16:52:57 -0800


> On Dec 6, 2022, at 7:13 AM, Danny Freeman <danny@dfreeman.email> wrote:
> 
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>>> On Dec 5, 2022, at 7:25 AM, Danny Freeman <danny@dfreeman.email> wrote:
>>> 
>>> 
>>> Yuan Fu <casouri@gmail.com> writes:
>>> 
>>>> I suggest capturing the whole node and using a function to fontify the 
>>>> symbol. With a function you
>>>> can do anything you want, including applying different faces to 
>>>> substrings. To do that, simply
>>>> define a function and use the function name as the capture name.
>>>> 
>>>> You can have a look at c-ts-mode--fontify-variable for a simple example.
>>> 
>>> This is exactly what I was looking for. I can't believe I didn't think
>>> of this when I was reading the documentation.
>>> 
>>> Thank you for your help!
>> 
>> Let me know if you have ideas on how could the documentation be improved to 
>> make it clearer. I have the curse of knowledge on me and everything seems so 
>> easy and clear ;-) 
>> 
>> Yuan
> 
> So far I am only working on font locking, and have NO experience with
> font locking in Emacs or with tree-sitter. With that in mind, using the
> starter-guide file, the html-manual, an existing grammar, and examples
> from python mode, I was able to get a working prototype in clojure-mode
> in 1 day. I think that speaks to the quality of the documentation!

Great!

> 
> The treesit-explore-mode is a really great tool for implementing the
> syntax highlighting as well. It is a real treat to work with.
> 
> Here is how I ended up using a function to fontify the symbols the way I
> needed to, in case you are curious:
> 
> https://github.com/dannyfreeman/clojure-mode/blob/513403c5e97330b65d024e2e904c165021540480/clojure-ts-mode.el#L162-L177
> 
> Right now that entire file is a rough proof of concept. There is a lot
> more work that needs to be done before it's ready for the general
> public.

It looks great!

Yuan


reply via email to

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