Fixed #614: Better citation completion

- Support \jobname in bibliography file name
- Support \nobibliography
- Support \bibentry for completion
This commit is contained in:
Karl Yngve Lervåg 2016-12-29 19:27:50 +01:00
parent 6c159818d1
commit 9c9091ca7b
2 changed files with 31 additions and 3 deletions

View File

@ -76,9 +76,12 @@ endfunction
" {{{1 Bibtex
let s:bib = {
\ 'patterns' : ['\v\\\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*$'],
\ 'patterns' : [
\ '\v\\\a*cite\a*%(\s*\[[^]]*\]){0,2}\s*\{[^}]*$',
\ '\v\\bibentry\s*\{[^}]*$',
\ ],
\ 'bibs' : '''\v%(%(\\@<!%(\\\\)*)@<=\%.*)@<!'
\ . '\\(bibliography|add(bibresource|globalbib|sectionbib))'
\ . '\\(%(no)?bibliography|add(bibresource|globalbib|sectionbib))'
\ . '\m\s*{\zs[^}]\+\ze}''',
\ 'type_length' : 0,
\ 'bstfile' : expand('<sfile>:p:h') . '/vimcomplete',
@ -231,7 +234,8 @@ function! s:bib.find_bibs() dict " {{{2
let l:bibfiles = []
for l:entry in map(filter(l:lines, 'v:val =~ ' . self.bibs),
\ 'matchstr(v:val, ' . self.bibs . ')')
\ 'matchstr(v:val, ' . self.bibs . ')')
let l:entry = substitute(l:entry, '\\jobname', b:vimtex.name, 'g')
let l:bibfiles += map(split(l:entry, ','), 'fnamemodify(v:val, '':r'')')
endfor

24
test/issues/614/test.tex Normal file
View File

@ -0,0 +1,24 @@
\documentclass{article}
\usepackage{natbib}
\usepackage{bibentry}
\bibliographystyle{apalike}
\nobibliography{\jobname}
% This is the sample bib file
\begin{filecontents}{\jobname.bib}
@book{Saussure1995,
Author = {Ferdinand de Saussure},
Origyear = {1916},
Publisher = {Payot},
Title = {Cours de Linguistique G{\'e}n{\'e}rale},
Year = {1995}
}
\end{filecontents}
\begin{document}
This is a complete citation in the middle of the text:
\bibentry{
\end{document}