Skip to content

Commit

Permalink
rc: bindings to vim.opt
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Feb 25, 2025
1 parent ae3fd99 commit b2f8a7c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
15 changes: 13 additions & 2 deletions modules/wrapper/rc/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}: let
inherit (builtins) map mapAttrs filter;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.strings) concatLines concatMapStringsSep optionalString;
inherit (lib.trivial) showWarnings;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
Expand All @@ -18,7 +18,18 @@ 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 [
(optionalString (append != null) "vim.opt.${name}:append(${toLuaObject append})")
(optionalString (prepend != null) "vim.opt.${name}:prepend(${toLuaObject prepend})")
(optionalString (remove != null) "vim.opt.${name}:remove(${toLuaObject remove})")
])
cfg.opt;

extraPluginConfigs = resolveDag {
name = "extra plugin configs";
Expand Down
36 changes: 35 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,40 @@ 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 = {runtimepath.append = ["~/.config/nvim"];};
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

0 comments on commit b2f8a7c

Please sign in to comment.