Skip to content

Commit 67860ef

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.1.1857: Missing clipboard provider support
Problem: Missing clipboard provider support (lilydjwg) Solution: Add clipboard provider feature (Foxe Chen) fixes: #12419 closes: #17998 Signed-off-by: Foxe Chen <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 1a09f11 commit 67860ef

21 files changed

Lines changed: 851 additions & 22 deletions

runtime/doc/builtin.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*builtin.txt* For Vim version 9.1. Last change: 2025 Oct 13
1+
*builtin.txt* For Vim version 9.1. Last change: 2025 Oct 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -13061,6 +13061,7 @@ channel Compiled with support for |channel| and |job|
1306113061
cindent Compiled with 'cindent' support. (always true)
1306213062
clientserver Compiled with remote invocation support |clientserver|.
1306313063
clipboard Compiled with 'clipboard' support.
13064+
clipboard_provider Compiled with |clipboard-providers| support
1306413065
clipboard_working Compiled with 'clipboard' support and it can be used.
1306513066
cmdline_compl Compiled with |cmdline-completion| support.
1306613067
cmdline_hist Compiled with |cmdline-history| support.

runtime/doc/eval.txt

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 9.1. Last change: 2025 Oct 12
1+
*eval.txt* For Vim version 9.1. Last change: 2025 Oct 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -38,6 +38,7 @@ a remark is given.
3838
12. The sandbox |eval-sandbox|
3939
13. Textlock |textlock|
4040
14. Vim script library |vim-script-library|
41+
15. Clipboard providers |clipboard-providers|
4142

4243
Testing support is documented in |testing.txt|.
4344
Profiling is documented at |profiling|.
@@ -2251,6 +2252,11 @@ v:clipmethod The current method of accessing the clipboard that is being
22512252
unavailable.
22522253
See 'clipmethod' for more details.
22532254

