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: Disable tree-sitter font-locking for smaller ranges Date: Sun, 16 Oct 2022 23:01:51 -0700 Message-ID: <543ACCB7-9EE3-41AF-B1E3-704B6E6BC085@gmail.com> References: <877d109hz1.fsf@thornhill.no> <672FF8D1-E5FB-44D8-8E6D-38EB94843B3B@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14867"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 17 08:11:45 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 1okJLl-0003gF-7B for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 08:11:45 +0200 Original-Received: from localhost ([::1]:46708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okJLj-0000Kx-TV for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 02:11:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okJD0-0004hM-Vy for emacs-devel@gnu.org; Mon, 17 Oct 2022 02:02:43 -0400 Original-Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:40661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okJCF-0004hH-OS for emacs-devel@gnu.org; Mon, 17 Oct 2022 02:02:42 -0400 Original-Received: by mail-pf1-x432.google.com with SMTP id h13so10154669pfr.7 for ; Sun, 16 Oct 2022 23:01:54 -0700 (PDT) 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=v+qr6ddfJg0dB9OlhuzayNEC8AM1AmLEBFgLyyI3WU4=; b=kiinXhN92QjI2QjICMUg+ue/lVFmKsslajRTPanbfO2Wf/teNMWPg7d3q2V3QsXNYU 45gNVnTg8O/KPqe1Nmy+Rz2EuznUjdLnWuc+PJl6xBbEC6EK1jighhavyI/xoQQbKPDM SaC3t3LBhcdlb3ZuLWxGXAkwvyIeCguJz3pYbeAuNlzz2v/0qzIaLTT+U9NyCvYfa8G+ sNgSAdOjNONM8venShwbVjfbdkxSnZe/iH4BH2QPulMMx+cXvaphIfhA6PMIaoRnnxez wGckb862kwua088ZJ3Vgdp6Uq4DJ1KYlM1++8NVWUyr+glbKHwivbJY3jmxya2LtdQcX 8fjg== 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=v+qr6ddfJg0dB9OlhuzayNEC8AM1AmLEBFgLyyI3WU4=; b=Ps+Ble173TOixfTDdpF9GlP6RNLji2zAdzY/7by2iPBxS/OdTv46wiuwsY16919wQm SkGSy8p9NfaLUW/ES3TvK0TwAosmHzNrRA4dxmpBHVkiHt4o9PzggBlapydQnxuWLMqd HN5jilf98I986CRFuqdbRUZUfldMjiyszeFZVGeIbC/0xi5LIYXjmwclEFo4JnHK70SC MnnDBnw7A2e2Y02okUo58jUQ3FoBVEzqd9yT3lesAcy6EzQOMyIg6+B3wY13bNaMi1b2 7PLHdUDE9dHLH4ZIELwHUB9C5tMrwWWei23kZHpvTJeGPKEypnNs08tOn1CLHtOJpWTW A6uQ== X-Gm-Message-State: ACrzQf3RXWcMoqvQ4GFvi9PTMUNZ9TNamwQrR5Wrj/Hd4fiU/PxDbZi9 9fnBJ4nmOWArxc+QHCp4Vj/0xk7kJ2o= X-Google-Smtp-Source: AMsMyM6A2vjfj/lTFZ+w+vVXE92LYgn7d/DFXsXIZQKl6LbJLx0bPKevPiCMw4/qH3BpeG35s2BUMQ== X-Received: by 2002:a63:d709:0:b0:461:be56:507e with SMTP id d9-20020a63d709000000b00461be56507emr9689764pgg.597.1665986513401; Sun, 16 Oct 2022 23:01:53 -0700 (PDT) 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 w4-20020a628204000000b005623fa9ad42sm5704838pfd.153.2022.10.16.23.01.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Oct 2022 23:01:53 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=casouri@gmail.com; helo=mail-pf1-x432.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" Xref: news.gmane.io gmane.emacs.devel:297915 Archived-At: > On Oct 16, 2022, at 10:49 PM, Theodor Thornhill = wrote: >=20 >=20 >=20 > On 17 October 2022 07:04:58 CEST, Yuan Fu wrote: >>=20 >>=20 >>> On Oct 16, 2022, at 3:32 AM, Theodor Thornhill = wrote: >>>=20 >>>=20 >>> Hi Yuan! >>>=20 >>> I've been trying to tweak the font-locking for tree-sitter in >>> js/ts-mode, and I'm still struggling with the template strings. Is >>> there a way to _disable_ font-locking for smaller ranges? >>>=20 >>> Let's say you have this string: >>> ``` >>> `Some string with ${5+5} many template substitutions = ${foo().bar().baz()}`; >>> ``` >>>=20 >>> This string will match something like: >>> ``` >>> (template_string (template_substitution) :*) >>> ``` >>>=20 >>> If you use this as a query: >>> ``` >>> (template_string) @font-lock-string-face >>> ``` >>>=20 >>> Everything inside the string is in string-face. >>>=20 >>> If you add >>> ``` >>> (template_substitution >>> "${" @font-lock-constant-face >>> (_) >>> "}" @font-lock-constant-face) >>> ``` >>>=20 >>> You get font-locking in the ranges inside the squigglies, as = expected. >>> However, if there isn't defined any rules for say, "(), . []" etc, = the >>> template_string capture will bleed into the substitution, because = its >>> range suggests it should. It would be nice to say something like: >>>=20 >>> ``` >>> (defvar fonts () >>> (treesit-font-lock-rules >>> :language 'tsx >>> :override t >>> :feature 'basic >>> '((template_string (_):* @disabled) @font-lock-string-face=20 >>> (template_substitution ["${" "}"] @font-lock-constant-face))) >>> ``` >>>=20 >>> to ensure that whatever is inside the wildcard match will _not_ be >>> considered for the string face, but whatever is still inside the = bigger >>> range will. Is this currently possible? If not, is >>> it possible to add? I guess I could make a function that would = remove >>> the range, but that seems fiddly and error prone. >>>=20 >>> I've tried fiddling with the :feature flag in = 'treesit-font-lock-rules', >>> but I never found a combination that did what I wanted. >>>=20 >>> Adding a small image of a stupid snipped just to make the point more = visual >>=20 >> The image you attached looks perfectly fine to me. Do you not want to = font-lock what=E2=80=99s inside a substitution? I=E2=80=99m not exactly = sure what result you want to archive. >>=20 >=20 > 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.=20 >=20 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 Yuan=