From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: Turning on/off tree-sitter modes Date: Fri, 29 Nov 2024 13:09:10 -0500 Message-ID: References: <556779b3-9308-4fd3-9050-bf9c49658cd1@gutov.dev> <864j43t8t9.fsf@gnu.org> <4cc676e8-cac5-4348-99b0-243baf74687e@gutov.dev> <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> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32809"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:Cf4AggpxB1R7hF4W80xHR6CF7Zw= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 19:10:14 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 1tH5RV-0008RA-JH for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 19:10:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH5Qk-0006pq-MV; Fri, 29 Nov 2024 13:09:26 -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 1tH5Qi-0006pg-Lt for emacs-devel@gnu.org; Fri, 29 Nov 2024 13:09:24 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH5Qf-0000AD-Rz for emacs-devel@gnu.org; Fri, 29 Nov 2024 13:09:23 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1tH5Qc-0007bO-65 for emacs-devel@gnu.org; Fri, 29 Nov 2024 19:09:18 +0100 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325858 Archived-At: > Here are the issues that are currently not handled by your patch, > which perhaps require modifications and additions (but should probably > be discussed first): > > . we need the ability to turn on and off selected TS-based modes, > and do it easily > . we should include in this feature handling of all the TS-based > modes in core (right now, I don't see python-ts-mode, > ruby-ts-mode, and csharp-ts-mode, at least) > . we should decide how to handle TS-based modes whose non-TS > counterparts are available as 3rd-party packages > . we should decide whether we want to modify auto-mode-alist or use > major-mode remapping for all the TS-based modes I remember writing a description of the UI I had in mind but can't find it again, so maybe I failed/forgot to send it? In any case I was thinking of a UI that's not specific to tree-sitter that works as follows: (defun change-major-mode (newmode) (interactive (list (read-the-new-mode))) (cond ((eq major-mode (the-mode-normally-selected-by-auto-mode-alist)) (setf (alist-get major-mode major-mode-remap-alist) newmode) (when (called-interactively-p) (customize-mark-as-set 'major-mode-remap-alist))) (t (let ((regexp (guess-regexp buffer-file-name))) (add-to-list 'auto-mode-alist (cons regexp newmode)) (when (called-interactively-p) ...somehow convince Custom to do the above `add-to-list`...)))) (funcall newmode)) `read-the-new-mode` could use a variable like Dmitry's `treesit--mode-associations` to provide good defaults. BTW, this var shouldn't be set like in his patch, IMO but via ###;;;autoload (add-to-list 'treesit--mode-associations (javascript-mode . js-ts-mode)) and its name should not be treesitter-specific either, then. We could also have a command `treesit-enable-all-mode` which uses a variable `treesit-mode-grammars` (an alist mapping modes to grammars, setup via the same kind of autoload+add-to-list as above), to add to `major-mode-remap-alist` all the TS modes for which the user has installed the corresponding grammar. Stefan