[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Turning on/off tree-sitter modes
From: |
Stefan Monnier |
Subject: |
Re: Turning on/off tree-sitter modes |
Date: |
Sun, 01 Dec 2024 21:58:37 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
>> For the init file, we have things like
>> (add-to-list 'major-mode-remap-alist '(foo-mode . bar-mode))
>> so I don't see any need for anything new.
> We might need to solve this for go-ts-mode and etc having no "original" to
> remap from, though.
I think we first need to think about what it is the user needs to do
there and what Emacs should do. AFAICT with our current code,
emacs -Q foo.go
will never open that mode is the intended mode even if the Go grammar is
installed, so I think we should first fix that and only once that fixed
we can start thinking about what the user may want to do to choose
a specific mode.
>>>> and its name should not be treesitter-specific either, then.
>>> ...But perhaps you have a more general purpose in mind for them.
>> cperl-mode/perl-mode, latex-mode/LaTeX-mode, c-mode/sm-c-mode,
>> caml-mode/tuareg-mode, ...
> So like major-mode-remap-alternatives?
Yes, I like that suggestion.
>> I'd imagine `treesit-enable-all-modes` could emit a warning about
>> modes lacking a grammar when used interactively, and offer (maybe with
>> a C-u prefix) to install the grammars?
> Sounds reasonable. I was thinking it would be more economical to defer the
> checking of grammars until a mode is actually used (so you can enable them
> all wholesale, and then gradually install needed grammars), but that's not
> critical. Pros and cons either way.
Oh, indeed, we could also use `major-mode-remap-alist` to remap all
modes which have TS alternative to a function which checks if the
grammar is installed and then either calls the "normal" mode or the
TS-alternative.
> Also, there was a request to exclude some modes from the "enable all" action,
> too. I took that to mean that we need a user option.
I suspect in 99% of the cases, this can be done by refraining from
installing the grammar. And even if not, I can't see why we'd need
a new user option. Appropriate entries in `major-mode-remap-alist` seem
sufficient to register that kind of user choice.
AFAICT all we need is two or three functions/commands to cover those
common configuration needs, but they're just functions/commands, so we
could just as well provide 50 of them.
`major-mode-remap-alternatives` seems good for `change-major-mode` but
`treesit-enable-all-modes` would inevitably be TS-specific and would
need some info about "TS modes out there" as well as some mapping
between modes and their corresponding grammar, and that doesn't fit into
the remit of `major-mode-remap-alternatives`.
Stefan
- Re: Turning on/off tree-sitter modes, Dmitry Gutov, 2024/12/01
- Re: Turning on/off tree-sitter modes,
Stefan Monnier <=
- Re: Turning on/off tree-sitter modes, Eli Zaretskii, 2024/12/02
- Re: Turning on/off tree-sitter modes, Stefan Monnier, 2024/12/02
- Re: Turning on/off tree-sitter modes, Eli Zaretskii, 2024/12/03
- Re: Turning on/off tree-sitter modes, Stefan Monnier, 2024/12/03
- Re: Turning on/off tree-sitter modes, Eli Zaretskii, 2024/12/03
- Re: Turning on/off tree-sitter modes, Stefan Monnier, 2024/12/03
- Re: Turning on/off tree-sitter modes, Eli Zaretskii, 2024/12/03
- Re: Turning on/off tree-sitter modes, Stefan Monnier, 2024/12/03
- Re: Turning on/off tree-sitter modes, Eli Zaretskii, 2024/12/03