Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rc: add bindings to vim.opt #666

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion modules/wrapper/rc/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.trivial) showWarnings;
inherit (lib.lists) optional;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
Expand All @@ -18,7 +19,19 @@ in {
mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}") cfg.globals;

optionsScript =
mapAttrsToList (name: value: "vim.o.${name} = ${toLuaObject value}") cfg.options;
mapAttrsToList (name: value: "vim.o.${name} = ${toLuaObject value}") cfg.options
++ mapAttrsToList (
name: {
append,
prepend,
remove,
}:
concatLines
((optional (append != null) "vim.opt.${name}:append(${toLuaObject append})")
++ (optional (prepend != null) "vim.opt.${name}:prepend(${toLuaObject prepend})")
++ (optional (remove != null) "vim.opt.${name}:remove(${toLuaObject remove})"))
)
cfg.opt;

extraPluginConfigs = resolveDag {
name = "extra plugin configs";
Expand Down
42 changes: 41 additions & 1 deletion modules/wrapper/rc/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}: let
inherit (lib.options) mkOption literalMD literalExpression;
inherit (lib.strings) optionalString;
inherit (lib.types) str bool int enum attrsOf lines listOf either path submodule anything;
inherit (lib.types) str bool int enum attrsOf lines listOf either path submodule anything nullOr;
inherit (lib.nvim.types) dagOf;
inherit (lib.nvim.lua) listToLuaTable;

Expand Down Expand Up @@ -278,6 +278,46 @@ in {
'';
};

opt = mkOption {
default = {};
type = attrsOf (submodule {
options = {
append = mkOption {
type = nullOr (listOf anything);
default = null;
description = "Values to append";
};

prepend = mkOption {
type = nullOr (listOf anything);
default = null;
description = "Values to prepend";
};

remove = mkOption {
type = nullOr (listOf anything);
default = null;
description = "Values to remove";
};
};
});

example = literalExpression ''
{
runtimepath.append = ["~/.config/nvim"];
formatoptions.append = ["n"];
formatoptions.remove = ["o"];
}
'';
description = ''
Wrapper of the lua `vim.opt` interface. Makes interacting with list and
map-style option more convenient.

If you're looking to set an option normally, instead of add/remove from
a list/map type option, see {option}`vim.options` instead.
'';
};

pluginRC = mkOption {
type = either (dagOf lines) str;
default = {};
Expand Down
Loading