From 36f564e4755a03fb66a2038972aa88ae30b7c5ab Mon Sep 17 00:00:00 2001 From: Foxe Chen Date: Sat, 25 Oct 2025 07:39:26 -0400 Subject: [PATCH] revert clipboard changes --- runtime/doc/builtin.txt | 3 +- runtime/doc/eval.txt | 143 +---- runtime/doc/options.txt | 29 +- runtime/doc/tags | 10 - runtime/doc/various.txt | 14 +- runtime/doc/version9.txt | 20 +- runtime/doc/wayland.txt | 6 +- runtime/syntax/vim.vim | 4 +- src/auto/configure | 53 +- src/clipboard.c | 692 +++++------------------- src/config.h.in | 3 - src/configure.ac | 15 - src/evalfunc.c | 32 +- src/evalvars.c | 3 +- src/feature.h | 13 - src/globals.h | 16 - src/gui.c | 2 +- src/optiondefs.h | 6 +- src/optionstr.c | 2 +- src/proto/evalfunc.pro | 1 - src/register.c | 4 - src/testdir/Make_all.mak | 2 - src/testdir/test_clipboard_provider.vim | 172 ------ src/testdir/test_clipmethod.vim | 35 +- src/testdir/test_eval_stuff.vim | 46 -- src/testdir/test_options.vim | 2 +- src/version.c | 21 - src/vim.h | 6 +- 28 files changed, 197 insertions(+), 1158 deletions(-) delete mode 100644 src/testdir/test_clipboard_provider.vim diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 7389a86b9d69d7..fd88b71a903c72 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -1,4 +1,4 @@ -*builtin.txt* For Vim version 9.1. Last change: 2025 Oct 14 +*builtin.txt* For Vim version 9.1. Last change: 2025 Oct 13 VIM REFERENCE MANUAL by Bram Moolenaar @@ -13061,7 +13061,6 @@ channel Compiled with support for |channel| and |job| cindent Compiled with 'cindent' support. (always true) clientserver Compiled with remote invocation support |clientserver|. clipboard Compiled with 'clipboard' support. -clipboard_provider Compiled with |clipboard-providers| support clipboard_working Compiled with 'clipboard' support and it can be used. cmdline_compl Compiled with |cmdline-completion| support. cmdline_hist Compiled with |cmdline-history| support. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 0f81f4d6b9e55b..04c9c88f0a4ffe 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 9.1. Last change: 2025 Oct 18 +*eval.txt* For Vim version 9.1. Last change: 2025 Oct 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -38,7 +38,6 @@ a remark is given. 12. The sandbox |eval-sandbox| 13. Textlock |textlock| 14. Vim script library |vim-script-library| -15. Clipboard providers |clipboard-providers| Testing support is documented in |testing.txt|. Profiling is documented at |profiling|. @@ -2246,17 +2245,10 @@ v:clipmethod The current method of accessing the clipboard that is being used. Can either have the value of: wayland The Wayland protocol is being used. x11 X11 selections are being used. - gui GUI specific method is being used - other Some other method is being used - none Clipboard functionality is disabled or - unavailable. + none The above methods are unavailable or + cannot be used. See 'clipmethod' for more details. - *v:clipproviders* -v:clipproviders - A dictionary containing clipboard providers, see - |clipboard-providers| for more information. - *v:cmdarg* *cmdarg-variable* v:cmdarg This variable is used for two purposes: 1. The extra arguments given to a file read/write command. @@ -5269,134 +5261,5 @@ Usage: >vim :call dist#vim9#Launch() :Launch . < -============================================================================== -15. Clipboard providers *clipboard-providers* - -When Vim is compiled with the |+clipboard_provider| feature, which requires -the |+eval| feature, creating custom clipboards is possible. These providers -handle the "+" and "*" registers. Note that if |+wayland_clipboard| or -|+xterm_clipboard| features are not compiled in, then the "+" register will -not be available. - -To add a provider, add a new entry to the |v:clipproviders| dictionary, in the -format of: > - let v:clipproviders["name"] = { - \ "available": function("Available"), - \ "paste": { - \ '+': function("Paste"), " For the + register - \ '*': function("Paste"), " For the * register - \ }, - \ "copy": { - \ '+': function("Copy"), " Same thing as above - \ '*': function("Copy"), - \ }, - \ } - -The key is the provider name, which should be used in 'clipmethod', for -example in the following example, you would add "name" to 'clipmethod' in -order to use it. > - set clipmethod=name,wayland,x11,gui - -Each callback can either be a name of a function in a string, a |Funcref|, or -a |lambda| expression. - -Note that these dictionary entries are optional, for example, if you don't -care about the "copy" functions, then you can simply exclude them. When Vim -yanks/copies something, then simply nothing will be done. - - *clipboard-provider-available* -The "available" callback should return a string, which should contain which -clipboard registers are available. For example, if the "+" register is only -available, then the function would return "+", or if both "+" and "*" are -available, then return "+*". - - *clipboard-provider-paste* -The "paste" callback takes a first argument which is the register being put -(string), and a second argument which is the type of access (string). It -should return either a tuple/list or string. If a tuple/list is returned, it -should have two elements: - - The register type conforming to |setreg()|. - - A list of strings -If the register type is an empty string, then the type is automatically -chosen, see |setreg()|. If a string is returned, then it can either be "clear" -or "previous". "clear" makes Vim clear the register, and "previous" makes Vim -use the previous register contents (or current depending on how you view it). - -The second argument, the access type, can either be "explicit" or "implicit". -"explicit" means that the user is directly accessing the clipboard, such as -putting text, or calling |getreg()|; "implicit" means that the clipboard is -being accessed indirectly, such when |:registers| is called, or when an -unrelated operation causes Vim to access the clipboard. - -This is useful since some operations in Vim implicity access the clipboard -indirectly. For example, if when you want to create a provider for the OSC52 -command (accessing the clipboard via an escape code). Many terminals show a -confirmation if you want Vim to access the clipboard. This can be very -annoying with the terminal asking for permission everytime you do something -that accesses the clipboard behind the scenes. A good way to handle implicit -access is to return "previous", which leaves the register contents unchanged. - - *clipboard-provider-copy* -The "copy" callback returns nothing, and takes the given arguments in order: - - The register being operated on - - The register type, conforming to |getregtype()| - - A list of strings to copy - -The provider can do whatever it wants with the given information. This -function is called on every request to change the clipboard register(s). - - *clipboard-provider-textlock* -In both the "paste" and "copy" callbacks, it is not allowed to change the -buffer text, see |textlock|. - - *clipboard-provider-example* -Here is an example script that uses the clipboard provider feature through the -OSC52 command: >vim - - func Available() - return "*" - endfunc - - func Paste(reg, type) - " If implicit access, don't do anything - if a:type == "implicit" - return "previous" - endif - augroup OSC - autocmd! - autocmd TermResponseAll osc ++once call feedkeys("\", '!') - augroup END - - " Send command - call echoraw("\]52;;?\\\") - - " Wait until autocmd is triggered - while getchar(-1) != "\" - endwhile - - autocmd! OSC - - " Extract the base64 stuff - let l:stuff = matchstr(v:termosc, '52;.\+;\zs[A-Za-z0-9+/=]\+') - - return ("", blob2str(base64_decode(l:stuff))) - endfunc - - func Copy(reg, type, lines) - call echoraw("\]52;c;" .. - \ base64_encode(str2blob(a:lines)) .. "\\\") - endfunc - let v:clipproviders["myosc"] = { - \ "available": function("Available"), - \ "paste": { - \ '*': function("Paste") - \ }, - \ "copy": { - \ '*': function("Copy") - \ }, - \ } - set clipmethod=myosc - -< vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 798e50471f933a..6e3d56f8bc14f3 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1907,35 +1907,30 @@ A jump table for the options with a short description can be found at |Q_op|. {pattern}, this must be the last entry. *'clipmethod'* *'cpm'* -'clipmethod' 'cpm' string (default for Unix: "wayland,x11,gui,other", - for VMS: "x11,gui,other", - otherwise: "gui,other") +'clipmethod' 'cpm' string (default for Unix: "wayland,x11", + for VMS: "x11", + otherwise: "") global - {only when the |+clipboard| feature is included} + {only when the |+xterm_clipboard| or + |+wayland_clipboard| features are included} Specifies which method of accessing the system clipboard is used, depending on which method works first or is available. Supported methods are: wayland Wayland selections x11 X11 selections - gui GUI specific method - other Some other method - * Clipboard provider method - 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 - information. + Note: This option is ignored when either the GUI is running or if Vim + is run on a system without Wayland or X11 support, such as Windows or + macOS. The GUI or system way of accessing the clipboard is always + used instead. The option value is a list of comma separated items. The list is parsed left to right in order, and the first method that Vim determines is available or is working is used as the actual method for - accessing the clipboard. Setting this option to an empty value - disables the clipboard functionality on all systems. + accessing the clipboard. - The current method that is being used can be found in the - |v:clipmethod| variable. + The current method that is being used can be found in the |v:clipmethod| + variable. *'cmdheight'* *'ch'* 'cmdheight' 'ch' number (default 1) diff --git a/runtime/doc/tags b/runtime/doc/tags index df78fc45fc2e94..f53d05631f7bcb 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -1411,9 +1411,6 @@ $quote eval.txt /*$quote* +cindent various.txt /*+cindent* +clientserver various.txt /*+clientserver* +clipboard various.txt /*+clipboard* -+clipboard_plus_avail various.txt /*+clipboard_plus_avail* -+clipboard_provider various.txt /*+clipboard_provider* -+clipboard_star_avail various.txt /*+clipboard_star_avail* +clipboard_working various.txt /*+clipboard_working* +cmd editing.txt /*+cmd* +cmdline_compl various.txt /*+cmdline_compl* @@ -6694,12 +6691,6 @@ clipboard-autoselectml options.txt /*clipboard-autoselectml* clipboard-autoselectplus options.txt /*clipboard-autoselectplus* clipboard-exclude options.txt /*clipboard-exclude* clipboard-html options.txt /*clipboard-html* -clipboard-provider-available eval.txt /*clipboard-provider-available* -clipboard-provider-copy eval.txt /*clipboard-provider-copy* -clipboard-provider-example eval.txt /*clipboard-provider-example* -clipboard-provider-paste eval.txt /*clipboard-provider-paste* -clipboard-provider-textlock eval.txt /*clipboard-provider-textlock* -clipboard-providers eval.txt /*clipboard-providers* clipboard-unnamed options.txt /*clipboard-unnamed* clipboard-unnamedplus options.txt /*clipboard-unnamedplus* clojure-indent indent.txt /*clojure-indent* @@ -11264,7 +11255,6 @@ v:char eval.txt /*v:char* v:charconvert_from eval.txt /*v:charconvert_from* v:charconvert_to eval.txt /*v:charconvert_to* v:clipmethod eval.txt /*v:clipmethod* -v:clipproviders eval.txt /*v:clipproviders* v:cmdarg eval.txt /*v:cmdarg* v:cmdbang eval.txt /*v:cmdbang* v:collate eval.txt /*v:collate* diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index c7ed02764bb1fe..fa9be58a113e63 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -1,4 +1,4 @@ -*various.txt* For Vim version 9.1. Last change: 2025 Oct 16 +*various.txt* For Vim version 9.1. Last change: 2025 Oct 12 VIM REFERENCE MANUAL by Bram Moolenaar @@ -378,14 +378,7 @@ m *+channel* inter process communication |channel| T *+cindent* 'cindent', C indenting; Always enabled N *+clientserver* Unix and Win32: Remote invocation |clientserver| *+clipboard* |clipboard| support compiled-in -N *+clipboard_provider* |clipboard-providers| support compiled-in *+clipboard_working* |clipboard| support compiled-in and working - *+clipboard_star_avail* - |clipboard| support compiled-in and star "*" register - available - *+clipboard_plus_avail* - |clipboard| support compiled-in and separate plus "+" - register available T *+cmdline_compl* command line completion |cmdline-completion| T *+cmdline_hist* command line history |cmdline-history| T *+cmdline_info* 'showcmd' and 'ruler'; Always enabled since @@ -814,10 +807,7 @@ K Run a program to lookup the keyword under the :clip[reset] Attempts to choose a new method for accessing the clipboard, using the 'clipmethod' option. This is useful when the current method has become unavailable, - and you want to try using another method. If the - |+clipboard_provider| feature is being used, this - command should be called after the availability of one - of the clipboard registers changes. + and you want to try using another method. {only available when compiled with the |+clipboard| feature} diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt index b2a1f96b26bea2..ef7762253753b0 100644 --- a/runtime/doc/version9.txt +++ b/runtime/doc/version9.txt @@ -1,4 +1,4 @@ -*version9.txt* For Vim version 9.1. Last change: 2025 Oct 14 +*version9.txt* For Vim version 9.1. Last change: 2025 Oct 12 VIM REFERENCE MANUAL by Bram Moolenaar @@ -41653,8 +41653,6 @@ Other new features ~ - |items()| function now supports Blob. -- |clipboard-providers| support. - *changed-9.2* Changed~ ------- @@ -41902,29 +41900,13 @@ Options: ~ compositor Vim Variables: ~ -|v:clipmethod| The current 'clipmethod'. -|v:clipproviders| A dictionary containing clipboard providers - information. -|v:stacktrace| The most recent caught exception. -|v:t_enumvalue| Value of |enumvalue|. -|v:t_enum| Value of |enum| type. -|v:t_tuple| Value of |Tuple| type. |v:termda1| The escape sequence returned for the primary device attribute query (DA1). -|v:termosc| The most recent received OSC response. -|v:wayland_display| The name of the Wayland display Vim is connected to. Vim Arguments: ~ |-Y| Do not connect to the |wayland| compositor. |--clientserver| Specify backend for clientserver functionality. -Configure Switches: ~ ---with-wayland Enable the |wayland| feature. ---enable-wayland-focus-steal Enable the |wayland-focus-steal| feature. ---enable-socketserver Enable the |socketserver-clientserver| - feature. ---enable-clipboard-provider Enable the |clipboard-providers| feature. - ============================================================================== INCOMPATIBLE CHANGES *incompatible-9.2* diff --git a/runtime/doc/wayland.txt b/runtime/doc/wayland.txt index da28657a1e6b23..d00d9b825830aa 100644 --- a/runtime/doc/wayland.txt +++ b/runtime/doc/wayland.txt @@ -1,4 +1,4 @@ -*wayland.txt* For Vim version 9.1. Last change: 2025 Oct 12 +*wayland.txt* For Vim version 9.1. Last change: 2025 Oct 25 VIM REFERENCE MANUAL by Bram Moolenaar @@ -22,7 +22,7 @@ multiple Wayland seats in the same Wayland session. See |gui-wayland|. Please note that when using the GUI, Vim uses the toolkit such as GTK for accessing the clipboard, and does not access the clipboard though Wayland. You can check this though the |v:clipmethod| variable, which -should equal to "gui" when running the GUI. +should equal to "none" when running the GUI. Wayland commands: *:wlrestore* *:wl* @@ -73,7 +73,7 @@ selections, see |wayland-primary-selection| for more details. *wayland-persist* If you use X11 cut buffers, no such things exist on Wayland. Instead to emulate such functionality, a separate clipboard manager must be used in order -to persist selection data when a Wayland client exits. +to persist selection data when a Wayland client exists. *wayland-and-x11* If your version of Vim comes compiled with both X11 and Wayland support, then diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index bd2458f5b12b1f..89940ab303adb7 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -2,7 +2,7 @@ " Language: Vim script " Maintainer: Hirohito Higashi " Doug Kearns -" Last Change: 2025 Oct 14 +" Last Change: 2025 Oct 11 " Former Maintainer: Charles E. Campbell " DO NOT CHANGE DIRECTLY. @@ -166,7 +166,7 @@ syn keyword vimFuncName contained win_execute win_findbuf win_getid win_gettype " Predefined variable names {{{2 " GEN_SYN_VIM: vimVarName, START_STR='syn keyword vimVimVarName contained', END_STR='' 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 -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 +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 "--- syntax here and above generated by runtime/syntax/generator/gen_syntax_vim.vim --- diff --git a/src/auto/configure b/src/auto/configure index 525584d1daf751..613a18ee908323 100755 --- a/src/auto/configure +++ b/src/auto/configure @@ -857,7 +857,6 @@ enable_arabic enable_farsi enable_xim enable_fontset -enable_clipboard_provider with_wayland enable_wayland_focus_steal with_x @@ -1540,7 +1539,6 @@ Optional Features: --disable-farsi Deprecated. --enable-xim Include XIM input support. --enable-fontset Include X fontset output support. - --enable-clipboard-provider Include clipboard provider support. --enable-wayland-focus-steal Include focus stealing support for Wayland clipboard. @@ -9210,35 +9208,6 @@ fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_fontset" >&5 printf "%s\n" "$enable_fontset" >&6; } -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking --enable-clipboard-provider" >&5 -printf %s "checking --enable-clipboard-provider... " >&6; } -# Check whether --enable-clipboard-provider was given. -if test ${enable_clipboard_provider+y} -then : - enableval=$enable_clipboard_provider; enable_clipboard_provider=$enableval - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enableval" >&5 -printf "%s\n" "$enableval" >&6; } -else case e in #( - e) if test "x$features" = xtiny -then : - enable_clipboard_provider="no" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cannot use clipboard provider with tiny features" >&5 -printf "%s\n" "cannot use clipboard provider with tiny features" >&6; } -else case e in #( - e) enable_clipboard_provider="yes" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -printf "%s\n" "yes" >&6; } ;; -esac -fi ;; -esac -fi - -if test "$enable_clipboard_provider" = "yes"; then - printf "%s\n" "#define FEAT_CLIPBOARD_PROVIDER 1" >>confdefs.h - -fi - - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if shm_open is available" >&5 printf %s "checking if shm_open is available... " >&6; } cppflags_save=$CPPFLAGS @@ -14569,18 +14538,18 @@ then : fi if test "$enable_largefile,$enable_year2038" != no,no then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CPPFLAGS option for large files" >&5 -printf %s "checking for $CPPFLAGS option for large files... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable large file support" >&5 +printf %s "checking for $CC option to enable large file support... " >&6; } if test ${ac_cv_sys_largefile_opts+y} then : printf %s "(cached) " >&6 else case e in #( - e) ac_save_CPPFLAGS=$CPPFLAGS + e) ac_save_CC="$CC" ac_opt_found=no - for ac_opt in "none needed" "-D_FILE_OFFSET_BITS=64" "-D_LARGE_FILES=1"; do + for ac_opt in "none needed" "-D_FILE_OFFSET_BITS=64" "-D_LARGE_FILES=1" "-n32"; do if test x"$ac_opt" != x"none needed" then : - CPPFLAGS="$ac_save_CPPFLAGS $ac_opt" + CC="$ac_save_CC $ac_opt" fi cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14609,12 +14578,12 @@ then : if test x"$ac_opt" = x"none needed" then : # GNU/Linux s390x and alpha need _FILE_OFFSET_BITS=64 for wide ino_t. - CPPFLAGS="$CPPFLAGS -DFTYPE=ino_t" + CC="$CC -DFTYPE=ino_t" if ac_fn_c_try_compile "$LINENO" then : else case e in #( - e) CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64" + e) CC="$CC -D_FILE_OFFSET_BITS=64" if ac_fn_c_try_compile "$LINENO" then : ac_opt='-D_FILE_OFFSET_BITS=64' @@ -14630,7 +14599,7 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext test $ac_opt_found = no || break done - CPPFLAGS=$ac_save_CPPFLAGS + CC="$ac_save_CC" test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected" ;; esac @@ -14654,14 +14623,16 @@ printf "%s\n" "#define _FILE_OFFSET_BITS 64" >>confdefs.h printf "%s\n" "#define _LARGE_FILES 1" >>confdefs.h ;; #( + "-n32") : + CC="$CC -n32" ;; #( *) : as_fn_error $? "internal error: bad value for \$ac_cv_sys_largefile_opts" "$LINENO" 5 ;; esac if test "$enable_year2038" != no then : - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CPPFLAGS option for timestamps after 2038" >&5 -printf %s "checking for $CPPFLAGS option for timestamps after 2038... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option for timestamps after 2038" >&5 +printf %s "checking for $CC option for timestamps after 2038... " >&6; } if test ${ac_cv_sys_year2038_opts+y} then : printf %s "(cached) " >&6 diff --git a/src/clipboard.c b/src/clipboard.c index e5113866903727..13fcae6060fe27 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -134,12 +134,6 @@ static bool clip_wl_owner_exists(Clipboard_T *cbd); #endif // FEAT_WAYLAND_CLIPBOARD -#ifdef FEAT_CLIPBOARD_PROVIDER -static int clip_provider_is_available(Clipboard_T *cbd, char_u *provider); -static void clip_provider_set_selection(Clipboard_T *cbd, char_u *provider); -static void clip_provider_request_selection(Clipboard_T *cbd, char_u *provider); -#endif - /* * Selection stuff using Visual mode, for cutting and pasting text to other * windows. @@ -237,36 +231,32 @@ clip_update_selection(Clipboard_T *clip) } static int -clip_gen_own_selection(Clipboard_T *cbd UNUSED) +clip_gen_own_selection(Clipboard_T *cbd) { - if (clipmethod == CLIPMETHOD_GUI) - { -#ifdef FEAT_GUI - if (gui.in_use) - return clip_mch_own_selection(cbd); -#endif - } - else if (clipmethod == CLIPMETHOD_WAYLAND) +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD) +# ifdef FEAT_GUI + if (gui.in_use) + return clip_mch_own_selection(cbd); + else +# endif { + if (clipmethod == CLIPMETHOD_WAYLAND) + { #ifdef FEAT_WAYLAND_CLIPBOARD - return clip_wl_own_selection(cbd); + return clip_wl_own_selection(cbd); #endif - } - else if (clipmethod == CLIPMETHOD_X11) - { + } + else if (clipmethod == CLIPMETHOD_X11) + { #ifdef FEAT_XCLIPBOARD - return clip_xterm_own_selection(cbd); -#endif - } - else if (clipmethod == CLIPMETHOD_OTHER) - { -#if (!defined(FEAT_XCLIPBOARD) && !defined(FEAT_WAYLAND_CLIPBOARD) \ - && !defined(FEAT_CLIPBOARD_PROVIDER)) \ - || (!(defined(UNIX) || defined(MACOS_X)) && defined(FEAT_CLIPBOARD_PROVIDER)) - return clip_mch_own_selection(cbd); + return clip_xterm_own_selection(cbd); #endif + } } return FAIL; +#else + return clip_mch_own_selection(cbd); +#endif } void @@ -306,35 +296,31 @@ clip_own_selection(Clipboard_T *cbd) } static void -clip_gen_lose_selection(Clipboard_T *cbd UNUSED) +clip_gen_lose_selection(Clipboard_T *cbd) { - if (clipmethod == CLIPMETHOD_GUI) - { -#ifdef FEAT_GUI - if (gui.in_use) - clip_mch_lose_selection(cbd); -#endif - } - else if (clipmethod == CLIPMETHOD_WAYLAND) +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD) +# ifdef FEAT_GUI + if (gui.in_use) + clip_mch_lose_selection(cbd); + else +# endif { + if (clipmethod == CLIPMETHOD_WAYLAND) + { #ifdef FEAT_WAYLAND_CLIPBOARD - clip_wl_lose_selection(cbd); + clip_wl_lose_selection(cbd); #endif - } - else if (clipmethod == CLIPMETHOD_X11) - { + } + else if (clipmethod == CLIPMETHOD_X11) + { #ifdef FEAT_XCLIPBOARD - clip_xterm_lose_selection(cbd); + clip_xterm_lose_selection(cbd); #endif + } } - else if (clipmethod == CLIPMETHOD_OTHER) - { -#if (!defined(FEAT_XCLIPBOARD) && !defined(FEAT_WAYLAND_CLIPBOARD) \ - && !defined(FEAT_CLIPBOARD_PROVIDER)) \ - || (!(defined(UNIX) || defined(MACOS_X)) && defined(FEAT_CLIPBOARD_PROVIDER)) - clip_mch_lose_selection(cbd); +#else + clip_mch_lose_selection(cbd); #endif - } } void @@ -1360,77 +1346,57 @@ clip_gen_set_selection(Clipboard_T *cbd) return; } } - if (clipmethod == CLIPMETHOD_GUI) - { -#ifdef FEAT_GUI - if (gui.in_use) - clip_mch_set_selection(cbd); -#endif - } - else if (clipmethod == CLIPMETHOD_WAYLAND) +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD) +# ifdef FEAT_GUI + if (gui.in_use) + clip_mch_set_selection(cbd); + else +# endif { + if (clipmethod == CLIPMETHOD_WAYLAND) + { #ifdef FEAT_WAYLAND_CLIPBOARD - clip_wl_set_selection(cbd); + clip_wl_set_selection(cbd); #endif - } - else if (clipmethod == CLIPMETHOD_X11) - { + } + else if (clipmethod == CLIPMETHOD_X11) + { #ifdef FEAT_XCLIPBOARD - clip_xterm_set_selection(cbd); -#endif - } - else if (clipmethod == CLIPMETHOD_OTHER) - { -#if (!defined(FEAT_XCLIPBOARD) && !defined(FEAT_WAYLAND_CLIPBOARD) \ - && !defined(FEAT_CLIPBOARD_PROVIDER)) \ - || (!(defined(UNIX) || defined(MACOS_X)) && defined(FEAT_CLIPBOARD_PROVIDER)) - clip_mch_set_selection(cbd); + clip_xterm_set_selection(cbd); #endif + } } - else if (clipmethod == CLIPMETHOD_PROVIDER) - { -#ifdef FEAT_CLIPBOARD_PROVIDER - clip_provider_set_selection(cbd, clipprovider_name); +#else + clip_mch_set_selection(cbd); #endif - } } static void -clip_gen_request_selection(Clipboard_T *cbd UNUSED) +clip_gen_request_selection(Clipboard_T *cbd) { - if (clipmethod == CLIPMETHOD_GUI) - { +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD) # ifdef FEAT_GUI - if (gui.in_use) - clip_mch_request_selection(cbd); + if (gui.in_use) + clip_mch_request_selection(cbd); + else # endif - } - else if (clipmethod == CLIPMETHOD_WAYLAND) { + if (clipmethod == CLIPMETHOD_WAYLAND) + { #ifdef FEAT_WAYLAND_CLIPBOARD - clip_wl_request_selection(cbd); + clip_wl_request_selection(cbd); #endif - } - else if (clipmethod == CLIPMETHOD_X11) - { + } + else if (clipmethod == CLIPMETHOD_X11) + { #ifdef FEAT_XCLIPBOARD - clip_xterm_request_selection(cbd); -#endif - } - else if (clipmethod == CLIPMETHOD_OTHER) - { -#if (!defined(FEAT_XCLIPBOARD) && !defined(FEAT_WAYLAND_CLIPBOARD) \ - && !defined(FEAT_CLIPBOARD_PROVIDER)) \ - || (!(defined(UNIX) || defined(MACOS_X)) && defined(FEAT_CLIPBOARD_PROVIDER)) - clip_mch_request_selection(cbd); + clip_xterm_request_selection(cbd); #endif + } } - else if (clipmethod == CLIPMETHOD_PROVIDER) - { -#ifdef FEAT_CLIPBOARD_PROVIDER - clip_provider_request_selection(cbd, clipprovider_name); +#else + clip_mch_request_selection(cbd); #endif - } } #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) && defined(USE_SYSTEM)) \ @@ -1447,28 +1413,31 @@ clip_x11_owner_exists(Clipboard_T *cbd) int clip_gen_owner_exists(Clipboard_T *cbd UNUSED) { - if (clipmethod == CLIPMETHOD_OTHER) - { +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD) # ifdef FEAT_GUI_GTK - if (gui.in_use) - return clip_gtk_owner_exists(cbd); -# endif - } - else if (clipmethod == CLIPMETHOD_WAYLAND) - { -# ifdef FEAT_WAYLAND_CLIPBOARD - return clip_wl_owner_exists(cbd); + if (gui.in_use) + return clip_gtk_owner_exists(cbd); + else # endif - } - else if (clipmethod == CLIPMETHOD_X11) { -# ifdef FEAT_XCLIPBOARD - return clip_x11_owner_exists(cbd); -# endif + if (clipmethod == CLIPMETHOD_WAYLAND) + { +#ifdef FEAT_WAYLAND_CLIPBOARD + return clip_wl_owner_exists(cbd); +#endif + } + else if (clipmethod == CLIPMETHOD_X11) + { +#ifdef FEAT_XCLIPBOARD + return clip_x11_owner_exists(cbd); +#endif + } + else + return FALSE; } - else - return FALSE; - return FALSE; +#else + return TRUE; +#endif } #endif @@ -2292,18 +2261,10 @@ clip_get_selection(Clipboard_T *cbd) } else if (!is_clipboard_needs_update()) { -#ifdef FEAT_CLIPBOARD_PROVIDER - // We will choose if we want to the free the selection if using provider - if (clipmethod != CLIPMETHOD_PROVIDER) - clip_free_selection(cbd); -#endif + clip_free_selection(cbd); // Try to get selected text from another window clip_gen_request_selection(cbd); -#ifdef FEAT_CLIPBOARD_PROVIDER - if (clipmethod == CLIPMETHOD_PROVIDER) - clip_access_type = CLIP_ACCESS_IMPLICIT; -#endif } } @@ -3474,7 +3435,7 @@ clip_wl_owner_exists(Clipboard_T *cbd) * depending on the order of values in str. */ static clipmethod_T -get_clipmethod(char_u *str, bool *plus UNUSED, bool *star) +get_clipmethod(char_u *str, bool *plus UNUSED, bool *star UNUSED) { int len = (int)STRLEN(str) + 1; char_u *buf = alloc(len); @@ -3514,76 +3475,27 @@ get_clipmethod(char_u *str, bool *plus UNUSED, bool *star) #endif { #ifdef FEAT_XCLIPBOARD - // x_IOerror_handler() in os_unix.c should set xterm_dpy to NULL - // if we lost connection to the X server. + // x_IOerror_handler() in os_unix.c should set xterm_dpy to NULL if + // we lost connection to the X server. if (xterm_dpy != NULL) { - // If the X connection is lost then that handler will - // longjmp somewhere else, in that case we will call - // choose_clipmethod() again from there, and this if block - // won't be executed since xterm_dpy will be set to NULL. + // If the X connection is lost then that handler will longjmp + // somewhere else, in that case we will call choose_clipmethod() + // again from there, and this if block won't be executed since + // xterm_dpy will be set to NULL. xterm_update(); method = CLIPMETHOD_X11; - *plus = *star = true; + *plus = *star = TRUE; } #endif } } - else if (STRCMP(buf, "gui") == 0) - { -#ifdef FEAT_GUI - if (gui.in_use) - { - method = CLIPMETHOD_GUI; - *star = *plus = true; - } -#endif - } - else if (STRCMP(buf, "other") == 0) - { -#if (!defined(FEAT_XCLIPBOARD) && !defined(FEAT_WAYLAND_CLIPBOARD) \ - && !defined(FEAT_CLIPBOARD_PROVIDER)) \ - || (!(defined(UNIX) || defined(MACOS_X)) && defined(FEAT_CLIPBOARD_PROVIDER)) - method = CLIPMETHOD_OTHER; - *plus = *star = true; -#endif - } else { -#ifdef FEAT_CLIPBOARD_PROVIDER - // Check if it is the name of a provider -#ifndef ONE_CLIPBOARD - int plus_avail = clip_provider_is_available(&clip_plus, buf); -#endif - int star_avail = clip_provider_is_available(&clip_star, buf); - - if ( -#ifndef ONE_CLIPBOARD - plus_avail == 1 || -#endif - star_avail == 1) - { - method = CLIPMETHOD_PROVIDER; - - vim_free(clipprovider_name); - clipprovider_name = vim_strsave(buf); - -#ifndef ONE_CLIPBOARD - *plus = plus_avail == 1; -#endif - *star = star_avail == 1; - } - else if ( -#ifndef ONE_CLIPBOARD - plus_avail == -1 || -#endif - star_avail == -1) -#endif - { - ret = CLIPMETHOD_FAIL; - goto exit; - } + ret = CLIPMETHOD_FAIL; + goto exit; } + // Keep on going in order to catch errors if (method != CLIPMETHOD_NONE && ret == CLIPMETHOD_FAIL) ret = method; @@ -3601,30 +3513,17 @@ get_clipmethod(char_u *str, bool *plus UNUSED, bool *star) /* * Returns name of clipmethod in a statically allocated string. */ - static char_u * + static char * clipmethod_to_str(clipmethod_T method) { switch(method) { case CLIPMETHOD_WAYLAND: - return (char_u *)"wayland"; + return "wayland"; case CLIPMETHOD_X11: - return (char_u *)"x11"; - case CLIPMETHOD_GUI: - return (char_u *)"gui"; - case CLIPMETHOD_OTHER: - return (char_u *)"other"; - case CLIPMETHOD_PROVIDER: -#ifdef FEAT_CLIPBOARD_PROVIDER - if (clipprovider_name == NULL) - return (char_u *)"none"; - else - return clipprovider_name; -#else - return (char_u *)"none"; -#endif + return "x11"; default: - return (char_u *)"none"; + return "none"; } } @@ -3635,18 +3534,33 @@ clipmethod_to_str(clipmethod_T method) char * choose_clipmethod(void) { - bool plus = false; - bool star = false; - clipmethod_T method = get_clipmethod(p_cpm, &plus, &star); + bool regular = false, primary = false; + clipmethod_T method = get_clipmethod(p_cpm, ®ular, &primary); if (method == CLIPMETHOD_FAIL) return e_invalid_argument; -#if defined(FEAT_GUI) && defined(FEAT_WAYLAND) - if (method == CLIPMETHOD_GUI) +// If GUI is running or we are not on a system with Wayland or X11, then always +// return CLIPMETHOD_NONE. System or GUI clipboard handling always overrides. +#if defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD) +# if defined(FEAT_GUI) + if (gui.in_use) + { +# ifdef FEAT_WAYLAND // We only interact with Wayland for the clipboard, we can just deinit // everything. wayland_uninit_connection(); +# endif + + method = CLIPMETHOD_NONE; + goto lose_sel_exit; + } +# endif +#else + // If on a system like windows or macos, then clipmethod is irrelevant, we + // use their way of accessing the clipboard. + method = CLIPMETHOD_NONE; + goto exit; #endif // Deinitialize clipboard if there is no way to access clipboard @@ -3655,41 +3569,40 @@ choose_clipmethod(void) // If we have a clipmethod that works now, then initialize clipboard else if (clipmethod == CLIPMETHOD_NONE && method != CLIPMETHOD_NONE) { -#ifndef ONE_CLIPBOARD - clip_init_single(&clip_plus, plus); + clip_init_single(&clip_plus, regular); + clip_init_single(&clip_star, primary); clip_plus.did_warn = false; -#endif - clip_init_single(&clip_star, star); clip_star.did_warn = false; } - else if ((clipmethod != CLIPMETHOD_NONE && method != clipmethod)) + // Disown clipboard if we are switching to a new method + else if (clipmethod != CLIPMETHOD_NONE && method != clipmethod) { - // Disown clipboard if we are switching to a new method +#if (defined(FEAT_XCLIPBOARD) || defined(FEAT_WAYLAND_CLIPBOARD)) \ + && defined(FEAT_GUI) +lose_sel_exit: +#endif if (clip_star.owned) clip_lose_selection(&clip_star); - clip_init_single(&clip_star, star); -#ifndef ONE_CLIPBOARD if (clip_plus.owned) clip_lose_selection(&clip_plus); - clip_init_single(&clip_plus, plus); + +#if defined(FEAT_GUI) + if (!gui.in_use) #endif + { + clip_init_single(&clip_plus, regular); + clip_init_single(&clip_star, primary); + } } - else - { - // If availability of a clipboard changed, then update the clipboard - // structure. -#ifndef ONE_CLIPBOARD - if (plus != clip_plus.available) - clip_init_single(&clip_plus, plus); + +#if !defined(FEAT_XCLIPBOARD) && !defined(FEAT_WAYLAND_CLIPBOARD) +exit: #endif - if (star != clip_star.available) - clip_init_single(&clip_star, star); - } clipmethod = method; #ifdef FEAT_EVAL - set_vim_var_string(VV_CLIPMETHOD, clipmethod_to_str(method), -1); + set_vim_var_string(VV_CLIPMETHOD, (char_u*)clipmethod_to_str(method), -1); #endif return NULL; @@ -3712,325 +3625,4 @@ ex_clipreset(exarg_T *eap UNUSED) clipmethod_to_str(clipmethod)); } -#ifdef FEAT_CLIPBOARD_PROVIDER - -/* - * Check if a clipboard provider with given name exists and is available for the - * given clipboard. Returns 1 if the provider exists and the 'available' - * function returned true, 0 if the provider exists but the function returned - * false, and -1 on error. - */ - static int -clip_provider_is_available(Clipboard_T *cbd, char_u *provider) -{ - dict_T *providers = get_vim_var_dict(VV_CLIPPROVIDERS); - typval_T provider_tv = {0}; - callback_T callback = {0}; - typval_T rettv = {0}; - typval_T func_tv = {0}; - char_u *avail; - int res = 0; - - if (dict_get_tv(providers, (char *)provider, &provider_tv) == FAIL - || provider_tv.v_type != VAR_DICT) - return -1; - - if (dict_get_tv(provider_tv.vval.v_dict, "available", &func_tv) == FAIL) - { - clear_tv(&provider_tv); - // If "available" functon not specified assume always TRUE - return 1; - } - - if ((callback = get_callback(&func_tv)).cb_name == NULL) - goto fail; - - if (call_callback(&callback, -1, &rettv, 0, NULL) == FAIL || - rettv.v_type != VAR_STRING) - goto fail; - - avail = rettv.vval.v_string; - - - if ( -#ifndef ONE_CLIPBOARD - (vim_strchr(avail, '+') != NULL && cbd == &clip_plus) || -#endif - (vim_strchr(avail, '*') != NULL && cbd == &clip_star)) - res = 1; - - if (FALSE) -fail: - res = -1; - - free_callback(&callback); - clear_tv(&func_tv); - clear_tv(&rettv); - clear_tv(&provider_tv); - - return res; -} - -/* - * Get the specified callback "function" from the provider dictionary of for - * register "reg". - */ - static int -clip_provider_get_callback( - char_u *reg, - char_u *provider, - char_u *function, - callback_T *callback) -{ - dict_T *providers = get_vim_var_dict(VV_CLIPPROVIDERS); - typval_T provider_tv; - typval_T action_tv; - typval_T func_tv; - callback_T cb; - - if (dict_get_tv(providers, (char *)provider, &provider_tv) == FAIL) - return FAIL; - else if (provider_tv.v_type != VAR_DICT) - { - clear_tv(&provider_tv); - return FAIL; - } - else if (dict_get_tv( - provider_tv.vval.v_dict, - (char *)function, - &action_tv) == FAIL) - { - clear_tv(&provider_tv); - return FAIL; - } - else if (action_tv.v_type != VAR_DICT) - { - clear_tv(&provider_tv); - clear_tv(&action_tv); - return FAIL; - } - else if (dict_get_tv(action_tv.vval.v_dict, (char *)reg, &func_tv) == FAIL) - { - clear_tv(&provider_tv); - clear_tv(&action_tv); - return FAIL; - } - else if ((cb = get_callback(&func_tv)).cb_name == NULL) - { - clear_tv(&provider_tv); - clear_tv(&action_tv); - clear_tv(&func_tv); - return FAIL; - } - clear_tv(&provider_tv); - clear_tv(&action_tv); - - // func_tv owns the function name, so we must make a copy for the callback - set_callback(callback, &cb); - free_callback(&cb); - clear_tv(&func_tv); - return OK; -} - - static void -clip_provider_set_selection(Clipboard_T *cbd, char_u *provider) -{ - char_u *reg = (char_u *)(cbd == &clip_star ? "*" : "+"); - callback_T callback; - typval_T rettv; - typval_T argvars[4]; - yankreg_T *y_ptr; - char_u type[2 + NUMBUFLEN] = {0}; - list_T *list = NULL; - - if (clip_provider_get_callback( - reg, - provider, - (char_u *)"copy", - &callback) == FAIL) - return; - - // Possibly get selected text, if using autoselect for 'clipboard' - cbd->owned = TRUE; - clip_get_selection(cbd); - cbd->owned = FALSE; - - // Convert register type into a string - if (cbd == &clip_plus) - y_ptr = get_y_register(PLUS_REGISTER); - else - y_ptr = get_y_register(STAR_REGISTER); - - switch (y_ptr->y_type) - { - case MCHAR: - type[0] = 'v'; - break; - case MLINE: - type[0] = 'V'; - break; - case MBLOCK: - sprintf((char *)type, "%c%d", Ctrl_V, y_ptr->y_width + 1); - break; - default: - type[0] = 0; - break; - } - - argvars[0].v_type = VAR_STRING; - argvars[0].vval.v_string = reg; - - argvars[1].v_type = VAR_STRING; - argvars[1].vval.v_string = type; - - // Get register contents by creating a list of lines - list = list_alloc(); - - if (list == NULL) - { - free_callback(&callback); - return; - } - - for (int i = 0; i < y_ptr->y_size; i++) - if (list_append_string(list, y_ptr->y_array[i].string, -1) == FAIL) - { - free_callback(&callback); - list_unref(list); - return; - } - - list->lv_refcount++; - - argvars[2].v_type = VAR_LIST; - argvars[2].v_lock = VAR_FIXED; - argvars[2].vval.v_list = list; - - argvars[3].v_type = VAR_UNKNOWN; - - textlock++; - call_callback(&callback, -1, &rettv, 3, argvars); - clear_tv(&rettv); - textlock--; - - free_callback(&callback); - list_unref(list); -} - - static void -clip_provider_request_selection(Clipboard_T *cbd, char_u *provider) -{ - char_u *reg = (char_u *)(cbd == &clip_star ? "*" : "+"); - callback_T callback; - typval_T argvars[3]; - typval_T rettv; - int ret; - char_u *reg_type; - list_T *lines; - - if (clip_provider_get_callback( - reg, - provider, - (char_u *)"paste", - &callback) == FAIL) - return; - - argvars[0].v_type = VAR_STRING; - argvars[0].vval.v_string = reg; - - argvars[1].v_type = VAR_STRING; - argvars[1].vval.v_string = (char_u *) - (clip_access_type == CLIP_ACCESS_EXPLICIT ? "explicit" : "implicit"); - - argvars[2].v_type = VAR_UNKNOWN; - - textlock++; - ret = call_callback(&callback, -1, &rettv, 2, argvars); - textlock--; - - if (ret == FAIL) - goto exit; - else if (rettv.v_type == VAR_STRING - && STRCMP(rettv.vval.v_string, "clear") == 0) - { - clip_free_selection(cbd); - goto exit; - } - else if (rettv.v_type == VAR_STRING - && STRCMP(rettv.vval.v_string, "previous") == 0) - goto exit; - else if (rettv.v_type == VAR_TUPLE - && TUPLE_LEN(rettv.vval.v_tuple) == 2 - && TUPLE_ITEM(rettv.vval.v_tuple, 0)->v_type == VAR_STRING - && TUPLE_ITEM(rettv.vval.v_tuple, 1)->v_type == VAR_LIST) - { - reg_type = TUPLE_ITEM(rettv.vval.v_tuple, 0)->vval.v_string; - lines = TUPLE_ITEM(rettv.vval.v_tuple, 1)->vval.v_list; - } - else if (rettv.v_type == VAR_LIST - && rettv.vval.v_list->lv_len == 2 - && rettv.vval.v_list->lv_first->li_tv.v_type == VAR_STRING - && rettv.vval.v_list->lv_first->li_next->li_tv.v_type == VAR_LIST) - { - reg_type = rettv.vval.v_list->lv_first->li_tv.vval.v_string; - lines = rettv.vval.v_list->lv_first->li_next->li_tv.vval.v_list; - } - else - goto exit; - - { - char_u yank_type = MAUTO; - long block_len = -1; - yankreg_T *y_ptr; - char_u **contents; - listitem_T *li; - int i = 0; - - contents = ALLOC_MULT(char_u *, lines->lv_len + 1); // Ends with a NULL - - if (contents == NULL) - goto exit; - - // Convert strings in list to type char_u ** - FOR_ALL_LIST_ITEMS(lines, li) - { - char_u *str = tv_get_string_chk(&li->li_tv); - - if (str == NULL) - goto exit; - - contents[i++] = vim_strsave(str); - } - contents[i] = NULL; - - if (STRLEN(reg_type) > 0 - && get_yank_type(®_type, &yank_type, &block_len) == FAIL) - goto exit; - - if (cbd == &clip_plus) - y_ptr = get_y_register(PLUS_REGISTER); - else - y_ptr = get_y_register(STAR_REGISTER); - - clip_free_selection(cbd); - - str_to_reg(y_ptr, - yank_type, - (char_u *)contents, - STRLEN(contents), - block_len, - TRUE); - - for (int k = 0; k < i; k++) - vim_free(contents[k]); - vim_free(contents); - } - -exit: - free_callback(&callback); - clear_tv(&rettv); -} - -#endif // FEAT_CLIPBOARD_PROVIDER - #endif // FEAT_CLIPBOARD diff --git a/src/config.h.in b/src/config.h.in index eb0937d393d272..983f186b8d1d72 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -528,6 +528,3 @@ /* Define if you want to load libgpm dynamically */ #undef DYNAMIC_GPM - -/* Define if you want to have clipboard provider functionality*/ -#undef FEAT_CLIPBOARD_PROVIDER diff --git a/src/configure.ac b/src/configure.ac index 635b5f7222cc94..fa6757d69f0c27 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -2434,21 +2434,6 @@ AC_ARG_ENABLE(fontset, AC_MSG_RESULT($enable_fontset) dnl defining FEAT_XFONTSET is delayed, so that it can be disabled for no GUI -AC_MSG_CHECKING(--enable-clipboard-provider) -AC_ARG_ENABLE(clipboard-provider, - [ --enable-clipboard-provider Include clipboard provider support.], - [enable_clipboard_provider=$enableval - AC_MSG_RESULT($enableval)], - AS_IF([test "x$features" = xtiny], - [enable_clipboard_provider="no" - AC_MSG_RESULT([cannot use clipboard provider with tiny features])], - [enable_clipboard_provider="yes" - AC_MSG_RESULT([yes])])) -if test "$enable_clipboard_provider" = "yes"; then - AC_DEFINE(FEAT_CLIPBOARD_PROVIDER) -fi - - AC_MSG_CHECKING(if shm_open is available) cppflags_save=$CPPFLAGS CPPFLAGS="$CPPFLAGS $X_CFLAGS" diff --git a/src/evalfunc.c b/src/evalfunc.c index 1438f221190771..7c3139edc5de0f 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -6500,11 +6500,6 @@ f_getreg(typval_T *argvars, typval_T *rettv) return; } -#ifdef FEAT_CLIPBOARD_PROVIDER - if (clipmethod == CLIPMETHOD_PROVIDER) - clip_access_type = CLIP_ACCESS_EXPLICIT; -#endif - if (return_list) { rettv->v_type = VAR_LIST; @@ -6871,13 +6866,6 @@ f_has(typval_T *argvars, typval_T *rettv) 1 #else 0 -#endif - }, - {"clipboard_provider", -#ifdef FEAT_CLIPBOARD_PROVIDER - 1 -#else - 0 #endif }, {"cmdline_compl", 1}, @@ -7929,26 +7917,8 @@ f_has(typval_T *argvars, typval_T *rettv) else if (STRICMP(name, "clipboard_working") == 0) { x = TRUE; -#ifdef FEAT_CLIPBOARD - n = clip_star.available || clip_plus.available; -#endif - } - else if (STRICMP(name, "clipboard_star_avail") == 0) - { - x = TRUE; #ifdef FEAT_CLIPBOARD n = clip_star.available; -#endif - } - else if (STRICMP(name, "clipboard_plus_avail") == 0) - { - x = TRUE; -#ifdef FEAT_CLIPBOARD -# ifdef ONE_CLIPBOARD - n = FALSE; -# else - n = clip_plus.available; -# endif #endif } } @@ -11523,7 +11493,7 @@ f_setpos(typval_T *argvars, typval_T *rettv) /* * Translate a register type string to the yank type and block length */ - int + static int get_yank_type(char_u **pp, char_u *yank_type, long *block_len) { char_u *stropt = *pp; diff --git a/src/evalvars.c b/src/evalvars.c index 1bf41e85cf0b31..c840d872bd04f3 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -166,8 +166,7 @@ static struct vimvar {VV_NAME("wayland_display", VAR_STRING), NULL, VV_RO}, {VV_NAME("clipmethod", VAR_STRING), NULL, VV_RO}, {VV_NAME("termda1", VAR_STRING), NULL, VV_RO}, - {VV_NAME("termosc", VAR_STRING), NULL, VV_RO}, - {VV_NAME("clipproviders", VAR_DICT), &t_dict_string, VV_RO} + {VV_NAME("termosc", VAR_STRING), NULL, VV_RO}, }; // shorthand diff --git a/src/feature.h b/src/feature.h index 6860cbd981c4d8..11700a060d6fa7 100644 --- a/src/feature.h +++ b/src/feature.h @@ -905,19 +905,6 @@ # define FEAT_CLIPBOARD #endif -/* - * +clipboard_provider Allow Vim to use clipboard providers - */ -#if defined(FEAT_CLIPBOARD_PROVIDER) -# ifndef FEAT_EVAL -# undef FEAT_CLIPBOARD_PROVIDER -# else -# ifndef FEAT_CLIPBOARD -# define FEAT_CLIPBOARD -# endif -# endif -#endif - #ifdef FEAT_GUI # ifndef FEAT_CLIPBOARD # define FEAT_CLIPBOARD diff --git a/src/globals.h b/src/globals.h index eb9e07cf02ac62..6eba836d442f28 100644 --- a/src/globals.h +++ b/src/globals.h @@ -2067,9 +2067,6 @@ EXTERN int p_tgc_set INIT(= FALSE); #ifdef FEAT_CLIPBOARD EXTERN clipmethod_T clipmethod INIT(= CLIPMETHOD_NONE); -# ifdef FEAT_CLIPBOARD_PROVIDER -EXTERN char_u *clipprovider_name INIT(= NULL); -# endif #endif #ifdef FEAT_WAYLAND @@ -2119,16 +2116,3 @@ INIT(= CLIENTSERVER_METHOD_NONE); // Path to socket of last client that communicated with us EXTERN char_u *client_socket INIT(= NULL); #endif - -#ifdef FEAT_CLIPBOARD_PROVIDER -typedef enum -{ - CLIP_ACCESS_IMPLICIT, - CLIP_ACCESS_EXPLICIT, -} clip_access_T; - -// Only relevant for the clipboard provider feature. This indicates if the -// clipboard request is implicit (ex. access when doing :registers), -// explicit (ex. typing "+p). Always defaults to implicit. -EXTERN clip_access_T clip_access_type INIT(= CLIP_ACCESS_IMPLICIT); -#endif diff --git a/src/gui.c b/src/gui.c index 1e4dbdc85c81da..8c37d8740ec3e3 100644 --- a/src/gui.c +++ b/src/gui.c @@ -147,7 +147,7 @@ gui_start(char_u *arg UNUSED) #endif } else - // Reset clipmethod to CLIPMETHOD_GUI + // Reset clipmethod to CLIPMETHOD_NONE choose_clipmethod(); #ifdef FEAT_SOCKETSERVER diff --git a/src/optiondefs.h b/src/optiondefs.h index b5c649f27ab353..7f893d89da481f 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -638,11 +638,11 @@ static struct vimoption options[] = #ifdef FEAT_CLIPBOARD (char_u *)&p_cpm, PV_NONE, did_set_clipmethod, expand_set_clipmethod, # ifdef UNIX - {(char_u *)"wayland,x11,gui,other", (char_u *)0L} + {(char_u *)"wayland,x11", (char_u *)0L} # elif defined(VMS) - {(char_u *)"x11,gui,other", (char_u *)0L} + {(char_u *)"x11", (char_u *)0L} # else - {(char_u *)"gui,other", (char_u *)0L} + {(char_u *)"", (char_u *)0L} # endif #else (char_u *)NULL, PV_NONE, NULL, NULL, diff --git a/src/optionstr.c b/src/optionstr.c index 6bfb752531ab98..b4bfe742dfdd6d 100644 --- a/src/optionstr.c +++ b/src/optionstr.c @@ -45,7 +45,7 @@ static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL}; // Note: Keep this in sync with did_set_clipboard() static char *(p_cb_values[]) = {"unnamed", "unnamedplus", "autoselect", "autoselectplus", "autoselectml", "html", "exclude:", NULL}; // Note: Keep this in sync with get_clipmethod() -static char *(p_cpm_values[]) = {"wayland", "x11", "gui", "other", NULL}; +static char *(p_cpm_values[]) = {"wayland", "x11", NULL}; #endif #ifdef FEAT_CRYPT static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", diff --git a/src/proto/evalfunc.pro b/src/proto/evalfunc.pro index dad8c6771a801a..627af17a8ba68e 100644 --- a/src/proto/evalfunc.pro +++ b/src/proto/evalfunc.pro @@ -28,5 +28,4 @@ void f_len(typval_T *argvars, typval_T *rettv); void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv); void range_list_materialize(list_T *list); long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit); -int get_yank_type(char_u **pp, char_u *yank_type, long *block_len); /* vim: set ft=c : */ diff --git a/src/register.c b/src/register.c index 8d0ed7ace3c9da..1b3f60ec541cad 100644 --- a/src/register.c +++ b/src/register.c @@ -1559,10 +1559,6 @@ do_put( #ifdef FEAT_CLIPBOARD // Adjust register name for "unnamed" in 'clipboard'. adjust_clip_reg(®name); -# ifdef FEAT_CLIPBOARD_PROVIDER - if (clipmethod == CLIPMETHOD_PROVIDER) - clip_access_type = CLIP_ACCESS_EXPLICIT; -# endif (void)may_get_selection(regname); #endif diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index 61ce33a0a74656..0d4aeb0432fb50 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -105,7 +105,6 @@ NEW_TESTS = \ test_cjk_linebreak \ test_clientserver \ test_clipmethod \ - test_clipboard_provider \ test_close_count \ test_cmd_lists \ test_cmdline \ @@ -396,7 +395,6 @@ NEW_TESTS_RES = \ test_cjk_linebreak.res \ test_clientserver.res \ test_clipmethod.res \ - test_clipboard_provider.res \ test_close_count.res \ test_cmd_lists.res \ test_cmdline.res \ diff --git a/src/testdir/test_clipboard_provider.vim b/src/testdir/test_clipboard_provider.vim deleted file mode 100644 index ec9bc52343708e..00000000000000 --- a/src/testdir/test_clipboard_provider.vim +++ /dev/null @@ -1,172 +0,0 @@ -" Test for clipboard provider feature - -CheckFeature clipboard_provider - -func! AvailableBoth() - return "+*" -endfunc - -func! AvailablePlus() - return "+" -endfunc - -func! PasteList(reg, type) - return ["c", ["list"]] -endfunc - -func! PasteTuple(reg, type) - return ("", ["tuple", "of", "strings"]) -endfunc - -func! PasteType(reg, type) - let g:vim_test_type = a:type - return ("c", [a:type]) -endfunc - -func! PasteRegType(reg, type) - return (g:vim_test_reg_type, ["7 chars"]) -endfunc - -func! Copy(reg, type, lines) - let g:vim_test_stuff = { - \ "type": a:type, - \ "lines": a:lines - \ } -endfunc - -" Test if "available" function works properly for provider -func Test_clipboard_provider_available() - CheckUnix - CheckFeature clipboard_plus_avail - - let v:clipproviders["test"] = { - \ "available": function("AvailablePlus"), - \ "paste": { - \ '+': function("PasteList"), - \ '*': function("PasteList") - \ } - \ } - - set clipmethod=test - call assert_equal("test", v:clipmethod) - - call assert_equal("list", getreg("+")) - " Test if star register is unavailable - call assert_equal("", getreg("*")) - - let v:clipproviders["test"] = { - \ "available": function("AvailableBoth"), - \ "paste": { - \ '+': function("PasteList"), - \ '*': function("PasteList") - \ } - \ } - - clipreset - - call assert_equal("list", getreg("+")) - call assert_equal("list", getreg("*")) - - let v:clipproviders["test"] = { - \ "paste": { - \ '+': function("PasteList"), - \ '*': function("PasteList") - \ } - \ } - - " Should default to TRUE - call assert_equal("list", getreg("+")) - call assert_equal("list", getreg("*")) - - set clipmethod& -endfunc - -" Test if "paste" functions work properly for provider -func Test_clipboard_provider_paste() - " Test if tuples and lists work the same - let v:clipproviders["test"] = { - \ "paste": { - \ '*': function("PasteList") - \ } - \ } - - set clipmethod=test - call assert_equal("test", v:clipmethod) - - call assert_equal("list", getreg("*")) - - let v:clipproviders["test"] = { - \ "paste": { - \ '*': function("PasteTuple") - \ } - \ } - - call assert_equal("tuple\nof\nstrings\n", getreg("*")) - - " Test if "implicit" and "explicit" arguments are correctly used - let v:clipproviders["test"] = { - \ "paste": { - \ '*': function("PasteType") - \ } - \ } - - call assert_equal("explicit", getreg("*")) - - :registers - - call assert_equal("implicit", g:vim_test_type) - unlet g:vim_test_type - - " Test if correct register type is used - let v:clipproviders["test"] = { - \ "paste": { - \ '*': function("PasteRegType") - \ } - \ } - - let g:vim_test_reg_type = "v" - call assert_equal("v", getregtype("*")) - let g:vim_test_reg_type = "c" - call assert_equal("v", getregtype("*")) - - let g:vim_test_reg_type = "l" - call assert_equal("V", getregtype("*")) - let g:vim_test_reg_type = "l" - call assert_equal("V", getregtype("*")) - - let g:vim_test_reg_type = "b" - call assert_equal("7", getregtype("*")) - let g:vim_test_reg_type = "" - call assert_equal("7", getregtype("*")) - - let g:vim_test_reg_type = "b40" - call assert_equal("40", getregtype("*")) - - set clipmethod& -endfunc - -" Test if "copy" functions work properly for provider -func Test_clipboard_provider_copy() - let v:clipproviders["test"] = { - \ "copy": { - \ '*': function("Copy") - \ } - \ } - - set clipmethod=test - call assert_equal("test", v:clipmethod) - - call setreg("*", ["hello", "world", "!"], "c") - call assert_equal(["hello", "world", "!"], g:vim_test_stuff.lines) - call assert_equal("v", g:vim_test_stuff.type) - - call setreg("*", ["hello", "world", "!"], "l") - call assert_equal(["hello", "world", "!"], g:vim_test_stuff.lines) - call assert_equal("V", g:vim_test_stuff.type) - - call setreg("*", ["hello", "world", "!"], "b40") - call assert_equal(["hello", "world", "!"], g:vim_test_stuff.lines) - call assert_equal("40", g:vim_test_stuff.type) - - set clipmethod& -endfunc diff --git a/src/testdir/test_clipmethod.vim b/src/testdir/test_clipmethod.vim index b1e447923946c0..9b34658426b42c 100644 --- a/src/testdir/test_clipmethod.vim +++ b/src/testdir/test_clipmethod.vim @@ -1,12 +1,14 @@ " Tests for clipmethod -if has('unix') - source util/window_manager.vim -endif +source util/window_manager.vim + +CheckFeature clipboard_working +CheckFeature xterm_clipboard +CheckFeature wayland_clipboard +CheckUnix " Test if no available clipmethod sets v:clipmethod to none and deinits clipboard func Test_no_clipmethod_sets_v_clipmethod_none() - CheckFeature clipboard_working CheckNotGui set clipmethod= @@ -17,9 +19,6 @@ endfunc " Test if method chosen is in line with clipmethod order func Test_clipmethod_order() CheckNotGui - CheckFeature clipboard_working - CheckFeature xterm_clipboard - CheckFeature wayland_clipboard set cpm=wayland,x11 @@ -63,12 +62,12 @@ func Test_clipmethod_order() call EndWaylandCompositor(l:wayland_display) endfunc -" Test if clipmethod is set to 'gui' when gui is started -func Test_clipmethod_is_gui_when_gui_started() +" Test if clipmethod is set to 'none' when gui is started +func Test_clipmethod_is_none_when_gui() CheckCanRunGui - CheckFeature clipboard_working let lines =<< trim END + set cpm=wayland,x11 call writefile([v:clipmethod != ""], 'Cbdscript') gui -f call writefile([v:clipmethod], 'Cbdscript', 'a') @@ -79,15 +78,12 @@ func Test_clipmethod_is_gui_when_gui_started() call writefile(lines, 'Cbdscript', 'D') call system($'{GetVimCommand()} -S Cbdscript') - call assert_equal(['1', 'gui', 'gui'], readfile('Cbdscript')) + call assert_equal(['1', 'none', 'none'], readfile('Cbdscript')) endfunc " Test if :clipreset switches methods when current one doesn't work func Test_clipreset_switches() CheckNotGui - CheckFeature clipboard_working - CheckFeature xterm_clipboard - CheckFeature wayland_clipboard CheckFeature clientserver CheckXServer CheckWaylandCompositor @@ -177,15 +173,4 @@ func Test_clipreset_switches() endif endfunc -" Test if v:clipmethod is "other" on non-gui versions of MacOS and Windows -" builds -func Test_clipmethod_is_other_on_non_x11_wayland() - CheckFeature clipboard_working - CheckNotGui - CheckNotFeature wayland - CheckNotFeature x11 - - call assert_equal("other", v:clipmethod) -endfunc - " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim index 6adfb4d768a5ee..39bb4ba9f2d083 100644 --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -727,50 +727,4 @@ func Test_eval_string_in_special_key() silent! echo 0{1-$"\n|nö% endfunc -func AvailableTest() - return g:vim_test_plus .. g:vim_test_star -endfunc - -func Test_clipboard_runtime_features() - " Use clipboard provider because we can change if a register is available or - " not. - CheckFeature clipboard_provider - CheckFeature clipboard - - let g:vim_test_plus = '' - let g:vim_test_star = '' - - let v:clipproviders["evaltest"] = { - \ "available": function("AvailableTest") - \ } - - set clipmethod=evaltest - - if has('win32') || has('macunix') || - \ (!has('wayland_clipboard') && !has('xterm_clipboard')) - let g:vim_test_plus = '+' - let g:vim_test_star = '*' - clipreset - - " plus register should be disabled on windows or macos, or if Wayland and - " X11 is not enabled. - call assert_equal(0, has('clipboard_plus_avail')) - call assert_equal(1, has('clipboard_star_avail')) - else - let g:vim_test_star = '*' - let g:vim_test_plus = '+' - clipreset - - call assert_equal(1, has('clipboard_plus_avail')) - call assert_equal(1, has('clipboard_star_avail')) - - let g:vim_test_plus = "" - clipreset - - call assert_equal(0, has('clipboard_plus_avail')) - endif - - set clipmethod& -endfunc - " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim index 9fe790c4e84808..3abc067b3f8fd4 100644 --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -529,7 +529,7 @@ func Test_set_completion_string_values() if has('unix') || has('vms') call assert_match('wayland', getcompletion('set clipmethod=', 'cmdline')[1]) else - call assert_match('gui', getcompletion('set clipmethod=', 'cmdline')[0]) + call assert_match('wayland', getcompletion('set clipmethod=', 'cmdline')[0]) endif endif call assert_equal('.', getcompletion('set complete=', 'cmdline')[1]) diff --git a/src/version.c b/src/version.c index 3001dbd1c039fc..7a95c89cbb20da 100644 --- a/src/version.c +++ b/src/version.c @@ -155,11 +155,6 @@ static char *(features[]) = "+clipboard", #else "-clipboard", -#endif -#ifdef FEAT_CLIPBOARD_PROVIDER - "+clipboard_provider", -#else - "-clipboard_provider", #endif "+cmdline_compl", "+cmdline_hist", @@ -734,22 +729,6 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ -/**/ - 1869, -/**/ - 1868, -/**/ - 1867, -/**/ - 1866, -/**/ - 1865, -/**/ - 1864, -/**/ - 1863, -/**/ - 1862, /**/ 1861, /**/ diff --git a/src/vim.h b/src/vim.h index 6c35fe1ef43e04..83521b9efc9751 100644 --- a/src/vim.h +++ b/src/vim.h @@ -2256,8 +2256,7 @@ typedef int sock_T; #define VV_CLIPMETHOD 113 #define VV_TERMDA1 114 #define VV_TERMOSC 115 -#define VV_CLIPPROVIDERS 116 -#define VV_LEN 117 // number of v: vars +#define VV_LEN 116 // number of v: vars // used for v_number in VAR_BOOL and VAR_SPECIAL #define VVAL_FALSE 0L // VAR_BOOL @@ -2317,9 +2316,6 @@ typedef enum { CLIPMETHOD_NONE, CLIPMETHOD_WAYLAND, CLIPMETHOD_X11, - CLIPMETHOD_GUI, - CLIPMETHOD_OTHER, - CLIPMETHOD_PROVIDER } clipmethod_T; // Info about selected text