1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email: karl.yngve@gmail.com
"
function! vimtex#cite#get_entry(...) abort " {{{1
let l:key = a:0 > 0 ? a:1 : vimtex#cite#get_key()
if empty(l:key) | return {} | endif
" Ensure we're at the root directory when locating bib files
call vimtex#paths#pushd(b:vimtex.root)
let l:entries = []
for l:file in vimtex#bib#files()
let l:entries += vimtex#parser#bib(
\ l:file,
\ {'backend': has('nvim') ? 'lua' : 'vim'}
\)
endfor
call vimtex#paths#popd()
" Return entry with the given key
return l:entries->filter({_, x -> x.key ==# l:key})->get(0, {})
endfunction
" }}}1
function! vimtex#cite#get_key(...) abort " {{{1
let l:cmd = a:0 > 0 ? a:1 : vimtex#cmd#get_current()
if empty(l:cmd)
\ || l:cmd.name[1:] !~# g:vimtex#re#cite_cmd
\ || len(l:cmd.args) < 1
\ || len(l:cmd.args) > 2
return ''
endif
let l:current_word = a:0 > 1 ? a:2 : expand('<cword>')
let l:cites = l:cmd.args->map({_, x -> x.text})->join(',')->split(',\s*')
return index(l:cites, l:current_word) >= 0
\ ? l:current_word
\ : l:cites[0]
endfunction
" }}}1
function! vimtex#cite#get_key_at(line, col) abort " {{{1
let l:pos_saved = vimtex#pos#get_cursor()
call vimtex#pos#set_cursor(a:line, a:col)
let l:key = vimtex#cite#get_key()
call vimtex#pos#set_cursor(l:pos_saved)
return l:key
endfunction
" }}}1
|