Generalized view functionality
This commit is contained in:
parent
f9073001ec
commit
be02246fec
@ -14,6 +14,7 @@ function! latex#init() " {{{1
|
||||
|
||||
call latex#toc#init(s:initialized)
|
||||
call latex#fold#init(s:initialized)
|
||||
call latex#view#init(s:initialized)
|
||||
call latex#motion#init(s:initialized)
|
||||
call latex#change#init(s:initialized)
|
||||
call latex#latexmk#init(s:initialized)
|
||||
@ -104,27 +105,6 @@ function! latex#reinit() " {{{1
|
||||
\ endif
|
||||
silent execute 'buffer ' . n
|
||||
endfunction
|
||||
|
||||
function! latex#view(...) " {{{1
|
||||
let args = ' '
|
||||
if a:0 > 0
|
||||
let args .= join(a:000, ' ')
|
||||
else
|
||||
let outfile = g:latex#data[b:latex.id].out()
|
||||
if !filereadable(outfile)
|
||||
echomsg "Can't view: Output file is not readable!"
|
||||
return
|
||||
endif
|
||||
let args .= shellescape(outfile)
|
||||
endif
|
||||
|
||||
let exe = {}
|
||||
let exe.cmd = g:latex_viewer . args
|
||||
|
||||
call latex#util#execute(exe)
|
||||
|
||||
let g:latex#data[b:latex.id].cmds.view = exe.cmd
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
function! s:init_environment() " {{{1
|
||||
@ -169,13 +149,11 @@ function! s:init_environment() " {{{1
|
||||
|
||||
command! -buffer VimLatexInfo call latex#info()
|
||||
command! -buffer VimLatexHelp call latex#help()
|
||||
command! -buffer -nargs=* VimLatexView call latex#view('<args>')
|
||||
command! -buffer VimLatexReinitialize call latex#reinit()
|
||||
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> <localleader>li :call latex#info()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lh :call latex#help()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lv :call latex#view()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lR :call latex#reinit()<cr>
|
||||
endif
|
||||
endfunction
|
||||
@ -288,7 +266,7 @@ function! s:init_options() " {{{1
|
||||
call latex#util#set_default('g:latex_toc_secnumdepth', 3)
|
||||
call latex#util#set_default('g:latex_toc_split_side', 'leftabove')
|
||||
call latex#util#set_default('g:latex_toc_width', 30)
|
||||
call latex#util#set_default('g:latex_viewer', 'xdg-open')
|
||||
call latex#util#set_default('g:latex_view_enabled', 1)
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
|
124
autoload/latex/view.vim
Normal file
124
autoload/latex/view.vim
Normal file
@ -0,0 +1,124 @@
|
||||
" LaTeX plugin for Vim
|
||||
"
|
||||
" Maintainer: Karl Yngve Lervåg
|
||||
" Email: karl.yngve@gmail.com
|
||||
"
|
||||
|
||||
function! latex#view#init(initialized) " {{{1
|
||||
if !g:latex_view_enabled | return | endif
|
||||
|
||||
call latex#util#error_deprecated('g:latex_viewer')
|
||||
call latex#util#set_default('g:latex_view_method', '')
|
||||
call latex#util#set_default('g:latex_view_mupdf_options', '')
|
||||
call latex#util#set_default('g:latex_view_general_viewer', 'xdg-open')
|
||||
call latex#util#set_default('g:latex_view_general_options', '')
|
||||
|
||||
if g:latex_view_method == 'mupdf'
|
||||
call s:check_method_mupdf()
|
||||
let g:latex#data[b:latex.id].view = function('latex#view#mupdf')
|
||||
else
|
||||
call s:check_method_general()
|
||||
let g:latex#data[b:latex.id].view = function('latex#view#general')
|
||||
endif
|
||||
|
||||
command! -buffer -nargs=* VimLatexView call latex#view#view('<args>')
|
||||
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> <localleader>lv :call latex#view#view()<cr>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! latex#view#view(...) " {{{1
|
||||
if a:0 > 0
|
||||
let args = join(a:000, ' ')
|
||||
else
|
||||
let args = ''
|
||||
endif
|
||||
|
||||
call g:latex#data[b:latex.id].view(args)
|
||||
endfunction
|
||||
|
||||
function! latex#view#general(args) " {{{1
|
||||
let exe = {}
|
||||
let exe.cmd = g:latex_view_general_viewer
|
||||
|
||||
if a:args != ''
|
||||
let exe.cmd .= ' ' . a:args
|
||||
else
|
||||
let outfile = g:latex#data[b:latex.id].out()
|
||||
if !filereadable(outfile)
|
||||
echomsg "Can't view: Output file is not readable!"
|
||||
return
|
||||
endif
|
||||
let exe.cmd .= ' ' . g:latex_view_general_options
|
||||
let exe.cmd .= ' ' . shellescape(outfile)
|
||||
endif
|
||||
|
||||
call latex#util#execute(exe)
|
||||
let g:latex#data[b:latex.id].cmds.view = exe.cmd
|
||||
endfunction
|
||||
|
||||
function! latex#view#mupdf(args) "{{{1
|
||||
let outfile = fnameescape(g:latex#data[b:latex.id].out())
|
||||
if !filereadable(outfile)
|
||||
echomsg "Can't view: Output file is not readable!"
|
||||
return
|
||||
endif
|
||||
|
||||
" Open if not already open
|
||||
let pgrep = 'pgrep -nf "^mupdf.*'
|
||||
\ . fnamemodify(g:latex#data[b:latex.id].out(),':t')
|
||||
\ . '"'
|
||||
if !system(pgrep)[:-2]
|
||||
let exe = {}
|
||||
let exe.cmd = 'mupdf ' . g:latex_view_mupdf_options
|
||||
let exe.cmd .= ' ' . outfile
|
||||
call latex#util#execute(exe)
|
||||
let g:latex#data[b:latex.id].cmds.view = exe.cmd
|
||||
endif
|
||||
|
||||
" Do forward search if possible
|
||||
if !s:mupdf_forward_search | finish | endif
|
||||
|
||||
let l:cmd = "synctex view -i "
|
||||
\ . (line(".") + 1) . ":"
|
||||
\ . (col(".") + 1) . ":"
|
||||
\ . fnameescape(expand("%:p"))
|
||||
\ . " -o " . outfile
|
||||
\ . " | grep -m1 'Page:' | sed 's/Page://' | tr -d '\n'"
|
||||
let l:page = system(l:cmd)
|
||||
let g:latex#data[b:latex.id].cmds.view_mupdf_synctex = l:cmd
|
||||
let g:latex#data[b:latex.id].cmds.view_mupdf_synctex_page = l:page
|
||||
|
||||
if l:page > 0
|
||||
let exe = {}
|
||||
let exe.cmd = 'xdotool search --class mupdf type --window \%1 "'
|
||||
\ . l:page . 'g"'
|
||||
call latex#util#execute(exe)
|
||||
let g:latex#data[b:latex.id].cmds.view_mupdf_xdotool = exe.cmd
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
function! s:check_method_general() "{{{1
|
||||
if !executable(g:latex_view_general_viewer)
|
||||
echoerr "General viewer is not available!"
|
||||
echoerr "g:latex_view_general_viewer = "
|
||||
\ . g:latex_view_general_viewer
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! s:check_method_mupdf() "{{{1
|
||||
if !executable('mupdf')
|
||||
echoerr "MuPDF is not available!"
|
||||
endif
|
||||
|
||||
" Check if forward search is possible
|
||||
let s:mupdf_forward_search = executable('synctex') && executable('xdotool')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" vim: fdm=marker
|
105
doc/latex.txt
105
doc/latex.txt
@ -36,13 +36,14 @@ CONTENTS *vim-latex-contents*
|
||||
9. Latexmk .............................. |vim-latex-latexmk|
|
||||
Latexmk tricks ....................... |vim-latex-latexmk-tricks|
|
||||
Latexmk synctex ...................... |vim-latex-latexmk-synctex|
|
||||
10. Motion ............................... |vim-latex-motion|
|
||||
11. Change ............................... |vim-latex-change|
|
||||
12. Table of contents .................... |vim-latex-toc|
|
||||
13. Utility functions .................... |vim-latex-util|
|
||||
14. Function reference ................... |vim-latex-functions|
|
||||
15. Credits .............................. |vim-latex-credits|
|
||||
16. Changelog ............................ |vim-latex-changelog|
|
||||
10. View ................................. |vim-latex-view|
|
||||
11. Motion ............................... |vim-latex-motion|
|
||||
12. Change ............................... |vim-latex-change|
|
||||
13. Table of contents .................... |vim-latex-toc|
|
||||
14. Utility functions .................... |vim-latex-util|
|
||||
15. Function reference ................... |vim-latex-functions|
|
||||
16. Credits .............................. |vim-latex-credits|
|
||||
17. Changelog ............................ |vim-latex-changelog|
|
||||
|
||||
==============================================================================
|
||||
INTRO *vim-latex-intro*
|
||||
@ -78,15 +79,14 @@ initialization script that sets default mappings, creates autocommands and
|
||||
performs other necessary initialization. This initialization script is then
|
||||
called from |latex#init|.
|
||||
|
||||
The main interface provides some basic functionality. |latex#view|, by
|
||||
default mapped to '<localleader>lv', opens the current output file in
|
||||
a viewer. |latex#help| lists all mappings that are defined specifically for
|
||||
the current buffer, by default mapped to '<localleader>lh'. If the default
|
||||
mappings are used, |latex#help| will display them. |latex#info| echoes the
|
||||
contents of |g:latex#data| and |b:latex|. This is useful mainly for
|
||||
debugging. Finally, |latex#reinit| clears the current data in |g:latex#data|
|
||||
and |b:latex|, stops running `latexmk` processes |latex#latexmk#stop_all|, and
|
||||
then performs a new initialization with |latex#init|.
|
||||
The main interface provides some basic functionality. |latex#help| lists all
|
||||
`vim-latex` mappings defined for the current buffer, by default mapped to
|
||||
'<localleader>lh'. If the default mappings are used, |latex#help| will
|
||||
display them. |latex#info| echoes the contents of |g:latex#data| and
|
||||
|b:latex|. This is useful mainly for debugging. Finally, |latex#reinit|
|
||||
clears the current data in |g:latex#data| and |b:latex|, stops running
|
||||
`latexmk` processes |latex#latexmk#stop_all|, and then performs a new
|
||||
initialization with |latex#init|.
|
||||
|
||||
For each latex project that is opened, a |Dictionary| is created and added to
|
||||
the list |g:latex#data|. The dictionary is initialized with information tied
|
||||
@ -140,7 +140,6 @@ Functions:
|
||||
|latex#info|
|
||||
|latex#help|
|
||||
|latex#reinit|
|
||||
|latex#view|
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
Support for multi-file projects:~
|
||||
@ -209,7 +208,6 @@ o ]] *@:normal v]]<cr>
|
||||
|
||||
n <localleader>li *@:call latex#info()<cr>
|
||||
n <localleader>lh *@:call latex#help()<cr>
|
||||
n <localleader>lv *@:call latex#view()<cr>
|
||||
n <localleader>lR *@:call latex#reinit()<cr>
|
||||
n <localleader>lt *@:call latex#toc#open()<cr>
|
||||
n <localleader>lT *@:call latex#toc#toggle()<cr>
|
||||
@ -222,6 +220,7 @@ n <localleader>lg *@:call latex#latexmk#status()<cr>
|
||||
n <localleader>lG *@:call latex#latexmk#status(1)<cr>
|
||||
n <localleader>lc *@:call latex#latexmk#clean()<cr>
|
||||
n <localleader>lC *@:call latex#latexmk#clean(1)<cr>
|
||||
n <localleader>lv *@:call latex#view#view()<cr>
|
||||
|
||||
n zx *@:call latex#fold#refresh()<cr>
|
||||
n dse *@:call latex#change#env('')<cr>
|
||||
@ -257,7 +256,7 @@ Below the commands are listed in alphabetical order.
|
||||
*VimLatexStopAll* call latex#latexmk#stop_all()
|
||||
*VimLatexTocOpen* call latex#toc#open()
|
||||
*VimLatexTocToggle* call latex#toc#toggle()
|
||||
*VimLatexView* call latex#view()
|
||||
*VimLatexView* call latex#view#view()
|
||||
|
||||
==============================================================================
|
||||
OPTIONS *vim-latex-options*
|
||||
@ -305,7 +304,11 @@ Overview:~
|
||||
|g:latex_toc_secnumdepth|
|
||||
|g:latex_toc_split_side|
|
||||
|g:latex_toc_width|
|
||||
|g:latex_viewer|
|
||||
|g:latex_view_enabled|
|
||||
|g:latex_view_general_viewer|
|
||||
|g:latex_view_general_options|
|
||||
|g:latex_view_method|
|
||||
|g:latex_view_mupdf_options|
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
Detailed descriptions and default values:~
|
||||
@ -526,9 +529,29 @@ Define where the TOC window is opened. >
|
||||
Set width of TOC window. >
|
||||
let g:latex_toc_width = 30
|
||||
<
|
||||
*g:latex_viewer*
|
||||
Set default viewer application. >
|
||||
let g:latex_viewer = 'xdg-open'
|
||||
*g:latex_view_enabled*
|
||||
Enable interface for view functionality. >
|
||||
let g:latex_view_enabled = 1
|
||||
<
|
||||
*g:latex_view_general_options*
|
||||
Set custom options for general view command. >
|
||||
let g:latex_view_general_options = ''
|
||||
<
|
||||
*g:latex_view_general_viewer*
|
||||
Set general viewer. >
|
||||
let g:latex_view_general_viewer = 'xdg-open'
|
||||
<
|
||||
*g:latex_view_method*
|
||||
Set viewer method. If not set or set to `general`, it uses the general
|
||||
viewer, see |g:latex_view_general_viewer|. >
|
||||
let g:latex_view_method = ''
|
||||
The currently available choices are: >
|
||||
general
|
||||
mupdf
|
||||
<
|
||||
*g:latex_view_mupdf_options*
|
||||
Set custom options for mupdf viewer. >
|
||||
let g:latex_view_mupdf_options = ''
|
||||
<
|
||||
==============================================================================
|
||||
OMNI COMPLETION *vim-latex-completion*
|
||||
@ -795,6 +818,25 @@ to `gvim --remote-silent +%l "%f"` also works. However, this does not specify
|
||||
the vim server, and if you have several vim instances running, then it might
|
||||
not work as expected.
|
||||
|
||||
==============================================================================
|
||||
VIEW *vim-latex-view*
|
||||
|
||||
|vim-latex| provides functions for viewing the compiled documents. A command
|
||||
and a mapping is defined for the multipurpose `view` function, which calls the
|
||||
chosen view method defined by |g:latex_view_method|.
|
||||
|
||||
Associated settings:
|
||||
|g:latex_view_enabled|
|
||||
|g:latex_view_general_viewer|
|
||||
|g:latex_view_general_options|
|
||||
|g:latex_view_method|
|
||||
|g:latex_view_mupdf_options|
|
||||
|
||||
Functions:
|
||||
|latex#view#view|
|
||||
|latex#view#general|
|
||||
|latex#view#mupdf|
|
||||
|
||||
==============================================================================
|
||||
MOTION *vim-latex-motion*
|
||||
|
||||
@ -1114,18 +1156,17 @@ CHANGELOG *vim-latex-changelog*
|
||||
The following changelog only logs important changes, such as changes that
|
||||
break backwards compatibility. See the git log for the detailed changelog.
|
||||
|
||||
2014-08-24: Made continuous mode optional~
|
||||
Added option |g:latex_latexmk_continuous| to set whether or not the `latexmk`
|
||||
process should run in continuous mode. Also added option
|
||||
|g:latex_latexmk_background| to set whether single compilations should run in
|
||||
the foreground or the background.
|
||||
2014-12-07: Added more general view functionality~
|
||||
Added new module for view functionality. This allows more complex view
|
||||
functions (and commands), for instance to do forward (and possibly backwards)
|
||||
searching through `synctex`. In the first version, I added forward search for
|
||||
mupdf by use of the `synctex` command and `xdotools`.
|
||||
|
||||
I also deprecated the old variable that sets options for `latexmk`, because
|
||||
I find that it makes more sense to control `latexmk` through `latexmkrc`
|
||||
files.
|
||||
The `g:latex_viewer` option has now been deprecated. Instead one should use
|
||||
|g:latex_view_method| and |g:latex_view_general_viewer|.
|
||||
|
||||
Deprecated option:
|
||||
*g:latex_latexmk_options*
|
||||
*g:latex_viewer*
|
||||
|
||||
2014-06-13: Changed some option names~
|
||||
Some |vim-latex| option names were changed in an attempt to make the names
|
||||
|
Loading…
x
Reference in New Issue
Block a user