Compare commits

...

10 commits

Author SHA1 Message Date
raf
21c2da1ecb
Merge a6c879e8a3 into b4c06c71dc 2024-09-26 17:44:30 +03:00
raf
a6c879e8a3
Merge branch 'main' into v0.7 2024-09-26 14:44:26 +00:00
Gerg-L
b4c06c71dc
docs: fix declerations (#381)
* docs: fix declerations

* fix: formatting for your baldness
2024-09-26 01:46:47 +03:00
a56a83bd46
flake: bump neo-tree 2024-09-26 00:29:52 +03:00
raf
141a272747
Merge branch 'main' into v0.7 2024-09-24 10:54:31 +00:00
Ching Pei Yang
941a2a6f2e
Merge branch 'main' into v0.7 2024-08-24 14:37:46 +02:00
Ching Pei Yang
e40cce5653
fix: map descriptions (#358)
* remove unused

* maps: fix missing description
2024-08-17 13:08:47 +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
raf
3ca7e3b841
Merge branch 'main' into v0.7 2024-08-12 00:10:03 +00:00
diniamo
b71bf75dcd
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-12 00:07:45 +00:00
7 changed files with 130 additions and 191 deletions

View file

@ -74,7 +74,7 @@
(lib.removePrefix (toString ../.))
(lib.removePrefix "/")
(x: {
url = "https://github.com/NotAShelf/nvf/blob/main/${decl}";
url = "https://github.com/NotAShelf/nvf/blob/main/${x}";
name = "<nvf/${x}>";
})
]

View file

@ -26,6 +26,28 @@ making good use of its extensive Lua API. Additionally, Vimscript is slow and
brings unnecessary performance overhead while working with different
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";
...
};
```
### `vim.lsp.nvimCodeActionMenu` removed in favor of `vim.ui.fastaction` {#sec-nvim-code-action-menu-deprecation}
The nvim-code-action-menu plugin has been archived and broken for a long time,
@ -37,6 +59,7 @@ Note that we are looking to add more alternatives in the future like
dressing.nvim and actions-preview.nvim, in case fastaction doesn't work for
everyone.
## Changelog {#sec-release-0.7-changelog}
[ItsSorae](https://github.com/ItsSorae):
@ -132,6 +155,8 @@ everyone.
has been introduced for setting up internal plugins. See the "DAG entries in
nvf" manual page for more information.
- Rewrite `vim.maps`, see the breaking changes section above.
[NotAShelf](https://github.com/notashelf):
[ts-error-translator.nvim]: https://github.com/dmmulroy/ts-error-translator.nvim

View file

@ -863,11 +863,11 @@
"plugin-neo-tree-nvim": {
"flake": false,
"locked": {
"lastModified": 1713050882,
"narHash": "sha256-cZwOVpdMT0NCtp6Ha592QA2RzKVS6LhXXcjfDBCQ+0k=",
"lastModified": 1726542367,
"narHash": "sha256-Lqt0KJNT9HmpJwZoWChYeVBrDWhscRe8COqVCwgcTwk=",
"owner": "nvim-neo-tree",
"repo": "neo-tree.nvim",
"rev": "22e566aeb075c94f670f34077e05ba95190dfb4a",
"rev": "a77af2e764c5ed4038d27d1c463fa49cd4794e07",
"type": "github"
},
"original": {

View file

@ -8,7 +8,7 @@
# The core neovim modules.
# Contains configuration for core neovim features
# such as spellchecking, mappings, and the init script (init.vim).
neovim = map (p: "${./neovim}/${p}") [
neovim = map (p: ./neovim + "/${p}") [
"init"
"mappings"
];
@ -16,7 +16,7 @@
# Individual plugin modules, separated by the type of plugin.
# While adding a new type, you must make sure your type is
# included in the list below.
plugins = map (p: "${./plugins}/${p}") [
plugins = map (p: ./plugins + "/${p}") [
"assistant"
"autopairs"
"comments"
@ -46,7 +46,7 @@
# The neovim wrapper, used to build a wrapped neovim package
# using the configuration passed in `neovim` and `plugins` modules.
wrapper = map (p: "${./wrapper}/${p}") [
wrapper = map (p: ./wrapper + "/${p}") [
"build"
"rc"
"warnings"
@ -54,7 +54,7 @@
# Extra modules, such as deprecation warnings
# or renames in one place.
extra = map (p: "${./extra}/${p}") [
extra = map (p: ./extra + "/${p}") [
"deprecations.nix"
];
in

View file

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

View file

@ -1,61 +1,52 @@
{lib, ...}: let
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;
# 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.";
};
};
mapOption = submodule {
options =
mapConfigOptions
// {
action = mkOption {
type = str;
description = "The action to execute.";
description = "The command to execute.";
};
lua = mkOption {
type = bool;
description = ''
lua = mkBool false ''
If true, `action` is considered to be lua code.
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:
mkOption {
description = "Mappings for ${mode} mode";
@ -66,6 +57,7 @@ in {
options.vim = {
maps = mkOption {
type = submodule {
freeformType = attrsOf mapType;
options = {
normal = mapOptions "normal";
insert = mapOptions "insert";
@ -82,15 +74,11 @@ in {
};
};
default = {};
description = ''
Custom keybindings for any mode.
For plain maps (e.g. just 'map' or 'remap') use `maps.normalVisualOp`.
'';
description = "Custom keybindings.";
example = ''
maps = {
normal."<leader>m" = {
"<leader>m" = {
mode = "n";
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>

View file

@ -3,84 +3,18 @@
lib,
...
}: let
inherit (builtins) map mapAttrs filter;
inherit (lib.options) mkOption;
inherit (lib.attrsets) mapAttrsToList filterAttrs getAttrs attrValues attrNames;
inherit (builtins) map mapAttrs filter removeAttrs attrNames;
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.trivial) showWarnings;
inherit (lib.types) str nullOr;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.config) mkBool;
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 {
config = let
filterNonNull = attrs: filterAttrs (_: value: value != null) attrs;
filterNonNull = filterAttrs (_: value: value != null);
globalsScript =
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}")
(filterNonNull cfg.globals);
@ -97,38 +31,49 @@ in {
mapResult = result: concatLines (map mkLuarcSection result);
};
toLuaBindings = mode: maps:
map (value: ''
vim.keymap.set(${toLuaObject mode}, ${toLuaObject value.key}, ${toLuaObject value.action}, ${toLuaObject value.config})
'') (genMaps mode maps);
getAction = keymap:
if keymap.lua
then mkLuaInline keymap.action
else keymap.action;
# I'm not sure if every one of these will work.
allmap = toLuaBindings "" config.vim.maps.normalVisualOp;
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;
getOpts = keymap: {
inherit (keymap) desc silent nowait script expr unique noremap;
};
maps = [
nmap
imap
vmap
xmap
smap
cmap
omap
tmap
lmap
icmap
allmap
];
mappings = concatLines (map concatLines maps);
toLuaKeymap = {
name,
value,
}: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})";
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 {
vim = {
luaConfigRC = {
@ -136,7 +81,7 @@ in {
# basic
pluginConfigs = entryAfter ["basic"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] mappings;
mappings = entryAfter ["extraPluginConfigs"] keymaps;
};
builtLuaConfigRC = let