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 22:04:58 -0700 Message-ID: <672FF8D1-E5FB-44D8-8E6D-38EB94843B3B@gmail.com> References: <877d109hz1.fsf@thornhill.no> 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="29889"; 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 07:07:22 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 1okILR-0007YU-DK for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 07:07:21 +0200 Original-Received: from localhost ([::1]:36382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okILP-0000VL-Uq for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 01:07:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okIJD-00085n-2R for emacs-devel@gnu.org; Mon, 17 Oct 2022 01:05:03 -0400 Original-Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:41813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okIJB-0003uJ-Cw for emacs-devel@gnu.org; Mon, 17 Oct 2022 01:05:02 -0400 Original-Received: by mail-pj1-x102a.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so9969825pjl.0 for ; Sun, 16 Oct 2022 22:05:00 -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=bWRKiHgQ387bdbDsX+9ZyZhbELNYf7okD4WTeyYQxi8=; b=YGbNo0wemccJw/yOk0B+MCj7hRLxJDVJnPYdnMCCmCTNtb5qtBptkuCPay+k6L1KL2 Wk+y2XAY3kcnHraoNgUmAm5DBvqWrrAKu28CuncSSLMARh2b3d9yiZkKsEJohgIz2Uox XNHpwwD5r96PiP0+OBGF0COAraDoWnSH5RAiLldCuNeCnSoMVnbzewfA26PY/bblplhX ItLIs16d/A0B99BQYhd7oXoLywbv9lOKzRjv6niC+avJ10cHzImMx61znXXJgujvqJWh KpWmj/g3RdkhTSmPatbqfWwzMAz3AnoJBds7+WwCU2e+Th9d3ETlRWQU3z9TlamyRrG/ z9Xg== 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=bWRKiHgQ387bdbDsX+9ZyZhbELNYf7okD4WTeyYQxi8=; b=pN8os01oh2Th0zxdBtvNxb/VucPA7gMXZMNVwFSf1I72+t4MWocFFiD6C8QoWOv55l Pp6PmJP0pNY015/lHwsD93S81RItfBY8wt6oUVsSaDTMLZK10U34cJB7L8PfBTz0A/mR LFztnbji1Ar3m2evdYKBn69XLXqs6lmtBLuPQXkn8MVlPL/xUdsi4CpbpgTBICjF+2Ar nCPIFr7Bw/3IFp37kSiR3n/0WxcA8ClD7cL4Qq2KC/A/nf+sCOjYk8rK5hFWs6Sr+2Mx ky+cfUaDtlUZMegSpXrIP8dh0Hgvrwr6OGuj9XFd6x3aNHt2xzACuL3LvGRM+l0OSdXf Ph/Q== X-Gm-Message-State: ACrzQf3soujlEbj0+xXhsNdz9Vo+pdEj7hXLqhDG9H49RFs5khH944wJ ecyyZTpjSqoofSWG4ncQpdE= X-Google-Smtp-Source: AMsMyM6aeNfQdxXbsG3R1N0VQv5J6HwS1Fpbry70toYJN1dUJdJbh39TnT8ThIY1yzT1/sb7hwZULA== X-Received: by 2002:a17:90a:f315:b0:20b:15fc:ac5c with SMTP id ca21-20020a17090af31500b0020b15fcac5cmr30373283pjb.220.1665983099929; Sun, 16 Oct 2022 22:04:59 -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 m4-20020a170902f64400b00176b84eb29asm5484146plg.301.2022.10.16.22.04.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Oct 2022 22:04:59 -0700 (PDT) In-Reply-To: <877d109hz1.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=casouri@gmail.com; helo=mail-pj1-x102a.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:297905 Archived-At: > 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 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. If you don=E2=80=99t want font-lock in substitutions, you can put=20 > '((template_string) @font-lock-string-face=20 > (template_substitution ["${" "}"] @font-lock-constant-face)) After all other queries, and mark these two with :override t. That = should do it. Also, when I was browsing tsx=E2=80=99s grammar file, I didn=E2=80=99t = find definition of template_substitution at all. That means at least = some part of js and tsx=E2=80=99s grammar are not interchangeable. Yuan=