From 4678f734111f341dc29b5f16adb8e084b97ded7e Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 28 Apr 2025 22:51:04 +0300 Subject: [PATCH 1/2] neovim/clipboard: init module --- docs/release-notes/rl-0.8.md | 6 ++- modules/neovim/init/clipboard.nix | 80 +++++++++++++++++++++++++++++++ modules/neovim/init/default.nix | 1 + 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 modules/neovim/init/clipboard.nix diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 80a0300c..f0f58e7c 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -91,6 +91,9 @@ options for `vim.diagnostic.config()` can now be customized through the [](#opt-vim.diagnostics.config) in nvf. +- Add `vim.clipboard` module for easily managing Neovim clipboard providers and + relevant packages in a simple UI. + [amadaluzia](https://github.com/amadaluzia): [haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim @@ -361,4 +364,5 @@ [Hardtime.nvim]: https://github.com/m4xshen/hardtime.nvim -- Add Plugin [Hardtime.nvim] under `vim.binds.hardtime-nvim` with `enable` and `setupOpts` options +- Add Plugin [Hardtime.nvim] under `vim.binds.hardtime-nvim` with `enable` and + `setupOpts` options diff --git a/modules/neovim/init/clipboard.nix b/modules/neovim/init/clipboard.nix new file mode 100644 index 00000000..011effaf --- /dev/null +++ b/modules/neovim/init/clipboard.nix @@ -0,0 +1,80 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.options) mkOption mkEnableOption mkPackageOption; + inherit (lib.types) nullOr either str listOf submodule; + inherit (lib.attrsets) mapAttrs mapAttrsToList filterAttrs; + cfg = config.vim.clipboard; +in { + options = { + vim = { + clipboard = { + enable = mkEnableOption '' + clipboard management for Neovim. Users may still choose to manage their + clipboard through [](#opt-vim.options) should they wish to avoid using + this module. + ''; + + registers = mkOption { + type = either str (listOf str); + default = ""; + example = "unnamedplus"; + description = '' + The register to be used by the Neovim clipboard. Recognized types are: + + * unnamed: Vim will use the clipboard register `"*"` for all yank, delete, + change and put operations which would normally go to the unnamed register. + + * unnamedplus: A variant of the "unnamed" flag which uses the clipboard register + `"+"` ({command}`:h quoteplus`) instead of register `"*"` for all yank, delete, + change and put operations which would normally go to the unnamed register. + + When `unnamed` and `unnamedplus` is included simultaneously yank and delete + operations (but not put) will additionally copy the text into register `"*"`. + + Please see {command}`:h clipboard` for more details. + + ''; + }; + + providers = mkOption { + type = submodule { + options = let + clipboards = { + # name = "package name"; + wl-copy = "wl-clipboard"; + xclip = "xclip"; + xsel = "xsel"; + }; + in + mapAttrs (name: pname: { + enable = mkEnableOption name; + package = mkPackageOption pkgs pname {nullable = true;}; + }) + clipboards; + }; + default = {}; + description = '' + Clipboard providers for which packages will be added to nvf's + {option}`extraPackages`. The `package` field may be set to `null` + if related packages are already found in system packages to + potentially reduce closure sizes. + ''; + }; + }; + }; + }; + + config = mkIf cfg.enable { + vim = { + options.clipboard = cfg.registers; + extraPackages = mapAttrsToList (_: v: v.package) ( + filterAttrs (_: v: v.enable && v.package != null) cfg.providers + ); + }; + }; +} diff --git a/modules/neovim/init/default.nix b/modules/neovim/init/default.nix index 7db6f2ef..30a481a1 100644 --- a/modules/neovim/init/default.nix +++ b/modules/neovim/init/default.nix @@ -2,6 +2,7 @@ imports = [ ./autocmds.nix ./basic.nix + ./clipboard.nix ./debug.nix ./diagnostics.nix ./highlight.nix From 69e75a00ed25a1708fca234a15bbd361e02ead73 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 4 May 2025 18:22:47 +0300 Subject: [PATCH 2/2] neovim/basic: deprecate `vim.useSystemClipboard` --- docs/release-notes/rl-0.8.md | 7 +++++++ modules/extra/deprecations.nix | 9 +++++++++ modules/neovim/init/basic.nix | 10 ---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index f0f58e7c..014a4a23 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -19,6 +19,11 @@ unavailable as they have been refactored out of the main none-ls repository upstream. +- `vim.useSystemClipboard` has been deprecated as a part of removing most + top-level convenience options, and should instead be configured in the new + module interface. You may set [](#opt-vim.clipboard.registers) appropriately + to configure Neovim to use the system clipboard. + [NotAShelf](https://github.com/notashelf): [typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim @@ -93,6 +98,8 @@ - Add `vim.clipboard` module for easily managing Neovim clipboard providers and relevant packages in a simple UI. + - This deprecates `vim.useSystemClipboard` as well, see breaking changes + section above for migration options. [amadaluzia](https://github.com/amadaluzia): diff --git a/modules/extra/deprecations.nix b/modules/extra/deprecations.nix index 86497130..91d8ef28 100644 --- a/modules/extra/deprecations.nix +++ b/modules/extra/deprecations.nix @@ -111,6 +111,15 @@ in { under the diagnostics module. Please consider using one of 'vim.diagnostics.config' or 'vim.luaConfigRC' to configure LSP lines for Neovim through its own diagnostics API. '') + + # 2025-05-04 + (mkRemovedOptionModule ["vim" "useSystemClipboard"] '' + Clipboard behaviour should now be controlled through the new, more fine-grained module + interface found in 'vim.clipboard'. To replicate previous behaviour, you may either + add 'vim.opt.clipboard:append("unnamedplus")' in luaConfigRC, or preferably set it + in 'vim.clipboard.registers'. Please see the documentation for the new module for more + details, or open an issue if you are confused. + '') ] # Migrated via batchRenameOptions. Further batch renames must be below this line. diff --git a/modules/neovim/init/basic.nix b/modules/neovim/init/basic.nix index 47bfe500..195ef5e7 100644 --- a/modules/neovim/init/basic.nix +++ b/modules/neovim/init/basic.nix @@ -34,12 +34,6 @@ in { description = "Enable syntax highlighting"; }; - useSystemClipboard = mkOption { - type = bool; - default = false; - description = "Make use of the clipboard for default yank and paste operations. Don't use * and +"; - }; - lineNumberMode = mkOption { type = enum ["relative" "number" "relNumber" "none"]; default = "relNumber"; @@ -144,10 +138,6 @@ in { # to pre-set Neovim options. Fear not, though as the Lua DAG is still as powerful as it # could be. luaConfigRC.basic = entryAfter ["globalsScript"] '' - ${optionalString cfg.useSystemClipboard '' - vim.opt.clipboard:append("unnamedplus") - ''} - ${optionalString cfg.syntaxHighlighting '' vim.cmd("syntax on") ''}