Compare commits

..

34 commits

Author SHA1 Message Date
Ching Pei Yang
43e6e673af add TODO 2024-08-15 15:53:45 +02:00
Ching Pei Yang
1b82b13dc7 lib: allow luaInline in lz.n map action 2024-08-15 15:53:45 +02:00
Ching Pei Yang
f5850432a8 flake: update lzn-auto-require 2024-08-15 15:53:45 +02:00
Ching Pei Yang
f672689023 fixup! wrapper: use lzn-auto-require loader 2024-08-15 15:53:45 +02:00
Ching Pei Yang
669088244d lib: add mkSetLuaBinding 2024-08-15 15:53:45 +02:00
Ching Pei Yang
769e07e7cc wrapper: use lzn-auto-require loader 2024-08-15 15:53:45 +02:00
Ching Pei Yang
0b9f69a20f flake: add plugin lzn-auto-require 2024-08-15 15:52:34 +02:00
Ching Pei Yang
9dd2a11e4d lz.n: generate less code 2024-08-15 15:52:34 +02:00
Ching Pei Yang
09e83a6cec lz.n: wrap lua code in function 2024-08-15 15:52:34 +02:00
Ching Pei Yang
c027a87527 lib: add mkLznBinding 2024-08-15 15:52:34 +02:00
Ching Pei Yang
abd76db843 nvim-tree: load nvim-tree if openOnSetup 2024-08-15 15:52:34 +02:00
Ching Pei Yang
85c0839105 nvim-tree: move to lz.n keymaps 2024-08-15 15:52:34 +02:00
Ching Pei Yang
6fc691a7c3 lib: add mkLznBinding 2024-08-15 15:52:34 +02:00
Ching Pei Yang
14bc100a5e lib: change lz.n spec "inlineLua" types to str 2024-08-15 15:50:16 +02:00
Ching Pei Yang
290de58ae9 lz.n: missing type check 2024-08-15 15:50:16 +02:00
Ching Pei Yang
1ee0a513cc lib: add lznKeySpec example 2024-08-15 15:50:16 +02:00
Ching Pei Yang
346f536737 lz.n: process key maps 2024-08-15 15:50:16 +02:00
Ching Pei Yang
ee5a157894 remove unused 2024-08-15 15:50:16 +02:00
Pei Yang Ching
805dd05b39 lib: fix lz.n map type 2024-08-15 15:50:16 +02:00
Ching Pei Yang
d3e39d10b0 lib: add lz.n KeySpec 2024-08-15 15:50:16 +02:00
Pei Yang Ching
14061c6db5 nvim-tree: use lazy 2024-08-15 15:50:16 +02:00
Pei Yang Ching
5c105b8182 lazy: add setupOpts support 2024-08-15 15:50:16 +02:00
Pei Yang Ching
b10c525ffe fix: broken optPlugins 2024-08-15 15:50:16 +02:00
Pei Yang Ching
9b4332ed77 switch to other hacky array-table syntax 2024-08-15 15:50:16 +02:00
Pei Yang Ching
f632fa1a92 wrap lazy init code in function 2024-08-15 15:50:16 +02:00
Ching Pei Yang
0faf4b923b flake: update lz.n 2024-08-15 15:50:16 +02:00
Ching Pei Yang
205582135d lib: add lznPluginTableType 2024-08-15 15:50:16 +02:00
Ching Pei Yang
1988203073 lib: export lznPluginType 2024-08-15 15:50:16 +02:00
Ching Pei Yang
d1d91ff8a5 lz.n: load lz.n 2024-08-15 15:50:16 +02:00
Ching Pei Yang
b552b33077 lz.n: add basic lazy.plugins option 2024-08-15 15:50:16 +02:00
Pei Yang Ching
920e0bad5e lib: add basic lz.n plugin spec type 2024-08-15 15:50:16 +02:00
Pei Yang Ching
f3ce59ed40 add lazy module skeleton 2024-08-15 15:50:16 +02:00
Pei Yang Ching
50efc3b557 flake: add lz.n plugin 2024-08-15 15:50:16 +02:00
Ching Pei Yang
2fc7dc798b
Re-add old maps API (#356)
* wrapper: fix wrong import source

* wrapper: fix typo

* Revert "lib/binds: improve code, adjust functions to new api"

This reverts commit 6cb57e1d26.

* mappings: re-add legacy vim.maps API

* mappings: fix wrong submodule syntax

* docs: fix missing section id
2024-08-13 00:27:05 +02:00
4 changed files with 123 additions and 71 deletions

View file

@ -4,7 +4,7 @@ Release notes for release 0.7
## Breaking Changes and Migration Guide {#sec-breaking-changes-and-migration-guide-0-7} ## Breaking Changes and Migration Guide {#sec-breaking-changes-and-migration-guide-0-7}
### `vim.configRC` removed ### `vim.configRC` removed {#sec-vim-configrc-removed}
In v0.7 we are removing `vim.configRC` in favor of making `vim.luaConfigRC` the In v0.7 we are removing `vim.configRC` in favor of making `vim.luaConfigRC` the
top-level DAG, and thereby making the entire configuration Lua based. This top-level DAG, and thereby making the entire configuration Lua based. This
@ -26,7 +26,7 @@ making good use of its extensive Lua API. Additionally, Vimscript is slow and
brings unnecessary performance overhead while working with different brings unnecessary performance overhead while working with different
configuration formats. configuration formats.
### `vim.maps` rewrite ### `vim.maps` rewrite {#sec-vim-maps-rewrite}
Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new
`mode` option has mode has been introduced. It can be either a string, or a list `mode` option has mode has been introduced. It can be either a string, or a list

View file

@ -5,29 +5,30 @@
inherit (lib.attrsets) isAttrs mapAttrs; inherit (lib.attrsets) isAttrs mapAttrs;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
mkLuaBinding = mode: key: action: desc: binds = rec {
mkLuaBinding = key: action: desc:
mkIf (key != null) { mkIf (key != null) {
${key} = { "${key}" = {
inherit mode action desc; inherit action desc;
lua = true; lua = true;
silent = true; silent = true;
}; };
}; };
mkExprBinding = mode: key: action: desc: mkExprBinding = key: action: desc:
mkIf (key != null) { mkIf (key != null) {
${key} = { "${key}" = {
inherit mode action desc; inherit action desc;
lua = true; lua = true;
silent = true; silent = true;
expr = true; expr = true;
}; };
}; };
mkBinding = mode: key: action: desc: mkBinding = key: action: desc:
mkIf (key != null) { mkIf (key != null) {
${key} = { "${key}" = {
inherit mode action desc; inherit action desc;
silent = true; silent = true;
}; };
}; };
@ -38,34 +39,6 @@
inherit default description; inherit default description;
}; };
# Utility function that takes two attrsets:
# { someKey = "some_value" } and
# { someKey = { description = "Some Description"; }; }
# and merges them into
# { someKey = { value = "some_value"; description = "Some Description"; }; }
addDescriptionsToMappings = actualMappings: mappingDefinitions:
mapAttrs (name: value: let
isNested = isAttrs value;
returnedValue =
if isNested
then addDescriptionsToMappings actualMappings.${name} mappingDefinitions.${name}
else {
inherit value;
inherit (mappingDefinitions.${name}) description;
};
in
returnedValue)
actualMappings;
mkSetBinding = mode: binding: action:
mkBinding mode binding.value action binding.description;
mkSetExprBinding = mode: binding: action:
mkExprBinding mode binding.value action binding.description;
mkSetLuaBinding = mode: binding: action:
mkLuaBinding mode binding.value action binding.description;
# Utility function that takes two attrsets: # Utility function that takes two attrsets:
# { someKey = "some_value" } and # { someKey = "some_value" } and
# { someKey = { description = "Some Description"; }; } # { someKey = { description = "Some Description"; }; }

