Fix #632: Refresh viewer paths when changing main
This commit is contained in:
parent
1cd633d6ba
commit
7046490ce2
@ -195,6 +195,7 @@ function! vimtex#toggle_main() " {{{1
|
|||||||
\ ? b:vimtex_local.sub_id
|
\ ? b:vimtex_local.sub_id
|
||||||
\ : b:vimtex_local.main_id
|
\ : b:vimtex_local.main_id
|
||||||
let b:vimtex = g:vimtex_data[b:vimtex_id]
|
let b:vimtex = g:vimtex_data[b:vimtex_id]
|
||||||
|
call b:vimtex.viewer.refresh_paths()
|
||||||
|
|
||||||
call vimtex#echo#status(['vimtex: ',
|
call vimtex#echo#status(['vimtex: ',
|
||||||
\ ['Normal', 'Changed to `'],
|
\ ['Normal', 'Changed to `'],
|
||||||
|
@ -4,6 +4,13 @@
|
|||||||
" Email: karl.yngve@gmail.com
|
" 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
|
function! vimtex#view#common#apply_xwin_template(class, viewer) " {{{1
|
||||||
let a:viewer.class = a:class
|
let a:viewer.class = a:class
|
||||||
let a:viewer.xwin_id = 0
|
let a:viewer.xwin_id = 0
|
||||||
@ -12,20 +19,6 @@ function! vimtex#view#common#apply_xwin_template(class, viewer) " {{{1
|
|||||||
return a:viewer
|
return a:viewer
|
||||||
endfunction
|
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
|
" }}}1
|
||||||
function! vimtex#view#common#not_readable(output) " {{{1
|
function! vimtex#view#common#not_readable(output) " {{{1
|
||||||
if !filereadable(a:output)
|
if !filereadable(a:output)
|
||||||
@ -38,6 +31,40 @@ endfunction
|
|||||||
|
|
||||||
" }}}1
|
" }}}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 = {}
|
let s:xwin_template = {}
|
||||||
|
|
||||||
function! s:xwin_template.view(file) dict " {{{1
|
function! s:xwin_template.view(file) dict " {{{1
|
||||||
@ -130,23 +157,4 @@ endfunction
|
|||||||
|
|
||||||
" }}}1
|
" }}}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
|
" vim: fdm=marker sw=2
|
||||||
|
@ -30,7 +30,7 @@ function! vimtex#view#general#new() " {{{1
|
|||||||
"
|
"
|
||||||
" Start from standard template
|
" 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
|
" Add callback hook
|
||||||
|
@ -33,7 +33,7 @@ function! vimtex#view#mupdf#new() " {{{1
|
|||||||
" Use the xwin template
|
" Use the xwin template
|
||||||
"
|
"
|
||||||
return vimtex#view#common#apply_xwin_template('MuPDF',
|
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
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
@ -32,7 +32,7 @@ function! vimtex#view#zathura#new() " {{{1
|
|||||||
" Use the xwin template
|
" Use the xwin template
|
||||||
"
|
"
|
||||||
return vimtex#view#common#apply_xwin_template('Zathura',
|
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
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
Loading…
Reference in New Issue
Block a user