diff --git a/config/nvim/lua/fschauen/plugins/nerdy.lua b/config/nvim/lua/fschauen/plugins/nerdy.lua index 2e6a262..c3f884d 100644 --- a/config/nvim/lua/fschauen/plugins/nerdy.lua +++ b/config/nvim/lua/fschauen/plugins/nerdy.lua @@ -1,3 +1,5 @@ +local keymap = require("fschauen.plugins.telescope").keymap + return { "2kabhishek/nerdy.nvim", @@ -8,11 +10,7 @@ return { "nvim-telescope/telescope.nvim", }, - keys = function() - local helper = require("fschauen.plugins.telescope").keymap_helper - local lhs, desc = helper.lhs, helper.description - return { - { lhs("i"), "Nerdy", desc = desc("Nerd [i]cons") }, - } - end, + keys = { + keymap { "i", "Nerdy", desc = "Nerd [i]cons" }, + }, } diff --git a/config/nvim/lua/fschauen/plugins/nvim-notify.lua b/config/nvim/lua/fschauen/plugins/nvim-notify.lua index 980023f..10ce3a1 100644 --- a/config/nvim/lua/fschauen/plugins/nvim-notify.lua +++ b/config/nvim/lua/fschauen/plugins/nvim-notify.lua @@ -18,14 +18,13 @@ return { local dismiss_notifications = function() require("notify").dismiss() end - local helper = require("fschauen.plugins.telescope").keymap_helper - local lhs, desc = helper.lhs, helper.description + local keymap = require("fschauen.plugins.telescope").keymap return { -- stylua: ignore start { "n", "Notifications", desc = "Display notification history" }, { "", dismiss_notifications, desc = "Dismiss notifications" }, - { lhs("n"), telescope_notifications, desc = desc("[n]otifications") }, + keymap { "n", telescope_notifications, desc = "[n]otifications" }, -- stylua: ignore end } end, diff --git a/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua b/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua index ca2f12b..7ce8865 100644 --- a/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua +++ b/config/nvim/lua/fschauen/plugins/telescope-file-browser.lua @@ -1,19 +1,16 @@ +local keymap = require("fschauen.plugins.telescope").keymap return { "nvim-telescope/telescope-file-browser.nvim", dependencies = "nvim-telescope/telescope.nvim", - keys = function() - local helper = require("fschauen.plugins.telescope").keymap_helper - local lhs, desc = helper.lhs, helper.description - return { - { - lhs("B"), - "Telescope file_browser theme=ivy", - desc = desc("file [B]rowser"), - }, - } - end, + keys = { + keymap { + "B", + "Telescope file_browser theme=ivy", + desc = "file [B]rowser", + }, + }, config = function() require("telescope").load_extension("file_browser") end, } diff --git a/config/nvim/lua/fschauen/plugins/telescope.lua b/config/nvim/lua/fschauen/plugins/telescope.lua index 25ce1e4..605cfc0 100644 --- a/config/nvim/lua/fschauen/plugins/telescope.lua +++ b/config/nvim/lua/fschauen/plugins/telescope.lua @@ -1,12 +1,6 @@ local ui = require("fschauen.util.icons").ui ----Create the left hand side for a Telescope keymap. -local lhs = function(keys) return "f" .. keys end - ----Create the description for a Telescope keymap. -local desc = function(text) return ui.Telescope .. " Telescope " .. text end - -local builtin_picker = function(name, opts) +local builtin = function(name, opts) return function(title) return function() local picker = require("telescope.builtin")[name] @@ -18,17 +12,17 @@ local builtin_picker = function(name, opts) end local pickers = setmetatable({ - all_files = builtin_picker("find_files", { + all_files = builtin("find_files", { hidden = true, no_ignore = true, no_ignore_parent = true, }), - all_man_pages = builtin_picker("man_pages", { + all_man_pages = builtin("man_pages", { sections = { "ALL" }, }), - colorscheme = builtin_picker("colorscheme", { enable_preview = true }), - diagnostics = builtin_picker("diagnostics", { bufnr = 0 }), - dotfiles = builtin_picker("find_files", { cwd = "~/.dotfiles", hidden = true }), + colorscheme = builtin("colorscheme", { enable_preview = true }), + diagnostics = builtin("diagnostics", { bufnr = 0 }), + dotfiles = builtin("find_files", { cwd = "~/.dotfiles", hidden = true }), selection = function(title) return function() local text = require("fschauen.util").get_selected_text() @@ -38,13 +32,77 @@ local pickers = setmetatable({ } end end, - here = builtin_picker("current_buffer_fuzzy_find"), + here = builtin("current_buffer_fuzzy_find"), }, { -- Fall back to telescope's built-in pickers if a custom one is not defined -- above, but make sure to keep the title we defined. - __index = function(_, key) return builtin_picker(key) end, + __index = function(_, key) return builtin(key) end, }) +---@class LazyKeysSpec +---@field desc string + +---Create consistent key maps with the same prefix and description style. +---@param spec LazyKeysSpec lazy.nvim key spec to modify +---@return LazyKeysSpec modified key spec with prefix and description +local keymap = function(spec) + vim.validate("Telescope key spec", spec, "table") + vim.validate("Telescope key lhs", spec[1], "string") + vim.validate("Telescope key rhs", spec[2], { "string", "function" }) + vim.validate("Telescope key description", spec.desc, "string") + return vim.tbl_extend("force", spec, { + "f" .. spec[1], -- lhs + spec[2], -- rhs + desc = ui.Telescope .. " Telescope " .. spec.desc, + }) +end + +local keys = { + -- stylua: ignore start + { "a", pickers.autocommands " Autocommands" , desc = "[a]utocommands" }, + { "b", pickers.buffers " Buffers" , desc = "[b]uffers" }, + --"B" used in telescope-file-browser + { "c", pickers.colorscheme " Colorschemes" , desc = "[c]olorschemes" }, + { "C", pickers.commands " Commands" , desc = "[C]ommands" }, + { "d", pickers.diagnostics "󰀪 Diagnostics" , desc = "[d]iagnostics" }, + --"e" + { "f", pickers.find_files " Files" , desc = "[f]ind files" }, + { "F", pickers.all_files " ALL files" , desc = "all [F]iles" }, + { "gr", pickers.live_grep " Live grep" , desc = "Live [gr]ep" }, + { "gf", pickers.git_files " Git files" , desc = "[g]it [f]iles" }, + { "gc", pickers.git_commits " Commits" , desc = "[g]it [c]ommits" }, + { "h", pickers.here " Current buffer" , desc = "[b]uffer [h]ere" }, + { "H", pickers.highlights "󰌶 Highlights" , desc = "[H]ighlights" }, + --"i" used in nerdy + { "j", pickers.jumplist " Jumplist" , desc = "[j]umplist" }, + { "k", pickers.keymaps " Keymaps" , desc = "[k]eymaps" }, + { "K", pickers.help_tags " Help tags" , desc = "[K] help/documentation" }, + { "l", pickers.loclist " Location list" , desc = "[l]ocation List" }, + { "m", pickers.all_man_pages " Man pages" , desc = "[m]an pages" }, + --"n" used in vim-notify + { "o", pickers.vim_options " Vim options" , desc = "[o]ptions" }, + --"p" + { "q", pickers.quickfix " Quickfix" , desc = "[q]uickfix" }, + { "r", pickers.lsp_references " References" , desc = "[r]eferences" }, + { "R", pickers.registers "󱓥 Registers" , desc = "[R]registers" }, + { "s", pickers.lsp_document_symbols "󰫧 Document Symbols " , desc = "LSP document [s]ymbols" }, + { "S", pickers.lsp_workspace_symbols "󱄑 Workspace Symbols " , desc = "LSP workspace [S]ymbols" }, + --"t" used in todo_comments + { "T", pickers.treesitter " Treesitter symbols" , desc = "[T]reesitter Symbols" }, + --"u" + --"v" + { "w", pickers.selection " Grep" , desc = "[w]word under cursor" }, + { "w", pickers.selection " Grep", mode = "v" , desc = "[w]ord(s) selected" }, + --"x" + --"y" + { "z", pickers.spell_suggest "󰓆 Spelling suggestions" , desc = "[z] spell suggestions" }, + { ".", pickers.dotfiles " Dotfiles" , desc = "[.]dotfiles" }, + { ":", pickers.command_history " Command history" , desc = "[:]command history" }, + { "/", pickers.search_history " Search history" , desc = "[/]search history" }, + { " ", pickers.resume "󰐎 Resume" , desc = "Resume " }, + -- stylua: ignore end +} + return { "nvim-telescope/telescope.nvim", @@ -57,53 +115,11 @@ return { cmd = "Telescope", - keymap_helper = { lhs = lhs, description = desc }, + ---@diagnostic disable-next-line: param-type-mismatch + keys = vim.iter(keys):map(keymap):totable(), - keys = { - -- stylua: ignore start - { lhs"a", pickers.autocommands " Autocommands" , desc = desc("[a]utocommands") }, - { lhs"b", pickers.buffers " Buffers" , desc = desc("[b]uffers") }, - --lhs"B" used in telescope-file-browser - { lhs"c", pickers.colorscheme " Colorschemes" , desc = desc("[c]olorschemes") }, - { lhs"C", pickers.commands " Commands" , desc = desc("[C]ommands") }, - { lhs"d", pickers.diagnostics "󰀪 Diagnostics" , desc = desc("[d]iagnostics") }, - --lhs"e" - { lhs"f", pickers.find_files " Files" , desc = desc("[f]ind files") }, - { lhs"F", pickers.all_files " ALL files" , desc = desc("all [F]iles") }, - { lhs"gr", pickers.live_grep " Live grep" , desc = desc("Live [gr]ep") }, - { lhs"gf", pickers.git_files " Git files" , desc = desc("[g]it [f]iles") }, - { lhs"gc", pickers.git_commits " Commits" , desc = desc("[g]it [c]ommits") }, - { lhs"h", pickers.here " Current buffer" , desc = desc("[b]uffer [h]ere") }, - { lhs"H", pickers.highlights "󰌶 Highlights" , desc = desc("[H]ighlights") }, - --lhs"i" used in nerdy - { lhs"j", pickers.jumplist " Jumplist" , desc = desc("[j]umplist") }, - { lhs"k", pickers.keymaps " Keymaps" , desc = desc("[k]eymaps") }, - { lhs"K", pickers.help_tags " Help tags" , desc = desc("[K] help/documentation") }, - { lhs"l", pickers.loclist " Location list" , desc = desc("[l]ocation List") }, - { lhs"m", pickers.all_man_pages " Man pages" , desc = desc("[m]an pages") }, - --lhs"n" used in vim-notify - { lhs"o", pickers.vim_options " Vim options" , desc = desc("[o]ptions") }, - --lhs"p" - { lhs"q", pickers.quickfix " Quickfix" , desc = desc("[q]uickfix") }, - { lhs"r", pickers.lsp_references " References" , desc = desc("[r]eferences") }, - { lhs"R", pickers.registers "󱓥 Registers" , desc = desc("[R]registers") }, - { lhs"s", pickers.lsp_document_symbols "󰫧 Document Symbols " , desc = desc("LSP document [s]ymbols") }, - { lhs"S", pickers.lsp_workspace_symbols "󱄑 Workspace Symbols " , desc = desc("LSP workspace [S]ymbols") }, - --lhs"t" used in todo_comments - { lhs"T", pickers.treesitter " Treesitter symbols" , desc = desc("[T]reesitter Symbols") }, - --lhs"u" - --lhs"v" - { lhs"w", pickers.selection " Grep" , desc = desc("[w]word under cursor") }, - { lhs"w", pickers.selection " Grep", mode = "v" , desc = desc("[w]ord(s) selected") }, - --lhs"x" - --lhs"y" - { lhs"z", pickers.spell_suggest "󰓆 Spelling suggestions" , desc = desc("[z] spell suggestions") }, - { lhs".", pickers.dotfiles " Dotfiles" , desc = desc("[.]dotfiles") }, - { lhs":", pickers.command_history " Command history" , desc = desc("[:]command history") }, - { lhs"/", pickers.search_history " Search history" , desc = desc("[/]search history") }, - { lhs"", pickers.resume "󰐎 Resume" , desc = desc("Resume ") }, - -- stylua: ignore end - }, + -- Export this function so we can use in other plugins. + keymap = keymap, opts = function() local actions = require("telescope.actions") diff --git a/config/nvim/lua/fschauen/plugins/todo-comments.lua b/config/nvim/lua/fschauen/plugins/todo-comments.lua index 989e8b4..0bb8c2b 100644 --- a/config/nvim/lua/fschauen/plugins/todo-comments.lua +++ b/config/nvim/lua/fschauen/plugins/todo-comments.lua @@ -1,3 +1,5 @@ +local keymap = require("fschauen.plugins.telescope").keymap + return { "folke/todo-comments.nvim", @@ -8,13 +10,9 @@ return { event = { "BufReadPost", "BufNewFile" }, - keys = function() - local helper = require("fschauen.plugins.telescope").keymap_helper - local lhs, desc = helper.lhs, helper.description - return { - { lhs("t"), "TodoTelescope", desc = desc("[t]odos") }, - } - end, + keys = { + keymap { "t", "TodoTelescope", desc = "[t]odos" }, + }, opts = function() local ui = require("fschauen.util.icons").ui