From 140a486abe6dd3cbc40d0620985fccee6f5f609f Mon Sep 17 00:00:00 2001 From: Maria José Solano Date: Wed, 31 Jan 2024 20:37:47 -0800 Subject: refactor(inc-selection): simplify keymap and add error message --- lua/nvim-treesitter/incremental_selection.lua | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/incremental_selection.lua b/lua/nvim-treesitter/incremental_selection.lua index 0ba10971e..f6f8fb266 100644 --- a/lua/nvim-treesitter/incremental_selection.lua +++ b/lua/nvim-treesitter/incremental_selection.lua @@ -5,6 +5,7 @@ local ts_utils = require "nvim-treesitter.ts_utils" local locals = require "nvim-treesitter.locals" local parsers = require "nvim-treesitter.parsers" local queries = require "nvim-treesitter.query" +local utils = require "nvim-treesitter.utils" local M = {} @@ -138,22 +139,14 @@ function M.attach(bufnr) local config = configs.get_module "incremental_selection" for funcname, mapping in pairs(config.keymaps) do if mapping then - ---@type string, string|function - local mode, rhs - if funcname == "init_selection" then - mode = "n" - ---@type function - rhs = M[funcname] + local mode = funcname == "init_selection" and "n" or "x" + local rhs = M[funcname] ---@type function + + if not rhs then + utils.notify("Unknown keybinding: " .. funcname .. debug.traceback(), vim.log.levels.ERROR) else - mode = "x" - rhs = M[funcname] ---@type function + vim.keymap.set(mode, mapping, rhs, { buffer = bufnr, silent = true, desc = FUNCTION_DESCRIPTIONS[funcname] }) end - vim.keymap.set( - mode, - mapping, - rhs, - { buffer = bufnr, silent = true, noremap = true, desc = FUNCTION_DESCRIPTIONS[funcname] } - ) end end end -- cgit v1.2.3-70-g09d2