Skip to content

Commit

Permalink
modules/wrapper: add vim.options (#386)
Browse files Browse the repository at this point in the history
* wrapper/rc: add `vim.options`

Translates an attribute set of values into `vim.o` values in a key-value format.

* docs: document addition of optionsScript

* wrapper/rc: don't filter null values in {options,global}Script

* wrapper/rc: add examples to vim.options & vim.globals; wording
  • Loading branch information
NotAShelf authored Sep 28, 2024
1 parent c957b23 commit ab9a7c1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
17 changes: 10 additions & 7 deletions docs/manual/configuring/dag-entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ can add code that relies on other code. However, if you don't know what the
entries are called, it's hard to do that, so here is a list of the internal
entries in nvf:

`vim.luaConfigRC` (top-level DAG):
## `vim.luaConfigRC` (top-level DAG) {#ch-vim-luaconfigrc}

1. (`luaConfigPre`) - not a part of the actual DAG, instead, it's simply
inserted before the rest of the DAG
2. `globalsScript` - used to set globals defined in `vim.globals`
3. `basic` - used to set basic configuration options
4. `theme` (this is simply placed before `pluginConfigs`, meaning that surrounding entries don't depend on it) - used to set up the theme, which has to be done before other plugins
5. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option,
see the [Custom Plugins](/index.xhtml#ch-custom-plugins) page for adding your own
plugins) DAG, used to set up internal plugins
6. `extraPluginConfigs` - the result of `vim.extraPlugins`, which is not a
4. `optionsScript` - used to set options defined in `vim.o`
5. `theme` (this is simply placed before `pluginConfigs`, meaning that
surrounding entries don't depend on it) - used to set up the theme, which has
to be done before other plugins
6. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option,
see the [Custom Plugins](/index.xhtml#ch-custom-plugins) page for adding your
own plugins) DAG, used to set up internal plugins
7. `extraPluginConfigs` - the result of `vim.extraPlugins`, which is not a
direct DAG, but is converted to, and resolved as one internally
7. `mappings` - the result of `vim.maps`
8. `mappings` - the result of `vim.maps`
14 changes: 9 additions & 5 deletions modules/wrapper/rc/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@
maps);
in {
config = let
filterNonNull = attrs: filterAttrs (_: value: value != null) attrs;
globalsScript =
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}")
(filterNonNull cfg.globals);
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}") cfg.globals;

optionsScript =
mapAttrsToList (name: value: "vim.o.${name} = ${toLuaObject value}") cfg.options;

extraPluginConfigs = resolveDag {
name = "extra plugin configs";
Expand Down Expand Up @@ -132,9 +133,12 @@ in {
in {
vim = {
luaConfigRC = {
# `vim.g` and `vim.o`
globalsScript = entryAnywhere (concatLines globalsScript);
# basic
pluginConfigs = entryAfter ["basic"] pluginConfigs;
optionsScript = entryAfter ["basic"] (concatLines optionsScript);

# Basic
pluginConfigs = entryAfter ["optionsScript"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] mappings;
};
Expand Down
30 changes: 26 additions & 4 deletions modules/wrapper/rc/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,38 @@ in {
globals = mkOption {
type = attrs;
default = {};
example = {"some_variable" = 42;};
description = ''
An attribute set containing global variable values
for storing vim variables as early as possible. If
populated, this option will set vim variables in the
built luaConfigRC as the first item.
E.g. {foo = "bar"} will set `vim.g.foo` to "bar" where
the type of `bar` in the resulting vimscript will be
infered from the type of the value in the `{name = value}`
pair.
::: {.note}
`{foo = "bar";}` will set `vim.g.foo` to "bar", where
the type of `bar` in the resulting Lua value will be
inferred from the type of the value in the `{name = value;}`
pair passed to the option.
:::
'';
};

options = mkOption {
type = attrs;
default = {};
example = {visualbell = true;};
description = ''
An attribute set containing vim options to be set
as early as possible. If populated, this option will
set vim options in the built luaConfigRC after `basic`
and before `pluginConfigs` DAG entries.
::: {.note}
`{foo = "bar";}` will set `vim.o.foo` to "bar", where
the type of `bar` in the resulting Lua value will be
inferred from the type of the value in the`{name = value;}`
pair passed to the option.
:::
'';
};

Expand Down

0 comments on commit ab9a7c1

Please sign in to comment.