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-preview in 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:changedtick is 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.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Something like traces.vim would be awesome to have built-in.
https://github.com/markonm/traces.vim
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #19624 as resolved.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()