plugins/misc: adapt to new maps options

This commit is contained in:
Gaetan Lepage 2023-09-15 14:35:13 +02:00 committed by Gaétan Lepage
parent 574fb73258
commit dd6a114e52
18 changed files with 262 additions and 193 deletions

View file

@ -57,7 +57,7 @@ with lib; let
} }
// bufferOptions; // bufferOptions;
keymaps = { keymapsActions = {
previous = "Previous"; previous = "Previous";
next = "Next"; next = "Next";
movePrevious = "MovePrevious"; movePrevious = "MovePrevious";
@ -227,7 +227,7 @@ in {
optionName: funcName: optionName: funcName:
helpers.mkNullOrOption types.str "Keymap for function Buffer${funcName}" helpers.mkNullOrOption types.str "Keymap for function Buffer${funcName}"
) )
keymaps keymapsActions
); );
}; };
@ -326,20 +326,25 @@ in {
} }
// cfg.extraOptions; // cfg.extraOptions;
userKeymapsList = keymaps =
mapAttrsToList flatten
( (
optionName: funcName: let mapAttrsToList
key = cfg.keymaps.${optionName}; (
in optionName: funcName: let
mkIf (key != null) { key = cfg.keymaps.${optionName};
${key} = { in
optional
(key != null)
{
mode = "n";
inherit key;
action = "<Cmd>Buffer${funcName}<CR>"; action = "<Cmd>Buffer${funcName}<CR>";
inherit (cfg.keymaps) silent; options.silent = cfg.keymaps.silent;
}; }
} )
) keymapsActions
keymaps; );
in in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = with pkgs.vimPlugins; [ extraPlugins = with pkgs.vimPlugins; [
@ -347,7 +352,7 @@ in {
nvim-web-devicons nvim-web-devicons
]; ];
maps.normal = mkMerge userKeymapsList; inherit keymaps;
extraConfigLua = '' extraConfigLua = ''
require('barbar').setup(${helpers.toLuaObject setupOptions}) require('barbar').setup(${helpers.toLuaObject setupOptions})

View file

@ -93,19 +93,19 @@ in
// cfg.extraConfig // cfg.extraConfig
); );
maps.normal = mkMerge ( keymaps = flatten (
mapAttrsToList mapAttrsToList
( (
name: value: let name: value: let
key = cfg.keymaps.${name}; key = cfg.keymaps.${name};
in in
if key == null optional
then {} (key != null)
else { {
${key} = { mode = "n";
action = ":JuliaCell${value.cmd}<CR>"; inherit key;
inherit (cfg.keymaps) silent; action = ":JuliaCell${value.cmd}<CR>";
}; options.silent = cfg.keymaps.silent;
} }
) )
mappings mappings

View file

@ -34,9 +34,20 @@ in {
# Add the typst compiler to nixvim packages # Add the typst compiler to nixvim packages
extraPackages = with pkgs; [typst]; extraPackages = with pkgs; [typst];
maps.normal = with cfg.keymaps; keymaps = with cfg.keymaps;
helpers.mkModeMaps {inherit silent;} { helpers.mkKeymaps
${watch} = ":TypstWatch<CR>"; {
}; mode = "n";
options.silent = silent;
}
(
optional
(watch != null)
{
# mode = "n";
key = watch;
action = ":TypstWatch<CR>";
}
);
}; };
} }

View file

