From 5d8eb192d7735c3d56c8a501a2e96958163b6373 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 16 Mar 2024 09:29:32 +0000 Subject: [PATCH] plugins: switch to mkLuaInline --- modules/core/default.nix | 3 +- modules/rich-presence/neocord/neocord.nix | 3 +- modules/statusline/lualine/config.nix | 29 +++++++------ modules/terminal/toggleterm/toggleterm.nix | 37 ++++++++-------- modules/ui/breadcrumbs/config.nix | 50 +++++++++++----------- modules/ui/smartcolumn/config.nix | 7 +-- modules/utility/telescope/config.nix | 3 +- modules/visuals/fidget/fidget.nix | 27 ++++++------ 8 files changed, 80 insertions(+), 79 deletions(-) diff --git a/modules/core/default.nix b/modules/core/default.nix index 682566c..954b9d9 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -12,6 +12,7 @@ inherit (lib.types) bool str listOf oneOf attrsOf nullOr attrs submodule unspecified lines; inherit (lib.nvim.types) dagOf pluginsOpt extraPluginType; inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort; + inherit (lib.generators) mkLuaInline; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.vim) valToVim; @@ -86,7 +87,7 @@ else config; action = if action.lua - then {"__raw" = action.action;} + then mkLuaInline action.action else action.action; }; in diff --git a/modules/rich-presence/neocord/neocord.nix b/modules/rich-presence/neocord/neocord.nix index 28f89c7..1d6e625 100644 --- a/modules/rich-presence/neocord/neocord.nix +++ b/modules/rich-presence/neocord/neocord.nix @@ -2,6 +2,7 @@ inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.types) bool int str enum nullOr listOf; + inherit (lib.nvim.types) mkPluginSetupOption; in { imports = [ @@ -22,7 +23,7 @@ in { options.vim.presence.neocord = { enable = mkEnableOption "neocord plugin for discord rich presence"; - setupOpts = lib.nvim.mkPluginSetupOption "neocord" { + setupOpts = mkPluginSetupOption "neocord" { logo = mkOption { type = str; # TODO: can the default be documented better, maybe with an enum? default = "auto"; diff --git a/modules/statusline/lualine/config.nix b/modules/statusline/lualine/config.nix index 9ab576e..96c874b 100644 --- a/modules/statusline/lualine/config.nix +++ b/modules/statusline/lualine/config.nix @@ -6,10 +6,11 @@ inherit (lib.modules) mkIf mkMerge; inherit (lib.trivial) boolToString; inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.generators) mkLuaInline; cfg = config.vim.statusline.lualine; breadcrumbsCfg = config.vim.ui.breadcrumbs; - rawLua = code: {"__raw" = code;}; in { config = mkMerge [ # TODO: move into nvim-tree file @@ -23,7 +24,7 @@ in { # TODO: rewrite in new syntax winbar.lualine_c = [ "navic" - (rawLua "draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}") + (mkLuaInline "draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}") ]; }; }) @@ -49,20 +50,20 @@ in { }; sections = { - lualine_a = builtins.map rawLua (cfg.activeSection.a ++ cfg.extraActiveSection.a); - lualine_b = builtins.map rawLua (cfg.activeSection.b ++ cfg.extraActiveSection.b); - lualine_c = builtins.map rawLua (cfg.activeSection.c ++ cfg.extraActiveSection.c); - lualine_x = builtins.map rawLua (cfg.activeSection.x ++ cfg.extraActiveSection.x); - lualine_y = builtins.map rawLua (cfg.activeSection.y ++ cfg.extraActiveSection.y); - lualine_z = builtins.map rawLua (cfg.activeSection.z ++ cfg.extraActiveSection.z); + lualine_a = builtins.map mkLuaInline (cfg.activeSection.a ++ cfg.extraActiveSection.a); + lualine_b = builtins.map mkLuaInline (cfg.activeSection.b ++ cfg.extraActiveSection.b); + lualine_c = builtins.map mkLuaInline (cfg.activeSection.c ++ cfg.extraActiveSection.c); + lualine_x = builtins.map mkLuaInline (cfg.activeSection.x ++ cfg.extraActiveSection.x); + lualine_y = builtins.map mkLuaInline (cfg.activeSection.y ++ cfg.extraActiveSection.y); + lualine_z = builtins.map mkLuaInline (cfg.activeSection.z ++ cfg.extraActiveSection.z); }; inactive_sections = { - lualine_a = builtins.map rawLua (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a); - lualine_b = builtins.map rawLua (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b); - lualine_c = builtins.map rawLua (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c); - lualine_x = builtins.map rawLua (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x); - lualine_y = builtins.map rawLua (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y); - lualine_z = builtins.map rawLua (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z); + lualine_a = builtins.map mkLuaInline (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a); + lualine_b = builtins.map mkLuaInline (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b); + lualine_c = builtins.map mkLuaInline (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c); + lualine_x = builtins.map mkLuaInline (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x); + lualine_y = builtins.map mkLuaInline (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y); + lualine_z = builtins.map mkLuaInline (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z); }; # probably don't need this? tabline = []; diff --git a/modules/terminal/toggleterm/toggleterm.nix b/modules/terminal/toggleterm/toggleterm.nix index 8b3f051..865e66f 100644 --- a/modules/terminal/toggleterm/toggleterm.nix +++ b/modules/terminal/toggleterm/toggleterm.nix @@ -7,7 +7,8 @@ inherit (lib.nvim.binds) mkMappingOption; inherit (lib.types) nullOr str enum bool package either int; inherit (lib) mkRenamedOptionModule; - inherit (lib.nvim.types) mkPluginSetupOption rawLua; + inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.generators) mkLuaInline; in { imports = [ (mkRenamedOptionModule ["vim" "terminal" "toggleterm" "direction"] ["vim" "terminal" "toggleterm" "setupOpts" "direction"]) @@ -38,32 +39,28 @@ in { }; size = mkOption { - type = either rawLua int; + type = either luaInline int; description = "Number or lua function which is passed to the current terminal"; - default = { - __raw = '' - function(term) - if term.direction == "horizontal" then - return 15 - elseif term.direction == "vertical" then - return vim.o.columns * 0.4 - end + default = mkLuaInline '' + function(term) + if term.direction == "horizontal" then + return 15 + elseif term.direction == "vertical" then + return vim.o.columns * 0.4 end - ''; - }; + end + ''; }; winbar = { enabled = mkEnableOption "winbar in terminal" // {default = true;}; name_formatter = mkOption { - type = rawLua; + type = luaInline; description = "Winbar formatter function."; - default = { - __raw = '' - function(term) - return term.name - end - ''; - }; + default = mkLuaInline '' + function(term) + return term.name + end + ''; }; }; }; diff --git a/modules/ui/breadcrumbs/config.nix b/modules/ui/breadcrumbs/config.nix index 88ddddf..35c08ec 100644 --- a/modules/ui/breadcrumbs/config.nix +++ b/modules/ui/breadcrumbs/config.nix @@ -8,9 +8,9 @@ inherit (lib.lists) optionals; inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.lua) toLuaObject; + inherit (lib.generators) mkLuaInline; cfg = config.vim.ui.breadcrumbs; - mkRawLua = code: {__raw = code;}; in { config = mkIf cfg.enable { vim.startPlugins = @@ -31,40 +31,40 @@ in { vim.ui.breadcrumbs.navbuddy.setupOpts = { mappings = { - ${cfg.navbuddy.mappings.close} = mkRawLua "actions.close()"; - ${cfg.navbuddy.mappings.nextSibling} = mkRawLua "actions.next_sibling()"; - ${cfg.navbuddy.mappings.previousSibling} = mkRawLua "actions.previous_sibling()"; - ${cfg.navbuddy.mappings.parent} = mkRawLua "actions.parent()"; - ${cfg.navbuddy.mappings.children} = mkRawLua "actions.children()"; - ${cfg.navbuddy.mappings.root} = mkRawLua "actions.root()"; + ${cfg.navbuddy.mappings.close} = mkLuaInline "actions.close()"; + ${cfg.navbuddy.mappings.nextSibling} = mkLuaInline "actions.next_sibling()"; + ${cfg.navbuddy.mappings.previousSibling} = mkLuaInline "actions.previous_sibling()"; + ${cfg.navbuddy.mappings.parent} = mkLuaInline "actions.parent()"; + ${cfg.navbuddy.mappings.children} = mkLuaInline "actions.children()"; + ${cfg.navbuddy.mappings.root} = mkLuaInline "actions.root()"; - ${cfg.navbuddy.mappings.visualName} = mkRawLua "actions.visual_name()"; - ${cfg.navbuddy.mappings.visualScope} = mkRawLua "actions.visual_scope()"; + ${cfg.navbuddy.mappings.visualName} = mkLuaInline "actions.visual_name()"; + ${cfg.navbuddy.mappings.visualScope} = mkLuaInline "actions.visual_scope()"; - ${cfg.navbuddy.mappings.yankName} = mkRawLua "actions.yank_name()"; - ${cfg.navbuddy.mappings.yankScope} = mkRawLua "actions.yank_scope()"; + ${cfg.navbuddy.mappings.yankName} = mkLuaInline "actions.yank_name()"; + ${cfg.navbuddy.mappings.yankScope} = mkLuaInline "actions.yank_scope()"; - ${cfg.navbuddy.mappings.insertName} = mkRawLua "actions.insert_name()"; - ${cfg.navbuddy.mappings.insertScope} = mkRawLua "actions.insert_scope()"; + ${cfg.navbuddy.mappings.insertName} = mkLuaInline "actions.insert_name()"; + ${cfg.navbuddy.mappings.insertScope} = mkLuaInline "actions.insert_scope()"; - ${cfg.navbuddy.mappings.appendName} = mkRawLua "actions.append_name()"; - ${cfg.navbuddy.mappings.appendScope} = mkRawLua "actions.append_scope()"; + ${cfg.navbuddy.mappings.appendName} = mkLuaInline "actions.append_name()"; + ${cfg.navbuddy.mappings.appendScope} = mkLuaInline "actions.append_scope()"; - ${cfg.navbuddy.mappings.rename} = mkRawLua "actions.rename()"; + ${cfg.navbuddy.mappings.rename} = mkLuaInline "actions.rename()"; - ${cfg.navbuddy.mappings.delete} = mkRawLua "actions.delete()"; + ${cfg.navbuddy.mappings.delete} = mkLuaInline "actions.delete()"; - ${cfg.navbuddy.mappings.foldCreate} = mkRawLua "actions.fold_create()"; - ${cfg.navbuddy.mappings.foldDelete} = mkRawLua "actions.fold_delete()"; + ${cfg.navbuddy.mappings.foldCreate} = mkLuaInline "actions.fold_create()"; + ${cfg.navbuddy.mappings.foldDelete} = mkLuaInline "actions.fold_delete()"; - ${cfg.navbuddy.mappings.comment} = mkRawLua "actions.comment()"; + ${cfg.navbuddy.mappings.comment} = mkLuaInline "actions.comment()"; - ${cfg.navbuddy.mappings.select} = mkRawLua "actions.select()"; + ${cfg.navbuddy.mappings.select} = mkLuaInline "actions.select()"; - ${cfg.navbuddy.mappings.moveDown} = mkRawLua "actions.move_down()"; - ${cfg.navbuddy.mappings.moveUp} = mkRawLua "actions.move_up()"; + ${cfg.navbuddy.mappings.moveDown} = mkLuaInline "actions.move_down()"; + ${cfg.navbuddy.mappings.moveUp} = mkLuaInline "actions.move_up()"; - ${cfg.navbuddy.mappings.telescope} = mkRawLua '' + ${cfg.navbuddy.mappings.telescope} = mkLuaInline '' actions.telescope({ layout_strategy = "horizontal", layout_config = { @@ -74,7 +74,7 @@ in { preview_width = 0.50 }, })''; - ${cfg.navbuddy.mappings.help} = mkRawLua "actions.help()"; + ${cfg.navbuddy.mappings.help} = mkLuaInline "actions.help()"; }; }; diff --git a/modules/ui/smartcolumn/config.nix b/modules/ui/smartcolumn/config.nix index 8aff4b0..9edbdbb 100644 --- a/modules/ui/smartcolumn/config.nix +++ b/modules/ui/smartcolumn/config.nix @@ -13,8 +13,9 @@ in { vim = { startPlugins = ["smartcolumn"]; - vim.luaConfigRC.smartcolumn = entryAnywhere '' - require("smartcolumn").setup(${toLuaObject cfg.setupOpts}) - ''; + luaConfigRC.smartcolumn = entryAnywhere '' + require("smartcolumn").setup(${toLuaObject cfg.setupOpts}) + ''; + }; }; } diff --git a/modules/utility/telescope/config.nix b/modules/utility/telescope/config.nix index 4e60f22..f178158 100644 --- a/modules/utility/telescope/config.nix +++ b/modules/utility/telescope/config.nix @@ -9,6 +9,7 @@ inherit (lib.nvim.dag) entryAnywhere; # TODO: move this to its own module inherit (lib) pushDownDefault; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.telescope; self = import ./telescope.nix {inherit pkgs lib;}; @@ -66,7 +67,7 @@ in { vim.luaConfigRC.telescope = entryAnywhere '' local telescope = require('telescope') - telescope.setup(${nvim.lua.toLuaObject cfg.setupOpts}) + telescope.setup(${toLuaObject cfg.setupOpts}) ${ if config.vim.ui.noice.enable diff --git a/modules/visuals/fidget/fidget.nix b/modules/visuals/fidget/fidget.nix index 482391a..6897800 100644 --- a/modules/visuals/fidget/fidget.nix +++ b/modules/visuals/fidget/fidget.nix @@ -9,8 +9,7 @@ inherit (lib.strings) toUpper; inherit (lib.types) int float bool str enum listOf attrsOf; inherit (lib.nvim.types) mkPluginSetupOption; - - rawLua = lua: {__raw = lua;}; + inherit (lib.generators) mkLuaInline; in { imports = [ (mkRenamedOptionModule ["vim" "visuals" "fidget-nvim" "align" "bottom"] ["vim" "visuals" "fidget-nvim" "setupOpts" "notification" "window" "align"]) @@ -50,7 +49,7 @@ in { apply = clear: if clear then - rawLua '' + mkLuaInline '' function(client_id) local client = vim.lsp.get_client_by_id(client_id) return client and client.name or nil @@ -66,7 +65,7 @@ in { return msg.lsp_client.name end ''; - apply = rawLua; + apply = mkLuaInline; }; ignore = mkOption { description = "Ignore LSP servers by name"; @@ -177,7 +176,7 @@ in { default = '' require("fidget.progress.display").default_format_message ''; - apply = rawLua; + apply = mkLuaInline; }; format_annote = mkOption { description = "How to format a progress annotation"; @@ -185,7 +184,7 @@ in { default = '' function(msg) return msg.title end ''; - apply = rawLua; + apply = mkLuaInline; }; format_group_name = mkOption { description = "How to format a progress notification group's name"; @@ -193,13 +192,13 @@ in { default = '' function(group) return tostring(group) end ''; - apply = rawLua; + apply = mkLuaInline; }; overrides = mkOption { description = "Override options from the default notification config"; type = attrsOf str; default = {rust_analyzer = "{ name = 'rust-analyzer' }";}; - apply = mapAttrs (key: lua: rawLua lua); + apply = mapAttrs (key: lua: mkLuaInline lua); }; }; @@ -227,7 +226,7 @@ in { description = "Minimum notifications level"; type = enum ["debug" "info" "warn" "error"]; default = "info"; - apply = filter: rawLua "vim.log.levels.${toUpper filter}"; + apply = filter: mkLuaInline "vim.log.levels.${toUpper filter}"; }; history_size = mkOption { description = "Number of removed messages to retain in history"; @@ -243,7 +242,7 @@ in { description = "How to configure notification groups when instantiated"; type = attrsOf str; default = {default = "require('fidget.notification').default_config";}; - apply = mapAttrs (key: lua: rawLua lua); + apply = mapAttrs (key: lua: mkLuaInline lua); }; redirect = mkOption { description = "Conditionally redirect notifications to another backend"; @@ -255,7 +254,7 @@ in { end end ''; - apply = rawLua; + apply = mkLuaInline; }; view = { @@ -287,7 +286,7 @@ in { return cnt == 1 and msg or string.format("(%dx) %s", cnt, msg) end ''; - apply = rawLua; + apply = mkLuaInline; }; }; @@ -373,7 +372,7 @@ in { description = "Minimum logging level"; type = enum ["debug" "error" "info" "trace" "warn" "off"]; default = "warn"; - apply = logLevel: rawLua "vim.log.levels.${toUpper logLevel}"; + apply = logLevel: mkLuaInline "vim.log.levels.${toUpper logLevel}"; }; max_size = mkOption { description = "Maximum log file size, in KB"; @@ -391,7 +390,7 @@ in { default = '' string.format("%s/fidget.nvim.log", vim.fn.stdpath("cache")) ''; - apply = rawLua; + apply = mkLuaInline; }; }; };