Preserve register values when merging new ones #3354
The new command
Commands from the local history (
I recently hit this problem with my kakoune-state-save plugin: after using it for a while, it would load my command history but not update it. Eventually I figured out that when I quit Kakoune, the following sequence of events would take place:
One alternative would be for me to give up on merging values from other sessions - always load at startup, always save at shutdown, and any changes made between the two get clobbered. Unfortunate, but a lot of other tools work the same way, so it might not be the worst thing.
Another alternative would be, instead of the
We don't need a special mode for appending to history, as
I couldn't get your reproducer to run (possibly a a-s missing, and a different implementation of
As for your problem, as I understand you're requesting to have a "merge" flag on
The expected outcome is to have the 100 commands that were inserted first in the command history, right?
Looks like I omitted an
As for "expected outcome", the way these registers were described to me was that new values would be "merged" with existing values, which I assumed was like a Git merge - you have a common history, then branches with different additions, and when you merge you get the union of all the branches. And in fact Kakoune does currently behave like that - as long as there are less than 100 unique history items in total.
I couldn't honestly say the current behaviour is buggy - it has some sensibly-chosen invariants like "never more than 100 items of history" and "the most recently added item is always at the end", and a sensible implementation that ensures those invariants are always upheld. However, part of the reason why history registers were introduced was so that they could be saved and restored externally, and the current implementation makes that use-case difficult.
Maybe the answer is to allow an unlimited number of history items, or to impose the limit after the merge operation instead of during, or some other, wilder approach the one I outlined in the OP. My point is, Kakoune would be more useful if its implementation were more flexible in this specific way.