mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-16 23:33:50 +00:00
plugins: better compatability with nullable keybinds
Mostly involves filtering keybinds that are null in cases where the keybind is the attrname, and optionalString for manual lua keybind registration.
This commit is contained in:
parent
1cda8228e9
commit
f040b4a943
8 changed files with 185 additions and 155 deletions
|
|
@ -21,11 +21,11 @@
|
|||
'';
|
||||
|
||||
mkLuaKeymap = mode: key: action: desc: opts:
|
||||
opts
|
||||
mkIf (key != null) (opts
|
||||
// {
|
||||
inherit mode key action desc;
|
||||
lua = true;
|
||||
};
|
||||
});
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim = {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
}: let
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.attrsets) optionalAttrs;
|
||||
inherit (lib.attrsets) mapAttrs' optionalAttrs;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.attrsets) attrValues filterAttrs mapAttrsToList;
|
||||
inherit (lib.lists) map optional optionals elem;
|
||||
|
|
@ -98,14 +98,17 @@ in {
|
|||
preset = "luasnip";
|
||||
};
|
||||
|
||||
keymap = {
|
||||
${mappings.complete} = ["show" "fallback"];
|
||||
${mappings.close} = ["hide" "fallback"];
|
||||
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"];
|
||||
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"];
|
||||
${mappings.confirm} = ["accept" "fallback"];
|
||||
|
||||
${mappings.next} = [
|
||||
keymap =
|
||||
mapAttrs' (mapping-name: action: {
|
||||
name = mappings.${mapping-name};
|
||||
value = action;
|
||||
}) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) {
|
||||
complete = ["show" "fallback"];
|
||||
close = ["hide" "fallback"];
|
||||
scrollDocsUp = ["scroll_documentation_up" "fallback"];
|
||||
scrollDocsDown = ["scroll_documentation_down" "fallback"];
|
||||
confirm = ["accept" "fallback"];
|
||||
next = [
|
||||
"select_next"
|
||||
"snippet_forward"
|
||||
(mkLuaInline
|
||||
|
|
@ -122,27 +125,30 @@ in {
|
|||
'')
|
||||
"fallback"
|
||||
];
|
||||
${mappings.previous} = [
|
||||
previous = [
|
||||
"select_prev"
|
||||
"snippet_backward"
|
||||
"fallback"
|
||||
];
|
||||
};
|
||||
});
|
||||
|
||||
# cmdline is not enabled by default, we're just providing keymaps in
|
||||
# case the user enables them
|
||||
cmdline.keymap = {
|
||||
${mappings.complete} = ["show" "fallback"];
|
||||
${mappings.close} = ["hide" "fallback"];
|
||||
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"];
|
||||
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"];
|
||||
cmdline.keymap =
|
||||
mapAttrs' (mapping-name: action: {
|
||||
name = mappings.${mapping-name};
|
||||
value = action;
|
||||
}) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null) {
|
||||
complete = ["show" "fallback"];
|
||||
close = ["hide" "fallback"];
|
||||
scrollDocsUp = ["scroll_documentation_up" "fallback"];
|
||||
scrollDocsDown = ["scroll_documentation_down" "fallback"];
|
||||
# NOTE: mappings.confirm is skipped because our default, <CR> would
|
||||
# lead to accidental triggers of blink.accept instead of executing
|
||||
# the cmd
|
||||
|
||||
${mappings.next} = ["select_next" "show" "fallback"];
|
||||
${mappings.previous} = ["select_prev" "fallback"];
|
||||
};
|
||||
next = ["select_next" "show" "fallback"];
|
||||
previous = ["select_prev" "fallback"];
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.attrsets) filterAttrs mapAttrs';
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
|
|
@ -72,14 +73,19 @@ in {
|
|||
formatting.format = cfg.format;
|
||||
|
||||
# `cmp` and `luasnip` are defined above, in the `nvim-cmp` section
|
||||
mapping = {
|
||||
${mappings.complete} = mkLuaInline "cmp.mapping.complete()";
|
||||
${mappings.close} = mkLuaInline "cmp.mapping.abort()";
|
||||
${mappings.scrollDocsUp} = mkLuaInline "cmp.mapping.scroll_docs(-4)";
|
||||
${mappings.scrollDocsDown} = mkLuaInline "cmp.mapping.scroll_docs(4)";
|
||||
${mappings.confirm} = mkLuaInline "cmp.mapping.confirm({ select = true })";
|
||||
mapping =
|
||||
mapAttrs' (mapping-name: action: {
|
||||
name = mappings.${mapping-name};
|
||||
value = action;
|
||||
}) (filterAttrs (mapping-name: _action: mappings.${mapping-name} != null)
|
||||
{
|
||||
complete = mkLuaInline "cmp.mapping.complete()";
|
||||
close = mkLuaInline "cmp.mapping.abort()";
|
||||
scrollDocsUp = mkLuaInline "cmp.mapping.scroll_docs(-4)";
|
||||
scrollDocsDown = mkLuaInline "cmp.mapping.scroll_docs(4)";
|
||||
confirm = mkLuaInline "cmp.mapping.confirm({ select = true })";
|
||||
|
||||
${mappings.next} = mkLuaInline ''
|
||||
next = mkLuaInline ''
|
||||
cmp.mapping(function(fallback)
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
|
|
@ -100,7 +106,7 @@ in {
|
|||
end)
|
||||
'';
|
||||
|
||||
${mappings.previous} = mkLuaInline ''
|
||||
previous = mkLuaInline ''
|
||||
cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
|
|
@ -113,7 +119,7 @@ in {
|
|||
end
|
||||
end)
|
||||
'';
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -214,13 +214,20 @@ in {
|
|||
on_attach = function(client, bufnr)
|
||||
default_on_attach(client, bufnr)
|
||||
local opts = { noremap=true, silent=true, buffer = bufnr }
|
||||
|
||||
${optionalString config.vim.vendoredKeymaps ''
|
||||
vim.keymap.set("n", "<localleader>rr", ":RustLsp runnables<CR>", opts)
|
||||
vim.keymap.set("n", "<localleader>rp", ":RustLsp parentModule<CR>", opts)
|
||||
vim.keymap.set("n", "<localleader>rm", ":RustLsp expandMacro<CR>", opts)
|
||||
vim.keymap.set("n", "<localleader>rc", ":RustLsp openCargo", opts)
|
||||
vim.keymap.set("n", "<localleader>rg", ":RustLsp crateGraph x11", opts)
|
||||
${optionalString cfg.dap.enable ''
|
||||
''}
|
||||
|
||||
${optionalString (cfg.dap.enable && config.vim.vendoredKeymaps) ''
|
||||
vim.keymap.set("n", "<localleader>rd", ":RustLsp debuggables<cr>", opts)
|
||||
''}
|
||||
|
||||
${optionalString (cfg.dap.enable && config.vim.debugger.nvim-dap.mappings.continue != null) ''
|
||||
vim.keymap.set(
|
||||
"n", "${config.vim.debugger.nvim-dap.mappings.continue}",
|
||||
function()
|
||||
|
|
|
|||
|
|
@ -117,7 +117,9 @@ in {
|
|||
|
||||
local attach_metals_keymaps = function(client, bufnr)
|
||||
attach_keymaps(client, bufnr) -- from lsp-setup
|
||||
${optionalString (cfg.lsp.extraMappings.listCommands != null) ''
|
||||
vim.api.nvim_buf_set_keymap(bufnr, 'n', '${cfg.lsp.extraMappings.listCommands}', '<cmd>lua ${listCommandsAction}<CR>', {noremap=true, silent=true, desc='Show all Metals commands'})
|
||||
''}
|
||||
end
|
||||
|
||||
metals_config = require('metals').bare_config()
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@ in {
|
|||
end
|
||||
})
|
||||
|
||||
${optionalString (cfg.lazygit.mappings.open != null) ''
|
||||
vim.keymap.set('n', ${toLuaObject cfg.lazygit.mappings.open}, function() lazygit:toggle() end, {silent = true, noremap = true, desc = '${lazygitMapDesc}'})
|
||||
''}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.attrsets) filterAttrs mapAttrs';
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.lists) optionals;
|
||||
|
|
@ -30,46 +31,51 @@ in {
|
|||
];
|
||||
|
||||
vim.ui.breadcrumbs.navbuddy.setupOpts = {
|
||||
mappings = {
|
||||
${cfg.navbuddy.mappings.close} = mkLuaInline "actions.close()";
|
||||
${cfg.navbuddy.mappings.nextSibling} = mkLuaInline "actions.next_sibling()";
|
||||
${cfg.navbuddy.mappings.previousSibling} = mkLuaInline "actions.previous_sibling()";
|
||||
${cfg.navbuddy.mappings.parent} = mkLuaInline "actions.parent()";
|
||||
${cfg.navbuddy.mappings.children} = mkLuaInline "actions.children()";
|
||||
${cfg.navbuddy.mappings.root} = mkLuaInline "actions.root()";
|
||||
mappings =
|
||||
mapAttrs' (mapping-name: action: {
|
||||
name = cfg.navbuddy.mappings.${mapping-name};
|
||||
value = action;
|
||||
}) (filterAttrs (mapping-name: _action: cfg.navbuddy.mappings.${mapping-name} != null)
|
||||
{
|
||||
close = mkLuaInline "actions.close()";
|
||||
nextSibling = mkLuaInline "actions.next_sibling()";
|
||||
previousSibling = mkLuaInline "actions.previous_sibling()";
|
||||
parent = mkLuaInline "actions.parent()";
|
||||
children = mkLuaInline "actions.children()";
|
||||
root = mkLuaInline "actions.root()";
|
||||
|
||||
${cfg.navbuddy.mappings.visualName} = mkLuaInline "actions.visual_name()";
|
||||
${cfg.navbuddy.mappings.visualScope} = mkLuaInline "actions.visual_scope()";
|
||||
visualName = mkLuaInline "actions.visual_name()";
|
||||
visualScope = mkLuaInline "actions.visual_scope()";
|
||||
|
||||
${cfg.navbuddy.mappings.yankName} = mkLuaInline "actions.yank_name()";
|
||||
${cfg.navbuddy.mappings.yankScope} = mkLuaInline "actions.yank_scope()";
|
||||
yankName = mkLuaInline "actions.yank_name()";
|
||||
yankScope = mkLuaInline "actions.yank_scope()";
|
||||
|
||||
${cfg.navbuddy.mappings.insertName} = mkLuaInline "actions.insert_name()";
|
||||
${cfg.navbuddy.mappings.insertScope} = mkLuaInline "actions.insert_scope()";
|
||||
insertName = mkLuaInline "actions.insert_name()";
|
||||
insertScope = mkLuaInline "actions.insert_scope()";
|
||||
|
||||
${cfg.navbuddy.mappings.appendName} = mkLuaInline "actions.append_name()";
|
||||
${cfg.navbuddy.mappings.appendScope} = mkLuaInline "actions.append_scope()";
|
||||
appendName = mkLuaInline "actions.append_name()";
|
||||
appendScope = mkLuaInline "actions.append_scope()";
|
||||
|
||||
${cfg.navbuddy.mappings.rename} = mkLuaInline "actions.rename()";
|
||||
rename = mkLuaInline "actions.rename()";
|
||||
|
||||
${cfg.navbuddy.mappings.delete} = mkLuaInline "actions.delete()";
|
||||
delete = mkLuaInline "actions.delete()";
|
||||
|
||||
${cfg.navbuddy.mappings.foldCreate} = mkLuaInline "actions.fold_create()";
|
||||
${cfg.navbuddy.mappings.foldDelete} = mkLuaInline "actions.fold_delete()";
|
||||
foldCreate = mkLuaInline "actions.fold_create()";
|
||||
foldDelete = mkLuaInline "actions.fold_delete()";
|
||||
|
||||
${cfg.navbuddy.mappings.comment} = mkLuaInline "actions.comment()";
|
||||
comment = mkLuaInline "actions.comment()";
|
||||
|
||||
${cfg.navbuddy.mappings.select} = mkLuaInline "actions.select()";
|
||||
select = mkLuaInline "actions.select()";
|
||||
|
||||
${cfg.navbuddy.mappings.moveDown} = mkLuaInline "actions.move_down()";
|
||||
${cfg.navbuddy.mappings.moveUp} = mkLuaInline "actions.move_up()";
|
||||
moveDown = mkLuaInline "actions.move_down()";
|
||||
moveUp = mkLuaInline "actions.move_up()";
|
||||
|
||||
${cfg.navbuddy.mappings.togglePreview} = mkLuaInline "actions.toggle_preview()";
|
||||
togglePreview = mkLuaInline "actions.toggle_preview()";
|
||||
|
||||
${cfg.navbuddy.mappings.vsplit} = mkLuaInline "actions.vsplit()";
|
||||
${cfg.navbuddy.mappings.hsplit} = mkLuaInline "actions.hsplit()";
|
||||
vsplit = mkLuaInline "actions.vsplit()";
|
||||
hsplit = mkLuaInline "actions.hsplit()";
|
||||
|
||||
${cfg.navbuddy.mappings.telescope} = mkLuaInline ''
|
||||
telescope = mkLuaInline ''
|
||||
actions.telescope({
|
||||
layout_strategy = "horizontal",
|
||||
layout_config = {
|
||||
|
|
@ -79,8 +85,8 @@ in {
|
|||
preview_width = 0.50
|
||||
},
|
||||
})'';
|
||||
${cfg.navbuddy.mappings.help} = mkLuaInline "actions.help()";
|
||||
};
|
||||
help = mkLuaInline "actions.help()";
|
||||
});
|
||||
};
|
||||
|
||||
vim.pluginRC.breadcrumbs = entryAfter ["lspconfig"] ''
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.options) literalExpression mkOption;
|
||||
inherit (lib.types) bool str;
|
||||
inherit (lib.nvim.types) mkPluginSetupOption;
|
||||
|
||||
|
|
@ -64,7 +64,8 @@ in {
|
|||
|
||||
useVendoredKeybindings = mkOption {
|
||||
type = bool;
|
||||
default = true;
|
||||
default = config.vim.vendoredKeymaps;
|
||||
defaultText = literalExpression "config.vim.vendoredKeymaps";
|
||||
description = ''
|
||||
Use alternative set of keybindings that avoids conflicts with other popular plugins, e.g. nvim-leap
|
||||
'';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue