From 2139057fe4a9c9a5495472c8e321f4ed0e66810d Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Mon, 16 Aug 2021 22:44:16 -0400 Subject: [PATCH 1/3] Zathura backward search: --remote-expr for latexmk In the latexmk command line, make sure that --remote-expr is used instead of --remote for SyncTeX backwards search when opening Zathura. This ensures consistency between starting compilation via ll and opening the viewer separately via lv. Refer https://github.com/lervag/vimtex/issues/2127#issuecomment-897950923 --- autoload/vimtex/view/zathura.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimtex/view/zathura.vim b/autoload/vimtex/view/zathura.vim index 95235783b5..78fc8d85c2 100644 --- a/autoload/vimtex/view/zathura.vim +++ b/autoload/vimtex/view/zathura.vim @@ -80,7 +80,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-expr \"\\\"\"vimtex#view#reverse_goto(\%{line}, ''"''"''\%{input}''"''"'')\"\\\"\"\" \%S' endif let cmd = vimtex#compiler#latexmk#wrap_option('new_viewer_always', '0') From 9af661097f15af588cd572f25397cd2f4c451dc8 Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Mon, 16 Aug 2021 23:07:55 -0400 Subject: [PATCH 2/3] Backward search: better support for tab pages When a file is open in a different tab page, make sure to switch to that tab page when SyncTeX backward search requests that file. The previous behavior was to use bufwinnr, which does not look at windows in other tab pages and therefore acts as if the buffer is not open anywhere. Refer https://stackoverflow.com/a/42628934 --- autoload/vimtex/view.vim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/autoload/vimtex/view.vim b/autoload/vimtex/view.vim index 34966884ce..5c6632e0bd 100644 --- a/autoload/vimtex/view.vim +++ b/autoload/vimtex/view.vim @@ -87,11 +87,18 @@ function! vimtex#view#reverse_goto(line, filename) abort " {{{1 endif " Go to correct buffer and line + + " Get buffer number let l:bufnr = bufnr(l:file) - let l:winnr = bufwinnr(l:file) - execute l:winnr >= 0 - \ ? l:winnr . 'wincmd w' - \ : 'buffer ' . l:bufnr + " Get window and tab numbers + try + let [l:winid] = win_findbuf(l:bufnr) + let [l:tabnr, l:winnr] = win_id2tabwin(l:winid) + execute l:tabnr . 'tabnext' + execute l:winnr . 'wincmd w' + catch + execute 'edit' l:file + endtry execute 'normal!' a:line . 'G' redraw From b003fee92d5b4ea5179f5801a3f554506dccdb95 Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Mon, 16 Aug 2021 23:12:17 -0400 Subject: [PATCH 3/3] Add option vimtex_view_reverse_search_edit_cmd This option controls the command that is used to open new files from SyncTeX backward search in multi-file projects. Refer #2127 --- autoload/vimtex/options.vim | 1 + autoload/vimtex/view.vim | 6 +++--- doc/vimtex.txt | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/autoload/vimtex/options.vim b/autoload/vimtex/options.vim index cf03c8eee9..5502286eaf 100644 --- a/autoload/vimtex/options.vim +++ b/autoload/vimtex/options.vim @@ -378,6 +378,7 @@ function! vimtex#options#init() abort " {{{1 call s:init_option('vimtex_view_method', 'general') call s:init_option('vimtex_view_use_temp_files', 0) call s:init_option('vimtex_view_forward_search_on_start', 1) + call s:init_option('vimtex_view_reverse_search_edit_cmd', 'edit') " OS dependent defaults let l:os = vimtex#util#get_os() diff --git a/autoload/vimtex/view.vim b/autoload/vimtex/view.vim index 5c6632e0bd..4f5acc23c0 100644 --- a/autoload/vimtex/view.vim +++ b/autoload/vimtex/view.vim @@ -72,10 +72,10 @@ function! vimtex#view#reverse_goto(line, filename) abort " {{{1 let l:file = resolve(a:filename) " Open file if necessary - if !bufexists(l:file) + if !bufloaded(l:file) if filereadable(l:file) try - execute 'edit' l:file + execute g:vimtex_view_reverse_search_edit_cmd l:file catch call vimtex#log#warning("Reverse goto failed") return @@ -97,7 +97,7 @@ function! vimtex#view#reverse_goto(line, filename) abort " {{{1 execute l:tabnr . 'tabnext' execute l:winnr . 'wincmd w' catch - execute 'edit' l:file + execute g:vimtex_view_reverse_search_edit_cmd l:file endtry execute 'normal!' a:line . 'G' diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 3519d87aec..bfea40dc4f 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -2743,6 +2743,18 @@ OPTIONS *vimtex-options* Default value: 1 +*g:vimtex_view_reverse_search_edit_cmd* + When working in a multi-file project, initiating backward search + |vimtex-synctex-backward-search| may require opening a file that is not + currently open in a window. This option controls the command that is used to + open files as a result of a backward search. + + Examples: `edit` (open buffer in current window); `tabedit` (open buffer in + new tab page, similar to the Vim command-line option `--remote-tab`); + `split` (split current window to open buffer, similar to `--remote`) + + Default value: `edit` + *g:vimtex_view_method* Set the viewer method.