From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Treesitter query question, matching only substring of a node Date: Wed, 7 Dec 2022 16:52:57 -0800 Message-ID: References: <87sfhvdn6k.fsf@dfreeman.email> <87o7sheure.fsf@dfreeman.email> <097583CE-DB01-4BCD-9A87-5D30E92A4F66@gmail.com> <87iliotuj6.fsf@dfreeman.email> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27499"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Danny Freeman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 08 01:53:53 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 1p35Af-0006yq-3x for ged-emacs-devel@m.gmane-mx.org; Thu, 08 Dec 2022 01:53:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p359s-00017B-8r; Wed, 07 Dec 2022 19:53:04 -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 1p359q-00016f-Tl for emacs-devel@gnu.org; Wed, 07 Dec 2022 19:53:02 -0500 Original-Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p359p-0008K0-4J for emacs-devel@gnu.org; Wed, 07 Dec 2022 19:53:02 -0500 Original-Received: by mail-pl1-x62c.google.com with SMTP id d7so20379pll.9 for ; Wed, 07 Dec 2022 16:53:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rqKSGwYzSFFrskh+DqtWLS0yJn9g4HIxJ18HaHYKwHQ=; b=JHR2ly43j5UXz6taYSBlnPfWigzZXeRgTEJBVxkFgnnTQbspbVmeKjP+KNWs5qCc1L 9Th3McC0y8uEWivbETUNXxipsISkNJx/MzMnPY3juYqAlFgfZXfc+WcUdjzL0n58ADmM YVxpBuFFe5lcl+SlEkTDcRe/feXmw1toMILMqbAIaGPqsFSEQbClmcQ2yeJ01uQOPhx8 jEyr5IDoUF/NMEe7YD1WB0iBdt+orHhMMEgSsU9JRUgAsrAHx+IQBBabopC+LScLMi6w 1Zl1iPwfjNFlRrfQBX9PNZ6hfk1fNl7kiZo71LzFvJxSG40khtowL0EAJelsMzOMnyat Pt+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rqKSGwYzSFFrskh+DqtWLS0yJn9g4HIxJ18HaHYKwHQ=; b=v/hkRKlxnNcbt5D2dpWdipUnb0ick2ypMQgv165bdPBuYhfPOU66Q5YxXTs4dteQwb WsJfKhwvDotepLhGpDcE7mjjM32VqCsPrEq8XKXRSBr0tDi7gKEwt5DiITx4YrZpD3lF 1lGiUjf8Blkei2sU68KWp9Y7jwAc6BwaZLHuo+4G4D2aYYV/4ZAt1P2jiyBr/tohtDnS GiJkoh0f7dXuzs+LuKEhKeg/wz+v0BLVaqQ4ICXLFXPOqMJ2i7oGAOD0QPmOBhdof/zj GmUPHf6HXNmsMSXt2ynDJKWdVkeh+7Vngtjf9XnwG5zzLnRLV9FHK5Jf0drgcliU2UOj hwQw== X-Gm-Message-State: ANoB5pnturZKUhN/hn1n5Cf70a3aJFhPPRdAfTaYsivd7fclhR+/BWnk pwWB4re8Ibd7h15WuObPmhnUKsyRdGemtg== X-Google-Smtp-Source: AA0mqf6T8PyBdNg3egr3pyq9necJxZip32NIIyvfP/5F33prkGJglIM8DTUGrLYXtACnMqI2e7LWqw== X-Received: by 2002:a17:902:e743:b0:187:34f6:3323 with SMTP id p3-20020a170902e74300b0018734f63323mr1821276plf.59.1670460778908; Wed, 07 Dec 2022 16:52:58 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id e8-20020a17090301c800b00189b2b8dbedsm13280079plh.228.2022.12.07.16.52.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2022 16:52:58 -0800 (PST) In-Reply-To: <87iliotuj6.fsf@dfreeman.email> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=casouri@gmail.com; helo=mail-pl1-x62c.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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:301030 Archived-At: > On Dec 6, 2022, at 7:13 AM, Danny Freeman = wrote: >=20 >=20 > Yuan Fu writes: >=20 >>> On Dec 5, 2022, at 7:25 AM, Danny Freeman = wrote: >>>=20 >>>=20 >>> Yuan Fu writes: >>>=20 >>>> 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. >>>>=20 >>>> You can have a look at c-ts-mode--fontify-variable for a simple = example. >>>=20 >>> This is exactly what I was looking for. I can't believe I didn't = think >>> of this when I was reading the documentation. >>>=20 >>> Thank you for your help! >>=20 >> 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 ;-)=20 >>=20 >> Yuan >=20 > 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! >=20 > The treesit-explore-mode is a really great tool for implementing the > syntax highlighting as well. It is a real treat to work with. >=20 > Here is how I ended up using a function to fontify the symbols the way = I > needed to, in case you are curious: >=20 > = https://github.com/dannyfreeman/clojure-mode/blob/513403c5e97330b65d024e2e= 904c165021540480/clojure-ts-mode.el#L162-L177 >=20 > 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=