aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorpatrick96 <p.ziegler96@gmail.com>2021-11-09 18:24:35 +0100
committerStephan Seitz <stephan.seitz@fau.de>2021-11-12 19:55:04 +0100
commite3dabec4620843a55fdb03d1aeebf5edaa62107e (patch)
tree47f632f1454ee47b2f08e7660343e03e29735c46 /lua
parentPython: highlight semicolon (diff)
downloadnvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.tar
nvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.tar.gz
nvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.tar.bz2
nvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.tar.lz
nvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.tar.xz
nvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.tar.zst
nvim-treesitter-e3dabec4620843a55fdb03d1aeebf5edaa62107e.zip
Add condition function to module config
The function is called with the language and bufnr, if it returns false, the module is disabled for that buffer. This gives the user more fine-grained control over whether a module is started.
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/configs.lua11
-rw-r--r--lua/nvim-treesitter/info.lua7
2 files changed, 12 insertions, 6 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index a31d7fd79..95b6ab986 100644
--- a/lua/nvim-treesitter/configs.lua
+++ b/lua/nvim-treesitter/configs.lua
@@ -335,8 +335,9 @@ M.commands = {
}
-- @param mod: module (string)
--- @param ft: filetype (string)
-function M.is_enabled(mod, lang)
+-- @param lang: the language of the buffer (string)
+-- @param bufnr: the bufnr (number)
+function M.is_enabled(mod, lang, bufnr)
if not parsers.list[lang] or not parsers.has_parser(lang) then
return false
end
@@ -350,6 +351,10 @@ function M.is_enabled(mod, lang)
return false
end
+ if module_config.cond and not module_config.cond(lang, bufnr) then
+ return false
+ end
+
for _, parser in pairs(module_config.disable) do
if lang == parser then
return false
@@ -445,7 +450,7 @@ function M.attach_module(mod_name, bufnr, lang)
local lang = lang or parsers.get_buf_lang(bufnr)
local resolved_mod = resolve_module(mod_name)
- if resolved_mod and not attached_buffers_by_module.has(mod_name, bufnr) and M.is_enabled(mod_name, lang) then
+ if resolved_mod and not attached_buffers_by_module.has(mod_name, bufnr) and M.is_enabled(mod_name, lang, bufnr) then
attached_buffers_by_module.set(mod_name, bufnr, true)
resolved_mod.attach(bufnr, lang)
end
diff --git a/lua/nvim-treesitter/info.lua b/lua/nvim-treesitter/info.lua
index 1ba7620b9..ed5a90b8d 100644
--- a/lua/nvim-treesitter/info.lua
+++ b/lua/nvim-treesitter/info.lua
@@ -58,7 +58,7 @@ local function longest_string_length(list)
return length
end
-local function append_module_table(curbuf, parserlist, namespace, modulelist)
+local function append_module_table(curbuf, origbuf, parserlist, namespace, modulelist)
local maxlen_parser = longest_string_length(parserlist)
table.sort(modulelist)
@@ -77,7 +77,7 @@ local function append_module_table(curbuf, parserlist, namespace, modulelist)
for _, module in pairs(modulelist) do
local modlen = #module
module = namespace_prefix .. module
- if configs.is_enabled(module, parser) then
+ if configs.is_enabled(module, parser, origbuf) then
line = line .. "✓"
else
line = line .. "✗"
@@ -91,6 +91,7 @@ local function append_module_table(curbuf, parserlist, namespace, modulelist)
end
local function print_info_modules(parserlist, module)
+ local origbuf = api.nvim_get_current_buf()
api.nvim_command "enew"
local curbuf = api.nvim_get_current_buf()
@@ -109,7 +110,7 @@ local function print_info_modules(parserlist, module)
table.sort(parserlist)
for _, namespace in ipairs(namespaces) do
- append_module_table(curbuf, parserlist, namespace, modules[namespace])
+ append_module_table(curbuf, origbuf, parserlist, namespace, modules[namespace])
end
api.nvim_buf_set_option(curbuf, "modified", false)