From c129c536858b40d03d983608b971b1f1c446f9c4 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 19:31:28 +0100 Subject: [PATCH 01/17] lib/binds: add simpler keymap helper --- lib/binds.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/binds.nix b/lib/binds.nix index 22bca735..15791b65 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -91,6 +91,8 @@ lua = true; desc = binding.description; }; + + mkKeymap = mode: key: action: opt: opt // {inherit mode key action;}; }; in binds From fed9f348c20de1df2ae3a9c2460f62e9f0d5a935 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 19:31:55 +0100 Subject: [PATCH 02/17] telescope: switch to simpler keybind helper --- modules/plugins/utility/telescope/config.nix | 59 +++++++++----------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index c94fe901..76cfa8bd 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -5,15 +5,14 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.nvim.binds) addDescriptionsToMappings; inherit (lib.strings) optionalString; inherit (lib.lists) optionals; - inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding; + inherit (lib.nvim.binds) pushDownDefault mkKeymap; cfg = config.vim.telescope; - mappingDefinitions = options.vim.telescope.mappings; - mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; + keys = cfg.mappings; + inherit (options.vim.telescope) mappings; in { config = mkIf cfg.enable { vim = { @@ -34,39 +33,35 @@ in { keys = [ - (mkSetLznBinding "n" mappings.findFiles "Telescope find_files") - (mkSetLznBinding "n" mappings.liveGrep "Telescope live_grep") - (mkSetLznBinding "n" mappings.buffers "Telescope buffers") - (mkSetLznBinding "n" mappings.helpTags "Telescope help_tags") - (mkSetLznBinding "n" mappings.open "Telescope") - (mkSetLznBinding "n" mappings.resume "Telescope resume") + (mkKeymap "n" keys.findFiles "Telescope find_files" {desc = mappings.findFiles.description;}) + (mkKeymap "n" keys.liveGrep "Telescope live_grep" {desc = mappings.liveGrep.description;}) + (mkKeymap "n" keys.buffers "Telescope buffers" {desc = mappings.buffers.description;}) + (mkKeymap "n" keys.helpTags "Telescope help_tags" {desc = mappings.helpTags.description;}) + (mkKeymap "n" keys.open "Telescope" {desc = mappings.open.description;}) + (mkKeymap "n" keys.resume "Telescope resume" {desc = mappings.resume.description;}) - (mkSetLznBinding "n" mappings.gitCommits "Telescope git_commits") - (mkSetLznBinding "n" mappings.gitBufferCommits "Telescope git_bcommits") - (mkSetLznBinding "n" mappings.gitBranches "Telescope git_branches") - (mkSetLznBinding "n" mappings.gitStatus "Telescope git_status") - (mkSetLznBinding "n" mappings.gitStash "Telescope git_stash") + (mkKeymap "n" keys.gitCommits "Telescope git_commits" {desc = mappings.gitCommits.description;}) + (mkKeymap "n" keys.gitBufferCommits "Telescope git_bcommits" {desc = mappings.gitBufferCommits.description;}) + (mkKeymap "n" keys.gitBranches "Telescope git_branches" {desc = mappings.gitBranches.description;}) + (mkKeymap "n" keys.gitStatus "Telescope git_status" {desc = mappings.gitStatus.description;}) + (mkKeymap "n" keys.gitStash "Telescope git_stash" {desc = mappings.gitStash.description;}) ] ++ (optionals config.vim.lsp.enable [ - (mkSetLznBinding "n" mappings.lspDocumentSymbols "Telescope lsp_document_symbols") - (mkSetLznBinding "n" mappings.lspWorkspaceSymbols "Telescope lsp_workspace_symbols") + (mkKeymap "n" keys.lspDocumentSymbols "Telescope lsp_document_symbols" {desc = mappings.lspDocumentSymbols.description;}) + (mkKeymap "n" keys.lspWorkspaceSymbols "Telescope lsp_workspace_symbols" {desc = mappings.lspWorkspaceSymbols.description;}) - (mkSetLznBinding "n" mappings.lspReferences "Telescope lsp_references") - (mkSetLznBinding "n" mappings.lspImplementations "Telescope lsp_implementations") - (mkSetLznBinding "n" mappings.lspDefinitions "Telescope lsp_definitions") - (mkSetLznBinding "n" mappings.lspTypeDefinitions "Telescope lsp_type_definitions") - (mkSetLznBinding "n" mappings.diagnostics "Telescope diagnostics") + (mkKeymap "n" keys.lspReferences "Telescope lsp_references" {desc = mappings.lspReferences.description;}) + (mkKeymap "n" keys.lspImplementations "Telescope lsp_implementations" {desc = mappings.lspImplementations.description;}) + (mkKeymap "n" keys.lspDefinitions "Telescope lsp_definitions" {desc = mappings.lspDefinitions.description;}) + (mkKeymap "n" keys.lspTypeDefinitions "Telescope lsp_type_definitions" {desc = mappings.lspTypeDefinitions.description;}) + (mkKeymap "n" keys.diagnostics "Telescope diagnostics" {desc = mappings.diagnostics.description;}) ]) - ++ ( - optionals config.vim.treesitter.enable [ - (mkSetLznBinding "n" mappings.treesitter "Telescope treesitter") - ] - ) - ++ ( - optionals config.vim.projects.project-nvim.enable [ - (mkSetLznBinding "n" mappings.findProjects "Telescope projects") - ] - ); + ++ optionals config.vim.treesitter.enable [ + (mkKeymap "n" keys.treesitter "Telescope treesitter" {desc = mappings.treesitter.description;}) + ] + ++ optionals config.vim.projects.project-nvim.enable [ + (mkKeymap "n" keys.findProjects "Telescope projects" {desc = mappings.findProjects.description;}) + ]; }; binds.whichKey.register = pushDownDefault { From a83168e6d775ca575cb8a26d87ed2cf8b6bbd72a Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 19:48:40 +0100 Subject: [PATCH 03/17] trouble: switch to new keybind helper --- modules/plugins/lsp/trouble/config.nix | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/plugins/lsp/trouble/config.nix b/modules/plugins/lsp/trouble/config.nix index b64a9151..c41dec60 100644 --- a/modules/plugins/lsp/trouble/config.nix +++ b/modules/plugins/lsp/trouble/config.nix @@ -5,12 +5,11 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault; + inherit (lib.nvim.binds) mkKeymap pushDownDefault; cfg = config.vim.lsp; - mappingDefinitions = options.vim.lsp.trouble.mappings; - mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions; + inherit (options.vim.lsp.trouble) mappings; in { config = mkIf (cfg.enable && cfg.trouble.enable) { vim = { @@ -21,12 +20,12 @@ in { cmd = "Trouble"; keys = [ - (mkSetLznBinding "n" mappings.workspaceDiagnostics "Trouble toggle diagnostics") - (mkSetLznBinding "n" mappings.documentDiagnostics "Trouble toggle diagnostics filter.buf=0") - (mkSetLznBinding "n" mappings.lspReferences "Trouble toggle lsp_references") - (mkSetLznBinding "n" mappings.quickfix "Trouble toggle quickfix") - (mkSetLznBinding "n" mappings.locList "Trouble toggle loclist") - (mkSetLznBinding "n" mappings.symbols "Trouble toggle symbols") + (mkKeymap "n" cfg.trouble.mappings.workspaceDiagnostics "Trouble toggle diagnostics" {desc = mappings.workspaceDiagnostics.description;}) + (mkKeymap "n" cfg.trouble.mappings.documentDiagnostics "Trouble toggle diagnostics filter.buf=0" {desc = mappings.documentDiagnostics.description;}) + (mkKeymap "n" cfg.trouble.mappings.lspReferences "Trouble toggle lsp_references" {desc = mappings.lspReferences.description;}) + (mkKeymap "n" cfg.trouble.mappings.quickfix "Trouble toggle quickfix" {desc = mappings.quickfix.description;}) + (mkKeymap "n" cfg.trouble.mappings.locList "Trouble toggle loclist" {desc = mappings.locList.description;}) + (mkKeymap "n" cfg.trouble.mappings.symbols "Trouble toggle symbols" {desc = mappings.symbols.description;}) ]; }; From 8edc48c5eaa7d61c3a344cc0af409866617def7d Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 19:48:59 +0100 Subject: [PATCH 04/17] comment-nvim: switch to new keybind helper --- .../plugins/comments/comment-nvim/config.nix | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/plugins/comments/comment-nvim/config.nix b/modules/plugins/comments/comment-nvim/config.nix index c2c1a7e2..fc48416b 100644 --- a/modules/plugins/comments/comment-nvim/config.nix +++ b/modules/plugins/comments/comment-nvim/config.nix @@ -1,14 +1,14 @@ { + options, config, lib, ... }: let inherit (lib.modules) mkIf; - inherit (lib.nvim.binds) mkLznExprBinding mkLznBinding; + inherit (lib.nvim.binds) mkKeymap; cfg = config.vim.comments.comment-nvim; - self = import ./comment-nvim.nix {inherit lib;}; - inherit (self.options.vim.comments.comment-nvim) mappings; + inherit (options.vim.comments.comment-nvim) mappings; in { config = mkIf cfg.enable { vim.lazy.plugins.comment-nvim = { @@ -16,24 +16,28 @@ in { setupModule = "Comment"; inherit (cfg) setupOpts; keys = [ - (mkLznBinding ["n"] cfg.mappings.toggleOpLeaderLine "(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description) - (mkLznBinding ["n"] cfg.mappings.toggleOpLeaderBlock "(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description) - (mkLznExprBinding ["n"] cfg.mappings.toggleCurrentLine '' + (mkKeymap ["n"] cfg.mappings.toggleOpLeaderLine "(comment_toggle_linewise)" {desc = mappings.toggleOpLeaderLine.description;}) + (mkKeymap ["n"] cfg.mappings.toggleOpLeaderBlock "(comment_toggle_blockwise)" {desc = mappings.toggleOpLeaderBlock.description;}) + (mkKeymap ["n"] cfg.mappings.toggleCurrentLine '' function() return vim.api.nvim_get_vvar('count') == 0 and '(comment_toggle_linewise_current)' or '(comment_toggle_linewise_count)' end - '' - mappings.toggleCurrentLine.description) - (mkLznExprBinding ["n"] cfg.mappings.toggleCurrentBlock '' + '' { + expr = true; + desc = mappings.toggleCurrentLine.description; + }) + (mkKeymap ["n"] cfg.mappings.toggleCurrentBlock '' function() return vim.api.nvim_get_vvar('count') == 0 and '(comment_toggle_blockwise_current)' or '(comment_toggle_blockwise_count)' end - '' - mappings.toggleCurrentBlock.description) - (mkLznBinding ["x"] cfg.mappings.toggleSelectedLine "(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description) - (mkLznBinding ["x"] cfg.mappings.toggleSelectedBlock "(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description) + '' { + expr = true; + desc = mappings.toggleCurrentBlock.description; + }) + (mkKeymap ["x"] cfg.mappings.toggleSelectedLine "(comment_toggle_linewise_visual)" {desc = mappings.toggleSelectedLine.description;}) + (mkKeymap ["x"] cfg.mappings.toggleSelectedBlock "(comment_toggle_blockwise_visual)" {desc = mappings.toggleSelectedBlock.description;}) ]; }; }; From f085f5a04753d02ead8d0c73391e69a79c2d997e Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 19:49:27 +0100 Subject: [PATCH 05/17] docs/hacking: use new keybind helper --- docs/manual/hacking/keybinds.md | 123 ++++++-------------------------- 1 file changed, 23 insertions(+), 100 deletions(-) diff --git a/docs/manual/hacking/keybinds.md b/docs/manual/hacking/keybinds.md index 8c9e7233..3940466f 100644 --- a/docs/manual/hacking/keybinds.md +++ b/docs/manual/hacking/keybinds.md @@ -30,53 +30,12 @@ There are many settings available in the options. Please refer to the [documentation](https://notashelf.github.io/nvf/options.html#opt-vim.keymaps) to see a list of them. -**nvf** provides a list of helper commands, so that you don't have to write the +**nvf** provides a helper function, so that you don't have to write the mapping attribute sets every time: -- `mkBinding = key: action: desc:` - makes a basic binding, with `silent` set to - true. -- `mkExprBinding = key: action: desc:` - makes an expression binding, with - `lua`, `silent`, and `expr` set to true. -- `mkLuaBinding = key: action: desc:` - makes an expression binding, with `lua`, - and `silent` set to true. +- `mkKeymap`, which mimics neovim's `vim.keymap.set` function -Do note that the Lua in these bindings is actual Lua, and not pasted into a -`:lua` command. Therefore, you should either pass in a function like -`require('someplugin').some_function`, without actually calling it, or you -should define your own functions, for example - -```lua -function() - require('someplugin').some_function() -end -``` - -Additionally, to not have to repeat the descriptions, there's another utility -function with its own set of functions: Utility function that takes two -attribute sets: - -- `{ someKey = "some_value" }` -- `{ someKey = { description = "Some Description"; }; }` - -and merges them into -`{ someKey = { value = "some_value"; description = "Some Description"; }; }` - -```nix -addDescriptionsToMappings = actualMappings: mappingDefinitions: -``` - -This function can be used in combination with the same `mkBinding` functions as -above, except they only take two arguments - `binding` and `action`, and have -different names: - -- `mkSetBinding = binding: action:` - makes a basic binding, with `silent` set - to true. -- `mkSetExprBinding = binding: action:` - makes an expression binding, with - `lua`, `silent`, and `expr` set to true. -- `mkSetLuaBinding = binding: action:` - makes an expression binding, with - `lua`, and `silent` set to true. - -You can read the source code of some modules to see them in action, but their +You can read the source code of some modules to see them in action, but the usage should look something like this: ```nix @@ -90,20 +49,13 @@ in { # Mappings should always be inside an attrset called mappings mappings = { - # mkMappingOption is a helper function from lib, - # that takes a description (which will also appear in which-key), - # and a default mapping (which can be null) - toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc"; - toggleCurrentBlock = mkMappingOption "Toggle current block comment" "gbc"; - - toggleOpLeaderLine = mkMappingOption "Toggle line comment" "gc"; - toggleOpLeaderBlock = mkMappingOption "Toggle block comment" "gb"; - - toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc"; - toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb"; + workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "lwd"; + documentDiagnostics = mkMappingOption "Document diagnostics [trouble]" "ld"; + lspReferences = mkMappingOption "LSP References [trouble]" "lr"; + quickfix = mkMappingOption "QuickFix [trouble]" "xq"; + locList = mkMappingOption "LOCList [trouble]" "xl"; + symbols = mkMappingOption "Symbols [trouble]" "xs"; }; - - }; } ``` @@ -111,56 +63,27 @@ in { # config.nix { config, - pkgs, lib, + options, ... }: let - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkSetBinding; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) mkKeymap; - cfg = config.vim.plugin; - self = import ./plugindefinition.nix {inherit lib;}; - mappingDefinitions = self.options.vim.plugin; + cfg = config.vim.plugin; - # addDescriptionsToMappings is a helper function from lib, - # that merges mapping values and their descriptions - # into one nice attribute set - mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; + keys = cfg.mappings; + inherit (options.vim.lsp.trouble) mappings; in { - config = mkIf (cfg.enable) { - # ... - vim.maps.normal = mkMerge [ - # mkSetBinding is another helper function from lib, - # that actually adds the mapping with a description. - (mkSetBinding mappings.findFiles " Telescope find_files") - (mkSetBinding mappings.liveGrep " Telescope live_grep") - (mkSetBinding mappings.buffers " Telescope buffers") - (mkSetBinding mappings.helpTags " Telescope help_tags") - (mkSetBinding mappings.open " Telescope") - - (mkSetBinding mappings.gitCommits " Telescope git_commits") - (mkSetBinding mappings.gitBufferCommits " Telescope git_bcommits") - (mkSetBinding mappings.gitBranches " Telescope git_branches") - (mkSetBinding mappings.gitStatus " Telescope git_status") - (mkSetBinding mappings.gitStash " Telescope git_stash") - - (mkIf config.vim.lsp.enable (mkMerge [ - (mkSetBinding mappings.lspDocumentSymbols " Telescope lsp_document_symbols") - (mkSetBinding mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") - - (mkSetBinding mappings.lspReferences " Telescope lsp_references") - (mkSetBinding mappings.lspImplementations " Telescope lsp_implementations") - (mkSetBinding mappings.lspDefinitions " Telescope lsp_definitions") - (mkSetBinding mappings.lspTypeDefinitions " Telescope lsp_type_definitions") - (mkSetBinding mappings.diagnostics " Telescope diagnostics") - ])) - - ( - mkIf config.vim.treesitter.enable - (mkSetBinding mappings.treesitter " Telescope treesitter") - ) + config = mkIf cfg.enable { + vim.keymaps = [ + (mkKeymap "n" keys.workspaceDiagnostics "Trouble toggle diagnostics" {desc = mappings.workspaceDiagnostics.description;}) + (mkKeymap "n" keys.documentDiagnostics "Trouble toggle diagnostics filter.buf=0" {desc = mappings.documentDiagnostics.description;}) + (mkKeymap "n" keys.lspReferences "Trouble toggle lsp_references" {desc = mappings.lspReferences.description;}) + (mkKeymap "n" keys.quickfix "Trouble toggle quickfix" {desc = mappings.quickfix.description;}) + (mkKeymap "n" keys.locList "Trouble toggle loclist" {desc = mappings.locList.description;}) + (mkKeymap "n" keys.symbols "Trouble toggle symbols" {desc = mappings.symbols.description;}) ]; - # ... }; } ``` From 458c0f6ed583c379fb4478b2baa2db8e10a00eef Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 20:05:57 +0100 Subject: [PATCH 06/17] nvimtree: use new keybind helper --- modules/plugins/filetree/nvimtree/config.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index 7881fa79..7c34fa25 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -6,7 +6,7 @@ }: let inherit (lib.strings) optionalString; inherit (lib.modules) mkIf; - inherit (lib.nvim.binds) mkLznBinding; + inherit (lib.nvim.binds) mkKeymap; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.binds) pushDownDefault; @@ -27,10 +27,10 @@ in { cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"]; keys = [ - (mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle" mappings.toggle.description) - (mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh" mappings.refresh.description) - (mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile" mappings.findFile.description) - (mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) + (mkKeymap ["n"] cfg.mappings.toggle ":NvimTreeToggle" {desc = mappings.toggle.description;}) + (mkKeymap ["n"] cfg.mappings.refresh ":NvimTreeRefresh" {desc = mappings.refresh.description;}) + (mkKeymap ["n"] cfg.mappings.findFile ":NvimTreeFindFile" {desc = mappings.findFile.description;}) + (mkKeymap ["n"] cfg.mappings.focus ":NvimTreeFocus" {desc = mappings.focus.description;}) ]; }; From e697d71ebe581471ce628ef1528135b6c524a2d4 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 20:19:07 +0100 Subject: [PATCH 07/17] toggleterm: use new keybind helper --- modules/plugins/terminal/toggleterm/config.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index d3a71fbd..280f29d2 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -7,7 +7,7 @@ inherit (lib.lists) optional; inherit (lib.modules) mkIf; inherit (lib.meta) getExe; - inherit (lib.nvim.binds) mkLznBinding; + inherit (lib.nvim.binds) mkKeymap; inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.terminal.toggleterm; @@ -19,7 +19,7 @@ in { package = "toggleterm-nvim"; cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; keys = - [(mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal")] + [(mkKeymap "n" cfg.mappings.open "execute v:count . \"ToggleTerm\"" {desc = "Toggle terminal";})] ++ optional cfg.lazygit.enable { key = cfg.lazygit.mappings.open; mode = "n"; From dd1bc19600b9946fd69ba97ef9ca6f74377e4dd8 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 20:19:24 +0100 Subject: [PATCH 08/17] leap: use new keybind helpers --- modules/plugins/utility/motion/leap/config.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/plugins/utility/motion/leap/config.nix b/modules/plugins/utility/motion/leap/config.nix index 94a00c99..b9cb58d5 100644 --- a/modules/plugins/utility/motion/leap/config.nix +++ b/modules/plugins/utility/motion/leap/config.nix @@ -4,7 +4,7 @@ ... }: let inherit (lib.modules) mkIf mkDefault; - inherit (lib.nvim.binds) mkLznBinding; + inherit (lib.nvim.binds) mkKeymap; cfg = config.vim.utility.motion.leap; in { @@ -14,11 +14,11 @@ in { lazy.plugins.leap-nvim = { package = "leap-nvim"; keys = [ - (mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTo "(leap-forward-to)" "Leap forward to") - (mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTo "(leap-backward-to)" "Leap backward to") - (mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTill "(leap-forward-till)" "Leap forward till") - (mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTill "(leap-backward-till)" "Leap backward till") - (mkLznBinding ["n" "o" "x"] cfg.mappings.leapFromWindow "(leap-from-window)" "Leap from window") + (mkKeymap ["n" "o" "x"] cfg.mappings.leapForwardTo "(leap-forward-to)" {desc = "Leap forward to";}) + (mkKeymap ["n" "o" "x"] cfg.mappings.leapBackwardTo "(leap-backward-to)" {desc = "Leap backward to";}) + (mkKeymap ["n" "o" "x"] cfg.mappings.leapForwardTill "(leap-forward-till)" {desc = "Leap forward till";}) + (mkKeymap ["n" "o" "x"] cfg.mappings.leapBackwardTill "(leap-backward-till)" {desc = "Leap backward till";}) + (mkKeymap ["n" "o" "x"] cfg.mappings.leapFromWindow "(leap-from-window)" {desc = "Leap from window";}) ]; after = '' From e812ef2c3f726470733970a8efa9b08065d95de3 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 20:28:20 +0100 Subject: [PATCH 09/17] nvim-dap: use new keybind helpers --- modules/plugins/debugger/nvim-dap/config.nix | 37 ++++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/modules/plugins/debugger/nvim-dap/config.nix b/modules/plugins/debugger/nvim-dap/config.nix index b99fb3d3..eb07ad2a 100644 --- a/modules/plugins/debugger/nvim-dap/config.nix +++ b/modules/plugins/debugger/nvim-dap/config.nix @@ -1,4 +1,5 @@ { + options, config, lib, ... @@ -6,13 +7,11 @@ inherit (lib.strings) optionalString; inherit (lib.modules) mkIf mkMerge; inherit (lib.attrsets) mapAttrs; - inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding mkSetLuaLznBinding; + inherit (lib.nvim.binds) mkKeymap; inherit (lib.nvim.dag) entryAnywhere entryAfter; cfg = config.vim.debugger.nvim-dap; - self = import ./nvim-dap.nix {inherit lib;}; - mappingDefinitions = self.options.vim.debugger.nvim-dap.mappings; - mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; + inherit (options.vim.debugger.nvim-dap) mappings; in { config = mkMerge [ (mkIf cfg.enable { @@ -30,23 +29,23 @@ in { // mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources; maps.normal = mkMerge [ - (mkSetLuaBinding mappings.continue "require('dap').continue") - (mkSetLuaBinding mappings.restart "require('dap').restart") - (mkSetLuaBinding mappings.terminate "require('dap').terminate") - (mkSetLuaBinding mappings.runLast "require('dap').run_last") + (mkKeymap "n" cfg.mappings.continue "require('dap').continue" {desc = mappings.continue.description;}) + (mkKeymap "n" cfg.mappings.restart "require('dap').restart" {desc = mappings.restart.description;}) + (mkKeymap "n" cfg.mappings.terminate "require('dap').terminate" {desc = mappings.terminate.description;}) + (mkKeymap "n" cfg.mappings.runLast "require('dap').run_last" {desc = mappings.runLast.description;}) - (mkSetLuaBinding mappings.toggleRepl "require('dap').repl.toggle") - (mkSetLuaBinding mappings.hover "require('dap.ui.widgets').hover") - (mkSetLuaBinding mappings.toggleBreakpoint "require('dap').toggle_breakpoint") + (mkKeymap "n" cfg.mappings.toggleRepl "require('dap').repl.toggle" {desc = mappings.toggleRepl.description;}) + (mkKeymap "n" cfg.mappings.hover "require('dap.ui.widgets').hover" {desc = mappings.hover.description;}) + (mkKeymap "n" cfg.mappings.toggleBreakpoint "require('dap').toggle_breakpoint" {desc = mappings.toggleBreakpoint.description;}) - (mkSetLuaBinding mappings.runToCursor "require('dap').run_to_cursor") - (mkSetLuaBinding mappings.stepInto "require('dap').step_into") - (mkSetLuaBinding mappings.stepOut "require('dap').step_out") - (mkSetLuaBinding mappings.stepOver "require('dap').step_over") - (mkSetLuaBinding mappings.stepBack "require('dap').step_back") + (mkKeymap "n" cfg.mappings.runToCursor "require('dap').run_to_cursor" {desc = mappings.runToCursor.description;}) + (mkKeymap "n" cfg.mappings.stepInto "require('dap').step_into" {desc = mappings.stepInto.description;}) + (mkKeymap "n" cfg.mappings.stepOut "require('dap').step_out" {desc = mappings.stepOut.description;}) + (mkKeymap "n" cfg.mappings.stepOver "require('dap').step_over" {desc = mappings.stepOver.description;}) + (mkKeymap "n" cfg.mappings.stepBack "require('dap').step_back" {desc = mappings.stepBack.description;}) - (mkSetLuaBinding mappings.goUp "require('dap').up") - (mkSetLuaBinding mappings.goDown "require('dap').down") + (mkKeymap "n" cfg.mappings.goUp "require('dap').up" {desc = mappings.goUp.description;}) + (mkKeymap "n" cfg.mappings.goDown "require('dap').down" {desc = mappings.goDown.description;}) ]; }; }) @@ -60,7 +59,7 @@ in { inherit (cfg.ui) setupOpts; keys = [ - (mkSetLuaLznBinding "n" mappings.toggleDapUI "function() require('dapui').toggle() end") + (mkKeymap "n" cfg.mappings.toggleDapUI "function() require('dapui').toggle() end" {desc = mappings.toggleDapUI.descritpion;}) ]; }; From aa903d1960fd1f0973a3e72a736a45a3078e23be Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 17 Nov 2024 20:28:58 +0100 Subject: [PATCH 10/17] lib/binds: remove unused helpers --- lib/binds.nix | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/binds.nix b/lib/binds.nix index 15791b65..e2bd6f9a 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -68,17 +68,6 @@ pushDownDefault = attr: mapAttrs (_: mkDefault) attr; - mkLznBinding = mode: key: action: desc: { - inherit mode desc key action; - }; - - mkLznExprBinding = mode: key: action: desc: { - inherit mode desc key action; - lua = true; - silent = true; - expr = true; - }; - mkSetLznBinding = mode: binding: action: { inherit action mode; key = binding.value; From 0ae4bab073319c9c936b77ab1a308f4262026e0e Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 29 Nov 2024 13:42:57 +0100 Subject: [PATCH 11/17] typo --- modules/plugins/debugger/nvim-dap/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/debugger/nvim-dap/config.nix b/modules/plugins/debugger/nvim-dap/config.nix index eb07ad2a..a6d72dc1 100644 --- a/modules/plugins/debugger/nvim-dap/config.nix +++ b/modules/plugins/debugger/nvim-dap/config.nix @@ -59,7 +59,7 @@ in { inherit (cfg.ui) setupOpts; keys = [ - (mkKeymap "n" cfg.mappings.toggleDapUI "function() require('dapui').toggle() end" {desc = mappings.toggleDapUI.descritpion;}) + (mkKeymap "n" cfg.mappings.toggleDapUI "function() require('dapui').toggle() end" {desc = mappings.toggleDapUI.description;}) ]; }; From bc637fd7d1b0c723a0e0c73bde279beb22043942 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 29 Nov 2024 13:49:55 +0100 Subject: [PATCH 12/17] fixup! nvim-dap: use new keybind helpers --- modules/plugins/debugger/nvim-dap/config.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/plugins/debugger/nvim-dap/config.nix b/modules/plugins/debugger/nvim-dap/config.nix index a6d72dc1..aa8f8386 100644 --- a/modules/plugins/debugger/nvim-dap/config.nix +++ b/modules/plugins/debugger/nvim-dap/config.nix @@ -28,7 +28,7 @@ in { } // mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources; - maps.normal = mkMerge [ + keymaps = [ (mkKeymap "n" cfg.mappings.continue "require('dap').continue" {desc = mappings.continue.description;}) (mkKeymap "n" cfg.mappings.restart "require('dap').restart" {desc = mappings.restart.description;}) (mkKeymap "n" cfg.mappings.terminate "require('dap').terminate" {desc = mappings.terminate.description;}) From 3011af88f163a94624d35a84ad842aa625b90d92 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Fri, 29 Nov 2024 14:01:40 +0100 Subject: [PATCH 13/17] fixup! lib/binds: remove unused helpers --- lib/binds.nix | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/binds.nix b/lib/binds.nix index e2bd6f9a..bb40a89e 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -68,19 +68,6 @@ pushDownDefault = attr: mapAttrs (_: mkDefault) attr; - mkSetLznBinding = mode: binding: action: { - inherit action mode; - key = binding.value; - desc = binding.description; - }; - - mkSetLuaLznBinding = mode: binding: action: { - inherit action mode; - key = binding.value; - lua = true; - desc = binding.description; - }; - mkKeymap = mode: key: action: opt: opt // {inherit mode key action;}; }; in From db0e8a65a50a6e0bf097d44d0c29bec32287c201 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 30 Nov 2024 15:30:12 +0100 Subject: [PATCH 14/17] docs: update release notes --- docs/release-notes/rl-0.7.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 8dcfc5b0..ae536cc8 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -137,6 +137,8 @@ it to something other than `mapleader` to avoid conflicts. [lz.n]: https://github.com/mrcjkb/lz.n +- Add simpler helper functions for making keymaps + [jacekpoz](https://jacekpoz.pl): [ocaml-lsp]: https://github.com/ocaml/ocaml-lsp From 3b86940f71b1eb4ae55811c9d302777846bc1210 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:35:41 +0100 Subject: [PATCH 15/17] format Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> --- modules/plugins/filetree/nvimtree/config.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/plugins/filetree/nvimtree/config.nix b/modules/plugins/filetree/nvimtree/config.nix index 7c34fa25..e20a1458 100644 --- a/modules/plugins/filetree/nvimtree/config.nix +++ b/modules/plugins/filetree/nvimtree/config.nix @@ -27,10 +27,10 @@ in { cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"]; keys = [ - (mkKeymap ["n"] cfg.mappings.toggle ":NvimTreeToggle" {desc = mappings.toggle.description;}) - (mkKeymap ["n"] cfg.mappings.refresh ":NvimTreeRefresh" {desc = mappings.refresh.description;}) - (mkKeymap ["n"] cfg.mappings.findFile ":NvimTreeFindFile" {desc = mappings.findFile.description;}) - (mkKeymap ["n"] cfg.mappings.focus ":NvimTreeFocus" {desc = mappings.focus.description;}) + (mkKeymap "n" cfg.mappings.toggle ":NvimTreeToggle" {desc = mappings.toggle.description;}) + (mkKeymap "n" cfg.mappings.refresh ":NvimTreeRefresh" {desc = mappings.refresh.description;}) + (mkKeymap "n" cfg.mappings.findFile ":NvimTreeFindFile" {desc = mappings.findFile.description;}) + (mkKeymap "n" cfg.mappings.focus ":NvimTreeFocus" {desc = mappings.focus.description;}) ]; }; From fa7785ede6a2e54f8e676c0af89153e01dd0a7e5 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:36:17 +0100 Subject: [PATCH 16/17] format Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> --- modules/plugins/comments/comment-nvim/config.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/plugins/comments/comment-nvim/config.nix b/modules/plugins/comments/comment-nvim/config.nix index fc48416b..2b555a90 100644 --- a/modules/plugins/comments/comment-nvim/config.nix +++ b/modules/plugins/comments/comment-nvim/config.nix @@ -36,8 +36,8 @@ in { expr = true; desc = mappings.toggleCurrentBlock.description; }) - (mkKeymap ["x"] cfg.mappings.toggleSelectedLine "(comment_toggle_linewise_visual)" {desc = mappings.toggleSelectedLine.description;}) - (mkKeymap ["x"] cfg.mappings.toggleSelectedBlock "(comment_toggle_blockwise_visual)" {desc = mappings.toggleSelectedBlock.description;}) + (mkKeymap "x" cfg.mappings.toggleSelectedLine "(comment_toggle_linewise_visual)" {desc = mappings.toggleSelectedLine.description;}) + (mkKeymap "x" cfg.mappings.toggleSelectedBlock "(comment_toggle_blockwise_visual)" {desc = mappings.toggleSelectedBlock.description;}) ]; }; }; From b3170c0fe308dc3ebf043acb1b79599fa7ad6b50 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:37:03 +0100 Subject: [PATCH 17/17] format Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> --- modules/plugins/comments/comment-nvim/config.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/plugins/comments/comment-nvim/config.nix b/modules/plugins/comments/comment-nvim/config.nix index 2b555a90..4c18f7e9 100644 --- a/modules/plugins/comments/comment-nvim/config.nix +++ b/modules/plugins/comments/comment-nvim/config.nix @@ -16,9 +16,9 @@ in { setupModule = "Comment"; inherit (cfg) setupOpts; keys = [ - (mkKeymap ["n"] cfg.mappings.toggleOpLeaderLine "(comment_toggle_linewise)" {desc = mappings.toggleOpLeaderLine.description;}) - (mkKeymap ["n"] cfg.mappings.toggleOpLeaderBlock "(comment_toggle_blockwise)" {desc = mappings.toggleOpLeaderBlock.description;}) - (mkKeymap ["n"] cfg.mappings.toggleCurrentLine '' + (mkKeymap "n" cfg.mappings.toggleOpLeaderLine "(comment_toggle_linewise)" {desc = mappings.toggleOpLeaderLine.description;}) + (mkKeymap "n" cfg.mappings.toggleOpLeaderBlock "(comment_toggle_blockwise)" {desc = mappings.toggleOpLeaderBlock.description;}) + (mkKeymap "n" cfg.mappings.toggleCurrentLine '' function() return vim.api.nvim_get_vvar('count') == 0 and '(comment_toggle_linewise_current)' or '(comment_toggle_linewise_count)'