2024-01-24 22:49:29 +01:00
|
|
|
{
|
|
|
|
lib,
|
2024-01-25 15:43:06 +01:00
|
|
|
nixvimOptions,
|
2024-02-19 10:29:19 +01:00
|
|
|
nixvimUtils,
|
2024-01-24 22:49:29 +01:00
|
|
|
}:
|
2024-05-05 19:39:35 +02:00
|
|
|
with lib;
|
|
|
|
{
|
|
|
|
mkVimPlugin =
|
|
|
|
config:
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
url ? if defaultPackage != null then defaultPackage.meta.homepage else null,
|
|
|
|
maintainers,
|
|
|
|
imports ? [ ],
|
|
|
|
description ? null,
|
|
|
|
# deprecations
|
|
|
|
deprecateExtraConfig ? false,
|
|
|
|
optionsRenamedToSettings ? [ ],
|
|
|
|
# colorscheme
|
|
|
|
isColorscheme ? false,
|
|
|
|
colorscheme ? name,
|
|
|
|
# options
|
|
|
|
originalName ? name,
|
|
|
|
defaultPackage ? null,
|
|
|
|
settingsOptions ? { },
|
|
|
|
settingsExample ? null,
|
|
|
|
globalPrefix ? "",
|
|
|
|
extraOptions ? { },
|
|
|
|
# config
|
|
|
|
extraConfig ? cfg: { },
|
|
|
|
extraPlugins ? [ ],
|
|
|
|
extraPackages ? [ ],
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
namespace = if isColorscheme then "colorschemes" else "plugins";
|
2024-03-08 12:06:00 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
cfg = config.${namespace}.${name};
|
2024-01-24 22:49:29 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
globals = cfg.settings or { };
|
2024-02-12 16:13:52 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
# does this evaluate package?
|
|
|
|
packageOption =
|
|
|
|
if defaultPackage == null then
|
|
|
|
{ }
|
|
|
|
else
|
2024-05-17 14:09:20 +02:00
|
|
|
{ package = nixvimOptions.mkPluginPackageOption name defaultPackage; };
|
2024-01-24 22:49:29 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
createSettingsOption = (isString globalPrefix) && (globalPrefix != "");
|
2024-02-12 12:07:50 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
settingsOption = optionalAttrs createSettingsOption {
|
2024-02-12 16:13:52 +01:00
|
|
|
settings = nixvimOptions.mkSettingsOption {
|
|
|
|
options = settingsOptions;
|
|
|
|
example = settingsExample;
|
2024-01-24 22:49:29 +01:00
|
|
|
description = ''
|
2024-03-01 23:02:09 +01:00
|
|
|
The configuration options for **${name}** without the `${globalPrefix}` prefix.
|
|
|
|
|
2024-06-29 01:02:51 +00:00
|
|
|
For example, the following settings are equivialent to these `:setglobal` commands:
|
|
|
|
- `foo_bar = 1` -> `:setglobal ${globalPrefix}foo_bar=1`
|
|
|
|
- `hello = "world"` -> `:setglobal ${globalPrefix}hello="world"`
|
|
|
|
- `some_toggle = true` -> `:setglobal ${globalPrefix}some_toggle`
|
|
|
|
- `other_toggle = false` -> `:setglobal no${globalPrefix}other_toggle`
|
2024-01-24 22:49:29 +01:00
|
|
|
'';
|
|
|
|
};
|
2024-02-12 12:07:50 +01:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
inherit maintainers;
|
|
|
|
nixvimInfo = {
|
|
|
|
inherit description name url;
|
|
|
|
kind = namespace;
|
|
|
|
};
|
2024-02-20 21:20:59 +01:00
|
|
|
};
|
2024-05-05 19:39:35 +02:00
|
|
|
options.${namespace}.${name} = {
|
2024-02-13 23:25:13 +01:00
|
|
|
enable = mkEnableOption originalName;
|
2024-05-05 19:39:35 +02:00
|
|
|
} // settingsOption // packageOption // extraOptions;
|
2024-01-24 22:49:29 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
imports =
|
|
|
|
let
|
|
|
|
basePluginPath = [
|
|
|
|
namespace
|
|
|
|
name
|
|
|
|
];
|
|
|
|
settingsPath = basePluginPath ++ [ "settings" ];
|
|
|
|
in
|
|
|
|
imports
|
|
|
|
++ (optional (deprecateExtraConfig && createSettingsOption) (
|
|
|
|
mkRenamedOptionModule (basePluginPath ++ [ "extraConfig" ]) settingsPath
|
|
|
|
))
|
|
|
|
++ (map (
|
|
|
|
option:
|
|
|
|
let
|
|
|
|
optionPath = if isString option then [ option ] else option; # option is already a path (i.e. a list)
|
2024-02-19 10:29:19 +01:00
|
|
|
|
|
|
|
optionPathSnakeCase = map nixvimUtils.toSnakeCase optionPath;
|
|
|
|
in
|
2024-05-05 19:39:35 +02:00
|
|
|
mkRenamedOptionModule (basePluginPath ++ optionPath) (settingsPath ++ optionPathSnakeCase)
|
|
|
|
) optionsRenamedToSettings);
|
2024-02-12 12:07:50 +01:00
|
|
|
|
2024-05-05 19:39:35 +02:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
inherit extraPackages;
|
|
|
|
globals = mapAttrs' (n: nameValuePair (globalPrefix + n)) globals;
|
|
|
|
# does this evaluate package? it would not be desired to evaluate package if we use another package.
|
|
|
|
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
|
|
|
|
}
|
2024-05-28 21:22:35 +02:00
|
|
|
(optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; })
|
2024-05-05 19:39:35 +02:00
|
|
|
(extraConfig cfg)
|
|
|
|
]);
|
|
|
|
};
|
2024-01-24 22:49:29 +01:00
|
|
|
}
|