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: Stefan Monnier
Subject: Re: Turning on/off tree-sitter modes
Date: Fri, 29 Nov 2024 13:09:10 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> Here are the issues that are currently not handled by your patch,
> which perhaps require modifications and additions (but should probably
> be discussed first):
>
>   . we need the ability to turn on and off selected TS-based modes,
>     and do it easily
>   . we should include in this feature handling of all the TS-based
>     modes in core (right now, I don't see python-ts-mode,
>     ruby-ts-mode, and csharp-ts-mode, at least)
>   . we should decide how to handle TS-based modes whose non-TS
>     counterparts are available as 3rd-party packages
>   . we should decide whether we want to modify auto-mode-alist or use
>     major-mode remapping for all the TS-based modes

I remember writing a description of the UI I had in mind but can't find
it again, so maybe I failed/forgot to send it?

In any case I was thinking of a UI that's not specific to tree-sitter
that works as follows:

   (defun change-major-mode (newmode)
     (interactive (list (read-the-new-mode)))
     (cond
      ((eq major-mode (the-mode-normally-selected-by-auto-mode-alist))
       (setf (alist-get major-mode major-mode-remap-alist) newmode)
       (when (called-interactively-p)
         (customize-mark-as-set 'major-mode-remap-alist)))
      (t
       (let ((regexp (guess-regexp buffer-file-name)))
         (add-to-list 'auto-mode-alist (cons regexp newmode))
         (when (called-interactively-p)
           ...somehow convince Custom to do the above `add-to-list`...))))
     (funcall newmode))


`read-the-new-mode` could use a variable like Dmitry's
`treesit--mode-associations` to provide good defaults.

BTW, this var shouldn't be set like in his patch, IMO but via

    ###;;;autoload
    (add-to-list 'treesit--mode-associations (javascript-mode . js-ts-mode))

  and its name should not be treesitter-specific either, then.

We could also have a command `treesit-enable-all-mode` which uses
a variable `treesit-mode-grammars` (an alist mapping modes to grammars,
setup via the same kind of autoload+add-to-list as above), to add to
`major-mode-remap-alist` all the TS modes for which the user has
installed the corresponding grammar.


        Stefan




reply via email to

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