From: Yuan Fu <casouri@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi@gnus.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: Average-user-facing interface for tree-sitter
Date: Wed, 19 Oct 2022 17:23:10 -0700 [thread overview]
Message-ID: <F387BC11-FD63-417B-94EF-3EC83ADAD7AF@gmail.com> (raw)
In-Reply-To: <jwvlepc7cm3.fsf-monnier+emacs@gnu.org>
> 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
next prev parent reply other threads:[~2022-10-20 0:23 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 6:11 Average-user-facing interface for tree-sitter Yuan Fu
2022-10-13 0:54 ` [SPAM UNSURE] " Stephen Leake
2022-10-13 6:32 ` Stephen Leake
2022-10-13 6:22 ` Lars Ingebrigtsen
2022-10-13 9:18 ` Robert Pluim
2022-10-13 9:21 ` Lars Ingebrigtsen
2022-10-13 9:32 ` Po Lu
2022-10-13 9:42 ` Robert Pluim
2022-10-13 12:31 ` Stefan Kangas
2022-10-13 9:57 ` Daniel Martín
2022-10-13 10:01 ` [SPAM UNSURE] " Stephen Leake
2022-10-13 14:32 ` Jostein Kjønigsen
2022-10-13 16:14 ` Eli Zaretskii
2022-10-13 17:27 ` Lars Ingebrigtsen
2022-10-13 19:44 ` Yuan Fu
2022-10-14 11:02 ` Lars Ingebrigtsen
2022-10-14 11:22 ` Stephen Leake
2022-10-14 20:10 ` Yuan Fu
2022-10-14 20:19 ` Yuan Fu
2022-10-14 20:49 ` Stefan Monnier
2022-10-14 22:51 ` Yuan Fu
2022-10-15 3:26 ` Stefan Monnier
2022-10-15 5:05 ` Yuan Fu
2022-10-17 9:07 ` Yuan Fu
2022-10-17 9:15 ` Lars Ingebrigtsen
2022-10-18 20:54 ` Yuan Fu
2022-10-18 21:48 ` Stefan Monnier
2022-10-18 22:06 ` Yuan Fu
2022-10-18 22:31 ` Stefan Monnier
2022-10-18 23:06 ` Yuan Fu
2022-10-19 2:52 ` Stefan Monnier
2022-10-19 3:48 ` [External] : " Drew Adams
2022-10-20 0:23 ` Yuan Fu [this message]
2022-10-19 5:35 ` Theodor Thornhill
2022-10-20 0:28 ` Yuan Fu
2022-10-20 7:44 ` Theodor Thornhill
2022-10-20 17:53 ` Stefan Monnier
2022-10-20 18:10 ` Theodor Thornhill
2022-10-20 18:11 ` Theodor Thornhill
2022-10-20 23:06 ` Yuan Fu
2022-10-21 22:10 ` Yuan Fu
2022-10-21 22:35 ` Stefan Monnier
2022-10-23 1:59 ` Fu Yuan
2022-10-23 4:59 ` Theodor Thornhill
2022-10-24 12:57 ` Stefan Monnier
2022-10-24 17:14 ` Stephen Leake
2022-10-24 21:07 ` Stefan Monnier
2022-10-24 20:51 ` Yuan Fu
2022-10-24 23:55 ` Stefan Monnier
2022-10-25 21:37 ` Yuan Fu
2022-10-25 22:49 ` Stefan Monnier
2022-10-27 1:56 ` Yuan Fu
2022-10-27 15:21 ` Stefan Monnier
2022-10-27 15:29 ` Dmitry Gutov
2022-10-28 8:02 ` Yuan Fu
2022-10-24 16:46 ` Stephen Leake
2022-10-18 20:49 ` Stefan Monnier
2022-10-18 20:58 ` Yuan Fu
2022-10-13 13:05 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2022-10-15 9:49 Payas Relekar
2022-10-16 11:03 ` Katevan Lomidze
2022-10-16 11:43 ` Eli Zaretskii
2022-10-15 13:03 Ketevan Lomidze
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=F387BC11-FD63-417B-94EF-3EC83ADAD7AF@gmail.com \
--to=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=larsi@gnus.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.