2255+
*v:clipproviders*
2256+
v:clipproviders
2257+
A dictionary containing clipboard providers, see
2258+
|clipboard-providers| for more information.
2259+
22542260
*v:cmdarg* *cmdarg-variable*
22552261
v:cmdarg This variable is used for two purposes:
22562262
1. The extra arguments given to a file read/write command.
@@ -5263,5 +5269,133 @@ Usage: >vim
52635269
:call dist#vim9#Launch(<args>)
52645270
:Launch <app> <args>.
52655271
<
5272+
==============================================================================
5273+
15. Clipboard providers *clipboard-providers*
5274+
5275+
When Vim is compiled with the |+clipboard_provider| feature, which requires
5276+
the |+eval| feature, creating custom clipboards is possible. These providers
5277+
handle the "+" and "*" registers. Note that on non-Unix or non-VMS systems,
5278+
only the "*" register will be available for use.
5279+
5280+
To add a provider, add a new entry to the |v:clipproviders| dictionary, in the
5281+
format of: >
5282+
let v:clipproviders["name"] = {
5283+
\ "available": function("Available"),
5284+
\ "paste": {
5285+
\ '+': function("Paste"), " For the + register
5286+
\ '*': function("Paste"), " For the * register
5287+
\ },
5288+
\ "copy": {
5289+
\ '+': function("Copy"), " Same thing as above
5290+
\ '*': function("Copy"),
5291+
\ },
5292+
\ }
5293+
5294+
The key is the provider name, which should be used in 'clipmethod', for
5295+
example in the following example, you would add "name" to 'clipmethod' in
5296+
order to use it. >
5297+
set clipmethod=name,wayland,x11,gui
5298+
5299+
Each callback can either be a name of a function in a string, a |Funcref|, or
5300+
a |lambda| expression.
5301+
5302+
Note that these dictionary entries are optional, for example, if you don't
5303+
care about the "copy" functions, then you can simply exclude them. When Vim
5304+
yanks/copies something, then simply nothing will be done.
5305+
5306+
*clipboard-provider-available*
5307+
The "available" callback should return a string, which should contain which
5308+
clipboard registers are available. For example, if the "+" register is only
5309+
available, then the function would return "+", or if both "+" and "*" are
5310+
available, then return "+*".
5311+
5312+
*clipboard-provider-paste*
5313+
The "paste" callback takes a first argument which is the register being put
5314+
(string), and a second argument which is the type of access (string). It
5315+
should return either a tuple/list or string. If a tuple/list is returned, it
5316+
should have two elements:
5317+
- The register type conforming to |setreg()|.
5318+
- A list of strings
5319+
If the register type is an empty string, then the type is automatically
5320+
chosen, see |setreg()|. If a string is returned, then it can either be "clear"
5321+
or "previous". "clear" makes Vim clear the register, and "previous" makes Vim
5322+
use the previous register contents (or current depending on how you view it).
5323+
5324+
The second argument, the access type, can either be "explicit" or "implicit".
5325+
"explicit" means that the user is directly accessing the clipboard, such as
5326+
putting text, or calling |getreg()|; "implicit" means that the clipboard is
5327+
being accessed indirectly, such when |:registers| is called, or when an
5328+
unrelated operation causes Vim to access the clipboard.
5329+
5330+
This is useful since some operations in Vim implicity access the clipboard
5331+
indirectly. For example, if when you want to create a provider for the OSC52
5332+
command (accessing the clipboard via an escape code). Many terminals show a
5333+
confirmation if you want Vim to access the clipboard. This can be very
5334+
annoying with the terminal asking for permission everytime you do something
5335+
that accesses the clipboard behind the scenes. A good way to handle implicit
5336+
access is to return "previous", which leaves the register contents unchanged.
5337+
5338+
*clipboard-provider-copy*
5339+
The "copy" callback returns nothing, and takes the given arguments in order:
5340+
- The register being operated on
5341+
- The register type, conforming to |getregtype()|
5342+
- A list of strings to copy
5343+
5344+
The provider can do whatever it wants with the given information. This
5345+
function is called on every request to change the clipboard register(s).
5346+
5347+
*clipboard-provider-textlock*
5348+
In both the "paste" and "copy" callbacks, it is not allowed to change the
5349+
buffer text, see |textlock|.
5350+
5351+
*clipboard-provider-example*
5352+
Here is an example script that uses the clipboard provider feature through the
5353+
OSC52 command: >vim
5354+
5355+
func Available()
5356+
return "+"
5357+
endfunc
5358+
5359+
func Paste(reg, type)
5360+
" If implicit access, don't do anything
5361+
if a:type == "implicit"
5362+
return "previous"
5363+
endif
5364+
5365+
augroup OSC
5366+
autocmd!
5367+
autocmd TermResponseAll osc ++once call feedkeys("\<F30>", '!')
5368+
augroup END
5369+
5370+
" Send command
5371+
call echoraw("\<Esc>]52;c;?\<Esc>\\")
5372+
5373+
" Wait until autocmd is triggered
5374+
while getchar(-1) != "\<F30>"
5375+
endwhile
5376+
5377+
autocmd! OSC
5378+
5379+
" Extract the base64 stuff
5380+
let l:stuff = matchstr(v:termosc, '52;c;\zs[A-Za-z0-9+/=]\+')
5381+
5382+
return ("", blob2str(base64_decode(l:stuff)))
5383+
endfunc
5384+
5385+
func Copy(reg, type, lines)
5386+
call echoraw("\<Esc>]52;c;" ..
5387+
\ base64_encode(str2blob(a:lines)) .. "\<Esc>\\")
5388+
endfunc
5389+
let v:clipproviders["myosc"] = {
5390+
\ "available": function("Available"),
5391+
\ "paste": {
5392+
\ '+': function("Paste"),
5393+
\ },
5394+
\ "copy": {
5395+
\ '+': function("Copy"),
5396+
\ },
5397+
\ }
5398+
set clipmethod=myosc
52665399

5400+
<
52675401
vim:tw=78:ts=8:noet:ft=help:norl:

runtime/doc/options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,10 +1919,15 @@ A jump table for the options with a short description can be found at |Q_op|.
19191919
x11 X11 selections
19201920
gui GUI specific method
19211921
other Some other method
1922+
* Clipboard provider method
19221923

19231924
Note: "other" is used on systems without X11/Wayland, such as
19241925
MS-Windows or MacOS, when running Vim without the GUI.
19251926

1927+
Note that the name of the clipboard provider should be used when you
1928+
want to use a clipboard provider. See |clipboard-providers| for more
1929+
information.
1930+
19261931
The option value is a list of comma separated items. The list is
19271932
parsed left to right in order, and the first method that Vim
19281933
determines is available or is working is used as the actual method for

