Skip to content

Commit 78abafe

Browse files
psfloydGaetanLepage
authored andcommitted
plugins/lz-n: init
1 parent 593f521 commit 78abafe

File tree

3 files changed

+371
-0
lines changed

3 files changed

+371
-0
lines changed

plugins/default.nix

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

120120
./pluginmanagers/packer.nix
121121
./pluginmanagers/lazy.nix
122+
./pluginmanagers/lz-n.nix
122123

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

plugins/pluginmanagers/lz-n.nix

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
{
2+
lib,
3+
options,
4+
config,
5+
pkgs,
6+
...
7+
}:
8+
with lib;
9+
let
10+
inherit (lib.nixvim) defaultNullOpts;
11+
in
12+
nixvim.neovim-plugin.mkNeovimPlugin config {
13+
name = "lz-n";
14+
originalName = "lz.n";
15+
maintainers = [ maintainers.psfloyd ];
16+
defaultPackage = pkgs.vimPlugins.lz-n;
17+
18+
settingsDescription = ''
19+
Options provided to `vim.g.lz_n`.
20+
21+
`{ load = "fun"; }` -> `vim.g.lz_n = { load = fun, }`
22+
'';
23+
24+
settingsOptions = {
25+
load = defaultNullOpts.mkLuaFn "vim.cmd.packadd" ''
26+
Function used by `lz.n` to load plugins.
27+
'';
28+
};
29+
30+
callSetup = false; # Does not use setup
31+
32+
extraOptions =
33+
let
34+
lzPluginType = types.submodule {
35+
freeformType = types.attrsOf types.anything;
36+
options = {
37+
__unkeyed-1 = mkOption {
38+
type = types.str;
39+
description = ''
40+
The "unkeyed" attribute is the plugin's name.
41+
This is passed to `load` function and should normally match the repo name of the plugin.
42+
43+
More specifically, this is the name of the folder in `/pack/opt/{name}` that is loaded with `load` (`packadd` by default).
44+
See `:h packadd`.
45+
'';
46+
};
47+
48+
enabled = nixvim.defaultNullOpts.mkStrLuaFnOr types.bool true ''
49+
When false, or if the function returns false, then this plugin will not be included in the spec.
50+
This option corresponds to the `enabled` property of lz.n.
51+
'';
52+
53+
beforeAll = nixvim.mkNullOrLuaFn ''
54+
Always executed before any plugins are loaded.
55+
'';
56+
57+
before = nixvim.mkNullOrLuaFn ''
58+
Executed before this plugin is loaded.
59+
'';
60+
61+
after = nixvim.mkNullOrLuaFn ''
62+
Executed after this plugin is loaded.
63+
'';
64+
65+
load = nixvim.mkNullOrLuaFn ''
66+
Can be used to override the `vim.g.lz_n.load()` function for this plugin.
67+
'';
68+
69+
priority = nixvim.defaultNullOpts.mkUnsignedInt (literalMD "`50` (or `1000` if `colorscheme` is set)") ''
70+
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
71+
'';
72+
73+
event = nixvim.mkNullOrOption' {
74+
type = types.anything;
75+
description = ''
76+
Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua
77+
'';
78+
example = [
79+
"BufEnter *.lua"
80+
"DeferredUIEnter"
81+
];
82+
};
83+
84+
cmd = nixvim.mkNullOrOption' {
85+
type = types.anything;
86+
description = ''
87+
Lazy-load on command.
88+
'';
89+
example = [
90+
"Neotree"
91+
"Telescope"
92+
];
93+
};
94+
95+
ft = nixvim.mkNullOrOption' {
96+
type = types.anything;
97+
description = ''
98+
Lazy-load on filetype.
99+
'';
100+
example = [ "tex" ];
101+
};
102+
103+
colorscheme = nixvim.mkNullOrOption' {
104+
type = types.anything;
105+
description = ''
106+
Lazy-load on colorscheme.
107+
'';
108+
example = "onedarker";
109+
};
110+
111+
keys = nixvim.mkNullOrOption' {
112+
type = types.listOf types.anything;
113+
description = ''
114+
Lazy-load on key mapping. Mode is `n` by default.
115+
'';
116+
example = [
117+
"<C-a>"
118+
[
119+
"<C-x>"
120+
"g<C-x>"
121+
]
122+
{
123+
__unkeyed-1 = "<leader>fb";
124+
__unkeyed-2 = "<CMD>Telescope buffers<CR>";
125+
desc = "Telescope buffers";
126+
}
127+
{ __raw = "{ '<leader>ft', '<CMD>Neotree toggle<CR>', desc = 'NeoTree toggle' }"; }
128+
];
129+
};
130+
};
131+
};
132+
in
133+
{
134+
plugins = mkOption {
135+
description = ''
136+
List of plugin specs provided to the `require('lz.n').load` function.
137+
Plugin specs can be ${nixvim.nixvimTypes.rawLua.description}.
138+
'';
139+
default = [ ];
140+
type = types.listOf lzPluginType;
141+
example = [
142+
{
143+
__unkeyed-1 = "neo-tree.nvim";
144+
enabled = ''
145+
function()
146+
return true
147+
end
148+
'';
149+
keys = [
150+
{
151+
__unkeyed-1 = "<leader>ft";
152+
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
153+
desc = "NeoTree toggle";
154+
}
155+
];
156+
after = ''
157+
function()
158+
require("neo-tree").setup()
159+
end
160+
'';
161+
}
162+
{
163+
__unkeyed-1 = "telescope.nvim";
164+
cmd = [ "Telescope" ];
165+
keys = [
166+
{
167+
__unkeyed-1 = "<leader>fa";
168+
__unkeyed-2 = "<CMD>Telescope autocommands<CR>";
169+
desc = "Telescope autocommands";
170+
}
171+
{
172+
__unkeyed-1 = "<leader>fb";
173+
__unkeyed-2 = "<CMD>Telescope buffers<CR>";
174+
desc = "Telescope buffers";
175+
}
176+
];
177+
}
178+
{
179+
__unkeyed-1 = "onedarker.nvim";
180+
colorscheme = [ "onedarker" ];
181+
}
182+
{
183+
__raw = ''
184+
{
185+
"crates.nvim",
186+
ft = "toml",
187+
},
188+
'';
189+
}
190+
];
191+
};
192+
};
193+
194+
extraConfig = cfg: {
195+
globals.lz_n = modules.mkAliasAndWrapDefsWithPriority id options.plugins.lz-n.settings;
196+
extraConfigLua = mkIf (cfg.plugins != [ ]) ''
197+
require('lz.n').load( ${nixvim.toLuaObject cfg.plugins})
198+
'';
199+
};
200+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
let
2+
/*
3+
Transform plugins into attrset and set optional to true
4+
This installs the plugin files to {runtimepath}/pack/opt, instead of {runtimepath}/pack/start.
5+
Plugins in pack/opt are not loaded on startup, but can be later loaded with `:packadd {name}` or `require("lz.n").load({name})`
6+
7+
See `nixpkgs/pkgs/applications/editors/neovim/utils.nix`
8+
See `nixpkgs/pkgs/applications/editors/vim/plugins/vim-utils.nix`
9+
*/
10+
optionalPlugins = map (x: (if x ? plugin then x else { plugin = x; }) // { optional = true; });
11+
in
12+
{
13+
# Empty configuration
14+
empty = {
15+
plugins.lz-n.enable = true;
16+
};
17+
18+
# Empty configuration
19+
defaults = {
20+
plugins.lz-n = {
21+
enable = true;
22+
settings = {
23+
load.__raw = "vim.cmd.packadd";
24+
};
25+
};
26+
};
27+
28+
# single-plugin and priority of plugins.lz-n.settings to globals.lz-n
29+
example-single-plugin = {
30+
module =
31+
{ pkgs, lib, ... }:
32+
{
33+
extraPlugins = optionalPlugins [ pkgs.vimPlugins.neo-tree-nvim ];
34+
35+
plugins.lz-n = {
36+
enable = true;
37+
settings = {
38+
load = lib.mkDefault "vim.cmd.packadd";
39+
};
40+
plugins = [
41+
# enabled, on keys as rawLua
42+
{
43+
__unkeyed-1 = "neo-tree.nvim";
44+
enabled = ''
45+
function()
46+
return true
47+
end
48+
'';
49+
keys = [
50+
{
51+
__unkeyed-1 = "<leader>ft";
52+
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
53+
desc = "NeoTree toggle";
54+
}
55+
];
56+
after = # lua
57+
''
58+
function()
59+
require("neo-tree").setup()
60+
end
61+
'';
62+
}
63+
];
64+
};
65+
};
66+
};
67+
68+
example-multiple-plugin = {
69+
module =
70+
{ pkgs, lib, ... }:
71+
{
72+
extraPlugins =
73+
with pkgs.vimPlugins;
74+
[ onedarker-nvim ]
75+
++ (optionalPlugins [
76+
neo-tree-nvim
77+
dial-nvim
78+
vimtex
79+
telescope-nvim
80+
nvim-biscuits
81+
crates-nvim
82+
]);
83+
84+
plugins.treesitter.enable = true;
85+
86+
plugins.lz-n = {
87+
enable = true;
88+
plugins = [
89+
# enabled, on keys
90+
{
91+
__unkeyed-1 = "neo-tree.nvim";
92+
enabled = ''
93+
function()
94+
return true
95+
end
96+
'';
97+
keys = [
98+
{
99+
__unkeyed-1 = "<leader>ft";
100+
__unkeyed-2 = "<CMD>Neotree toggle<CR>";
101+
desc = "NeoTree toggle";
102+
}
103+
];
104+
after = # lua
105+
''
106+
function()
107+
require("neo-tree").setup()
108+
end
109+
'';
110+
}
111+
# on keys as list of str and rawLua
112+
{
113+
__unkeyed-1 = "dial.nvim";
114+
keys = [
115+
"<C-a>"
116+
{ __raw = "{ '<C-x>'; mode = 'n' }"; }
117+
];
118+
}
119+
# beforeAll, before, on filetype
120+
{
121+
__unkeyed-1 = "vimtex";
122+
ft = [ "plaintex" ];
123+
beforeAll = # lua
124+
''
125+
function()
126+
vim.g.vimtex_compiler_method = "latexrun"
127+
end
128+
'';
129+
before = # lua
130+
''
131+
function()
132+
vim.g.vimtex_compiler_method = "latexmk"
133+
end
134+
'';
135+
}
136+
# On event
137+
{
138+
__unkeyed-1 = "nvim-biscuits";
139+
event.__raw = "{ 'BufEnter *.lua' }";
140+
after.__raw = ''
141+
function()
142+
require('nvim-biscuits').setup({})
143+
end
144+
'';
145+
}
146+
# On command no setup function, priority
147+
{
148+
__unkeyed-1 = "telescope.nvim";
149+
cmd = [ "Telescope" ];
150+
priority = 500;
151+
}
152+
# On colorschme
153+
{
154+
__unkeyed-1 = "onedarker.nvim";
155+
colorscheme = [ "onedarker" ];
156+
}
157+
# raw value
158+
{
159+
__raw = ''
160+
{
161+
"crates.nvim",
162+
ft = "toml",
163+
}
164+
'';
165+
}
166+
];
167+
};
168+
};
169+
};
170+
}

0 commit comments

Comments
 (0)