From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Average-user-facing interface for tree-sitter Date: Thu, 13 Oct 2022 12:44:01 -0700 Message-ID: <9794E2EF-4DB5-4A04-90F0-3EB51E6BE008@gmail.com> References: <3A7E7CD1-74A7-4352-9DFE-FC982EAA398E@gmail.com> <87ilko9r9e.fsf@gnus.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10053"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 13 21:44:59 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 1oj48Z-0002PU-0E for ged-emacs-devel@m.gmane-mx.org; Thu, 13 Oct 2022 21:44:59 +0200 Original-Received: from localhost ([::1]:51198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oj48X-00067E-HJ for ged-emacs-devel@m.gmane-mx.org; Thu, 13 Oct 2022 15:44:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oj47j-0005Kv-41 for emacs-devel@gnu.org; Thu, 13 Oct 2022 15:44:07 -0400 Original-Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:37526) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oj47h-0002rm-Fb for emacs-devel@gnu.org; Thu, 13 Oct 2022 15:44:06 -0400 Original-Received: by mail-pj1-x1030.google.com with SMTP id p3-20020a17090a284300b0020a85fa3ffcso5870768pjf.2 for ; Thu, 13 Oct 2022 12:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VxEs4MOhegI8eNnGruxlf52MFEpxfepB0RlsE2/NnXs=; b=EnGHYJWzJQ6LAFOiZ59Io9oLJF425eSzhBnscRd+4VqmDA16juMoYLneNY485ReOZj hgoFpnIRynksFAs7JQiaZ8yzmAO5/ijMMrxMhiHf0RnL+g/H9xikds0gqwO0c3ZwIMZX zK+u50YU4y0naxfUARX8ts2uEV6vT7Jy4vS7dUK8CoMrJWrZfslJpYv/I6qjZKsfFyj+ rJUNLjHHrbjlqbDi5B+pW6DI9vmC5yHVgYMhNpXaiALidGsQRhuvdJrzljEhfMcLqH9P APWRKHiKVi9ASHMcQtUFFa60C6X7cPNq8IzzvJFhqcx4/N+7Co7ozZgaocApp6Yei/Sn PrUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VxEs4MOhegI8eNnGruxlf52MFEpxfepB0RlsE2/NnXs=; b=KqsX3H6rHBK/lCDmmfGHxZ5N/+FSrILtLg+iWXJViGks60XzDE4Ko/DwtX1AJXMxOQ Vyi2NAvSphViLcWMeNbkrfGAyaYHU66J1LleMXVA2XBuq3tuIBCBi8BuikajVfsjFVOJ nKAbvi1wLX5xIXeJ3Hi6Tef+TqTDPPMvKO2PNen34ZNbNDbNjdQgzZHvCfMj+vNklrOf rFTq/aA4oILMiOyxpOGVMiBhm9PavGtrnlg2eUWPxfEcsFNC61I6d2S+a7/C0olycUVp h6XBG5Mzqr5CWPX1wodCjfT2UQtQoNdlEWUhx4/OTeC0mVH6eXt9ES9Dj30euHkdgg9a wfuw== X-Gm-Message-State: ACrzQf0igxAZp/HXvBW2dox2SUqS45h0THzhCdfYTuYW7uMZTpcb4dNt 5tzgoDJCbAvMzHgzV1lShVo= X-Google-Smtp-Source: AMsMyM7yQsGP1aU0oTCJ8ZD/ZPW19xrOEEr+mCoU28WnoFyI7oDHGVDzuBBd4dJimlLznbRxinBlFw== X-Received: by 2002:a17:902:bd95:b0:17a:582:4eb with SMTP id q21-20020a170902bd9500b0017a058204ebmr1394520pls.40.1665690243230; Thu, 13 Oct 2022 12:44:03 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id a12-20020aa7970c000000b00562b05c9674sm76521pfg.130.2022.10.13.12.44.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Oct 2022 12:44:02 -0700 (PDT) In-Reply-To: <87ilko9r9e.fsf@gnus.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=casouri@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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" Xref: news.gmane.io gmane.emacs.devel:297692 Archived-At: > On Oct 12, 2022, at 11:22 PM, Lars Ingebrigtsen = wrote: >=20 > Yuan Fu writes: >=20 >> =46rom the suggestions I collected from the old thread, here is my = proposal: >>=20 >> We define a custom option treesit-settings (we can discuss the name >> later), which controls whether to enable/disable tree-sitter for each >> major mode, and the default preference, like this: >>=20 >> (defcustom treesit-settings '((t nil nil)) >> "Tree-sitter toggles for major modes. >=20 > Hm... well, there's also modes that are "pure treesit", and there are > (or will be) alternate modes with and without tree-sitter. >=20 > I think users basically fall into two camps: The ones that want to = have > tree-sitter in all modes, and ones that want to enable it in specific > modes (and ones that don't want it at all). (Note Computer > Science-mandated off-by-one error.) >=20 > This suggests to me that we should just use the normal minor mode > machinery that we have for these things. >=20 > That is, people that want treesit in python-mode will say: >=20 > (add-hook 'python-mode 'treesit-mode) >=20 > And people that want it everywhere will say: >=20 > (global-treesit-mode) >=20 > This mode will, in addition to switching `treesit-mode' on everywhere, > also set up `major-mode-remap-alist', so that `typescript-mode' is > mapped to `ts-mode', and `c-mode' is mapped to `treesit-c-mode' (which > I'm sure somebody is going to write in a couple of days), etc. Ok, so to make it concrete, in addition to treesit-mode and = global-treesit-mode, we would have treesit-major-mode-remap-alist: same as major-mode-remap-alist, appended to major-mode-remap-alist when global-treesit-mode turns on. treesit-toggle-function: A function treesit-mode calls to enable tree-sitter support, major modes set this function. I have yet to come up a way to combine the minor-mode machinery with the = ability to specify backend for each feature (imenu, xref, font-lock, = etc). Maybe we can have something like feature-provider-alist: An buffer-local alist of (FEATURE . PROVIDERS), FEATURE could be indent, font-lock, imenu, xref, etc, PROVIDERS is a list of treesit, eglot, emacs, etc. But I failed to see how to integrate it with the rest. I wonder if we can have a major mode hook that runs before the body = runs, like xxx-mode-before-hook. Then user can set = feature-provider-alist in that hook. This way major modes can decide = what backend (provider) to use for each features. Yuan=