runtime/doc/tags

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,7 @@ $quote eval.txt /*$quote*
14111411
+cindent various.txt /*+cindent*
14121412
+clientserver various.txt /*+clientserver*
14131413
+clipboard various.txt /*+clipboard*
1414+
+clipboard_provider various.txt /*+clipboard_provider*
14141415
+clipboard_working various.txt /*+clipboard_working*
14151416
+cmd editing.txt /*+cmd*
14161417
+cmdline_compl various.txt /*+cmdline_compl*
@@ -6691,6 +6692,12 @@ clipboard-autoselectml options.txt /*clipboard-autoselectml*
66916692
clipboard-autoselectplus options.txt /*clipboard-autoselectplus*
66926693
clipboard-exclude options.txt /*clipboard-exclude*
66936694
clipboard-html options.txt /*clipboard-html*
6695+
clipboard-provider-available eval.txt /*clipboard-provider-available*
6696+
clipboard-provider-copy eval.txt /*clipboard-provider-copy*
6697+
clipboard-provider-example eval.txt /*clipboard-provider-example*
6698+
clipboard-provider-paste eval.txt /*clipboard-provider-paste*
6699+
clipboard-provider-textlock eval.txt /*clipboard-provider-textlock*
6700+
clipboard-providers eval.txt /*clipboard-providers*
66946701
clipboard-unnamed options.txt /*clipboard-unnamed*
66956702
clipboard-unnamedplus options.txt /*clipboard-unnamedplus*
66966703
clojure-indent indent.txt /*clojure-indent*
@@ -11254,6 +11261,7 @@ v:char eval.txt /*v:char*
1125411261
v:charconvert_from eval.txt /*v:charconvert_from*
1125511262
v:charconvert_to eval.txt /*v:charconvert_to*
1125611263
v:clipmethod eval.txt /*v:clipmethod*
11264+
v:clipproviders eval.txt /*v:clipproviders*
1125711265
v:cmdarg eval.txt /*v:cmdarg*
1125811266
v:cmdbang eval.txt /*v:cmdbang*
1125911267
v:collate eval.txt /*v:collate*

runtime/doc/various.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*various.txt* For Vim version 9.1. Last change: 2025 Oct 12
1+
*various.txt* For Vim version 9.1. Last change: 2025 Oct 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -378,6 +378,7 @@ m *+channel* inter process communication |channel|
378378
T *+cindent* 'cindent', C indenting; Always enabled
379379
N *+clientserver* Unix and Win32: Remote invocation |clientserver|
380380
*+clipboard* |clipboard| support compiled-in
381+
N *+clipboard_provider* |clipboard-providers| support compiled-in
381382
*+clipboard_working* |clipboard| support compiled-in and working
382383
T *+cmdline_compl* command line completion |cmdline-completion|
383384
T *+cmdline_hist* command line history |cmdline-history|
@@ -807,7 +808,10 @@ K Run a program to lookup the keyword under the
807808
:clip[reset] Attempts to choose a new method for accessing the
808809
clipboard, using the 'clipmethod' option. This is
809810
useful when the current method has become unavailable,
810-
and you want to try using another method.
811+
and you want to try using another method. If the
812+
|+clipboard_provider| feature is being used, this
813+
command should be called after the availability of one
814+
of the clipboard registers changes.
811815
{only available when compiled with the |+clipboard|
812816
feature}
813817

runtime/doc/version9.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Oct 12
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Oct 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41653,6 +41653,8 @@ Other new features ~
4165341653

4165441654
- |items()| function now supports Blob.
4165541655

41656+
- |clipboard-providers| support.
41657+
4165641658
*changed-9.2*
4165741659
Changed~
4165841660
-------
@@ -41900,13 +41902,29 @@ Options: ~
4190041902
compositor
4190141903

4190241904
Vim Variables: ~
41905+
|v:clipmethod| The current 'clipmethod'.
41906+
|v:clipproviders| A dictionary containing clipboard providers
41907+
information.
41908+
|v:stacktrace| The most recent caught exception.
41909+
|v:t_enumvalue| Value of |enumvalue|.
41910+
|v:t_enum| Value of |enum| type.
41911+
|v:t_tuple| Value of |Tuple| type.
4190341912
|v:termda1| The escape sequence returned for the primary device
4190441913
attribute query (DA1).
41914+
|v:termosc| The most recent received OSC response.
41915+
|v:wayland_display| The name of the Wayland display Vim is connected to.
4190541916

4190641917
Vim Arguments: ~
4190741918
|-Y| Do not connect to the |wayland| compositor.
4190841919
|--clientserver| Specify backend for clientserver functionality.
4190941920

41921+
Configure Switches: ~
41922+
--with-wayland Enable the |wayland| feature.
41923+
--enable-wayland-focus-steal Enable the |wayland-focus-steal| feature.
41924+
--enable-socketserver Enable the |socketserver-clientserver|
41925+
feature.
41926+
--enable-clipboard-provider Enable the |clipboard-providers| feature.
41927+
4191041928

4191141929
==============================================================================
4191241930
INCOMPATIBLE CHANGES *incompatible-9.2*

runtime/syntax/vim.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Vim script
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <[email protected]>
5-
" Last Change: 2025 Oct 11
5+
" Last Change: 2025 Oct 14
66
" Former Maintainer: Charles E. Campbell
77

88
" DO NOT CHANGE DIRECTLY.
@@ -166,7 +166,7 @@ syn keyword vimFuncName contained win_execute win_findbuf win_getid win_gettype
166166
" Predefined variable names {{{2
167167
" GEN_SYN_VIM: vimVarName, START_STR='syn keyword vimVimVarName contained', END_STR=''
168168
syn keyword vimVimVarName contained count count1 prevcount errmsg warningmsg statusmsg shell_error this_session version lnum termresponse fname lang lc_time ctype charconvert_from charconvert_to fname_in fname_out fname_new fname_diff cmdarg foldstart foldend folddashes foldlevel progname servername dying exception throwpoint register cmdbang insertmode val key profiling fcs_reason fcs_choice beval_bufnr beval_winnr beval_winid beval_lnum beval_col beval_text scrollstart swapname swapchoice swapcommand char mouse_win mouse_winid mouse_lnum mouse_col operator searchforward hlsearch oldfiles windowid progpath completed_item option_new option_old option_oldlocal option_oldglobal option_command option_type errors false true none null numbermax numbermin numbersize
169-
syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1 termosc
169+
syn keyword vimVimVarName contained vim_did_enter testing t_number t_string t_func t_list t_dict t_float t_bool t_none t_job t_channel t_blob t_class t_object termrfgresp termrbgresp termu7resp termstyleresp termblinkresp event versionlong echospace argv collate exiting colornames sizeofint sizeoflong sizeofpointer maxcol python3_version t_typealias t_enum t_enumvalue stacktrace t_tuple wayland_display clipmethod termda1 termosc clipproviders
170170

171171
"--- syntax here and above generated by runtime/syntax/generator/gen_syntax_vim.vim ---
172172

src/auto/configure

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ enable_arabic
857857
enable_farsi
858858
enable_xim
859859
enable_fontset
860+
enable_clipboard_provider
860861
with_wayland
861862
enable_wayland_focus_steal
862863
with_x
@@ -1539,6 +1540,7 @@ Optional Features:
15391540
--disable-farsi Deprecated.
15401541
--enable-xim Include XIM input support.
15411542
--enable-fontset Include X fontset output support.
1543+
--enable-clipboard-provider Include clipboard provider support.
15421544
--enable-wayland-focus-steal
15431545
Include focus stealing support for Wayland
15441546
clipboard.
@@ -9208,6 +9210,35 @@ fi
92089210
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_fontset" >&5
92099211
printf "%s\n" "$enable_fontset" >&6; }
92109212

9213+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking --enable-clipboard-provider" >&5
9214+
printf %s "checking --enable-clipboard-provider... " >&6; }
9215+
# Check whether --enable-clipboard-provider was given.
9216+
if test ${enable_clipboard_provider+y}
9217+
then :
9218+
enableval=$enable_clipboard_provider; enable_clipboard_provider=$enableval
9219+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5
9220+
printf "%s\n" "$enableval" >&6; }
9221+
else case e in #(
9222+
e) if test "x$features" = xtiny
9223+
then :
9224+
enable_clipboard_provider="no"
9225+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cannot use clipboard provider with tiny features" >&5
9226+
printf "%s\n" "cannot use clipboard provider with tiny features" >&6; }
9227+
else case e in #(
9228+
e) enable_clipboard_provider="yes"
9229+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9230+
printf "%s\n" "yes" >&6; } ;;
9231+
esac
9232+
fi ;;
9233+
esac
9234+
fi
9235+
9236+
if test "$enable_clipboard_provider" = "yes"; then
9237+
printf "%s\n" "#define FEAT_CLIPBOARD_PROVIDER 1" >>confdefs.h
9238+
9239+
fi
9240+
9241+
92119242
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if shm_open is available" >&5
92129243
printf %s "checking if shm_open is available... " >&6; }
92139244
cppflags_save=$CPPFLAGS

0 commit comments

Comments
 (0)