Skip to content

Commit 1f96fda

Browse files
committed
lib/options: added mkLazyLoadOption
1 parent e1b6607 commit 1f96fda

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

lib/options.nix

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,108 @@ rec {
366366
else
367367
example;
368368
};
369+
370+
mkLazyLoadOption =
371+
{
372+
originalName,
373+
lazyLoadDefaults ? { },
374+
}:
375+
let
376+
pluginDefault = {
377+
enable = false;
378+
} // lazyLoadDefaults;
379+
in
380+
mkOption {
381+
description = ''
382+
Lazy-load settings for ${originalName}.
383+
'';
384+
type =
385+
with helpers.nixvimTypes;
386+
let
387+
triggerType = oneOf [
388+
rawLua
389+
str
390+
(listOf str)
391+
];
392+
in
393+
submodule {
394+
options = with defaultNullOpts; {
395+
396+
enable = mkOption {
397+
type = bool;
398+
default = pluginDefault.enable;
399+
description = ''
400+
Enable lazy-loading for ${originalName}
401+
'';
402+
};
403+
404+
# Spec loading:
405+
enabled = mkStrLuaFnOr bool pluginDefault.enabledInSpec or null ''
406+
When false, or if the function returns false, then ${originalName} will not be included in the spec.
407+
Equivalence: lz.n => enabled; lazy.nvim => enabled
408+
'';
409+
410+
priority = mkNullable number pluginDefault.priority or null ''
411+
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
412+
Equivalence: lz.n => priority; lazy.nvim => priority
413+
'';
414+
415+
# Spec setup
416+
# Actions
417+
beforeAll = mkLuaFn pluginDefault.beforeAll or null ''
418+
Always executed before any plugins are loaded.
419+
Equivalence: lz.n => beforeAll; lazy.nvim => init
420+
'';
421+
422+
before = mkLuaFn pluginDefault.before or null ''
423+
Executed before ${originalName} is loaded.
424+
Equivalence: lz.n => before; lazy.nvim => None
425+
'';
426+
427+
after = mkLuaFn pluginDefault.after or null ''
428+
Executed after ${originalName} is loaded.
429+
Equivalence: lz.n => after; lazy.nvim => config
430+
'';
431+
432+
# Triggers
433+
event = mkNullable triggerType pluginDefault.event or null ''
434+
Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua`
435+
Equivalence: lz.n => event; lazy.nvim => event
436+
'';
437+
438+
cmd = mkNullable triggerType pluginDefault.cmd or null ''
439+
Lazy-load on command.
440+
Equivalence: lz.n => cmd; lazy.nvim => cmd
441+
'';
442+
443+
ft = mkNullable triggerType pluginDefault.ft or null ''
444+
Lazy-load on filetype.
445+
Equivalence: lz.n => ft; lazy.nvim => ft
446+
'';
447+
448+
keys = mkNullable (listOf helpers.keymaps.mapOptionSubmodule) pluginDefault.keys or null ''
449+
Lazy-load on key mapping. Use the same format as `config.keymaps`.
450+
Equivalence: lz.n => keys; lazy.nvim => keys
451+
'';
452+
453+
colorscheme = mkNullable triggerType pluginDefault.colorscheme or null ''
454+
Lazy-load on colorscheme.
455+
Equivalence: lz.n => colorscheme; lazy.nvim => None
456+
'';
457+
458+
extraSettings = mkSettingsOption {
459+
description = ''
460+
Extra settings to pass to the lazy loader backend.
461+
'';
462+
example = {
463+
dependencies = {
464+
__unkeyed-1 = "nvim-lua/plenary.nvim";
465+
lazy = true;
466+
};
467+
};
468+
};
469+
};
470+
};
471+
default = pluginDefault;
472+
};
369473
}

0 commit comments

Comments
 (0)