diff --git a/lib/binds.nix b/lib/binds.nix new file mode 100644 index 00000000..2d22f6d8 --- /dev/null +++ b/lib/binds.nix @@ -0,0 +1,105 @@ +{lib}: let + inherit (lib.options) mkOption; + inherit (lib.modules) mkIf; + inherit (lib.types) nullOr str submodule bool; + inherit (lib.attrsets) isAttrs mapAttrs attrsOf; +in rec { + # mkLuaBinding creates a binding with Lua and silent flags. + # + # Arguments: + # - key: The name of the binding. + # - action: The action to be performed when the binding is activated. + # - desc: The description of the binding. + mkLuaBinding = key: action: desc: + mkIf (key != null) { + "${key}" = { + inherit action desc; + lua = true; + silent = true; + }; + }; + + # mkExprBinding creates a binding with Lua, silent, and expr flags. + # + # Arguments: + # - key: The name of the binding. + # - action: The action to be performed when the binding is activated. + # - desc: The description of the binding. + mkExprBinding = key: action: desc: + mkIf (key != null) { + "${key}" = { + inherit action desc; + lua = true; + silent = true; + expr = true; + }; + }; + + # mkBinding creates a binding with silent flag. + # + # Arguments: + # - key: The name of the binding. + # - action: The action to be performed when the binding is activated. + # - desc: The description of the binding. + mkBinding = key: action: desc: + mkIf (key != null) { + "${key}" = { + inherit action desc; + silent = true; + }; + }; + + # mkMappingOption creates an option that can be null or a string. + # + # Arguments: + # - description: The description of the option. + # - default: The default value of the option. + mkMappingOption = description: default: + mkOption { + type = nullOr str; + inherit default description; + }; + + # Utility function that takes two attrsets: + # { someKey = "some_value" } and + # { someKey = { description = "Some Description"; }; } + # and merges them into + # { someKey = { value = "some_value"; description = "Some Description"; }; } + addDescriptionsToMappings = actualMappings: mappingDefinitions: + mapAttrs (name: value: let + isNested = isAttrs value; + returnedValue = + if isNested + then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}" + else { + inherit value; + inherit (mappingDefinitions."${name}") description; + }; + in + returnedValue) + actualMappings; + + # mkSetBinding creates a binding with the provided action and description. + # + # Arguments: + # - binding: The binding to be set. + # - action: The action to be performed when the binding is activated. + mkSetBinding = binding: action: + mkBinding binding.value action binding.description; + + # mkSetExprBinding creates an expression binding with the provided action and description. + # + # Arguments: + # - binding: The binding to be set. + # - action: The action to be performed when the binding is activated. + mkSetExprBinding = binding: action: + mkExprBinding binding.value action binding.description; + + # mkSetLuaBinding creates a Lua binding with the provided action and description. + # + # Arguments: + # - binding: The binding to be set. + # - action: The action to be performed when the binding is activated. + mkSetLuaBinding = binding: action: + mkLuaBinding binding.value action binding.description; +} diff --git a/lib/default.nix b/lib/default.nix index fc5aca13..61a529f1 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,8 +1,10 @@ {lib}: { - modules = import ./modules.nix {inherit lib;}; - dag = import ./dag.nix {inherit lib;}; types = import ./types {inherit lib;}; + + binds = import ./binds.nix {inherit lib;}; + dag = import ./dag.nix {inherit lib;}; languages = import ./languages.nix {inherit lib;}; lua = import ./lua.nix {inherit lib;}; + modules = import ./modules.nix {inherit lib;}; vim = import ./vim.nix {inherit lib;}; } diff --git a/lib/stdlib-extended.nix b/lib/stdlib-extended.nix index 98332487..364b5d19 100644 --- a/lib/stdlib-extended.nix +++ b/lib/stdlib-extended.nix @@ -4,70 +4,9 @@ nixpkgsLib: let mkNvimLib = import ./.; in - nixpkgsLib.extend (self: super: rec { + nixpkgsLib.extend (self: super: { nvim = mkNvimLib {lib = self;}; - mkLuaBinding = key: action: desc: - self.mkIf (key != null) { - "${key}" = { - inherit action desc; - lua = true; - silent = true; - }; - }; - - mkExprBinding = key: action: desc: - self.mkIf (key != null) { - "${key}" = { - inherit action desc; - lua = true; - silent = true; - expr = true; - }; - }; - - mkBinding = key: action: desc: - self.mkIf (key != null) { - "${key}" = { - inherit action desc; - silent = true; - }; - }; - - mkMappingOption = description: default: - self.mkOption { - type = self.types.nullOr self.types.str; - inherit default description; - }; - - # Utility function that takes two attrsets: - # { someKey = "some_value" } and - # { someKey = { description = "Some Description"; }; } - # and merges them into - # { someKey = { value = "some_value"; description = "Some Description"; }; } - addDescriptionsToMappings = actualMappings: mappingDefinitions: - self.attrsets.mapAttrs (name: value: let - isNested = self.isAttrs value; - returnedValue = - if isNested - then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}" - else { - value = value; - description = mappingDefinitions."${name}".description; - }; - in - returnedValue) - actualMappings; - - mkSetBinding = binding: action: - mkBinding binding.value action binding.description; - - mkSetExprBinding = binding: action: - mkExprBinding binding.value action binding.description; - - mkSetLuaBinding = binding: action: - mkLuaBinding binding.value action binding.description; - # For forward compatibility. literalExpression = super.literalExpression or super.literalExample; }) diff --git a/modules/modules.nix b/modules/modules.nix index f69ba829..d9e66115 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -39,13 +39,12 @@ core = map (p: ./core + "/${p}") [ "build" - "mappings" "warnings" ]; neovim = map (p: ./neovim + "/${p}") [ "basic" - "maps" + "mappings" "spellcheck" ]; diff --git a/modules/neovim/maps/default.nix b/modules/neovim/mappings/default.nix similarity index 100% rename from modules/neovim/maps/default.nix rename to modules/neovim/mappings/default.nix diff --git a/modules/core/mappings/default.nix b/modules/neovim/mappings/options.nix similarity index 90% rename from modules/core/mappings/default.nix rename to modules/neovim/mappings/options.nix index dfc0ddac..6488d294 100644 --- a/modules/core/mappings/default.nix +++ b/modules/neovim/mappings/options.nix @@ -1,7 +1,7 @@ {lib, ...}: let - inherit (lib) mkOption types; - inherit (lib) nvim; - inherit (nvim.modules) mkBoolOption; + inherit (lib.types) submodule str bool attrsOf nullOr; + inherit (lib.options) mkOption; + inherit (lib.nvim.modules) mkBoolOption; # Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you! mapConfigOptions = { @@ -30,23 +30,23 @@ "Whether to use the 'noremap' variant of the command, ignoring any custom mappings on the defined action. It is highly advised to keep this on, which is the default."; desc = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = null; description = "A description of this keybind, to be shown in which-key, if you have it enabled."; }; }; - mapOption = types.submodule { + mapOption = submodule { options = mapConfigOptions // { action = mkOption { - type = types.str; + type = str; description = "The action to execute."; }; lua = mkOption { - type = types.bool; + type = bool; description = '' If true, `action` is considered to be lua code. Thus, it will not be wrapped in `""`. @@ -59,14 +59,14 @@ mapOptions = mode: mkOption { description = "Mappings for ${mode} mode"; - type = types.attrsOf mapOption; + type = attrsOf mapOption; default = {}; }; in { options = { vim = { maps = mkOption { - type = types.submodule { + type = submodule { options = { normal = mapOptions "normal"; insert = mapOptions "insert"; diff --git a/modules/plugins/assistant/copilot/config.nix b/modules/plugins/assistant/copilot/config.nix index 18f540dd..2b0ca43a 100644 --- a/modules/plugins/assistant/copilot/config.nix +++ b/modules/plugins/assistant/copilot/config.nix @@ -1,11 +1,15 @@ { - pkgs, config, lib, ... }: let inherit (builtins) toJSON; - inherit (lib) mkIf nvim mkLuaBinding mkMerge; + inherit (lib.trivial) boolToString toString; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.strings) optionalString; + inherit (lib.lists) optionals; + inherit (lib.nvim.binds) mkLuaBinding; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.assistant.copilot; @@ -22,69 +26,73 @@ ''; in { config = mkIf cfg.enable { - vim.startPlugins = - [ - "copilot-lua" - cfg.copilotNodePackage - ] - ++ lib.optionals (cfg.cmp.enable) [ - "copilot-cmp" - ]; + vim = { + startPlugins = + [ + "copilot-lua" + cfg.copilotNodePackage + ] + ++ optionals cfg.cmp.enable [ + "copilot-cmp" + ]; - vim.luaConfigRC.copilot = nvim.dag.entryAnywhere '' - require("copilot").setup({ - -- available options: https://github.com/zbirenbaum/copilot.lua - copilot_node_command = "${cfg.copilotNodeCommand}", - panel = { - enabled = ${lib.boolToString (!cfg.cmp.enable)}, - keymap = { - jump_prev = false, - jump_next = false, - accept = false, - refresh = false, - open = false, + luaConfigRC.copilot = entryAnywhere '' + require("copilot").setup({ + -- available options: https://github.com/zbirenbaum/copilot.lua + copilot_node_command = "${cfg.copilotNodeCommand}", + panel = { + enabled = ${boolToString (!cfg.cmp.enable)}, + keymap = { + jump_prev = false, + jump_next = false, + accept = false, + refresh = false, + open = false, + }, + layout = { + position = "${cfg.panel.position}", + ratio = ${toString cfg.panel.ratio}, + }, }, - layout = { - position = "${cfg.panel.position}", - ratio = ${toString cfg.panel.ratio}, + suggestion = { + enabled = ${boolToString (!cfg.cmp.enable)}, + keymap = { + accept = false, + accept_word = false, + accept_line = false, + next = false, + prev = false, + dismiss = false, + }, }, - }, - suggestion = { - enabled = ${lib.boolToString (!cfg.cmp.enable)}, - keymap = { - accept = false, - accept_word = false, - accept_line = false, - next = false, - prev = false, - dismiss = false, - }, - }, - }) + }) - ${lib.optionalString (cfg.cmp.enable) '' - require("copilot_cmp").setup() - ''} - ''; + ${optionalString cfg.cmp.enable '' + require("copilot_cmp").setup() + ''} + ''; - vim.maps.normal = mkMerge [ - (mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding '' - function() require("copilot.panel").open({ position = "${cfg.panel.position}", ratio = ${toString cfg.panel.ratio}, }) end - '' - cfg.mappings.panel.open) "[copilot] Accept suggestion") - ]; + maps = { + normal = mkMerge [ + (mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion") + (mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion") + (mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion") + (mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion") + (mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding '' + function() require("copilot.panel").open({ position = "${cfg.panel.position}", ratio = ${toString cfg.panel.ratio}, }) end + '' + cfg.mappings.panel.open) "[copilot] Accept suggestion") + ]; - vim.maps.insert = mkMerge [ - (mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion") - (mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)") - (mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)") - (mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion") - (mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion") - (mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion") - ]; + insert = mkMerge [ + (mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion") + (mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)") + (mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)") + (mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion") + (mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion") + (mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion") + ]; + }; + }; }; } diff --git a/modules/plugins/assistant/copilot/copilot.nix b/modules/plugins/assistant/copilot/copilot.nix index 85838694..c1459564 100644 --- a/modules/plugins/assistant/copilot/copilot.nix +++ b/modules/plugins/assistant/copilot/copilot.nix @@ -4,7 +4,9 @@ lib, ... }: let - inherit (lib) mkEnableOption mkOption types; + inherit (lib.types) enum float nullOr package str; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.meta) getExe; cfg = config.vim.assistant.copilot; in { @@ -14,7 +16,7 @@ in { panel = { position = mkOption { - type = types.enum [ + type = enum [ "bottom" "top" "left" @@ -24,7 +26,7 @@ in { description = "Panel position"; }; ratio = mkOption { - type = types.float; + type = float; default = 0.4; description = "Panel size"; }; @@ -33,81 +35,81 @@ in { mappings = { panel = { jumpPrev = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = "[["; description = "Jump to previous suggestion"; }; jumpNext = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = "]]"; description = "Jump to next suggestion"; }; accept = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Accept suggestion"; }; refresh = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = "gr"; description = "Refresh suggestions"; }; open = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Open suggestions"; }; }; suggestion = { accept = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Accept suggetion"; }; acceptWord = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = null; description = "Accept next word"; }; acceptLine = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = null; description = "Accept next line"; }; prev = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Previous suggestion"; }; next = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Next suggestion"; }; dismiss = mkOption { - type = types.nullOr types.str; + type = nullOr str; default = ""; description = "Dismiss suggestion"; }; }; }; - copilotNodeCommand = mkOption { - type = types.str; - default = "${lib.getExe cfg.copilotNodePackage}"; - description = '' - The command that will be executed to initiate nodejs for GitHub Copilot. - Recommended to leave as default. - ''; - }; - copilotNodePackage = mkOption { - type = with types; nullOr package; + type = nullOr package; default = pkgs.nodejs-slim; description = '' The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command you may want to set this option to null so that the package is not pulled from nixpkgs. ''; }; + + copilotNodeCommand = mkOption { + type = str; + default = "${getExe cfg.copilotNodePackage}"; + description = '' + The command that will be executed to initiate nodejs for GitHub Copilot. + Recommended to leave as default. + ''; + }; }; } diff --git a/modules/plugins/assistant/default.nix b/modules/plugins/assistant/default.nix index a8096c8a..3521c526 100644 --- a/modules/plugins/assistant/default.nix +++ b/modules/plugins/assistant/default.nix @@ -1,6 +1,5 @@ -_: { +{ imports = [ ./copilot - # ./tabnine.nix # removed until I find a way around the initialisation script the plugin requires ]; } diff --git a/modules/plugins/assistant/tabnine/config.nix b/modules/plugins/assistant/tabnine/config.nix deleted file mode 100644 index e9cc209e..00000000 --- a/modules/plugins/assistant/tabnine/config.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ - config, - lib, - ... -}: let - inherit (builtins) toJSON; - inherit (lib) mkIf mkMerge mkExprBinding boolToString nvim; - - cfg = config.vim.assistant.tabnine; -in { - config = mkIf cfg.enable { - vim.startPlugins = ["tabnine-nvim"]; - - vim.maps.insert = mkMerge [ - (mkExprBinding cfg.mappings.accept '' - function() - local state = require("tabnine.state") - local completion = require("tabnine.completion") - - if not state.completions_cache then - return "${toJSON cfg.mappings.accept}" - end - - vim.schedule(completion.accept) - end - '' "orzel") - (mkExprBinding cfg.mappings.dismiss '' - function() - local state = require("tabnine.state") - local completion = require("tabnine.completion") - - if not state.completions_cache then - return "${toJSON cfg.mappings.dismiss}" - end - - vim.schedule(function() - completion.clear() - state.completions_cache = nil - end) - end - '' "orzel") - ]; - - vim.luaConfigRC.tabnine-nvim = nvim.dag.entryAnywhere '' - require('tabnine').setup({ - disable_auto_comment = ${boolToString cfg.disable_auto_comment}, - accept_keymap = null, - dismiss_keymap = null, - debounce_ms = ${cfg.debounce_ms}, - exclude_filetypes = ${cfg.exclude_filetypes}, - }) - ''; - }; -} diff --git a/modules/plugins/assistant/tabnine/default.nix b/modules/plugins/assistant/tabnine/default.nix deleted file mode 100644 index 84f3cf2f..00000000 --- a/modules/plugins/assistant/tabnine/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -_: { - imports = [ - ./config.nix - ./tabnine.nix - ]; -} diff --git a/modules/plugins/assistant/tabnine/tabnine.nix b/modules/plugins/assistant/tabnine/tabnine.nix deleted file mode 100644 index 949a6b17..00000000 --- a/modules/plugins/assistant/tabnine/tabnine.nix +++ /dev/null @@ -1,30 +0,0 @@ -{lib, ...}: let - inherit (lib) mkEnableOption mkOption types mkMappingOption; -in { - options.vim.assistant.tabnine = { - enable = mkEnableOption "Tabnine assistant"; - - disable_auto_comment = mkOption { - type = types.bool; - default = true; - description = "Disable auto comment"; - }; - - mappings = { - accept = mkMappingOption "Accept [Tabnine]" ""; - dismiss = mkMappingOption "Dismiss [Tabnine]" ""; - }; - - debounce_ms = mkOption { - type = types.int; - default = 800; - description = "Debounce ms"; - }; - - exclude_filetypes = mkOption { - type = types.listOf types.str; - default = ["TelescopePrompt" "NvimTree" "alpha"]; - description = "Exclude filetypes"; - }; - }; -} diff --git a/modules/plugins/autopairs/default.nix b/modules/plugins/autopairs/default.nix index 742665c7..cc2f69c6 100644 --- a/modules/plugins/autopairs/default.nix +++ b/modules/plugins/autopairs/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-autopairs ]; diff --git a/modules/plugins/autopairs/nvim-autopairs/config.nix b/modules/plugins/autopairs/nvim-autopairs/config.nix index 0aceca5d..b45db98c 100644 --- a/modules/plugins/autopairs/nvim-autopairs/config.nix +++ b/modules/plugins/autopairs/nvim-autopairs/config.nix @@ -1,18 +1,20 @@ { - lib, config, + lib, ... }: let - inherit (lib) mkIf nvim optionalString boolToString; + inherit (lib.strings) optionalString; + inherit (lib.trivial) boolToString; + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.autopairs; in { - config = - mkIf (cfg.enable) - { - vim.startPlugins = ["nvim-autopairs"]; + config = mkIf cfg.enable { + vim = { + startPlugins = ["nvim-autopairs"]; - vim.luaConfigRC.autopairs = nvim.dag.entryAnywhere '' + luaConfigRC.autopairs = entryAnywhere '' require("nvim-autopairs").setup{} ${optionalString (config.vim.autocomplete.type == "nvim-compe") '' require('nvim-autopairs.completion.compe').setup({ @@ -23,4 +25,5 @@ in { ''} ''; }; + }; } diff --git a/modules/plugins/autopairs/nvim-autopairs/default.nix b/modules/plugins/autopairs/nvim-autopairs/default.nix index f2283310..70980494 100644 --- a/modules/plugins/autopairs/nvim-autopairs/default.nix +++ b/modules/plugins/autopairs/nvim-autopairs/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./nvim-autopairs.nix diff --git a/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix b/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix index 330d1186..8dbdce67 100644 --- a/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix +++ b/modules/plugins/autopairs/nvim-autopairs/nvim-autopairs.nix @@ -1,31 +1,37 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkOption types; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.tyoes) enum bool; in { options.vim = { autopairs = { - enable = mkEnableOption "autopairs" // {default = false;}; + enable = mkEnableOption "autopairs"; type = mkOption { - type = types.enum ["nvim-autopairs"]; + type = enum ["nvim-autopairs"]; default = "nvim-autopairs"; - description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]"; + description = '' + Set the autopairs type. + + Options: + - nvim-autopairs [nvim-autopairs] + ''; }; nvim-compe = { map_cr = mkOption { - type = types.bool; + type = bool; default = true; description = ''map on insert mode''; }; map_complete = mkOption { - type = types.bool; + type = bool; default = true; description = "auto insert `(` after select function or method item"; }; auto_select = mkOption { - type = types.bool; + type = bool; default = false; description = "auto select first item"; }; diff --git a/modules/plugins/comments/comment-nvim/comment-nvim.nix b/modules/plugins/comments/comment-nvim/comment-nvim.nix index 13ca4753..f1fed468 100644 --- a/modules/plugins/comments/comment-nvim/comment-nvim.nix +++ b/modules/plugins/comments/comment-nvim/comment-nvim.nix @@ -1,8 +1,9 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption; + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.binds) mkMappingOption; in { options.vim.comments.comment-nvim = { - enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim"; + enable = mkEnableOption "smart and powerful comment plugin for neovim [comment-nvim]"; mappings = { toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc"; diff --git a/modules/plugins/comments/default.nix b/modules/plugins/comments/default.nix index cb6ac191..afc1a879 100644 --- a/modules/plugins/comments/default.nix +++ b/modules/plugins/comments/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./comment-nvim ]; diff --git a/modules/plugins/completion/default.nix b/modules/plugins/completion/default.nix index 77d51b41..0cae45f6 100644 --- a/modules/plugins/completion/default.nix +++ b/modules/plugins/completion/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./nvim-cmp ]; diff --git a/modules/plugins/completion/nvim-cmp/config.nix b/modules/plugins/completion/nvim-cmp/config.nix index b20f71b7..7da666e5 100644 --- a/modules/plugins/completion/nvim-cmp/config.nix +++ b/modules/plugins/completion/nvim-cmp/config.nix @@ -4,8 +4,11 @@ ... }: let inherit (builtins) toJSON; - inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList mkIf mkSetLuaBinding mkMerge optionalString; - inherit (lib.nvim) dag; + inherit (lib.binds) addDescriptionsToMappings mkSetLuaBinding; + inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString; + inherit (lib.attrsets) attrNames mapAttrsToList; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.dag) entryAfter entryAnywhere; cfg = config.vim.autocomplete; lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable; @@ -33,209 +36,213 @@ dagPlacement = if lspkindEnabled - then dag.entryAfter ["lspkind"] - else dag.entryAnywhere; + then entryAfter ["lspkind"] + else entryAnywhere; in { config = mkIf cfg.enable { - vim.startPlugins = [ - "nvim-cmp" - "cmp-buffer" - "cmp-vsnip" - "cmp-path" - "vim-vsnip" - ]; + vim = { + startPlugins = [ + "nvim-cmp" + "cmp-buffer" + "cmp-vsnip" + "cmp-path" + "vim-vsnip" + ]; - vim.autocomplete.sources = { - "nvim-cmp" = null; - "vsnip" = "[VSnip]"; - "buffer" = "[Buffer]"; - "crates" = "[Crates]"; - "path" = "[Path]"; - "copilot" = "[Copilot]"; + autocomplete.sources = { + "nvim-cmp" = null; + "vsnip" = "[VSnip]"; + "buffer" = "[Buffer]"; + "crates" = "[Crates]"; + "path" = "[Path]"; + "copilot" = "[Copilot]"; + }; + + maps = { + insert = mkMerge [ + (mkSetLuaBinding mappings.complete '' + require('cmp').complete + '') + (mkSetLuaBinding mappings.confirm '' + function() + if not require('cmp').confirm({ select = true }) then + local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true) + + vim.fn.feedkeys(termcode, 'n') + end + end + '') + (mkSetLuaBinding mappings.next '' + function() + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local cmp = require('cmp') + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn['vsnip#available'](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true) + + vim.fn.feedkeys(termcode, 'n') + end + end + '') + (mkSetLuaBinding mappings.previous '' + function() + local cmp = require('cmp') + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn['vsnip#available'](-1) == 1 then + feedkeys("(vsnip-jump-prev)", "") + end + end + '') + (mkSetLuaBinding mappings.close '' + require('cmp').mapping.abort() + '') + (mkSetLuaBinding mappings.scrollDocsUp '' + require('cmp').mapping.scroll_docs(-4) + '') + (mkSetLuaBinding mappings.scrollDocsDown '' + require('cmp').mapping.scroll_docs(4) + '') + ]; + + command = mkMerge [ + (mkSetLuaBinding mappings.complete '' + require('cmp').complete + '') + (mkSetLuaBinding mappings.close '' + require('cmp').mapping.close() + '') + (mkSetLuaBinding mappings.scrollDocsUp '' + require('cmp').mapping.scroll_docs(-4) + '') + (mkSetLuaBinding mappings.scrollDocsDown '' + require('cmp').mapping.scroll_docs(4) + '') + ]; + + select = mkMerge [ + (mkSetLuaBinding mappings.next '' + function() + local cmp = require('cmp') + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn['vsnip#available'](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true) + + vim.fn.feedkeys(termcode, 'n') + end + end + '') + (mkSetLuaBinding mappings.previous '' + function() + local cmp = require('cmp') + + local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) + end + + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn['vsnip#available'](-1) == 1 then + feedkeys("(vsnip-jump-prev)", "") + end + end + '') + ]; + }; + + # TODO: alternative snippet engines to vsnip + # https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82 + luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement '' + local nvim_cmp_menu_map = function(entry, vim_item) + -- name for each source + vim_item.menu = ({ + ${builtMaps} + })[entry.source.name] + print(vim_item.menu) + return vim_item + end + + ${optionalString lspkindEnabled '' + lspkind_opts.before = ${cfg.formatting.format} + ''} + + local cmp = require'cmp' + cmp.setup({ + ${optionalString config.vim.ui.borders.enable '' + -- explicitly enabled by setting ui.borders.enable = true + -- TODO: try to get nvim-cmp to follow global border style + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + ''} + + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + + sources = { + ${builtSources} + }, + + completion = { + completeopt = 'menu,menuone,noinsert', + }, + + formatting = { + format = + ${ + if lspkindEnabled + then "lspkind.cmp_format(lspkind_opts)" + else cfg.formatting.format + }, + } + }) + ${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") '' + local cmp_autopairs = require('nvim-autopairs.completion.cmp') + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} })) + ''} + ''); + + snippets.vsnip.enable = + if (cfg.type == "nvim-cmp") + then true + else config.vim.snippets.vsnip.enable; }; - - vim.maps.insert = mkMerge [ - (mkSetLuaBinding mappings.complete '' - require('cmp').complete - '') - (mkSetLuaBinding mappings.confirm '' - function() - if not require('cmp').confirm({ select = true }) then - local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true) - - vim.fn.feedkeys(termcode, 'n') - end - end - '') - (mkSetLuaBinding mappings.next '' - function() - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - local cmp = require('cmp') - - local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - end - - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn['vsnip#available'](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() - else - local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true) - - vim.fn.feedkeys(termcode, 'n') - end - end - '') - (mkSetLuaBinding mappings.previous '' - function() - local cmp = require('cmp') - - local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - end - - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn['vsnip#available'](-1) == 1 then - feedkeys("(vsnip-jump-prev)", "") - end - end - '') - (mkSetLuaBinding mappings.close '' - require('cmp').mapping.abort() - '') - (mkSetLuaBinding mappings.scrollDocsUp '' - require('cmp').mapping.scroll_docs(-4) - '') - (mkSetLuaBinding mappings.scrollDocsDown '' - require('cmp').mapping.scroll_docs(4) - '') - ]; - - vim.maps.command = mkMerge [ - (mkSetLuaBinding mappings.complete '' - require('cmp').complete - '') - (mkSetLuaBinding mappings.close '' - require('cmp').mapping.close() - '') - (mkSetLuaBinding mappings.scrollDocsUp '' - require('cmp').mapping.scroll_docs(-4) - '') - (mkSetLuaBinding mappings.scrollDocsDown '' - require('cmp').mapping.scroll_docs(4) - '') - ]; - - vim.maps.select = mkMerge [ - (mkSetLuaBinding mappings.next '' - function() - local cmp = require('cmp') - local has_words_before = function() - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - end - - if cmp.visible() then - cmp.select_next_item() - elseif vim.fn['vsnip#available'](1) == 1 then - feedkey("(vsnip-expand-or-jump)", "") - elseif has_words_before() then - cmp.complete() - else - local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true) - - vim.fn.feedkeys(termcode, 'n') - end - end - '') - (mkSetLuaBinding mappings.previous '' - function() - local cmp = require('cmp') - - local feedkey = function(key, mode) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) - end - - if cmp.visible() then - cmp.select_prev_item() - elseif vim.fn['vsnip#available'](-1) == 1 then - feedkeys("(vsnip-jump-prev)", "") - end - end - '') - ]; - - # TODO: alternative snippet engines to vsnip - # https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82 - vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement '' - local nvim_cmp_menu_map = function(entry, vim_item) - -- name for each source - vim_item.menu = ({ - ${builtMaps} - })[entry.source.name] - print(vim_item.menu) - return vim_item - end - - ${optionalString lspkindEnabled '' - lspkind_opts.before = ${cfg.formatting.format} - ''} - - local cmp = require'cmp' - cmp.setup({ - ${optionalString (config.vim.ui.borders.enable) '' - -- explicitly enabled by setting ui.borders.enable = true - -- TODO: try to get nvim-cmp to follow global border style - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - ''} - - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - - sources = { - ${builtSources} - }, - - completion = { - completeopt = 'menu,menuone,noinsert', - }, - - formatting = { - format = - ${ - if lspkindEnabled - then "lspkind.cmp_format(lspkind_opts)" - else cfg.formatting.format - }, - } - }) - ${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") '' - local cmp_autopairs = require('nvim-autopairs.completion.cmp') - cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} })) - ''} - ''); - - vim.snippets.vsnip.enable = - if (cfg.type == "nvim-cmp") - then true - else config.vim.snippets.vsnip.enable; }; } diff --git a/modules/plugins/completion/nvim-cmp/default.nix b/modules/plugins/completion/nvim-cmp/default.nix index 603347f4..65578c38 100644 --- a/modules/plugins/completion/nvim-cmp/default.nix +++ b/modules/plugins/completion/nvim-cmp/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./config.nix ./nvim-cmp.nix diff --git a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix index 38c86198..d71a06a3 100644 --- a/modules/plugins/completion/nvim-cmp/nvim-cmp.nix +++ b/modules/plugins/completion/nvim-cmp/nvim-cmp.nix @@ -1,9 +1,10 @@ {lib, ...}: let - inherit (lib) mkEnableOption mkMappingOption mkOption types; + inherit (lib.types) enum nullOr attrsOf str; + inherit (lib) mkEnableOption mkMappingOption mkOption; in { options.vim = { autocomplete = { - enable = mkEnableOption "enable autocomplete" // {default = false;}; + enable = mkEnableOption "enable autocomplete"; mappings = { complete = mkMappingOption "Complete [nvim-cmp]" ""; @@ -16,9 +17,14 @@ in { }; type = mkOption { - type = types.enum ["nvim-cmp"]; + type = enum ["nvim-cmp"]; default = "nvim-cmp"; - description = "Set the autocomplete plugin. Options: [nvim-cmp]"; + description = '' + Set the autocomplete plugin. + + Options: + - [nvim-cmp] + ''; }; sources = mkOption { @@ -31,7 +37,7 @@ in { Note: only use a single attribute name per attribute set ''; - type = with types; attrsOf (nullOr str); + type = attrsOf (nullOr str); default = {}; example = '' {nvim-cmp = null; buffer = "[Buffer]";} @@ -48,9 +54,9 @@ in { Default is to call the menu mapping function. ''; - type = types.str; + type = str; default = "nvim_cmp_menu_map"; - example = lib.literalMD '' + example = '' ```lua function(entry, vim_item) return vim_item diff --git a/modules/plugins/dashboard/alpha/alpha.nix b/modules/plugins/dashboard/alpha/alpha.nix index 3c43e15f..bdc9f67e 100644 --- a/modules/plugins/dashboard/alpha/alpha.nix +++ b/modules/plugins/dashboard/alpha/alpha.nix @@ -1,11 +1,7 @@ -{ - config, - lib, - ... -}: let - inherit (lib) mkEnableOption; +{lib, ...}: let + inherit (lib.options) mkEnableOption; in { options.vim.dashboard.alpha = { - enable = mkEnableOption "dashboard via alpha.nvim"; + enable = mkEnableOption "dashboard [alpha-nvim]"; }; } diff --git a/modules/plugins/dashboard/alpha/config.nix b/modules/plugins/dashboard/alpha/config.nix index a2ee14b4..36896650 100644 --- a/modules/plugins/dashboard/alpha/config.nix +++ b/modules/plugins/dashboard/alpha/config.nix @@ -3,217 +3,220 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.options) mkIf; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.dashboard.alpha; in { config = mkIf cfg.enable { - vim.startPlugins = [ - "alpha-nvim" - "nvim-web-devicons" - ]; + vim = { + startPlugins = [ + "alpha-nvim" + "nvim-web-devicons" + ]; - # the entire credit for this dashboard configuration to https://github.com/Rishabh672003 - # honestly, excellent work - vim.luaConfigRC.alpha = nvim.dag.entryAnywhere '' - local alpha = require("alpha") - local plenary_path = require("plenary.path") - local dashboard = require("alpha.themes.dashboard") - local cdir = vim.fn.getcwd() - local if_nil = vim.F.if_nil + # the entire credit for this dashboard configuration to https://github.com/Rishabh672003 + # honestly, excellent work + luaConfigRC.alpha = entryAnywhere '' + local alpha = require("alpha") + local plenary_path = require("plenary.path") + local dashboard = require("alpha.themes.dashboard") + local cdir = vim.fn.getcwd() + local if_nil = vim.F.if_nil - local nvim_web_devicons = { - enabled = true, - highlight = true, - } + local nvim_web_devicons = { + enabled = true, + highlight = true, + } - local function get_extension(fn) - local match = fn:match("^.+(%..+)$") - local ext = "" - if match ~= nil then - ext = match:sub(2) - end - return ext - end + local function get_extension(fn) + local match = fn:match("^.+(%..+)$") + local ext = "" + if match ~= nil then + ext = match:sub(2) + end + return ext + end - local function icon(fn) - local nwd = require("nvim-web-devicons") - local ext = get_extension(fn) - return nwd.get_icon(fn, ext, { default = true }) - end + local function icon(fn) + local nwd = require("nvim-web-devicons") + local ext = get_extension(fn) + return nwd.get_icon(fn, ext, { default = true }) + end - local function file_button(fn, sc, short_fn) - short_fn = short_fn or fn - local ico_txt - local fb_hl = {} + local function file_button(fn, sc, short_fn) + short_fn = short_fn or fn + local ico_txt + local fb_hl = {} - if nvim_web_devicons.enabled then - local ico, hl = icon(fn) - local hl_option_type = type(nvim_web_devicons.highlight) - if hl_option_type == "boolean" then - if hl and nvim_web_devicons.highlight then - table.insert(fb_hl, { hl, 0, 3 }) - end - end - if hl_option_type == "string" then - table.insert(fb_hl, { nvim_web_devicons.highlight, 0, 3 }) - end - ico_txt = ico .. " " - else - ico_txt = "" - end - local file_button_el = dashboard.button(sc, ico_txt .. short_fn, "e " .. fn .. " ") - local fn_start = short_fn:match(".*[/\\]") - if fn_start ~= nil then - table.insert(fb_hl, { "Comment", #ico_txt - 2, #fn_start + #ico_txt }) - end - file_button_el.opts.hl = fb_hl - return file_button_el - end + if nvim_web_devicons.enabled then + local ico, hl = icon(fn) + local hl_option_type = type(nvim_web_devicons.highlight) + if hl_option_type == "boolean" then + if hl and nvim_web_devicons.highlight then + table.insert(fb_hl, { hl, 0, 3 }) + end + end + if hl_option_type == "string" then + table.insert(fb_hl, { nvim_web_devicons.highlight, 0, 3 }) + end + ico_txt = ico .. " " + else + ico_txt = "" + end + local file_button_el = dashboard.button(sc, ico_txt .. short_fn, "e " .. fn .. " ") + local fn_start = short_fn:match(".*[/\\]") + if fn_start ~= nil then + table.insert(fb_hl, { "Comment", #ico_txt - 2, #fn_start + #ico_txt }) + end + file_button_el.opts.hl = fb_hl + return file_button_el + end - local default_mru_ignore = { "gitcommit" } + local default_mru_ignore = { "gitcommit" } - local mru_opts = { - ignore = function(path, ext) - return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext)) - end, - } + local mru_opts = { + ignore = function(path, ext) + return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext)) + end, + } - --- @param start number - --- @param cwd string optional - --- @param items_number number optional number of items to generate, default = 10 - local function mru(start, cwd, items_number, opts) - opts = opts or mru_opts - items_number = if_nil(items_number, 15) + --- @param start number + --- @param cwd string optional + --- @param items_number number optional number of items to generate, default = 10 + local function mru(start, cwd, items_number, opts) + opts = opts or mru_opts + items_number = if_nil(items_number, 15) - local oldfiles = {} - for _, v in pairs(vim.v.oldfiles) do - if #oldfiles == items_number then - break - end - local cwd_cond - if not cwd then - cwd_cond = true - else - cwd_cond = vim.startswith(v, cwd) - end - local ignore = (opts.ignore and opts.ignore(v, get_extension(v))) or false - if (vim.fn.filereadable(v) == 1) and cwd_cond and not ignore then - oldfiles[#oldfiles + 1] = v - end - end - local target_width = 35 + local oldfiles = {} + for _, v in pairs(vim.v.oldfiles) do + if #oldfiles == items_number then + break + end + local cwd_cond + if not cwd then + cwd_cond = true + else + cwd_cond = vim.startswith(v, cwd) + end + local ignore = (opts.ignore and opts.ignore(v, get_extension(v))) or false + if (vim.fn.filereadable(v) == 1) and cwd_cond and not ignore then + oldfiles[#oldfiles + 1] = v + end + end + local target_width = 35 - local tbl = {} - for i, fn in ipairs(oldfiles) do - local short_fn - if cwd then - short_fn = vim.fn.fnamemodify(fn, ":.") - else - short_fn = vim.fn.fnamemodify(fn, ":~") - end + local tbl = {} + for i, fn in ipairs(oldfiles) do + local short_fn + if cwd then + short_fn = vim.fn.fnamemodify(fn, ":.") + else + short_fn = vim.fn.fnamemodify(fn, ":~") + end - if #short_fn > target_width then - short_fn = plenary_path.new(short_fn):shorten(1, { -2, -1 }) - if #short_fn > target_width then - short_fn = plenary_path.new(short_fn):shorten(1, { -1 }) - end - end + if #short_fn > target_width then + short_fn = plenary_path.new(short_fn):shorten(1, { -2, -1 }) + if #short_fn > target_width then + short_fn = plenary_path.new(short_fn):shorten(1, { -1 }) + end + end - local shortcut = tostring(i + start - 1) + local shortcut = tostring(i + start - 1) - local file_button_el = file_button(fn, shortcut, short_fn) - tbl[i] = file_button_el - end - return { - type = "group", - val = tbl, - opts = {}, - } - end + local file_button_el = file_button(fn, shortcut, short_fn) + tbl[i] = file_button_el + end + return { + type = "group", + val = tbl, + opts = {}, + } + end - local default_header = { - type = "text", - val = { + local default_header = { + type = "text", + val = { - [[███ ██ ███████ ██████ ██ ██ ██ ███ ███]], - [[████ ██ ██ ██ ██ ██ ██ ██ ████ ████]], - [[██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████ ██]], - [[██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██]], - [[██ ████ ███████ ██████ ████ ██ ██ ██]], + [[███ ██ ███████ ██████ ██ ██ ██ ███ ███]], + [[████ ██ ██ ██ ██ ██ ██ ██ ████ ████]], + [[██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████ ██]], + [[██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██]], + [[██ ████ ███████ ██████ ████ ██ ██ ██]], - -- [[ __ ]], - -- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]], - -- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], - -- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], - -- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], - -- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], - }, - opts = { - position = "center", - hl = "Type", - -- wrap = "overflow"; - }, - } + -- [[ __ ]], + -- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]], + -- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], + -- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], + -- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], + -- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], + }, + opts = { + position = "center", + hl = "Type", + -- wrap = "overflow"; + }, + } - local section_mru = { - type = "group", - val = { - { - type = "text", - val = "Recent files", - opts = { - hl = "SpecialComment", - shrink_margin = false, - position = "center", - }, - }, - { type = "padding", val = 1 }, - { - type = "group", - val = function() - return { mru(0, cdir) } - end, - opts = { shrink_margin = false }, - }, - }, - } + local section_mru = { + type = "group", + val = { + { + type = "text", + val = "Recent files", + opts = { + hl = "SpecialComment", + shrink_margin = false, + position = "center", + }, + }, + { type = "padding", val = 1 }, + { + type = "group", + val = function() + return { mru(0, cdir) } + end, + opts = { shrink_margin = false }, + }, + }, + } - local buttons = { - type = "group", - val = { - { type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } }, - { type = "padding", val = 1 }, - -- TODO: buttons should be added based on whether or not the relevant plugin is available - dashboard.button("e", " New file", "ene"), -- available all the time - dashboard.button("SPC F", "󰈞 Find file"), -- telescope - dashboard.button("SPC ff", "󰊄 Live grep"), -- telescope - dashboard.button("SPC p", " Projects"), -- any project - dashboard.button("q", "󰅚 Quit", "qa"), -- available all the time - }, - position = "center", - } + local buttons = { + type = "group", + val = { + { type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } }, + { type = "padding", val = 1 }, + -- TODO: buttons should be added based on whether or not the relevant plugin is available + dashboard.button("e", " New file", "ene"), -- available all the time + dashboard.button("SPC F", "󰈞 Find file"), -- telescope + dashboard.button("SPC ff", "󰊄 Live grep"), -- telescope + dashboard.button("SPC p", " Projects"), -- any project + dashboard.button("q", "󰅚 Quit", "qa"), -- available all the time + }, + position = "center", + } - local config = { - layout = { - { type = "padding", val = 2 }, - default_header, - { type = "padding", val = 2 }, - section_mru, - { type = "padding", val = 2 }, - buttons, - }, - opts = { - margin = 5, - setup = function() - vim.cmd([[ - autocmd alpha_temp DirChanged * lua require('alpha').redraw() - ]]) - end, - }, - } + local config = { + layout = { + { type = "padding", val = 2 }, + default_header, + { type = "padding", val = 2 }, + section_mru, + { type = "padding", val = 2 }, + buttons, + }, + opts = { + margin = 5, + setup = function() + vim.cmd([[ + autocmd alpha_temp DirChanged * lua require('alpha').redraw() + ]]) + end, + }, + } - alpha.setup(config) - ''; + alpha.setup(config) + ''; + }; }; } diff --git a/modules/plugins/dashboard/alpha/default.nix b/modules/plugins/dashboard/alpha/default.nix index 16496c63..913b32b7 100644 --- a/modules/plugins/dashboard/alpha/default.nix +++ b/modules/plugins/dashboard/alpha/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./alpha.nix ./config.nix diff --git a/modules/plugins/dashboard/dashboard-nvim/config.nix b/modules/plugins/dashboard/dashboard-nvim/config.nix index 13c08e64..a171bfce 100644 --- a/modules/plugins/dashboard/dashboard-nvim/config.nix +++ b/modules/plugins/dashboard/dashboard-nvim/config.nix @@ -3,17 +3,20 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.options) mkIf; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.dashboard.dashboard-nvim; in { config = mkIf cfg.enable { - vim.startPlugins = [ - "dashboard-nvim" - ]; + vim = { + startPlugins = [ + "dashboard-nvim" + ]; - vim.luaConfigRC.dashboard-nvim = nvim.dag.entryAnywhere '' - require("dashboard").setup{} - ''; + luaConfigRC.dashboard-nvim = entryAnywhere '' + require("dashboard").setup{} + ''; + }; }; } diff --git a/modules/plugins/dashboard/default.nix b/modules/plugins/dashboard/default.nix index c63ad3ef..365ea8d0 100644 --- a/modules/plugins/dashboard/default.nix +++ b/modules/plugins/dashboard/default.nix @@ -1,4 +1,4 @@ -{...}: { +{ imports = [ ./alpha ./dashboard-nvim