Better search for mail file (fixes #30)

Don't assume project structure is
  project/subdirs/files,
Instead search every parent folder for possible tex files.
This commit is contained in:
Karl Yngve Lervåg 2014-07-16 11:37:39 +02:00
parent 9a715c57a9
commit da45ad0c50

View File

@ -265,11 +265,20 @@ function! s:get_main_recurse(file) " {{{1
endif endif
" "
" Search for files that include the current file " Gather candidate files
" "
let l:glob1 = expand('%:p:h') . '/*.tex' let l:path = expand('%:p:h')
let l:glob2 = expand('%:p:h:h') . '/*.tex' let l:dirs = l:path
for l:file in split(glob(l:glob1)) + split(glob(l:glob2)) while l:path != '/'
let l:path = fnamemodify(l:path, ':h')
let l:dirs .= ',' . l:path
endwhile
let l:candidates = globpath(l:dirs, '*.tex', 0, 1)
"
" Search through candidates for \include{current file}
"
for l:file in l:candidates
if len(filter(readfile(l:file), 'v:val =~ ''\v\\(input|include)\{' if len(filter(readfile(l:file), 'v:val =~ ''\v\\(input|include)\{'
\ . '((.*)\/)?' \ . '((.*)\/)?'
\ . fnamemodify(a:file, ':t:r') . '(\.tex)?''')) > 0 \ . fnamemodify(a:file, ':t:r') . '(\.tex)?''')) > 0