summaryrefslogtreecommitdiffstats
path: root/modules/neovim/init/clipboard.nix
blob: a3c3c106f96f5c3f570a02a13fa7bce68ec3158f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
  config,
  pkgs,
  lib,
  ...
}: let
  inherit (lib.modules) mkIf;
  inherit (lib.options) mkOption mkEnableOption mkPackageOption;
  inherit (lib.types) submodule enum;
  inherit (lib.attrsets) mapAttrs mapAttrsToList filterAttrs;
  cfg = config.vim.clipboard;
in {
  options = {
    vim = {
      clipboard = {
        enable = mkEnableOption ''
          clipboard management for Neovim. Users may still choose to manage their
          clipboard through {option}`vim.options` should they wish to avoid using
          this module.
        '';

        registers = mkOption {
          type = enum ["" "unnamedplus" "unnamed" "unnamed,unnamedplus"];
          default = "";
          example = "unnamedplus";
          description = ''
            The register to be used by the Neovim clipboard. Recognized types are:

            * unnamed: Vim will use the clipboard register `"*"` for all yank, delete,
              change and put operations which would normally go to the unnamed register.

            * unnamedplus: A variant of the "unnamed" flag which uses the clipboard register
            `"+"` ({command}`:h quoteplus`) instead of register `"*"` for all yank, delete,
            change and put operations which would normally go to the unnamed register.

            When `unnamed` and `unnamedplus` is included simultaneously as `"unnamed,unnamedplus"`,
            yank and delete operations (but not put) will additionally copy the text into register `"*"`.

            Please see  {command}`:h clipboard` for more details.

          '';
        };

        providers = mkOption {
          type = submodule {
            options = let
              clipboards = {
                # name = "package name";
                wl-copy = "wl-clipboard";
                xclip = "xclip";
                xsel = "xsel";
              };
            in
              mapAttrs (name: pname: {
                enable = mkEnableOption name;
                package = mkPackageOption pkgs pname {nullable = true;};
              })
              clipboards;
          };
          default = {};
          description = ''
            Clipboard providers for which packages will be added to nvf's
            {option}`extraPackages`. The `package` field may be set to `null`
            if related packages are already found in system packages to
            potentially reduce closure sizes.
          '';
        };
      };
    };
  };

  config = mkIf cfg.enable {
    vim = {
      options.clipboard = cfg.registers;
      extraPackages = mapAttrsToList (_: v: v.package) (
        filterAttrs (_: v: v.enable && v.package != null) cfg.providers
      );
    };
  };
}