From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Noah Peart Newsgroups: gmane.emacs.bugs Subject: bug#70361: [PATCH] Add font-locking for operators in go-ts-mode. Date: Mon, 15 Apr 2024 05:05:17 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f619820616216f2b" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31086"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 70361@debbugs.gnu.org, Eli Zaretskii To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 15 14:06:29 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rwL6T-0007vE-Cu for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Apr 2024 14:06:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwL63-0001eK-T1; Mon, 15 Apr 2024 08:06:03 -0400 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 1rwL5u-0001e3-Dv for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 08:05:56 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwL5q-0001h8-On for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 08:05:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rwL62-0002UO-5g for bug-gnu-emacs@gnu.org; Mon, 15 Apr 2024 08:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noah Peart Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Apr 2024 12:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70361 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70361-submit@debbugs.gnu.org id=B70361.17131827589559 (code B ref 70361); Mon, 15 Apr 2024 12:06:02 +0000 Original-Received: (at 70361) by debbugs.gnu.org; 15 Apr 2024 12:05:58 +0000 Original-Received: from localhost ([127.0.0.1]:37051 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwL5u-0002Tt-KX for submit@debbugs.gnu.org; Mon, 15 Apr 2024 08:05:58 -0400 Original-Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]:45536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwL5m-0002Rk-4s for 70361@debbugs.gnu.org; Mon, 15 Apr 2024 08:05:52 -0400 Original-Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-2331bef249eso1303973fac.3 for <70361@debbugs.gnu.org>; Mon, 15 Apr 2024 05:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713182728; x=1713787528; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=T2yHInQgxIdbfHOHgmDXAmvtPl+G/ZmEyBd9iw5Qfeg=; b=IC+XHIz+IDlhoKypm8K1y+EOpi87RXRIUjkNGGikykoYfhH7tKwJSGNsVHQeB0C5tV 3BGDCppvY5qSvRUlUTj3mevtVxzaXOBulSUd+bgQV7PK/WOpb8FxnbpP5zY49MnMQaxc hdjDSXuU+m8P/+tT6ky7aQ5oI3LKslqaYG3bsJmb3Agc1Q9KzksS4YtqVvMoCYj5JWci hHkg9pe+7xlikO5O+371aWbWWNYKI5KaC5pFSgcyoBdQLBaNylWI1AM4z20L8+Du+e2d CwXog+7/SrZQJOFgG0A4HpqVLZb1poEQiUIC4MkkwbAxg3MU3x1QTm80GCjlWIY88mDi RAnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713182728; x=1713787528; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=T2yHInQgxIdbfHOHgmDXAmvtPl+G/ZmEyBd9iw5Qfeg=; b=xRaOZLJyTjzZ1zgEJrQTemsQG+Iur0uBHQOTCst6ereRtgPdocP1wFAVvQnjZSGBqU W+V1gfp1Jx7nqhj2IAmw3a+JS09WKssRF6CtG/8SgQNt+mDB9/1q5M3Y92HrvqIvvgU1 3sRY1Zs94qfEZRC458yAzQ9lOuOWnutBR48dBeDyO3hbSBeAeDub0COzO7dF+GPJMp0a jm4NLMDCAgLTWn6eh3EVCGcv2vdMn55P/3hdYcrf3csO0baikiY9rYdnxa2dOod54mj0 GW2RvcAhh93kbDnYDxvAR2I31TFVPurtWNU/TdAUkB9UZtfM/bR00WUbiJYnwAKQT6vL 1gFQ== X-Forwarded-Encrypted: i=1; AJvYcCW8j2uw1AOf602GgWS4Z5Ys2mp78+JZewW8a6qN4/Eu+u3f07LorERWQb67F7XAo6FrkmIa5hYEev7/cnJ2TKMraPw6hGY= X-Gm-Message-State: AOJu0YxGhX4F0fl6RAB0lfP8Uk9B4XngqVKde7yNO4Yv2X6Bc//JQCNb upkQ3ya0+sZYPMs2E/CeIK2qvNlaIAamMfhKCBZLABzbA0FptAOIqvLKydY/fcce2l2bleSZHga O5ZzDKffd7eTvrp5Oz+RVRCGTLiA= X-Google-Smtp-Source: AGHT+IE5Kog6vhofQzMAXBBxy6QXkhphdMxbtKNQbn4bhcrQMVtqtHC+sN5aSsT0H8r0zFn6Mvhc++K7zxEhfRz5Yqk= X-Received: by 2002:a05:6870:8a28:b0:22a:7b20:410d with SMTP id p40-20020a0568708a2800b0022a7b20410dmr12106126oaq.33.1713182728392; Mon, 15 Apr 2024 05:05:28 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283365 Archived-At: --000000000000f619820616216f2b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thankyou, this all makes sense. I do think it would be nice if it was easier to somehow add user customizations to the font-locking, especially since it is so easy to write tree-sitter font-locking rules. > We just don=E2=80=99t want a central tree-sitter-font-lock-feature-list t= hat controls the feature list of every major mode in a single place. What would you think of something like a `user` feature that could be enabled globally and users could add their mode-specific rules there? Eg. (defvar my-treesit-font-lock-rules (treesit-font-lock-rules :language 'go :feature 'user '((identifier)) :language 'typescript :feature 'user '((identifier)) ;; ... )) This wouldn't work very well in certain cases where ordering of the rules was important, however. On Sun, Apr 14, 2024 at 4:34=E2=80=AFPM Yuan Fu wrote: > > Eli Zaretskii writes: > > >> From: Noah Peart > >> Date: Sat, 13 Apr 2024 00:32:59 -0700 > >> Cc: 70361@debbugs.gnu.org > >> > >> On a somewhat related note, I was wondering why the treesit modes in > emacs > >> define their `treesit-font-lock-feature-list`s in the mode definitions= . > >> > >> Wouldn't it be more user-friendly to `defvar` the feature list? > > > > AFAIR, we do that in the mode's settings because the translation of > > general categories into mode-specific settings is not easy, and > > because we want users to control that via the fontification level, not > > below that. > > > > What problems do you see with the current approach that would require > > more fine-grained user control? And why do you think a defvar is the > > proper way of providing such control? > > Replying to Noah, I don=E2=80=99t think there=E2=80=99s anything wrong fo= r a major mode > to define a xxx-mode-feature-list and assign it to > treesit-font-lock-feature-list when setting up the major mode. We just > don=E2=80=99t want a central tree-sitter-font-lock-feature-list that cont= rols > the feature list of every major mode in a single place. > > But again, even if a xxx-mode defines xxx-mode-feature-list, it would be > a bit of a hassle to take out or remove a single feature from the list, > since it=E2=80=99s a list of list. (You can just setq the whole list, but= then > you need to keep it in sync with upstream.) It=E2=80=99s probably easier = to call > treesit-font-lock-recompute-features in the major mode hook anyway. > > Yuan > --000000000000f619820616216f2b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thankyou, this all makes sense.=C2=A0 I do think it= =C2=A0would be nice if it was easier to somehow=C2=A0
add user cu= stomizations to the font-locking, especially since it is so easy to write t= ree-sitter
font-locking rules.

