Compare commits

...

7 commits

Author SHA1 Message Date
Ching Pei Yang
275f78f683
Merge f43d3835f1 into 773186d93d 2024-08-03 16:43:18 +00:00
Ching Pei Yang
f43d3835f1 nvim-tree: load nvim-tree if openOnSetup 2024-08-03 18:42:53 +02:00
Ching Pei Yang
664d7154b4 nvim-tree: move to lz.n keymaps 2024-08-03 18:42:53 +02:00
Ching Pei Yang
42c60df933 lib: add mkLznBinding 2024-08-03 18:42:53 +02:00
Ching Pei Yang
b437242689 lib: change lz.n spec "inlineLua" types to str 2024-08-03 18:42:53 +02:00
Ching Pei Yang
c6071b7da4 lz.n: missing type check 2024-08-03 18:42:52 +02:00
Ching Pei Yang
4d51981179 lib: add lznKeySpec example 2024-08-03 18:42:12 +02:00
4 changed files with 32 additions and 19 deletions

View file

@ -67,6 +67,10 @@
mkLuaBinding binding.value action binding.description;
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
mkLznBinding = mode: lhs: rhs: desc: {
inherit mode lhs rhs desc;
};
};
in
binds

View file

@ -138,14 +138,14 @@
# lz.n options
before = mkOption {
type = nullOr luaInline;
description = "Code to run before plugin is loaded";
type = nullOr str;
description = "Lua code to run before plugin is loaded. This will be wrapped in a function.";
default = null;
};
after = mkOption {
type = nullOr luaInline;
description = "Code to run after plugin is loaded";
type = nullOr str;
description = "Lua code to run after plugin is loaded. This will be wrapped in a function.";
default = null;
};
@ -186,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,11 +4,11 @@
pkgs,
...
}: let
inherit (builtins) filter;
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) mkBinding;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.binds) pushDownDefault;
cfg = config.vim.filetree.nvimTree;
@ -16,13 +16,6 @@
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 +27,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) [
(mkLznBinding ["n"] cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkLznBinding ["n"] cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
(mkLznBinding ["n"] cfg.mappings.findFile ":NvimTreeFindFile<cr>" mappings.findFile.description)
(mkLznBinding ["n"] cfg.mappings.focus ":NvimTreeFocus<cr>" mappings.focus.description)
];
};
};
};
@ -49,6 +49,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

@ -3,13 +3,13 @@
config,
...
}: let
inherit (builtins) toJSON;
inherit (builtins) toJSON typeOf head length;
inherit (lib.modules) mkIf;
inherit (lib.attrsets) mapAttrsToList;
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 = {
@ -40,7 +40,10 @@
${optionalString (spec.after != null) spec.after}
end
'';
keys = map toLuzLznKeySpec spec.keys;
keys =
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
then map toLuzLznKeySpec spec.keys
else spec.keys;
};
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
in {
@ -49,7 +52,7 @@ in {
optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
luaConfigRC.lzn-load = entryAnywhere ''
luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
require('lz.n').load(${toLuaObject lznSpecs})
'';
};