Merge pull request #473 from horriblename/lib/simpler-binds

internal: simpler helper functions for keymaps
This commit is contained in:
raf 2024-12-02 21:23:55 +03:00 committed by GitHub
commit ce21e1f98a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 109 additions and 210 deletions

View file

@ -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 [documentation](https://notashelf.github.io/nvf/options.html#opt-vim.keymaps) to
see a list of them. 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: mapping attribute sets every time:
- `mkBinding = key: action: desc:` - makes a basic binding, with `silent` set to - `mkKeymap`, which mimics neovim's `vim.keymap.set` function
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.
Do note that the Lua in these bindings is actual Lua, and not pasted into a You can read the source code of some modules to see them in action, but the
`: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
usage should look something like this: usage should look something like this:
```nix ```nix
@ -90,20 +49,13 @@ in {
# Mappings should always be inside an attrset called mappings # Mappings should always be inside an attrset called mappings
mappings = { mappings = {
# mkMappingOption is a helper function from lib, workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "<leader>lwd";
# that takes a description (which will also appear in which-key), documentDiagnostics = mkMappingOption "Document diagnostics [trouble]" "<leader>ld";
# and a default mapping (which can be null) lspReferences = mkMappingOption "LSP References [trouble]" "<leader>lr";
toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc"; quickfix = mkMappingOption "QuickFix [trouble]" "<leader>xq";
toggleCurrentBlock = mkMappingOption "Toggle current block comment" "gbc"; locList = mkMappingOption "LOCList [trouble]" "<leader>xl";
symbols = mkMappingOption "Symbols [trouble]" "<leader>xs";
toggleOpLeaderLine = mkMappingOption "Toggle line comment" "gc";
toggleOpLeaderBlock = mkMappingOption "Toggle block comment" "gb";
toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc";
toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb";
}; };
};
} }
``` ```
@ -111,56 +63,27 @@ in {
# config.nix # config.nix
{ {
config, config,
pkgs,
lib, lib,
options,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkSetBinding; inherit (lib.nvim.binds) mkKeymap;
cfg = config.vim.plugin; cfg = config.vim.plugin;
self = import ./plugindefinition.nix {inherit lib;};
mappingDefinitions = self.options.vim.plugin;
# addDescriptionsToMappings is a helper function from lib, keys = cfg.mappings;
# that merges mapping values and their descriptions inherit (options.vim.lsp.trouble) mappings;
# into one nice attribute set
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in { in {
config = mkIf (cfg.enable) { config = mkIf cfg.enable {
# ... vim.keymaps = [
vim.maps.normal = mkMerge [ (mkKeymap "n" keys.workspaceDiagnostics "<cmd>Trouble toggle diagnostics<CR>" {desc = mappings.workspaceDiagnostics.description;})
# mkSetBinding is another helper function from lib, (mkKeymap "n" keys.documentDiagnostics "<cmd>Trouble toggle diagnostics filter.buf=0<CR>" {desc = mappings.documentDiagnostics.description;})
# that actually adds the mapping with a description. (mkKeymap "n" keys.lspReferences "<cmd>Trouble toggle lsp_references<CR>" {desc = mappings.lspReferences.description;})
(mkSetBinding mappings.findFiles "<cmd> Telescope find_files<CR>") (mkKeymap "n" keys.quickfix "<cmd>Trouble toggle quickfix<CR>" {desc = mappings.quickfix.description;})
(mkSetBinding mappings.liveGrep "<cmd> Telescope live_grep<CR>") (mkKeymap "n" keys.locList "<cmd>Trouble toggle loclist<CR>" {desc = mappings.locList.description;})
(mkSetBinding mappings.buffers "<cmd> Telescope buffers<CR>") (mkKeymap "n" keys.symbols "<cmd>Trouble toggle symbols<CR>" {desc = mappings.symbols.description;})
(mkSetBinding mappings.helpTags "<cmd> Telescope help_tags<CR>")
(mkSetBinding mappings.open "<cmd> Telescope<CR>")
(mkSetBinding mappings.gitCommits "<cmd> Telescope git_commits<CR>")
(mkSetBinding mappings.gitBufferCommits "<cmd> Telescope git_bcommits<CR>")
(mkSetBinding mappings.gitBranches "<cmd> Telescope git_branches<CR>")
(mkSetBinding mappings.gitStatus "<cmd> Telescope git_status<CR>")
(mkSetBinding mappings.gitStash "<cmd> Telescope git_stash<CR>")
(mkIf config.vim.lsp.enable (mkMerge [
(mkSetBinding mappings.lspDocumentSymbols "<cmd> Telescope lsp_document_symbols<CR>")
(mkSetBinding mappings.lspWorkspaceSymbols "<cmd> Telescope lsp_workspace_symbols<CR>")
(mkSetBinding mappings.lspReferences "<cmd> Telescope lsp_references<CR>")
(mkSetBinding mappings.lspImplementations "<cmd> Telescope lsp_implementations<CR>")
(mkSetBinding mappings.lspDefinitions "<cmd> Telescope lsp_definitions<CR>")
(mkSetBinding mappings.lspTypeDefinitions "<cmd> Telescope lsp_type_definitions<CR>")
(mkSetBinding mappings.diagnostics "<cmd> Telescope diagnostics<CR>")
]))
(
mkIf config.vim.treesitter.enable
(mkSetBinding mappings.treesitter "<cmd> Telescope treesitter<CR>")
)
]; ];
# ...
}; };
} }
``` ```

View file

@ -160,6 +160,7 @@ The changes are, in no particular order:
[lz.n]: https://github.com/mrcjkb/lz.n [lz.n]: https://github.com/mrcjkb/lz.n
- Add [lz.n] support and lazy-load some builtin plugins. - Add [lz.n] support and lazy-load some builtin plugins.
- Add simpler helper functions for making keymaps
[jacekpoz](https://jacekpoz.pl): [jacekpoz](https://jacekpoz.pl):

View file

@ -68,29 +68,7 @@
pushDownDefault = attr: mapAttrs (_: mkDefault) attr; pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
mkLznBinding = mode: key: action: desc: { mkKeymap = mode: key: action: opt: opt // {inherit mode key action;};
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;
desc = binding.description;
};
mkSetLuaLznBinding = mode: binding: action: {
inherit action mode;
key = binding.value;
lua = true;
desc = binding.description;
};
}; };
in in
binds binds

View file

@ -1,14 +1,14 @@
{ {
options,
config, config,
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkLznExprBinding mkLznBinding; inherit (lib.nvim.binds) mkKeymap;
cfg = config.vim.comments.comment-nvim; cfg = config.vim.comments.comment-nvim;
self = import ./comment-nvim.nix {inherit lib;}; inherit (options.vim.comments.comment-nvim) mappings;
inherit (self.options.vim.comments.comment-nvim) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.lazy.plugins.comment-nvim = { vim.lazy.plugins.comment-nvim = {
@ -16,24 +16,28 @@ in {
setupModule = "Comment"; setupModule = "Comment";
inherit (cfg) setupOpts; inherit (cfg) setupOpts;
keys = [ keys = [
(mkLznBinding ["n"] cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description) (mkKeymap "n" cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" {desc = mappings.toggleOpLeaderLine.description;})
(mkLznBinding ["n"] cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description) (mkKeymap "n" cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" {desc = mappings.toggleOpLeaderBlock.description;})
(mkLznExprBinding ["n"] cfg.mappings.toggleCurrentLine '' (mkKeymap "n" cfg.mappings.toggleCurrentLine ''
function() function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)' return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(comment_toggle_linewise_count)' or '<Plug>(comment_toggle_linewise_count)'
end end
'' '' {
mappings.toggleCurrentLine.description) expr = true;
(mkLznExprBinding ["n"] cfg.mappings.toggleCurrentBlock '' desc = mappings.toggleCurrentLine.description;
})
(mkKeymap ["n"] cfg.mappings.toggleCurrentBlock ''
function() function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)' return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
or '<Plug>(comment_toggle_blockwise_count)' or '<Plug>(comment_toggle_blockwise_count)'
end end
'' '' {
mappings.toggleCurrentBlock.description) expr = true;
(mkLznBinding ["x"] cfg.mappings.toggleSelectedLine "<Plug>(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description) desc = mappings.toggleCurrentBlock.description;
(mkLznBinding ["x"] cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description) })
(mkKeymap "x" cfg.mappings.toggleSelectedLine "<Plug>(comment_toggle_linewise_visual)" {desc = mappings.toggleSelectedLine.description;})
(mkKeymap "x" cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" {desc = mappings.toggleSelectedBlock.description;})
]; ];
}; };
}; };

View file

@ -1,4 +1,5 @@
{ {
options,
config, config,
lib, lib,
... ...
@ -6,13 +7,11 @@
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.attrsets) mapAttrs; inherit (lib.attrsets) mapAttrs;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding mkSetLuaLznBinding; inherit (lib.nvim.binds) mkKeymap;
inherit (lib.nvim.dag) entryAnywhere entryAfter; inherit (lib.nvim.dag) entryAnywhere entryAfter;
cfg = config.vim.debugger.nvim-dap; cfg = config.vim.debugger.nvim-dap;
self = import ./nvim-dap.nix {inherit lib;}; inherit (options.vim.debugger.nvim-dap) mappings;
mappingDefinitions = self.options.vim.debugger.nvim-dap.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in { in {
config = mkMerge [ config = mkMerge [
(mkIf cfg.enable { (mkIf cfg.enable {
@ -29,24 +28,24 @@ in {
} }
// mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources; // mapAttrs (_: v: (entryAfter ["nvim-dap"] v)) cfg.sources;
maps.normal = mkMerge [ keymaps = [
(mkSetLuaBinding mappings.continue "require('dap').continue") (mkKeymap "n" cfg.mappings.continue "require('dap').continue" {desc = mappings.continue.description;})
(mkSetLuaBinding mappings.restart "require('dap').restart") (mkKeymap "n" cfg.mappings.restart "require('dap').restart" {desc = mappings.restart.description;})
(mkSetLuaBinding mappings.terminate "require('dap').terminate") (mkKeymap "n" cfg.mappings.terminate "require('dap').terminate" {desc = mappings.terminate.description;})
(mkSetLuaBinding mappings.runLast "require('dap').run_last") (mkKeymap "n" cfg.mappings.runLast "require('dap').run_last" {desc = mappings.runLast.description;})
(mkSetLuaBinding mappings.toggleRepl "require('dap').repl.toggle") (mkKeymap "n" cfg.mappings.toggleRepl "require('dap').repl.toggle" {desc = mappings.toggleRepl.description;})
(mkSetLuaBinding mappings.hover "require('dap.ui.widgets').hover") (mkKeymap "n" cfg.mappings.hover "require('dap.ui.widgets').hover" {desc = mappings.hover.description;})
(mkSetLuaBinding mappings.toggleBreakpoint "require('dap').toggle_breakpoint") (mkKeymap "n" cfg.mappings.toggleBreakpoint "require('dap').toggle_breakpoint" {desc = mappings.toggleBreakpoint.description;})
(mkSetLuaBinding mappings.runToCursor "require('dap').run_to_cursor") (mkKeymap "n" cfg.mappings.runToCursor "require('dap').run_to_cursor" {desc = mappings.runToCursor.description;})
(mkSetLuaBinding mappings.stepInto "require('dap').step_into") (mkKeymap "n" cfg.mappings.stepInto "require('dap').step_into" {desc = mappings.stepInto.description;})
(mkSetLuaBinding mappings.stepOut "require('dap').step_out") (mkKeymap "n" cfg.mappings.stepOut "require('dap').step_out" {desc = mappings.stepOut.description;})
(mkSetLuaBinding mappings.stepOver "require('dap').step_over") (mkKeymap "n" cfg.mappings.stepOver "require('dap').step_over" {desc = mappings.stepOver.description;})
(mkSetLuaBinding mappings.stepBack "require('dap').step_back") (mkKeymap "n" cfg.mappings.stepBack "require('dap').step_back" {desc = mappings.stepBack.description;})
(mkSetLuaBinding mappings.goUp "require('dap').up") (mkKeymap "n" cfg.mappings.goUp "require('dap').up" {desc = mappings.goUp.description;})
(mkSetLuaBinding mappings.goDown "require('dap').down") (mkKeymap "n" cfg.mappings.goDown "require('dap').down" {desc = mappings.goDown.description;})
]; ];
}; };
}) })
@ -60,7 +59,7 @@ in {
inherit (cfg.ui) setupOpts; inherit (cfg.ui) setupOpts;
keys = [ keys = [
(mkSetLuaLznBinding "n" mappings.toggleDapUI "function() require('dapui').toggle() end") (mkKeymap "n" cfg.mappings.toggleDapUI "function() require('dapui').toggle() end" {desc = mappings.toggleDapUI.description;})
]; ];
}; };

View file

@ -6,7 +6,7 @@
}: let }: let
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkLznBinding; inherit (lib.nvim.binds) mkKeymap;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.binds) pushDownDefault; inherit (lib.nvim.binds) pushDownDefault;
@ -27,10 +27,10 @@ in {
cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"]; cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"];
keys = [ keys = [
(mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description) (mkKeymap "n" cfg.mappings.toggle ":NvimTreeToggle<cr>" {desc = mappings.toggle.description;})
(mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description) (mkKeymap "n" cfg.mappings.refresh ":NvimTreeRefresh<cr>" {desc = mappings.refresh.description;})
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description) (mkKeymap "n" cfg.mappings.findFile ":NvimTreeFindFile<cr>" {desc = mappings.findFile.description;})
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description) (mkKeymap "n" cfg.mappings.focus ":NvimTreeFocus<cr>" {desc = mappings.focus.description;})
]; ];
}; };

View file

@ -5,12 +5,11 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding pushDownDefault; inherit (lib.nvim.binds) mkKeymap pushDownDefault;
cfg = config.vim.lsp; cfg = config.vim.lsp;
mappingDefinitions = options.vim.lsp.trouble.mappings; inherit (options.vim.lsp.trouble) mappings;
mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions;
in { in {
config = mkIf (cfg.enable && cfg.trouble.enable) { config = mkIf (cfg.enable && cfg.trouble.enable) {
vim = { vim = {
@ -21,12 +20,12 @@ in {
cmd = "Trouble"; cmd = "Trouble";
keys = [ keys = [
(mkSetLznBinding "n" mappings.workspaceDiagnostics "<cmd>Trouble toggle diagnostics<CR>") (mkKeymap "n" cfg.trouble.mappings.workspaceDiagnostics "<cmd>Trouble toggle diagnostics<CR>" {desc = mappings.workspaceDiagnostics.description;})
(mkSetLznBinding "n" mappings.documentDiagnostics "<cmd>Trouble toggle diagnostics filter.buf=0<CR>") (mkKeymap "n" cfg.trouble.mappings.documentDiagnostics "<cmd>Trouble toggle diagnostics filter.buf=0<CR>" {desc = mappings.documentDiagnostics.description;})
(mkSetLznBinding "n" mappings.lspReferences "<cmd>Trouble toggle lsp_references<CR>") (mkKeymap "n" cfg.trouble.mappings.lspReferences "<cmd>Trouble toggle lsp_references<CR>" {desc = mappings.lspReferences.description;})
(mkSetLznBinding "n" mappings.quickfix "<cmd>Trouble toggle quickfix<CR>") (mkKeymap "n" cfg.trouble.mappings.quickfix "<cmd>Trouble toggle quickfix<CR>" {desc = mappings.quickfix.description;})
(mkSetLznBinding "n" mappings.locList "<cmd>Trouble toggle loclist<CR>") (mkKeymap "n" cfg.trouble.mappings.locList "<cmd>Trouble toggle loclist<CR>" {desc = mappings.locList.description;})
(mkSetLznBinding "n" mappings.symbols "<cmd>Trouble toggle symbols<CR>") (mkKeymap "n" cfg.trouble.mappings.symbols "<cmd>Trouble toggle symbols<CR>" {desc = mappings.symbols.description;})
]; ];
}; };

View file

@ -7,7 +7,7 @@
inherit (lib.lists) optional; inherit (lib.lists) optional;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.meta) getExe; inherit (lib.meta) getExe;
inherit (lib.nvim.binds) mkLznBinding; inherit (lib.nvim.binds) mkKeymap;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.terminal.toggleterm; cfg = config.vim.terminal.toggleterm;
@ -19,7 +19,7 @@ in {
package = "toggleterm-nvim"; package = "toggleterm-nvim";
cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"]; cmd = ["ToggleTerm" "ToggleTermSendCurrentLine" "ToggleTermSendVisualLines" "ToggleTermSendVisualSelection" "ToggleTermSetName" "ToggleTermToggleAll"];
keys = keys =
[(mkLznBinding ["n"] cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" "Toggle terminal")] [(mkKeymap "n" cfg.mappings.open "<Cmd>execute v:count . \"ToggleTerm\"<CR>" {desc = "Toggle terminal";})]
++ optional cfg.lazygit.enable { ++ optional cfg.lazygit.enable {
key = cfg.lazygit.mappings.open; key = cfg.lazygit.mappings.open;
mode = "n"; mode = "n";

View file

@ -4,7 +4,7 @@
... ...
}: let }: let
inherit (lib.modules) mkIf mkDefault; inherit (lib.modules) mkIf mkDefault;
inherit (lib.nvim.binds) mkLznBinding; inherit (lib.nvim.binds) mkKeymap;
cfg = config.vim.utility.motion.leap; cfg = config.vim.utility.motion.leap;
in { in {
@ -14,11 +14,11 @@ in {
lazy.plugins.leap-nvim = { lazy.plugins.leap-nvim = {
package = "leap-nvim"; package = "leap-nvim";
keys = [ keys = [
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" "Leap forward to") (mkKeymap ["n" "o" "x"] cfg.mappings.leapForwardTo "<Plug>(leap-forward-to)" {desc = "Leap forward to";})
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" "Leap backward to") (mkKeymap ["n" "o" "x"] cfg.mappings.leapBackwardTo "<Plug>(leap-backward-to)" {desc = "Leap backward to";})
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" "Leap forward till") (mkKeymap ["n" "o" "x"] cfg.mappings.leapForwardTill "<Plug>(leap-forward-till)" {desc = "Leap forward till";})
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" "Leap backward till") (mkKeymap ["n" "o" "x"] cfg.mappings.leapBackwardTill "<Plug>(leap-backward-till)" {desc = "Leap backward till";})
(mkLznBinding ["n" "o" "x"] cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" "Leap from window") (mkKeymap ["n" "o" "x"] cfg.mappings.leapFromWindow "<Plug>(leap-from-window)" {desc = "Leap from window";})
]; ];
after = '' after = ''

View file

@ -5,15 +5,14 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) addDescriptionsToMappings;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.lists) optionals; inherit (lib.lists) optionals;
inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding; inherit (lib.nvim.binds) pushDownDefault mkKeymap;
cfg = config.vim.telescope; cfg = config.vim.telescope;
mappingDefinitions = options.vim.telescope.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; keys = cfg.mappings;
inherit (options.vim.telescope) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
@ -34,39 +33,35 @@ in {
keys = keys =
[ [
(mkSetLznBinding "n" mappings.findFiles "<cmd>Telescope find_files<CR>") (mkKeymap "n" keys.findFiles "<cmd>Telescope find_files<CR>" {desc = mappings.findFiles.description;})
(mkSetLznBinding "n" mappings.liveGrep "<cmd>Telescope live_grep<CR>") (mkKeymap "n" keys.liveGrep "<cmd>Telescope live_grep<CR>" {desc = mappings.liveGrep.description;})
(mkSetLznBinding "n" mappings.buffers "<cmd>Telescope buffers<CR>") (mkKeymap "n" keys.buffers "<cmd>Telescope buffers<CR>" {desc = mappings.buffers.description;})
(mkSetLznBinding "n" mappings.helpTags "<cmd>Telescope help_tags<CR>") (mkKeymap "n" keys.helpTags "<cmd>Telescope help_tags<CR>" {desc = mappings.helpTags.description;})
(mkSetLznBinding "n" mappings.open "<cmd>Telescope<CR>") (mkKeymap "n" keys.open "<cmd>Telescope<CR>" {desc = mappings.open.description;})
(mkSetLznBinding "n" mappings.resume "<cmd>Telescope resume<CR>") (mkKeymap "n" keys.resume "<cmd>Telescope resume<CR>" {desc = mappings.resume.description;})
(mkSetLznBinding "n" mappings.gitCommits "<cmd>Telescope git_commits<CR>") (mkKeymap "n" keys.gitCommits "<cmd>Telescope git_commits<CR>" {desc = mappings.gitCommits.description;})
(mkSetLznBinding "n" mappings.gitBufferCommits "<cmd>Telescope git_bcommits<CR>") (mkKeymap "n" keys.gitBufferCommits "<cmd>Telescope git_bcommits<CR>" {desc = mappings.gitBufferCommits.description;})
(mkSetLznBinding "n" mappings.gitBranches "<cmd>Telescope git_branches<CR>") (mkKeymap "n" keys.gitBranches "<cmd>Telescope git_branches<CR>" {desc = mappings.gitBranches.description;})
(mkSetLznBinding "n" mappings.gitStatus "<cmd>Telescope git_status<CR>") (mkKeymap "n" keys.gitStatus "<cmd>Telescope git_status<CR>" {desc = mappings.gitStatus.description;})
(mkSetLznBinding "n" mappings.gitStash "<cmd>Telescope git_stash<CR>") (mkKeymap "n" keys.gitStash "<cmd>Telescope git_stash<CR>" {desc = mappings.gitStash.description;})
] ]
++ (optionals config.vim.lsp.enable [ ++ (optionals config.vim.lsp.enable [
(mkSetLznBinding "n" mappings.lspDocumentSymbols "<cmd>Telescope lsp_document_symbols<CR>") (mkKeymap "n" keys.lspDocumentSymbols "<cmd>Telescope lsp_document_symbols<CR>" {desc = mappings.lspDocumentSymbols.description;})
(mkSetLznBinding "n" mappings.lspWorkspaceSymbols "<cmd>Telescope lsp_workspace_symbols<CR>") (mkKeymap "n" keys.lspWorkspaceSymbols "<cmd>Telescope lsp_workspace_symbols<CR>" {desc = mappings.lspWorkspaceSymbols.description;})
(mkSetLznBinding "n" mappings.lspReferences "<cmd>Telescope lsp_references<CR>") (mkKeymap "n" keys.lspReferences "<cmd>Telescope lsp_references<CR>" {desc = mappings.lspReferences.description;})
(mkSetLznBinding "n" mappings.lspImplementations "<cmd>Telescope lsp_implementations<CR>") (mkKeymap "n" keys.lspImplementations "<cmd>Telescope lsp_implementations<CR>" {desc = mappings.lspImplementations.description;})
(mkSetLznBinding "n" mappings.lspDefinitions "<cmd>Telescope lsp_definitions<CR>") (mkKeymap "n" keys.lspDefinitions "<cmd>Telescope lsp_definitions<CR>" {desc = mappings.lspDefinitions.description;})
(mkSetLznBinding "n" mappings.lspTypeDefinitions "<cmd>Telescope lsp_type_definitions<CR>") (mkKeymap "n" keys.lspTypeDefinitions "<cmd>Telescope lsp_type_definitions<CR>" {desc = mappings.lspTypeDefinitions.description;})
(mkSetLznBinding "n" mappings.diagnostics "<cmd>Telescope diagnostics<CR>") (mkKeymap "n" keys.diagnostics "<cmd>Telescope diagnostics<CR>" {desc = mappings.diagnostics.description;})
]) ])
++ ( ++ optionals config.vim.treesitter.enable [
optionals config.vim.treesitter.enable [ (mkKeymap "n" keys.treesitter "<cmd>Telescope treesitter<CR>" {desc = mappings.treesitter.description;})
(mkSetLznBinding "n" mappings.treesitter "<cmd>Telescope treesitter<CR>") ]
] ++ optionals config.vim.projects.project-nvim.enable [
) (mkKeymap "n" keys.findProjects "<cmd>Telescope projects<CR>" {desc = mappings.findProjects.description;})
++ ( ];
optionals config.vim.projects.project-nvim.enable [
(mkSetLznBinding "n" mappings.findProjects "<cmd>Telescope projects<CR>")
]
);
}; };
binds.whichKey.register = pushDownDefault { binds.whichKey.register = pushDownDefault {