renzmann / treesit-auto

Automatic installation, usage, and fallback for tree-sitter major modes in Emacs 29
GNU General Public License v3.0
369 stars 28 forks source link

Provide an easy way to exclude languages from using tree sitter enabled modes #35

Closed ktetzlaff closed 9 months ago

ktetzlaff commented 1 year ago

While experimenting with treesit-auto, I found it rather difficult to use tree sitter enabled modes for some/most languages and use non-tree-sitter modes for a few selected modes (like e.g. c/c++-mode).

While it is great that treesit-auto provides an easy way to use treesit enabled modes, there doesn't seem to be an easy way to exclude certain languages from having the tree sitter support enabled automatically in major-mode-remap-alist.

There are the variables treesit-auto-langs and treesit-auto-opt-out-list. But both only seem to influence treesit-auto-install-all and thus do not inhibit languages from getting added to major-mode-remap-alist.

It would be great if e.g. treesit-auto-opt-out-list would be promoted to a defcustom that actually not only stops languages from getting processed in treesit-auto-install-all but also stops opted out languages from getting added to major-mode-remap-alist.

And by providing a real exclude option, treesit-auto-langs would probably not be needed anymore because it does not provide a way to add languages, but seems to be a more elaborate way to exclude languages (where, if you want to have tree-sitter support by default, you first need to build a list of all supported languages and then remove the ones which you don't want).

I'd be happy to provide a pull request for that but would rather get some feedback first.

renzmann commented 1 year ago

I kept flip-flopping in my head about whether the right way was an inclusion list or exclusion list for controlling which languages do/don't get used or installed, hence the seemingly duplicitous variables. Thanks for the motivating issue that tips the scales one way over the other.

I agree with the point about how the opt-out list should work, that seems like a pretty natural way for it to operate. I guess when first writing that I just assumed that if someone didn't want to use a tree-sitter mode, they'd remove it from their .emacs.d/tree-sitter directory or treesit-extra-load-path, but those don't count when libraries are installed under an admin directory, like /usr/lib or something where the user may or may not have editing privileges.

DogLooksGood commented 1 year ago

I entercounter this issue as well. Probably it's better to use existing built-in variables instead of introducing a new one?

domq commented 1 year ago

I entercounter this issue as well. Probably it's better to use existing built-in variables instead of introducing a new one?

Concur — In fact, there is a global-treesit-auto-modes variable that define-globalized-minor-mode kind of declares by mistake, it would be nice if that variable did what it says in its doc string (AFAICT, right now it doesn't do anything at all)

renzmann commented 1 year ago

Wild, I had no idea that global-treesit-auto-modes even existed. So the idea here is that if an end user sets this variable directly, it would let them keep or remove specific modes for treesit-auto?

theasp commented 10 months ago

For anyone stuck while waiting for a proper fix, this method works for me to prevent yaml-ts-mode:

(when (require 'treesit nil t)
  (use-package treesit-auto
    :ensure t
    :demand t
    :config
    (setq treesit-auto-install t)
    (setq treesit-auto-opt-out-list '(yaml))
    (treesit-auto-install-all)
    (setq treesit-auto-install nil)
    (global-treesit-auto-mode)))

Edit: You'll also have to delete the yaml tree-sitter .so

renzmann commented 10 months ago

@ktetzlaff @theasp Feel free to try out the new feature on the treesit-auto-langs branch.

63 modifies the package so that treesit-auto-langs behaves the way you describe in the OP; basically treesit-auto will be completely disabled for anything not present in this list.

(package-vc-install "https://github.com/renzmann/treesit-auto" "treesit-auto-langs")

I'm going to putz and test it a bit over the next day or two before merging in.