Compare commits

...

5 commits

Author SHA1 Message Date
Ching Pei Yang
b2eafaf8d6 nvim-tree: load nvim-tree if openOnSetup 2024-08-03 16:59:41 +02:00
Ching Pei Yang
dfd9172371 lib: add lznKeySpec example 2024-08-03 16:39:16 +02:00
Ching Pei Yang
f29664626b nvim-tree: move to lz.n keymaps 2024-08-03 16:39:16 +02:00
Ching Pei Yang
085d5d304a lz.n: process key maps 2024-08-03 14:45:48 +02:00
Ching Pei Yang
4efc5d89d0 remove unused 2024-08-03 14:45:29 +02:00
3 changed files with 38 additions and 18 deletions

View file

@ -57,13 +57,6 @@
};
lznKeysSpec = submodule {
apply = x:
x
// {
"@1" = x.lhs;
"@2" = x.rhs;
};
options = {
desc = mkOption {
description = "Description of the key map";
@ -193,7 +186,12 @@
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); # TODO: support lz.n.KeysSpec
type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]);
example = ''
keys = [
{lhs = "<leader>s"; rhs = ":NvimTreeToggle<cr>"; desc = "Toggle NvimTree"}
]
'';
};
# TODO: enabled, beforeAll, colorscheme, priority, load

View file

@ -4,6 +4,7 @@
pkgs,
...
}: let
inherit (builtins) filter;
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) mkBinding;
@ -13,16 +14,13 @@
cfg = config.vim.filetree.nvimTree;
self = import ./nvimtree.nix {inherit pkgs lib;};
mkNormalBinding = lhs: rhs: desc: {
inherit lhs rhs desc;
mode = ["n"];
};
inherit (self.options.vim.filetree.nvimTree) mappings;
in {
config = mkIf cfg.enable {
vim.maps.normal = mkMerge [
(mkBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
(mkBinding cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkBinding cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
vim.binds.whichKey.register = pushDownDefault {
"<leader>t" = "+NvimTree";
};
@ -34,6 +32,13 @@ in {
setupModule = "nvim-tree";
inherit (cfg) setupOpts;
cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"];
keys = filter ({lhs, ...}: lhs != null) [
(mkNormalBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkNormalBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
(mkNormalBinding cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkNormalBinding cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
};
};
};
@ -49,6 +54,7 @@ in {
${
optionalString cfg.openOnSetup ''
require('lz.n').trigger_load("nvim-tree-lua")
-- autostart behaviour
-- Open on startup has been deprecated
-- see https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup

View file

@ -9,11 +9,26 @@
inherit (lib.generators) mkLuaInline;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.dag) entryBefore;
cfg = config.vim.lazy;
toLuzLznKeySpec = {
desc,
noremap,
expr,
nowait,
ft,
lhs,
rhs,
mode,
}: {
"@1" = lhs;
"@2" = rhs;
inherit desc noremap expr nowait ft mode;
};
toLuaLznSpec = name: spec:
(removeAttrs spec ["package" "setupModule" "setupOpts"])
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
// {
"@1" = name;
after = mkLuaInline ''
@ -25,6 +40,7 @@
${optionalString (spec.after != null) spec.after}
end
'';
keys = map toLuzLznKeySpec spec.keys;
};
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
in {
@ -33,7 +49,7 @@ in {
optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
luaConfigRC.lzn-load = entryAnywhere ''
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
require('lz.n').load(${toLuaObject lznSpecs})
'';
};