Compare commits
3 Commits
master
...
issue-630/
Author | SHA1 | Date | |
---|---|---|---|
|
b1696f0767 | ||
|
ed0106cbcf | ||
|
924d507a2f |
@ -460,8 +460,8 @@ function! s:init_local_blob() " {{{1
|
||||
let l:local.tex = l:filename
|
||||
let l:local.pid = 0
|
||||
let l:local.name = fnamemodify(l:filename, ':t:r')
|
||||
let l:local.root = fnamemodify(l:filename, ':h')
|
||||
let l:local.base = fnamemodify(l:filename, ':t')
|
||||
let l:local.root = get(s:, 'root', fnamemodify(l:filename, ':h'))
|
||||
let l:local.base = get(s:, 'base', fnamemodify(l:filename, ':t'))
|
||||
|
||||
let s:vimtex_next_id += 1
|
||||
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
|
||||
" several other plugins and editors.
|
||||
"
|
||||
let l:candidate = s:get_main_from_specifier(
|
||||
\ '^\c\s*%\s*!\?\s*tex\s\+root\s*=\s*\zs.*\ze\s*$')
|
||||
let l:candidate = s:get_main_from_texroot()
|
||||
if !empty(l:candidate)
|
||||
return l:candidate
|
||||
endif
|
||||
@ -528,8 +527,7 @@ function! s:get_main() " {{{1
|
||||
"
|
||||
" Support for subfiles package
|
||||
"
|
||||
let l:candidate = s:get_main_from_specifier(
|
||||
\ '^\C\s*\\documentclass\[\zs.*\ze\]{subfiles}')
|
||||
let l:candidate = s:get_main_from_subfile()
|
||||
if !empty(l:candidate)
|
||||
return l:candidate
|
||||
endif
|
||||
@ -570,21 +568,47 @@ function! s:get_main() " {{{1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! s:get_main_from_specifier(spec) " {{{1
|
||||
function! s:get_main_from_texroot() " {{{1
|
||||
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 l:filename[0] ==# '/'
|
||||
if filereadable(l:filename) | return l:filename | endif
|
||||
else
|
||||
" The candidate may be relative both to the current buffer file and to
|
||||
" the working directory (for subfile package)
|
||||
for l:candidate in map([
|
||||
\ expand('%:p:h'),
|
||||
\ getcwd()],
|
||||
\ 'simplify(v:val . ''/'' . l:filename)')
|
||||
let l:candidate = simplify(expand('%:p:h') . '/' . l:filename)
|
||||
if filereadable(l:candidate) | return l:candidate | endif
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ''
|
||||
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
|
||||
endfor
|
||||
|
2
test/issues/630/localpackage.sty
Normal file
2
test/issues/630/localpackage.sty
Normal file
@ -0,0 +1,2 @@
|
||||
\ProvidesPackage{localpackage}
|
||||
\endinput
|
10
test/issues/630/main.tex
Normal file
10
test/issues/630/main.tex
Normal 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
17
test/issues/630/minivimrc
Normal 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
|
5
test/issues/630/sub/sub.tex
Normal file
5
test/issues/630/sub/sub.tex
Normal file
@ -0,0 +1,5 @@
|
||||
\documentclass[main.tex]{subfiles}
|
||||
|
||||
\begin{document}
|
||||
a
|
||||
\end{document}
|
Loading…
Reference in New Issue
Block a user