diff --git a/configuration.nix b/configuration.nix index 435e145..7d6f417 100644 --- a/configuration.nix +++ b/configuration.nix @@ -188,6 +188,7 @@ inputs: let }; vim.ui = { + borders.enable = true; noice.enable = true; colorizer.enable = true; modes-nvim.enable = false; # the theme looks terrible with catppuccin diff --git a/docs/manual/custom-plugins.adoc b/docs/manual/custom-plugins.adoc index 642b60e..6f6da92 100644 --- a/docs/manual/custom-plugins.adoc +++ b/docs/manual/custom-plugins.adoc @@ -3,11 +3,42 @@ You can use custom plugins, before they are implemented in the flake. To add a plugin, you need to add it to your config's `config.vim.startPlugins` array. -This is an example of adding the FrenzyExists/aquarium-vim plugin: + + +=== New Method +As of version 0.5, we have a more extensive API for configuring plugins, under `vim.extraPlugins`. + +Instead of using DAGs exposed by the library, you may use the extra plugin module as follows: [source,nix] ---- { + config.vim.extraPlugins = with pkgs.vimPlugins; { + aerial = { + package = aerial-nvim; + setup = '' + require('aerial').setup { + -- some lua configuration here + } + ''; + }; + + harpoon = { + package = harpoon; + setup = "require('harpoon').setup {}"; + after = ["aerial"]; + }; + }; +} +---- + +=== Old Method +Users who have not yet updated to 0.5, or prefer a more hands-on approach may use the old method where the load orderof the plugins is determined by DAGs. + +[source,nix] +---- +{ + # fetch plugin source from GitHub and add it to startPlugins config.vim.startPlugins = [ (pkgs.fetchFromGitHub { owner = "FrenzyExists"; diff --git a/docs/manual/home-manager.adoc b/docs/manual/home-manager.adoc index a937738..df60652 100644 --- a/docs/manual/home-manager.adoc +++ b/docs/manual/home-manager.adoc @@ -43,38 +43,4 @@ Then we should be able to use the given module. E.g. } ---- -=== Custom vim/neovim plugins -It is possible to add custom plugins to your configuration by using the `vim.startPlugins` option and the this flake's lua DAG library. - -Start by adding it to startPlugins. This example uses nvim-surround, but the process will be similar for other plugins as well. - -[source,nix] ----- -{ - programs.neovim-flake = { - enable = true; - settings = { - vim.startPlugins = [ pkgs.vimPlugins.nvim-surround ]; - }; - }; -} ----- - -Followed by requiring the plugin, should it need one, in the lua DAG. Please note that you're able to name the DAG to however you want, the name will add a `--SECTION ` in the init.vim, under which it will be initialized. `lib.nvim.dag.entryAfter ["name"]` could also be used to initialize a plugin only after a previous plugin has beeni initialize -Your final setup will likely look like this, where nvim-flake refers to your flake input or fetch. - -[source,nix] ----- -{ - programs.neovim-flake = { - enable = true; - settings = { - vim.startPlugins = [ pkgs.vimPlugins.nvim-surround ]; - luaConfigRC.nvim-surround = nvim-flake.lib.nvim.dag.entryAnywhere '' # nvim-flake is a reference to the flake. Please change this accordingly to your config. - require("nvim-surround").setup() - ''; - }; - }; -} ----- diff --git a/docs/release-notes/rl-0.5.adoc b/docs/release-notes/rl-0.5.adoc index 865ee3f..cde1d4b 100644 --- a/docs/release-notes/rl-0.5.adoc +++ b/docs/release-notes/rl-0.5.adoc @@ -8,14 +8,18 @@ https://github.com/horriblename[horriblename]: -* Add transparency support for tokyonight theme. +* Added transparency support for tokyonight theme. -* Fix bug where cmp's close and scrollDocs mappings wasn't working. +* Fixed a bug where cmp's close and scrollDocs mappings wasn't working. + +* Streamlined and simplified extra plugin API with the addition of <>. https://github.com/amanse[amanse]: -* Add daily notes options for obsidian plugin +* Added daily notes options for obsidian plugin. https://github.com/notashelf[notashelf]: -* Add GitHub Copilot to completion sources +* Added GitHub Copilot to completion sources. + +* Added <> for global and individual plugin border configuration. diff --git a/flake.lock b/flake.lock index b69a675..c3b6a38 100644 --- a/flake.lock +++ b/flake.lock @@ -855,17 +855,17 @@ "nmd": { "flake": false, "locked": { - "lastModified": 1680213367, - "narHash": "sha256-NbSXxpFAK5IMcsQTK0vSGy099HExx3SEagqW4Lpc+X8=", - "owner": "rycee", + "lastModified": 1687627428, + "narHash": "sha256-7zGfXuNS5RHqhpEdz2fwrtqvF86JRo5U1hrxZSYgcm8=", + "owner": "~rycee", "repo": "nmd", - "rev": "abb15317ebd17e5a0a7dd105e2ce52f2700185a8", - "type": "gitlab" + "rev": "824a380546b5d0d0eb701ff8cd5dbafb360750ff", + "type": "sourcehut" }, "original": { - "owner": "rycee", + "owner": "~rycee", "repo": "nmd", - "type": "gitlab" + "type": "sourcehut" } }, "noice-nvim": { diff --git a/flake.nix b/flake.nix index 3e1d977..4de2635 100644 --- a/flake.nix +++ b/flake.nix @@ -58,7 +58,7 @@ # For generating documentation website nmd = { - url = "gitlab:rycee/nmd"; + url = "sourcehut:~rycee/nmd"; flake = false; }; diff --git a/lib/types/default.nix b/lib/types/default.nix index 6d5777d..bfaa38d 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -4,6 +4,6 @@ typesLanguage = import ./languages.nix {inherit lib;}; in { inherit (typesDag) dagOf; - inherit (typesPlugin) pluginsOpt; + inherit (typesPlugin) pluginsOpt extraPluginType; inherit (typesLanguage) diagnostics mkGrammarOption; } diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index 1a65fa7..ccbde55 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -92,15 +92,37 @@ with lib; let "copilot-cmp" ]; # You can either use the name of the plugin or a package. - pluginsType = with types; - listOf ( - nullOr ( - either - (enum availablePlugins) - package - ) + pluginType = with types; + nullOr ( + either + package + (enum availablePlugins) ); + + pluginsType = types.listOf pluginType; + + extraPluginType = with types; + submodule { + options = { + package = mkOption { + type = pluginType; + }; + after = mkOption { + type = listOf str; + default = []; + description = "Setup this plugin after the following ones."; + }; + setup = mkOption { + type = lines; + default = ""; + description = "Lua code to run during setup."; + example = "require('aerial').setup {}"; + }; + }; + }; in { + inherit extraPluginType; + pluginsOpt = { description, default ? [], diff --git a/modules/completion/nvim-cmp/config.nix b/modules/completion/nvim-cmp/config.nix index 52e8972..e7ab3ac 100644 --- a/modules/completion/nvim-cmp/config.nix +++ b/modules/completion/nvim-cmp/config.nix @@ -193,12 +193,14 @@ in { 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 = { - -- TODO: at some point, those need to be optional - -- but first nvim cmp module needs to be detached from "cfg.autocomplete" completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, + ''} snippet = { expand = function(args) diff --git a/modules/core/default.nix b/modules/core/default.nix index 9261caf..fd097ef 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -158,6 +158,27 @@ in { description = "List of plugins to optionally load"; }; + extraPlugins = mkOption { + type = types.attrsOf nvim.types.extraPluginType; + default = {}; + description = '' + List of plugins and related config. + Note that these are setup after builtin plugins. + ''; + example = literalExpression '' + with pkgs.vimPlugins; { + aerial = { + package = aerial-nvim; + setup = "require('aerial').setup {}"; + }; + harpoon = { + package = harpoon; + setup = "require('harpoon').setup {}"; + after = ["aerial"]; + }; + }''; + }; + globals = mkOption { default = {}; description = "Set containing global variable values"; @@ -297,6 +318,7 @@ in { result; in { vim = { + startPlugins = map (x: x.package) (attrValues cfg.extraPlugins); configRC = { globalsScript = nvim.dag.entryAnywhere (concatStringsSep "\n" globalsScript); @@ -314,6 +336,27 @@ in { in nvim.dag.entryAfter ["globalsScript"] luaConfig; + extraPluginConfigs = let + mkSection = r: '' + -- SECTION: ${r.name} + ${r.data} + ''; + mapResult = r: (wrapLuaConfig (concatStringsSep "\n" (map mkSection r))); + extraPluginsDag = mapAttrs (_: { + after, + setup, + ... + }: + nvim.dag.entryAfter after setup) + cfg.extraPlugins; + pluginConfig = resolveDag { + name = "extra plugins config"; + dag = extraPluginsDag; + inherit mapResult; + }; + in + nvim.dag.entryAfter ["luaScript"] pluginConfig; + # This is probably not the right way to set the config. I'm not sure how it should look like. mappings = let maps = [ diff --git a/modules/lsp/lsp-signature/config.nix b/modules/lsp/lsp-signature/config.nix index 738dcb5..1e73476 100644 --- a/modules/lsp/lsp-signature/config.nix +++ b/modules/lsp/lsp-signature/config.nix @@ -14,7 +14,14 @@ in { vim.luaConfigRC.lsp-signature = nvim.dag.entryAnywhere '' -- Enable lsp signature viewer - require("lsp_signature").setup() + require("lsp_signature").setup({ + ${optionalString (config.vim.ui.borders.plugins.lsp-signature.enable) '' + bind = true, -- This is mandatory, otherwise border config won't get registered. + handler_opts = { + border = "${config.vim.ui.borders.plugins.lsp-signature.style}" + } + ''} + }) ''; }; } diff --git a/modules/lsp/lspconfig/config.nix b/modules/lsp/lspconfig/config.nix index 70485be..e9d7b3c 100644 --- a/modules/lsp/lspconfig/config.nix +++ b/modules/lsp/lspconfig/config.nix @@ -16,6 +16,13 @@ in { vim.luaConfigRC.lspconfig = nvim.dag.entryAfter ["lsp-setup"] '' local lspconfig = require('lspconfig') + + ${ + # TODO: make border style configurable + optionalString (config.vim.ui.borders.enable) '' + require('lspconfig.ui.windows').default_options.border = '${config.vim.ui.borders.globalStyle}' + '' + } ''; } { diff --git a/modules/lsp/lspsaga/config.nix b/modules/lsp/lspsaga/config.nix index 3b7ea26..74b91fc 100644 --- a/modules/lsp/lspsaga/config.nix +++ b/modules/lsp/lspsaga/config.nix @@ -39,7 +39,11 @@ in { vim.luaConfigRC.lspsage = nvim.dag.entryAnywhere '' -- Enable lspsaga local saga = require 'lspsaga' - saga.init_lsp_saga() + saga.init_lsp_saga({ + ${optionalString (config.vim.ui.borders.plugins.lspsaga.enable) '' + border_style = '${config.vim.ui.borders.plugins.lspsaga.style}', + ''} + }) ''; }; } diff --git a/modules/minimap/codewindow/config.nix b/modules/minimap/codewindow/config.nix index 1025e63..ac82829 100644 --- a/modules/minimap/codewindow/config.nix +++ b/modules/minimap/codewindow/config.nix @@ -27,7 +27,7 @@ in { vim.luaConfigRC.codewindow = nvim.dag.entryAnywhere '' local codewindow = require('codewindow') codewindow.setup({ - exclude_filetypes = { 'NvimTree', 'orgagenda'}, + exclude_filetypes = { 'NvimTree', 'orgagenda', 'Alpha'}, }) ''; }; diff --git a/modules/ui/borders/borders.nix b/modules/ui/borders/borders.nix new file mode 100644 index 0000000..179de44 --- /dev/null +++ b/modules/ui/borders/borders.nix @@ -0,0 +1,43 @@ +{ + config, + lib, + ... +}: let + inherit (lib) mkOption mkEnableOption types; + + cfg = config.vim.ui.borders; + + defaultStyles = ["none" "single" "double" "rounded"]; +in { + options.vim.ui.borders = { + enable = mkEnableOption "visible borders for most windows"; + + globalStyle = mkOption { + type = types.enum defaultStyles; + default = "rounded"; + description = '' + global border style to use + ''; + }; + + # TODO: make per-plugin borders configurable + plugins = let + mkPluginStyleOption = name: { + enable = mkEnableOption "whether to enable borders for the ${name} plugin" // {default = cfg.enable;}; + + style = mkOption { + type = types.enum (defaultStyles ++ lib.optionals (name != "which-key") ["shadow"]); + default = cfg.globalStyle; + description = "border style to use for the ${name} plugin"; + }; + }; + in { + # despite not having it listed in example configuration, which-key does support the rounded type + # additionall, it supports a "shadow" type that is similar to none but is of higher contrast + which-key = mkPluginStyleOption "which-key"; + lspsaga = mkPluginStyleOption "lspsaga"; + nvim-cmp = mkPluginStyleOption "nvim-cmp"; + lsp-signature = mkPluginStyleOption "lsp-signature"; + }; + }; +} diff --git a/modules/ui/borders/default.nix b/modules/ui/borders/default.nix new file mode 100644 index 0000000..526ac4e --- /dev/null +++ b/modules/ui/borders/default.nix @@ -0,0 +1,5 @@ +_: { + imports = [ + ./borders.nix + ]; +} diff --git a/modules/ui/breadcrumbs/config.nix b/modules/ui/breadcrumbs/config.nix index 01d5d2c..7bf7dc1 100644 --- a/modules/ui/breadcrumbs/config.nix +++ b/modules/ui/breadcrumbs/config.nix @@ -66,7 +66,7 @@ in { lsp = { auto_attach = ${boolToString nb.lsp.autoAttach}, - preference = nil, -- TODO: convert list to lua table if not null + -- preference = nil, -- TODO: convert list to lua table if not null }, source_buffer = { diff --git a/modules/ui/default.nix b/modules/ui/default.nix index 1c63c40..bbcb9d2 100644 --- a/modules/ui/default.nix +++ b/modules/ui/default.nix @@ -7,5 +7,6 @@ _: { ./colorizer ./illuminate ./breadcrumbs + ./borders ]; } diff --git a/modules/ui/noice/config.nix b/modules/ui/noice/config.nix index 705256b..d12ebf0 100644 --- a/modules/ui/noice/config.nix +++ b/modules/ui/noice/config.nix @@ -32,7 +32,7 @@ in { command_palette = true, -- position the cmdline and popupmenu together long_message_to_split = true, -- long messages will be sent to a split inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = false, -- add a border to hover docs and signature help + lsp_doc_border = ${boolToString (config.vim.ui.borders.enable)}, -- add a border to hover docs and signature help }, format = { diff --git a/modules/utility/binds/which-key/config.nix b/modules/utility/binds/which-key/config.nix index a5c1569..8b0fa6c 100644 --- a/modules/utility/binds/which-key/config.nix +++ b/modules/utility/binds/which-key/config.nix @@ -18,7 +18,13 @@ in { [""] = "SPACE", [""] = "RETURN", [""] = "TAB", - } + }, + + ${lib.optionalString (config.vim.ui.borders.plugins.which-key.enable) '' + window = { + border = "${config.vim.ui.borders.plugins.which-key.style}", + }, + ''} }) wk.register({