@ -110,30 +110,35 @@ in {
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = [pkgs.vimPlugins.nvim-lspconfig]; extraPlugins = [pkgs.vimPlugins.nvim-lspconfig];
maps.normal = let keymaps = let
mkMaps = prefix: mkMaps = prefix:
mapAttrs mapAttrsToList
(key: action: let (
actionStr = key: action: let
if isString action actionStr =
then action if isString action
else action.action; then action
actionProps = else action.action;
if isString action actionProps =
then {} if isString action
else filterAttrs (n: v: n != "action") action; then {}
in else filterAttrs (n: v: n != "action") action;
{ in {
inherit (cfg.keymaps) silent; mode = "n";
inherit key;
action = prefix + actionStr; action = prefix + actionStr;
lua = true; lua = true;
options =
{
inherit (cfg.keymaps) silent;
}
// actionProps;
} }
// actionProps); );
in in
mkMerge [ (mkMaps "vim.diagnostic." cfg.keymaps.diagnostic)
(mkMaps "vim.diagnostic." cfg.keymaps.diagnostic) ++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf);
(mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf)
];
# Enable all LSP servers # Enable all LSP servers
extraConfigLua = '' extraConfigLua = ''

View file

@ -83,24 +83,31 @@ in {
let $BAT_THEME = '${cfg.highlightTheme}' let $BAT_THEME = '${cfg.highlightTheme}'
''; '';
maps.normal = keymaps =
mapAttrs mapAttrsToList
(key: action: let (
actionStr = key: action: let
if isString action actionStr =
then action if isString action
else action.action; then action
actionProps = else action.action;
if isString action actionProps =
then {} if isString action
else filterAttrs (n: v: n != "action") action; then {}
in else filterAttrs (n: v: n != "action") action;
{ in {
silent = cfg.keymapsSilent; mode = "n";
inherit key;
action = "require('telescope.builtin').${actionStr}"; action = "require('telescope.builtin').${actionStr}";
lua = true; lua = true;
options =
{
silent = cfg.keymapsSilent;
}
// actionProps;
} }
// actionProps) )
cfg.keymaps; cfg.keymaps;
extraConfigLua = let extraConfigLua = let

View file

@ -142,16 +142,14 @@ in {
require('auto-save').setup(${helpers.toLuaObject options}) require('auto-save').setup(${helpers.toLuaObject options})
''; '';
maps.normal = with cfg.keymaps; let keymaps = with cfg.keymaps;
inherit (cfg.keymaps) silent; optional
in (toggle != null)
mkMerge [ {
(mkIf (toggle != null) { mode = "n";
${toggle} = { key = toggle;
action = ":ASToggle<CR>"; action = ":ASToggle<CR>";
inherit silent; options.silent = cfg.keymaps.silent;
}; };
})
];
}; };
} }

View file

@ -299,21 +299,24 @@ in {
require("coverage").setup(${helpers.toLuaObject setupOptions}) require("coverage").setup(${helpers.toLuaObject setupOptions})
''; '';
maps.normal = mkMerge ( keymaps =
mapAttrsToList flatten
( (
optionName: properties: let mapAttrsToList
key = cfg.keymaps.${optionName}; (
in optionName: properties: let
mkIf (key != null) key = cfg.keymaps.${optionName};
{ in
${key} = { optional
(key != null)
{
mode = "n";
inherit key;
action = ":Coverage${properties.command}<CR>"; action = ":Coverage${properties.command}<CR>";
silent = cfg.keymapsSilent; options.silent = cfg.keymapsSilent;
}; }
} )
) keymapsDef
keymapsDef );
);
}; };
} }

View file

