Closed jordwalke closed 6 years ago
This looks like a better approach than my reliance on vim's nohidden+confirm
behavior. I'll try this patch and probably merge it manually.
I'm using it and it's pretty reliable so far. We need more testing though. The downside was that I had to come up with something that works in all cases like unnamed buffers, buffers where the undo stack is past/before the last save point. Vim really should have a command "return to the last save point for this buffer".
There's one minor downside to my current approach. If you made changes without saving, that would ideally leave "redo" commits when you reopen the file next time, if you use Vim's persistent (awesome) undo like I do. With this approach, the :e!
command will remove those if you choose not to save. It's pretty minor - it's as if you had done :e!
yourself before closing the file.
But there's no other way it seems. Vim doesn't have a way to "return to last saved position" - any combination of :earlier 1f/0f
/ :later 1f/0f
had some problem.
After this, I think we should add a similar feature for when you do :WintabsCloseWindow
. When you do something like closing multiple tabs/windows in MacVim, it checks if there exists any buffer in all the tabs that are about to be closed and asks you what to do. If there's just one with unsaved changes, it has the same experience as this PR. If there's multiple - it gives you several options - we can recreate this:
It cycles one by one through all the unsaved docs, asking you what to do with each one but also letting you select "Discard All" to stop cycling and abandon all changes.
@jordwalke I implemented something similar in the recent commits - try to save buffer at the beginning of wintabs#close instead of doing it using nohidden+confirm. But instead of using a custom save dialog, I'm relying on confirm edit
since this dialog is i18n'ed.
I'm closing this PR, but please let me know if there are bugs in my implementation.
Bug:
I think before doing anything in WinClose, we should first get the file to "a non-problematic state". That means revert it if it's not opened in any other tab. This way we don't have to deal with the endless complexities that vim throws at us with listed/unlisted buffers - where we don't find out about errors before it's too late.
This might allow you to remove other parts of the code that acts defensively.