Simplified local data var name

This commit is contained in:
Karl Yngve Lervåg 2015-06-05 23:55:34 +02:00
parent b891bd72a3
commit bba575b3b6
7 changed files with 70 additions and 65 deletions

View File

@ -33,26 +33,20 @@ function! vimtex#init() " {{{1
endfunction endfunction
" }}}1 " }}}1
function! vimtex#info() " {{{1 function! vimtex#info(global) " {{{1
if !s:initialized if !s:initialized
echoerr 'Error: vimtex has not been initialized!' echoerr 'Error: vimtex has not been initialized!'
return return
endif endif
" Print buffer data if a:global
call vimtex#echo#echo("b:vimtex\n")
call s:print_dict(b:vimtex)
" Print global data
let n = 0 let n = 0
for data in g:vimtex#data for data in g:vimtex#data
" Prepare for printing
let d = deepcopy(data) let d = deepcopy(data)
for f in ['aux', 'out', 'log'] for f in ['aux', 'out', 'log']
silent execute 'let d.' . f . ' = data.' . f . '()' silent execute 'let d.' . f . ' = data.' . f . '()'
endfor endfor
" Print data blob title line
call vimtex#echo#formatted([ call vimtex#echo#formatted([
\ "\n\ng:vimtex#data[", \ "\n\ng:vimtex#data[",
\ ['VimtexSuccess', n], \ ['VimtexSuccess', n],
@ -61,12 +55,22 @@ function! vimtex#info() " {{{1
call s:print_dict(d) call s:print_dict(d)
let n += 1 let n += 1
endfor endfor
else
let d = deepcopy(b:vimtex)
for f in ['aux', 'out', 'log']
silent execute 'let d.data.' . f . ' = b:vimtex.data.' . f . '()'
endfor
call vimtex#echo#formatted([
\ "b:vimtex : ",
\ ['VimtexSuccess', remove(d.data, 'name') . "\n"]])
call s:print_dict(d)
endif
endfunction endfunction
" }}}1 " }}}1
function! vimtex#wordcount(detailed) " {{{1 function! vimtex#wordcount(detailed) " {{{1
" Run texcount, save output to lines variable " 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 = 'cd ' . vimtex#util#fnameescape(data.root)
let cmd .= '; texcount -nosub -sum ' let cmd .= '; texcount -nosub -sum '
let cmd .= a:detailed > 0 ? '-inc ' : '-merge ' let cmd .= a:detailed > 0 ? '-inc ' : '-merge '
@ -120,6 +124,7 @@ function! s:init_environment() " {{{1
let id = s:get_id(main) let id = s:get_id(main)
if id >= 0 if id >= 0
let b:vimtex.id = id let b:vimtex.id = id
let b:vimtex.data = g:vimtex#data[id]
else else
let data = {} let data = {}
let data.tex = main let data.tex = main
@ -138,14 +143,15 @@ function! s:init_environment() " {{{1
call add(g:vimtex#data, data) call add(g:vimtex#data, data)
let b:vimtex.id = len(g:vimtex#data) - 1 let b:vimtex.id = len(g:vimtex#data) - 1
let b:vimtex.data = g:vimtex#data[-1]
endif endif
" Define commands " 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> == "!") command! -buffer -bang VimtexWordCount call vimtex#wordcount(<q-bang> == "!")
" Define mappings " Define mappings
nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info()<cr> nnoremap <buffer> <plug>(vimtex-info) :call vimtex#info(0)<cr>
endfunction endfunction
function! s:init_options() " {{{1 function! s:init_options() " {{{1

View File

@ -83,7 +83,7 @@ let s:bibtex = 1
let s:completion_type = '' let s:completion_type = ''
function! vimtex#complete#labels(regex) " {{{1 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 . '''') let matches = filter(copy(labels), 'v:val[0] =~ ''' . a:regex . '''')
" Try to match label and number " 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 " The bibtex completion seems to require that we are in the project root
let l:save_pwd = getcwd() 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 " Find data from external bib files
let bibfiles = join(s:bibtex_find_bibs(), ',') let bibfiles = join(s:bibtex_find_bibs(), ',')
@ -227,7 +227,7 @@ function! s:bibtex_search(regexp) " {{{2
execute 'lcd ' . fnameescape(l:save_pwd) execute 'lcd ' . fnameescape(l:save_pwd)
" Find data from 'thebibliography' environments " 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 if match(lines, '\C\\begin{thebibliography}') >= 0
for line in filter(filter(lines, 'v:val =~# ''\C\\bibitem'''), for line in filter(filter(lines, 'v:val =~# ''\C\\bibitem'''),
\ 'v:val =~ a:regexp') \ 'v:val =~ a:regexp')
@ -249,7 +249,7 @@ function! s:bibtex_find_bibs(...) " {{{2
if a:0 if a:0
let file = a:1 let file = a:1
else else
let file = g:vimtex#data[b:vimtex.id].tex let file = b:vimtex.data.tex
endif endif
if !filereadable(file) if !filereadable(file)

View File

@ -28,7 +28,7 @@ function! vimtex#labels#open() " {{{1
let index = {} let index = {}
let index.name = s:name 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.all_entries = deepcopy(index.entries)
let index.hook_init_post = function('s:index_hook_init_post') let index.hook_init_post = function('s:index_hook_init_post')
let index.help = [ let index.help = [

View File

@ -29,8 +29,8 @@ function! vimtex#latexmk#init(initialized) " {{{1
compiler latexmk compiler latexmk
" Initialize system PID " Initialize system PID
if !has_key(g:vimtex#data[b:vimtex.id], 'pid') if !has_key(b:vimtex.data, 'pid')
let g:vimtex#data[b:vimtex.id].pid = 0 let b:vimtex.data.pid = 0
endif endif
" Define commands " Define commands
@ -84,8 +84,8 @@ function! vimtex#latexmk#callback(status) " {{{1
call vimtex#latexmk#errors_open(0) call vimtex#latexmk#errors_open(0)
if g:vimtex_view_enabled if g:vimtex_view_enabled
\ && has_key(g:vimtex#data[b:vimtex.id].viewer, 'latexmk_callback') \ && has_key(b:vimtex.data.viewer, 'latexmk_callback')
call g:vimtex#data[b:vimtex.id].viewer.latexmk_callback() call b:vimtex.data.viewer.latexmk_callback()
endif endif
call vimtex#echo#status(['latexmk compile: ', call vimtex#echo#status(['latexmk compile: ',
@ -96,7 +96,7 @@ endfunction
" }}}1 " }}}1
function! vimtex#latexmk#clean(full) " {{{1 function! vimtex#latexmk#clean(full) " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = b:vimtex.data
if data.pid if data.pid
call vimtex#echo#status(['latexmk clean: ', call vimtex#echo#status(['latexmk clean: ',
\ ['VimtexWarning', 'not while latexmk is running!']]) \ ['VimtexWarning', 'not while latexmk is running!']])
@ -122,7 +122,7 @@ function! vimtex#latexmk#clean(full) " {{{1
\ 'bg' : 0, \ 'bg' : 0,
\ } \ }
call vimtex#util#execute(exe) 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: ', call vimtex#echo#status(['latexmk clean: ',
\ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]]) \ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]])
@ -142,7 +142,7 @@ endfunction
" }}}1 " }}}1
function! vimtex#latexmk#toggle() " {{{1 function! vimtex#latexmk#toggle() " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = b:vimtex.data
if data.pid if data.pid
call vimtex#latexmk#stop() call vimtex#latexmk#stop()
@ -153,7 +153,7 @@ endfunction
" }}}1 " }}}1
function! vimtex#latexmk#compile() " {{{1 function! vimtex#latexmk#compile() " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = b:vimtex.data
if data.pid if data.pid
call vimtex#echo#status(['latexmk compile: ', call vimtex#echo#status(['latexmk compile: ',
\ ['VimtexWarning', 'already running for `' . data.base . "'"]]) \ ['VimtexWarning', 'already running for `' . data.base . "'"]])
@ -180,7 +180,7 @@ endfunction
" }}}1 " }}}1
function! vimtex#latexmk#compile_ss(verbose) " {{{1 function! vimtex#latexmk#compile_ss(verbose) " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = b:vimtex.data
if data.pid if data.pid
call vimtex#echo#status(['latexmk compile: ', call vimtex#echo#status(['latexmk compile: ',
\ ['VimtexWarning', 'already running for `' . data.base . "'"]]) \ ['VimtexWarning', 'already running for `' . data.base . "'"]])
@ -212,7 +212,7 @@ endfunction
function! vimtex#latexmk#errors_open(force) " {{{1 function! vimtex#latexmk#errors_open(force) " {{{1
cclose cclose
let log = g:vimtex#data[b:vimtex.id].log() let log = b:vimtex.data.log()
if empty(log) if empty(log)
if a:force if a:force
call vimtex#echo#status(['latexmk errors: ', call vimtex#echo#status(['latexmk errors: ',
@ -258,8 +258,8 @@ let s:open_quickfix_window = 0
" }}}1 " }}}1
function! vimtex#latexmk#output() " {{{1 function! vimtex#latexmk#output() " {{{1
if has_key(g:vimtex#data[b:vimtex.id], 'tmp') if has_key(b:vimtex.data, 'tmp')
let tmp = g:vimtex#data[b:vimtex.id].tmp let tmp = b:vimtex.data.tmp
else else
call vimtex#echo#status(['vimtex: ', ['VimtexWarning', 'No output exists']]) call vimtex#echo#status(['vimtex: ', ['VimtexWarning', 'No output exists']])
return return
@ -320,7 +320,7 @@ function! vimtex#latexmk#status(detailed) " {{{1
\ ['VimtexWarning', 'not running']]) \ ['VimtexWarning', 'not running']])
endif endif
else else
if g:vimtex#data[b:vimtex.id].pid if b:vimtex.data.pid
call vimtex#echo#status(['latexmk status: ', call vimtex#echo#status(['latexmk status: ',
\ ['VimtexSuccess', 'running']]) \ ['VimtexSuccess', 'running']])
else else
@ -332,11 +332,11 @@ endfunction
" }}}1 " }}}1
function! vimtex#latexmk#stop() " {{{1 function! vimtex#latexmk#stop() " {{{1
let pid = g:vimtex#data[b:vimtex.id].pid let pid = b:vimtex.data.pid
let base = g:vimtex#data[b:vimtex.id].base let base = b:vimtex.data.base
if pid if pid
call s:latexmk_kill_pid(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: ', call vimtex#echo#status(['latexmk compile: ',
\ ['VimtexSuccess', 'stopped (' . base . ')']]) \ ['VimtexSuccess', 'stopped (' . base . ')']])
else else
@ -412,9 +412,9 @@ function! s:latexmk_build_cmd(data) " {{{1
endif endif
if g:vimtex_view_enabled if g:vimtex_view_enabled
\ && has_key(g:vimtex#data[b:vimtex.id].viewer, \ && has_key(b:vimtex.data.viewer,
\ 'latexmk_append_argument') \ '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 endif
let cmd .= ' ' . vimtex#util#fnameescape(a:data.base) let cmd .= ' ' . vimtex#util#fnameescape(a:data.base)
@ -476,19 +476,18 @@ function! s:stop_buffer() " {{{1
" Only run if latex variables are set " Only run if latex variables are set
" "
if !exists('b:vimtex') | return | endif if !exists('b:vimtex') | return | endif
let id = b:vimtex.id
let pid = g:vimtex#data[id].pid
" "
" Only stop if latexmk is running " 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 " Count the number of buffers that point to current latex blob
" "
let n = 0 let n = 0
for b in filter(range(1, bufnr('$')), 'buflisted(v:val)') 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 let n += 1
endif endif
endfor endfor

