From d24a1c63d4057e858d47e4594c8899cbf1536121 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sat, 20 Nov 2021 22:31:22 +0100
Subject: [PATCH] Make disable accept a function
Replaces the condition setting (though it does the exact inverse)
---
doc/nvim-treesitter.txt | 25 +++++++++++++++++++------
lua/nvim-treesitter/configs.lua | 25 +++++++++++++++----------
2 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index 9cc975ed2..d0f204146 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -74,14 +74,9 @@ Each module corresponds to an entry in the dictionary passed to the
EOF
<
-All modules share some common options, like `enable`, `disable`, and
-`condition`.
+All modules share some common options, like `enable` and `disable`.
When `enable` is `true` this will enable the module for all supported languages,
if you want to disable the module for some languages you can pass a list to the `disable` option.
-For more fine-grained control, `condition` takes a function and whenever it returns
-`false` the module is disabled for that buffer.
-The `condition` function is called once when a module starts in a buffer and
-received the language and the buffer number as arguments.
>
lua <
+ lua < 50000
+ end,
+ },
+ }
+ EOF
+<
+
Options that define or accept a keymap use the same format you use to define
keymaps in Neovim, so you can write keymaps as `gd`, `a`, `a`
`` (control + a), `` (alt + n), `` (enter), etc.
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index 9f563af59..3da54fd7e 100644
--- a/lua/nvim-treesitter/configs.lua
+++ b/lua/nvim-treesitter/configs.lua
@@ -23,15 +23,16 @@ local builtin_modules = {
highlight = {
module_path = "nvim-treesitter.highlight",
enable = false,
- disable = { "markdown" }, -- FIXME(vigoux): markdown highlighting breaks everything for now
custom_captures = {},
- is_supported = queries.has_highlights,
+ is_supported = function(lang)
+ -- FIXME(vigoux): markdown highlighting breaks everything for now
+ return lang ~= "markdown" and queries.has_highlights(lang)
+ end,
additional_vim_regex_highlighting = false,
},
incremental_selection = {
module_path = "nvim-treesitter.incremental_selection",
enable = false,
- disable = {},
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
@@ -45,7 +46,6 @@ local builtin_modules = {
indent = {
module_path = "nvim-treesitter.indent",
enable = false,
- disable = {},
is_supported = queries.has_indents,
},
}
@@ -351,16 +351,21 @@ function M.is_enabled(mod, lang, bufnr)
return false
end
- if module_config.condition and not module_config.condition(lang, bufnr) then
- return false
- end
-
- for _, parser in pairs(module_config.disable) do
- if lang == parser then
+ local disable = module_config.disable
+ if type(disable) == 'function' then
+ if disable(lang, bufnr) then
return false
end
+ elseif type(disable) == 'table' then
+ -- Otherwise it's a list of languages
+ for _, parser in pairs(disable) do
+ if lang == parser then
+ return false
+ end
+ end
end
+
return true
end