diff --git a/lib/neovim-plugin.nix b/lib/neovim-plugin.nix index 46d7969f96..2a58b84ce5 100644 --- a/lib/neovim-plugin.nix +++ b/lib/neovim-plugin.nix @@ -110,11 +110,12 @@ with lib; { extraPlugins = (optional installPackage cfg.package) ++ extraPlugins; inherit extraPackages; - - ${extraConfigNamespace} = optionalString callSetup '' + } + (optionalAttrs callSetup { + ${extraConfigNamespace} = '' require('${luaName}')${setup}(${optionalString (cfg ? settings) (toLuaObject cfg.settings)}) ''; - } + }) (optionalAttrs (isColorscheme && (colorscheme != null)) { colorscheme = mkDefault colorscheme; }) (extraConfig cfg) ]); diff --git a/modules/autocmd.nix b/modules/autocmd.nix index 280894e9f3..8b9cd76a92 100644 --- a/modules/autocmd.nix +++ b/modules/autocmd.nix @@ -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 = [ diff --git a/modules/diagnostics.nix b/modules/diagnostics.nix index 0daee58e4d..189e525fa2 100644 --- a/modules/diagnostics.nix +++ b/modules/diagnostics.nix @@ -19,7 +19,7 @@ with lib; }; config = { - extraConfigLuaPre = optionalString (config.diagnostics != { }) '' + extraConfigLuaPre = mkIf (config.diagnostics != { }) '' vim.diagnostic.config(${helpers.toLuaObject config.diagnostics}) ''; }; diff --git a/modules/highlights.nix b/modules/highlights.nix index a6a7d057ef..1a0280ae9b 100644 --- a/modules/highlights.nix +++ b/modules/highlights.nix @@ -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 - -- }} - ''; - }; + -- }} + ''; + } + ]; } diff --git a/modules/keymaps.nix b/modules/keymaps.nix index e517766749..e58b978942 100644 --- a/modules/keymaps.nix +++ b/modules/keymaps.nix @@ -90,7 +90,7 @@ with lib; ${concatStringsSep "\n" luaDefs} ''; - extraConfigLua = optionalString (config.keymaps != [ ]) '' + extraConfigLua = mkIf (config.keymaps != [ ]) '' -- Set up keybinds {{{ do local __nixvim_binds = ${helpers.toLuaObject (map normalizeMapping config.keymaps)} diff --git a/modules/opts.nix b/modules/opts.nix index f7b2d1a706..959d629fc7 100644 --- a/modules/opts.nix +++ b/modules/opts.nix @@ -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.concatNonEmptyLines ( + 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; }; } diff --git a/modules/top-level/output.nix b/modules/top-level/output.nix index 57b2152386..bd62d2174f 100644 --- a/modules/top-level/output.nix +++ b/modules/top-level/output.nix @@ -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