> We j= ust don=E2=80=99t want a central tree-sitter-font-lock-feature-list that co= ntrols
the feature list of every major mode in a single place.
What would you think of something like a `user` feature that co= uld be enabled
globally and users could add their mode-specific r= ules there? Eg.

=C2=A0 =C2=A0 (defvar my-treesit-f= ont-lock-rules
=C2=A0 =C2=A0 =C2=A0 (treesit-font-lock-rules
=C2=A0 = =C2=A0 =C2=A0 =C2=A0:language 'go
=C2=A0 =C2=A0 =C2=A0 =C2=A0:featur= e 'user
=C2=A0 =C2=A0 =C2=A0 =C2=A0'((identifier))

=C2=A0= =C2=A0 =C2=A0 =C2=A0:language 'typescript
=C2=A0 =C2=A0 =C2=A0 =C2= =A0:feature 'user
=C2=A0 =C2=A0 =C2=A0 =C2=A0'((identifier))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0;; ...
=C2=A0 =C2=A0 =C2=A0 =C2=A0))

This wouldn't work very well in certain cases wher= e ordering of the rules
was important, however.

On Sun, Apr = 14, 2024 at 4:34=E2=80=AFPM Yuan Fu <casouri@gmail.com> wrote:

Eli Zaretskii <eliz@gn= u.org> writes:

>> From: Noah Peart <noah.v.peart@gmail.com>
>> Date: Sat, 13 Apr 2024 00:32:59 -0700
>> Cc: 703= 61@debbugs.gnu.org
>>
>> On a somewhat related note, I was wondering why the treesit modes = in emacs
>> define their `treesit-font-lock-feature-list`s in the mode definit= ions.
>>
>> Wouldn't it be more user-friendly to `defvar` the feature list= ?
>
> AFAIR, we do that in the mode's settings because the translation o= f
> general categories into mode-specific settings is not easy, and
> because we want users to control that via the fontification level, not=
> below that.
>
> What problems do you see with the current approach that would require<= br> > more fine-grained user control?=C2=A0 And why do you think a defvar is= the
> proper way of providing such control?

Replying to Noah, I don=E2=80=99t think there=E2=80=99s anything wrong for = a major mode
to define a xxx-mode-feature-list and assign it to
treesit-font-lock-feature-list when setting up the major mode. We just
don=E2=80=99t want a central tree-sitter-font-lock-feature-list that contro= ls
the feature list of every major mode in a single place.

But again, even if a xxx-mode defines xxx-mode-feature-list, it would be a bit of a hassle to take out or remove a single feature from the list,
since it=E2=80=99s a list of list. (You can just setq the whole list, but t= hen
you need to keep it in sync with upstream.) It=E2=80=99s probably easier to= call
treesit-font-lock-recompute-features in the major mode hook anyway.

Yuan
--000000000000f619820616216f2b--