From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Disable tree-sitter font-locking for smaller ranges Date: Mon, 17 Oct 2022 08:33:11 +0200 Message-ID: <87o7ub0xjs.fsf@thornhill.no> References: <877d109hz1.fsf@thornhill.no> <672FF8D1-E5FB-44D8-8E6D-38EB94843B3B@gmail.com> <543ACCB7-9EE3-41AF-B1E3-704B6E6BC085@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24317"; 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 Mon Oct 17 08:46: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 1okJtF-000695-PS for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 08:46:22 +0200 Original-Received: from localhost ([::1]:43648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okJt9-0001qp-B3 for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 02:46:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okJgf-00033v-Ny for emacs-devel@gnu.org; Mon, 17 Oct 2022 02:33:21 -0400 Original-Received: from out2.migadu.com ([2001:41d0:2:aacc::]:16457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okJgb-0001nx-Rx for emacs-devel@gnu.org; Mon, 17 Oct 2022 02:33:21 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1665988392; 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=y+ZYrvRVn0yrijD2nNoPOryYqkdtk+RLDFw+djswmSo=; b=kZmPh5y+wstW+moBwa3RvCTOxuDmNvBkOiNR9XZLDDjuGWpTHs/TkIhxhZ+3K/5/H8LV5X Efxzo/Vi01foJqcJFZKR2tU9q7ExEpcmqYgYzvexR3tQpm9AC3/pdIrhMH5gFg1lR/XLxu LaxLUZtaxYsD30OmOb94kYMLCGntPf1wOBd27HWF8hv9BzMrAMRkf9LhuXaFNzy5KwA9Cw xef7OmW64+s4uSWUNKG1IJY3Ow+OUtT27uNUGbgkLzSpzmszXgXqXwjK4xhbXbu89MP4+z QaIh4tGmF7n707UpMk3ZhDb4f0L+Xh0jWP3yB+rEMHnzvmCuehhjCEXXBx87yQ== In-Reply-To: <543ACCB7-9EE3-41AF-B1E3-704B6E6BC085@gmail.com> X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=theo@thornhill.no; helo=out2.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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" Xref: news.gmane.io gmane.emacs.devel:297921 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Yuan Fu writes: >>>=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 exac= tly 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 > 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 > Yes! That's it! Thanks :) See attached patch: Theo --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-correct-ordering-in-template_substitution.patch >From dbe998506f9052455d3499638930418832f5c243 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Mon, 17 Oct 2022 08:29:39 +0200 Subject: [PATCH] Add correct ordering in template_substitution We want to override the template substitution contents with no coloring, because we need the font-lock-string-face not to bleed into the substitutions. The correct ordering of these forms are important. * lisp/progmodes/js.el (js--treesit-settings): Move template string related queries to top, and use the correct ordering. * lisp/progmodes/ts-mode.el (ts-mode--settings): Move template string related queries to top, and use the correct ordering. --- lisp/progmodes/js.el | 12 ++++++++---- lisp/progmodes/ts-mode.el | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 18499a466a..0cf106f482 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3461,8 +3461,14 @@ js--treesit-settings :language 'javascript :feature 'basic :override t - `(;; Everything overrides template string. + `( + ;; The order of these are important. We want to keep coloring in + ;; the string, but not in the substitution, thus delegating the + ;; contents of that substitution to the usual rules (template_string) @font-lock-string-face + (template_substitution) @default ; Color everything white + (template_substitution + ["${" "}"] @font-lock-builtin-face) ((identifier) @font-lock-constant-face (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face)) @@ -3559,9 +3565,7 @@ js--treesit-settings (string) @font-lock-string-face (comment) @font-lock-comment-face - [,@js--treesit-keywords] @font-lock-keyword-face - - (template_substitution ["${" "}"] @font-lock-constant-face)))) + [,@js--treesit-keywords] @font-lock-keyword-face))) (defun js-treesit-current-defun () diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index 10d4b7bd18..5a8f7da30a 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -110,7 +110,14 @@ ts-mode--settings :override t :feature 'basic '( + ;; The order of these are important. We want to keep coloring in + ;; the string, but not in the substitution, thus delegating the + ;; contents of that substitution to the usual rules (template_string) @font-lock-string-face + (template_substitution) @default ; Color everything white + (template_substitution + ["${" "}"] @font-lock-builtin-face) + ((identifier) @font-lock-constant-face (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face)) @@ -225,9 +232,6 @@ ts-mode--settings (string) @font-lock-string-face (template_string) @font-lock-string-face - (template_substitution - ["${" "}"] @font-lock-constant-face) - ["!" "abstract" "as" -- 2.34.1 --=-=-=--