Replies: 1 comment
|
Something like |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I've been thinking on how to do this for the past couple of days, and here are my thoughts
Originally I was going to do this something like
'inccommand'or:command-previewin Neovim, however I have been thinking of a more generalized API that substitution preview would be based upon:Essentially a transaction on a buffer can be started, creating a sort of copy-on-write (like in filesystems) behaviour for the buffer. If a line is changed, then the underlying data block storing the line is not modified in place, instead a new copy is created. Any reads on the buffer (
:write,getline(), ...) would not be aware of the changes and use the original buffer contents before the transaction. However when drawing the buffer in the window, the changes will be displayed. When the transaction is "committed" finally, then the changes are actually merged with the buffer, and if the transaction is "discarded", then the changes are discarded.During a transaction:
b:changedtickis not modifiedThere would also be the risk of a transaction on a buffer not being matched with a "commit" or "discard" due to something like a bug in a plugin. The obvious solution to this would to be add a warning before exiting Vim, indicating that a transaction is ongoing.
There is also the risk of Vim crashing during a transaction, the solution to this would be make the buffer transaction feature be part of how Vim stores buffer text internally (
memline.c/memfile.c), so it is part of the swap file.There would also need to be feature to allow adding a callback as a User command is typed, however that shouldn't be too complex.
This explanation is definitely missing a lot of other things/nuances that I have been thinking of as well, and I may just be overcomplicating things a lot... However this is the gist of what I have thought of so far.
All reactions