patch 9.1.1973: some minor problems with clipboard provider code
Commit:
https://github.com/vim/vim/commit/131d878aaa0d20efd3f2863633ba7cb5965b7233
Author: Foxe Chen <
chen...@gmail.com>
Date: Fri Dec 12 08:44:14 2025 +0100
patch 9.1.1973: some minor problems with clipboard provider code
Problem: some minor problems with clipboard provider code
(after v9.1.1972)
Solution: Fix minor issues (Foxe Chen)
- allow empty register type for paste function to mean automatic
- fix internal inc_clip_provider() and dec_clip_provider() functions not
setting the pause count correctly
- don't call paste function when yanking
closes: #18909
Signed-off-by: Foxe Chen <
chen...@gmail.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index ebb6d5ba7..6bd012033 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 Dec 11
+*eval.txt* For Vim version 9.1. Last change: 2025 Dec 12
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -5343,7 +5343,8 @@ The "paste" callback takes the following arguments in the following order:
It should return a |list| or |tuple| containing the following elements in
order:
- 1. Register type (and optional width) conforming to |setreg()|
+ 1. Register type (and optional width) conforming to |setreg()|. If it
+ is an empty string, then the type is automatically chosen.
2. A |list| of strings to return to Vim, each representing a line.
*clipboard-providers-copy*
diff --git a/src/clipboard.c b/src/clipboard.c
index 51f705430..6d321e5c0 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -3934,8 +3934,8 @@ clip_provider_paste(char_u *reg, char_u *provider)
}
*curval++ = NULL;
- if (STRLEN(reg_type) <= 0
- || get_yank_type(®_type, &yank_type, &block_len) == FAIL)
+ if (*reg_type != NUL && (STRLEN(reg_type) <= 0
+ || get_yank_type(®_type, &yank_type, &block_len) == FAIL))
{
emsg(e_invalid_argument);
goto free_lstval;
@@ -3977,7 +3977,7 @@ exit:
// This prevents unnecessary calls when accessing the provider often in an
// interval.
//
-// If -1 then allow provider callback to be called then set to zero. Default
+// If -1 then allow provider callback to be called then set to one. Default
// value (is allowed) is -2.
static int star_pause_count = -2, plus_pause_count = -2;
@@ -4031,15 +4031,19 @@ call_clip_provider_set(int reg)
void
inc_clip_provider(void)
{
- plus_pause_count = plus_pause_count == -2 ? -1 : plus_pause_count + 1;
- star_pause_count = star_pause_count == -2 ? -1 : star_pause_count + 1;
+ plus_pause_count = (plus_pause_count == -2
+ || plus_pause_count == -1) ? -1 : plus_pause_count + 1;
+ star_pause_count = (star_pause_count == -2
+ || star_pause_count == -1) ? -1 : star_pause_count + 1;
}
void
dec_clip_provider(void)
{
- plus_pause_count = plus_pause_count == -1 ? -1 : plus_pause_count - 1;
- star_pause_count = star_pause_count == -1 ? -1 : star_pause_count - 1;
+ if (plus_pause_count != -2)
+ plus_pause_count = plus_pause_count == -1 ? -1 : plus_pause_count - 1;
+ if (star_pause_count != -2)
+ star_pause_count = star_pause_count == -1 ? -1 : star_pause_count - 1;
if (plus_pause_count == 0 || plus_pause_count == -1)
plus_pause_count = -2;
diff --git a/src/register.c b/src/register.c
index 589d07f71..12fe8ebb1 100644
--- a/src/register.c
+++ b/src/register.c
@@ -1420,6 +1420,7 @@ op_yank(oparg_T *oap, int deleting, int mess)
}
#ifdef FEAT_CLIPBOARD_PROVIDER
+ inc_clip_provider();
if (curr == &y_regs[REAL_PLUS_REGISTER])
call_clip_provider_set('+');
else if (curr == &y_regs[STAR_REGISTER])
@@ -1467,6 +1468,9 @@ op_yank(oparg_T *oap, int deleting, int mess)
#if defined(FEAT_EVAL)
if (!deleting && has_textyankpost())
yank_do_autocmd(oap, y_current);
+#endif
+#ifdef FEAT_CLIPBOARD_PROVIDER
+ dec_clip_provider();
#endif
return OK;
diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim
index 49fa9509e..eb0eaca53 100644
--- a/src/testdir/test_eval_stuff.vim
+++ b/src/testdir/test_eval_stuff.vim
@@ -754,6 +754,7 @@ func s:Paste(reg)
elseif l:t == "count"
let g:vim_paste_count[a:reg] += 1
+ let g:vim_test = "hello"
return ("c", ["hello"])
elseif l:t == "store"
@@ -1073,14 +1074,82 @@ func Test_clipboard_provider_accessed_once()
call assert_equal(1, g:vim_paste_count['+'])
call assert_equal(1, g:vim_paste_count['*'])
+ call assert_equal(0, g:vim_copy_count['+'])
+ call assert_equal(0, g:vim_copy_count['*'])
+
+ let g:vim_paste_count = {'*': 0, '+': 0}
+
call execute(':global/quick/:yank +')
call execute(':global/quick/:yank *')
call assert_equal(1, g:vim_copy_count['+'])
call assert_equal(1, g:vim_copy_count['*'])
+ call assert_equal(0, g:vim_paste_count['+'])
+ call assert_equal(0, g:vim_paste_count['*'])
+
bw!
set clipmethod&
endfunc
+" Test if the copying does not call the paste callback, and pasting does not all
+" the copy callback.
+func Test_clipboard_provider_copy_paste_independent()
+ 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}
+
+ new
+
+ put +
+
+ put *
+
+ bw!
+
+ call getreg("+")
+ call getreg("*")
+
+ call assert_equal(0, g:vim_copy_count['*'])
+ call assert_equal(0, g:vim_copy_count['+'])
+
+ let g:vim_paste_count = {'*': 0, '+': 0}
+
+ " Emitting TextYankPost event may cause a clipboard access
+ augroup Test
+ autocmd!
+ autocmd TextYankPost * let g:test = 2
+ augroup END
+
+ new
+ call setline(1, "The quick brown fox jumps over the lazy dog")
+
+ yank +
+
+ yank *
+
+ bw!
+ autocmd! Test
+
+ call setreg("+", "hello")
+ call setreg("*", "hello")
+
+ call assert_equal(0, g:vim_paste_count['*'])
+ call assert_equal(0, g:vim_paste_count['+'])
+
+ set clipmethod&
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index e754b6021..43bb41282 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1973,
/**/
1972,
/**/