View file

@ -1,17 +1,9 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) either str listOf attrsOf nullOr submodule; inherit (lib.types) either str listOf attrsOf nullOr submodule bool;
inherit (lib.nvim.config) mkBool; inherit (lib.nvim.config) mkBool;
mapType = submodule { mapConfigOptions = {
mode = mkOption {
type = either str (listOf str);
description = ''
The short-name of the mode to set the keymapping for. Passing an empty string is the equivalent of `:map`.
See `:help map-modes` for a list of modes.
'';
};
desc = mkOption { desc = mkOption {
type = nullOr str; type = nullOr str;
default = null; default = null;
@ -34,10 +26,69 @@
unique = mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map."; unique = mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map.";
noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default."; noremap = mkBool true "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default.";
}; };
mapType = submodule {
options =
mapConfigOptions
// {
mode = mkOption {
type = either str (listOf str);
description = ''
The short-name of the mode to set the keymapping for. Passing an empty string is the equivalent of `:map`.
See `:help map-modes` for a list of modes.
'';
};
};
};
# legacy stuff
mapOption = submodule {
options =
mapConfigOptions
// {
action = mkOption {
type = str;
description = "The action to execute.";
};
lua = mkOption {
type = bool;
description = ''
If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`.
'';
default = false;
};
};
};
mapOptions = mode:
mkOption {
description = "Mappings for ${mode} mode";
type = attrsOf mapOption;
default = {};
};
in { in {
options.vim = { options.vim = {
maps = mkOption { maps = mkOption {
type = attrsOf mapType; type = submodule {
freeformType = attrsOf mapType;
options = {
normal = mapOptions "normal";
insert = mapOptions "insert";
select = mapOptions "select";
visual = mapOptions "visual and select";
terminal = mapOptions "terminal";
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
visualOnly = mapOptions "visual only";
operator = mapOptions "operator-pending";
insertCommand = mapOptions "insert and command-line";
lang = mapOptions "insert, command-line and lang-arg";
command = mapOptions "command-line";
};
};
default = {}; default = {};
description = "Custom keybindings."; description = "Custom keybindings.";
example = '' example = ''

View file

@ -3,7 +3,7 @@
lib, lib,
... ...
}: let }: let
inherit (builtins) map mapAttrs filter; inherit (builtins) map mapAttrs filter removeAttrs attrNames;
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList; inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
inherit (lib.strings) concatLines concatMapStringsSep optionalString; inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.trivial) showWarnings; inherit (lib.trivial) showWarnings;
@ -45,7 +45,35 @@ in {
value, value,
}: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})"; }: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})";
keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull config.maps))); namedModes = {
"normal" = ["n"];
"insert" = ["i"];
"select" = ["s"];
"visual" = ["v"];
"terminal" = ["t"];
"normalVisualOp" = ["n" "v" "o"];
"visualOnly" = ["n" "x"];
"operator" = ["o"];
"insertCommand" = ["i" "c"];
"lang" = ["l"];
"command" = ["c"];
};
maps =
removeAttrs cfg.maps (attrNames namedModes)
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normal;}) cfg.maps.normal
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insert;}) cfg.maps.insert
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.select;}) cfg.maps.select
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visual;}) cfg.maps.visual
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.terminal;}) cfg.maps.terminal
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normalVisualOp;}) cfg.maps.normalVisualOp
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visualOnly;}) cfg.maps.visualOnly
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.operator;}) cfg.maps.operator
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insertCommand;}) cfg.maps.insertCommand
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.lang;}) cfg.maps.lang
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.command;}) cfg.maps.command;
keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull maps)));
in { in {
vim = { vim = {
luaConfigRC = { luaConfigRC = {