@ -187,22 +187,20 @@ in {
require('harpoon').setup(${helpers.toLuaObject options}) require('harpoon').setup(${helpers.toLuaObject options})
''; '';
maps.normal = let keymaps = let
silent = cfg.keymapsSilent;
km = cfg.keymaps; km = cfg.keymaps;
simpleMappings = mkMerge ( simpleMappings = flatten (
mapAttrsToList mapAttrsToList
( (
optionName: luaFunc: let optionName: luaFunc: let
key = km.${optionName}; key = km.${optionName};
in in
mkIf (key != null) { optional
${key} = { (key != null)
action = luaFunc; {
lua = true; inherit key;
inherit silent; action = luaFunc;
};
} }
) )
{ {
@ -217,38 +215,44 @@ in {
mkNavMappings = name: genLuaFunc: let mkNavMappings = name: genLuaFunc: let
mappingsAttrs = km.${name}; mappingsAttrs = km.${name};
in in
mkIf flatten
(mappingsAttrs != null)
( (
mapAttrs' optionals
(id: key: { (mappingsAttrs != null)
name = key; (
value = { mapAttrsToList
(id: key: {
inherit key;
action = genLuaFunc id; action = genLuaFunc id;
lua = true; })
inherit silent; mappingsAttrs
}; )
})
mappingsAttrs
); );
in
mkMerge [ allMappings =
simpleMappings simpleMappings
( ++ (
mkNavMappings mkNavMappings
"navFile" "navFile"
(id: "function() require('harpoon.ui').nav_file(${id}) end") (id: "function() require('harpoon.ui').nav_file(${id}) end")
) )
( ++ (
mkNavMappings mkNavMappings
"gotoTerminal" "gotoTerminal"
(id: "function() require('harpoon.term').gotoTerminal(${id}) end") (id: "function() require('harpoon.term').gotoTerminal(${id}) end")
) )
( ++ (
mkNavMappings mkNavMappings
"tmuxGotoTerminal" "tmuxGotoTerminal"
(id: "function() require('harpoon.tmux').gotoTerminal(${id}) end") (id: "function() require('harpoon.tmux').gotoTerminal(${id}) end")
) );
]; in
helpers.mkKeymaps
{
mode = "n";
lua = true;
options.silent = cfg.keymapsSilent;
}
allMappings;
}; };
} }

View file

@ -19,7 +19,14 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
maps.insert."<Tab>" = "<CMD>lua require([[intellitab]]).indent()<CR>"; keymaps = [
{
mode = "i";
key = "<Tab>";
action = "require('intellitab').indent";
lua = true;
}
];
plugins.treesitter = { plugins.treesitter = {
indent = true; indent = true;
}; };

View file

@ -181,21 +181,23 @@ in {
require("neogen").setup(${helpers.toLuaObject setupOptions}) require("neogen").setup(${helpers.toLuaObject setupOptions})
''; '';
maps.normal = mkMerge ( keymaps =
mapAttrsToList flatten
( (
optionName: properties: let mapAttrsToList
key = cfg.keymaps.${optionName}; (
in optionName: properties: let
mkIf (key != null) key = cfg.keymaps.${optionName};
{ in
${key} = { optional (key != null)
{
mode = "n";
inherit key;
action = ":Neogen ${properties.command}<CR>"; action = ":Neogen ${properties.command}<CR>";
silent = cfg.keymapsSilent; options.silent = cfg.keymapsSilent;
}; }
} )
) keymapDef
keymapDef );
);
}; };
} }

View file

@ -19,6 +19,7 @@ in
keymaps = { keymaps = {
enable = mkEnableOption "keymaps for copying using OSC52"; enable = mkEnableOption "keymaps for copying using OSC52";
silent = mkOption { silent = mkOption {
type = types.bool; type = types.bool;
description = "Wether nvim-osc52 keymaps should be silent"; description = "Wether nvim-osc52 keymaps should be silent";
@ -55,28 +56,36 @@ in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
maps = mkIf cfg.keymaps.enable { keymaps = with cfg.keymaps;
normal = { mkIf enable
"${cfg.keymaps.copy}" = { [
{
mode = "n";
key = copy;
action = "require('osc52').copy_operator"; action = "require('osc52').copy_operator";
expr = true;
lua = true; lua = true;
inherit (cfg.keymaps) silent; options = {
}; expr = true;
"${cfg.keymaps.copyLine}" = { inherit silent;
action = "${cfg.keymaps.copy}_"; };
remap = true; }
inherit (cfg.keymaps) silent; {
}; mode = "n";
}; key = copyLine;
visual = { action = "${copy}_";
"${cfg.keymaps.copyVisual}" = { options = {
remap = true;
inherit silent;
};
}
{
mode = "v";
key = copyVisual;
action = "require('osc52').copy_visual"; action = "require('osc52').copy_visual";
lua = true; lua = true;
inherit (cfg.keymaps) silent; options.silent = silent;
}; }
}; ];
};
extraConfigLua = '' extraConfigLua = ''
require('osc52').setup(${helpers.toLuaObject setupOptions}) require('osc52').setup(${helpers.toLuaObject setupOptions})

View file

@ -27,11 +27,13 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
maps.normal = mkIf (cfg.keymap.key != null) { keymaps = with cfg.keymap;
${cfg.keymap.key} = { optional (key != null)
{
mode = "n";
inherit key;
action = ":Quickmath<CR>"; action = ":Quickmath<CR>";
inherit (cfg.keymap) silent; options.silent = cfg.keymap.silent;
}; };
};
}; };
} }