View File

@ -74,7 +74,7 @@ function! vimtex#mappings#init(initialized)
if g:vimtex_view_enabled if g:vimtex_view_enabled
nmap <silent><buffer> <localleader>lv <plug>(vimtex-view) 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) nmap <silent><buffer> <localleader>lr <plug>(vimtex-reverse-search)
endif endif
endif endif

View File

@ -288,7 +288,7 @@ let s:re_other = {
" }}}1 " }}}1
function! s:parse_toc() " {{{1 function! s:parse_toc() " {{{1
let file = g:vimtex#data[b:vimtex.id].tex let file = b:vimtex.data.tex
" Reset TOC numbering " Reset TOC numbering
call s:number_reset('preamble') call s:number_reset('preamble')

View File

@ -8,7 +8,7 @@ function! vimtex#view#init(initialized) " {{{1
call vimtex#util#set_default('g:vimtex_view_enabled', 1) call vimtex#util#set_default('g:vimtex_view_enabled', 1)
if !g:vimtex_view_enabled | return | endif if !g:vimtex_view_enabled | return | endif
let data = g:vimtex#data[b:vimtex.id] let data = b:vimtex.data
" Initialize viewer options " Initialize viewer options
for viewer in s:viewers for viewer in s:viewers
@ -36,18 +36,18 @@ function! vimtex#view#init(initialized) " {{{1
" Define commands " Define commands
command! -buffer -nargs=? -complete=file VimtexView 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') if has_key(data.viewer, 'reverse_search')
command! -buffer -nargs=* VimtexRSearch command! -buffer -nargs=* VimtexRSearch
\ call g:vimtex#data[b:vimtex.id].viewer.reverse_search() \ call b:vimtex.data.viewer.reverse_search()
endif endif
" Define mappings " Define mappings
nnoremap <buffer> <plug>(vimtex-view) 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') if has_key(data.viewer, 'reverse_search')
nnoremap <buffer> <plug>(vimtex-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 endif
endfunction endfunction
@ -76,7 +76,7 @@ endfunction
" }}}2 " }}}2
function! s:general.view(file) dict " {{{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 if s:output_not_readable(outfile) | return | endif
let exe = {} let exe = {}
@ -120,7 +120,7 @@ endfunction
" }}}2 " }}}2
function! s:mupdf.view(file) dict " {{{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 s:output_not_readable(outfile) | return | endif
if !self.xwin_exists() if !self.xwin_exists()
@ -173,7 +173,7 @@ function! s:mupdf.reverse_search() dict " {{{2
if !executable('xdotool') | return | endif if !executable('xdotool') | return | endif
if !executable('synctex') | 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 s:output_not_readable(outfile) | return | endif
if !self.xwin_exists() if !self.xwin_exists()
@ -219,7 +219,7 @@ function! s:mupdf.latexmk_callback() dict " {{{2
if !self.xwin_exists() if !self.xwin_exists()
if self.xwin_get_id() if self.xwin_get_id()
call self.xwin_send_keys(g:vimtex_view_mupdf_send_keys) 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() call self.focus_vim()
endif endif
endif endif
@ -246,7 +246,7 @@ endfunction
" }}}2 " }}}2
function! s:okular.view(file) dict " {{{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 if s:output_not_readable(outfile) | return | endif
let exe = {} let exe = {}
@ -268,7 +268,7 @@ endfunction
" }}}2 " }}}2
function! s:qpdfview.view(file) dict " {{{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 if s:output_not_readable(outfile) | return | endif
let exe = {} let exe = {}
@ -292,7 +292,7 @@ endfunction
" }}}2 " }}}2
function! s:sumatrapdf.view(file) dict " {{{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 if s:output_not_readable(outfile) | return | endif
let exe = {} let exe = {}
@ -328,7 +328,7 @@ endfunction
" }}}2 " }}}2
function! s:zathura.view(file) dict " {{{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 s:output_not_readable(outfile) | return | endif
if !self.xwin_exists() if !self.xwin_exists()
@ -369,7 +369,7 @@ endfunction
function! s:zathura.latexmk_callback() dict " {{{2 function! s:zathura.latexmk_callback() dict " {{{2
if !self.xwin_exists() if !self.xwin_exists()
if self.xwin_get_id() 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() call self.focus_vim()
endif endif
endif endif