-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add new "custom" register #18642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add new "custom" register #18642
Conversation
a85528a to
f462aa6
Compare
3e2b9d0 to
91f23e8
Compare
|
I think this is ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I just left a few comments after a quick read through the help.
ae792b8 to
909b92b
Compare
|
I think this is ready |
0b94d1e to
8dabf65
Compare
|
Made it so that there are two custom registers ("^" and "&"). Did this since OSC 52 supports multiple selections on X11/Wayland on some terminals, which Neovim provides support for so I think we should do as well. |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
runtime/doc/options.txt
Outdated
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar counting comments, of course.
31409a8 to
1a434aa
Compare
1a434aa to
7ccc329
Compare
|
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. |
| global | ||
| {not available when compiled without the |+eval| | ||
| feature} | ||
| This options specifies a function to be used whenever the custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| This options specifies a function to be used whenever the custom | |
| This option specifies a function to be used whenever the custom |
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 | |
| 1. The register type, conforming to |setreg()|, that the | |
| register will be set to. | |
| 2. A |list| containing a list of strings to set the register |
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 'regreqfunc' and 'regsetfunc' 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.
I am open to using a different character for the register name.