From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Danny Freeman Newsgroups: gmane.emacs.devel Subject: Re: Treesitter query question, matching only substring of a node Date: Tue, 06 Dec 2022 10:13:45 -0500 Message-ID: <87iliotuj6.fsf@dfreeman.email> References: <87sfhvdn6k.fsf@dfreeman.email> <87o7sheure.fsf@dfreeman.email> <097583CE-DB01-4BCD-9A87-5D30E92A4F66@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20681"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 06 16:36:00 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p2ZzC-00053C-Pv for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Dec 2022 16:35:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2Zyd-0002as-Gw; Tue, 06 Dec 2022 10:35:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2Zya-0002ZI-7v for emacs-devel@gnu.org; Tue, 06 Dec 2022 10:35:20 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2ZyX-0002Xq-NV for emacs-devel@gnu.org; Tue, 06 Dec 2022 10:35:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1670340913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WbqSfkIbsaHk/uAa9dl+wIWG+EioRsyjDsj1opuKPQ8=; b=CkR+WilrTdNIYY+hZInfeVXFidNxu/Ib1R/r9mSyckvPUGFeDxvcZqhNIePjx+sml9ceLp Fg1PC/7uKXxqgJ4FzCJeq+v6eUn8g2LB/5ouqUzNsHR5bwwGwhHxjIFvFgbSbqGVc8cBm3 o42e/40Bo3aG6/L7SzhyGTznr58tYd4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <097583CE-DB01-4BCD-9A87-5D30E92A4F66@gmail.com> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=188.165.223.204; envelope-from=danny@dfreeman.email; helo=out2.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300971 Archived-At: Yuan Fu writes: >> On Dec 5, 2022, at 7:25 AM, Danny Freeman wrote: >> >> >> Yuan Fu 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! 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. -- Danny Freeman