all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Jostein Kjønigsen" <jostein@secure.kjonigsen.net>
To: Lars Ingebrigtsen <larsi@gnus.org>, Yuan Fu <casouri@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Average-user-facing interface for tree-sitter
Date: Thu, 13 Oct 2022 16:32:37 +0200	[thread overview]
Message-ID: <da5ee667-11b0-2daa-912e-51fcbd2d4e33@secure.kjonigsen.net> (raw)
In-Reply-To: <87ilko9r9e.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 4669 bytes --]


> Yuan Fu<casouri@gmail.com>  writes:
>
>>  From the suggestions I collected from the old thread, here is my proposal:
>>
>> 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:
>>
>> (defcustom treesit-settings '((t nil nil))
>>    "Tree-sitter toggles for major modes.
> Hm...  well, there's also modes that are "pure treesit", and there are
> (or will be) alternate modes with and without tree-sitter.
>
> 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.)
>
> This suggests to me that we should just use the normal minor mode
> machinery that we have for these things.
>
> That is, people that want treesit in python-mode will say:
>
> (add-hook 'python-mode 'treesit-mode)
>
> And people that want it everywhere will say:
>
> (global-treesit-mode)
>
> 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.
>
>
Hey there.

I'd like to come up with a somewhat contrarian point of view, if nothing 
else to provide a point of reference.

Right now we have a single (that is: one, 1) implementation for c-mode 
and c++-mode. They are based on cc-mode.

There's no c-mode where you enable usage of cc-mode through a 
minor-mode, nor is there a global-cc-mode toggle. And there's a really 
simple reason for that. That's because c-mode is implemented using 
cc-mode as a foundation, and there's no other implementations.

