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

View file

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

View file

@ -34,9 +34,20 @@ in {
# Add the typst compiler to nixvim packages
extraPackages = with pkgs; [typst];
maps.normal = with cfg.keymaps;
helpers.mkModeMaps {inherit silent;} {
${watch} = ":TypstWatch<CR>";
};
keymaps = with cfg.keymaps;
helpers.mkKeymaps
{
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 {
extraPlugins = [pkgs.vimPlugins.nvim-lspconfig];
maps.normal = let
keymaps = let
mkMaps = prefix:
mapAttrs
(key: action: let
actionStr =
if isString action
then action
else action.action;
actionProps =
if isString action
then {}
else filterAttrs (n: v: n != "action") action;
in
{
inherit (cfg.keymaps) silent;
mapAttrsToList
(
key: action: let
actionStr =
if isString action
then action
else action.action;
actionProps =
if isString action
then {}
else filterAttrs (n: v: n != "action") action;
in {
mode = "n";
inherit key;
action = prefix + actionStr;
lua = true;
options =
{
inherit (cfg.keymaps) silent;
}
// actionProps;
}
// actionProps);
);
in
mkMerge [
(mkMaps "vim.diagnostic." cfg.keymaps.diagnostic)
(mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf)
];
(mkMaps "vim.diagnostic." cfg.keymaps.diagnostic)
++ (mkMaps "vim.lsp.buf." cfg.keymaps.lspBuf);
# Enable all LSP servers
extraConfigLua = ''

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -140,6 +140,12 @@
};
"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 = ",";
action = "<cmd>echo \"test\"<cr>";
}
{
mode = ["n" "s"];
};
};
key = "<C-p>";
action = "<cmd>echo \"test\"<cr>";
}
];
};
mkMaps = {

View file

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