treewide: remove with lib; from docs and sources

This commit is contained in:
raf 2024-11-25 18:11:53 +03:00
parent 0be7d8adcf
commit 7da133c3a1
Signed by: NotAShelf
GPG key ID: AF26552424E53993
2 changed files with 36 additions and 23 deletions

View file

@ -1,9 +1,10 @@
# Keybinds {#sec-keybinds} # Keybinds {#sec-keybinds}
As of 0.4, there exists an API for writing your own keybinds and a couple of As of 0.4, there exists an API for writing your own keybinds and a couple of
useful utility functions are available in the [extended standard useful utility functions are available in the
library](https://github.com/NotAShelf/nvf/tree/main/lib). The following [extended standard library](https://github.com/NotAShelf/nvf/tree/main/lib). The
section contains a general overview to how you may utilize said functions. following section contains a general overview to how you may utilize said
functions.
## Custom Key Mappings Support for a Plugin {#sec-custom-key-mappings} ## Custom Key Mappings Support for a Plugin {#sec-custom-key-mappings}
@ -26,18 +27,18 @@ An example, simple keybinding, can look like this:
``` ```
There are many settings available in the options. Please refer to the There are many settings available in the options. Please refer to the
[documentation](https://notashelf.github.io/nvf/options.html#opt-vim.keymaps) [documentation](https://notashelf.github.io/nvf/options.html#opt-vim.keymaps) to
to see a list of them. see a list of them.
**nvf** provides a list of helper commands, so that you don't have to write the **nvf** provides a list of helper commands, so that you don't have to write the
mapping attribute sets every time: mapping attribute sets every time:
- `mkBinding = key: action: desc:` - makes a basic binding, with `silent` set - `mkBinding = key: action: desc:` - makes a basic binding, with `silent` set to
to true. true.
- `mkExprBinding = key: action: desc:` - makes an expression binding, with - `mkExprBinding = key: action: desc:` - makes an expression binding, with
`lua`, `silent`, and `expr` set to true. `lua`, `silent`, and `expr` set to true.
- `mkLuaBinding = key: action: desc:` - makes an expression binding, with - `mkLuaBinding = key: action: desc:` - makes an expression binding, with `lua`,
`lua`, and `silent` set to true. and `silent` set to true.
Do note that the Lua in these bindings is actual Lua, and not pasted into a Do note that the Lua in these bindings is actual Lua, and not pasted into a
`:lua` command. Therefore, you should either pass in a function like `:lua` command. Therefore, you should either pass in a function like
@ -57,7 +58,8 @@ attribute sets:
- `{ someKey = "some_value" }` - `{ someKey = "some_value" }`
- `{ someKey = { description = "Some Description"; }; }` - `{ someKey = { description = "Some Description"; }; }`
and merges them into `{ someKey = { value = "some_value"; description = "Some Description"; }; }` and merges them into
`{ someKey = { value = "some_value"; description = "Some Description"; }; }`
```nix ```nix
addDescriptionsToMappings = actualMappings: mappingDefinitions: addDescriptionsToMappings = actualMappings: mappingDefinitions:
@ -67,8 +69,8 @@ This function can be used in combination with the same `mkBinding` functions as
above, except they only take two arguments - `binding` and `action`, and have above, except they only take two arguments - `binding` and `action`, and have
different names: different names:
- `mkSetBinding = binding: action:` - makes a basic binding, with `silent` - `mkSetBinding = binding: action:` - makes a basic binding, with `silent` set
set to true. to true.
- `mkSetExprBinding = binding: action:` - makes an expression binding, with - `mkSetExprBinding = binding: action:` - makes an expression binding, with
`lua`, `silent`, and `expr` set to true. `lua`, `silent`, and `expr` set to true.
- `mkSetLuaBinding = binding: action:` - makes an expression binding, with - `mkSetLuaBinding = binding: action:` - makes an expression binding, with
@ -79,7 +81,10 @@ usage should look something like this:
```nix ```nix
# plugindefinition.nix # plugindefinition.nix
{lib, ...}: with lib; { {lib, ...}: let
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
in {
options.vim.plugin = { options.vim.plugin = {
enable = mkEnableOption "Enable plugin"; enable = mkEnableOption "Enable plugin";
@ -109,9 +114,10 @@ usage should look something like this:
pkgs, pkgs,
lib, lib,
... ...
}: }: let
with lib; inherit (lib.modules) mkIf mkMerge;
with builtins; let inherit (lib.nvim.binds) mkSetBinding;
cfg = config.vim.plugin; cfg = config.vim.plugin;
self = import ./plugindefinition.nix {inherit lib;}; self = import ./plugindefinition.nix {inherit lib;};
mappingDefinitions = self.options.vim.plugin; mappingDefinitions = self.options.vim.plugin;
@ -157,11 +163,12 @@ in {
# ... # ...
}; };
} }
``` ```
::: {.note} ::: {.note}
If you have come across a plugin that has an API that doesn't seem to easily If you have come across a plugin that has an API that doesn't seem to easily
allow custom keybindings, don't be scared to implement a draft PR. We'll help allow custom keybindings, don't be scared to implement a draft PR. We'll help
you get it done. you get it done.
::: :::

View file

@ -1,31 +1,37 @@
{lib}: {lib}: let
with lib; let inherit (lib.options) mkOption mkPackageOption;
inherit (lib.attrsets) attrNames;
inherit (lib.types) listOf either enum submodule package;
diagnosticSubmodule = _: { diagnosticSubmodule = _: {
options = { options = {
type = mkOption { type = mkOption {
description = "Type of diagnostic to enable"; description = "Type of diagnostic to enable";
type = attrNames diagnostics; type = attrNames diagnostics;
}; };
package = mkOption { package = mkOption {
type = package;
description = "Diagnostics package"; description = "Diagnostics package";
type = types.package;
}; };
}; };
}; };
in {
diagnostics = { diagnostics = {
langDesc, langDesc,
diagnosticsProviders, diagnosticsProviders,
defaultDiagnosticsProvider, defaultDiagnosticsProvider,
}: }:
mkOption { mkOption {
description = "List of ${langDesc} diagnostics to enable"; type = listOf (either (enum (attrNames diagnosticsProviders)) (submodule diagnosticSubmodule));
type = with types; listOf (either (enum (attrNames diagnosticsProviders)) (submodule diagnosticSubmodule));
default = defaultDiagnosticsProvider; default = defaultDiagnosticsProvider;
description = "List of ${langDesc} diagnostics to enable";
}; };
mkGrammarOption = pkgs: grammar: mkGrammarOption = pkgs: grammar:
mkPackageOption pkgs ["${grammar} treesitter"] { mkPackageOption pkgs ["${grammar} treesitter"] {
default = ["vimPlugins" "nvim-treesitter" "builtGrammars" grammar]; default = ["vimPlugins" "nvim-treesitter" "builtGrammars" grammar];
}; };
in {
inherit diagnostics diagnosticSubmodule mkGrammarOption;
} }