-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
{ | ||
lib, | ||
helpers, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
inherit (lib) mkOption; | ||
inherit (helpers) | ||
mkNullOrLuaFn' | ||
nixvimTypes | ||
keymaps | ||
defaultNullOpts | ||
; | ||
|
||
name = "lz-n"; | ||
originalName = "lz.n"; | ||
|
||
mkLazyLoadOption = | ||
{ | ||
originalName ? "this plugin", | ||
}: | ||
let | ||
pluginDefault = { | ||
name = originalName; | ||
}; | ||
in | ||
mkOption { | ||
description = "Lazy-load settings for ${originalName}."; | ||
type = | ||
with nixvimTypes; | ||
submodule { | ||
options = with defaultNullOpts; { | ||
name = mkOption { | ||
type = str; | ||
default = pluginDefault.name or null; | ||
description = "The plugin's name (not the module name). This is what is passed to the load(name) function."; | ||
}; | ||
enabledInSpec = mkStrLuaFnOr bool pluginDefault.enabledInSpec or null '' | ||
When false, or if the function returns false, then ${originalName} will not be included in the spec. | ||
This option corresponds to the `enabled` property of lz.n. | ||
''; | ||
beforeAll = mkLuaFn pluginDefault.beforeAll | ||
or null "Always executed before any plugins are loaded."; | ||
before = mkLuaFn pluginDefault.before or null "Executed before ${originalName} is loaded."; | ||
after = mkLuaFn pluginDefault.after or null "Executed after ${originalName} is loaded."; | ||
event = | ||
mkNullable (listOf str) pluginDefault.event or null | ||
"Lazy-load on event. Events can be specified as BufEnter or with a pattern like BufEnter *.lua"; | ||
cmd = mkNullable (listOf str) pluginDefault.cmd or null "Lazy-load on command."; | ||
ft = mkNullable (listOf str) pluginDefault.ft or null "Lazy-load on filetype."; | ||
keys = mkNullable (listOf keymaps.mapOptionSubmodule) pluginDefault.keys | ||
or null "Lazy-load on key mapping. Use the same format as `config.keymaps`."; | ||
colorscheme = mkNullable (listOf str) pluginDefault.colorscheme or null "Lazy-load on colorscheme."; | ||
priority = mkNullable number pluginDefault.priority or null '' | ||
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first. | ||
Default priority is 50 (or 1000 if colorscheme is set). | ||
''; | ||
load = mkLuaFn pluginDefault.load | ||
or null "Can be used to override the vim.g.lz_n.load() function for ${originalName}."; | ||
}; | ||
}; | ||
default = pluginDefault; | ||
}; | ||
in | ||
with lib; | ||
helpers.neovim-plugin.mkNeovimPlugin config { | ||
inherit name originalName; | ||
maintainers = with helpers.maintainers; [ psfloyd ]; | ||
defaultPackage = pkgs.vimPlugins.lz-n; | ||
|
||
settingsDescription = '' | ||
The configuration options for **${originalName}** using `vim.g.lz_n`. | ||
`{ load = "fun"; }` -> `vim.g.lz_n = { load = fun, }` | ||
''; | ||
|
||
settingsOptions = { | ||
load = mkNullOrLuaFn' { | ||
description = '' | ||
Function used by `lz.n` to load plugins. | ||
''; | ||
default = null; | ||
pluginDefault = "vim.cmd.packadd"; | ||
}; | ||
}; | ||
|
||
settingsExample = { | ||
load = "vim.cmd.packadd"; | ||
}; | ||
|
||
callSetup = false; # Does not use setup | ||
|
||
extraOptions = with nixvimTypes; { | ||
plugins = mkOption { | ||
description = "List of plugins processed by lz.n"; | ||
default = [ ]; | ||
type = listOf (mkLazyLoadOption { }).type; | ||
}; | ||
}; | ||
|
||
extraConfig = cfg: { | ||
globals.lz_n = cfg.settings; | ||
extraConfigLua = | ||
let | ||
processKeymap = | ||
keymaps: | ||
if keymaps == null then | ||
null | ||
else | ||
map ( | ||
keymap: | ||
{ | ||
__unkeyed_1 = keymap.key; | ||
__unkeyed_2 = keymap.action; | ||
inherit (keymap) mode; | ||
} | ||
// keymap.options | ||
) keymaps; | ||
pluginToLua = plugin: { | ||
"__unkeyed" = plugin.name; | ||
inherit (plugin) | ||
beforeAll | ||
before | ||
after | ||
event | ||
cmd | ||
ft | ||
colorscheme | ||
priority | ||
load | ||
; | ||
enabled = plugin.enabledInSpec; | ||
keys = processKeymap plugin.keys; | ||
}; | ||
pluginListToLua = map pluginToLua; | ||
plugins = pluginListToLua cfg.plugins; | ||
pluginSpecs = if length plugins == 1 then head plugins else plugins; | ||
in | ||
mkIf (cfg.plugins != [ ]) '' | ||
require('lz.n').load( | ||
${helpers.toLuaObject pluginSpecs} | ||
) | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ pkgs, ... }: | ||
{ | ||
# Empty configuration | ||
empty = { | ||
plugins.lz-n.enable = true; | ||
}; | ||
|
||
# Settings | ||
example = { | ||
plugins.lz-n = { | ||
enable = true; | ||
settings = { | ||
load = "vim.cmd.packadd"; | ||
}; | ||
}; | ||
|
||
}; | ||
|
||
test = { | ||
extraPlugins = with pkgs.vimPlugins; [ | ||
neo-tree-nvim | ||
vimtex | ||
telescope-nvim | ||
nvim-biscuits | ||
onedarker-nvim | ||
]; | ||
plugins.treesitter.enable = true; | ||
plugins.lz-n = { | ||
enable = true; | ||
plugins = [ | ||
# enabledInSpec, on keys | ||
{ | ||
name = "neo-tree.nvim"; | ||
enabledInSpec = '' | ||
function() | ||
return false | ||
end | ||
''; | ||
keys = [ | ||
{ | ||
mode = [ "n" ]; | ||
key = "<leader>ft"; | ||
action = "<CMD>Neotree toggle<CR>"; | ||
options = { | ||
desc = "NeoTree toggle"; | ||
}; | ||
} | ||
{ | ||
mode = [ | ||
"n" | ||
"v" | ||
]; | ||
key = "gft"; | ||
action = "<CMD>Neotree toggle<CR>"; | ||
options = { | ||
desc = "NeoTree toggle"; | ||
}; | ||
} | ||
]; | ||
after = # lua | ||
'' | ||
function() | ||
require("neo-tree").setup() | ||
end | ||
''; | ||
} | ||
# beforeAll, before, on filetype | ||
{ | ||
name = "vimtex"; | ||
ft = [ "plaintex" ]; | ||
beforeAll = # lua | ||
'' | ||
function() | ||
vim.g.vimtex_compiler_method = "latexrun" | ||
end | ||
''; | ||
before = # lua | ||
'' | ||
function() | ||
vim.g.vimtex_compiler_method = "latexmk" | ||
end | ||
''; | ||
} | ||
# On event | ||
{ | ||
name = "nvim-biscuits"; | ||
event = [ "BufEnter *.lua" ]; | ||
after = '' | ||
function() | ||
require('nvim-biscuits').setup({}) | ||
end | ||
''; | ||
} | ||
# On command no setup function, priority | ||
{ | ||
name = "telescope.nvim"; | ||
cmd = [ "Telescope" ]; | ||
priority = 500; | ||
} | ||
# On colorschme | ||
{ | ||
name = "onedarker.nvim"; | ||
colorscheme = [ "onedarker" ]; | ||
} | ||
]; | ||
}; | ||
}; | ||
|
||
} |