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: Stefan Monnier
Subject: Re: Average-user-facing interface for tree-sitter
Date: Fri, 14 Oct 2022 23:26:46 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> (add-hook 'xxx-mode-hook
>           (lambda () (when (eq major-mode 'xxx-mode)
>                        (treesit-mode))))
>
> Which again is a bit awkward.

Awkward but possible.  Another approach can be:

    (add-hook 'xxx-mode-hook #'treesit-mode)
    (add-hook 'yyy-mode-hook (lambda () (treesit-mode -1)))

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

Because it needs to be able to say "for this mode and all its derived
modes" but also "for this mode only" as well as various combinations,
and then you need to document how it interacts with the major mode's
hook, ...

Maybe we should devise a way to "centrally" control the value of some
vars depending on major modes, but if so we should carefully design
a thing specifically for that, make sure it's sufficiently flexible, and
then use it for several (any?) variable.

All the vars I've seen so far which do that do it quite naively, which
works OK for simple cases but breaks down one way or another when you
start taking derived modes into account.  Hence my considering it a code
smell (just like most uses of the `major-mode` variable).


        Stefan




reply via email to

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