From 02c530137934d16299360d56207a1c5b2e4c79f8 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 29 May 2024 13:16:28 -0700 Subject: [PATCH] No look: Refactor to drop 0.6 support --- neovim/lua/_bindings.lua | 13 +-- neovim/lua/_colors.lua | 15 +-- neovim/lua/_settings.lua | 15 +-- neovim/lua/init.lua | 8 +- neovim/lua/plugins.lua | 40 +++----- neovim/lua/plugins/completion.lua | 4 +- neovim/lua/plugins/grepper.lua | 36 ++----- neovim/lua/plugins/lsp.lua | 165 ++++++++++++------------------ neovim/lua/utils.lua | 45 +------- 9 files changed, 107 insertions(+), 234 deletions(-) diff --git a/neovim/lua/_bindings.lua b/neovim/lua/_bindings.lua index b371610..a8d1b34 100644 --- a/neovim/lua/_bindings.lua +++ b/neovim/lua/_bindings.lua @@ -55,16 +55,9 @@ function _G.complete_space() end utils.keymap_set("i", "", "v:lua.complete_space()", { expr = true }) --- TODO: remove check when dropping v0.6.0 -if vim.fn.has("nvim-0.7.0") == 1 then - vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" }) - vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" }) - vim.api.nvim_create_user_command("Spell", "setlocal spell! spelllang=en_us", { desc = "Toggle spelling" }) -else - vim.cmd("command! TagsUpdate !ctags -R .") - vim.cmd("command! Todo grep TODO") - vim.cmd("command Spell setlocal spell! spelllang=en_us") -end +vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" }) +vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" }) +vim.api.nvim_create_user_command("Spell", "setlocal spell! spelllang=en_us", { desc = "Toggle spelling" }) -- Pop spelling completion for word under cursor utils.keymap_set("n", "s", "viwas", { desc = "Show spelling suggestions" }) diff --git a/neovim/lua/_colors.lua b/neovim/lua/_colors.lua index f107a16..844c6ee 100644 --- a/neovim/lua/_colors.lua +++ b/neovim/lua/_colors.lua @@ -61,16 +61,11 @@ end -- Don't need the autocommand when dark-notify is installed local utils = require("utils") if not utils.is_plugin_loaded("dark-notify") then - -- TODO: remove check when dropping v0.6.0 - if vim.fn.has("nvim-0.7.0") == 1 then - vim.api.nvim_create_autocmd({ "FocusGained" }, { - pattern = "*", - callback = _G.update_colors, - group = vim.api.nvim_create_augroup("auto_colors", { clear = true }), - }) - else - utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()") - end + vim.api.nvim_create_autocmd({ "FocusGained" }, { + pattern = "*", + callback = _G.update_colors, + group = vim.api.nvim_create_augroup("auto_colors", { clear = true }), + }) end -- Initial setting of colors diff --git a/neovim/lua/_settings.lua b/neovim/lua/_settings.lua index a192ae4..36e4cb7 100644 --- a/neovim/lua/_settings.lua +++ b/neovim/lua/_settings.lua @@ -37,16 +37,11 @@ o.mouse = "a" -- Autocomplete options o.completeopt = "menuone,noinsert,noselect,preview" --- TODO: remove check when dropping v0.6.0 -if vim.fn.has("nvim-0.7.0") == 1 then - vim.api.nvim_create_autocmd({ "CompleteDone" }, { - pattern = "*", - command = "if pumvisible() == 0 | pclose | endif", - group = vim.api.nvim_create_augroup("close_preview", { clear = true }), - }) -else - utils.autocmd("close_preview", "CompleteDone * if pumvisible() == 0 | pclose | endif", true) -end +vim.api.nvim_create_autocmd({ "CompleteDone" }, { + pattern = "*", + command = "if pumvisible() == 0 | pclose | endif", + group = vim.api.nvim_create_augroup("close_preview", { clear = true }), +}) local has = vim.fn.has g.is_mac = (has("mac") or has("macunix") or has("gui_macvim") or vim.fn.system("uname"):find("^darwin") ~= nil) diff --git a/neovim/lua/init.lua b/neovim/lua/init.lua index c259fc5..f3f575c 100644 --- a/neovim/lua/init.lua +++ b/neovim/lua/init.lua @@ -1,5 +1,5 @@ -if vim.fn.has("nvim-0.6.0") ~= 1 then - print("ERROR: Requires nvim >= 0.6.0") +if vim.fn.has("nvim-0.7.0") ~= 1 then + print("ERROR: Requires nvim >= 0.7.0") end local o = vim.o @@ -26,4 +26,6 @@ vim.g.polyglot_disabled = { "go", "rust" } -- Plugins -- Packer auto installs and then lazy loads itself on PackerCommand and require the plugins module -- This command should only really be needed to bootstrap a new system -vim.cmd([[command! PackerBootstrap lua require("plugins")]]) +vim.api.nvim_create_user_command("PackerBootstrap", function() + require("plugins") +end, { desc = "Bootstrap Packer" }) diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua index d9c3b29..49bd8ce 100644 --- a/neovim/lua/plugins.lua +++ b/neovim/lua/plugins.lua @@ -190,16 +190,9 @@ use({ }) -- Custom status line -use({ - "https://github.com/SmiteshP/nvim-gps", - requires = "https://github.com/nvim-treesitter/nvim-treesitter", - disable = vim.fn.has("nvim-0.7.0") == 1, -}) --- Replaces gps for 0.7+ use({ "https://github.com/SmiteshP/nvim-navic", requires = "https://github.com/neovim/nvim-lspconfig", - disable = vim.fn.has("nvim-0.7.0") ~= 1, }) use({ @@ -207,7 +200,7 @@ use({ config = function() require("plugins.lualine").config_lualine() end, - after = vim.fn.has("nvim-0.7.0") == 1 and "nvim-navic" or "nvim-gps", + after = "nvim-navic", }) -- On Mac, update colors when dark mode changes @@ -305,8 +298,6 @@ use({ "https://github.com/neovim/nvim-lspconfig", "https://github.com/williamboman/mason-lspconfig.nvim", }, - -- Only supports >=0.7.0 - disable = vim.fn.has("nvim-0.7.0") ~= 1, }) -- Lua dev for vim @@ -318,7 +309,6 @@ use({ -- Rust analyzer use({ "https://github.com/simrat39/rust-tools.nvim", - disable = vim.fn.has("nvim-0.7.0") ~= 1, }) -- Better display of lsp diagnostics @@ -388,16 +378,6 @@ use({ require("utils").require_with_local("plugins.treesitter").setup() end, }) ---[[ TODO: Enable this as an alterantive or fallback for LSPs -use({ - "https://github.com/nvim-treesitter/nvim-treesitter-refactor", - requires = "https://github.com/nvim-treesitter/nvim-treesitter", - commit = utils.map_version_rule({ - [">=0.7.0"] = utils.nil_val, - ["<0.7.0"] = "75f5895", - }), -}) ---]] use({ "https://github.com/nvim-treesitter/nvim-treesitter-textobjects", requires = "https://github.com/nvim-treesitter/nvim-treesitter", @@ -497,13 +477,17 @@ use("https://github.com/hsanson/vim-android") use({ "https://github.com/sheerun/vim-polyglot", config = function() - -- TODO: Replace with api calls when dropping 0.6 - vim.cmd([[ - augroup polyglot_fts - au BufRead,BufNewFile */playbooks/*.yml,*/playbooks/*.yaml set filetype=yaml.ansible - au BufRead,BufNewFile go.mod,go.sum set filetype=gomod - augroup end - ]]) + local gid = vim.api.nvim_create_augroup("polyglot_fts", { clear = true }) + vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { + pattern = { "*/playbooks/*.yml", "*/playbooks/*.yaml" }, + command = "set filetype=yaml.ansible", + group = gid, + }) + vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { + pattern = { "go.mod", "go.sum" }, + command = "set filetype=gomod", + group = gid, + }) end, }) diff --git a/neovim/lua/plugins/completion.lua b/neovim/lua/plugins/completion.lua index 464f398..62afe7d 100644 --- a/neovim/lua/plugins/completion.lua +++ b/neovim/lua/plugins/completion.lua @@ -48,7 +48,9 @@ function M.config_cmp() -- Add a plug mapping to use in C-Space binding local utils = require("utils") - utils.keymap_set("i", "(cmp_complete)", "lua require('cmp').complete()", { desc = "Autocomplete" }) + utils.keymap_set("i", "(cmp_complete)", function() + require("cmp").complete() + end, { desc = "Autocomplete" }) -- Maybe add obsidian and obsidian new. This is done here in case obsidian.nvim is loaded before cmp utils.try_require("cmp_obsidian", function(cmp_obsidian) diff --git a/neovim/lua/plugins/grepper.lua b/neovim/lua/plugins/grepper.lua index e4953b1..1d3dfca 100644 --- a/neovim/lua/plugins/grepper.lua +++ b/neovim/lua/plugins/grepper.lua @@ -15,33 +15,15 @@ require("utils").keymap_set({ "n", "x" }, "gs", "(GrepperOperator)", { }) -- Override Todo command to use Grepper --- TODO: Remove check when dropping 0.6 -if vim.fn.has("nvim-0.7.0") == 1 then - vim.api.nvim_create_user_command("Todo", ":Grepper -noprompt -query TODO", { desc = "Search for TODO tags" }) -else - vim.cmd("command! Todo :Grepper -noprompt -query TODO") -end +vim.api.nvim_create_user_command("Todo", ":Grepper -noprompt -query TODO", { desc = "Search for TODO tags" }) -- Make some shortands for various grep programs --- TODO: Remove check when dropping 0.6 -if vim.fn.has("nvim-0.7.0") == 1 then - if vim.fn.executable("rg") == 1 then - vim.api.nvim_create_user_command("Rg", ":GrepperRg ", { nargs = "+", desc = "Ripgrep" }) - end - if vim.fn.executable("ag") == 1 then - vim.api.nvim_create_user_command("Ag", ":GrepperAg ", { nargs = "+", desc = "Silversearcher" }) - end - if vim.fn.executable("ack") == 1 then - vim.api.nvim_create_user_command("Ack", ":GrepperAck ", { nargs = "+", desc = "Ack search" }) - end -else - if vim.fn.executable("rg") == 1 then - vim.cmd("command -nargs=+ Rg :GrepperRg ") - end - if vim.fn.executable("ag") == 1 then - vim.cmd("command -nargs=+ Ag :GrepperAg ") - end - if vim.fn.executable("ack") == 1 then - vim.cmd("command -nargs=+ Ack :GrepperAck ") - end +if vim.fn.executable("rg") == 1 then + vim.api.nvim_create_user_command("Rg", ":GrepperRg ", { nargs = "+", desc = "Ripgrep" }) +end +if vim.fn.executable("ag") == 1 then + vim.api.nvim_create_user_command("Ag", ":GrepperAg ", { nargs = "+", desc = "Silversearcher" }) +end +if vim.fn.executable("ack") == 1 then + vim.api.nvim_create_user_command("Ack", ":GrepperAck ", { nargs = "+", desc = "Ack search" }) end diff --git a/neovim/lua/plugins/lsp.lua b/neovim/lua/plugins/lsp.lua index 456bd06..5073aa5 100644 --- a/neovim/lua/plugins/lsp.lua +++ b/neovim/lua/plugins/lsp.lua @@ -90,67 +90,38 @@ local function get_default_attach(override_capabilities) end -- Mappings - -- TODO: use functions instead of strings when dropping 0.6 local lsp_keymap = utils.curry_keymap("n", "l", { buffer = bufnr }) - lsp_keymap("h", "lua vim.lsp.buf.hover()", { desc = "Display hover" }) - lsp_keymap("rn", "lua vim.lsp.buf.rename()", { desc = "Refactor rename" }) - lsp_keymap("e", "lua vim.diagnostic.open_float()", { desc = "Open float dialog" }) - lsp_keymap("D", "lua vim.lsp.buf.declaration()", { desc = "Go to declaration" }) - lsp_keymap("d", "lua vim.lsp.buf.definition()", { desc = "Go to definition" }) - lsp_keymap("t", "lua vim.lsp.buf.type_definition()", { desc = "Go to type definition" }) - lsp_keymap("i", "lua vim.lsp.buf.implementation()", { desc = "Show implementations" }) - lsp_keymap("s", "lua vim.lsp.buf.signature_help()", { desc = "Show signature help" }) - lsp_keymap("wa", "lua vim.lsp.buf.add_workspace_folder()", { desc = "Workspace: Add folder" }) - lsp_keymap("wr", "lua vim.lsp.buf.remove_workspace_folder()", { desc = "Workspace: Remove folder" }) - lsp_keymap( - "wl", - "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", - { desc = "Workspace: List folders" } - ) - lsp_keymap("r", "lua vim.lsp.buf.references()", { desc = "References" }) - lsp_keymap("p", "lua vim.diagnostic.goto_prev()", { desc = "Previous diagnostic" }) - lsp_keymap("n", "lua vim.diagnostic.goto_next()", { desc = "Next diagnostic" }) + lsp_keymap("h", vim.lsp.buf.hover, { desc = "Display hover" }) + lsp_keymap("rn", vim.lsp.buf.rename, { desc = "Refactor rename" }) + lsp_keymap("e", vim.diagnostic.open_float, { desc = "Open float dialog" }) + lsp_keymap("D", vim.lsp.buf.declaration, { desc = "Go to declaration" }) + lsp_keymap("d", vim.lsp.buf.definition, { desc = "Go to definition" }) + lsp_keymap("t", vim.lsp.buf.type_definition, { desc = "Go to type definition" }) + lsp_keymap("i", vim.lsp.buf.implementation, { desc = "Show implementations" }) + lsp_keymap("s", vim.lsp.buf.signature_help, { desc = "Show signature help" }) + lsp_keymap("wa", vim.lsp.buf.add_workspace_folder, { desc = "Workspace: Add folder" }) + lsp_keymap("wr", vim.lsp.buf.remove_workspace_folder, { desc = "Workspace: Remove folder" }) + lsp_keymap("wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, { desc = "Workspace: List folders" }) + lsp_keymap("r", vim.lsp.buf.references, { desc = "References" }) + lsp_keymap("p", vim.diagnostic.goto_prev, { desc = "Previous diagnostic" }) + lsp_keymap("n", vim.diagnostic.goto_next, { desc = "Next diagnostic" }) + if server_capabilities.codeActionProvider then + lsp_keymap("A", vim.lsp.buf.code_action, { desc = "Select code actions" }) + lsp_keymap("A", vim.lsp.buf.code_action, { mode = "v", desc = "Select code actions" }) + end -- Set insert keymap for signature help - utils.keymap_set( - "i", - "", - "lua vim.lsp.buf.signature_help()", - { buffer = bufnr, desc = "Show signature help" } - ) + utils.keymap_set("i", "", vim.lsp.buf.signature_help, { buffer = bufnr, desc = "Show signature help" }) -- Some top level aliases or remaps - utils.keymap_set("n", "K", "lua vim.lsp.buf.hover()", { buffer = bufnr, desc = "Display hover" }) - utils.keymap_set( - "n", - "gD", - "lua vim.lsp.buf.declaration()", - { buffer = bufnr, desc = "Go to declaration" } - ) - utils.keymap_set( - "n", - "gd", - "lua vim.lsp.buf.definition()", - { buffer = bufnr, desc = "Go to definition" } - ) - utils.keymap_set( - "n", - "rn", - "lua vim.lsp.buf.rename()", - { buffer = bufnr, desc = "Refactor rename" } - ) - utils.keymap_set( - "n", - "[d", - "lua vim.diagnostic.goto_prev()", - { buffer = bufnr, desc = "Previous diagnostic" } - ) - utils.keymap_set( - "n", - "]d", - "lua vim.diagnostic.goto_next()", - { buffer = bufnr, desc = "Next diagnostic" } - ) + utils.keymap_set("n", "K", vim.lsp.buf.hover, { buffer = bufnr, desc = "Display hover" }) + utils.keymap_set("n", "gD", vim.lsp.buf.declaration, { buffer = bufnr, desc = "Go to declaration" }) + utils.keymap_set("n", "gd", vim.lsp.buf.definition, { buffer = bufnr, desc = "Go to definition" }) + utils.keymap_set("n", "rn", vim.lsp.buf.rename, { buffer = bufnr, desc = "Refactor rename" }) + utils.keymap_set("n", "[d", vim.diagnostic.goto_prev, { buffer = bufnr, desc = "Previous diagnostic" }) + utils.keymap_set("n", "]d", vim.diagnostic.goto_next, { buffer = bufnr, desc = "Next diagnostic" }) -- Older keymaps --[[ @@ -181,12 +152,12 @@ local function get_default_attach(override_capabilities) -- Set some keybinds conditional on server capabilities if vim.fn.has("nvim-0.8") == 1 then - lsp_keymap("f", "lua vim.lsp.buf.format({async=true})", { desc = "Format code" }) - lsp_keymap( - "f", - "lua vim.lsp.buf.format({async=true})", - { mode = "v", desc = "Format selected code" } - ) + lsp_keymap("f", function() + vim.lsp.buf.format({ async = true }) + end, { desc = "Format code" }) + lsp_keymap("f", function() + vim.lsp.buf.format({ async = true }) + end, { mode = "v", desc = "Format selected code" }) if server_capabilities.documentFormattingProvider then vim.api.nvim_create_autocmd({ "BufWritePre" }, { pattern = { "*.rs", "*.go", "*.sh", "*.lua" }, @@ -199,59 +170,57 @@ local function get_default_attach(override_capabilities) end else -- HACK: Support for <0.8 - lsp_keymap("f", "lua vim.lsp.buf.formatting()", { desc = "Format code" }) - lsp_keymap( - "f", - "lua vim.lsp.buf.range_formatting()", - { mode = "v", desc = "Format selected code" } - ) + lsp_keymap("f", vim.lsp.buf.formatting, { desc = "Format code" }) + lsp_keymap("f", vim.lsp.buf.range_formatting, { mode = "v", desc = "Format selected code" }) if server_capabilities.documentFormattingProvider then - vim.cmd([[ - augroup lsp_format - autocmd! - autocmd BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000) - augroup END - ]]) + vim.api.nvim_create_autocmd({ "BufWritePre" }, { + pattern = { "*.rs", "*.go", "*.sh", "*.lua" }, + callback = function() + vim.lsp.buf.formatting_sync(nil, 1000) + end, + group = vim.api.nvim_create_augroup("lsp_format", { clear = true }), + desc = "Auto format code on save", + }) end end -- Set autocommands conditional on server_capabilities if server_capabilities.documentHighlightProvider then - vim.cmd([[ - :highlight link LspReferenceRead MatchParen - :highlight link LspReferenceText MatchParen - :highlight link LspReferenceWrite MatchParen - augroup lsp_document_highlight - autocmd! - autocmd CursorHold lua vim.lsp.buf.document_highlight() - autocmd CursorMoved lua vim.lsp.buf.clear_references() - augroup END - ]]) + vim.api.nvim_set_hl(0, "LspReferenceRead", { link = "MatchParen" }) + vim.api.nvim_set_hl(0, "LspReferenceText", { link = "MatchParen" }) + vim.api.nvim_set_hl(0, "LspReferenceWrite", { link = "MatchParen" }) + local hl_group = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true }) + vim.api.nvim_create_autocmd( + { "CursorHold" }, + { pattern = "", callback = vim.lsp.buf.document_highlight, group = hl_group } + ) + vim.api.nvim_create_autocmd( + { "CursorMoved" }, + { pattern = "", callback = vim.lsp.buf.clear_references, group = hl_group } + ) end -- Some override some fuzzy finder bindings to use lsp sources - if utils.try_require("telescope") ~= nil then + utils.try_require("telescope.builtin", function(builtin) -- Replace some Telescope bindings with LSP versions local telescope_keymap = utils.curry_keymap("n", "f", { buffer = bufnr }) if server_capabilities.documentSymbolProvider then - telescope_keymap("t", "Telescope lsp_document_symbols", { desc = "Find buffer tags" }) + telescope_keymap("t", builtin.lsp_document_symbols, { desc = "Find buffer tags" }) end if server_capabilities.workspaceSymbolProvider then - telescope_keymap("T", "Telescope lsp_dynamic_workspace_symbols", { desc = "Find tags" }) + telescope_keymap("T", builtin.lsp_dynamic_workspace_symbols, { desc = "Find tags" }) end -- Replace some LSP bindings with Telescope ones if server_capabilities.definitionProvider then - lsp_keymap("d", "Telescope lsp_definitions", { desc = "Find definition" }) + lsp_keymap("d", builtin.lsp_definitions, { desc = "Find definition" }) end if server_capabilities.typeDefinitionProvider then - lsp_keymap("t", "Telescope lsp_type_definition", { desc = "Find type definition" }) + lsp_keymap("t", builtin.lsp_type_definition, { desc = "Find type definition" }) end - lsp_keymap("i", "Telescope lsp_implementations", { desc = "Find implementations" }) - lsp_keymap("r", "Telescope lsp_references", { desc = "Find references" }) - lsp_keymap("A", "Telescope lsp_code_actions", { desc = "Select code actions" }) - lsp_keymap("A", "Telescope lsp_range_code_actions", { mode = "v", desc = "Select code actions" }) - end + lsp_keymap("i", builtin.lsp_implementations, { desc = "Find implementations" }) + lsp_keymap("r", builtin.lsp_references, { desc = "Find references" }) + end) -- Attach navic for statusline location if server_capabilities.documentSymbolProvider then @@ -342,13 +311,7 @@ function M.config_lsp() -- Auto setup mason installed servers utils.try_require("mason-lspconfig", function(mason_lspconfig) -- Get list of servers that are installed but not set up - local already_setup - if lsp_config["util"] and lsp_config.util["available_servers"] then - already_setup = lsp_config.util.available_servers() - else - -- HACK: For lspconfig versions lower than 0.1.4, which is required for nvim <0.7.0 - already_setup = lsp_config.available_servers() - end + local already_setup = lsp_config.util.available_servers() local needs_setup = vim.tbl_filter(function(server) return not vim.tbl_contains(already_setup, server) end, mason_lspconfig.get_installed_servers()) diff --git a/neovim/lua/utils.lua b/neovim/lua/utils.lua index 75dab32..10a7b45 100644 --- a/neovim/lua/utils.lua +++ b/neovim/lua/utils.lua @@ -5,23 +5,6 @@ function M.get_color(synID, what, mode) return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(synID)), what, mode) end --- Create an autocmd --- TODO: Remove this and use nvim_create_autocmd and nvim_create_augroup when dropping .6 -function M.autocmd(group, cmds, clear) - clear = clear == nil and false or clear - if type(cmds) == "string" then - cmds = { cmds } - end - vim.cmd("augroup " .. group) - if clear then - vim.cmd([[au!]]) - end - for _, cmd in ipairs(cmds) do - vim.cmd("autocmd " .. cmd) - end - vim.cmd([[augroup END]]) -end - -- Terminal escape a given string function M.t(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -195,38 +178,13 @@ end -- Calls keymap_set with preferred defaults function M.keymap_set(mode, lhs, rhs, opts) opts = vim.tbl_extend("keep", opts, { noremap = true, silent = true }) - -- TODO: Remove this check when dropping 0.6 support - if vim.fn.has("nvim-0.7") == 1 then - vim.keymap.set(mode, lhs, rhs, opts) - else - -- Desc is not supported in 0.6 - opts["desc"] = nil - if type(mode) ~= "string" then - for _, m in pairs(mode) do - M.keymap_set(m, lhs, rhs, opts) - end - return - end - -- Buffer requires a different function - local buffer = M.tbl_pop(opts, "buffer") - if buffer == nil then - vim.api.nvim_set_keymap(mode, lhs, rhs, opts) - else - vim.api.nvim_buf_set_keymap(buffer, mode, lhs, rhs, opts) - end - end + vim.keymap.set(mode, lhs, rhs, opts) end -- Returns a curried function for passing data into vim.keymap.set function M.curry_keymap(mode, prefix, default_opts) default_opts = vim.tbl_extend("keep", default_opts or {}, { noremap = true, silent = true }) - -- TODO: Remove when dropping 0.6 - if vim.fn.has("nvim-0.7") ~= 1 then - -- NOTE: This is incompatible with a lua function on rhs and a bool buffer instead of number - return M.keymap_group(mode, prefix, default_opts) - end - return function(lhs, rhs, opts) opts = vim.tbl_extend("keep", opts or {}, default_opts) local opt_mode = M.tbl_pop(opts, "mode") @@ -236,7 +194,6 @@ end -- Returns a function used to create keymaps with consistent prefixes function M.keymap_group(mode, prefix, default_opts) - -- TODO: Remove when dropping 0.6 since curry_keymap exists return function(lhs, rhs, opts) opts = opts or default_opts if opts ~= nil and default_opts ~= nil and opts ~= default_opts then