unison
unison copied to clipboard
persist recent scratch file saves?
Is your feature request related to a problem? Please describe.
Scratch files are meant for ephemeral use, but at times they have valuable content that hasn't been added to the codebase yet. It's fairly easy to accidentally lose scratch file contents, and it would be nice if there were a rescue ladder if this happens.
In a recent example I just made a blatant user error in which I accidentally deleted a scratch file that I still was working on and hadn't run a update on yet.
But there are more subtle ways that this can happen. For example say that you are working your way through a messy merge, fixing a bunch of compile errors. You can't update yet, because there are still compile errors in your scratch file, so you are just using LSP to go to the next compile error and hacking away until it is gone. Crucially you might not have saved your scratch file (since this isn't necessary to get LSP feedback). In your ucm console you run edit foo, which puts it into your scratch file. But you had unsaved changed in your scratch file. The behavior from here depends on your editor. For me vim warns me that the scratch file was changed but I have unsaved work in it. But sometimes I am a bit careless and hit enter. There are escape hatches like undo, but they go away when I've closed my editor.
Describe the solution you'd like
I'm not sure exactly, but a fairly simple solution that comes to mind is having something like the reflog but for scratch files. It could remember the content (perhaps just in raw text form) of the last N scratch file saves, with a way to peek at the content or load it into your current scratch file.
Describe alternatives you've considered
I haven't thought about it a lot. I pondered whether there is something that you can do that is better than saving the raw scratch file text (something more like ephemeral updates), but that seems to break down if your code hasn't gotten to a compiling state.