Simplified local data var name
This commit is contained in:
parent
b891bd72a3
commit
bba575b3b6
@ -33,40 +33,44 @@ function! vimtex#init() " {{{1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#info() " {{{1
|
||||
function! vimtex#info(global) " {{{1
|
||||
if !s:initialized
|
||||
echoerr 'Error: vimtex has not been initialized!'
|
||||
return
|
||||
endif
|
||||
|
||||
" Print buffer data
|
||||
call vimtex#echo#echo("b:vimtex\n")
|
||||
call s:print_dict(b:vimtex)
|
||||
if a:global
|
||||
let n = 0
|
||||
for data in g:vimtex#data
|
||||
let d = deepcopy(data)
|
||||
for f in ['aux', 'out', 'log']
|
||||
silent execute 'let d.' . f . ' = data.' . f . '()'
|
||||
endfor
|
||||
|
||||
" Print global data
|
||||
let n = 0
|
||||
for data in g:vimtex#data
|
||||
" Prepare for printing
|
||||
let d = deepcopy(data)
|
||||
for f in ['aux', 'out', 'log']
|
||||
silent execute 'let d.' . f . ' = data.' . f . '()'
|
||||
call vimtex#echo#formatted([
|
||||
\ "\n\ng:vimtex#data[",
|
||||
\ ['VimtexSuccess', n],
|
||||
\ '] : ',
|
||||
\ ['VimtexSuccess', remove(d, 'name') . "\n"]])
|
||||
call s:print_dict(d)
|
||||
let n += 1
|
||||
endfor
|
||||
else
|
||||
let d = deepcopy(b:vimtex)
|
||||
for f in ['aux', 'out', 'log']
|
||||
silent execute 'let d.data.' . f . ' = b:vimtex.data.' . f . '()'
|
||||
endfor
|
||||
|
||||
" Print data blob title line
|
||||
call vimtex#echo#formatted([
|
||||
\ "\n\ng:vimtex#data[",
|
||||
\ ['VimtexSuccess', n],
|
||||
\ '] : ',
|
||||
\ ['VimtexSuccess', remove(d, 'name') . "\n"]])
|
||||
\ "b:vimtex : ",
|
||||
\ ['VimtexSuccess', remove(d.data, 'name') . "\n"]])
|
||||
call s:print_dict(d)
|
||||
let n += 1
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#wordcount(detailed) " {{{1
|
||||
" Run texcount, save output to lines variable
|
||||
let data = g:vimtex#data[b:vimtex.id]
|
||||
let data = b:vimtex.data
|
||||
let cmd = 'cd ' . vimtex#util#fnameescape(data.root)
|
||||
let cmd .= '; texcount -nosub -sum '
|
||||
let cmd .= a:detailed > 0 ? '-inc ' : '-merge '
|
||||
@ -120,6 +124,7 @@ function! s:init_environment() " {{{1
|
||||
let id = s:get_id(main)
|
||||
if id >= 0
|
||||
let b:vimtex.id = id
|
||||
let b:vimtex.data = g:vimtex#data[id]
|
||||
else
|
||||
let data = {}
|
||||
let data.tex = main
|
||||
@ -138,14 +143,15 @@ function! s:init_environment() " {{{1
|
||||
|
||||
call add(g:vimtex#data, data)
|
||||
let b:vimtex.id = len(g:vimtex#data) - 1
|
||||
let b:vimtex.data = g:vimtex#data[-1]
|
||||
endif
|
||||
|
||||
" Define commands
|
||||
command! -buffer VimtexInfo call vimtex#info()
|
||||
command! -buffer -bang VimtexInfo call vimtex#info(<q-bang> == "!")
|
||||
command! -buffer -bang VimtexWordCount call vimtex#wordcount(<q-bang> == "!")
|
||||
|
||||
" Define mappings
|
||||
nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info()<cr>
|
||||
nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info(0)<cr>
|
||||
endfunction
|
||||
|
||||
function! s:init_options() " {{{1
|
||||
|
@ -83,7 +83,7 @@ let s:bibtex = 1
|
||||
let s:completion_type = ''
|
||||
|
||||
function! vimtex#complete#labels(regex) " {{{1
|
||||
let labels = s:labels_get(g:vimtex#data[b:vimtex.id].aux())
|
||||
let labels = s:labels_get(b:vimtex.data.aux())
|
||||
let matches = filter(copy(labels), 'v:val[0] =~ ''' . a:regex . '''')
|
||||
|
||||
" Try to match label and number
|
||||
@ -172,7 +172,7 @@ function! s:bibtex_search(regexp) " {{{2
|
||||
|
||||
" The bibtex completion seems to require that we are in the project root
|
||||
let l:save_pwd = getcwd()
|
||||
execute 'lcd ' . fnameescape(g:vimtex#data[b:vimtex.id].root)
|
||||
execute 'lcd ' . fnameescape(b:vimtex.data.root)
|
||||
|
||||
" Find data from external bib files
|
||||
let bibfiles = join(s:bibtex_find_bibs(), ',')
|
||||
@ -227,7 +227,7 @@ function! s:bibtex_search(regexp) " {{{2
|
||||
execute 'lcd ' . fnameescape(l:save_pwd)
|
||||
|
||||
" Find data from 'thebibliography' environments
|
||||
let lines = readfile(g:vimtex#data[b:vimtex.id].tex)
|
||||
let lines = readfile(b:vimtex.data.tex)
|
||||
if match(lines, '\C\\begin{thebibliography}') >= 0
|
||||
for line in filter(filter(lines, 'v:val =~# ''\C\\bibitem'''),
|
||||
\ 'v:val =~ a:regexp')
|
||||
@ -249,7 +249,7 @@ function! s:bibtex_find_bibs(...) " {{{2
|
||||
if a:0
|
||||
let file = a:1
|
||||
else
|
||||
let file = g:vimtex#data[b:vimtex.id].tex
|
||||
let file = b:vimtex.data.tex
|
||||
endif
|
||||
|
||||
if !filereadable(file)
|
||||
|
@ -28,7 +28,7 @@ function! vimtex#labels#open() " {{{1
|
||||
|
||||
let index = {}
|
||||
let index.name = s:name
|
||||
let index.entries = s:gather_labels(g:vimtex#data[b:vimtex.id].tex)
|
||||
let index.entries = s:gather_labels(b:vimtex.data.tex)
|
||||
let index.all_entries = deepcopy(index.entries)
|
||||
let index.hook_init_post = function('s:index_hook_init_post')
|
||||
let index.help = [
|
||||
|
@ -29,8 +29,8 @@ function! vimtex#latexmk#init(initialized) " {{{1
|
||||
compiler latexmk
|
||||
|
||||
" Initialize system PID
|
||||
if !has_key(g:vimtex#data[b:vimtex.id], 'pid')
|
||||
let g:vimtex#data[b:vimtex.id].pid = 0
|
||||
if !has_key(b:vimtex.data, 'pid')
|
||||
let b:vimtex.data.pid = 0
|
||||
endif
|
||||
|
||||
" Define commands
|
||||
@ -84,8 +84,8 @@ function! vimtex#latexmk#callback(status) " {{{1
|
||||
call vimtex#latexmk#errors_open(0)
|
||||
|
||||
if g:vimtex_view_enabled
|
||||
\ && has_key(g:vimtex#data[b:vimtex.id].viewer, 'latexmk_callback')
|
||||
call g:vimtex#data[b:vimtex.id].viewer.latexmk_callback()
|
||||
\ && has_key(b:vimtex.data.viewer, 'latexmk_callback')
|
||||
call b:vimtex.data.viewer.latexmk_callback()
|
||||
endif
|
||||
|
||||
call vimtex#echo#status(['latexmk compile: ',
|
||||
@ -96,7 +96,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#latexmk#clean(full) " {{{1
|
||||
let data = g:vimtex#data[b:vimtex.id]
|
||||
let data = b:vimtex.data
|
||||
if data.pid
|
||||
call vimtex#echo#status(['latexmk clean: ',
|
||||
\ ['VimtexWarning', 'not while latexmk is running!']])
|
||||
@ -122,7 +122,7 @@ function! vimtex#latexmk#clean(full) " {{{1
|
||||
\ 'bg' : 0,
|
||||
\ }
|
||||
call vimtex#util#execute(exe)
|
||||
let g:vimtex#data[b:vimtex.id].cmd_latexmk_clean = cmd
|
||||
let b:vimtex.data.cmd_latexmk_clean = cmd
|
||||
|
||||
call vimtex#echo#status(['latexmk clean: ',
|
||||
\ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]])
|
||||
@ -142,7 +142,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#latexmk#toggle() " {{{1
|
||||
let data = g:vimtex#data[b:vimtex.id]
|
||||
let data = b:vimtex.data
|
||||
|
||||
if data.pid
|
||||
call vimtex#latexmk#stop()
|
||||
@ -153,7 +153,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#latexmk#compile() " {{{1
|
||||
let data = g:vimtex#data[b:vimtex.id]
|
||||
let data = b:vimtex.data
|
||||
if data.pid
|
||||
call vimtex#echo#status(['latexmk compile: ',
|
||||
\ ['VimtexWarning', 'already running for `' . data.base . "'"]])
|
||||
@ -180,7 +180,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#latexmk#compile_ss(verbose) " {{{1
|
||||
let data = g:vimtex#data[b:vimtex.id]
|
||||
let data = b:vimtex.data
|
||||
if data.pid
|
||||
call vimtex#echo#status(['latexmk compile: ',
|
||||
\ ['VimtexWarning', 'already running for `' . data.base . "'"]])
|
||||
@ -212,7 +212,7 @@ endfunction
|
||||
function! vimtex#latexmk#errors_open(force) " {{{1
|
||||
cclose
|
||||
|
||||
let log = g:vimtex#data[b:vimtex.id].log()
|
||||
let log = b:vimtex.data.log()
|
||||
if empty(log)
|
||||
if a:force
|
||||
call vimtex#echo#status(['latexmk errors: ',
|
||||
@ -258,8 +258,8 @@ let s:open_quickfix_window = 0
|
||||
|
||||
" }}}1
|
||||
function! vimtex#latexmk#output() " {{{1
|
||||
if has_key(g:vimtex#data[b:vimtex.id], 'tmp')
|
||||
let tmp = g:vimtex#data[b:vimtex.id].tmp
|
||||
if has_key(b:vimtex.data, 'tmp')
|
||||
let tmp = b:vimtex.data.tmp
|
||||
else
|
||||
call vimtex#echo#status(['vimtex: ', ['VimtexWarning', 'No output exists']])
|
||||
return
|
||||
@ -320,7 +320,7 @@ function! vimtex#latexmk#status(detailed) " {{{1
|
||||
\ ['VimtexWarning', 'not running']])
|
||||
endif
|
||||
else
|
||||
if g:vimtex#data[b:vimtex.id].pid
|
||||
if b:vimtex.data.pid
|
||||
call vimtex#echo#status(['latexmk status: ',
|
||||
\ ['VimtexSuccess', 'running']])
|
||||
else
|
||||
@ -332,11 +332,11 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
function! vimtex#latexmk#stop() " {{{1
|
||||
let pid = g:vimtex#data[b:vimtex.id].pid
|
||||
let base = g:vimtex#data[b:vimtex.id].base
|
||||
let pid = b:vimtex.data.pid
|
||||
let base = b:vimtex.data.base
|
||||
if pid
|
||||
call s:latexmk_kill_pid(pid)
|
||||
let g:vimtex#data[b:vimtex.id].pid = 0
|
||||
let b:vimtex.data.pid = 0
|
||||
call vimtex#echo#status(['latexmk compile: ',
|
||||
\ ['VimtexSuccess', 'stopped (' . base . ')']])
|
||||
else
|
||||
@ -412,9 +412,9 @@ function! s:latexmk_build_cmd(data) " {{{1
|
||||
endif
|
||||
|
||||
if g:vimtex_view_enabled
|
||||
\ && has_key(g:vimtex#data[b:vimtex.id].viewer,
|
||||
\ && has_key(b:vimtex.data.viewer,
|
||||
\ 'latexmk_append_argument')
|
||||
let cmd .= g:vimtex#data[b:vimtex.id].viewer.latexmk_append_argument()
|
||||
let cmd .= b:vimtex.data.viewer.latexmk_append_argument()
|
||||
endif
|
||||
|
||||
let cmd .= ' ' . vimtex#util#fnameescape(a:data.base)
|
||||
@ -476,19 +476,18 @@ function! s:stop_buffer() " {{{1
|
||||
" Only run if latex variables are set
|
||||
"
|
||||
if !exists('b:vimtex') | return | endif
|
||||
let id = b:vimtex.id
|
||||
let pid = g:vimtex#data[id].pid
|
||||
|
||||
"
|
||||
" Only stop if latexmk is running
|
||||
"
|
||||
if pid
|
||||
if b:vimtex.data.pid !=# 0
|
||||
"
|
||||
" Count the number of buffers that point to current latex blob
|
||||
"
|
||||
let n = 0
|
||||
for b in filter(range(1, bufnr('$')), 'buflisted(v:val)')
|
||||
if id == getbufvar(b, 'vimtex', {'id' : -1}).id
|
||||
echom getbufvar(b, 'vimtex', {'id' : -1}).id
|
||||
if b:vimtex.id == getbufvar(b, 'vimtex', {'id' : -1}).id
|
||||
let n += 1
|
||||
endif
|
||||
endfor
|
||||
|
@ -74,7 +74,7 @@ function! vimtex#mappings#init(initialized)
|
||||
|
||||
if g:vimtex_view_enabled
|
||||
nmap <silent><buffer> <localleader>lv <plug>(vimtex-view)
|
||||
if has_key(g:vimtex#data[b:vimtex.id], 'rsearch')
|
||||
if has_key(b:vimtex.data, 'rsearch')
|
||||
nmap <silent><buffer> <localleader>lr <plug>(vimtex-reverse-search)
|
||||
endif
|
||||
endif
|
||||
|
@ -288,7 +288,7 @@ let s:re_other = {
|
||||
" }}}1
|
||||
|
||||
function! s:parse_toc() " {{{1
|
||||
let file = g:vimtex#data[b:vimtex.id].tex
|
||||
let file = b:vimtex.data.tex
|
||||
|
||||
" Reset TOC numbering
|
||||
call s:number_reset('preamble')
|
||||
|
@ -8,7 +8,7 @@ function! vimtex#view#init(initialized) " {{{1
|
||||
call vimtex#util#set_default('g:vimtex_view_enabled', 1)
|
||||
if !g:vimtex_view_enabled | return | endif
|
||||
|
||||
let data = g:vimtex#data[b:vimtex.id]
|
||||
let data = b:vimtex.data
|
||||
|
||||
" Initialize viewer options
|
||||
for viewer in s:viewers
|
||||
@ -36,18 +36,18 @@ function! vimtex#view#init(initialized) " {{{1
|
||||
|
||||
" Define commands
|
||||
command! -buffer -nargs=? -complete=file VimtexView
|
||||
\ call g:vimtex#data[b:vimtex.id].viewer.view(<q-args>)
|
||||
\ call b:vimtex.data.viewer.view(<q-args>)
|
||||
if has_key(data.viewer, 'reverse_search')
|
||||
command! -buffer -nargs=* VimtexRSearch
|
||||
\ call g:vimtex#data[b:vimtex.id].viewer.reverse_search()
|
||||
\ call b:vimtex.data.viewer.reverse_search()
|
||||
endif
|
||||
|
||||
" Define mappings
|
||||
nnoremap <buffer> <plug>(vimtex-view)
|
||||
\ :call g:vimtex#data[b:vimtex.id].viewer.view('')<cr>
|
||||
\ :call b:vimtex.data.viewer.view('')<cr>
|
||||
if has_key(data.viewer, 'reverse_search')
|
||||
nnoremap <buffer> <plug>(vimtex-reverse-search)
|
||||
\ :call g:vimtex#data[b:vimtex.id].viewer.reverse_search()<cr>
|
||||
\ :call b:vimtex.data.viewer.reverse_search()<cr>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -76,7 +76,7 @@ endfunction
|
||||
|
||||
" }}}2
|
||||
function! s:general.view(file) dict " {{{2
|
||||
let outfile = a:file !=# '' ? a:file : g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = a:file !=# '' ? a:file : b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
let exe = {}
|
||||
@ -120,7 +120,7 @@ endfunction
|
||||
|
||||
" }}}2
|
||||
function! s:mupdf.view(file) dict " {{{2
|
||||
let outfile = a:file !=# '' ? a:file : g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = a:file !=# '' ? a:file : b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
if !self.xwin_exists()
|
||||
@ -173,7 +173,7 @@ function! s:mupdf.reverse_search() dict " {{{2
|
||||
if !executable('xdotool') | return | endif
|
||||
if !executable('synctex') | return | endif
|
||||
|
||||
let outfile = g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
if !self.xwin_exists()
|
||||
@ -219,7 +219,7 @@ function! s:mupdf.latexmk_callback() dict " {{{2
|
||||
if !self.xwin_exists()
|
||||
if self.xwin_get_id()
|
||||
call self.xwin_send_keys(g:vimtex_view_mupdf_send_keys)
|
||||
call self.forward_search(g:vimtex#data[b:vimtex.id].out())
|
||||
call self.forward_search(b:vimtex.data.out())
|
||||
call self.focus_vim()
|
||||
endif
|
||||
endif
|
||||
@ -246,7 +246,7 @@ endfunction
|
||||
|
||||
" }}}2
|
||||
function! s:okular.view(file) dict " {{{2
|
||||
let outfile = a:file !=# '' ? a:file : g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = a:file !=# '' ? a:file : b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
let exe = {}
|
||||
@ -268,7 +268,7 @@ endfunction
|
||||
|
||||
" }}}2
|
||||
function! s:qpdfview.view(file) dict " {{{2
|
||||
let outfile = a:file !=# '' ? a:file : g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = a:file !=# '' ? a:file : b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
let exe = {}
|
||||
@ -292,7 +292,7 @@ endfunction
|
||||
|
||||
" }}}2
|
||||
function! s:sumatrapdf.view(file) dict " {{{2
|
||||
let outfile = a:file !=# '' ? a:file : g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = a:file !=# '' ? a:file : b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
let exe = {}
|
||||
@ -328,7 +328,7 @@ endfunction
|
||||
|
||||
" }}}2
|
||||
function! s:zathura.view(file) dict " {{{2
|
||||
let outfile = a:file !=# '' ? a:file : g:vimtex#data[b:vimtex.id].out()
|
||||
let outfile = a:file !=# '' ? a:file : b:vimtex.data.out()
|
||||
if s:output_not_readable(outfile) | return | endif
|
||||
|
||||
if !self.xwin_exists()
|
||||
@ -369,7 +369,7 @@ endfunction
|
||||
function! s:zathura.latexmk_callback() dict " {{{2
|
||||
if !self.xwin_exists()
|
||||
if self.xwin_get_id()
|
||||
call self.forward_search(g:vimtex#data[b:vimtex.id].out())
|
||||
call self.forward_search(b:vimtex.data.out())
|
||||
call self.focus_vim()
|
||||
endif
|
||||
endif
|
||||
|
Loading…
Reference in New Issue
Block a user