Closed kaihowl closed 9 years ago
Thank you for your issue.
I do not use the compile-features of the suite. However, I would be interested in a pull-request. As you wrote, the best fix would be to make origdir a local variable in all files/functions.
Ok. I'll work up a PR next weekend.
PR ready to go. Let me know if that works for you.
Thank you for your contribution!
I tried the vim-latex-devel list already but to no avail so far. Since development on latexsuite seems rather dead, I am thinking of contributing the fix to this fork instead.
The current project I am using vim-latex on has a main file including several sections from files in a folder sections/. If I callll while editing sections/foo.tex, vim-latex will return from compilation correctly but also set cwd to sections/. This is unexpected behavior for me. I would not expect compilation to suddenly change the working directory.
I dug into the source code and came to the following conclusion: s:origdir is used throughout the source code to save the cwd at the beginning of a function and later restore it. Unfortunately, s:origdir is a script-local variable. Therefore, reusing the method of "save cwd to s:origdir and restore" will not work if calls of functions using this method are nested.
This is exactly the source of my unexpected change of cwd after compilation. tex_RunLaTeX saves the correct cwd to s:origdir. It then changes the working directory. This is followed by calling tex_CompileLaTex() at some point, which will save the wrong cwd again to s:origdir and thus overrides the old, but correct cwd. By extension, the final restore of cwd at the end of tex_RunLaTeX will then restore the the incorrect directory, which in my case is the subdirectory sections/.
As a simple solution, I propose to substitute s:origdir with l:origdir or simply origdir as I see no compelling reason to make origdir a script-local variable. A simple "%s/s:origdir/l:origdir/g" on ftplugin/latex-suite/compiler.vim solved the original issue for me. It also appears to be used in main.vim, texproject.vim, and texviewer.vim. The same fix will probably apply there as well.
Are you willing to accept a pull request on this?