From 184fca889a99263f2b144381474f5a3415418b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Jan 2017 21:43:44 +0100 Subject: [PATCH 1/3] Added test files for #640 --- test/issues/640/testagain/test.pgf | 0 test/issues/640/tested.pdf | 0 test/issues/640/tester/test.pdf | 0 test/issues/640/tester/test.tex | 13 +++++++++++++ test/issues/640/tester/test/test.png | 0 test/issues/640/tester/testing/test.eps | 0 6 files changed, 13 insertions(+) create mode 100644 test/issues/640/testagain/test.pgf create mode 100644 test/issues/640/tested.pdf create mode 100644 test/issues/640/tester/test.pdf create mode 100644 test/issues/640/tester/test.tex create mode 100644 test/issues/640/tester/test/test.png create mode 100644 test/issues/640/tester/testing/test.eps 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 From c98b1783770d6bb4a35427943a6ecac9d97ad6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Jan 2017 21:46:41 +0100 Subject: [PATCH 2/3] Added functions to calculate relative path --- autoload/vimtex/paths.vim | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 autoload/vimtex/paths.vim diff --git a/autoload/vimtex/paths.vim b/autoload/vimtex/paths.vim new file mode 100644 index 0000000..77b7e3c --- /dev/null +++ b/autoload/vimtex/paths.vim @@ -0,0 +1,44 @@ +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve LervÄg +" Email: karl.yngve@gmail.com +" + +function! vimtex#paths#shorten_relative(path) " {{{1 + " Input: An absolute path + " Output: Relative path with respect to the vimtex root, path relative to + " vimtex root (unless absolute path is shorter) + + let l:relative = vimtex#paths#relative(a:path, b:vimtex.root) + return strlen(l:relative) < strlen(a:path) + \ ? l:relative : a:path +endfunction + +" }}}1 +function! vimtex#paths#relative(path, current) " {{{1 + " Note: This algorithm is based on the one presented by @Offirmo at SO, + " http://stackoverflow.com/a/12498485/51634 + let l:target = a:path + + let l:common = a:current + let l:result = '' + while substitute(l:target, '^' . l:common, '', '') ==# l:target + let l:common = fnamemodify(l:common, ':h') + let l:result = empty(l:result) ? '..' : '../' . l:result + endwhile + + if l:common ==# '/' + let l:result .= '/' + endif + + let l:forward = substitute(l:target, '^' . l:common, '', '') + if !empty(l:forward) + let l:result = empty(l:result) + \ ? l:forward[1:] + \ : l:result . l:forward + endif + + return l:result +endfunction + +" }}}1 From f86a72ce9019056f6b2a944737f125a2e239065c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 9 Jan 2017 21:47:50 +0100 Subject: [PATCH 3/3] Fixed #640: Parse \graphicspath for img completion Note: This deprecates the option g:vimtex_complete_img_use_tail! --- autoload/vimtex/complete.vim | 43 ++++++++++++++++++++++++++++-------- doc/vimtex.txt | 6 ----- 2 files changed, 34 insertions(+), 15 deletions(-) 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)|.