From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Turning on/off tree-sitter modes Date: Mon, 2 Dec 2024 04:04:49 +0200 Message-ID: <84e8cd47-6606-457e-b122-a639227f67a1@gutov.dev> References: <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> <27a62624-387c-4233-b995-170270e26efd@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12036"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 02 03:06:03 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 1tHvp4-0002vU-4G for ged-emacs-devel@m.gmane-mx.org; Mon, 02 Dec 2024 03:06:02 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tHvo5-0002so-V0; Sun, 01 Dec 2024 21:05:03 -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 1tHvo0-0002sW-JS for emacs-devel@gnu.org; Sun, 01 Dec 2024 21:04:57 -0500 Original-Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tHvny-0003Rq-Qw for emacs-devel@gnu.org; Sun, 01 Dec 2024 21:04:56 -0500 Original-Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 6E18011400CE; Sun, 1 Dec 2024 21:04:53 -0500 (EST) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Sun, 01 Dec 2024 21:04:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1733105093; x=1733191493; bh=FBnjf1PozoK05CrSD6jaz5YkzwFNtBU7dRYpY66mwLg=; b= e9Cv4lIg3wjVSW74T/XQGNQ8IZOm+6XSgasESm+VkZjWPKcoKgXritQF0Ar90PiX 7PyKt1z8Zo6MXHPYkFg8ZtO3bzrsFb7k1VObuf5ONLkbgsrJ1xwaFt6oifTZXuJt O8JrWgxfPxRHOX24F19wt5zSrPD/xzBsn8SkwUMpecNNTkvp7S8EHJs7O/W3M+Wu 7OiwRuTzxICzJw9B0U03ekG7kWH3RpOrSRtke5AYTjiiK1WLFRvPtEMXmuIdBwXA mbC5jYzCXRZvNpH5mkQyMnR/g9CCw0eulsArl98lflU0j4G6uPxHVWg1Oj8CwsLU qbzv5drdo9y1x1WfaBdNQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1733105093; x= 1733191493; bh=FBnjf1PozoK05CrSD6jaz5YkzwFNtBU7dRYpY66mwLg=; b=H 3LgtMotddgEUv5lJzvquNGmyc9TU9JxNWo3EJ/xGiwf0UovcBV4I0bEXaymk9jSS /R50RM9o41jJxZAzYuPEUhAWZYvVV50SK4MirXUz+Pp73gTAUJKZ6cDRzwqtcAlj kfrIyCnX5vd9t/nqpr5UfuhHb3r/ZveehvciepNHztx+UIcRHWC+8oYom+k/UW9T olRFmZW6fbmNgNbVubbsCqmYQOj/Xxmd6JK2Y7FPFk8OOLOi0tb98PVWb5fTke71 vApCqeUl/CgjAo8I12EKBz1PI0u046riRf+xnx8YlUMFjEN6ZLsQFW2xKphUXjO2 KfPp65xn23GilCSUOrQfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrheekgdegudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeen ucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvg hvqeenucggtffrrghtthgvrhhnpeetudeljeegheetgfehgeejkeeuhedvveeikeeufedt vddtveefhfdvveegudejheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegumhhithhrhiesghhuthhovhdruggvvhdpnhgspghrtghpthhtohep vddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmhhonhhnihgvrhesihhrohdruh hmohhnthhrvggrlhdrtggrpdhrtghpthhtohepvghmrggtshdquggvvhgvlhesghhnuhdr ohhrgh X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 1 Dec 2024 21:04:52 -0500 (EST) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=103.168.172.155; envelope-from=dmitry@gutov.dev; helo=fhigh-a4-smtp.messagingengine.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_SBL_A=0.1 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:325933 Archived-At: On 30/11/2024 20:49, Stefan Monnier wrote: >>> 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)) >> >> That sounds interesting, especially the 'guess-regexp' part. I think >> it would make it ineligible for calling from the init script, though, >> which could be a preference for many. > > It's definitely meant for interactive use, yes. Sounds good. > For the init file, we have things like > > (add-to-list 'major-mode-remap-alist '(foo-mode . bar-mode)) > > so I don't see any need for anything new. We might need to solve this for go-ts-mode and etc having no "original" to remap from, though. Maybe just using your FIXME (adding auto-mode-alist entry for 'go-mode'). >>> `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)) >> >> TBF one of my goals for the later patches was to avoid adding new public >> "registry" variables, like treesit-auto-mode-alist, >> treesit-major-mode-remap-alist, treesit-interpreter-mode-alist, etc. It > > In my mind, `treesit--mode-associations` is just a helper variable for > the UI, to let modes register themselves as a possible good choice for > specific languages, so the UI can provide nice defaults and/or completion. > It should not change the behavior of Emacs in any significant way. >>> and its name should not be treesitter-specific either, then. >> ...But perhaps you have a more general purpose in mind for them. > > cperl-mode/perl-mode, latex-mode/LaTeX-mode, c-mode/sm-c-mode, > caml-mode/tuareg-mode, ... So like major-mode-remap-alternatives? If the goal were just to "tag" major mode name symbols, we could delegate that to define-derived-mode and loaddefs-generate--make-autoload. But that couldn't mention the "from" modes, I guess. >>> We could also have a command `treesit-enable-all-modes` 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. >> It seemed to me that users might first choose the modes/languages they want, >> and then be told (sometimes with warnings) which grammars are still missing >> or cannot be found by Emacs somehow. But there can be different ways of >> looking at it. > > I'd imagine `treesit-enable-all-modes` could emit a warning about > modes lacking a grammar when used interactively, and offer (maybe with > a C-u prefix) to install the grammars? Sounds reasonable. I was thinking it would be more economical to defer the checking of grammars until a mode is actually used (so you can enable them all wholesale, and then gradually install needed grammars), but that's not critical. Pros and cons either way. Also, there as a request to exclude some modes from the "enable all" action, too. I took that to mean that we need a user option.