Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

enable for only a single language or list of languages #30

Closed
akinsho opened this issue Apr 20, 2021 · 12 comments
Closed

enable for only a single language or list of languages #30

akinsho opened this issue Apr 20, 2021 · 12 comments

Comments

@akinsho
Copy link

akinsho commented Apr 20, 2021

Hi 👋🏿 thanks for your work on this plugin.

I've just moved over from luochen1990's plugin and I'm wondering if it's possible to enable this plugin for only a few filetypes primarily since there are only a few languages I use that tend to get a little unmanageable with their parens (e.g. lisps) but for things like lua I don't really need this functionality.

@p00f
Copy link
Owner

p00f commented Apr 21, 2021 via email

@akinsho
Copy link
Author

akinsho commented Apr 21, 2021

@p00f I just tried setting enable = {"dart"} as an example but that doesn't work lua still shows rainbow parentheses 🤔 the README says the key is enable not enabled but I tried using enabled and that just turns the plugin off completely

@p00f
Copy link
Owner

p00f commented Apr 21, 2021

It is enable indeed. Also, sorry but there's only enable = true and disable = list of languages

https://github.com/nvim-treesitter/nvim-treesitter#modules

@akinsho
Copy link
Author

akinsho commented Apr 21, 2021

@p00f thanks that works, shame it works in that order since to only enable it for a few languages I'd end up having to list all available languages except the one I want 😅 . Anyway thanks for the help.

@akinsho akinsho closed this as completed Apr 21, 2021
@ahmedelgabri
Copy link

I came here for the same exact request as @akinsho, it will be great @p00f if there is a way to enable the plugin only for some langauges.

@p00f
Copy link
Owner

p00f commented May 30, 2021

I don't want to implement this on the module side, can you open an issue on the main nvim-treesitter repo and see? If they don't want to then I'll try doing it

@ahmedelgabri

@ahmedelgabri
Copy link

I don't want to implement this on the module side, can you open an issue on the main nvim-treesitter repo and see? If they don't want to then I'll try doing it

@ahmedelgabri

Unless I'm missing something why is it needed to be added to treesitter? I actually don't see that useful on the treesitter side but I see it useful here, the reason is I might want treesitter support for more languages than I'd like rainbow parentheses support. Technically I want support for treesitter for everything, but rainbow parentheses support only for lisp like languages.

@p00f
Copy link
Owner

p00f commented May 30, 2021

This is an not a standalone plugin but an nvim-treesitter module generated from the module template given by nvim-treesitter:

image

Enabling and disabling is controlled by the main nvim-treesitter plugin:
https://github.com/nvim-treesitter/nvim-treesitter#modules

https://github.com/nvim-treesitter/nvim-treesitter/blob/972f70956ac8635ab2f6d7ed0b24e5cd159d7a04/doc/nvim-treesitter.txt#L58

If they implement this on their side then you can do it to any module given here

https://github.com/nvim-treesitter/nvim-treesitter/wiki/Extra-modules-and-plugins#extra-modules

note that 3 out of the 6 modules mentioned there are outside the nvim-treesitter organization

@ahmedelgabri
Copy link

I think I found a way around this limitation without maintaining a full table of disabled languages.

local parsers = require("nvim-treesitter.parsers")

rainbow = {
  enable = true,
  -- Enable only for lisp like languages
  disable = vim.tbl_filter(
    function(p)
      return p ~= "clojure" and p ~= "commonlisp" and p ~= "fennel" and p ~= "query"
    end,
    parsers.available_parsers()
  )
},

@p00f
Copy link
Owner

p00f commented May 30, 2021

Neat! If that list grows larger you can use

local enabled_list = {"clojure", "fennel", "commonlisp", "query", ...}
rainbow = {
  enable = true,
  -- Enable only for lisp like languages
  disable = vim.tbl_filter(
    function(p)
        local disable = true
        for _, lang in pairs(enabled_list) do
          if p==lang then disable = false end
        end
        return disable
    end,
    parsers.available_parsers()
  )
},

@illia-danko
Copy link

Should be a part of the documentation imho.

@oblitum
Copy link

oblitum commented Feb 7, 2022

It would be nice if enable could either be true or a list of languages. The vim.tbl_filter snippet isn't hmm... ergonomic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants