|
| 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 | +} |
0 commit comments