[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: |
Wed, 19 Oct 2022 17:23:10 -0700 |
> On Oct 18, 2022, at 7:52 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>>> BTW, I see that `global-treesit-mode--turn-on` is currently a (non
>>> official) alias of `treesit-mode`, but I think it should only call
>>> `treesit-mode` in those buffers where there is some indication that the
>>> major mode provides some treesit-mode support (e.g., currently that
>>> could be if `major-mode-backend-function` is set).
>>
>> I’m changing it to what you described in another email. (So
>> major-mode-backend-function is goner). I can use treesit-font-lock-settings
>> as the minimum criterion.
Ends up using treesit-mode-supported.
>>
>>>
>>> And then maybe `treesit-mode` should signal an error (and turn itself
>>> off) if it's enabled in a buffer whose major mode does not provide any
>>> support for `treesit-mode`.
>>
>> So currently treesit-mode signals a warning if it can’t activate tree-sitter
>> and (eq this-command ’treesit-mode), but if it is called in find-file-hook,
>> etc set up by global-treesit-mode, it doesn’t signal a warning.
>
> That's why define-globalized-minor-mode has a TURN-ON function
> argument separately from the MODE argument: the TURN-ON function has
> to determine whether to enable the minor mode or not. It shouldn't
> blindly call `treesit-mode` but first check whether `treesit-mode`
> is applicable.
>
> This way, `treesit-mode` can always signal an error when called in
> a buffer where it's not applicable: it's always the responsibility of
> the caller to check beforehand.
Ok, I pushed the new system. Now major modes sets a range of tree-sitter
specific variables, and treesit-mode takes care of activating them. For
example, python-mode sets these:
(setq-local treesit-mode-supported t)
(setq-local treesit-required-languages '(python))
(setq-local treesit-font-lock-feature-list
'((basic) (moderate) (elaborate)))
(setq-local treesit-font-lock-settings python--treesit-settings)
(setq-local treesit-imenu-function
#'python-imenu-treesit-create-index)
Js-mode sets these:
(setq-local treesit-mode-supported t)
(setq-local treesit-required-languages '(javascript))
(setq-local treesit-simple-indent-rules js--treesit-indent-rules)
(setq-local treesit-defun-type-regexp
(rx (or "class_declaration"
"method_definition"
"function_declaration"
"lexical_declaration")))
(setq-local treesit-font-lock-settings js--treesit-font-lock-settings)
(setq-local treesit-font-lock-feature-list '((minimal) (moderate) (full)))
treesit-mode-supported could seem a bit redundant, but no harm in being
explicit I guess?
Now global-treesit-mode never signals warning, and treesit-mode always signals
warning, when treesit can’t activate in a buffer.
Yuan
- Re: Average-user-facing interface for tree-sitter, (continued)
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/15
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/17
- Re: Average-user-facing interface for tree-sitter, Lars Ingebrigtsen, 2022/10/17
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/18
- Re: Average-user-facing interface for tree-sitter, Stefan Monnier, 2022/10/18
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/18
- Re: Average-user-facing interface for tree-sitter, Stefan Monnier, 2022/10/18
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/18
- Re: Average-user-facing interface for tree-sitter, Stefan Monnier, 2022/10/18
- RE: [External] : Re: Average-user-facing interface for tree-sitter, Drew Adams, 2022/10/18
- Re: Average-user-facing interface for tree-sitter,
Yuan Fu <=
- Re: Average-user-facing interface for tree-sitter, Theodor Thornhill, 2022/10/19
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/19
- Re: Average-user-facing interface for tree-sitter, Theodor Thornhill, 2022/10/20
- Re: Average-user-facing interface for tree-sitter, Stefan Monnier, 2022/10/20
- Re: Average-user-facing interface for tree-sitter, Theodor Thornhill, 2022/10/20
- Re: Average-user-facing interface for tree-sitter, Theodor Thornhill, 2022/10/20
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/20
- Re: Average-user-facing interface for tree-sitter, Yuan Fu, 2022/10/21
- Re: Average-user-facing interface for tree-sitter, Stefan Monnier, 2022/10/21
- Re: Average-user-facing interface for tree-sitter, Fu Yuan, 2022/10/22