From 5ea6272bee4a0e28ccf3835695da42143bcdb851 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sun, 10 Mar 2024 21:00:14 +0000 Subject: [PATCH] feat(smartcolumn): custom setup opts --- configuration.nix | 2 +- modules/ui/smartcolumn/config.nix | 11 ++----- modules/ui/smartcolumn/smartcolumn.nix | 44 ++++++++++++++++---------- 3 files changed, 30 insertions(+), 27 deletions(-) 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;