xuhdev / vim-latex-live-preview

A Vim Plugin for Lively Previewing LaTeX PDF Output
https://www.topbug.net/blog/2013/06/13/live-preview-of-latex-in-vim/
GNU General Public License v3.0
832 stars 73 forks source link

Swap warning #7

Closed tomaszwojcik closed 7 years ago

tomaszwojcik commented 10 years ago

Hello

I use MacTeX and Mac OS X Preview as my preview program. When I start the :LLPStartPreview and save the file I get the following error:

"latex-test.tex" 10L, 207C written
Error detected while processing function <SNR>60_Compile:
line   10:
E768: Swap file exists: /Users/twojcik/.vim_tmp/latex-test.tex.swp (:silent! overrides)

I don't want to disable the swap.

xuhdev commented 10 years ago

It should not happen though. Can you stop Vim and see whether the file still exists? The warning should come because there IS a file with a name of latex-test.tex.swp there.

tomaszwojcik commented 10 years ago

I've tried that. After quitting Vim the swap file is erased.

xuhdev commented 10 years ago

I see the problem now. It's because you have set swp file to a specific directory, but the command to create a temp file also asks Vim to create the exact same file in that directory. This would not be a problem if you always have swp file in the same directory.

Anyway, this is a bug and I'm gonna fix it.

xuhdev commented 10 years ago

Hold on -- seems this is a problem of your configuration or a bug in Vim. Can you post the part of configuration which you set the path of the swp file?

tomaszwojcik commented 10 years ago

My tmp/backup config:

set backupdir=~/.vim_bck
set directory=~/.vim_tmp
xuhdev commented 10 years ago

OK, the problem is found.

Open any file with Vim with your configuration, run the following command twice:

:write! /tmp/the_file_name.ext

You'll see the error message pops up. Because Vim thinks this file has a corresponding swp file. Seems this is a defect that Vim doesn't create a prefix for the swap files for files in different directories.

Try to add the following to your vimrc file and apply this patch. Let me know whether it works for you.

autocmd BufEnter *.tex  let b:livepreview_buf_data['tmp_src_file'] = '/tmp/my_name.tex'
tomaszwojcik commented 10 years ago

After applying the patch and adding command to the vimrc I open any tex file and I get the following error:

Error detected while processing BufEnter Auto commands for "*.tex":
E121: Undefined variable: b:livepreview_buf_data
tekhnus commented 9 years ago

Just add double slashes to paths in your config to avoid name collision:

set backupdir=~/.vim_bck//
set directory=~/.vim_tmp//

(This will prefix swap file names with abolute paths)

nhooyr commented 8 years ago

harius's solution worked great for me.

satvug commented 7 years ago

Your solution worked for me too, harius - thanks!

badouralix commented 7 years ago

As the name of the file written in the tmp dir is essential to make the plugin work on a multi files project, the only lasting solution is to use @harius trick. I'm closing this issue after referencing it in the project readme. Feel free to re-open it whether something related happens.