Compare commits

...

54 commits

Author SHA1 Message Date
Pei Yang Ching
db76167e95 lazy: move type definition out of lib 2024-08-24 16:00:11 +02:00
Pei Yang Ching
236f3e84a6 flake: update lz.n and lzn-auto-require 2024-08-24 15:16:53 +02:00
Pei Yang Ching
299639065c lazy: use listOf plugins instead of attr 2024-08-24 15:15:31 +02:00
Pei Yang Ching
cb99286189 lib.binds: update lzn util functions 2024-08-24 15:03:34 +02:00
Pei Yang Ching
945b9e6500 lazy: use similar API to nvf keymaps 2024-08-24 15:03:34 +02:00
Ching Pei Yang
05156b4e1b flake: update lzn-auto-require 2024-08-24 15:03:34 +02:00
Ching Pei Yang
c992135d11 lz.n: add missing PluginSpec options 2024-08-24 15:03:34 +02:00
Ching Pei Yang
d64b4b827a add TODO 2024-08-24 15:03:34 +02:00
Ching Pei Yang
9c1c2056f2 lib: allow luaInline in lz.n map action 2024-08-24 15:03:34 +02:00
Ching Pei Yang
5f4dfb44e2 flake: update lzn-auto-require 2024-08-24 15:03:34 +02:00
Ching Pei Yang
7c8221a6d5 fixup! wrapper: use lzn-auto-require loader 2024-08-24 15:03:34 +02:00
Ching Pei Yang
608f8e6536 lib: add mkSetLuaBinding 2024-08-24 15:03:34 +02:00
Ching Pei Yang
99b1ce252c wrapper: use lzn-auto-require loader 2024-08-24 15:03:34 +02:00
Ching Pei Yang
0d17a40ae9 flake: add plugin lzn-auto-require 2024-08-24 15:03:34 +02:00
Ching Pei Yang
118f33f1fc lz.n: generate less code 2024-08-24 15:03:34 +02:00
Ching Pei Yang
5002e25c1d lz.n: wrap lua code in function 2024-08-24 15:03:34 +02:00
Ching Pei Yang
7c28651f51 lib: add mkLznBinding 2024-08-24 15:03:34 +02:00
Ching Pei Yang
c7bd41fe94 nvim-tree: load nvim-tree if openOnSetup 2024-08-24 15:03:34 +02:00
Ching Pei Yang
a8b0e8e073 nvim-tree: move to lz.n keymaps 2024-08-24 15:03:34 +02:00
Ching Pei Yang
eef3e773bc lib: add mkLznBinding 2024-08-24 15:00:56 +02:00
Ching Pei Yang
a46502b939 lib: change lz.n spec "inlineLua" types to str 2024-08-24 15:00:56 +02:00
Ching Pei Yang
0dae5a0ffe lz.n: missing type check 2024-08-24 15:00:56 +02:00
Ching Pei Yang
1226269143 lib: add lznKeySpec example 2024-08-24 15:00:56 +02:00
Ching Pei Yang
99bbdad2e1 lz.n: process key maps 2024-08-24 15:00:56 +02:00
Ching Pei Yang
0e3cc7f53c remove unused 2024-08-24 15:00:56 +02:00
Pei Yang Ching
024732e8b2 lib: fix lz.n map type 2024-08-24 15:00:56 +02:00
Ching Pei Yang
96244e0a2c lib: add lz.n KeySpec 2024-08-24 15:00:56 +02:00
Pei Yang Ching
8bbb9ff1b0 nvim-tree: use lazy 2024-08-24 15:00:56 +02:00
Pei Yang Ching
f68472a78b lazy: add setupOpts support 2024-08-24 15:00:56 +02:00
Pei Yang Ching
c0750e74c5 fix: broken optPlugins 2024-08-24 15:00:56 +02:00
Pei Yang Ching
d6c1424d12 switch to other hacky array-table syntax 2024-08-24 15:00:56 +02:00
Pei Yang Ching
e062e93d2f wrap lazy init code in function 2024-08-24 15:00:56 +02:00
Ching Pei Yang
35bb2157cf flake: update lz.n 2024-08-24 15:00:56 +02:00
Ching Pei Yang
bb49f63e71 lib: add lznPluginTableType 2024-08-24 15:00:56 +02:00
Ching Pei Yang
9817e31e10 lib: export lznPluginType 2024-08-24 15:00:56 +02:00
Ching Pei Yang
bdc1c83826 lz.n: load lz.n 2024-08-24 15:00:56 +02:00
Ching Pei Yang
d3c4eaa693 lz.n: add basic lazy.plugins option 2024-08-24 15:00:56 +02:00
Pei Yang Ching
d70951305d lib: add basic lz.n plugin spec type 2024-08-24 15:00:56 +02:00
Pei Yang Ching
caff0029a2 add lazy module skeleton 2024-08-24 15:00:56 +02:00
Pei Yang Ching
0ece3311c2 flake: add lz.n plugin 2024-08-24 15:00:56 +02:00
Pei Yang Ching
0f17254bb6 maps: fix missing description 2024-08-24 15:00:56 +02:00
Ching Pei Yang
6a5f8f68ab remove unused 2024-08-24 15:00:56 +02:00
Pei Yang Ching
12a01936cd cleanup unused import 2024-08-24 15:00:56 +02:00
Pei Yang Ching
e5a2c58f26 remove unneeded pipe 2024-08-24 15:00:56 +02:00
Pei Yang Ching
a6cfdb10fb keymaps: update example 2024-08-24 15:00:56 +02:00
Pei Yang Ching
afc7092d63 keymaps: use listOf mapOption instead 2024-08-24 15:00:56 +02:00
Pei Yang Ching
93c6f6e7f4 maps: fix bad mode names 2024-08-24 15:00:56 +02:00
Pei Yang Ching
cce4195148 maps: allow same key on multiple mode 2024-08-24 15:00:56 +02:00
Ching Pei Yang
84c2a32054 fix: map descriptions (#358)
* remove unused

* maps: fix missing description
2024-08-24 15:00:56 +02:00
Ching Pei Yang
3db8b47027 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-24 15:00:56 +02:00
diniamo
2dd1be0b45 vim.maps rewrite (#352)
* feat: rewrite vim.maps

* modules/mappings: enable silent by default

* docs: add entry for vim.maps rewrite

* lib/binds: improve code, adjust functions to new api
2024-08-24 14:35:50 +02:00
Gerg-L
fc2e5998e7
flake.lock: Update (#363)
Flake lock file updates:

• Updated input 'mnw':
    'github:Gerg-L/mnw/e06b48c51291cc1df08adcd34a8796f86d5b235e?narHash=sha256-qimVBdes%2B2gNRRcyFoIUA1RyOKV0Ee40hUaVVf7ZsNs%3D' (2024-08-22)
  → 'github:Gerg-L/mnw/c261925dbbf02f523af0e8add844df64fddf0359?narHash=sha256-SMgnviF6ofBPbyV3%2BrljPGcX0Hn9HBOhgXE10Cyjaic%3D' (2024-08-23)
2024-08-24 10:47:26 +00:00
Gerg-L
25fe1c4625
flake.lock: Update (#362)
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Validate flake & check formatting / Validate Flake (push) Has been cancelled
Validate flake & check formatting / Formatting via Alejandra (push) Has been cancelled
Flake lock file updates:

• Updated input 'mnw':
    'github:Gerg-L/mnw/c7b289f3f5a31b6e744be37d83fc231816621231?narHash=sha256-YF//iMALbrd2Ni9aju7w8NniH16Qz6RFTRD6md5UkDc%3D' (2024-07-28)
  → 'github:Gerg-L/mnw/e06b48c51291cc1df08adcd34a8796f86d5b235e?narHash=sha256-qimVBdes%2B2gNRRcyFoIUA1RyOKV0Ee40hUaVVf7ZsNs%3D' (2024-08-22)
2024-08-22 23:42:51 +00:00
fd90cf7fd5
flake: revert 37dbdbb06d4d99297ee94adf6733893242b979c7
Some checks failed
Set up binary cache / cachix (default) (push) Has been cancelled
Set up binary cache / cachix (maximal) (push) Has been cancelled
Set up binary cache / cachix (nix) (push) Has been cancelled
Validate flake & check formatting / Validate Flake (push) Has been cancelled
Validate flake & check formatting / Formatting via Alejandra (push) Has been cancelled
The bald frog balded again...
2024-08-12 19:26:09 +03:00
6 changed files with 128 additions and 188 deletions

View file

@ -4,6 +4,8 @@ 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 {#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
change introduces a few breaking changes: change introduces a few breaking changes:
@ -24,6 +26,28 @@ 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 {#sec-vim-maps-rewrite}
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
of strings, where a string represents the short-name of the map mode(s), that
the mapping should be set for. See `:help map-modes` for more information.
For example:
```nix
vim.maps.normal."<leader>m" = { ... };
```
has to be replaced by
```nix
vim.maps."<leader>m" = {
mode = "n";
...
};
```
## Changelog {#sec-release-0.7-changelog} ## Changelog {#sec-release-0.7-changelog}
[ItsSorae](https://github.com/ItsSorae): [ItsSorae](https://github.com/ItsSorae):
@ -114,6 +138,8 @@ configuration formats.
has been introduced for setting up internal plugins. See the "DAG entries in has been introduced for setting up internal plugins. See the "DAG entries in
nvf" manual page for more information. nvf" manual page for more information.
- Rewrite `vim.maps`, see the breaking changes section above.
[NotAShelf](https://github.com/notashelf): [NotAShelf](https://github.com/notashelf):
[ts-error-translator.nvim]: https://github.com/dmmulroy/ts-error-translator.nvim [ts-error-translator.nvim]: https://github.com/dmmulroy/ts-error-translator.nvim

View file

@ -69,11 +69,11 @@
}, },
"mnw": { "mnw": {
"locked": { "locked": {
"lastModified": 1723419050, "lastModified": 1724456641,
"narHash": "sha256-Eb8jBUgHwpte+bGsqeXNbKMBfZaDB7RiPQwyb1vzJK8=", "narHash": "sha256-SMgnviF6ofBPbyV3+rljPGcX0Hn9HBOhgXE10Cyjaic=",
"owner": "Gerg-L", "owner": "Gerg-L",
"repo": "mnw", "repo": "mnw",
"rev": "e625f5965567f16102bc52897c7600dcde53c6c3", "rev": "c261925dbbf02f523af0e8add844df64fddf0359",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -8,46 +8,27 @@
cfg = config.vim; cfg = config.vim;
in { in {
config = { config = {
vim.maps = { vim.maps = mkIf cfg.disableArrows {
normal = mkIf cfg.disableArrows {
"<up>" = {
action = "<nop>";
noremap = false;
};
"<down>" = {
action = "<nop>";
noremap = false;
};
"<left>" = {
action = "<nop>";
noremap = false;
};
"<right>" = {
action = "<nop>";
noremap = false;
};
};
insert = mkIf cfg.disableArrows {
"<up>" = { "<up>" = {
mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
}; };
"<down>" = { "<down>" = {
mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
}; };
"<left>" = { "<left>" = {
mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
}; };
"<right>" = { "<right>" = {
mode = ["n" "i"];
action = "<nop>"; action = "<nop>";
noremap = false; noremap = false;
}; };
}; };
}; };
};
} }

View file

@ -1,61 +1,52 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) bool str attrsOf nullOr submodule; inherit (lib.types) either str listOf attrsOf nullOr submodule bool;
inherit (lib.nvim.config) mkBool; inherit (lib.nvim.config) mkBool;
# Most of the keybindings code is highly inspired by pta2002/nixvim.
# Thank you!
mapConfigOptions = { mapConfigOptions = {
silent =
mkBool false
"Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
nowait =
mkBool false
"Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
script =
mkBool false
"Equivalent to adding <script> to a map.";
expr =
mkBool false
"Means that the action is actually an expression. Equivalent to adding <expr> 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.";
desc = mkOption { desc = mkOption {
type = nullOr str; type = nullOr str;
default = null; default = null;
description = "A description of this keybind, to be shown in which-key, if you have it enabled."; description = "A description of this keybind, to be shown in which-key, if you have it enabled.";
}; };
};
mapOption = submodule {
options =
mapConfigOptions
// {
action = mkOption { action = mkOption {
type = str; type = str;
description = "The action to execute."; description = "The command to execute.";
}; };
lua = mkBool false ''
lua = mkOption {
type = bool;
description = ''
If true, `action` is considered to be lua code. If true, `action` is considered to be lua code.
Thus, it will not be wrapped in `""`. Thus, it will not be wrapped in `""`.
''; '';
default = false;
silent = mkBool true "Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
nowait = mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
script = mkBool false "Equivalent to adding <script> to a map.";
expr = mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> 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.";
};
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;
};
mapOptions = mode: mapOptions = mode:
mkOption { mkOption {
description = "Mappings for ${mode} mode"; description = "Mappings for ${mode} mode";
@ -66,6 +57,7 @@ in {
options.vim = { options.vim = {
maps = mkOption { maps = mkOption {
type = submodule { type = submodule {
freeformType = attrsOf mapType;
options = { options = {
normal = mapOptions "normal"; normal = mapOptions "normal";
insert = mapOptions "insert"; insert = mapOptions "insert";
@ -82,15 +74,11 @@ in {
}; };
}; };
default = {}; default = {};
description = '' description = "Custom keybindings.";
Custom keybindings for any mode.
For plain maps (e.g. just 'map' or 'remap') use `maps.normalVisualOp`.
'';
example = '' example = ''
maps = { maps = {
normal."<leader>m" = { "<leader>m" = {
mode = "n";
silent = true; silent = true;
action = "<cmd>make<CR>"; action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR> }; # Same as nnoremap <leader>m <silent> <cmd>make<CR>

View file

@ -6,7 +6,7 @@
inherit (lib.trivial) boolToString warnIf; inherit (lib.trivial) boolToString warnIf;
in { in {
onedark = { onedark = {
setup = {style ? "dark"}: '' setup = {style ? "dark", ...}: ''
-- OneDark theme -- OneDark theme
require('onedark').setup { require('onedark').setup {
style = "${style}" style = "${style}"
@ -30,7 +30,7 @@ in {
}; };
dracula = { dracula = {
setup = {transparent}: '' setup = {transparent, ...}: ''
require('dracula').setup({ require('dracula').setup({
transparent_bg = ${boolToString transparent}, transparent_bg = ${boolToString transparent},
}); });

View file

@ -3,84 +3,18 @@
lib, lib,
... ...
}: let }: let
inherit (builtins) map mapAttrs filter; inherit (builtins) map mapAttrs filter removeAttrs attrNames;
inherit (lib.options) mkOption; inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
inherit (lib.attrsets) mapAttrsToList filterAttrs getAttrs attrValues attrNames;
inherit (lib.strings) concatLines concatMapStringsSep; inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.trivial) showWarnings; inherit (lib.trivial) showWarnings;
inherit (lib.types) str nullOr;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere; inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.config) mkBool;
cfg = config.vim; cfg = config.vim;
# Most of the keybindings code is highly inspired by pta2002/nixvim.
# Thank you!
mapConfigOptions = {
silent =
mkBool false
"Whether this mapping should be silent. Equivalent to adding <silent> to a map.";
nowait =
mkBool false
"Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
script =
mkBool false
"Equivalent to adding <script> to a map.";
expr =
mkBool false
"Means that the action is actually an expression. Equivalent to adding <expr> 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.";
desc = mkOption {
type = nullOr str;
default = null;
description = "A description of this keybind, to be shown in which-key, if you have it enabled.";
};
};
genMaps = mode: maps: let
/*
Take a user-defined action (string or attrs) and return the following attribute set:
{
action = (string) the actual action to map to this key
config = (attrs) the configuration options for this mapping (noremap, silent...)
}
*/
normalizeAction = action: {
# Extract the values of the config options that have been explicitly set by the user
config =
filterAttrs (_: v: v != null)
(getAttrs (attrNames mapConfigOptions) action);
action =
if action.lua
then mkLuaInline action.action
else action.action;
};
in
attrValues (mapAttrs
(key: action: let
normalizedAction = normalizeAction action;
in {
inherit (normalizedAction) action config;
inherit key;
inherit mode;
})
maps);
in { in {
config = let config = let
filterNonNull = attrs: filterAttrs (_: value: value != null) attrs; filterNonNull = filterAttrs (_: value: value != null);
globalsScript = globalsScript =
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}") mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}")
(filterNonNull cfg.globals); (filterNonNull cfg.globals);
@ -97,38 +31,49 @@ in {
mapResult = result: concatLines (map mkLuarcSection result); mapResult = result: concatLines (map mkLuarcSection result);
}; };
toLuaBindings = mode: maps: getAction = keymap:
map (value: '' if keymap.lua
vim.keymap.set(${toLuaObject mode}, ${toLuaObject value.key}, ${toLuaObject value.action}, ${toLuaObject value.config}) then mkLuaInline keymap.action
'') (genMaps mode maps); else keymap.action;
# I'm not sure if every one of these will work. getOpts = keymap: {
allmap = toLuaBindings "" config.vim.maps.normalVisualOp; inherit (keymap) desc silent nowait script expr unique noremap;
nmap = toLuaBindings "n" config.vim.maps.normal; };
vmap = toLuaBindings "v" config.vim.maps.visual;
xmap = toLuaBindings "x" config.vim.maps.visualOnly;
smap = toLuaBindings "s" config.vim.maps.select;
imap = toLuaBindings "i" config.vim.maps.insert;
cmap = toLuaBindings "c" config.vim.maps.command;
tmap = toLuaBindings "t" config.vim.maps.terminal;
lmap = toLuaBindings "l" config.vim.maps.lang;
omap = toLuaBindings "o" config.vim.maps.operator;
icmap = toLuaBindings "ic" config.vim.maps.insertCommand;
maps = [ toLuaKeymap = {
nmap name,
imap value,
vmap }: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})";
xmap
smap namedModes = {
cmap "normal" = ["n"];
omap "insert" = ["i"];
tmap "select" = ["s"];
lmap "visual" = ["v"];
icmap "terminal" = ["t"];
allmap "normalVisualOp" = ["n" "v" "o"];
]; "visualOnly" = ["n" "x"];
mappings = concatLines (map concatLines maps); "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 = {
@ -136,7 +81,7 @@ in {
# basic, theme # basic, theme
pluginConfigs = entryAfter ["theme"] pluginConfigs; pluginConfigs = entryAfter ["theme"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs; extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] mappings; mappings = entryAfter ["extraPluginConfigs"] keymaps;
}; };
builtLuaConfigRC = let builtLuaConfigRC = let