diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-05-20 15:18:57 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-05-20 15:19:10 -0400 |
commit | 666488e32463231ebb857d6480dd8f520c622199 (patch) | |
tree | 315aa739002e1f28ea0395f47fc458929825b1ef /vim/ftplugin | |
parent | 23a3336c0d2c65306a9cb1aeb386bbe24f8b38a5 (diff) | |
download | conf-666488e32463231ebb857d6480dd8f520c622199.tar.gz conf-666488e32463231ebb857d6480dd8f520c622199.zip |
use zathura and synctex for latex editing
Diffstat (limited to 'vim/ftplugin')
-rw-r--r-- | vim/ftplugin/tex.vim | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/vim/ftplugin/tex.vim b/vim/ftplugin/tex.vim index 1a43f9e..ef754e9 100644 --- a/vim/ftplugin/tex.vim +++ b/vim/ftplugin/tex.vim @@ -1,32 +1,61 @@ let b:tex_flavor="latex" " :make converts to pdf -setlocal makeprg=(cd\ /tmp\ &&\ pdflatex\ --halt-on-error\ %:p) +setlocal makeprg=(cd\ /tmp\ &&\ pdflatex\ --synctex=1\ --halt-on-error\ %:p) " xpdf needs to be manually refreshed when the file changes function! s:xpdf() - let l:pdf = '/tmp/' . expand('<afile>:t:r') . '.pdf' - let l:processes = split(system('ps xo args'), '\n') - for l:process in l:processes - if l:process =~ 'xpdf -remote localhost' - call system('xpdf -remote localhost -reload') - return - endif - endfor - call system('xpdf -remote localhost ' . l:pdf . ' &') + if s:is_running('xpdf -remote localhost') + call system('xpdf -remote localhost -reload') + return + endif + call system('xpdf -remote localhost ' . s:current_pdf() . ' &') endfunction " evince treats opening the same file twice as meaning 'reload' function! s:evince() - let l:pdf = '/tmp/' . expand('<afile>:t:r') . '.pdf' - call system('evince ' . l:pdf . ' &') + call system('evince ' . s:current_pdf() . ' &') +endfunction + +" zathura automatically reloads +function! s:zathura() + if s:is_running('^zathura') + return + endif + call remote_startserver("vim-zathura") + call system('zathura --fork -x "vim --servername vim-zathura --remote +%{line} %{input}" ' . s:current_pdf()) +endfunction + +function! s:current_pdf() + let base = expand('<afile>:t:r') + if base == '' + let base = expand('%:t:r') + endif + return '/tmp/' . base . '.pdf' +endfunction + +function! s:is_running(re) + let processes = split(system('ps xo args'), '\n') + for process in processes + if process =~ a:re + return 1 + endif + endfor + return 0 +endfunction + +function! Synctex() + if s:is_running('^zathura') + exe "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . expand('%:p') . " " . s:current_pdf() + redraw + endif endfunction " don't load the pdf if the make failed function! s:make_errors() - let l:qf = getqflist() - for l:line in l:qf - if l:line['type'] == 'E' + let qf = getqflist() + for line in qf + if line['type'] == 'E' return 1 endif endfor @@ -35,23 +64,26 @@ endfunction let b:automake_enabled = 0 function! s:automake() - let l:old_shellpipe = &shellpipe + let old_shellpipe = &shellpipe let &shellpipe = '>' try silent make! finally - let &shellpipe = l:old_shellpipe + let &shellpipe = old_shellpipe endtry endfunction augroup _tex autocmd! - if executable('xpdf') && strlen(expand('$DISPLAY')) - autocmd QuickFixCmdPost make if !s:make_errors() | call s:xpdf() | endif + if executable('zathura') && strlen(expand('$DISPLAY')) + autocmd QuickFixCmdPost make if !s:make_errors() | call s:zathura() | endif + elseif executable('xpdf') && strlen(expand('$DISPLAY')) + autocmd QuickFixCmdPost make if !s:make_errors() | call s:xpdf() | endif elseif executable('evince') && strlen(expand('$DISPLAY')) - autocmd QuickFixCmdPost make if !s:make_errors() | call s:evince() | endif + autocmd QuickFixCmdPost make if !s:make_errors() | call s:evince() | endif endif autocmd CursorHold,CursorHoldI,InsertLeave <buffer> if b:automake_enabled | call s:automake() | endif + autocmd CursorMoved <buffer> call Synctex() augroup END noremap <buffer> <silent><F6> :let b:automake_enabled = !b:automake_enabled<CR><F5> |