Refactored and improved recursive file finder
This commit is contained in:
parent
404061ff99
commit
4c76e8f740
@ -594,21 +594,7 @@ endfunction
|
|||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
function! s:get_main_latexmain(file) " {{{1
|
function! s:get_main_latexmain(file) " {{{1
|
||||||
"
|
for l:cand in s:findfiles_recursive('*.latexmain', expand('%:p:h'))
|
||||||
" Gather candidate files
|
|
||||||
"
|
|
||||||
let l:path = expand('%:p:h')
|
|
||||||
let l:dirs = l:path
|
|
||||||
while l:path != fnamemodify(l:path, ':h')
|
|
||||||
let l:path = fnamemodify(l:path, ':h')
|
|
||||||
let l:dirs .= ',' . l:path
|
|
||||||
endwhile
|
|
||||||
let l:candidates = split(globpath(fnameescape(l:dirs), '*.latexmain'), '\n')
|
|
||||||
|
|
||||||
"
|
|
||||||
" Use first valid candidate
|
|
||||||
"
|
|
||||||
for l:cand in l:candidates
|
|
||||||
let l:cand = fnamemodify(l:cand, ':p:r')
|
let l:cand = fnamemodify(l:cand, ':p:r')
|
||||||
if s:file_reaches_current(l:cand)
|
if s:file_reaches_current(l:cand)
|
||||||
return l:cand
|
return l:cand
|
||||||
@ -636,20 +622,9 @@ function! s:get_main_recurse(...) " {{{1
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
"
|
"
|
||||||
" Gather candidate files
|
" Search through candidates found recursively upwards in the directory tree
|
||||||
"
|
"
|
||||||
let l:path = fnamemodify(l:file, ':p:h')
|
for l:cand in s:findfiles_recursive('*.tex', fnamemodify(l:file, ':p:h'))
|
||||||
let l:dirs = l:path
|
|
||||||
while l:path != fnamemodify(l:path, ':h')
|
|
||||||
let l:path = fnamemodify(l:path, ':h')
|
|
||||||
let l:dirs .= ',' . l:path
|
|
||||||
endwhile
|
|
||||||
let l:candidates = split(globpath(fnameescape(l:dirs), '*.tex'), '\n')
|
|
||||||
|
|
||||||
"
|
|
||||||
" Search through candidates
|
|
||||||
"
|
|
||||||
for l:cand in l:candidates
|
|
||||||
" Avoid infinite recursion (checking the same file repeatedly)
|
" Avoid infinite recursion (checking the same file repeatedly)
|
||||||
if l:cand == l:file | continue | endif
|
if l:cand == l:file | continue | endif
|
||||||
|
|
||||||
@ -706,6 +681,17 @@ function! s:file_reaches_current(file) " {{{1
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" }}}1
|
||||||
|
function! s:findfiles_recursive(expr, path) " {{{1
|
||||||
|
let l:path = a:path
|
||||||
|
let l:dirs = l:path
|
||||||
|
while l:path != fnamemodify(l:path, ':h')
|
||||||
|
let l:path = fnamemodify(l:path, ':h')
|
||||||
|
let l:dirs .= ',' . l:path
|
||||||
|
endwhile
|
||||||
|
return split(globpath(fnameescape(l:dirs), a:expr), '\n')
|
||||||
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|
||||||
function! s:get_log() dict " {{{1
|
function! s:get_log() dict " {{{1
|
||||||
|
Loading…
Reference in New Issue
Block a user