diff --git a/docs/release-notes/rl-0.6.md b/docs/release-notes/rl-0.6.md index c162ac0..532f5d9 100644 --- a/docs/release-notes/rl-0.6.md +++ b/docs/release-notes/rl-0.6.md @@ -56,3 +56,5 @@ Release notes for release 0.6 - Rewrote the entire `fidget.nvim` module to include extensive configuration options. Option `vim.fidget-nvim.align.bottom` has been removed in favor of [vim.fidget-nvim.notification.window.align](vim.fidget-nvim.notification.window.align), which now supports `top` and `bottom` values. `vim.fidget-nvim.align.right` has no longer any equivalent and also has been removed. + +- `which-key.nvim` categories can now be customized through [vim.binds.whichKey.register](vim.binds.whichKey.register). diff --git a/lib/stdlib-extended.nix b/lib/stdlib-extended.nix index 9833248..ff7b7f6 100644 --- a/lib/stdlib-extended.nix +++ b/lib/stdlib-extended.nix @@ -68,6 +68,8 @@ in mkSetLuaBinding = binding: action: mkLuaBinding binding.value action binding.description; + pushDownDefault = attr: self.mapAttrs (name: value: self.mkDefault value) attr; + # For forward compatibility. literalExpression = super.literalExpression or super.literalExample; }) diff --git a/modules/filetree/nvimtree/config.nix b/modules/filetree/nvimtree/config.nix index 684be7a..f6ac65a 100644 --- a/modules/filetree/nvimtree/config.nix +++ b/modules/filetree/nvimtree/config.nix @@ -10,6 +10,8 @@ inherit (lib.nvim.binds) mkBinding; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) listToLuaTable expToLua; + # TODO: move this to its own module + inherit (lib) pushDownDefault; cfg = config.vim.filetree.nvimTree; self = import ./nvimtree.nix {inherit pkgs lib;}; @@ -25,6 +27,10 @@ in { (mkBinding cfg.mappings.focus ":NvimTreeFocus" mappings.focus.description) ]; + vim.binds.whichKey.register = pushDownDefault { + "t" = "+NvimTree"; + }; + vim.luaConfigRC.nvimtreelua = entryAnywhere '' ${ lib.optionalString cfg.disableNetrw '' diff --git a/modules/git/config.nix b/modules/git/config.nix index c02dc9e..8e34963 100644 --- a/modules/git/config.nix +++ b/modules/git/config.nix @@ -7,6 +7,8 @@ inherit (lib.modules) mkIf mkMerge; inherit (lib.nvim.binds) addDescriptionsToMappings mkSetExprBinding mkSetLuaBinding; inherit (lib.nvim.dag) entryAnywhere; + # TODO: move this to its own module + inherit (lib) pushDownDefault; cfg = config.vim.git; @@ -63,6 +65,10 @@ in { (mkSetLuaBinding gsMappings.resetHunk "function() package.loaded.gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end") ]; + vim.binds.whichKey.register = pushDownDefault { + "g" = "+Gitsigns"; + }; + vim.luaConfigRC.gitsigns = entryAnywhere '' require('gitsigns').setup{} ''; diff --git a/modules/lsp/nvim-code-action-menu/config.nix b/modules/lsp/nvim-code-action-menu/config.nix index c64f027..9f8f604 100644 --- a/modules/lsp/nvim-code-action-menu/config.nix +++ b/modules/lsp/nvim-code-action-menu/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkSetBinding nvim; + inherit (lib) addDescriptionsToMappings mkIf mkSetBinding nvim pushDownDefault; cfg = config.vim.lsp; @@ -17,6 +17,10 @@ in { vim.maps.normal = mkSetBinding mappings.open ":CodeActionMenu"; + vim.binds.whichKey.register = pushDownDefault { + "c" = "+CodeAction"; + }; + vim.luaConfigRC.code-action-menu = nvim.dag.entryAnywhere '' -- border configuration vim.g.code_action_menu_window_border = '${config.vim.ui.borders.plugins.code-action-menu.style}' diff --git a/modules/lsp/trouble/config.nix b/modules/lsp/trouble/config.nix index ee136a5..bb751c7 100644 --- a/modules/lsp/trouble/config.nix +++ b/modules/lsp/trouble/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetBinding nvim; + inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetBinding nvim pushDownDefault; cfg = config.vim.lsp; @@ -24,6 +24,12 @@ in { (mkSetBinding mappings.locList "TroubleToggle loclist") ]; + vim.binds.whichKey.register = pushDownDefault { + "l" = "Trouble"; + "x" = "+Trouble"; + "lw" = "Workspace"; + }; + vim.luaConfigRC.trouble = nvim.dag.entryAnywhere '' -- Enable trouble diagnostics viewer require("trouble").setup {} diff --git a/modules/minimap/codewindow/config.nix b/modules/minimap/codewindow/config.nix index 86b0137..b95aca8 100644 --- a/modules/minimap/codewindow/config.nix +++ b/modules/minimap/codewindow/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetLuaBinding nvim; + inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetLuaBinding nvim pushDownDefault; cfg = config.vim.minimap.codewindow; @@ -24,6 +24,10 @@ in { (mkSetLuaBinding mappings.toggleFocus "require('codewindow').toggle_focus") ]; + vim.binds.whichKey.register = pushDownDefault { + "m" = "+Minimap"; + }; + vim.luaConfigRC.codewindow = nvim.dag.entryAnywhere '' local codewindow = require('codewindow') codewindow.setup({ diff --git a/modules/minimap/minimap-vim/config.nix b/modules/minimap/minimap-vim/config.nix index ef318f7..6577e8c 100644 --- a/modules/minimap/minimap-vim/config.nix +++ b/modules/minimap/minimap-vim/config.nix @@ -4,7 +4,7 @@ lib, ... }: let - inherit (lib) mkIf; + inherit (lib) mkIf pushDownDefault; cfg = config.vim.minimap.minimap-vim; in { @@ -13,5 +13,9 @@ in { pkgs.code-minimap "minimap-vim" ]; + + vim.binds.whichKey.register = pushDownDefault { + "m" = "+Minimap"; + }; }; } diff --git a/modules/notes/mind-nvim/config.nix b/modules/notes/mind-nvim/config.nix index 98f7751..8a609b0 100644 --- a/modules/notes/mind-nvim/config.nix +++ b/modules/notes/mind-nvim/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib) mkIf nvim pushDownDefault; cfg = config.vim.notes.mind-nvim; in { @@ -18,6 +18,10 @@ in { "oc" = {action = ":MindClose";}; }; + vim.binds.whichKey.register = pushDownDefault { + "o" = "+Notes"; + }; + vim.luaConfigRC.mind-nvim = nvim.dag.entryAnywhere '' require'mind'.setup() ''; diff --git a/modules/notes/obsidian/config.nix b/modules/notes/obsidian/config.nix index 192244b..f521c62 100644 --- a/modules/notes/obsidian/config.nix +++ b/modules/notes/obsidian/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib) mkIf nvim pushDownDefault; cfg = config.vim.notes.obsidian; auto = config.vim.autocomplete; @@ -15,6 +15,10 @@ in { "tabular" ]; + vim.binds.whichKey.register = pushDownDefault { + "o" = "+Notes"; + }; + vim.luaConfigRC.obsidian = nvim.dag.entryAnywhere '' require("obsidian").setup({ dir = "${cfg.dir}", diff --git a/modules/notes/orgmode/config.nix b/modules/notes/orgmode/config.nix index 967a937..08df2de 100644 --- a/modules/notes/orgmode/config.nix +++ b/modules/notes/orgmode/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) mkIf mkMerge nvim; + inherit (lib) mkIf mkMerge nvim pushDownDefault; cfg = config.vim.notes.orgmode; in { @@ -13,6 +13,10 @@ in { "orgmode-nvim" ]; + vim.binds.whichKey.register = pushDownDefault { + "o" = "+Notes"; + }; + vim.luaConfigRC.orgmode = nvim.dag.entryAnywhere '' -- Load custom treesitter grammar for org filetype require('orgmode').setup_ts_grammar() diff --git a/modules/tabline/nvim-bufferline/config.nix b/modules/tabline/nvim-bufferline/config.nix index 9004c89..befafcd 100644 --- a/modules/tabline/nvim-bufferline/config.nix +++ b/modules/tabline/nvim-bufferline/config.nix @@ -3,7 +3,7 @@ lib, ... }: let - inherit (lib) mkIf mkMerge mkLuaBinding mkBinding nvim; + inherit (lib) mkIf mkMerge mkLuaBinding mkBinding nvim pushDownDefault; cfg = config.vim.tabline.nvimBufferline; self = import ./nvim-bufferline.nix { @@ -40,6 +40,13 @@ in { (mkBinding cfg.mappings.movePrevious ":BufferLineMovePrev" mappings.movePrevious.description) ]; + vim.binds.whichKey.register = pushDownDefault { + "b" = "+Buffer"; + "bm" = "BufferLineMove"; + "bs" = "BufferLineSort"; + "bsi" = "BufferLineSortById"; + }; + vim.luaConfigRC.nvimBufferline = nvim.dag.entryAnywhere '' require("bufferline").setup{ options = { diff --git a/modules/utility/binds/which-key/config.nix b/modules/utility/binds/which-key/config.nix index 6e2a83c..238d888 100644 --- a/modules/utility/binds/which-key/config.nix +++ b/modules/utility/binds/which-key/config.nix @@ -3,14 +3,17 @@ lib, ... }: let - inherit (lib) mkIf nvim; + inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.binds.whichKey; in { config = mkIf (cfg.enable) { vim.startPlugins = ["which-key"]; - vim.luaConfigRC.whichkey = nvim.dag.entryAnywhere '' + vim.luaConfigRC.whichkey = entryAnywhere '' local wk = require("which-key") wk.setup ({ key_labels = { @@ -20,108 +23,14 @@ in { [""] = "TAB", }, - ${lib.optionalString (config.vim.ui.borders.plugins.which-key.enable) '' + ${optionalString (config.vim.ui.borders.plugins.which-key.enable) '' window = { border = "${config.vim.ui.borders.plugins.which-key.style}", }, ''} }) - wk.register({ - ${ - if config.vim.tabline.nvimBufferline.enable - then '' - -- Buffer - ["b"] = { name = "+Buffer" }, - ["bm"] = { name = "BufferLineMove" }, - ["bs"] = { name = "BufferLineSort" }, - ["bsi"] = { name = "BufferLineSortById" }, - '' - else "" - } - - ${ - if config.vim.telescope.enable - then '' - ["f"] = { name = "+Telescope" }, - -- Telescope - ["fl"] = { name = "Telescope LSP" }, - ["fm"] = { name = "Cellular Automaton" }, -- TODO: mvoe this to its own parent group - ["fv"] = { name = "Telescope Git" }, - ["fvc"] = { name = "Commits" }, - '' - else "" - } - - ${ - if config.vim.lsp.trouble.enable - then '' - -- Trouble - ["lw"] = { name = "Workspace" }, - ["x"] = { name = "+Trouble" }, -- TODO: move all trouble binds to the same parent group - ["l"] = { name = "+Trouble" }, - '' - else "" - } - - ${ - if config.vim.lsp.nvimCodeActionMenu.enable - then '' - -- Parent Groups - ["c"] = { name = "+CodeAction" }, - '' - else "" - } - - ${ - if config.vim.minimap.codewindow.enable || config.vim.minimap.minimap-vim.enable - then '' - -- Minimap - ["m"] = { name = "+Minimap" }, -- TODO: remap both minimap plugins' keys to be the same - '' - else "" - } - - ${ - if config.vim.notes.mind-nvim.enable || config.vim.notes.obsidian.enable || config.vim.notes.orgmode.enable - then '' - -- Notes - ["o"] = { name = "+Notes" }, - -- TODO: options for other note taking plugins and their individual binds - -- TODO: move all note-taker binds under leader + o - '' - else "" - } - - ${ - # TODO: This probably will need to be reworked for custom-keybinds - if config.vim.filetree.nvimTree.enable - then '' - -- NvimTree - ["t"] = { name = "+NvimTree" }, - '' - else "" - } - - ${ - if config.vim.git.gitsigns.enable - then '' - -- Git - ["g"] = { name = "+Gitsigns" }, - '' - else "" - } - - ${ - if config.vim.utility.preview.glow.enable - then '' - -- Markdown - ["pm"] = { name = "+Preview Markdown" }, - '' - else "" - } - - }) + wk.register(${toLuaObject cfg.register}) ''; }; } diff --git a/modules/utility/binds/which-key/which-key.nix b/modules/utility/binds/which-key/which-key.nix index ceba7de..796dc8e 100644 --- a/modules/utility/binds/which-key/which-key.nix +++ b/modules/utility/binds/which-key/which-key.nix @@ -1,7 +1,18 @@ -{lib, ...}: let - inherit (lib) mkEnableOption; +{ + config, + lib, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) attrsOf str; in { options.vim.binds.whichKey = { enable = mkEnableOption "which-key keybind helper menu"; + + register = mkOption { + description = "Register label for which-key keybind helper menu"; + type = attrsOf str; + default = {}; + }; }; } diff --git a/modules/utility/preview/glow/config.nix b/modules/utility/preview/glow/config.nix index 5b9e14f..aca57f0 100644 --- a/modules/utility/preview/glow/config.nix +++ b/modules/utility/preview/glow/config.nix @@ -4,7 +4,7 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge mkBinding; + inherit (lib) nvim mkIf mkMerge mkBinding pushDownDefault; cfg = config.vim.utility.preview.glow; self = import ./glow.nix { @@ -19,6 +19,10 @@ in { (mkBinding cfg.mappings.openPreview ":Glow" mappings.openPreview.description) ]; + vim.binds.whichKey.register = pushDownDefault { + "pm" = "+Preview Markdown"; + }; + vim.luaConfigRC.glow = nvim.dag.entryAnywhere '' require('glow').setup({ glow_path = "${pkgs.glow}/bin/glow" diff --git a/modules/utility/telescope/config.nix b/modules/utility/telescope/config.nix index 53cde96..eb7a14e 100644 --- a/modules/utility/telescope/config.nix +++ b/modules/utility/telescope/config.nix @@ -4,7 +4,7 @@ lib, ... }: let - inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetBinding nvim; + inherit (lib) addDescriptionsToMappings mkIf mkMerge mkSetBinding nvim pushDownDefault; cfg = config.vim.telescope; self = import ./telescope.nix {inherit lib;}; @@ -52,6 +52,14 @@ in { ) ]; + vim.binds.whichKey.register = pushDownDefault { + "f" = "+Telescope"; + "fl" = "Telescope LSP"; + "fm" = "Cellular Automaton"; + "fv" = "Telescope Git"; + "fvc" = "Commits"; + }; + vim.luaConfigRC.telescope = nvim.dag.entryAnywhere '' local telescope = require('telescope') telescope.setup {