diff --git a/configuration.nix b/configuration.nix index 8420bbf..de778d5 100644 --- a/configuration.nix +++ b/configuration.nix @@ -210,7 +210,7 @@ inputs: let }; smartcolumn = { enable = true; - columnAt.languages = { + setupOpts.custom_colorcolumn = { # this is a freeform module, it's `buftype = int;` for configuring column position nix = 110; ruby = 120; diff --git a/modules/ui/smartcolumn/config.nix b/modules/ui/smartcolumn/config.nix index 48b47d2..8aff4b0 100644 --- a/modules/ui/smartcolumn/config.nix +++ b/modules/ui/smartcolumn/config.nix @@ -4,9 +4,8 @@ ... }: let inherit (lib.modules) mkIf; - inherit (lib.strings) concatStringsSep; - inherit (lib.nvim.lua) attrsetToLuaTable; inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.ui.smartcolumn; in { @@ -15,13 +14,7 @@ in { startPlugins = ["smartcolumn"]; vim.luaConfigRC.smartcolumn = entryAnywhere '' - require("smartcolumn").setup({ - colorcolumn = "${toString cfg.showColumnAt}", - -- { "help", "text", "markdown", "NvimTree", "alpha"}, - disabled_filetypes = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.disabledFiletypes)} }, - custom_colorcolumn = ${attrsetToLuaTable cfg.columnAt.languages}, - scope = "file", - }) + require("smartcolumn").setup(${toLuaObject cfg.setupOpts}) ''; }; } diff --git a/modules/ui/smartcolumn/smartcolumn.nix b/modules/ui/smartcolumn/smartcolumn.nix index bac4c7d..37d7a94 100644 --- a/modules/ui/smartcolumn/smartcolumn.nix +++ b/modules/ui/smartcolumn/smartcolumn.nix @@ -1,31 +1,41 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) nullOr int str submodule attrsOf either listOf; + inherit (lib.types) nullOr int str attrsOf either listOf; + inherit (lib.modules) mkRenamedOptionModule; + inherit (lib.nvim.types) mkPluginSetupOption; in { + imports = let + renamedSetupOpt = oldPath: newPath: + mkRenamedOptionModule (["vim" "ui" "smartcolumn"] ++ oldPath) (["vim" "ui" "smartcolumn" "setupOpts"] ++ newPath); + in [ + (renamedSetupOpt ["disabledFiletypes"] ["disabled_filetypes"]) + (renamedSetupOpt ["showColumnAt"] ["colorcolumn"]) + (renamedSetupOpt ["columnAt" "languages"] ["custom_colorcolumn"]) + ]; + options.vim.ui.smartcolumn = { enable = mkEnableOption "line length indicator"; - showColumnAt = mkOption { - type = nullOr int; - default = 120; - description = "The position at which the column will be displayed. Set to null to disable"; - }; + setupOpts = mkPluginSetupOption "smartcolumn.nvim" { + colorcolumn = mkOption { + type = nullOr (either str (listOf str)); + default = "120"; + description = "The position at which the column will be displayed. Set to null to disable"; + }; - disabledFiletypes = mkOption { - type = listOf str; - default = ["help" "text" "markdown" "NvimTree" "alpha"]; - description = "The filetypes smartcolumn will be disabled for."; - }; + disabled_filetypes = mkOption { + type = listOf str; + default = ["help" "text" "markdown" "NvimTree" "alpha"]; + description = "The filetypes smartcolumn will be disabled for."; + }; - columnAt = { - languages = mkOption { + custom_colorcolumn = mkOption { description = "The position at which smart column should be displayed for each individual buffer type"; - type = submodule { - freeformType = attrsOf (either int (listOf int)); - }; + type = attrsOf (either int (listOf int)); + default = {}; example = literalExpression '' - vim.ui.smartcolumn.columnAt.languages = { + vim.ui.smartcolumn.setupOpts.custom_colorcolumn = { nix = 110; ruby = 120; java = 130;