-
Notifications
You must be signed in to change notification settings - Fork 409
Description
Problem
The SyncTeX support for Zathura is excellent out of the box, but I noticed that the backward search command line is hard-coded to use --remote-expr to call vimtex#view#reverse_goto:
vimtex/autoload/vimtex/view/zathura.vim
Lines 38 to 41 in 078292e
| let l:cmd .= ' -x "' . g:vimtex_compiler_progname | |
| \ . ' --servername ' . v:servername | |
| \ . ' --remote-expr ' | |
| \ . '\"vimtex#view#reverse_goto(%{line}, ''%{input}'')\""' |
This function works well in single-file projects, but I noticed a few problems when switching files in multi-file projects. Specifically, consider the case that a project has files a.tex and b.tex, my Vim currently has a.tex open, and I perform a reverse search from a place in the PDF that corresponds to b.tex line 50.
- If
a.texhas unsaved changes, then VimTeX focusesa.texline 50. This seems to be because thesilent editfails here:
vimtex/autoload/vimtex/view.vim
Lines 74 to 77 in 078292e
" Open file if necessary if !bufexists(l:file) if filereadable(l:file) execute 'silent edit' l:file - If
a.texdoes not have unsaved changes, thenb.textakes over the buffer where I was editinga.tex. While this may be desirable behavior for other users, I would prefer thatb.texopen in a new tab page.
Suggested solutions/workarounds
I suppose that the first bullet point is a bug and should be fixed globally, but that the second bullet point hinges on subjective preferences. So, I propose that the first part be fixed e.g. by splitting the window, which is what Vim's --remote argument does. To address the tab page issue, I think it would be a good idea to make the behavior configurable.
Alternatively, the use of --remote-expr (as opposed to --remote or --remote-tab) could be made configurable. The stopgap solution that I am using right now is changing the hard-coded --remote-expr to use --remote-tab, and this seems to work fine.
My stopgap solution
diff --git a/autoload/vimtex/view/zathura.vim b/autoload/vimtex/view/zathura.vim
index 95235783..ec17b141 100644
--- a/autoload/vimtex/view/zathura.vim
+++ b/autoload/vimtex/view/zathura.vim
@@ -37,8 +37,7 @@ function! s:zathura.start(outfile) dict abort " {{{1
if self.has_synctex
let l:cmd .= ' -x "' . g:vimtex_compiler_progname
\ . ' --servername ' . v:servername
- \ . ' --remote-expr '
- \ . '\"vimtex#view#reverse_goto(%{line}, ''%{input}'')\""'
+ \ . ' --remote-tab +\%{line} \%{input}\"'
if g:vimtex_view_forward_search_on_start
let l:cmd .= ' --synctex-forward '
\ . line('.')
@@ -80,7 +79,7 @@ function! s:zathura.latexmk_append_argument() dict abort " {{{1
if self.has_synctex
let zathura .= ' -x \"' . g:vimtex_compiler_progname
\ . ' --servername ' . v:servername
- \ . ' --remote +\%{line} \%{input}\" \%S'
+ \ . ' --remote-tab +\%{line} \%{input}\" \%S'
endif
let cmd = vimtex#compiler#latexmk#wrap_option('new_viewer_always', '0')I suppose that one could also work around this by using the general viewer and configuring everything manually, but this has obvious downsides.
Miscellany
Additionally, I noticed that --remote and not --remote-expr is used later in the same file, in s:zathura.latexmk_append_argument(). Is there a reason for this? Apologies if this (or anything else in this issue) has already been addressed elsewhere.
vimtex/autoload/vimtex/view/zathura.vim
Lines 79 to 84 in 078292e
| let zathura = 'zathura ' . g:vimtex_view_zathura_options | |
| if self.has_synctex | |
| let zathura .= ' -x \"' . g:vimtex_compiler_progname | |
| \ . ' --servername ' . v:servername | |
| \ . ' --remote +\%{line} \%{input}\" \%S' | |
| endif |