This is based off of the now defunct clipboard provider feature. I've decided on "&" being the custom register, which can be controlled via the 'regputfunc' and 'regyankfunc' options. This is based in register.c, instead of clipboard.c, so it shouldn't break any clipboard code.
I didn't use the existing "+" or "*" registers since I think this and those registers should handle different things, instead of trying to fit them together. Also makes things a bit simpler
https://github.com/vim/vim/pull/18642
(4 files)
—
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.
—
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.
@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 12 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.
@dkearns commented on this pull request.
Thanks. I just left a few comments after a quick read through the help.
> @@ -1401,6 +1402,15 @@ register. The search direction is available in |v:searchforward|. Note that the value is restored when returning from a function |function-search-undo|. +11. Custom register "& *quote_&* *quote&* +Acts like a numbered or named register, but when the register is yanked to,⬇️ Suggested change
-Acts like a numbered or named register, but when the register is yanked to, +Acts like a named register, but when writing to the register
> @@ -1401,6 +1402,15 @@ register. The search direction is available in |v:searchforward|. Note that the value is restored when returning from a function |function-search-undo|. +11. Custom register "& *quote_&* *quote&* +Acts like a numbered or named register, but when the register is yanked to, +the callback specified in 'regsetfunc' is called, and when it is put, the⬇️ Suggested change
-the callback specified in 'regsetfunc' is called, and when it is put, the +the callback specified in 'regsetfunc' is called, and when it is read, the
> +specified (empty), then the register simply acts like another numbered or +named register. This register is not saved in the |viminfo| file and the⬇️ Suggested change
-specified (empty), then the register simply acts like another numbered or -named register. This register is not saved in the |viminfo| file and the +specified (empty), then the register simply acts like another +named register. This register is not saved in the |viminfo| file and the
> @@ -7033,6 +7033,64 @@ A jump table for the options with a short description can be found at |Q_op|. many states. This should prevent Vim from hanging on a combination of a complex pattern with long text. + *'regreqfunc* *'rrf'* +'regreqfunc' 'rrf' string (default "")
Shouldn't this be named 'reggetfunc'?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@dkearns commented on this pull request.
> @@ -7033,6 +7033,64 @@ A jump table for the options with a short description can be found at |Q_op|. many states. This should prevent Vim from hanging on a combination of a complex pattern with long text. + *'regreqfunc* *'rrf'*
- *'regreqfunc* *'rrf'* + *'regreqfunc'* *'rrf'*
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
> @@ -7033,6 +7033,64 @@ A jump table for the options with a short description can be found at |Q_op|. many states. This should prevent Vim from hanging on a combination of a complex pattern with long text. + *'regreqfunc* *'rrf'* +'regreqfunc' 'rrf' string (default "")
In the clipboard source code Vim uses "request" as the keyword for accessing the clipboard, so I did the same for here
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@dkearns commented on this pull request.
> @@ -7033,6 +7033,64 @@ A jump table for the options with a short description can be found at |Q_op|. many states. This should prevent Vim from hanging on a combination of a complex pattern with long text. + *'regreqfunc* *'rrf'* +'regreqfunc' 'rrf' string (default "")
The feature isn't related to the clipboard anymore is it?  Irrespective, I think it's more important to be consistent with setreg()/getreg() naming.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
> @@ -7033,6 +7033,64 @@ A jump table for the options with a short description can be found at |Q_op|. many states. This should prevent Vim from hanging on a combination of a complex pattern with long text. + *'regreqfunc* *'rrf'* +'regreqfunc' 'rrf' string (default "")
I suppose so, I'll change it. thanks
—
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.
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.
@zeertzjq commented on this pull request.
> +		set reggetfunc=GetFunc
+<
+	The value can be the name of a function, a |lambda| or a |Funcref|.  See
+	|option-value-function| for more information.
+	This option cannot be set from a |modeline| or in the |sandbox|, for
+	security reasons.
+	Additionally it is not allowed to change the buffer
+	text in the function, see |textlock|.
+
+						*'regsetfunc* *'rsf'*
+'regsetfunc' 'rsf'	string	(default "")
+			global
+			{not available when compiled without the |+eval|
+			feature}
+	This option specifies a function to be used whenever the custom
+	register |quote_&| is written inclusing |setreg()|. The function
What is "inclusing"?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@zeertzjq commented on this pull request.
In src/register.c:
> +}
+
+/*
+ * Call the function specified in 'reggetfunc'. Should be called to update the
+ * custom register before being accessed.
+ */
+    static void
+call_reggetfunc(void)
+{
+    typval_T	rettv;
+    typval_T	argvars[1];
+    int		ret;
+    char_u	*reg_type;
+    list_T	*lines;
+
+    // If 'reqreqfunc' option is empty, then do nothing and treat the register
⬇️ Suggested change
- // If 'reqreqfunc' option is empty, then do nothing and treat the register + // If 'reqgetfunc' option is empty, then do nothing and treat the register
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
> +		set reggetfunc=GetFunc
+<
+	The value can be the name of a function, a |lambda| or a |Funcref|.  See
+	|option-value-function| for more information.
+	This option cannot be set from a |modeline| or in the |sandbox|, for
+	security reasons.
+	Additionally it is not allowed to change the buffer
+	text in the function, see |textlock|.
+
+						*'regsetfunc* *'rsf'*
+'regsetfunc' 'rsf'	string	(default "")
+			global
+			{not available when compiled without the |+eval|
+			feature}
+	This option specifies a function to be used whenever the custom
+	register |quote_&| is written inclusing |setreg()|. The function
typo
—
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.
@zeertzjq commented on this pull request.
> +		set reggetfunc=GetFunc
+<
+	The value can be the name of a function, a |lambda| or a |Funcref|.  See
+	|option-value-function| for more information.
+	This option cannot be set from a |modeline| or in the |sandbox|, for
+	security reasons.
+	Additionally it is not allowed to change the buffer
+	text in the function, see |textlock|.
+
+						*'regsetfunc* *'rsf'*
+'regsetfunc' 'rsf'	string	(default "")
+			global
+			{not available when compiled without the |+eval|
+			feature}
+	This option specifies a function to be used whenever the custom
+	register |quote_&| is written including |setreg()|. The function
⬇️ Suggested change
- register |quote_&| is written including |setreg()|. The function + register |quote_&| is written including |setreg()|. The function
—
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.
> + Additionally it is not allowed to change the buffer + text in the function, see |textlock|.⬇️ Suggested change
- Additionally it is not allowed to change the buffer - text in the function, see |textlock|. + Additionally it is not allowed to change the buffer text in the + function, see |textlock|.
> + Additionally it is not allowed to change the buffer + text in the function, see |textlock|.
- Additionally it is not allowed to change the buffer - text in the function, see |textlock|. + Additionally it is not allowed to change the buffer text in the + function, see |textlock|.
—
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 15 commits.
You are receiving this because you are subscribed to this thread.
Made it so that there are two custom registers ("^" and "&"). Did this since OSC 52 supports multiple selections on X11/Wayland on some terminals.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.
@benknoble commented on this pull request.
> +	This options specifies a function to be used whenever the custom
+	registers |quote_&|, |quote_^| are read.  The function takes no
+	arguments, and should return a |tuple| or |list| containing the
+	following elements in order:
+		1. The register name.
+		2. The register type, conforming to |setreg()|, that the
+		   register will be set to.
+		3. A |list| containing a list of strings to set the register
+		   to.
+	Note that this function is not called on |:registers| or |:display|.
+
+	The following is a possible example use of this option:
+>vim
+		function GetFunc(reg)
+		    echom "Updating register " .. a:reg
+		    return ('l', readfile('stuff.txt'))
+		endfunction
+
+		set reggetfunc=GetFunc
I'm lost: how does reggetfunc know which register it's reading if it takes no argument? And yet the examples does… And why does the example only return 3 elements instead of 2? TIL that tuples are available in Vimscript, though.
It might help to see an actual use case for this.
In particular, why is that reading "& will mutate a different register? That seems… icky. I would prefer that reading it simply executes the callback and gives that value to whatever needs the register (a put or expression, presumably).
The docs seem to indicate that reading one of these will mutate another register, but that's not what happens at all. The docs really need to accurately describe the behavior, and a motivating use makes a much better example.
> + nothing and takes two arguments: + 1. The register name. + 2. The register type being used, conforming to |getregtype()|. + 3. A list of strings being written.
Similar counting comments, of course.
In src/register.c:
> + if ((long *)args->os_varp == (long *)&p_rgf) + ret = option_set_callback_func(p_rgf, &rgf_cb); + else + ret = option_set_callback_func(p_rsf, &rsf_cb);
nit: indentation looks inconsistent in changes here.
In src/structs.h:
> + #ifdef FEAT_DND -# define TILDE_REGISTER (PLUS_REGISTER + 1) +# define TILDE_REGISTER (PLUS_REGISTER + 1)
nit: unnecessary whitespace changes?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
> +	This options specifies a function to be used whenever the custom
+	registers |quote_&|, |quote_^| are read.  The function takes no
+	arguments, and should return a |tuple| or |list| containing the
+	following elements in order:
+		1. The register name.
+		2. The register type, conforming to |setreg()|, that the
+		   register will be set to.
+		3. A |list| containing a list of strings to set the register
+		   to.
+	Note that this function is not called on |:registers| or |:display|.
+
+	The following is a possible example use of this option:
+>vim
+		function GetFunc(reg)
+		    echom "Updating register " .. a:reg
+		    return ('l', readfile('stuff.txt'))
+		endfunction
+
+		set reggetfunc=GetFunc
I'm lost: how does
reggetfuncknow which register it's reading if it takes no argument? And yet the examples does… And why does the example only return 3 elements instead of 2? TIL that tuples are available in Vimscript, though.
I just messed up the documentation, I'll fix this later. Thanks for catching
The docs seem to indicate that reading one of these will mutate another register, but that's not what happens at all. The docs really need to accurately describe the behavior, and a motivating use makes a much better example.
I'm not sure what you mean by "mutate another register". If the "&yy is pressed, then it'll yank to the & register, same for the ^ register. I created this PR for the OSC52 feature, but from what ChatGPT said, there seems to be a bunch of other uses as well. I don't think we need to documentate it though, the user will find their way to this feature likely
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@64-bitman commented on this pull request.
In src/register.c:
> + if ((long *)args->os_varp == (long *)&p_rgf) + ret = option_set_callback_func(p_rgf, &rgf_cb); + else + ret = option_set_callback_func(p_rsf, &rsf_cb);
I believe thats just Github doing weird things
—
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 15 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.
@64-bitman pushed 1 commit.
You are receiving this because you are subscribed to this thread.
I have not yet found the time to have a good look at this PR but I think that some considerable thought should be given to the names used for these registers before they're cast in stone.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.