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

this plugin seems to no longer work #71

Closed jinyius closed 2 years ago

jinyius commented 3 years ago

been using this plugin happily for awhile, but it stopped working on my mbp. here's the output when trying to open an already open file (shows the E325 error and the swap file options are the typical ones):

"../Makefile" 44L, 1687B
Error detected while processing BufWinEnter Autocommands for "*"..function recover#CheckSwapFileExists[8]..<SNR>67_SetSwapfile:
line    3:
E325: ATTENTION
Found a swap file by the name "~/.vim/tmp//%Users%user%.vim%bundle%Recover.vim%Makefile.swp"
          owned by: user   dated: Tue Nov 09 20:36:01 2021
         file name: ~user/.vim/bundle/Recover.vim/Makefile
          modified: no
         user name: user   host name: xxx.local
        process ID: 19486 (STILL RUNNING)
While opening file "../Makefile"
             dated: Mon Feb 15 16:01:51 2021

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r ../Makefile"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/user/.vim/tmp//%Users%user%.vim%bundle%Recover.vim%Makefile.swp"
    to avoid this message.

Swap file "~/.vim/tmp//%Users%user%.vim%bundle%Recover.vim%Makefile.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort: 

macOS 12.0.1 vim --version (system /usr/bin/vim)

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct  1 2021 22:47:36)
macOS version - x86_64
Included patches: 1-2671
Compiled by root@apple.com
Normal version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
-arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      -mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        -termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
-balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            -gettext           +netbeans_intg     +termresponse
+builtin_terms     -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              -perl              +title
-clientserver      +job               +persistent_undo   -toolbar
+clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     -keymap            +postscript        -vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      -langmap           -profile           +virtualedit
+comments          +libcall           -python            +visual
-conceal           +linebreak         -python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          -rightleft         +wildignore
+cursorshape       -lua               +ruby/dyn          +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
-emacs_tags        -mouse_dec         +startuptime       -xpm
+eval              -mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      -mouse_netterm     +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa 
chrisbra commented 3 years ago
"../Makefile" 44L, 1687B
Error detected while processing BufWinEnter Autocommands for "*"..function recover#CheckSwapFileExists[8]..<SNR>67_SetSwapfile:
line    3:

is that the whole error message? I am wondering, because Line 3 is actually this one:

https://github.com/chrisbra/Recover.vim/blob/5b496fbf6d2b989d93f1748340d1a43c6d80766f/autoload/recover.vim#L367

Not sure what goes wrong there. Try to remove the :sil or change it to :sil! to ignore the error. Don't know if this helps.

jinyius commented 2 years ago

removing the sil so it's just the setl... causes the error to continue to be thrown.

making it sil! causes things such that starting up to open the file never completes unless you hit ^C to break. i then tried using setl! but it also does nothing.

what should be the behavior when a swp file exists due to the file already being open?

chrisbra commented 2 years ago

I don't understand. of course it doesn't help. I'd like to see the whole output, something causing the error. So if you manually do :setl noswapfile swapfile do you see an error message? Perhaps there is already another swapfile lying around? Or another SwapExists autocommand is triggered? I don't know yet.

what should be the behavior when a swp file exists due to the file already being open?

the idea is to close and re-open the swapfile, because it could have changed.

jinyius commented 2 years ago

here's what i did for your last message:

  1. open a file in one vim instance (creates a .swp file)
  2. open the same file in a different vim instance (with Recover.vim in place)
  3. hit this issue
  4. open the file read-only
  5. trigger :setl noswapfile swapfile
  6. observe this output:
    
    E325: ATTENTION
    Found a swap file by the name "~/.vim/tmp//%Users%user%.dotfiles%.zshrc.swp"
          owned by: user   dated: Thu Nov 18 08:50:09 2021
         file name: ~user/.zshrc
          modified: no
         user name: user   host name: xxx
        process ID: 29984 (STILL RUNNING)
    While opening file ".zshrc"
             dated: Tue Sep 21 09:22:54 2021

(1) Another program may be editing the same file. If this is the case, be careful not to end up with two different instances of the same file when making changes. Quit, or continue with caution. (2) An edit session for this file crashed. If this is the case, use ":recover" or "vim -r .zshrc" to recover the changes (see ":help recovery"). If you did this already, delete the swap file "/Users/jin/.vim/tmp//%Users%user%.dotfiles%.zshrc.swp" to avoid this message.

Press ENTER or type command to continue



using the "Edit anyway" option yields the same result.  choosing Recover only causes the noswap/swap local setting to pass w/o error.
anjiro commented 2 years ago

I'm having this problem as well. On my system, it looks like the problem is in s:Swapname():

https://github.com/chrisbra/Recover.vim/blob/5b496fbf6d2b989d93f1748340d1a43c6d80766f/autoload/recover.vim#L28

The return a[:1] cuts off the leading /, changing /Users/me/myfile.txt to Users/me/myfile.txt. Then filereadable() is 0:

https://github.com/chrisbra/Recover.vim/blob/5b496fbf6d2b989d93f1748340d1a43c6d80766f/autoload/recover.vim#L62-L67

and the setl command to reset the swapfile

https://github.com/chrisbra/Recover.vim/blob/5b496fbf6d2b989d93f1748340d1a43c6d80766f/autoload/recover.vim#L367

barfs as reported above.

I'm not clear on why the [1:] is there, but one fix is to change line 28 to

    return a[0] ==# '/' ? a : a[1:]
chrisbra commented 2 years ago

ah, that trim removes the leading \n that is out there and is also there when using redir. Can you create a PR for that change? Simply change the condition a[0] ==# '\n' ? a[1:] : a