mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-15 18:00:07 -04:00
Implement TSBufToggle.
This commit is contained in:
parent
68a2dc219f
commit
8e2807d09e
2 changed files with 29 additions and 0 deletions
|
|
@ -229,6 +229,13 @@ A list of modules can be found at |:TSModuleInfo|
|
||||||
:TSBufDisable {module}~
|
:TSBufDisable {module}~
|
||||||
|
|
||||||
Disable {module} on the current buffer
|
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|
|
A list of modules can be found at |:TSModuleInfo|
|
||||||
|
|
||||||
*:TSBufEnableAll*
|
*:TSBufEnableAll*
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,21 @@ local function disable_all(mod)
|
||||||
config_mod.enable = false
|
config_mod.enable = false
|
||||||
end
|
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
|
-- Recurses through all modules including submodules
|
||||||
-- @param accumulator function called for each module
|
-- @param accumulator function called for each module
|
||||||
-- @param root root configuration table to start at
|
-- @param root root configuration table to start at
|
||||||
|
|
@ -181,6 +196,13 @@ M.commands = {
|
||||||
"-complete=custom,nvim_treesitter#available_modules",
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
TSBufToggle = {
|
||||||
|
run = toggle_module,
|
||||||
|
args = {
|
||||||
|
"-nargs=1",
|
||||||
|
"-complete=custom,nvim_treesitter#available_modules",
|
||||||
|
},
|
||||||
|
},
|
||||||
TSEnableAll = {
|
TSEnableAll = {
|
||||||
run = enable_all,
|
run = enable_all,
|
||||||
args = {
|
args = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue