From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Unifying "foo-mode"s and "foo-ts-mode"s Date: Fri, 30 Dec 2022 17:02:14 +0200 Message-ID: <83zgb55409.fsf@gnu.org> References: <877cyagmti.fsf@posteo.net> <831qoi85u7.fsf@gnu.org> <87mt76f4n4.fsf@posteo.net> <83sfgy6l0n.fsf@gnu.org> <877cy9b1k0.fsf_-_@posteo.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4028"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, casouri@gmail.com To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 30 16:02:43 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 1pBGuB-0000qx-Tw for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Dec 2022 16:02:43 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBGtp-0003pN-HA; Fri, 30 Dec 2022 10:02:22 -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 1pBGtl-0003os-MA for emacs-devel@gnu.org; Fri, 30 Dec 2022 10:02:19 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBGtk-0001Rb-Jk; Fri, 30 Dec 2022 10:02:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=y2FBJpnrouH3kOL5IFWP6CdkHei33sqUGhh/Ixtz6xc=; b=NB3FapMth56K Pfqv5SVdM2UFpvC9mmfwGyX2y9NobomVv5z+KSDjIuaOboAymB/SgTYsGAENSvCs87guNgjM6+piJ GY9/N0QXwcJvumOWFcvpBmI6GqQhN1SQ8JEN9/KsdQuC52rHT7IKGkhgyvpJUHDm2LdI+aPGHP9e2 M10ekN6CxdoQyVpkhIxJXSXYhWclpEs56j5MNnZSZfuDOv2JZk5t4qExn0Aeyw4pIJZcBixQtwK2q Li6zohxxAOED2ILyrS9BC0XatowOfQC1gwhhoJqM5nznjW/KAZaa5qdxL+Ovz+akDAYAqSx1bIcxR oykbIobZdO/EWS7hJRdtlQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBGtk-0000BB-3I; Fri, 30 Dec 2022 10:02:16 -0500 In-Reply-To: <877cy9b1k0.fsf_-_@posteo.net> (message from Philip Kaludercic on Fri, 30 Dec 2022 10:58:39 +0000) 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:302110 Archived-At: > From: Philip Kaludercic > Cc: emacs-devel@gnu.org, Yuan Fu > Date: Fri, 30 Dec 2022 10:58:39 +0000 > > I have attached a sketch of my proposal with support for Python. > Instead of a separate python-ts-mode, we regulate tree-sitter support > using a user option `treesit-enabled-modes'. It can either be a list > > --8<---------------cut here---------------start------------->8--- > (setq treesit-enabled-modes '(python-mode c-mode)) > --8<---------------cut here---------------end--------------->8--- > > or generally enable tree-sitter > > --8<---------------cut here---------------start------------->8--- > (setq treesit-enabled-modes t) > --8<---------------cut here---------------end--------------->8--- I think we want to let the users say, for every single mode, whether they want to use the treesit-enabled variant or not, and also to be able to go back to the non-treesit mode later in the session (e.g., if they don't like the results). A list is not a convenient means for doing so. > > All a major modes has to do is pass a parser configuration > > --8<---------------cut here---------------start------------->8--- > (define-derived-mode python-mode prog-mode "Python" > "Major mode for editing Python files. > > \\{python-mode-map}" > :syntax-table python-mode-syntax-table > :parser-conf python-mode--treesit-conf > ... > --8<---------------cut here---------------end--------------->8--- > > that expands to > > --8<---------------cut here---------------start------------->8--- > (when-let > ((conf python-mode--treesit-conf) > ((cond > ((listp treesit-enabled-modes) > (memq 'python-mode treesit-enabled-modes)) > ((eq treesit-enabled-modes t)))) > ((treesit-ready-p > (nth 0 conf))) > (parser > (treesit-parser-create > (nth 0 conf)))) > (setq-local treesit-font-lock-feature-list > (nth 1 conf) > treesit-font-lock-settings > (nth 2 conf) > treesit-defun-name-function > (nth 3 conf) > treesit-defun-type-regexp > (nth 4 conf) > imenu-create-index-function > (nth 5 conf)) > (treesit-major-mode-setup)) > --8<---------------cut here---------------end--------------->8--- > > at *the end* of the major mode definition. Note that if no parser > configuration was parsed, the entire expression is byte-compiled away, > so there is no run-time overhead for other modes. What does this mean in user-facing behavior? Does it mean that if tree-sitter is not available, or the Python grammar fails to load for some reason, Emacs will silently fall back to the "traditional" python-mode? If so, I don't think this is what we want. The failure for loading tree-sitter support should not be silent. These are exactly the aspects of the behavior we discussed a month ago, and what we have now is the result of those discussions.