Skip to content

Commit

Permalink
treeside: use mkIf instead of optionalString for various extraConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
stasjok committed Jul 21, 2024
1 parent 2bd8f19 commit 73c34ca
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 68 deletions.
2 changes: 1 addition & 1 deletion lib/neovim-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ with lib;
extraPlugins = (optional installPackage cfg.package) ++ extraPlugins;
inherit extraPackages;

${extraConfigNamespace} = optionalString callSetup ''
${extraConfigNamespace} = mkIf callSetup ''
require('${luaName}')${setup}(${optionalString (cfg ? settings) (toLuaObject cfg.settings)})
'';
}
Expand Down
2 changes: 1 addition & 1 deletion modules/autocmd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ with lib;
let
inherit (config) autoGroups autoCmd;
in
mkIf (autoGroups != { } || autoCmd != { }) {
mkIf (autoGroups != { } || autoCmd != [ ]) {
# Introduced early October 2023.
# TODO remove in early December 2023.
assertions = [
Expand Down
2 changes: 1 addition & 1 deletion modules/diagnostics.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with lib;
};

config = {
extraConfigLuaPre = optionalString (config.diagnostics != { }) ''
extraConfigLuaPre = mkIf (config.diagnostics != { }) ''
vim.diagnostic.config(${helpers.toLuaObject config.diagnostics})
'';
};
Expand Down
80 changes: 41 additions & 39 deletions modules/highlights.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,52 @@ with lib;
};
};

config = {
extraConfigLuaPre =
(optionalString (config.highlight != { })
# lua
''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlight}
config = mkMerge [
{
extraConfigLuaPre =
mkIf (config.highlight != { })
# lua
''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlight}
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
end
end
end
-- }}
''
)
+ (optionalString (config.match != { })
# lua
''
-- Match groups {{
do
local match = ${helpers.toLuaObject config.match}
-- }}
'';
extraConfigLuaPost =
mkIf (config.highlightOverride != { })
# lua
''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlightOverride}
for k,v in pairs(match) do
vim.fn.matchadd(k, v)
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
end
end
end
-- }}
''
);

extraConfigLuaPost =
optionalString (config.highlightOverride != { })
# lua
''
-- Highlight groups {{
do
local highlights = ${helpers.toLuaObject config.highlightOverride}
'';
}
{
extraConfigLuaPre =
mkIf (config.match != { })
# lua
''
-- Match groups {{
do
local match = ${helpers.toLuaObject config.match}
for k,v in pairs(highlights) do
vim.api.nvim_set_hl(0, k, v)
for k,v in pairs(match) do
vim.fn.matchadd(k, v)
end
end
end
-- }}
'';
};
-- }}
'';
}
];
}
54 changes: 29 additions & 25 deletions modules/opts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,35 @@ in
};

config = {
extraConfigLuaPre = concatLines (
mapAttrsToList (
optionName:
{
prettyName,
luaVariableName,
luaApi,
...
}:
let
varName = "nixvim_${luaVariableName}";
optionDefinitions = config.${optionName};
in
optionalString (optionDefinitions != { }) ''
-- Set up ${prettyName} {{{
do
local ${varName} = ${helpers.toLuaObject optionDefinitions}
extraConfigLuaPre =
let
content = helpers.concatNonEmptyStringsNewline (
mapAttrsToList (
optionName:
{
prettyName,
luaVariableName,
luaApi,
...
}:
let
varName = "nixvim_${luaVariableName}";
optionDefinitions = config.${optionName};
in
optionalString (optionDefinitions != { }) ''
-- Set up ${prettyName} {{{
do
local ${varName} = ${helpers.toLuaObject optionDefinitions}
for k,v in pairs(${varName}) do
vim.${luaApi}[k] = v
end
end
-- }}}
''
) optionsAttrs
);
for k,v in pairs(${varName}) do
vim.${luaApi}[k] = v
end
end
-- }}}
''
) optionsAttrs
);
in
mkIf (content != "") content;
};
}
2 changes: 1 addition & 1 deletion modules/top-level/output.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ with lib;
'';
};

extraConfigLuaPre = lib.optionalString config.wrapRc ''
extraConfigLuaPre = lib.mkIf config.wrapRc ''
-- Ignore the user lua configuration
vim.opt.runtimepath:remove(vim.fn.stdpath('config')) -- ~/.config/nvim
vim.opt.runtimepath:remove(vim.fn.stdpath('config') .. "/after") -- ~/.config/nvim/after
Expand Down

0 comments on commit 73c34ca

Please sign in to comment.