diff --git a/lib/binds.nix b/lib/binds.nix index 298cd30..22bca73 100644 --- a/lib/binds.nix +++ b/lib/binds.nix @@ -79,14 +79,14 @@ expr = true; }; - mkSetLznBinding = binding: action: { - inherit action; + mkSetLznBinding = mode: binding: action: { + inherit action mode; key = binding.value; desc = binding.description; }; - mkSetLuaLznBinding = binding: action: { - inherit action; + mkSetLuaLznBinding = mode: binding: action: { + inherit action mode; key = binding.value; lua = true; desc = binding.description; diff --git a/modules/plugins/debugger/nvim-dap/config.nix b/modules/plugins/debugger/nvim-dap/config.nix index 7e9e8f7..b99fb3d 100644 --- a/modules/plugins/debugger/nvim-dap/config.nix +++ b/modules/plugins/debugger/nvim-dap/config.nix @@ -60,7 +60,7 @@ in { inherit (cfg.ui) setupOpts; keys = [ - (mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end") + (mkSetLuaLznBinding "n" mappings.toggleDapUI "function() require('dapui').toggle() end") ]; }; diff --git a/modules/plugins/lsp/trouble/config.nix b/modules/plugins/lsp/trouble/config.nix index cae0c7a..9bbc71c 100644 --- a/modules/plugins/lsp/trouble/config.nix +++ b/modules/plugins/lsp/trouble/config.nix @@ -21,12 +21,12 @@ in { cmd = "Trouble"; keys = [ - (mkSetLznBinding mappings.toggle "TroubleToggle") - (mkSetLznBinding mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") - (mkSetLznBinding mappings.documentDiagnostics "TroubleToggle document_diagnostics") - (mkSetLznBinding mappings.lspReferences "TroubleToggle lsp_references") - (mkSetLznBinding mappings.quickfix "TroubleToggle quickfix") - (mkSetLznBinding mappings.locList "TroubleToggle loclist") + (mkSetLznBinding "n" mappings.toggle "TroubleToggle") + (mkSetLznBinding "n" mappings.workspaceDiagnostics "TroubleToggle workspace_diagnostics") + (mkSetLznBinding "n" mappings.documentDiagnostics "TroubleToggle document_diagnostics") + (mkSetLznBinding "n" mappings.lspReferences "TroubleToggle lsp_references") + (mkSetLznBinding "n" mappings.quickfix "TroubleToggle quickfix") + (mkSetLznBinding "n" mappings.locList "TroubleToggle loclist") ]; }; diff --git a/modules/plugins/terminal/toggleterm/config.nix b/modules/plugins/terminal/toggleterm/config.nix index f0ebd72..d3a71fb 100644 --- a/modules/plugins/terminal/toggleterm/config.nix +++ b/modules/plugins/terminal/toggleterm/config.nix @@ -22,6 +22,7 @@ in { [(mkLznBinding ["n"] cfg.mappings.open "execute v:count . \"ToggleTerm\"" "Toggle terminal")] ++ optional cfg.lazygit.enable { key = cfg.lazygit.mappings.open; + mode = "n"; desc = lazygitMapDesc; }; diff --git a/modules/plugins/utility/telescope/config.nix b/modules/plugins/utility/telescope/config.nix index 6143627..d5881fa 100644 --- a/modules/plugins/utility/telescope/config.nix +++ b/modules/plugins/utility/telescope/config.nix @@ -34,36 +34,36 @@ in { keys = [ - (mkSetLznBinding mappings.findFiles " Telescope find_files") - (mkSetLznBinding mappings.liveGrep " Telescope live_grep") - (mkSetLznBinding mappings.buffers " Telescope buffers") - (mkSetLznBinding mappings.helpTags " Telescope help_tags") - (mkSetLznBinding mappings.open " Telescope") + (mkSetLznBinding "n" mappings.findFiles " Telescope find_files") + (mkSetLznBinding "n" mappings.liveGrep " Telescope live_grep") + (mkSetLznBinding "n" mappings.buffers " Telescope buffers") + (mkSetLznBinding "n" mappings.helpTags " Telescope help_tags") + (mkSetLznBinding "n" mappings.open " Telescope") - (mkSetLznBinding mappings.gitCommits " Telescope git_commits") - (mkSetLznBinding mappings.gitBufferCommits " Telescope git_bcommits") - (mkSetLznBinding mappings.gitBranches " Telescope git_branches") - (mkSetLznBinding mappings.gitStatus " Telescope git_status") - (mkSetLznBinding mappings.gitStash " Telescope git_stash") + (mkSetLznBinding "n" mappings.gitCommits " Telescope git_commits") + (mkSetLznBinding "n" mappings.gitBufferCommits " Telescope git_bcommits") + (mkSetLznBinding "n" mappings.gitBranches " Telescope git_branches") + (mkSetLznBinding "n" mappings.gitStatus " Telescope git_status") + (mkSetLznBinding "n" mappings.gitStash " Telescope git_stash") ] ++ (optionals config.vim.lsp.enable [ - (mkSetLznBinding mappings.lspDocumentSymbols " Telescope lsp_document_symbols") - (mkSetLznBinding mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") + (mkSetLznBinding "n" mappings.lspDocumentSymbols " Telescope lsp_document_symbols") + (mkSetLznBinding "n" mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") - (mkSetLznBinding mappings.lspReferences " Telescope lsp_references") - (mkSetLznBinding mappings.lspImplementations " Telescope lsp_implementations") - (mkSetLznBinding mappings.lspDefinitions " Telescope lsp_definitions") - (mkSetLznBinding mappings.lspTypeDefinitions " Telescope lsp_type_definitions") - (mkSetLznBinding mappings.diagnostics " Telescope diagnostics") + (mkSetLznBinding "n" mappings.lspReferences " Telescope lsp_references") + (mkSetLznBinding "n" mappings.lspImplementations " Telescope lsp_implementations") + (mkSetLznBinding "n" mappings.lspDefinitions " Telescope lsp_definitions") + (mkSetLznBinding "n" mappings.lspTypeDefinitions " Telescope lsp_type_definitions") + (mkSetLznBinding "n" mappings.diagnostics " Telescope diagnostics") ]) ++ ( optionals config.vim.treesitter.enable [ - (mkSetLznBinding mappings.treesitter " Telescope treesitter") + (mkSetLznBinding "n" mappings.treesitter " Telescope treesitter") ] ) ++ ( optionals config.vim.projects.project-nvim.enable [ - (mkSetLznBinding mappings.findProjects "") + (mkSetLznBinding "n" mappings.findProjects "") ] ); }; diff --git a/modules/wrapper/lazy/config.nix b/modules/wrapper/lazy/config.nix index 01deeb0..36c18a9 100644 --- a/modules/wrapper/lazy/config.nix +++ b/modules/wrapper/lazy/config.nix @@ -9,7 +9,6 @@ inherit (lib.generators) mkLuaInline; inherit (lib.strings) optionalString; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.nvim.dag) entryBefore entryAfter; cfg = config.vim.lazy; toLuaLznKeySpec = keySpec: @@ -50,6 +49,16 @@ end ''; + load = + if spec.load != null + then + mkLuaInline '' + funcion() + ${spec.load} + end + '' + else null; + keys = if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set" then map toLuaLznKeySpec (filter (keySpec: keySpec.key != null) spec.keys) diff --git a/modules/wrapper/lazy/lazy.nix b/modules/wrapper/lazy/lazy.nix index 2bbda27..56ec002 100644 --- a/modules/wrapper/lazy/lazy.nix +++ b/modules/wrapper/lazy/lazy.nix @@ -22,21 +22,21 @@ ''; desc = mkOption { - description = "Description of the key map"; type = nullOr str; default = null; + description = "Description of the key map"; }; ft = mkOption { - description = "TBD"; type = nullOr (listOf str); default = null; + description = "TBD"; }; mode = mkOption { - description = "Modes to bind in"; type = either str (listOf str); - default = ["n" "x" "s" "o"]; + example = ["n" "x" "o"]; + description = "Modes to bind in"; }; silent = mkBool true "Whether this mapping should be silent. Equivalent to adding to a map."; @@ -48,6 +48,21 @@ }; }; + lznEvent = submodule { + options = { + event = mkOption { + type = nullOr (either str (listOf str)); + example = "BufEnter"; + description = "Exact event name"; + }; + pattern = mkOption { + type = nullOr (either str (listOf str)); + example = "BufEnter *.lua"; + description = "Event pattern"; + }; + }; + }; + lznPluginType = submodule { options = { package = mkOption { @@ -57,84 +72,67 @@ setupModule = mkOption { type = nullOr str; - description = "Lua module to run setup function on."; default = null; + description = "Lua module to run setup function on."; }; setupOpts = mkOption { type = attrsOf anything; - description = "Options to pass to the setup function"; default = {}; + description = "Options to pass to the setup function"; }; # lz.n options enabled = mkOption { type = nullOr (either bool str); - description = "When false, or if the lua function returns false, this plugin will not be included in the spec"; default = null; + description = "When false, or if the lua function returns false, this plugin will not be included in the spec"; }; beforeAll = mkOption { type = nullOr lines; - description = "Lua code to run before any plugins are loaded. This will be wrapped in a function."; default = null; + description = "Lua code to run before any plugins are loaded. This will be wrapped in a function."; }; before = mkOption { type = nullOr lines; - description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; default = null; + description = "Lua code to run before plugin is loaded. This will be wrapped in a function."; }; after = mkOption { type = nullOr lines; + default = null; description = '' Lua code to run after plugin is loaded. This will be wrapped in a function. If [](#opt-vim.lazy.plugins._name_.setupModule) is provided, the setup will be ran before `after`. ''; - default = null; }; event = mkOption { - description = "Lazy-load on event"; + type = nullOr (oneOf [str (listOf str) lznEvent]); default = null; - type = let - event = submodule { - options = { - event = mkOption { - type = nullOr (either str (listOf str)); - description = "Exact event name"; - example = "BufEnter"; - }; - pattern = mkOption { - type = nullOr (either str (listOf str)); - description = "Event pattern"; - example = "BufEnter *.lua"; - }; - }; - }; - in - nullOr (oneOf [str (listOf str) event]); + description = "Lazy-load on event"; }; cmd = mkOption { - description = "Lazy-load on command"; - default = null; type = nullOr (either str (listOf str)); + default = null; + description = "Lazy-load on command"; }; ft = mkOption { - description = "Lazy-load on filetype"; - default = null; type = nullOr (either str (listOf str)); + default = null; + description = "Lazy-load on filetype"; }; keys = mkOption { - description = "Lazy-load on key mapping"; - default = null; type = nullOr (oneOf [str (listOf lznKeysSpec) (listOf str)]); + default = null; example = '' keys = [ { @@ -152,20 +150,21 @@ } ] ''; + description = "Lazy-load on key mapping"; }; colorscheme = mkOption { - description = "Lazy-load on colorscheme."; type = nullOr (either str (listOf str)); default = null; + description = "Lazy-load on colorscheme."; }; lazy = mkBool false "Lazy-load manually, e.g. using `trigger_load`."; priority = mkOption { type = nullOr int; - description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first."; default = null; + description = "Only useful for stat plugins (not lazy-loaded) to force loading certain plugins first."; }; load = mkOption { @@ -183,20 +182,14 @@ in { options.vim.lazy = { enable = mkEnableOption "plugin lazy-loading via lz.n and lzn-auto-require" // {default = true;}; loader = mkOption { - description = "Lazy loader to use"; type = enum ["lz.n"]; default = "lz.n"; + description = "Lazy loader to use"; }; plugins = mkOption { - default = {}; type = attrsOf lznPluginType; - description = '' - Plugins to lazy load. - - The attribute key is used as the plugin name: for the default `vim.g.lz_n.load` - function this should be either the `package.pname` or `package.name`. - ''; + default = {}; example = '' { toggleterm-nvim = { @@ -214,15 +207,21 @@ in { }; } ''; + description = '' + Plugins to lazy load. + + The attribute key is used as the plugin name: for the default `vim.g.lz_n.load` + function this should be either the `package.pname` or `package.name`. + ''; }; enableLznAutoRequire = mkOption { + type = bool; + default = true; description = '' Enable lzn-auto-require. Since builtin plugins rely on this, only turn off for debugging. ''; - type = bool; - default = true; }; builtLazyConfig = mkOption {