2015-07-18 17:05:45 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
|
|
|
|
2014-07-29 07:03:49 -04:00
|
|
|
" LatexBox_GetMainFileName: gets the name of the main file being compiled. {{{
|
2013-09-16 19:43:28 -04:00
|
|
|
" Description: returns the full path name of the main file.
|
|
|
|
" This function checks for the existence of a .latexmain file
|
|
|
|
" which might point to the location of a "main" latex file.
|
|
|
|
" If .latexmain exists, then return the full path name of the
|
|
|
|
" file being pointed to by it.
|
|
|
|
"
|
|
|
|
" Otherwise, return the full path name of the current buffer.
|
|
|
|
"
|
|
|
|
" You can supply an optional "modifier" argument to the
|
|
|
|
" function, which will optionally modify the file name before
|
|
|
|
" returning.
|
|
|
|
" NOTE: From version 1.6 onwards, this function always trims
|
|
|
|
" away the .latexmain part of the file name before applying the
|
|
|
|
" modifier argument.
|
2014-07-29 07:03:49 -04:00
|
|
|
" NOTE: This function is copied from the Latex-Suite project!
|
|
|
|
function! LatexBox_GetMainFileName(...)
|
2013-09-16 19:43:28 -04:00
|
|
|
if a:0 > 0
|
|
|
|
let modifier = a:1
|
|
|
|
else
|
|
|
|
let modifier = ':p'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:origdir = fnameescape(getcwd())
|
|
|
|
|
|
|
|
let dirmodifier = '%:p:h'
|
|
|
|
let dirLast = fnameescape(expand(dirmodifier))
|
|
|
|
exe 'cd '.dirLast
|
|
|
|
|
|
|
|
" move up the directory tree until we find a .latexmain file.
|
|
|
|
" TODO: Should we be doing this recursion by default, or should there be a
|
|
|
|
" setting?
|
2015-01-23 15:09:23 -05:00
|
|
|
while glob('*.latexmain',1) == ''
|
2013-09-16 19:43:28 -04:00
|
|
|
let dirmodifier = dirmodifier.':h'
|
|
|
|
let dirNew = fnameescape(expand(dirmodifier))
|
|
|
|
" break from the loop if we cannot go up any further.
|
|
|
|
if dirNew == dirLast
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
let dirLast = dirNew
|
|
|
|
exe 'cd '.dirLast
|
|
|
|
endwhile
|
|
|
|
|
2015-01-23 15:09:23 -05:00
|
|
|
let lheadfile = glob('*.latexmain',1)
|
2013-09-16 19:43:28 -04:00
|
|
|
if lheadfile != ''
|
|
|
|
" Remove the trailing .latexmain part of the filename... We never want
|
|
|
|
" that.
|
|
|
|
let lheadfile = fnamemodify(substitute(lheadfile, '\.latexmain$', '', ''), modifier)
|
|
|
|
else
|
|
|
|
" If we cannot find any main file, just modify the filename of the
|
|
|
|
" current buffer.
|
|
|
|
let lheadfile = expand('%'.modifier)
|
|
|
|
endif
|
|
|
|
|
2014-07-29 07:03:49 -04:00
|
|
|
exe 'cd '.s:origdir
|
2013-09-16 19:43:28 -04:00
|
|
|
|
|
|
|
" NOTE: The caller of this function needs to escape the file name with
|
|
|
|
" fnameescape() . The reason its not done here is that escaping is not
|
|
|
|
" safe if this file is to be used as part of an external command on
|
|
|
|
" certain platforms.
|
|
|
|
return lheadfile
|
|
|
|
endfunction
|
2015-07-18 17:05:45 -04:00
|
|
|
|
|
|
|
endif
|