Should fix #12419. Since we already have the clipmethod option now, a new value called provider is added, which uses the value of the option clipfunc to copy/paste.
The first argument of the function would take the type of operation:
'p' for paste
'y' for yank/copy
... maybe more
The second argument is a dictionary containing operation specific key/value pairs.
For the paste operation, the function would return a tuple: (<flags>, <contents>), where could be what motion type to use, if the clipboard is cleared/empty, and maybe more. <contents> is just what to paste. It is up to the function/plugin to determine what encoding to use, and what mime type to use if there are ones, but it should be text.
One use case for this is obviously implementing an OSC 52 plugin (Maybe OSC 5522 too?).
This might change, I'll see as I work on this PR.
https://github.com/vim/vim/pull/17998
(6 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Just in case Nvim compatibility is considered, this is the document of g:clipboard, which I think is equivalent with 'clipfunc' that you propose. https://neovim.io/doc/user/provider.html#g:clipboard
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
Just in case Nvim compatibility is considered, this is the document of
g:clipboardin Nvim, which I think is equivalent with'clipfunc'that you propose. https://neovim.io/doc/user/provider.html#g:clipboard
Looking at it, maybe there could be a v:clipboard vim var that is a list of dictionaries (providers), each with a paste, copy, and a function that checks if the provider is available + a name for the provider. Then those names of the providers can be used in clipmethod. Don't know if that is just overcomplicated but sounds straightforward enough
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 4 commits.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
and a function that checks if the provider is available
If you do so, please don't query for executable existence as it may slowdown vim startup on windows. It is quite slow there.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
and a function that checks if the provider is available
If you do so, please don't query for executable existence as it may slowdown vim startup on windows. It is quite slow there. I remember this was the issue with neovim back in a day I tried to use it on my windows box.
Thanks, I will take that into consideration
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
I think this is ready
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@h-east commented on this pull request.
In src/testdir/test_clipboard_provider.vim:
> +
+ " Check if texlock is working
+ call assert_fails("call setline(1, 'test')", "E565:")
+endfunc
+
+" Test if 'paste' callback works properly
+func Test_clipboard_provider_cb_paste()
+ new
+ let v:clipproviders["test"] = {
+ \ "available": {-> v:true},
+ \ "paste": function("Paste")
+ \ }
+ set clipmethod=test
+
+ if has('unnamedplus')
+ call assert_equal("reg: +", getreg('+'))
CI error has occurred.
From test_codestyle.vim:
Found errors in Test_test_files():
command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[636]..function RunTheTest[63]..Test_test_files[33]..<SNR>8_ReportError line 2: testdir/test_clipboard_provider.vim line 74: trailing white space
make[2]: *** [Makefile:187: opt_test.vim] Error 1
⬇️ Suggested change
- call assert_equal("reg: +", getreg('+'))
+ call assert_equal("reg: +", getreg('+'))
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@h-east commented on this pull request.
> Note: "other" is used on systems without X11/Wayland, such as MS-Windows or MacOS, when running Vim without the GUI. + Note that the name of the clipboard provider should be used when you + want to use a clipboard provider. See |clipboard-providers| for more⬇️ Suggested change
- want to use a clipboard provider. See |clipboard-providers| for more + want to use a clipboard provider. See |clipboard-providers| for more
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
can you please regenerate configure script on latest HEAD?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Turning this into a draft again for now because I've decided to go a different direction with the design
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 2 commits.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 0 commits.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 2 commits.
You are receiving this because you are subscribed to this thread.![]()
I think this is ready
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 12 commits.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.![]()
I think this is ready
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@chrisbra commented on this pull request.
Is the clipboard provider feature compatible with Neovim? I think we should call this out then. Also can a few people try this please?
In src/globals.h:
> @@ -972,7 +972,8 @@ EXTERN int gui_win_y INIT(= -1); #ifdef FEAT_CLIPBOARD EXTERN Clipboard_T clip_star; // PRIMARY selection in X11/Wayland -# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) +# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) \ + || ((defined(UNIX) || defined(VMS)) && defined(FEAT_CLIPBOARD_PROVIDER))
That looks wrong. Why would clip_plus depend on FEAT_CLIPBOARD_PROVIDER?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Is the clipboard provider feature compatible with Neovim? I think we should call this out then. Also can a few people try this please?
It is not compatible with neovim.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@64-bitman commented on this pull request.
In src/globals.h:
> @@ -972,7 +972,8 @@ EXTERN int gui_win_y INIT(= -1); #ifdef FEAT_CLIPBOARD EXTERN Clipboard_T clip_star; // PRIMARY selection in X11/Wayland -# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) +# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) \ + || ((defined(UNIX) || defined(VMS)) && defined(FEAT_CLIPBOARD_PROVIDER))
It doesn't. clip_plus is enabled if on UNIX/VMS and the clipboard provider feature exists. But it does not depend on it
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Is the clipboard provider feature compatible with Neovim? I think we should call this out then. Also can a few people try this please?
It is not compatible with neovim.
Even the configuration of the clipboard provider? Would it make sense to to try to be compatible with a Vim-Script provider for Neovim? Or does it not make sense? In any case, I think it should be mentioned that this is incompatible then.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@chrisbra commented on this pull request.
In src/globals.h:
> @@ -972,7 +972,8 @@ EXTERN int gui_win_y INIT(= -1); #ifdef FEAT_CLIPBOARD EXTERN Clipboard_T clip_star; // PRIMARY selection in X11/Wayland -# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) +# if defined(FEAT_X11) || defined(FEAT_WAYLAND_CLIPBOARD) \ + || ((defined(UNIX) || defined(VMS)) && defined(FEAT_CLIPBOARD_PROVIDER))
okay
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Is the clipboard provider feature compatible with Neovim? I think we should call this out then. Also can a few people try this please?
It is not compatible with neovim.
Even the configuration of the clipboard provider? Would it make sense to to try to be compatible with a Vim-Script provider for Neovim? Or does it not make sense? In any case, I think it should be mentioned that this is incompatible then.
The configuration of the clipboard provider is very similar to neovim. However it seems that Neovim uses g:clipboard unlike this PR which uses a dedicated vim var v:. I also don't see the point in being fully one to one compatible with Neovim. The only major difference I would say is that you can directly create a process like this in Neovim:
let g:clipboard = { \ 'name': 'myClipboard', \ 'copy': { \ '+': ['tmux', 'load-buffer', '-'], \ '*': ['tmux', 'load-buffer', '-'], \ }, \ 'paste': { \ '+': ['tmux', 'save-buffer', '-'], \ '*': ['tmux', 'save-buffer', '-'], \ }, \ 'cache_enabled': 1, \ }
In this PR this must be done manually, but that should be more than easy enough to emulate. There also seems to be a cache feature Neovim provides, but I think that can be simulated using Vimscript anyways:
If "cache_enabled" is TRUE then when a selection is copied Nvim will cache the selection until the copy command process dies. When pasting, if the copy process has not died the cached selection is applied.
I also don't see many separate community maintained clipboard provider plugins for Neovim. They all seem to provide a different way of supporting the Wayland, X11, or Windows clipboard, which we already have native support for. Additionally, from Neovim:
The presence of a working clipboard tool implicitly enables the "+" and "*" registers. Nvim supports these clipboard tools, in order of priority:
g:clipboard : User override (if set to a dict or any string "name" below; e.g. g:clipboard="tmux" forces tmux clipboard and skips auto-detection).
"pbcopy" : pbcopy, pbpaste (macOS)
"wl-copy" : wl-copy, wl-paste (if $WAYLAND_DISPLAY is set)
"wayclip" : waycopy, waypaste (if $WAYLAND_DISPLAY is set)
"xsel" : xsel (if $DISPLAY is set)
"xclip" : xclip (if $DISPLAY is set)
"lemonade" : lemonade (for SSH) https://github.com/pocke/lemonade
"doitclient": doitclient (for SSH) https://www.chiark.greenend.org.uk/~sgtatham/doit/
"win32yank" : win32yank (Windows)
"putclip" : putclip, getclip (Windows) https://cygwin.com/packages/summary/cygutils.html
"clip" : clip, powershell (Windows) https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/clip
"termux" : termux (via termux-clipboard-set, termux-clipboard-get)
"tmux" : tmux (if $TMUX is set)
"osc52" : clipboard-osc52 (if supported by your terminal)
We already have native clipboard support for 80% of the platforms these tools operate on.
Moreover, a big difference is that this PR utilizes the clipmethod option Vim has, meaning we can support multiple custom clipboard providers, while the g:clipboard variable for Neovim seems to only be for one clipboard provider.
Overall, I think it would just be too much work to try to be compatible with Neovim with little benefit.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
thanks, makes sense.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hi @64-bitman , this seems to completely break clipboard on macOS. How was this verified/tested on macOS? When I build and run the latest Vim, pasting from clipboard gives me a W23 warning, and inspecting v:clipmethod shows "none", and from local investigation it was caused by this commit.
I'm also surprised that we don't have tests that make sure this functionality works. We should probably add something for this.
I'm working on a fix (along with other more minor improvements related to this PR) but just wanted to see if I'm missing something here.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Also, what's the point of the "gui" clip method? In what situation does it serve a purpose than the other methods? It basically calls the same functionality as the other methods. Is it just to make it so GVim will automatically swap to GUI when starting up, but otherwise the user may not want to initialize Wayland/X11? I don't think the documentation is describing the intent enough. If that's the case shouldn't the default have "gui,wayland,x11,other" rather than "wayland,x11,gui,other"?
I'm also struggling to understand this piece of code:
#if defined(FEAT_GUI) && defined(FEAT_WAYLAND) if (method == CLIPMETHOD_GUI) // We only interact with Wayland for the clipboard, we can just deinit // everything. wayland_uninit_connection(); #endif
If the clip method is "GUI" doesn't that mean the GUI is indeed initialized? Why are we de-initializing Wayland here?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
From looking into it, seems like #18574 tried to fix some ifdef issues, but I don't think that really changed anything regarding the broken nature of it. Can we revert these two changes until we can properly implement and test the feature? This blocks Vim from working properly on other platforms. Vim needs to work on Windows and macOS and changes that touch those functionality should have been tested on those platforms.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
From looking into it, seems like #18574 tried to fix some ifdef issues, but I don't think that really changed anything regarding the broken nature of it. @chrisbra Can we revert these two changes until we can properly implement and test the feature on the relevant platforms to make sure they work? This currently blocks Vim from working properly on other platforms.
I plan on refactoring the code to address these issues when I have time
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I plan on refactoring the code to address these issues when I have time, see this #18600 (comment). Essentially I will remove the "gui" and "other" values from clipmethod, as they were made for the clipboard feature to work via the clipmethod option. I'll move the clipboard provider code to not be under the clipboard feature to get rid of all these confusing ifdefs.
I commented on the linked issue, but just duplicating it here. I think what you said sounds good. The current "gui" / "other" are quite confusing and they seem to be from a consequence of the option being originally from just supporting Wayland clipboards (for example, "other" actually means the actual platform native method).
That said, if this isn't fixed in less than 1 day I think we should just revert it. Things should not remain broken. And it gives you more time to properly fix it rather than having to hack around it under time pressure.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
or @chrisbra how about this is the "last" to warn me sth?
I warned you before and I'm sorry that I have to resort to such drastic measures, but you’re now being blocked for 3 months.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()