From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Turning on/off tree-sitter modes Date: Sun, 24 Nov 2024 09:29:30 +0200 Organization: LINKOV.NET Message-ID: <87ed31gku5.fsf@mail.linkov.net> References: <8634jnt5e3.fsf@gnu.org> <4864104c-cb23-4356-ad89-2fea111db66c@gutov.dev> <86ttc2rrh8.fsf@gnu.org> <86cyipsp94.fsf@gnu.org> <9cd17f8b-f88c-49f6-9024-0b6d297e18ac@gutov.dev> <867c8xsmri.fsf@gnu.org> <566ac897-ea5e-4141-bcb3-306d43c9118a@gutov.dev> <865xohrvfa.fsf@gnu.org> <86wmgwnyle.fsf@gnu.org> <178dfc7f-bc2d-4e3b-8417-a616ccc0eef3@gutov.dev> <86v7wgnxlz.fsf@gnu.org> <01d83ec8-c02b-4806-8764-38dc89a89125@gutov.dev> <86ttbzojho.fsf@gnu.org> <930f5c8e-1481-43a5-8f1d-2c13a98df74f@gutov.dev> <86r072krq5.fsf@gnu.org> <8b907a41-aa08-4b61-bced-7d4d3fcef4b2@gutov.dev> <87frnhsvp3.fsf@mail.linkov.net> <0d1e2770-0889-4862-8105-8a5f4631b11c@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12412"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: Eli Zaretskii , johan.myreen@gmail.com, emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 24 08:37:31 2024 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 1tF7BT-00039w-7n for ged-emacs-devel@m.gmane-mx.org; Sun, 24 Nov 2024 08:37:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tF7Ao-0002s2-Cv; Sun, 24 Nov 2024 02:36:50 -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 1tF7Aj-0002oF-Ah for emacs-devel@gnu.org; Sun, 24 Nov 2024 02:36:46 -0500 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tF7Ah-0006tB-FQ; Sun, 24 Nov 2024 02:36:45 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id B104540002; Sun, 24 Nov 2024 07:36:38 +0000 (UTC) In-Reply-To: <0d1e2770-0889-4862-8105-8a5f4631b11c@gutov.dev> (Dmitry Gutov's message of "Sun, 24 Nov 2024 04:29:11 +0200") X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=217.70.183.194; envelope-from=juri@linkov.net; helo=relay2-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325648 Archived-At: >> Recently Philip rightly noticed that 'major-mode-remap-alist' >> would be sufficient. And indeed, such a command could be implemented >> just as >> (defun treesit-add-enabled-mode (non-ts-mode ts-mode) >> (setopt major-mode-remap-alist >> (cons (cons non-ts-mode ts-mode) >> major-mode-remap-alist))) > > A few problems with that: > > - Where does the second argument come from? Do we read the first argument > from the user as well? The answer depends on the purpose of the 'treesit-add-enabled-mode' command that I still don't understand. Is it supposed to be used in user configs as (treesit-add-enabled-mode 'ruby-mode 'ruby-ts-mode) to be another way to do the same as (add-to-list 'major-mode-remap-alist '(ruby-mode . ruby-ts-mode)) Or maybe we want to simplify this setting. Then we need not a command, but a new option 'treesit-enable-modes': (add-to-list 'treesit-enable-modes 'ruby-ts-mode) > - Some modes can use major-mode-remap-alist, and some (such as go-ts-mode) > don't have "original" modes to hook up to. For those cases, the command > would have to read the regexps from the user, and it's #1 thing we > apparently want to avoid. > >> Or the idea was to simplify this by using only ts-mode here >> while maintaining a huge database of non-ts → ts mappings >> in an internal variable? (that will eventually grow >> into something like 'eglot-server-programs') > > If we want to have an option like treesit-enable-modes (allowing the user > to turn on all built-in ts modes), it doesn't seem like we could do that > without maintaining this database in some form. Only for built-in modes, > though. Actually, there is already such a database in files.el: the default value of 'auto-mode-alist' is the database of file associations. So for ts-modes that don't have a corresponding non-ts mode in core we need to add their file associations to 'auto-mode-alist'. However, not directly, but via a non-ts mode. So, for example, 'auto-mode-alist' should contain '("\\.go\\'" . go-mode)', then 'major-mode-remap-defaults' should contain a mapping from 'go-mode' to 'go-ts-mode'. This will help to remove the requirement to load a ts-mode file to change file associations, that currently causes problems such as: 0. emacs -Q 1. C-h f go- TAB that pops up the warnings buffer with: ⛔ Warning (treesit): Cannot activate tree-sitter, because language grammar for go is unavailable (not-found) ⛔ Warning (treesit): Cannot activate tree-sitter, because language grammar for gomod is unavailable (not-found) >> Then it could modify the variable 'major-mode-remap-defaults'. >> And 'major-mode-remap-alist' will take precedence over it >> when customized. > > I don't have a strong opinion, but it seems like if a variable is modified > by explicit command from the user, major-mode-remap-alist seems more > appropriate than major-mode-remap-defaults (which would be about some > global defaults). > > Not 100% sure though - because that plan would delete the vast majority of > the uses of the latter from the core (except for TeX's mappings, it seems). Agreed, 'major-mode-remap-defaults' could be removed when loading a ts-mode file will not modify file associations anymore.