diff --git a/autoload/vimtex/complete.vim b/autoload/vimtex/complete.vim index dde4905..e6bf5be 100644 --- a/autoload/vimtex/complete.vim +++ b/autoload/vimtex/complete.vim @@ -10,7 +10,6 @@ function! vimtex#complete#init_options() " {{{1 call vimtex#util#set_default('g:vimtex_complete_close_braces', 0) call vimtex#util#set_default('g:vimtex_complete_recursive_bib', 0) - call vimtex#util#set_default('g:vimtex_complete_img_use_tail', 0) endfunction " }}}1 @@ -378,26 +377,22 @@ let s:img = { \ 'patterns' : ['\v\\includegraphics\*?%(\s*\[[^]]*\]){0,2}\s*\{[^}]*$'], \ 'ext_re' : '\v\.%(' \ . join(['png', 'jpg', 'eps', 'pdf', 'pgf', 'tikz'], '|') - \ . ')$' + \ . ')$', \} function! s:img.complete(regex) dict " {{{2 - let self.candidates = [] - let self.candidates = split(globpath(b:vimtex.root, '**/*.*'), '\n') + call self.get_graphicspaths() + call self.gather_candidates() - let l:output = b:vimtex.out() - call filter(self.candidates, 'v:val !=# l:output') - call filter(self.candidates, 'v:val =~? self.ext_re') call filter(self.candidates, 'v:val =~# a:regex') - call map(self.candidates, 'strpart(v:val, len(b:vimtex.root)+1)') call map(self.candidates, '{ \ ''abbr'' : v:val, \ ''word'' : v:val, \ ''menu'' : '' [graphics]'', \ }') - if g:vimtex_complete_img_use_tail + if !empty(self.graphicspaths) for l:cand in self.candidates let l:cand.word = fnamemodify(l:cand.word, ':t') endfor @@ -406,6 +401,36 @@ function! s:img.complete(regex) dict " {{{2 return self.candidates endfunction +function! s:img.get_graphicspaths() dict " {{{2 + " Get preamble text and remove comments + let l:preamble = vimtex#parser#tex(b:vimtex.tex, { + \ 're_stop': '\\begin{document}', + \ 'detailed': 0, + \}) + call map(l:preamble, 'substitute(v:val, ''\\\@(vimtex-delim-toggle-modifier)|. diff --git a/test/issues/640/testagain/test.pgf b/test/issues/640/testagain/test.pgf new file mode 100644 index 0000000..e69de29 diff --git a/test/issues/640/tested.pdf b/test/issues/640/tested.pdf new file mode 100644 index 0000000..e69de29 diff --git a/test/issues/640/tester/test.pdf b/test/issues/640/tester/test.pdf new file mode 100644 index 0000000..e69de29 diff --git a/test/issues/640/tester/test.tex b/test/issues/640/tester/test.tex new file mode 100644 index 0000000..117f4bc --- /dev/null +++ b/test/issues/640/tester/test.tex @@ -0,0 +1,13 @@ +\documentclass{article} +\usepackage[utf8]{inputenc} +\usepackage{graphicx} +\graphicspath{{test} {testing}% + {../} + {../testagain/} +} + +\begin{document} + +\includegraphics[width=0.9\linewidth]{} + +\end{document} diff --git a/test/issues/640/tester/test/test.png b/test/issues/640/tester/test/test.png new file mode 100644 index 0000000..e69de29 diff --git a/test/issues/640/tester/testing/test.eps b/test/issues/640/tester/testing/test.eps new file mode 100644 index 0000000..e69de29