aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorechasnovski <evgeni.chasnovski@gmail.com>2021-01-31 12:43:08 +0200
committerStephan Seitz <stephan.lauf@yahoo.de>2021-02-01 19:37:39 +0100
commit8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e (patch)
tree051aa5c5709dcc746a27dd285530acca45e56757 /lua
parentUpdate lockfile.json (diff)
downloadnvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.tar
nvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.tar.gz
nvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.tar.bz2
nvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.tar.lz
nvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.tar.xz
nvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.tar.zst
nvim-treesitter-8e2807d09e1a5bd226b1ad77a71f3ac6c7fcd36e.zip
Implement `TSBufToggle`.
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/configs.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index b0d38244e..9f7627a00 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 = {