emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Average-user-facing interface for tree-sitter


From: Yuan Fu
Subject: Re: Average-user-facing interface for tree-sitter
Date: Thu, 13 Oct 2022 12:44:01 -0700


> On Oct 12, 2022, at 11:22 PM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> 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.

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]