Compare commits

...

3 Commits

Author SHA1 Message Date
Karl Yngve Lervåg
b1696f0767 Use findfile to simplify recursive file finding 2017-01-03 23:11:02 +01:00
Karl Yngve Lervåg
ed0106cbcf Fix #630: Allow subfile main path relative to main 2016-12-30 23:08:58 +01:00
Karl Yngve Lervåg
924d507a2f Added test files 2016-12-30 23:06:43 +01:00
5 changed files with 74 additions and 16 deletions

View File

@ -460,8 +460,8 @@ function! s:init_local_blob() " {{{1
let l:local.tex = l:filename let l:local.tex = l:filename
let l:local.pid = 0 let l:local.pid = 0
let l:local.name = fnamemodify(l:filename, ':t:r') let l:local.name = fnamemodify(l:filename, ':t:r')
let l:local.root = fnamemodify(l:filename, ':h') let l:local.root = get(s:, 'root', fnamemodify(l:filename, ':h'))
let l:local.base = fnamemodify(l:filename, ':t') let l:local.base = get(s:, 'base', fnamemodify(l:filename, ':t'))
let s:vimtex_next_id += 1 let s:vimtex_next_id += 1
let g:vimtex_data[s:vimtex_next_id] = l:local let g:vimtex_data[s:vimtex_next_id] = l:local
@ -519,8 +519,7 @@ function! s:get_main() " {{{1
" Search for TEX root specifier at the beginning of file. This is used by " Search for TEX root specifier at the beginning of file. This is used by
" several other plugins and editors. " several other plugins and editors.
" "
let l:candidate = s:get_main_from_specifier( let l:candidate = s:get_main_from_texroot()
\ '^\c\s*%\s*!\?\s*tex\s\+root\s*=\s*\zs.*\ze\s*$')
if !empty(l:candidate) if !empty(l:candidate)
return l:candidate return l:candidate
endif endif
@ -528,8 +527,7 @@ function! s:get_main() " {{{1
" "
" Support for subfiles package " Support for subfiles package
" "
let l:candidate = s:get_main_from_specifier( let l:candidate = s:get_main_from_subfile()
\ '^\C\s*\\documentclass\[\zs.*\ze\]{subfiles}')
if !empty(l:candidate) if !empty(l:candidate)
return l:candidate return l:candidate
endif endif
@ -570,21 +568,47 @@ function! s:get_main() " {{{1
endfunction endfunction
" }}}1 " }}}1
function! s:get_main_from_specifier(spec) " {{{1 function! s:get_main_from_texroot() " {{{1
for l:line in getline(1, 5) for l:line in getline(1, 5)
let l:filename = matchstr(l:line, a:spec) let l:filename = matchstr(l:line,
\ '^\c\s*%\s*!\?\s*tex\s\+root\s*=\s*\zs.*\ze\s*$')
if len(l:filename) > 0 if len(l:filename) > 0
if l:filename[0] ==# '/' if l:filename[0] ==# '/'
if filereadable(l:filename) | return l:filename | endif if filereadable(l:filename) | return l:filename | endif
else else
" The candidate may be relative both to the current buffer file and to let l:candidate = simplify(expand('%:p:h') . '/' . l:filename)
" the working directory (for subfile package) if filereadable(l:candidate) | return l:candidate | endif
for l:candidate in map([ endif
\ expand('%:p:h'), endif
\ getcwd()], endfor
\ 'simplify(v:val . ''/'' . l:filename)')
if filereadable(l:candidate) | return l:candidate | endif return ''
endfor endfunction
" }}}1
function! s:get_main_from_subfile() " {{{1
for l:line in getline(1, 5)
let l:filename = matchstr(l:line,
\ '^\C\s*\\documentclass\[\zs.*\ze\]{subfiles}')
if len(l:filename) > 0
if l:filename[0] ==# '/'
" Specified path is absolute
if filereadable(l:filename) | return l:filename | endif
else
" Try specified path as relative to current file path
let l:candidate = simplify(expand('%:p:h') . '/' . l:filename)
if filereadable(l:candidate) | return l:candidate | endif
" Try specified path as relative to the project main file. This is
" difficult, since the main file is the one we are looking for. We
" therefore assume that the main file lives somewhere upwards in the
" directory tree.
let l:candidate = findfile(l:filename, '.;')
if filereadable(l:candidate)
let s:root = fnamemodify(l:candidate, ':h')
let s:base = strpart(expand('%:p'), len(s:root) + 1)
return l:candidate
endif
endif endif
endif endif
endfor endfor

View File

@ -0,0 +1,2 @@
\ProvidesPackage{localpackage}
\endinput

10
test/issues/630/main.tex Normal file
View File

@ -0,0 +1,10 @@
\documentclass{article}
\usepackage{filecontents}
\usepackage{subfiles}
\usepackage{localpackage}
\begin{document}
\subfile{sub/sub.tex}
b
\end{document}

17
test/issues/630/minivimrc Normal file
View File

@ -0,0 +1,17 @@
set nocompatible
let &rtp = '~/.vim/bundle/vimtex,' . &rtp
let &rtp .= ',~/.vim/bundle/vimtex/after'
filetype plugin indent on
syntax enable
let g:tex_flavor = "latex"
let g:vimtex_latexmk_background = 1
let g:vimtex_view_general_viewer = 'SumatraPDF'
let g:vimtex_view_general_options =
\ '-reuse-instance -forward-search @line @pdf @tex'
let g:vimtex_view_general_options_latexmk = '-reuse-instance'
if !has('win32')
echoerr 'This test case should be run on windows!'
endif

View File

@ -0,0 +1,5 @@
\documentclass[main.tex]{subfiles}
\begin{document}
a
\end{document}