summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/nvim-treesitter.txt7
-rw-r--r--lua/nvim-treesitter/configs.lua22
2 files changed, 29 insertions, 0 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index b13cdace..d253194c 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -231,6 +231,13 @@ A list of modules can be found at |:TSModuleInfo|
Disable {module} on the current buffer
A list of modules can be found at |:TSModuleInfo|
+ *:TSBufToggle*
+:TSBufToggle {module}~
+
+Toggle (enable if disabled, disable if enabled) {module} on the current
+buffer.
+A list of modules can be found at |:TSModuleInfo|
+
*:TSBufEnableAll*
:TSBufEnableAll {module} [{language}]~
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index b0d38244..9f7627a0 100644
--- a/lua/nvim-treesitter/configs.lua
+++ b/lua/nvim-treesitter/configs.lua
@@ -136,6 +136,21 @@ local function disable_all(mod)
config_mod.enable = false
end
+-- Toggles a module for a buffer
+-- @param mod path to module
+-- @param bufnr buffer number, defaults to current buffer
+-- @param lang language, defaults to current language
+local function toggle_module(mod, bufnr, lang)
+ local bufnr = bufnr or api.nvim_get_current_buf()
+ local lang = lang or parsers.get_buf_lang(bufnr)
+
+ if attached_buffers_by_module.has(mod, bufnr) then
+ disable_module(mod, bufnr)
+ else
+ enable_module(mod, bufnr, lang)
+ end
+end
+
-- Recurses through all modules including submodules
-- @param accumulator function called for each module
-- @param root root configuration table to start at
@@ -181,6 +196,13 @@ M.commands = {
"-complete=custom,nvim_treesitter#available_modules",
},
},
+ TSBufToggle = {
+ run = toggle_module,
+ args = {
+ "-nargs=1",
+ "-complete=custom,nvim_treesitter#available_modules",
+ },
+ },
TSEnableAll = {
run = enable_all,
args = {