chrisbra / Recover.vim

A Plugin to show a diff, whenever recovering a buffer
http://www.vim.org/scripts/script.php?script_id=3068
247 stars 25 forks source link

Automatically delete swap file if no changes #1

Closed y closed 12 years ago

y commented 13 years ago

I ran across this simple plugin which automatically deletes the swapfile if it contains no differences: https://github.com/godlygeek/vim-files/blob/master/plugin/SwapExistsDiff.vim

Can you implement similar functionality in your plugin?

chrisbra commented 13 years ago

Thanks. I look into it.

regards, Christian

chrisbra commented 13 years ago

Please try the current version.This is an experimental version, but seems to do what you like.

y commented 13 years ago

Nice. Further thoughts- when opening the same file from two different vim processes, I would not let the second vim process recover from and delete the swapfile if the first instance is still running. Also would it be possible to allow the user the diff option in addition to the original list of options? I frequently want to abort or quit, especially if the swap file is the result of another running vim instance.

chrisbra commented 13 years ago

Yes, that is exactly the problem, why I am unsure about deleting swap files. As far as I know, there is no possibility, to know from within Vim whether a different Vim session is editing the same file. (May be, this feature needs a patch to the Vim source) I need to think about a workaround. The other options should be possible as well.

y commented 13 years ago

The swap file does indicate the process id, so it could be possible to check if that process were still alive and if it was named vim. But i'm not sure if that could be done in a portable way.

chrisbra commented 13 years ago

I know. But I think, Vim does not make this information available through its interface. You basically only know, whenever Vim shows its recovery dialog. That's what I mean when I said Vim needs a patch.

chrisbra commented 13 years ago

How about, we install an extra autocommand, that checks, whether the swapfile still exists, and if not, recreates the swap file? Would that work until a better approach with Vim can be found?