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: Tue, 18 Oct 2022 16:06:13 -0700


> On Oct 18, 2022, at 3:31 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>>> Too much magic, IMO.  Let each case handle it manually, since I suspect
>>> that every case will be different and the best thing to do will vary (it
>>> depends on whether the two modes are still actively maintained, whether
>>> by the same authors or not, the relative age and popularity of the
>>> respective modes, …)
>> 
>> So we don’t do anything in global-treesit-mode? Ie,
>> 
>> (define-globalized-minor-mode global-treesit-mode treesit-mode
>>  global-treesit-mode--turn-on
>>  :version "29.1"
>>  :group 'treesit
>>  :predicate t
>>  (when (not global-treesit-mode)
>>    (dolist (map treesit-remapped-major-mode-alist)
>>      (setq major-mode-remap-alist
>>            (remove map major-mode-remap-alist)))))
>> 
>> to
>> 
>> (define-globalized-minor-mode global-treesit-mode treesit-mode
>>  global-treesit-mode--turn-on
>>  :version "29.1"
>>  :group 'treesit
>>  :predicate t
>>  )
>> 
>> And remove treesit-remapped-major-mode-alist?
> 
> That's I'd do, yes.
> 
> It's much easier to add features later (if they prove to satisfy
> a common need) than to remove unused features.
> 
> 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.

> 
> 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. The idea is that if 
a user actively tries to turn on treesit-mode (by M-x treesit-mode), they 
should know if it didn’t work, but if they just turns on global-treesit-mode, 
they shouldn’t be bothered with warnings-in-the-face. And if one wants to know 
if tree-sitter is working for a buffer, they can use M-x treesit-mode to get a 
clear answer.

Yuan


reply via email to

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