Refactor and expand special registers
This implements some special registers from Kakoune:
-
#: index numbers for the current selections -
.: contents of the current selections -
%: name of the current file (#5577)
And adds special registers for the system and primary clipboards: * and + respectively. This also re-uses the trick from #6889 to store the selections yanked to clipboards so they can be re-used on paste if the clipboard hasn't changed.
The strategy here mirrors how Kakoune implements these special registers and should extend to the remaining special registers in Kakoune (1..9 for regex captures), but it's an unfortunately large refactor that adds complexity and allocations and needs updates for all register callsites. The overview is...
-
Registerbecomes a trait implemented by the old basic register type and each special register. -
readfunctions now return owned values. This is necessary because of the way some special registers produce their values. (This is not great though and it'd be nice to find a way around this.) -
read,writeandpushfunctions now take theEditoras a parameter. This is the main change that enables special registers and is what mirrors Kakoune but causes a larger change:-
Registersmoves from a field onEditorto fields on theContexttypes to avoid borrowing conflicts.
-
#: index numbers for the current selections .: contents of the current selections
Is the buffer save state exposed somehow? That would be useful.
Also, out of scope for this issue but is there any way to turn this into selection ranges?
I can't imagine use-cases for either of these, could you expand on that in a separate discussion? This is specifically about the Kakoune registers & clipboard registers
When and how is the # ever used? I found this line, but I can't find where it set...
https://github.com/helix-editor/helix/blob/a9849ebee41a8cb884a9351d36ebd399adb4111e/helix-term/src/commands.rs#L5480
Is there a pipe register too? https://github.com/helix-editor/helix/blob/a9849ebee41a8cb884a9351d36ebd399adb4111e/helix-term/src/commands.rs#L5204
When and how is the
#ever used? I found this line, but I can't find where it set...https://github.com/helix-editor/helix/blob/a9849ebee41a8cb884a9351d36ebd399adb4111e/helix-term/src/commands.rs#L5480
that register was a special case for that command in the past this PR adds it as a general purpose register.
Is there a pipe register too?
https://github.com/helix-editor/helix/blob/a9849ebee41a8cb884a9351d36ebd399adb4111e/helix-term/src/commands.rs#L5204
Is there a pipe register too?
https://github.com/helix-editor/helix/blob/a9849ebee41a8cb884a9351d36ebd399adb4111e/helix-term/src/commands.rs#L5204
Not in this PR. I don't think that makes too much sense for us given that we don't have an interactive shell yet
Yeah the existing line you linked is used for "#<C-a> or "#<C-x> so you can increment/decrement by selection number. With this PR you can use "#P to paste the selection numbers before each cursor.
Huh, cool! ~~Where # set?~~ Got it.
Pascal and I chatted about this and settled on something lighter-weight. The trait is replaced with matchs on the chars. The clipboard_provider moves from Editor to Registers and all clipboard commands switch to using the new clipboard registers. With that change we avoid the borrowing conflict and can keep registers on Editor plus we delete some clipboard-specific chunks of code out of the commands module.
maybe we should document somewhere that registers are stored in reverse so that we can push at the end? It would be nice to have some docs for that. It's obvious to me now but might be confusing for somebody new to the codebase