emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Turning on/off tree-sitter modes


From: Eli Zaretskii
Subject: Re: Turning on/off tree-sitter modes
Date: Wed, 04 Dec 2024 14:56:16 +0200

> Date: Wed, 4 Dec 2024 03:47:00 +0200
> Cc: emacs-devel@gnu.org
> From: Dmitry Gutov <dmitry@gutov.dev>
> 
> On 03/12/2024 16:55, Stefan Monnier wrote:
> > +;;;###autoload (add-to-list 'major-mode-remap-defaults
> > +;;;###autoload              '(cmake-mode . cmake-ts-mode-maybe))
> > +
> > +;;;###autoload
> > +(defun cmake-ts-mode-maybe ()
> > +  "Enable `cmake-ts-mode' if available."
> > +  (cond
> > +   ((treesit-ready-p 'cmake) (cmake-ts-mode))
> > +   ((fboundp 'cmake-mode) (cmake-mode))
> > +   (t (fundamental-mode))))
> 
> Should we do this switch if the grammar is not available? We could stay 
> with the tree-sitter mode if it doesn't anything bad.
> 
> Take for example rust-ts-mode, or dockerfile-ts-mode: the body of the 
> major mode function is wrapped in
> 
>    (when (treesit-ready-p 'dockerfile)
>       ...
>      )
> 
> which checks for the grammar, emits the warning and does nothing 
> otherwise. So dockerfile-ts-mode behaves like prog-mode in this case, 
> even highlighting strings using the default syntax table.

That's another possibility, indeed.  Its downside is that each mode
author will need to include this boilerplate code.

I'd prefer to have a general solution for this, which would leave most
of the boilerplate code to some central place, like normal-mode, with
only the minimum requirements from the mode itself.  If that is
reasonable and practical.



reply via email to

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