Skip to content

Commit

Permalink
merge: fix .bib file globbing
Browse files Browse the repository at this point in the history
refer: #1658, #2035
  • Loading branch information
lervag committed Jul 11, 2021
2 parents 8f1d239 + bd266f7 commit 607956c
Show file tree
Hide file tree
Showing 23 changed files with 8,996 additions and 10 deletions.
30 changes: 22 additions & 8 deletions autoload/vimtex/bib.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function! vimtex#bib#files() abort " {{{1
let l:bibs = map(
\ filter(readfile(l:file), "v:val =~# 'bcf:datasource'"),
\ {_, x -> matchstr(x, '<[^>]*>\zs[^<]*')})
for l:f in filter(copy(l:bibs), {_, x -> x =~# '[*?{[]' })
let l:bibs += glob(l:f, 0, 1)
endfor
if !empty(l:bibs) | return s:validate(l:bibs) | endif
endif
endif
Expand Down Expand Up @@ -73,18 +76,29 @@ function! s:files_manual() abort " {{{1
let l:cache.modified = 1
let l:current.ftime = l:ftime
let l:current.files = []

for l:entry in map(
\ filter(readfile(l:file), {_, x -> x =~# s:bib_re}),
\ {_, x -> matchstr(x, s:bib_re)})
let l:files = []
" Interpolate the \jobname command
let l:entry = substitute(l:entry, '\\jobname', b:vimtex.name, 'g')

for l:f in split(l:entry, ',')
if stridx(l:f, '*') >= 0
let l:files += glob(l:f, 0, 1)
else
let l:files += [fnamemodify(l:f, ':r')]
endif
" Assume comma separated list of files
let l:files = split(l:entry, ',')

" But also add the unmodified entry for consideration, as the comma may
" be part of the filename or part of a globbing expression.
if len(l:files) > 1
let l:files += [l:entry]
endif

" Now attempt to apply globbing where applicable
for l:exp in filter(copy(l:files), {_, x -> x =~# '[*?{[]'})
try
let l:globbed = glob(l:exp, 0, 1)
let l:files += l:globbed
catch /E220/
endtry
endfor

let l:current.files += l:files
Expand All @@ -104,4 +118,4 @@ endfunction

let s:bib_re = g:vimtex#re#not_comment . '\\('
\ . join(g:vimtex_bibliography_commands, '|')
\ . ')\s*\{\zs[^}]+\ze}'
\ . ')\s*\{\zs.+\ze}'
10 changes: 10 additions & 0 deletions test/test-completion-bibtex/test_globbed_1.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@book{DBLP:books/aw/Lamport86,
author = {Leslie Lamport},
title = {LaTeX: User's Guide {\&} Reference Manual},
publisher = {Addison-Wesley},
year = {1986},
isbn = {0-201-15790-X},
timestamp = {Thu, 03 Jan 2002 11:51:07 +0100},
biburl = {https://dblp.org/rec/books/aw/Lamport86.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
10 changes: 10 additions & 0 deletions test/test-completion-bibtex/test_globbed_2.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@book{DBLP:books/aw/Knuth86a,
author = {Donald E. Knuth},
title = {TeX: The Program},
publisher = {Addison-Wesley},
year = {1986},
isbn = {0-201-13437-3},
timestamp = {Thu, 03 Jan 2002 11:51:07 +0100},
biburl = {https://dblp.org/rec/books/aw/Knuth86a.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
6 changes: 6 additions & 0 deletions test/test-completion-bibtex/test_globbed_braces.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\documentclass{article}
\usepackage{biblatex}
\addbibresource{test_globbed_{1,2}.bib}
\begin{document}
Test
\end{document}
20 changes: 20 additions & 0 deletions test/test-completion-bibtex/test_globbed_braces.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set nocompatible
let &rtp = '../..,' . &rtp
filetype plugin on

nnoremap q :qall!<cr>
let g:vimtex_cache_root = '.'
let g:vimtex_cache_persistent = 0

let s:tex_filename = expand('<sfile>:r') . '.tex'
silent execute 'edit' s:tex_filename

if empty($INMAKE) | finish | endif

" calls files_manual when no bcf file for tex file found
let s:candidates = vimtex#test#completion('\cite{', '')
call assert_equal(2, len(s:candidates))

bwipeout!
call vimtex#test#finished()
Loading

0 comments on commit 607956c

Please sign in to comment.