neovim/init: merge conditionals in options set

This commit is contained in:
NotAShelf 2025-01-07 06:12:13 +03:00
parent b704a28a12
commit 356f92053c
No known key found for this signature in database
GPG key ID: EED98D11B85A2819
2 changed files with 49 additions and 47 deletions

View file

@ -5,6 +5,7 @@
}: let
inherit (lib.options) mkOption mkEnableOption literalMD;
inherit (lib.strings) optionalString;
inherit (lib.attrsets) optionalAttrs;
inherit (lib.types) enum bool str int either;
inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAfter;
@ -94,55 +95,55 @@ in {
# Set options that were previously interpolated in 'luaConfigRC.basic' as vim.options (vim.o)
# and 'vim.globals' (vim.g). Future options, if possible, should be added here instead of the
# luaConfigRC section below.
options = pushDownDefault {
# Options that are always set, with a lower priority
encoding = "utf-8";
hidden = true;
expandtab = true;
options = pushDownDefault (lib.mergeAttrsList [
{
# Options that are always set, with a lower priority
encoding = "utf-8";
hidden = true;
expandtab = true;
# Junkfile Behaviour
swapfile = !cfg.preventJunkFiles;
backup = !cfg.preventJunkFiles;
writebackup = !cfg.preventJunkFiles;
};
# Junkfile Behaviour
swapfile = !cfg.preventJunkFiles;
backup = !cfg.preventJunkFiles;
writebackup = !cfg.preventJunkFiles;
}
# Options that are more difficult to set through 'vim.options'. Fear not, though
# as the Lua DAG is still as powerful as it could be.
(optionalAttrs cfg.undoFile.enable {
undofile = true;
undodir = cfg.undoFile.path;
})
(optionalAttrs (cfg.bell == "none") {
errorbells = false;
visualbell = false;
})
(optionalAttrs (cfg.bell == "on") {
visualbell = false;
})
(optionalAttrs (cfg.bell == "visual") {
visualbell = false;
})
(optionalAttrs (cfg.lineNumberMode == "relative") {
relativenumber = true;
})
(optionalAttrs (cfg.lineNumberMode == "number") {
number = true;
})
(optionalAttrs (cfg.lineNumberMode == "relNumber") {
number = true;
relativenumber = true;
})
]);
# Options that are more difficult to set through 'vim.options'. Namely, appending values
# to pre-set Neovim options. Fear not, though as the Lua DAG is still as powerful as it
# could be.
luaConfigRC.basic = entryAfter ["globalsScript"] ''
-- Settings that are set for everything
vim.opt.shortmess:append("c")
${optionalString cfg.undoFile.enable ''
vim.o.undofile = true
vim.o.undodir = ${toLuaObject cfg.undoFile.path}
''}
${optionalString (cfg.bell == "none") ''
vim.o.errorbells = false
vim.o.visualbell = false
''}
${optionalString (cfg.bell == "on") ''
vim.o.visualbell = false
''}
${optionalString (cfg.bell == "visual") ''
vim.o.errorbells = false
''}
${optionalString (cfg.lineNumberMode == "relative") ''
vim.o.relativenumber = true
''}
${optionalString (cfg.lineNumberMode == "number") ''
vim.o.number = true
''}
${optionalString (cfg.lineNumberMode == "relNumber") ''
vim.o.number = true
vim.o.relativenumber = true
''}
${optionalString cfg.useSystemClipboard ''
vim.opt.clipboard:append("unnamedplus")
''}

View file

@ -235,7 +235,8 @@ in {
if isBool x
then toVimBool x # convert to a yes/no str
else x;
description = "Show the sign column"
description = "Show the sign column";
};
tabstop = mkOption {
type = int;