nix-community / nixvim

Configure Neovim with Nix! [maintainer=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.7k stars 261 forks source link

Expose keymap options for all keymaps defined by nixvim #603

Open traxys opened 1 year ago

traxys commented 1 year ago

Nixvim defines keymaps for some plugins, we should expose all the possible options for those plugins (like desc, silent, ....) instead of only allowing to specify a key.

Available keymap options (2024-06-01)

trueNAHO commented 10 months ago

Related: https://github.com/nix-community/nixvim/blob/b3fb1c4c8189bc873911da3f31d18082a0721fa9/lib/keymap-helpers.nix

MattSturgeon commented 4 months ago

I think the best approach is to add a mkMapOptionSubmodule variant that omitts either key or action.

Maybe we could do something like:


mkMapOptionSubmodule = defaults: mkMapOptionSubmodule' {
  hasKey = true;
  hasAction = true;
  inherit defaults;
};

mkMapOptionSubmodule' = {
  hasKey ? false,
  hasAction ? false,
  rawAction ? true,
  defaults ? {}
}: submodule {
  options = (
      (optionalAttrs hasKey {
        key = mkOption (
          {
            type = str;
            description = "The key to map.";
            example = "<C-m>";
          }
          // (optionalAttrs (defaults ? key) { default = defaults.key; })
        );
      })
      // (optionalAttrs hasAction {
        action = mkOption (
          {
            type =
              if rawAction
              then nixvimTypes.maybeRaw str
              else str;
            description = "The action to execute.";
          }
          // (optionalAttrs (defaults ? action) { default = defaults.action; })
        );
      })
      // {
        mode = mkModeOption defaults.mode or "";
        options = mapConfigOptions;
        # Deprecated `lua` option omitted
      }
  );
}
MattSturgeon commented 4 months ago

Or since mkMapOptionSubmodule is only used by the wtf LSP and internally in keymap-helpers, we could change its interface instead of introducing a variant.