Compare commits

..

33 commits

Author SHA1 Message Date
Ching Pei Yang
f6500bbd05 add TODO 2024-08-04 02:27:59 +02:00
Ching Pei Yang
432cb9c87b lib: allow luaInline in lz.n map action 2024-08-04 02:24:10 +02:00
Ching Pei Yang
9faddddf84 flake: update lzn-auto-require 2024-08-04 02:23:30 +02:00
Ching Pei Yang
682779b0f3 fixup! wrapper: use lzn-auto-require loader 2024-08-03 22:46:06 +02:00
Ching Pei Yang
8bddf37b43 lib: add mkSetLuaBinding 2024-08-03 22:33:23 +02:00
Ching Pei Yang
102b908deb wrapper: use lzn-auto-require loader 2024-08-03 22:28:51 +02:00
Ching Pei Yang
8dd9aa0cb5 flake: add plugin lzn-auto-require 2024-08-03 22:21:32 +02:00
Ching Pei Yang
c7df5c97f3 lz.n: generate less code 2024-08-03 19:48:13 +02:00
Ching Pei Yang
e086dc02fe lz.n: wrap lua code in function 2024-08-03 19:46:52 +02:00
Ching Pei Yang
fc58c85524 lib: add mkLznBinding 2024-08-03 19:18:25 +02:00
Ching Pei Yang
f43d3835f1 nvim-tree: load nvim-tree if openOnSetup 2024-08-03 18:42:53 +02:00
Ching Pei Yang
664d7154b4 nvim-tree: move to lz.n keymaps 2024-08-03 18:42:53 +02:00
Ching Pei Yang
42c60df933 lib: add mkLznBinding 2024-08-03 18:42:53 +02:00
Ching Pei Yang
b437242689 lib: change lz.n spec "inlineLua" types to str 2024-08-03 18:42:53 +02:00
Ching Pei Yang
c6071b7da4 lz.n: missing type check 2024-08-03 18:42:52 +02:00
Ching Pei Yang
4d51981179 lib: add lznKeySpec example 2024-08-03 18:42:12 +02:00
Ching Pei Yang
085d5d304a lz.n: process key maps 2024-08-03 14:45:48 +02:00
Ching Pei Yang
4efc5d89d0 remove unused 2024-08-03 14:45:29 +02:00
Pei Yang Ching
a4ad8654a6 lib: fix lz.n map type 2024-08-02 13:12:03 +02:00
Ching Pei Yang
593435318d lib: add lz.n KeySpec 2024-08-02 12:55:57 +02:00
Pei Yang Ching
8369ca5602 nvim-tree: use lazy 2024-08-02 12:55:57 +02:00
Pei Yang Ching
89b80ac8fb lazy: add setupOpts support 2024-08-02 12:55:57 +02:00
Pei Yang Ching
b3e54e5be4 fix: broken optPlugins 2024-08-02 12:55:57 +02:00
Pei Yang Ching
00193e902e switch to other hacky array-table syntax 2024-08-02 12:55:57 +02:00
Pei Yang Ching
618ade49c1 wrap lazy init code in function 2024-08-02 12:55:57 +02:00
Ching Pei Yang
d39f03f4db flake: update lz.n 2024-08-02 12:55:57 +02:00
Ching Pei Yang
315c93b5c5 lib: add lznPluginTableType 2024-08-02 12:55:57 +02:00
Ching Pei Yang
201b2969a1 lib: export lznPluginType 2024-08-02 12:55:57 +02:00
Ching Pei Yang
d1495cd13d lz.n: load lz.n 2024-08-02 12:55:57 +02:00
Ching Pei Yang
5f5dd22080 lz.n: add basic lazy.plugins option 2024-08-02 12:55:57 +02:00
Pei Yang Ching
49cb74afe5 lib: add basic lz.n plugin spec type 2024-08-02 12:55:57 +02:00
Pei Yang Ching
9d4b95b740 add lazy module skeleton 2024-08-02 12:55:57 +02:00
Pei Yang Ching
cd92dcf986 flake: add lz.n plugin 2024-08-02 12:55:57 +02:00
14 changed files with 321 additions and 306 deletions

View file

