[Vim-latex-cvs] vimfiles/ftplugin/latex-suite multicompile.vim,1.2,1.3
Brought to you by:
srinathava,
tmaas
|
From: <sri...@us...> - 2003-08-31 08:25:20
|
Update of /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite
In directory sc8-pr-cvs1:/tmp/cvs-serv29731
Modified Files:
multicompile.vim
Log Message:
- Refactored code to only have one copy of the main function
Tex_CompileMultipleTimes() instead of maintaining a duplicate. Just
duplicate the helper functions.
- Also removed a bug in the original version where a change in the index
terms was not causing latex to be rerun.
Index: multicompile.vim
===================================================================
RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite/multicompile.vim,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** multicompile.vim 29 Aug 2003 02:32:51 -0000 1.2
--- multicompile.vim 31 Aug 2003 08:25:15 -0000 1.3
***************
*** 10,36 ****
" ============================================================================
! " Tex_CompileMultipleTimes: compile a latex file multiple times {{{
! " Description: compile a latex file multiple times to get cross-references asd
! " right.
function! Tex_CompileMultipleTimes()
! if has('python') && g:Tex_UsePython
! python compileMultipleTimes()
! else
! call Tex_CompileMultipleTimes_Vim()
endif
! endfunction " }}}
! if !has('python') || !g:Tex_UsePython
! " Tex_GotoTempFile: open a temp file. reuse from next time on {{{
! " Description:
! function! Tex_GotoTempFile()
! if !exists('s:tempFileName')
! let s:tempFileName = tempname()
endif
! exec 'silent! split '.s:tempFileName
! endfunction " }}}
! " Tex_IsPresentInFile: finds if a string str, is present in filename {{{
! " Description:
! function! Tex_IsPresentInFile(regexp, filename)
call Tex_GotoTempFile()
--- 10,100 ----
" ============================================================================
! " Tex_CompileMultipleTimes: The main function {{{
! " Description: compiles a file multiple times to get cross-references right.
function! Tex_CompileMultipleTimes()
! let mainFileName_root = Tex_GetMainFileName(':p:t:r:r')
!
! if mainFileName_root == ''
! let mainFileName_root = expand("%:p:t:r")
! endif
!
! let idxFileName = mainFileName_root.'.idx'
!
!
! let runCount = 0
! let needToRerun = 1
! while needToRerun == 1 && runCount < 5
! " assume we need to run only once.
! let needToRerun = 0
!
! let idxlinesBefore = Tex_CatFile(idxFileName)
!
! " first run latex once.
! silent! call Tex_CompileLatex()
!
! let idxlinesAfter = Tex_CatFile(idxFileName)
!
! " If .idx file changed, then run makeindex to generate the new .ind
! " file and remember to rerun latex.
! if runCount == 0 && glob(idxFileName) != '' && idxlinesAfter != idxlinesAfter
! echomsg "running makeindex..."
! let temp_mp = &mp | let &mp='makeindex $*.idx'
! exec 'silent! make '.mainFileName_root
! let &mp = temp_mp
!
! let needToRerun = 1
! endif
!
! " The first time we see if we need to run bibtex
! if runCount == 0 && Tex_IsPresentInFile('\\bibdata', mainFileName_root.'.aux')
! let bibFileName = mainFileName_root . '.bbl'
!
! let biblinesBefore = Tex_CatFile(bibFileName)
!
! echomsg "running bibtex..."
! let temp_mp = &mp | let &mp='bibtex'
! exec 'silent! make '.mainFileName_root
! let &mp = temp_mp
!
! let biblinesAfter = Tex_CatFile(bibFileName)
!
! " If the .bbl file changed after running bibtex, we need to
! " latex again.
! if biblinesAfter != biblinesBefore
! echomsg 'need to rerun because bibliography file changed...'
! let needToRerun = 1
endif
! endif
! " check if latex asks us to rerun
! if Tex_IsPresentInFile('Rerun to get cross-references right', mainFileName_root.'.log')
! echomsg "need to rerun to get cross-references right..."
! let needToRerun = 1
endif
!
! let runCount = runCount + 1
! endwhile
!
! " finally set up the error window and the preview of the log
! silent! call Tex_SetupErrorWindow()
! endfunction " }}}
!
! " Various helper functions used by Tex_CompileMultipleTimes(). These functions
! " use python where available (and allowed) otherwise do it in native vim at
! " the cost of some slowdown and some new temporary buffers being opened.
! " Tex_GotoTempFile: open a temp file. reuse from next time on {{{
! " Description:
! function! Tex_GotoTempFile()
! if !exists('s:tempFileName')
! let s:tempFileName = tempname()
! endif
! exec 'silent! split '.s:tempFileName
! endfunction " }}}
! " Tex_IsPresentInFile: finds if a string str, is present in filename {{{
! " Description:
! function! Tex_IsPresentInFile(regexp, filename)
! if has('python') && g:Tex_UsePython
! exec 'python isPresentInFile(r"'.a:regexp.'", r"'.a:filename.'")'
! else
call Tex_GotoTempFile()
***************
*** 45,60 ****
if search(a:regexp, 'w')
! let retVal = 1
else
! let retVal = 0
endif
-
silent! bd
- return retVal
- endfunction " }}}
- " Tex_CatFile: returns the contents of the file in a string {{{
- " Description:
- function! Tex_CatFile(filename)
call Tex_GotoTempFile()
--- 109,131 ----
if search(a:regexp, 'w')
! let retval = 1
else
! let retval = 0
endif
silent! bd
+ endif
+
+ return retval
+ endfunction " }}}
+ " Tex_CatFile: returns the contents of a file in a <NL> seperated string {{{
+ function! Tex_CatFile(filename)
+ if has('python') && g:Tex_UsePython
+ " catFile assigns a value to retval
+ exec 'python catFile("'.a:filename.'")'
+ else
+ if glob(a:filename) == ''
+ return ''
+ endif
call Tex_GotoTempFile()
***************
*** 69,73 ****
let _a = @a
silent! normal! ggVG"ay
! let retVal = @a
let @a = _a
--- 140,144 ----
let _a = @a
silent! normal! ggVG"ay
! let retval = @a
let @a = _a
***************
*** 75,157 ****
let &report = _report
let &sc = _sc
! return retVal
! endfunction " }}}
! " Tex_CompileMultipleTimes_Vim: vim implementaion of compileMultipleTimes() {{{
! " Description: compiles a file multiple times to get cross-references right.
! function! Tex_CompileMultipleTimes_Vim()
! let mainFileName_root = Tex_GetMainFileName(':p:t:r:r')
!
! if mainFileName_root == ''
! let mainFileName_root = expand("%:p:t:r")
! endif
!
! let runCount = 0
! let needToRerun = 1
! while needToRerun == 1 && runCount < 5
! " assume we need to run only once.
! let needToRerun = 0
!
! " first run latex once.
! silent! call Tex_CompileLatex()
!
! " The first time we see if we need to run bibtex
! if runCount == 0 && Tex_IsPresentInFile('\\bibdata', mainFileName_root.'.aux')
! let bibFileName = mainFileName_root . '.bbl'
!
! let biblinesBefore = Tex_CatFile(bibFileName)
!
! echomsg "running bibtex..."
! let temp_mp = &mp | let &mp='bibtex'
! exec 'silent! make '.mainFileName_root
! let &mp = temp_mp
!
! let biblinesAfter = Tex_CatFile(bibFileName)
!
! " If the .bbl file changed after running bibtex, we need to
! " latex again.
! if biblinesAfter != biblinesBefore
! echomsg 'need to rerun because bibliography file changed...'
! let needToRerun = 1
! endif
! endif
!
! if runCount == 0 && filereadable(mainFileName_root.'.idx')
! let idxFileName = mainFileName_root.'.idx'
! let idxlinesBefore = Tex_CatFile(idxFileName)
!
! echomsg "running makeindex..."
! let temp_mp = &mp | let &mp='makeindex $*.idx'
! exec 'silent! make '.mainFileName_root
! let &mp = temp_mp
!
! let idxlinesAfter = Tex_CatFile(idxFileName)
!
! " If the .idx file changed, then we need to rerun.
! if idxlinesBefore != idxlinesAfter
! echomsg 'need to rerun to get index right...'
! let needToRerun = 1
! endif
! endif
!
! " check if latex asks us to rerun
! if Tex_IsPresentInFile('Rerun to get cross-references right', mainFileName_root.'.log')
! echomsg "need to rerun to get cross-references right..."
! let needToRerun = 1
! endif
!
! let runCount = runCount + 1
! endwhile
!
! " finally set up the error window and the preview of the log
! silent! call Tex_SetupErrorWindow()
! endfunction " }}}
finish
endif
python <<EOF
! import vim
! import re, os, string
# isPresentInFile: check if regexp is present in the file {{{
def isPresentInFile(regexp, filename):
--- 146,176 ----
let &report = _report
let &sc = _sc
! endif
! return retval
! endfunction
! " }}}
+ " Define the functions in python if available.
+ if !has('python') || !g:Tex_UsePython
finish
endif
python <<EOF
! import string, vim, re
! # catFile: assigns a local variable retval to the contents of a file {{{
! def catFile(filename):
! try:
! file = open(fname)
! lines = ''.join(file.readlines())
! file.close()
! except:
! lines = ''
!
! # escape double quotes and backslashes before quoting the string so
! # everything passes throught.
! vim.command("""let retval = "%s" """ % re.sub(r'"|\\', r'\\\g<0>', lines))
! return lines
+ # }}}
# isPresentInFile: check if regexp is present in the file {{{
def isPresentInFile(regexp, filename):
***************
*** 161,245 ****
fp.close()
if re.search(regexp, fcontents):
return 1
else:
return None
except:
return None
- # }}}
- # catFile: return the contents of a file. {{{
- def catFile(fileName):
- try:
- file = open(fileName)
- lines = string.join(file.readlines(), '')
- file.close()
- except:
- lines = ''
- return lines
-
- # }}}
- # compileMultipleTimes: compile the main file multiple times as needed. {{{
- def compileMultipleTimes():
- mainFileName_full = vim.eval("Tex_GetMainFileName(':p:r')")
- mainFileName_root = vim.eval("Tex_GetMainFileName(':p:r:r')")
-
- if not mainFileName_root:
- mainFileName_full = vim.eval('expand("%:p")')
- mainFileName_root = vim.eval('expand("%:p:r")')
-
- runCount = 0
- needToRerun = 1
- while needToRerun == 1 and runCount < 5:
- needToRerun = 0
-
- # first run latex once.
- vim.command('silent! call Tex_CompileLatex()')
-
- if runCount == 0 and isPresentInFile(r'\\bibdata', mainFileName_root + '.aux'):
- bibFileName = mainFileName_root + '.bbl'
-
- biblinesBefore = catFile(bibFileName)
-
- vim.command('echomsg "running bibtex..."')
- vim.command('let temp_mp = &mp | let &mp=\'bibtex\'')
- vim.command('silent! make %s' % mainFileName_root)
- vim.command('let &mp = temp_mp')
-
- biblinesAfter = catFile(bibFileName)
-
- # if the .bbl file changed with this bibtex command, then we need
- # to rerun latex to refresh the bibliography
- if biblinesAfter != biblinesBefore:
- vim.command("echomsg 'need to rerun because bibliography file changed...'")
- needToRerun = 1
-
- # The first time see if a .idx file has been created. If so we need to
- # run makeindex.
- if runCount == 0 and os.path.exists(mainFileName_root + '.idx'):
- idxFileName = mainFileName_root + '.idx'
- idxlinesBefore = catFile(idxFileName)
-
- vim.command('echomsg "running makeindex..."')
- vim.command("""let temp_mp = &mp | let &mp='makeindex $*.idx'""")
- vim.command("""silent! make %s""" % mainFileName_root)
- vim.command("""let &mp = temp_mp""")
-
- idxlinesAfter = Tex_CatFile(idxFileName)
-
- # If the .idx file changed, then we need to rerun.
- if idxlinesBefore != idxlinesAfter:
- vim.command("echomsg 'need to rerun to get index right...'")
- needToRerun = 1
-
- # check if latex asks us to rerun
- if isPresentInFile('Rerun to get cross-references right', mainFileName_root + '.log'):
- vim.command('echomsg "need to rerun to get cross-references right..."')
- needToRerun = 1
-
- runCount = runCount + 1
-
- # finally set up the error window and the preview of the log
- vim.command('echomsg "ran latex a total of %d times"' % runCount)
- vim.command('silent! call Tex_SetupErrorWindow()')
# }}}
EOF
--- 180,192 ----
fp.close()
if re.search(regexp, fcontents):
+ vim.command('let retval = 1')
return 1
else:
+ vim.command('let retval = 0')
return None
except:
+ vim.command('let retval = 0')
return None
# }}}
EOF
|