diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index ff8a4585f..cb8a3d33a 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -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; @@ -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"; diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index 4cd3026fe..8435c34f0 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -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; @@ -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 = {};