Now if we are starting to implement some new major-modes using 
treesitter as a foundation (for instance ts-mode or c#-mode), such a 
toggle for tree-sitter-mode will be equally pointless. There is no 
ts-mode without treesitter. And what should we do if people activate 
ts-mode without these bespoke minor-modes being active at the same time? 
I think it's a bit fuzzy and doesn't really sound very .. well defined.

Existing users of typescript-mode can be guided to the new 
implementation through a variety of ways, but to me the flow of 
activating typescript-mode major-mode, then treesit-minor-mode, and then 
magically switching to ts-mode makes absolutely no sense. And the 
performance of that is probably terrible too.

For those users I think a simple deprecation warning which informs about 
the new built-in ts-mode should be more than sufficient, for the users 
to clean out the old (buggy) typescript.el from their conigs.

The one place where it gets slightly complicated is for major-modes 
where one decides to have two or more canonical implementations, that is 
to add a new treesitter backend alongside the existing elisp-one.

For an established built in-mode, like c-mode, switching over night is 
probable not feasable nor desirable. So in practice you will have a few 
modes where you might have multiple backends, ideally only in a 
transitional phase, but in worst case scenario permanently.

So how can we deal with /that/ problem, where we have it, and not 
everywhere else?

I've had a similar "problem" for LSP backend for some programming 
languages. The solution I landed on there was to have a defcustom per 
language/major-mode where there were different LSP-backends which I may 
want to use.

Examples below:

- (defcustom csharp-lsp-backend) ;; 'lsp-mode 'omnisharp

- (defcustom typescript-lsp-backend) ;; 'lsp-mode 'tide

Then I in my major-mode hooks checked for which of the possible backends 
are chosen and dynamically dispatch based on that.

For major-modes ending up with multiple backends, I think this is an 
approach which scales better (supports more than 1 backend, but only 1 
at a time!), and will perform better (because it means avoiding 
triggering code for more than one single backend when activated).

It will also better support the flow if we eventually end up with a 
single backend again which then becomes the default. In that case, we 
don't need to maintain empty/obsolete minor-modes just to avoid breaking 
people's major-mode hooks. Then they will just have a defcustom setting 
which will be ignored.

Personally I think that would work much better, and support the 
transitional period we may be entering, without causing lasting "cruft" 
in the code-base we rather would not have.

Just my 2 cents.

--
Jostein



[-- Attachment #2: Type: text/html, Size: 5649 bytes --]

  parent reply	other threads:[~2022-10-13 14:32 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-12  6:11 Average-user-facing interface for tree-sitter Yuan Fu
2022-10-13  0:54 ` [SPAM UNSURE] " Stephen Leake
2022-10-13  6:32   ` Stephen Leake
2022-10-13  6:22 ` Lars Ingebrigtsen
2022-10-13  9:18   ` Robert Pluim
2022-10-13  9:21     ` Lars Ingebrigtsen
2022-10-13  9:32     ` Po Lu
2022-10-13  9:42       ` Robert Pluim
2022-10-13 12:31         ` Stefan Kangas
2022-10-13  9:57     ` Daniel Martín
2022-10-13 10:01     ` [SPAM UNSURE] " Stephen Leake
2022-10-13 14:32   ` Jostein Kjønigsen [this message]
2022-10-13 16:14     ` Eli Zaretskii
2022-10-13 17:27     ` Lars Ingebrigtsen
2022-10-13 19:44   ` Yuan Fu
2022-10-14 11:02     ` Lars Ingebrigtsen
2022-10-14 11:22       ` Stephen Leake
2022-10-14 20:10         ` Yuan Fu
2022-10-14 20:19       ` Yuan Fu
2022-10-14 20:49     ` Stefan Monnier
2022-10-14 22:51       ` Yuan Fu
2022-10-15  3:26         ` Stefan Monnier
2022-10-15  5:05           ` Yuan Fu
2022-10-17  9:07             ` Yuan Fu
2022-10-17  9:15               ` Lars Ingebrigtsen
2022-10-18 20:54                 ` Yuan Fu
2022-10-18 21:48                   ` Stefan Monnier
2022-10-18 22:06                     ` Yuan Fu
2022-10-18 22:31                       ` Stefan Monnier
2022-10-18 23:06                         ` Yuan Fu
2022-10-19  2:52                           ` Stefan Monnier
2022-10-19  3:48                             ` [External] : " Drew Adams
2022-10-20  0:23                             ` Yuan Fu
2022-10-19  5:35                           ` Theodor Thornhill
2022-10-20  0:28                             ` Yuan Fu
2022-10-20  7:44                               ` Theodor Thornhill
2022-10-20 17:53                                 ` Stefan Monnier
2022-10-20 18:10                                   ` Theodor Thornhill
2022-10-20 18:11                                     ` Theodor Thornhill
2022-10-20 23:06                                     ` Yuan Fu
2022-10-21 22:10                                       ` Yuan Fu
2022-10-21 22:35                                         ` Stefan Monnier
2022-10-23  1:59                                           ` Fu Yuan
2022-10-23  4:59                                             ` Theodor Thornhill
2022-10-24 12:57                                             ` Stefan Monnier
2022-10-24 17:14                                               ` Stephen Leake
2022-10-24 21:07                                                 ` Stefan Monnier
2022-10-24 20:51                                               ` Yuan Fu
2022-10-24 23:55                                                 ` Stefan Monnier
2022-10-25 21:37                                                   ` Yuan Fu
2022-10-25 22:49                                                     ` Stefan Monnier
2022-10-27  1:56                                                       ` Yuan Fu
2022-10-27 15:21                                                         ` Stefan Monnier
2022-10-27 15:29                                                           ` Dmitry Gutov
2022-10-28  8:02                                                             ` Yuan Fu
2022-10-24 16:46                                             ` Stephen Leake
2022-10-18 20:49             ` Stefan Monnier
2022-10-18 20:58               ` Yuan Fu
2022-10-13 13:05 ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2022-10-15  9:49 Payas Relekar
2022-10-16 11:03 ` Katevan Lomidze
2022-10-16 11:43   ` Eli Zaretskii
2022-10-15 13:03 Ketevan Lomidze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da5ee667-11b0-2daa-912e-51fcbd2d4e33@secure.kjonigsen.net \
    --to=jostein@secure.kjonigsen.net \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.