nix-community.nixvim/plugins/utils/comment-nvim.nix

105 lines
3.1 KiB
Nix
Raw Normal View History

2021-11-23 19:01:10 +01:00
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.plugins.comment-nvim;
2021-11-23 19:01:10 +01:00
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
plugins.comment-nvim = {
2021-11-23 19:01:10 +01:00
enable = mkEnableOption "Enable comment-nvim";
padding = mkOption {
2021-11-24 16:29:57 +01:00
type = types.nullOr types.bool;
2021-11-23 19:01:10 +01:00
description = "Add a space b/w comment and the line";
2021-11-24 16:29:57 +01:00
default = null;
2021-11-23 19:01:10 +01:00
};
sticky = mkOption {
2021-11-24 16:29:57 +01:00
type = types.nullOr types.bool;
2021-11-23 19:01:10 +01:00
description = "Whether the cursor should stay at its position";
2021-11-24 16:29:57 +01:00
default = null;
2021-11-23 19:01:10 +01:00
};
ignore = mkOption {
type = types.nullOr types.str;
description = "Lines to be ignored while comment/uncomment";
default = null;
};
toggler = mkOption {
type = types.nullOr (types.submodule ({ ... }: {
2021-11-23 19:01:10 +01:00
options = {
line = mkOption {
type = types.str;
description = "line-comment keymap";
default = "gcc";
};
block = mkOption {
type = types.str;
description = "block-comment keymap";
default = "gbc";
};
};
2021-11-24 16:29:57 +01:00
}));
2021-11-23 19:01:10 +01:00
description = "LHS of toggle mappings in NORMAL + VISUAL mode";
2021-11-24 16:29:57 +01:00
default = null;
2021-11-23 19:01:10 +01:00
};
opleader = mkOption {
type = types.nullOr (types.submodule ({ ... }: {
2021-11-23 19:01:10 +01:00
options = {
line = mkOption {
type = types.str;
description = "line-comment keymap";
default = "gc";
};
block = mkOption {
type = types.str;
description = "block-comment keymap";
default = "gb";
};
};
2021-11-24 16:29:57 +01:00
}));
2021-11-23 19:01:10 +01:00
description = "LHS of operator-pending mappings in NORMAL + VISUAL mode";
2021-11-24 16:29:57 +01:00
default = null;
2021-11-23 19:01:10 +01:00
};
mappings = mkOption {
type = types.nullOr (types.submodule ({ ... }: {
2021-11-23 19:01:10 +01:00
options = {
basic = mkOption {
type = types.bool;
description = "operator-pending mapping. Includes 'gcc', 'gcb', 'gc[count]{motion}' and 'gb[count]{motion}'";
2021-11-23 19:01:10 +01:00
default = true;
};
extra = mkOption {
type = types.bool;
description = "extra mapping. Includes 'gco', 'gc0', 'gcA'";
default = true;
};
extended = mkOption {
type = types.bool;
description = "extended mapping. Includes 'g>', 'g<', 'g>[count]{motion}' and 'g<[count]{motion}'";
2021-11-23 19:01:10 +01:00
default = false;
};
};
2021-11-24 16:29:57 +01:00
}));
2021-11-23 19:01:10 +01:00
description = "Create basic (operator-pending) and extended mappings for NORMAL + VISUAL mode";
2021-11-24 16:29:57 +01:00
default = null;
2021-11-23 19:01:10 +01:00
};
};
};
config =
let
setupOptions = {
padding = cfg.padding;
sticky = cfg.sticky;
ignore = cfg.ignore;
toggler = cfg.toggler;
opleader = cfg.opleader;
mappings = cfg.mappings;
};
in
mkIf cfg.enable {
2021-11-23 19:01:10 +01:00
extraPlugins = [ pkgs.vimPlugins.comment-nvim ];
extraConfigLua =
''require("Comment").setup${helpers.toLuaObject setupOptions}'';
};
}