Skip to content

Commit 648f988

Browse files
committed
plugins/lz-n: init
1 parent 3fc6938 commit 648f988

File tree

3 files changed

+257
-0
lines changed

3 files changed

+257
-0
lines changed

plugins/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118

119119
./pluginmanagers/packer.nix
120120
./pluginmanagers/lazy.nix
121+
./pluginmanagers/lz-n.nix
121122

122123
./snippets/friendly-snippets.nix
123124
./snippets/luasnip

plugins/pluginmanagers/lz-n.nix

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
lib,
3+
helpers,
4+
config,
5+
pkgs,
6+
...
7+
}:
8+
let
9+
inherit (lib) mkOption;
10+
inherit (helpers)
11+
mkNullOrLuaFn'
12+
nixvimTypes
13+
keymaps
14+
defaultNullOpts
15+
;
16+
17+
name = "lz-n";
18+
originalName = "lz.n";
19+
20+
mkLazyLoadOption =
21+
{
22+
originalName ? "this plugin",
23+
}:
24+
let
25+
pluginDefault = {
26+
name = originalName;
27+
};
28+
in
29+
mkOption {
30+
description = "Lazy-load settings for ${originalName}.";
31+
type =
32+
with nixvimTypes;
33+
submodule {
34+
options = with defaultNullOpts; {
35+
name = mkOption {
36+
type = str;
37+
default = pluginDefault.name or null;
38+
description = "The plugin's name (not the module name). This is what is passed to the load(name) function.";
39+
};
40+
enabledInSpec = mkStrLuaFnOr bool pluginDefault.enabledInSpec or null ''
41+
When false, or if the function returns false, then ${originalName} will not be included in the spec.
42+
This option corresponds to the `enabled` property of lz.n.
43+
'';
44+
beforeAll = mkLuaFn pluginDefault.beforeAll
45+
or null "Always executed before any plugins are loaded.";
46+
before = mkLuaFn pluginDefault.before or null "Executed before ${originalName} is loaded.";
47+
after = mkLuaFn pluginDefault.after or null "Executed after ${originalName} is loaded.";
48+
event =
49+
mkNullable (listOf str) pluginDefault.event or null
50+
"Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua";
51+
cmd = mkNullable (listOf str) pluginDefault.cmd or null "Lazy-load on command.";
52+
ft = mkNullable (listOf str) pluginDefault.ft or null "Lazy-load on filetype.";
53+
keys = mkNullable (listOf keymaps.mapOptionSubmodule) pluginDefault.keys
54+
or null "Lazy-load on key mapping. Use the same format as `config.keymaps`.";
55+
colorscheme = mkNullable (listOf str) pluginDefault.colorscheme or null "Lazy-load on colorscheme.";
56+
priority = mkNullable number pluginDefault.priority or null ''
57+
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
58+
Default priority is 50 (or 1000 if colorscheme is set).
59+
'';
60+
load = mkLuaFn pluginDefault.load
61+
or null "Can be used to override the vim.g.lz_n.load() function for ${originalName}.";
62+
};
63+
};
64+
default = pluginDefault;
65+
};
66+
in
67+
with lib;
68+
helpers.neovim-plugin.mkNeovimPlugin config {
69+
inherit name originalName;
70+
maintainers = with helpers.maintainers; [ psfloyd ];
71+
defaultPackage = pkgs.vimPlugins.lz-n;
72+
73+
settingsDescription = ''
74+
The configuration options for **${originalName}** using `vim.g.lz_n`.
75+
76+
`{ load = "fun"; }` -> `vim.g.lz_n = { load = fun, }`
77+
'';
78+
79+
settingsOptions = {
80+
load = mkNullOrLuaFn' {
81+
description = ''
82+
Function used by `lz.n` to load plugins.
83+
'';
84+
default = null;
85+
pluginDefault = "vim.cmd.packadd";
86+
};
87+
};
88+
89+
settingsExample = {
90+
load = "vim.cmd.packadd";
91+
};
92+
93+
callSetup = false; # Does not use setup
94+
95+
extraOptions = with nixvimTypes; {
96+
plugins = mkOption {
97+
description = "List of plugins processed by lz.n";
98+
default = [ ];
99+
type = listOf (mkLazyLoadOption { }).type;
100+
};
101+
};
102+
103+
extraConfig = cfg: {
104+
globals.lz_n = cfg.settings;
105+
extraConfigLua =
106+
let
107+
processKeymap =
108+
keymaps:
109+
if keymaps == null then
110+
null
111+
else
112+
map (
113+
keymap:
114+
{
115+
__unkeyed_1 = keymap.key;
116+
__unkeyed_2 = keymap.action;
117+
inherit (keymap) mode;
118+
}
119+
// keymap.options
120+
) keymaps;
121+
pluginToLua = plugin: {
122+
"__unkeyed" = plugin.name;
123+
inherit (plugin)
124+
beforeAll
125+
before
126+
after
127+
event
128+
cmd
129+
ft
130+
colorscheme
131+
priority
132+
load
133+
;
134+
enabled = plugin.enabledInSpec;
135+
keys = processKeymap plugin.keys;
136+
};
137+
pluginListToLua = map pluginToLua;
138+
plugins = pluginListToLua cfg.plugins;
139+
pluginSpecs = if length plugins == 1 then head plugins else plugins;
140+
in
141+
mkIf (cfg.plugins != [ ]) ''
142+
require('lz.n').load(
143+
${helpers.toLuaObject pluginSpecs}
144+
)
145+
'';
146+
};
147+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{ pkgs, ... }:
2+
{
3+
# Empty configuration
4+
empty = {
5+
plugins.lz-n.enable = true;
6+
};
7+
8+
# Settings
9+
example = {
10+
plugins.lz-n = {
11+
enable = true;
12+
settings = {
13+
load = "vim.cmd.packadd";
14+
};
15+
};
16+
17+
};
18+
19+
test = {
20+
extraPlugins = with pkgs.vimPlugins; [
21+
neo-tree-nvim
22+
vimtex
23+
telescope-nvim
24+
nvim-biscuits
25+
onedarker-nvim
26+
];
27+
plugins.treesitter.enable = true;
28+
plugins.lz-n = {
29+
enable = true;
30+
plugins = [
31+
# enabledInSpec, on keys
32+
{
33+
name = "neo-tree.nvim";
34+
enabledInSpec = ''
35+
function()
36+
return false
37+
end
38+
'';
39+
keys = [
40+
{
41+
mode = [ "n" ];
42+
key = "<leader>ft";
43+
action = "<CMD>Neotree toggle<CR>";
44+
options = {
45+
desc = "NeoTree toggle";
46+
};
47+
}
48+
{
49+
mode = [
50+
"n"
51+
"v"
52+
];
53+
key = "gft";
54+
action = "<CMD>Neotree toggle<CR>";
55+
options = {
56+
desc = "NeoTree toggle";
57+
};
58+
}
59+
];
60+
after = # lua
61+
''
62+
function()
63+
require("neo-tree").setup()
64+
end
65+
'';
66+
}
67+
# beforeAll, before, on filetype
68+
{
69+
name = "vimtex";
70+
ft = [ "plaintex" ];
71+
beforeAll = # lua
72+
''
73+
function()
74+
vim.g.vimtex_compiler_method = "latexrun"
75+
end
76+
'';
77+
before = # lua
78+
''
79+
function()
80+
vim.g.vimtex_compiler_method = "latexmk"
81+
end
82+
'';
83+
}
84+
# On event
85+
{
86+
name = "nvim-biscuits";
87+
event = [ "BufEnter *.lua" ];
88+
after = ''
89+
function()
90+
require('nvim-biscuits').setup({})
91+
end
92+
'';
93+
}
94+
# On command no setup function, priority
95+
{
96+
name = "telescope.nvim";
97+
cmd = [ "Telescope" ];
98+
priority = 500;
99+
}
100+
# On colorschme
101+
{
102+
name = "onedarker.nvim";
103+
colorscheme = [ "onedarker" ];
104+
}
105+
];
106+
};
107+
};
108+
109+
}

0 commit comments

Comments
 (0)