diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2020-06-21 20:38:00 +0200 |
|---|---|---|
| committer | Thomas Vigouroux <39092278+vigoux@users.noreply.github.com> | 2020-07-14 22:34:43 +0200 |
| commit | 69cabc69be49bc37c8a9bbb7def1415504b489b2 (patch) | |
| tree | cc4925d6ce00654c181a7cb4d2eef3dc488a324b /lua/nvim-treesitter/configs.lua | |
| parent | c42c38a8346dd9edda96477b774d3e086cd73650 (diff) | |
Add textobjects module
Diffstat (limited to 'lua/nvim-treesitter/configs.lua')
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index abed55a7..f09c8ac9 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -4,6 +4,19 @@ local queries = require'nvim-treesitter.query' local parsers = require'nvim-treesitter.parsers' local utils = require'nvim-treesitter.utils' +local M = {} + +local function has_some_textobject_mapping(lang) + for _, v in pairs(M.get_module('textobjects').keymaps) do + if type(v) == 'table' then + if v[lang] then + return true + end + end + end + return false +end + local config = { modules = {}, ensure_installed = nil @@ -65,13 +78,22 @@ local builtin_modules = { list_definitions = "gnD" } } + }, + textobjects = { + module_path = 'nvim-treesitter.textobjects', + enable = false, + disable = {}, + is_supported = function(lang) + return has_some_textobject_mapping(lang) or queries.has_textobjects(lang) + end, + keymaps = { + inverse_mappings = true + } } } local special_config_keys = {'enable', 'disable', 'keymaps'} -local M = {} - -- Resolves a module by requiring the `module_path` or using the module definition. local function resolve_module(mod_name) local config_mod = M.get_module(mod_name) @@ -279,12 +301,17 @@ function M.setup_module(mod, data, mod_name) mod.disable = data.disable end if mod.keymaps and type(data.keymaps) == 'table' then - for f, map in pairs(data.keymaps) do - if mod.keymaps[f] then - mod.keymaps[f] = map + if mod.keymaps.inverse_mappings then + mod.keymaps = data.keymaps + else + for f, map in pairs(data.keymaps) do + if mod.keymaps[f] then + mod.keymaps[f] = map + end end end end + for k, v in pairs(data) do -- Just copy all non-special configuration keys if not vim.tbl_contains(special_config_keys, k) then |
