With the exception of the "available" callback if a callback is not provided,
Vim will not invoke anything, and this is not an error.
+If the "paste" or "copy" callbacks are triggered recursively, then they will
+not be called.
+
*clipboard-providers-textlock*
In both the "paste" and "copy" callbacks, it is not allowed to change the
buffer text, see |textlock|.
static void
clip_provider_copy(char_u *reg, char_u *provider)
{
+ static bool recursive = false;
callback_T callback;
typval_T rettv;
typval_T argvars[4];
char_u type[2 + NUMBUFLEN] = {0};
list_T *list = NULL;
+ if (recursive)
+ return;
+
if (clip_provider_get_callback(
reg,
provider,
argvars[3].v_type = VAR_UNKNOWN;
textlock++;
+ recursive = true;
call_callback(&callback, -1, &rettv, 3, argvars);
+ recursive = false;
clear_tv(&rettv);
textlock--;
static void
clip_provider_paste(char_u *reg, char_u *provider)
{
+ static bool recursive = false;
callback_T callback;
typval_T argvars[2];
typval_T rettv;
char_u *reg_type;
list_T *lines;
+ if (recursive)
+ return;
+
if (clip_provider_get_callback(
reg,
provider,
argvars[1].v_type = VAR_UNKNOWN;
textlock++;
+ recursive = true;
ret = call_callback(&callback, -1, &rettv, 1, argvars);
+ recursive = false;
textlock--;
if (ret == FAIL)
else
return ("c", [])
endif
+ endif
+ if exists("g:vim_paste_recursive")
+ call getreg(a:reg)
endif
endfunc
if exists("g:vim_copy_count")
let g:vim_copy_count[a:reg] += 1
endif
+ if exists("g:vim_copy_recursive")
+ call setreg(a:reg, a:lines)
+ endif
let g:vim_copy = {
\ "reg": a:reg,
set clipboard&
endfunc
+" Test that callback aren't called recursively
+func Test_clipboard_provider_recursive()
+ let v:clipproviders["test"] = {
+ \ "paste": {
+ \ '+': function("s:Paste"),
+ \ '*': function("s:Paste")
+ \ },
+ \ "copy": {
+ \ '+': function("s:Copy"),
+ \ '*': function("s:Copy")
+ \ }
+ \ }
+ set clipmethod=test
+
+ let g:vim_paste = "count"
+ let g:vim_paste_count = {'*': 0, '+': 0}
+ let g:vim_copy_count = {'*': 0, '+': 0}
+ let g:vim_paste_recursive = 1
+ let g:vim_copy_recursive = 1
+
+ call getreg('+')
+ call assert_equal(1, g:vim_paste_count['+'])
+ call setreg('+', 'test')
+ call assert_equal(1, g:vim_copy_count['+'])
+
+ set clipmethod&
+ unlet g:vim_paste_recursive
+ unlet g:vim_copy_recursive
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab