From d65555b7f3bc03d0be8fe0b69a85e61a29b7f53f Mon Sep 17 00:00:00 2001 From: diniamo Date: Thu, 21 Nov 2024 22:03:28 +0100 Subject: [PATCH] runner/run-nvim: init --- docs/release-notes/rl-0.7.md | 2 ++ flake.lock | 17 +++++++++ flake.nix | 6 ++++ modules/modules.nix | 1 + modules/plugins/runner/default.nix | 5 +++ modules/plugins/runner/run-nvim/config.nix | 38 ++++++++++++++++++++ modules/plugins/runner/run-nvim/default.nix | 6 ++++ modules/plugins/runner/run-nvim/run-nvim.nix | 18 ++++++++++ 8 files changed, 93 insertions(+) create mode 100644 modules/plugins/runner/default.nix create mode 100644 modules/plugins/runner/run-nvim/config.nix create mode 100644 modules/plugins/runner/run-nvim/default.nix create mode 100644 modules/plugins/runner/run-nvim/run-nvim.nix diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 876f1ab..b8d85c3 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -201,6 +201,8 @@ To migrate to `nixfmt`, simply change `vim.languages.nix.format.type` to is bundled with nvf, if you enable the module, since there is no way to provide only the LSP server. +- Add `run.nvim` (https://github.com/diniamo/run.nvim) support for running code using cached commands. + [Neovim documentation on `vim.cmd`]: https://neovim.io/doc/user/lua.html#vim.cmd() - Make Neovim's configuration file entirely Lua based. This comes with a few diff --git a/flake.lock b/flake.lock index d9e6b47..dd24986 100644 --- a/flake.lock +++ b/flake.lock @@ -1710,6 +1710,22 @@ "type": "github" } }, + "plugin-run-nvim": { + "flake": false, + "locked": { + "lastModified": 1732273891, + "narHash": "sha256-/YLSbKh0wV6VYlNWeGrEbUUBQuchNcJjm1zn6vwYmro=", + "owner": "diniamo", + "repo": "run.nvim", + "rev": "0ae1cb228341ffec317efea4247550610de6fe0e", + "type": "github" + }, + "original": { + "owner": "diniamo", + "repo": "run.nvim", + "type": "github" + } + }, "plugin-rustaceanvim": { "flake": false, "locked": { @@ -2123,6 +2139,7 @@ "plugin-registers": "plugin-registers", "plugin-rose-pine": "plugin-rose-pine", "plugin-rtp-nvim": "plugin-rtp-nvim", + "plugin-run-nvim": "plugin-run-nvim", "plugin-rustaceanvim": "plugin-rustaceanvim", "plugin-smartcolumn": "plugin-smartcolumn", "plugin-sqls-nvim": "plugin-sqls-nvim", diff --git a/flake.nix b/flake.nix index 4e417e7..319b8f5 100644 --- a/flake.nix +++ b/flake.nix @@ -242,6 +242,12 @@ flake = false; }; + # Runners + plugin-run-nvim = { + url = "github:diniamo/run.nvim"; + flake = false; + }; + # Debuggers plugin-nvim-dap = { url = "github:mfussenegger/nvim-dap"; diff --git a/modules/modules.nix b/modules/modules.nix index 784c413..bc441e9 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -31,6 +31,7 @@ "notes" "projects" "rich-presence" + "runner" "session" "snippets" # "spellcheck" # FIXME: see neovim/init/spellcheck.nix diff --git a/modules/plugins/runner/default.nix b/modules/plugins/runner/default.nix new file mode 100644 index 0000000..d37fb5f --- /dev/null +++ b/modules/plugins/runner/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./run-nvim + ]; +} diff --git a/modules/plugins/runner/run-nvim/config.nix b/modules/plugins/runner/run-nvim/config.nix new file mode 100644 index 0000000..70cd5c9 --- /dev/null +++ b/modules/plugins/runner/run-nvim/config.nix @@ -0,0 +1,38 @@ +{ + lib, + config, + options, + ... +}: let + inherit (lib.modules) mkIf mkDefault; + inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLznBinding mkSetLuaLznBinding; + + cfg = config.vim.runner.run-nvim; + mappingDefinitions = options.vim.runner.run-nvim.mappings; + mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; +in { + config = mkIf cfg.enable { + vim = { + lazy.plugins.run-nvim = { + package = "run-nvim"; + setupModule = "run"; + inherit (cfg) setupOpts; + + cmd = "Run"; + + keys = [ + (mkSetLznBinding "n" mappings.run "Run") + (mkSetLznBinding "n" mappings.runOverride "Run!") + (mkSetLuaLznBinding "n" mappings.runCommand '' + function() + local input = vim.fn.input("Run command: ") + if input ~= "" then require("run").run(input, false) end + end + '') + ]; + }; + + binds.whichKey.register."r" = mkDefault "+Run"; + }; + }; +} diff --git a/modules/plugins/runner/run-nvim/default.nix b/modules/plugins/runner/run-nvim/default.nix new file mode 100644 index 0000000..5062c6e --- /dev/null +++ b/modules/plugins/runner/run-nvim/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./run-nvim.nix + ./config.nix + ]; +} diff --git a/modules/plugins/runner/run-nvim/run-nvim.nix b/modules/plugins/runner/run-nvim/run-nvim.nix new file mode 100644 index 0000000..dd24e6c --- /dev/null +++ b/modules/plugins/runner/run-nvim/run-nvim.nix @@ -0,0 +1,18 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption; + inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.nvim.binds) mkMappingOption; +in { + options = { + vim.runner.run-nvim = { + enable = mkEnableOption "run.nvim"; + setupOpts = mkPluginSetupOption "run.nvim" {}; + + mappings = { + run = mkMappingOption "Run cached" "ri"; + runOverride = mkMappingOption "Run and override" "ro"; + runCommand = mkMappingOption "Run prompt" "rc"; + }; + }; + }; +}