@ -83,7 +83,7 @@ Release notes for release 0.5
- Updated indent-blankine.nvim to v3 - this comes with a few option changes, which will be migrated with `renamedOptionModule` - Updated indent-blankine.nvim to v3 - this comes with a few option changes, which will be migrated with `renamedOptionModule`
[jacekpoz](https://jacekpoz.pl): [jacekpoz](https://github.com/jacekpoz):
- Fixed scrollOffset not being used - Fixed scrollOffset not being used

View file

@ -62,7 +62,7 @@ vim.api.nvim_set_keymap('n', '<leader>a', ':lua camelToSnake()<CR>', { noremap =
- Added rose-pine theme. - Added rose-pine theme.
[jacekpoz](https://jacekpoz.pl): [jacekpoz](https://github.com/jacekpoz):
- Added `vim.autocomplete.alwaysComplete`. Allows users to have the autocomplete window popup only when manually activated. - Added `vim.autocomplete.alwaysComplete`. Allows users to have the autocomplete window popup only when manually activated.

View file

@ -4,8 +4,6 @@ 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
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:
@ -26,28 +24,6 @@ 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
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):
@ -86,17 +62,14 @@ vim.maps."<leader>m" = {
recommended to go through rustacean.nvim's README to take a closer look at its recommended to go through rustacean.nvim's README to take a closer look at its
features and usage features and usage
[jacekpoz](https://jacekpoz.pl): [jacekpoz](https://github.com/jacekpoz):
[ocaml-lsp]: https://github.com/ocaml/ocaml-lsp [ocaml-lsp]: https://github.com/ocaml/ocaml-lsp
[new-file-template.nvim]: https://github.com/otavioschwanck/new-file-template.nvim
- Add [ocaml-lsp] support - Add [ocaml-lsp] support
- Fix "Emac" typo - Fix "Emac" typo
- Add [new-file-template.nvim] to automatically fill new file contents using templates.
[diniamo](https://github.com/diniamo): [diniamo](https://github.com/diniamo):
- Move the `theme` dag entry to before `luaScript`. - Move the `theme` dag entry to before `luaScript`.
@ -138,8 +111,6 @@ vim.maps."<leader>m" = {
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
@ -169,10 +140,10 @@ vim.maps."<leader>m" = {
- Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available - Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available
under `vim.filetree.neo-tree`, similar to nvimtree. under `vim.filetree.neo-tree`, similar to nvimtree.
- Add `nvf-print-config` & `nvf-print-config-path` helper scripts to Neovim - Add `print-nvf-config` & `print-nvf-config-path` helper scripts to Neovim
closure. Both of those scripts have been automatically added to your PATH upon closure. Both of those scripts have been automatically added to your PATH upon
using neovimConfig or `programs.nvf.enable`. using neovimConfig or `programs.nvf.enable`.
- `nvf-print-config` will display your `init.lua`, in full. - `print-nvf-config` will display your `init.lua`, in full.
- `nvf-print-config-path` will display the path to _a clone_ of your - `print-nvf-config-path` will display the path to _a clone_ of your
`init.lua`. This is not the path used by the Neovim wrapper, but an `init.lua`. This is not the path used by the Neovim wrapper, but an
identical clone. identical clone.

View file

@ -69,11 +69,11 @@
}, },
"mnw": { "mnw": {
"locked": { "locked": {
"lastModified": 1723419050, "lastModified": 1722191188,
"narHash": "sha256-Eb8jBUgHwpte+bGsqeXNbKMBfZaDB7RiPQwyb1vzJK8=", "narHash": "sha256-YF//iMALbrd2Ni9aju7w8NniH16Qz6RFTRD6md5UkDc=",
"owner": "Gerg-L", "owner": "Gerg-L",
"repo": "mnw", "repo": "mnw",
"rev": "e625f5965567f16102bc52897c7600dcde53c6c3", "rev": "c7b289f3f5a31b6e744be37d83fc231816621231",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -971,22 +971,6 @@
"type": "github" "type": "github"
} }
}, },
"plugin-new-file-template-nvim": {
"flake": false,
"locked": {
"lastModified": 1721518222,
"narHash": "sha256-g0IjJrHRXw7U9goVLzVYUyHBSsDZGHMpi3YZPhg64zA=",
"owner": "otavioschwanck",
"repo": "new-file-template.nvim",
"rev": "6ac66669dbf2dc5cdee184a4fe76d22465ca67e8",
"type": "github"
},
"original": {
"owner": "otavioschwanck",
"repo": "new-file-template.nvim",
"type": "github"
}
},
"plugin-noice-nvim": { "plugin-noice-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1912,7 +1896,6 @@
"plugin-neo-tree-nvim": "plugin-neo-tree-nvim", "plugin-neo-tree-nvim": "plugin-neo-tree-nvim",
"plugin-neocord": "plugin-neocord", "plugin-neocord": "plugin-neocord",
"plugin-neodev-nvim": "plugin-neodev-nvim", "plugin-neodev-nvim": "plugin-neodev-nvim",
"plugin-new-file-template-nvim": "plugin-new-file-template-nvim",
"plugin-noice-nvim": "plugin-noice-nvim", "plugin-noice-nvim": "plugin-noice-nvim",
"plugin-none-ls": "plugin-none-ls", "plugin-none-ls": "plugin-none-ls",
"plugin-nui-nvim": "plugin-nui-nvim", "plugin-nui-nvim": "plugin-nui-nvim",

View file

@ -639,15 +639,9 @@
}; };
plugin-nvim-nio = { plugin-nvim-nio = {
# (required by nvim-dap-ui) # (required nvim-dap-ui)
url = "github:nvim-neotest/nvim-nio"; url = "github:nvim-neotest/nvim-nio";
flake = false; flake = false;
}; };
plugin-new-file-template-nvim = {
# (required by new-file-template.nvim)
url = "github:otavioschwanck/new-file-template.nvim";
flake = false;
};
}; };
} }

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

@ -7,72 +7,91 @@ inputs: {
extraModules ? [], extraModules ? [],
}: let }: let
inherit (pkgs) vimPlugins; inherit (pkgs) vimPlugins;
inherit (pkgs.vimUtils) buildVimPlugin;
inherit (lib.strings) isString toString; inherit (lib.strings) isString toString;
inherit (lib.lists) filter map concatLists; inherit (lib.lists) filter map concatLists;
inherit (lib.attrsets) recursiveUpdate getAttr;
inherit (lib.asserts) assertMsg;
# import modules.nix with `check`, `pkgs` and `lib` as arguments # import modules.nix with `check`, `pkgs` and `lib` as arguments
# check can be disabled while calling this file is called # check can be disabled while calling this file is called
# to avoid checking in all modules # to avoid checking in all modules
nvimModules = import ./modules.nix {inherit pkgs check lib;}; nvimModules = import ./modules.nix {
inherit pkgs check lib;
};
# evaluate the extended library with the modules # evaluate the extended library with the modules
# optionally with any additional modules passed by the user # optionally with any additional modules passed by the user
module = lib.evalModules { module = lib.evalModules {
specialArgs = extraSpecialArgs // {modulesPath = toString ./.;}; specialArgs = recursiveUpdate {modulesPath = toString ./.;} extraSpecialArgs;
modules = concatLists [[configuration] nvimModules extraModules]; modules = concatLists [[configuration] nvimModules extraModules];
}; };
# alias to the internal configuration # alias to the internal configuration
vimOptions = module.config.vim; vimOptions = module.config.vim;
noBuildPlug = {pname, ...} @ attrs: let
src = inputs."plugin-${attrs.pname}";
in
{
version = src.shortRev or src.shortDirtyRev or "dirty";
outPath = src;
passthru.vimPlugin = false;
}
// attrs;
# build a vim plugin with the given name and arguments # build a vim plugin with the given name and arguments
# if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug
# instead # instead
buildPlug = attrs: let buildPlug = {pname, ...} @ attrs: let
src = inputs."plugin-${attrs.pname}"; src = getAttr ("plugin-" + pname) inputs;
in in
pkgs.vimUtils.buildVimPlugin ( pkgs.stdenvNoCC.mkDerivation ({
{
version = src.shortRev or src.shortDirtyRev or "dirty";
inherit src; inherit src;
version = src.shortRev or src.shortDirtyRev or "dirty";
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r . $out
runHook postInstall
'';
} }
// attrs // attrs);
);
noBuildPlug = {pname, ...} @ attrs: let
input = getAttr ("plugin-" + pname) inputs;
in
{
version = input.shortRev or input.shortDirtyRev or "dirty";
outPath = getAttr ("plugin-" + pname) inputs;
}
// attrs;
buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars);
pluginBuilders = { buildConfigPlugins = plugins:
nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars; map
flutter-tools-patched = buildPlug { (plug: (
if (isString plug)
then
(
if (plug == "nvim-treesitter")
then (buildTreesitterPlug vimOptions.treesitter.grammars)
else if (plug == "flutter-tools-patched")
then
(
buildPlug
{
pname = "flutter-tools"; pname = "flutter-tools";
patches = [../patches/flutter-tools.patch]; patches = [../patches/flutter-tools.patch];
}; }
}; )
else noBuildPlug {pname = plug;}
buildConfigPlugins = plugins: )
map (
plug:
if (isString plug)
then pluginBuilders.${plug} or (noBuildPlug {pname = plug;})
else plug else plug
) (filter (f: f != null) plugins); ))
(filter
(f: f != null)
plugins);
# built (or "normalized") plugins that are modified # built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins); builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
# additional Lua and Python3 packages, mapped to their respective functions # additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format mnw expects. end user should # to conform to the format makeNeovimConfig expects. end user should
# only ever need to pass a list of packages, which are modified # only ever need to pass a list of packages, which are modified
# here # here
extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages;
@ -82,7 +101,7 @@ inputs: {
# generate a wrapped Neovim package. # generate a wrapped Neovim package.
neovim-wrapped = inputs.mnw.lib.wrap pkgs { neovim-wrapped = inputs.mnw.lib.wrap pkgs {
neovim = vimOptions.package; neovim = vimOptions.package;
plugins = builtStartPlugins ++ builtOptPlugins; plugins = concatLists [builtStartPlugins builtOptPlugins];
appName = "nvf"; appName = "nvf";
extraBinPath = vimOptions.extraPackages; extraBinPath = vimOptions.extraPackages;
initLua = vimOptions.builtLuaConfigRC; initLua = vimOptions.builtLuaConfigRC;
@ -92,11 +111,20 @@ inputs: {
inherit extraLuaPackages extraPython3Packages; inherit extraLuaPackages extraPython3Packages;
}; };
dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC;
# Additional helper scripts for printing and displaying nvf configuration # Additional helper scripts for printing and displaying nvf configuration
# in your commandline. # in your commandline.
printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}"; printConfig = pkgs.writers.writeDashBin "print-nvf-config" ''
printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}"; cat << EOF
${vimOptions.builtLuaConfigRC}
EOF
'';
printConfigPath = pkgs.writers.writeDashBin "print-nvf-config-path" ''
realpath ${pkgs.writeTextFile {
name = "nvf-init.lua";
text = vimOptions.builtLuaConfigRC;
}}
'';
in { in {
inherit (module) options config; inherit (module) options config;
inherit (module._module.args) pkgs; inherit (module._module.args) pkgs;
@ -106,7 +134,7 @@ in {
neovim = pkgs.symlinkJoin { neovim = pkgs.symlinkJoin {
name = "nvf-with-helpers"; name = "nvf-with-helpers";
paths = [neovim-wrapped printConfig printConfigPath]; paths = [neovim-wrapped printConfig printConfigPath];
postBuild = "echo Helpers added"; postBuild = "echo helpers added";
meta = { meta = {
description = "Wrapped version of Neovim with additional helper scripts"; description = "Wrapped version of Neovim with additional helper scripts";

View file

@ -8,27 +8,46 @@
cfg = config.vim; cfg = config.vim;
in { in {
config = { config = {
vim.maps = mkIf cfg.disableArrows { 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 {
"<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,49 +1,96 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.types) either str listOf attrsOf nullOr submodule; inherit (lib.types) bool str attrsOf nullOr submodule;
inherit (lib.nvim.config) mkBool; 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.";
mapType = submodule { nowait =
mode = mkOption { mkBool false
type = either str (listOf str); "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map.";
description = ''
The short-name of the mode to set the keymapping for. Passing an empty string is the equivalent of `: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.";
See `:help map-modes` for a list of modes.
'';
};
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 command to execute."; description = "The action 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."; mapOptions = mode:
nowait = mkBool false "Whether to wait for extra input on ambiguous mappings. Equivalent to adding <nowait> to a map."; mkOption {
script = mkBool false "Equivalent to adding <script> to a map."; description = "Mappings for ${mode} mode";
expr = mkBool false "Means that the action is actually an expression. Equivalent to adding <expr> to a map."; type = attrsOf mapOption;
unique = mkBool false "Whether to fail if the map is already defined. Equivalent to adding <unique> to a map."; 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.";
}; };
in { in {
options.vim = { options.vim = {
maps = mkOption { maps = mkOption {
type = attrsOf mapType; type = submodule {
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 for any mode.
For plain maps (e.g. just 'map' or 'remap') use `maps.normalVisualOp`.
'';
example = '' example = ''
maps = { maps = {
"<leader>m" = { normal."<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

@ -4,7 +4,6 @@
./ccc ./ccc
./gestures ./gestures
./motion ./motion
./new-file-template
./telescope ./telescope
./icon-picker ./icon-picker
./images ./images

View file

@ -1,23 +0,0 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
cfg = config.vim.utility.new-file-template;
in {
config = mkIf cfg.enable {
vim = {
startPlugins = [
"new-file-template-nvim"
];
pluginRC.new-file-template = entryAnywhere ''
require('new-file-template').setup(${toLuaObject cfg.setupOpts})
'';
};
};
}

View file

@ -1,6 +0,0 @@
{
imports = [
./config.nix
./new-file-template.nix
];
}

View file

@ -1,54 +0,0 @@
{lib, ...}: let
inherit (lib.options) mkOption;
inherit (lib.types) attrsOf bool listOf str;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.utility.new-file-template = {
enable = mkOption {
type = bool;
default = false;
description = ''
new-file-template.nvim: Automatically insert a template on new files in neovim.
::: {.note}
For custom templates add a directory containing `lua/templates/*.lua`
to `vim.additionalRuntimePaths`.
:::
[custom-template-docs]: https://github.com/otavioschwanck/new-file-template.nvim?tab=readme-ov-file#creating-new-templates
More documentation on the templates available at [custom-template-docs]
'';
};
setupOpts = mkPluginSetupOption "nvim-file-template.nvim" {
disableInsert = mkOption {
type = bool;
default = false;
description = "Enter insert mode after inserting the template";
};
disableAutocmd = mkOption {
type = bool;
default = false;
description = "Disable the autocmd that creates the template";
};
disableFiletype = mkOption {
type = listOf str;
default = [];
description = "Disable default templates for specific filetypes";
};
disableSpecific = mkOption {
type = attrsOf (listOf str);
default = {};
description = "Disable specific regexp for the default templates.";
example = "{ ruby = [\".*\"]; }";
};
suffixAsFiletype = mkOption {
type = bool;
default = false;
description = "Use suffix of filename rather than `vim.bo.filetype` as filetype";
};
};
};
}

View file

@ -4,19 +4,86 @@
... ...
}: let }: let
inherit (builtins) map mapAttrs filter; inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList; inherit (lib.options) mkOption;
inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames;
inherit (lib.strings) concatLines concatMapStringsSep optionalString; inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.misc) mapAttrsFlatten;
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 = filterAttrs (_: value: value != null); filterNonNull = attrs: filterAttrs (_: value: value != null) attrs;
globalsScript = globalsScript =
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}") mapAttrsFlatten (name: value: "vim.g.${name} = ${toLuaObject value}")
(filterNonNull cfg.globals); (filterNonNull cfg.globals);
extraPluginConfigs = resolveDag { extraPluginConfigs = resolveDag {
@ -31,21 +98,38 @@ in {
mapResult = result: concatLines (map mkLuarcSection result); mapResult = result: concatLines (map mkLuarcSection result);
}; };
getAction = keymap: toLuaBindings = mode: maps:
if keymap.lua map (value: ''
then mkLuaInline keymap.action vim.keymap.set(${toLuaObject mode}, ${toLuaObject value.key}, ${toLuaObject value.action}, ${toLuaObject value.config})
else keymap.action; '') (genMaps mode maps);
getOpts = keymap: { # I'm not sure if every one of these will work.
inherit (keymap) silent nowait script expr unique noremap; 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;
toLuaKeymap = { maps = [
name, nmap
value, imap
}: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})"; vmap
xmap
keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull config.maps))); smap
cmap
omap
tmap
lmap
icmap
allmap
];
mappings = concatLines (map concatLines maps);
in { in {
vim = { vim = {
luaConfigRC = { luaConfigRC = {
@ -53,7 +137,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"] keymaps; mappings = entryAfter ["extraPluginConfigs"] mappings;
# FIXME: put this somewhere less stupid # FIXME: put this somewhere less stupid
footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require.loader').register_loader()"); footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require.loader').register_loader()");
}; };