Skip to content

Commit

Permalink
plugins/instant: switch to mkPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Jan 14, 2024
1 parent 1a7a726 commit c29a33d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 94 deletions.
160 changes: 67 additions & 93 deletions plugins/utils/instant.nix
Original file line number Diff line number Diff line change
@@ -1,109 +1,83 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib; {
options.plugins.instant = {
enable = mkEnableOption "instant.nvim";

package = helpers.mkPackageOption "instant" pkgs.vimPlugins.instant-nvim;

username = mkOption {
type = with types; nullOr str;
description = ''
Username.
Explicitly set to `null` if you do not want this option to be set.
} @ args:
with lib;
with import ../helpers.nix {inherit lib;};
mkPlugin args {
name = "instant";
description = "instant.nvim";
package = pkgs.vimPlugins.instant-nvim;
globalPrefix = "instant_";

options = let
mkStr = global: default: desc:
mkDefaultOpt {
inherit global;
type = types.str;
description = ''
${desc}
Default: ${default}
'';
};
in {
username = mkDefaultOpt {
type = types.str;
description = ''
Username.
Explicitly set to `null` if you do not want this option to be set.
'';
};

onlyCwd = mkDefaultOpt {
type = types.bool;
description = ''
Choose whether to share files only in the current working directory in session mode.
Default: `true`
'';
};

cursorHlGroupUser1 = mkStr "cursor_hl_group_user_1" "Cursor" ''
Cursor highlight group for user 1.
'';
};

onlyCwd = helpers.defaultNullOpts.mkBool true ''
Choose whether to share files only in the current working directory in session mode.
'';

cursorHlGroupUser1 = helpers.defaultNullOpts.mkStr "Cursor" ''
Cursor highlight group for user 1.
'';

cursorHlGroupUser2 = helpers.defaultNullOpts.mkStr "Cursor" ''
Cursor highlight group for user 2.
'';

cursorHlGroupUser3 = helpers.defaultNullOpts.mkStr "Cursor" ''
Cursor highlight group for user 3.
'';

cursorHlGroupUser4 = helpers.defaultNullOpts.mkStr "Cursor" ''
Cursor highlight group for user 4.
'';

cursorHlGroupDefault = helpers.defaultNullOpts.mkStr "Cursor" ''
Cursor highlight group for any other userr.
'';
cursorHlGroupUser2 = mkStr "cursor_hl_group_user_2" "Cursor" ''
Cursor highlight group for user 2.
'';

nameHlGroupUser1 = helpers.defaultNullOpts.mkStr "CursorLineNr" ''
Virtual text highlight group for user 1.
'';
cursorHlGroupUser3 = mkStr "cursor_hl_group_user_3" "Cursor" ''
Cursor highlight group for user 3.
'';

nameHlGroupUser2 = helpers.defaultNullOpts.mkStr "CursorLineNr" ''
Virtual text highlight group for user 2.
'';
cursorHlGroupUser4 = mkStr "cursor_hl_group_user_4" "Cursor" ''
Cursor highlight group for user 4.
'';

nameHlGroupUser3 = helpers.defaultNullOpts.mkStr "CursorLineNr" ''
Virtual text highlight group for user 3.
'';
cursorHlGroupDefault = mkStr "cursor_hl_group_default" "Cursor" ''
Cursor highlight group for any other userr.
'';

nameHlGroupUser4 = helpers.defaultNullOpts.mkStr "CursorLineNr" ''
Virtual text highlight group for user 4.
'';
nameHlGroupUser1 = mkStr "name_hl_group_user_1" "CursorLineNr" ''
Virtual text highlight group for user 1.
'';

nameHlGroupDefault = helpers.defaultNullOpts.mkStr "CursorLineNr" ''
Virtual text highlight group for any other user.
'';
nameHlGroupUser2 = mkStr "name_hl_group_user_2" "CursorLineNr" ''
Virtual text highlight group for user 2.
'';

extraOptions = mkOption {
type = types.attrs;
default = {};
description = ''
Extra configuration options for instant without the 'instant_' prefix.
Example: To set 'instant_foobar' to 1, write
```nix
extraConfig = {
foobar = true;
};
```
nameHlGroupUser3 = mkStr "name_hl_group_user_3" "CursorLineNr" ''
Virtual text highlight group for user 3.
'';
};
};

config = let
cfg = config.plugins.instant;
in
mkIf cfg.enable {
extraPlugins = [cfg.package];
nameHlGroupUser4 = mkStr "name_hl_group_user_4" "CursorLineNr" ''
Virtual text highlight group for user 4.
'';

globals =
mapAttrs'
(name: nameValuePair ("instant_" + name))
(
with cfg;
{
inherit username;
only_cwd = onlyCwd;
cursor_hl_group_user_1 = cursorHlGroupUser1;
cursor_hl_group_user_2 = cursorHlGroupUser2;
cursor_hl_group_user_3 = cursorHlGroupUser3;
cursor_hl_group_user_4 = cursorHlGroupUser4;
cursor_hl_group_default = cursorHlGroupDefault;
name_hl_group_user_1 = nameHlGroupUser1;
name_hl_group_user_2 = nameHlGroupUser2;
name_hl_group_user_3 = nameHlGroupUser3;
name_hl_group_user_4 = nameHlGroupUser4;
name_hl_group_default = nameHlGroupDefault;
}
// extraOptions
);
nameHlGroupDefault = mkStr "name_hl_group_default" "CursorLineNr" ''
Virtual text highlight group for any other user.
'';
};
}
}
1 change: 0 additions & 1 deletion tests/test-sources/plugins/utils/instant.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
nameHlGroupUser3 = "CursorLineNr";
nameHlGroupUser4 = "CursorLineNr";
nameHlGroupDefault = "CursorLineNr";
extraOptions = {};
};
};
}

0 comments on commit c29a33d

Please sign in to comment.