chrisbra / Recover.vim

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

Req. for Enhancement: auto-delete if no changes & nobody editing #46

Closed Astara closed 7 years ago

Astara commented 7 years ago

It would really be a nice enhancement if a value could be set in my .vimrc ... something like let g:Recover_delete_redundant_swaps=1

(or any other easy way to do it... )

If it didn't have the problem of not detecting file already being edited, I'd just hack in Delete as a default in my local copy (not knowing much about vim scripting, I used the 'mod' (posted at end in 'diff -u' (patch) form), but it also deletes the file when someone else is editing it ;-(

(Usually me, but in some forgotten window that's been minimized... ;-))...

> diff -u recover.vim recover.vim
--- recover.vim.orig  2017-03-14 15:34:47.000000000 -0700
+++ recover.vim 2017-03-14 16:26:33.604411520 -0700
@@ -174,10 +174,11 @@
     if not_modified
  let p = 3
     else
- call inputsave()
- let p = confirm(info, cmd, (delete ? 7 : 1), 'I')
+    "  call inputsave()
+    "  let p = confirm(info, cmd, (delete ? 7 : 1), 'I')
     "    endif
- call inputrestore()
+        let p = 7
+    "  call inputrestore()
     endif
     let b:swapname=v:swapname
     if p == 1 || p == 3
@@ -213,7 +214,7 @@
     elseif p == 7
  " Delete Swap file, if not different
  call s:SwapChoice('d')
- call <sid>EchoMsg("Found SwapFile, deleting...")
+ "call <sid>EchoMsg("Found SwapFile, deleting...")
  " might trigger SwapExists again!
  call s:SetSwapfile()
     else
chrisbra commented 7 years ago

wait a second. It already detects if the file is already edited in another Vim instance. And in that case it does not delete the swap file. That is the correct solution.

Astara commented 7 years ago

Yes, that is the correct solution, but it also doesn't delete the swap file if there IS no other Vim instance with the file open (and there are no changes).

I'm proposing that:

1) if a file is not open in another window, AND 2) it is not modified,

then there there be a config-option to auto-delete the swap file... does that sound more reasonable (and clear?)...

chrisbra commented 7 years ago

okay, please check again (and also see the help for how to configure it this way).

Astara commented 7 years ago

Getting this error:

Error detected while processing function recover#ConfirmSwapDiff:
line   28:
E706: Variable type mismatch for: msg
line   32:
E714: List required
0
Swap and on-disk file seem to be identical
Swap File '.dataspec.h.swp' found: 
D(i)ff, (O)pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort, [D]elete:

....

If I try to edit it without "recover.vim" in my .vim folder, I get the expected message:

E325: ATTENTION
Found a swap file by the name ".dataspec.h.swp"
          owned by: astara  dated: Wed Mar 15 01:38:01 2017
         file name: /home/tools/xosview/xosview-1.90/src/dataspec.h
          modified: no
         user name: astara host name: Ishtar
        process ID: 65559 (still running)
While opening file "dataspec.h"
             dated: Mon Mar 13 20:18:20 2017

I think I broke it... :-(

sigh... have to go to dentist, so might be slow in getting back for another test...

chrisbra commented 7 years ago

Oops, should be fixed now.

Astara commented 7 years ago

Better... no error messages now.. In the case of the file unchanged, but open in another window (or by another user), it shows the full warning about it being edited... which is good.

But a few things when no one is editing the file (and its unchanged).;

1) Gvim comes up with a blank screen, and at the bottom it says "Press Enter or type command to continue".

The you press enter, and you see the file, but the "Press Enter or type command to continue" message is still at the bottom.

2) (this may be intentional) the 2nd opening of the file doesn't delete the old swap file, but acts as though you chose "Edit anyway".

If the swap file is same as the original, why keep the old one?

Looking better. :-) Tnx!

chrisbra commented 7 years ago

1) I don't see that message. I see gvim flashing the swapfileexists dialog and then it opens up. 2) I rather not delete anything by default.

Astara commented 7 years ago

This: gvim-2nd-ed is the message I see now, when opening meter.cc a second time.

As for not deleting anything by default -- I won't push too much on that -- if I can do something similar as before and modify script to do so for me. Else .. 2 things 1) maybe you could include a variable that someone would set in .vimrc or .gvimrc like is done for syntax files, like for bash shell... uses .sh syntax, but one can set: let g:is_bash=1

or 2) regarding not deleting... if this is case, we are talking about deleting a "swp" file that isn't in use (right?) and that swap file has no changes compared to the original file, right?

So why would someone want to keep it?

(For me, I don't, which is why I ask why someone would want to keep it?

But if you an think of any reason why someone would not want it deleted, when it contains no difference, and doesn't indicate another user... ...then why not?

? A*a