Skip to content

Commit

Permalink
helpers: refactor mk[Neo]vimPlugin for colorschemes handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Mar 12, 2024
1 parent 61ee055 commit cf7102c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
14 changes: 7 additions & 7 deletions lib/neovim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ with lib; rec {

mkNeovimPlugin = config: {
name,
colorscheme ? false,
maintainers,
url ? defaultPackage.meta.homepage,
imports ? [],
# deprecations
deprecateExtraOptions ? false,
optionsRenamedToSettings ? [],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage,
Expand All @@ -53,7 +55,7 @@ with lib; rec {
callSetup ? true,
}: let
namespace =
if colorscheme
if isColorscheme
then "colorschemes"
else "plugins";
in {
Expand Down Expand Up @@ -114,7 +116,7 @@ with lib; rec {
config = let
cfg = config.${namespace}.${name};
extraConfigNamespace =
if colorscheme
if isColorscheme
then "extraConfigLuaPre"
else "extraConfigLua";
in
Expand All @@ -128,10 +130,8 @@ with lib; rec {
require('${luaName}').setup(${toLuaObject cfg.settings})
'';
}
(optionalAttrs colorscheme {
# We use `mkDefault` here to let individual plugins override this option.
# For instance, setting it to `null` a specific way of setting the coloscheme.
colorscheme = lib.mkDefault name;
(optionalAttrs (isColorscheme && (colorscheme != null)) {
inherit colorscheme;
})
(extraConfig cfg)
]
Expand Down
12 changes: 6 additions & 6 deletions lib/vim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
with lib; {
mkVimPlugin = config: {
name,
colorscheme ? false,
url ?
if defaultPackage != null
then defaultPackage.meta.homepage
Expand All @@ -16,6 +15,9 @@ with lib; {
# deprecations
deprecateExtraConfig ? false,
optionsRenamedToSettings ? [],
# colorscheme
isColorscheme ? false,
colorscheme ? name,
# options
originalName ? name,
defaultPackage ? null,
Expand All @@ -30,7 +32,7 @@ with lib; {
extraPackages ? [],
}: let
namespace =
if colorscheme
if isColorscheme
then "colorschemes"
else "plugins";

Expand Down Expand Up @@ -127,10 +129,8 @@ with lib; {
# does this evaluate package? it would not be desired to evaluate package if we use another package.
extraPlugins = extraPlugins ++ optional (defaultPackage != null) cfg.package;
}
(optionalAttrs colorscheme {
# We use `mkDefault` here to let individual plugins override this option.
# For instance, setting it to `null` a specific way of setting the coloscheme.
colorscheme = lib.mkDefault name;
(optionalAttrs (isColorscheme && (colorscheme != null)) {
inherit colorscheme;
})
(extraConfig cfg)
]
Expand Down
7 changes: 3 additions & 4 deletions plugins/colorschemes/ayu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
with lib;
helpers.neovim-plugin.mkNeovimPlugin config {
name = "ayu";
colorscheme = true;
isColorscheme = true;
originalName = "neovim-ayu";
defaultPackage = pkgs.vimPlugins.neovim-ayu;
# The colorscheme option is set by the `setup` function.
colorscheme = null;
callSetup = false;

maintainers = [maintainers.GaetanLepage];
Expand Down Expand Up @@ -42,9 +44,6 @@ with lib;
};

extraConfig = cfg: {
# The colorscheme option is set by the `setup` function.
colorscheme = null;

extraConfigLuaPre = ''
local ayu = require("ayu")
ayu.setup(${helpers.toLuaObject cfg.settings})
Expand Down
2 changes: 1 addition & 1 deletion plugins/colorschemes/gruvbox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:
helpers.neovim-plugin.mkNeovimPlugin config {
name = "gruvbox";
colorscheme = true;
isColorscheme = true;
originalName = "gruvbox.nvim";
defaultPackage = pkgs.vimPlugins.gruvbox-nvim;

Expand Down
2 changes: 1 addition & 1 deletion plugins/colorschemes/nord.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:
helpers.vim-plugin.mkVimPlugin config {
name = "nord";
colorscheme = true;
isColorscheme = true;
originalName = "nord.nvim";
defaultPackage = pkgs.vimPlugins.nord-nvim;
globalPrefix = "nord_";
Expand Down

0 comments on commit cf7102c

Please sign in to comment.