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 15:51:15 -0700


> On Oct 14, 2022, at 1:49 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>> I wonder if we can have a major mode hook that runs before the body runs,
>> like xxx-mode-before-hook.
> 
> Given the way things are currently setup, it's not really feasible in
> a clean and reliable way, no.
> 
> What we have instead is:
> - the `:after-hook`, i.e. part of the major-mode's
>  code that is run after the major-mode hook.
> - The `hack-local-variables-hook` which the major-mode can set
>  buffer-locally.  It's similar to the `after-hook:`, except it's run
>  after setting the file-local variables, so it's more often what
>  we want.
> 

I dunno, it literally has “hack” in its name. If we can’t do before-hook, maybe 
its best to let major mode setup normally and locally bind 
treesit-enable-function, which treesit-mode calls should user add it to major 
mode hook.

And if a user wants more control (eg, use tree-sitter for indent only), he/she 
assigns the tree-sitter function to indent-line-function, etc. No hand-holding 
from us.

Buuut, if a user wants tree-sitter for parent mode but not derived mode, they 
need to write

(add-hook 'xxx-mode-hook
          (lambda () (when (eq major-mode 'xxx-mode)
                       (treesit-mode))))

Which again is a bit awkward.

So maybe a central variable isn’t that bad an idea. Could you layout why 
mapping modes to some information is bad? Can we fix it somehow?

Yuan


reply via email to

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