View file

@ -52,25 +52,25 @@ in {
// cfg.extraOptions; // cfg.extraOptions;
mappings = mappings =
mapAttrs' mapAttrsToList
(motion: key: { (
name = key; motion: key: {
value = { mode = ["n" "o" "x"];
inherit key;
action = "function() require('spider').motion('${motion}') end"; action = "function() require('spider').motion('${motion}') end";
lua = true; lua = true;
inherit (cfg.keymaps) silent; options = {
desc = "Spider-${motion}"; inherit (cfg.keymaps) silent;
}; desc = "Spider-${motion}";
}) };
}
)
cfg.keymaps.motions; cfg.keymaps.motions;
in in
mkIf cfg.enable { mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
maps = keymaps = mappings;
genAttrs
["normal" "operator" "visualOnly"]
(mode: mappings);
extraConfigLua = '' extraConfigLua = ''
require("${pluginName}").setup(${helpers.toLuaObject setupOptions}) require("${pluginName}").setup(${helpers.toLuaObject setupOptions})

View file

@ -264,27 +264,24 @@ in {
require("todo-comments").setup${helpers.toLuaObject setupOptions} require("todo-comments").setup${helpers.toLuaObject setupOptions}
''; '';
maps.normal = let keymaps =
silent = cfg.keymapsSilent; flatten
inherit (cfg) keymaps; (
in
mkMerge (
mapAttrsToList mapAttrsToList
( (
optionName: funcName: let optionName: funcName: let
keymap = keymaps.${optionName}; keymap = cfg.keymaps.${optionName};
inherit (keymap) key;
cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}"; cwd = optionalString (keymap.cwd != null) " cwd=${keymap.cwd}";
keywords = optionalString (keymap.keywords != null) " keywords=${keymap.keywords}"; keywords = optionalString (keymap.keywords != null) " keywords=${keymap.keywords}";
action = ":${funcName}${cwd}${keywords}<CR>";
in in
mkIf (keymap != null) { optional
${key} = { (keymap != null)
inherit silent action; {
}; mode = "n";
inherit (keymap) key;
action = ":${funcName}${cwd}${keywords}<CR>";
options.silent = cfg.keymapsSilent;
} }
) )
commands commands

View file

@ -33,20 +33,29 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
extraPlugins = [cfg.package]; extraPlugins = [cfg.package];
maps.normal = with cfg.keymaps; keymaps = with cfg.keymaps;
(optionalAttrs (bdelete != null) helpers.mkKeymaps
{ {
${bdelete} = { mode = "n";
options.silent = cfg.keymapsSilent;
}
(
(
optional
(bdelete != null)
{
key = bdelete;
action = ":Bdelete<CR>"; action = ":Bdelete<CR>";
silent = cfg.keymapsSilent; }
}; )
}) ++ (
// (optionalAttrs (bwipeout != null) optional
{ (bwipeout != null)
${bwipeout} = { {
key = bwipeout;
action = ":Bwipeout<CR>"; action = ":Bwipeout<CR>";
silent = cfg.keymapsSilent; }
}; )
}); );
}; };
} }

View file

@ -140,6 +140,12 @@
}; };
"71" = { "71" = {
maps.normal."<leader>hb" = "<cmd>lua require('gitsigns').blame_line{full=true}<cr>"; keymaps = [
{
mode = "n";
key = "<leader>hb";
action = "<cmd>lua require('gitsigns').blame_line{full=true}<cr>";
}
];
}; };
} }

View file

@ -38,9 +38,13 @@
{ {
key = ","; key = ",";
action = "<cmd>echo \"test\"<cr>"; action = "<cmd>echo \"test\"<cr>";
}
{
mode = ["n" "s"]; mode = ["n" "s"];
}; key = "<C-p>";
}; action = "<cmd>echo \"test\"<cr>";
}
];
}; };
mkMaps = { mkMaps = {

View file

@ -87,6 +87,6 @@
}; };
}; };
# Simple mapping with only Description # Simple mapping with only Description
maps.normal."ff".desc = "Test"; maps.byMode.normal."ff".options.desc = "Test";
}; };
} }