From 2cfeb2276438eb64121be689c3c5806e41f6f7a9 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 4 Jun 2023 14:12:08 +0300 Subject: [PATCH] feat: implement freeform smartcolumn column positions --- extra.nix | 10 +++++++- lib/lua.nix | 22 +++++++++++++++- modules/ui/smartcolumn/config.nix | 8 +----- modules/ui/smartcolumn/smartcolumn.nix | 35 +++++++++----------------- modules/utility/ccc/config.nix | 11 ++++---- 5 files changed, 48 insertions(+), 38 deletions(-) diff --git a/extra.nix b/extra.nix index a91ff9b..60d6cf9 100644 --- a/extra.nix +++ b/extra.nix @@ -178,7 +178,15 @@ inputs: let vim.ui = { noice.enable = true; - smartcolumn.enable = true; + smartcolumn = { + enable = true; + columnAt.languages = { + # this is a freeform module, it's `buftype = int;` for configuring column position + nix = 110; + ruby = 120; + java = 130; + }; + }; colorizer.enable = true; }; diff --git a/lib/lua.nix b/lib/lua.nix index b21c459..f665159 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -1,12 +1,32 @@ # Helpers for converting values to lua -{lib}: { +{lib}: rec { + # yes? no. yesNo = value: if value then "yes" else "no"; + # Convert a null value to lua's nil nullString = value: if value == null then "nil" else "'${value}'"; + + # Helper function to convert an attribute name to a Lua table key + attrToKey = name: name; + + # Function to convert a Nix attrset to a Lua table + attrsetToLuaTable = attrset: + "{ " + + ( + builtins.concatStringsSep ", " + (builtins.attrValues ( + builtins.mapAttrs ( + name: value: + attrToKey name + " = " + ("\"" + builtins.toJSON value + "\"") + ) + attrset + )) + ) + + " }"; } diff --git a/modules/ui/smartcolumn/config.nix b/modules/ui/smartcolumn/config.nix index 6d017db..afa9fc7 100644 --- a/modules/ui/smartcolumn/config.nix +++ b/modules/ui/smartcolumn/config.nix @@ -18,13 +18,7 @@ in { colorcolumn = "${toString cfg.showColumnAt}", -- { "help", "text", "markdown", "NvimTree", "alpha"}, disabled_filetypes = { ${concatStringsSep ", " (map (x: "\"" + x + "\"") cfg.disabledFiletypes)} }, - custom_colorcolumn = { - -- TODO: use cfg.languages..columnAt when it's fixed to dynamically define per-language length - ruby = "120", - java = "120", - nix = "120", - markdown = "80", - }, + custom_colorcolumn = ${nvim.lua.attrsetToLuaTable cfg.columnAt.languages}, scope = "file", }) ''; diff --git a/modules/ui/smartcolumn/smartcolumn.nix b/modules/ui/smartcolumn/smartcolumn.nix index cad0899..1b965a0 100644 --- a/modules/ui/smartcolumn/smartcolumn.nix +++ b/modules/ui/smartcolumn/smartcolumn.nix @@ -1,19 +1,8 @@ -{ - config, - lib, - ... -}: +{lib, ...}: with lib; -with builtins; let - languageOpts = { - columnAt = mkOption { - type = types.nullOr types.int; - default = 80; - }; - }; -in { +with builtins; { options.vim.ui.smartcolumn = { - enable = mkEnableOption "Enable smartcolumn line length indicator"; + enable = mkEnableOption "Enable Smartcolumn line length indicator"; showColumnAt = mkOption { type = types.nullOr types.int; @@ -27,15 +16,15 @@ in { description = "The filetypes smartcolumn will be disabled for."; }; - /* - languages = mkOption { - default = {}; - description = "Language specific configuration."; - type = with types; - attrsOf (submodule { - options = languageOpts; - }); + columnAt = { + # TODO: the current implementation only allows for options such as { ruby = "120", java = "120" } + # whereas the lua config would allow { ruby = "120", java = { "180", "200"} }, this needs to be fixed in the custom lib + languages = lib.mkOption { + description = "The position at which smart column should be displayed for each individual buffer type"; + type = lib.types.submodule { + freeformType = with lib.types; attrsOf int; + }; + }; }; - */ }; } diff --git a/modules/utility/ccc/config.nix b/modules/utility/ccc/config.nix index 4ec2f16..1b04618 100644 --- a/modules/utility/ccc/config.nix +++ b/modules/utility/ccc/config.nix @@ -16,12 +16,6 @@ in { "ccc" ]; - vim.maps.normal = mkMerge [ - (mkSetLuaBinding mappings.quit "require('ccc').mapping.quit") - (mkSetLuaBinding mappings.increase10 "require('ccc').mapping.increase10") - (mkSetLuaBinding mappings.decrease10 "require('ccc').mapping.decrease10") - ]; - vim.luaConfigRC.ccc = nvim.dag.entryAnywhere '' local ccc = require("ccc") ccc.setup { @@ -52,6 +46,11 @@ in { { ccc.picker.css_rgb, ccc.output.css_hsl }, { ccc.picker.css_hsl, ccc.output.hex }, }, + mappings = { + ["q"] = ccc.mapping.quit, + ["L"] = ccc.mapping.increase10, + ["H"] = ccc.mapping.decrease10, + }, } ''; };