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: Fri, 14 Oct 2022 13:19:45 -0700


> On Oct 14, 2022, at 4:02 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> 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.
> 
> Yup.

Thinking more about it, there are some problems need to be resolved:
- when does xxx-mode.el set treesit-major-mode-remap-alist? Require-time? That’ 
seems too late: M-x xxx-mode (autoloader) -> (require ‘xxx-mode) -> added to 
treesit-major-mode-remap-alist -> ?
- If global-treesit-mode is already on, changing treesit-major-mode-remap-alist 
doesn’t do anything, you need to toggle global-treesit-mode for it to take 
effect.

> 
>> treesit-toggle-function: A function treesit-mode calls to enable
>> tree-sitter support, major modes set this function.
> 
> Hm...  I'm not sure.  A mode like python-mode which has both treesit and
> non-treesit code paths would just be
> 
>  (if treesit-mode
>      (do-one-thing)
>    (do-the-old-thing))
> 
> I think?  On the other hand, that wouldn't allow dynamic switching
> between treesit and non, so perhaps we should have something like that;
> yes.

As I said in the previous message, setting treesit-mode locally in major mode 
hook doesn’t do anything, because the hook runs after all the setup.

> 
>> 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.
> 
> Hm...

Emm…

Yuan




reply via email to

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