From 60f2d1e8ffb1491e62d538c1bb4b6f73f581fba6 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 28 Apr 2024 00:39:50 +0300 Subject: [PATCH] lib: move keymap and mode types to a lib --- default.nix | 4 +- lib/default.nix | 8 +++ lib/types.nix | 134 ++++++++++++++++++++++++++++++++++++++++ modules/input.nix | 30 +++++---- modules/vim/keymap.nix | 135 +---------------------------------------- 5 files changed, 166 insertions(+), 145 deletions(-) create mode 100644 lib/default.nix create mode 100644 lib/types.nix diff --git a/default.nix b/default.nix index c435d7f..8b4b180 100644 --- a/default.nix +++ b/default.nix @@ -3,16 +3,18 @@ , nix2lua ? import }: - let inherit (pkgs.lib) evalModules filter concatMapStringsSep showWarnings; + extendedLib = import ./lib { inherit (pkgs) lib; }; + allModules = import ./module-list.nix { inherit pkgs; }; rawModule = evalModules { modules = [ config ] ++ allModules; specialArgs = { inherit pkgs; + lib = extendedLib; nix2lua = nix2lua.lib; }; }; diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..152ec54 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,8 @@ +{ lib }: + +let + types = import ./types.nix { inherit lib; }; +in +lib // { + types = lib.types // types; +} diff --git a/lib/types.nix b/lib/types.nix new file mode 100644 index 0000000..fbdc426 --- /dev/null +++ b/lib/types.nix @@ -0,0 +1,134 @@ +{ lib }: + +let + modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ]; + mode = with lib.types; either modeEnum (uniq (listOf modeEnum)); + + # TODO: maybe add more options and add descriptions from + # :help vim.keymap.set + # :help nvim_set_keymap + keymap = lib.types.submodule ({ config, ... }: { + options = with lib; { + lhs = mkOption { + type = types.str; + description = '' + Left-hand side |{lhs}| of the mapping. + ''; + }; + rhs = mkOption { + type = with types; oneOf [ str attrs ]; + description = '' + Right-hand side |{rhs}| of the mapping, can be a Lua function. + ''; + }; + mode = mkOption { + type = mode; + default = ""; + description = '' + Mode | Norm | Ins | Cmd | Vis | Sel | Opr | Term | Lang | + Command +------+-----+-----+-----+-----+-----+------+------+ + "" | yes | - | - | yes | yes | yes | - | - | + "n" | yes | - | - | - | - | - | - | - | + "!" | - | yes | yes | - | - | - | - | - | + "i" | - | yes | - | - | - | - | - | - | + "c" | - | - | yes | - | - | - | - | - | + "v" | - | - | - | yes | yes | - | - | - | + "x" | - | - | - | yes | - | - | - | - | + "s" | - | - | - | - | yes | - | - | - | + "o" | - | - | - | - | - | yes | - | - | + "t" | - | - | - | - | - | - | yes | - | + "l" | - | yes | yes | - | - | - | - | yes | + + `:help map-overview` + ''; + }; + buffer = mkOption { + type = with types; nullOr str; + default = null; + description = '' + The mapping will be effective in the current buffer only. + + `:help :map-buffer` + ''; + }; + nowait = mkOption { + type = types.bool; + default = false; + description = '' + When defining a buffer-local mapping for "," there may be a global mapping + that starts with ",". Then you need to type another character for Vim to know + whether to use the "," mapping or the longer one. To avoid this add the + argument. Then the mapping will be used when it matches, Vim does + not wait for more characters to be typed. + + `:help :map-nowait` + ''; + }; + silent = mkOption { + type = types.bool; + default = false; + description = '' + To define a mapping which will not be echoed on the command line. + + `:help :map-silent` + ''; + }; + script = mkOption { + type = types.bool; + default = false; + description = '' + If the first argument to one of these commands is "