From 7046490ce20ee78f109f14fb0bede1808820f9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 4 Dec 2016 13:03:17 +0100 Subject: [PATCH] Fix #632: Refresh viewer paths when changing main --- autoload/vimtex.vim | 1 + autoload/vimtex/view/common.vim | 74 ++++++++++++++++++-------------- autoload/vimtex/view/general.vim | 2 +- autoload/vimtex/view/mupdf.vim | 2 +- autoload/vimtex/view/zathura.vim | 2 +- 5 files changed, 45 insertions(+), 36 deletions(-) diff --git a/autoload/vimtex.vim b/autoload/vimtex.vim index fffa696..3fc9e7c 100644 --- a/autoload/vimtex.vim +++ b/autoload/vimtex.vim @@ -195,6 +195,7 @@ function! vimtex#toggle_main() " {{{1 \ ? b:vimtex_local.sub_id \ : b:vimtex_local.main_id let b:vimtex = g:vimtex_data[b:vimtex_id] + call b:vimtex.viewer.refresh_paths() call vimtex#echo#status(['vimtex: ', \ ['Normal', 'Changed to `'], diff --git a/autoload/vimtex/view/common.vim b/autoload/vimtex/view/common.vim index 43265a5..9b3d729 100644 --- a/autoload/vimtex/view/common.vim +++ b/autoload/vimtex/view/common.vim @@ -4,6 +4,13 @@ " Email: karl.yngve@gmail.com " +function! vimtex#view#common#apply_common_template(viewer) " {{{1 + call extend(a:viewer, deepcopy(s:common_template)) + call a:viewer.refresh_paths() + return a:viewer +endfunction + +" }}}1 function! vimtex#view#common#apply_xwin_template(class, viewer) " {{{1 let a:viewer.class = a:class let a:viewer.xwin_id = 0 @@ -12,20 +19,6 @@ function! vimtex#view#common#apply_xwin_template(class, viewer) " {{{1 return a:viewer endfunction -" }}}1 -function! vimtex#view#common#use_temp_files_p(viewer) " {{{1 - if g:vimtex_view_use_temp_files - let a:viewer.out = b:vimtex.root . '/' . b:vimtex.name . '_vimtex.pdf' - let a:viewer.synctex = fnamemodify(a:viewer.out, ':r') . '.synctex.gz' - let a:viewer.copy_files = function('s:copy_files') - else - let a:viewer.out = b:vimtex.out(1) - let a:viewer.synctex = fnamemodify(a:viewer.out, ':r') . '.synctex.gz' - endif - - return a:viewer -endfunction - " }}}1 function! vimtex#view#common#not_readable(output) " {{{1 if !filereadable(a:output) @@ -38,6 +31,40 @@ endfunction " }}}1 +let s:common_template = {} + +function! s:common_template.refresh_paths() dict " {{{1 + if g:vimtex_view_use_temp_files + let self.out = b:vimtex.root . '/' . b:vimtex.name . '_vimtex.pdf' + else + let self.out = b:vimtex.out(1) + endif + + let self.synctex = fnamemodify(self.out, ':r') . '.synctex.gz' +endfunction + +" }}}1 +function! s:common_template.copy_files() dict " {{{1 + if !g:vimtex_view_use_temp_files | return | endif + + " + " Copy pdf file + " + if getftime(b:vimtex.out()) > getftime(self.out) + call writefile(readfile(b:vimtex.out(), 'b'), self.out, 'b') + endif + + " + " Copy synctex file + " + let l:old = b:vimtex.ext('synctex.gz') + if getftime(l:old) > getftime(self.synctex) + call rename(l:old, self.synctex) + endif +endfunction + +" }}}1 + let s:xwin_template = {} function! s:xwin_template.view(file) dict " {{{1 @@ -130,23 +157,4 @@ endfunction " }}}1 -function! s:copy_files() dict " {{{1 - " - " Copy pdf file - " - if getftime(b:vimtex.out()) > getftime(self.out) - call writefile(readfile(b:vimtex.out(), 'b'), self.out, 'b') - endif - - " - " Copy synctex file - " - let l:old = b:vimtex.ext('synctex.gz') - if getftime(l:old) > getftime(self.synctex) - call rename(l:old, self.synctex) - endif -endfunction - -" }}}1 - " vim: fdm=marker sw=2 diff --git a/autoload/vimtex/view/general.vim b/autoload/vimtex/view/general.vim index 55b2add..ac31e39 100644 --- a/autoload/vimtex/view/general.vim +++ b/autoload/vimtex/view/general.vim @@ -30,7 +30,7 @@ function! vimtex#view#general#new() " {{{1 " " Start from standard template " - let l:viewer = vimtex#view#common#use_temp_files_p(deepcopy(s:general)) + let l:viewer = vimtex#view#common#apply_common_template(deepcopy(s:general)) " " Add callback hook diff --git a/autoload/vimtex/view/mupdf.vim b/autoload/vimtex/view/mupdf.vim index b57cc8c..e6ca3fb 100644 --- a/autoload/vimtex/view/mupdf.vim +++ b/autoload/vimtex/view/mupdf.vim @@ -33,7 +33,7 @@ function! vimtex#view#mupdf#new() " {{{1 " Use the xwin template " return vimtex#view#common#apply_xwin_template('MuPDF', - \ vimtex#view#common#use_temp_files_p(deepcopy(s:mupdf))) + \ vimtex#view#common#apply_common_template(deepcopy(s:mupdf))) endfunction " }}}1 diff --git a/autoload/vimtex/view/zathura.vim b/autoload/vimtex/view/zathura.vim index c8568fa..54c3ba0 100644 --- a/autoload/vimtex/view/zathura.vim +++ b/autoload/vimtex/view/zathura.vim @@ -32,7 +32,7 @@ function! vimtex#view#zathura#new() " {{{1 " Use the xwin template " return vimtex#view#common#apply_xwin_template('Zathura', - \ vimtex#view#common#use_temp_files_p(deepcopy(s:zathura))) + \ vimtex#view#common#apply_common_template(deepcopy(s:zathura))) endfunction " }}}1