Update of /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4081
Modified Files:
main.vim texviewer.vim
Log Message:
New: Using :vimgrep if v:version >= 700.
This avoids common pitfalls with correctly setting up the 'grepprg'
and also avoids all the quoting and calling issues on various
platforms. This should hopefully reduce the frequency of the most
commonly occuring problem which users of vim-latex face.
Doing this also uncovered a hidden bug in Tex_ScanFileForLabels().
Looks like cruft was carried over when code was copied over blindly
from Tex_ScanFileForCite().
Also distilled the :grep'ing into Tex_Grep and Tex_Grepadd which call
either :grep or :vimgrep depending on the vim version. A small change
needed to be made to Tex_SyncPreviewWindow() to account for differing
cwindow looks like :grep or :vimgrep is used.
Index: main.vim
===================================================================
RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite/main.vim,v
retrieving revision 1.78
retrieving revision 1.79
diff -C2 -d -r1.78 -r1.79
*** main.vim 7 Sep 2005 18:27:02 -0000 1.78
--- main.vim 25 Sep 2005 09:32:28 -0000 1.79
***************
*** 170,175 ****
" ==============================================================================
! " Helper Functions
" ==============================================================================
" Tex_ShowVariableValue: debugging help {{{
" provides a way to examine script local variables from outside the script.
--- 170,232 ----
" ==============================================================================
! " Helper functions for debugging
" ==============================================================================
+ " Tex_Debug: appends the argument into s:debugString {{{
+ " Description:
+ "
+ " Do not want a memory leak! Set this to zero so that latex-suite always
+ " starts out in a non-debugging mode.
+ if !exists('g:Tex_Debug')
+ let g:Tex_Debug = 0
+ endif
+ function! Tex_Debug(str, ...)
+ if !g:Tex_Debug
+ return
+ endif
+ if a:0 > 0
+ let pattern = a:1
+ else
+ let pattern = ''
+ endif
+ if !exists('s:debugString_'.pattern)
+ let s:debugString_{pattern} = ''
+ endif
+ let s:debugString_{pattern} = s:debugString_{pattern}.a:str."\n"
+
+ let s:debugString_ = (exists('s:debugString_') ? s:debugString_ : '')
+ \ . pattern.' : '.a:str."\n"
+
+ if Tex_GetVarValue('Tex_DebugLog') != ''
+ exec 'redir! >> '.Tex_GetVarValue('Tex_DebugLog')
+ silent! echo pattern.' : '.a:str
+ redir END
+ endif
+ endfunction " }}}
+ " Tex_PrintDebug: prings s:debugString {{{
+ " Description:
+ "
+ function! Tex_PrintDebug(...)
+ if a:0 > 0
+ let pattern = a:1
+ else
+ let pattern = ''
+ endif
+ if exists('s:debugString_'.pattern)
+ echo s:debugString_{pattern}
+ endif
+ endfunction " }}}
+ " Tex_ClearDebug: clears the s:debugString string {{{
+ " Description:
+ "
+ function! Tex_ClearDebug(...)
+ if a:0 > 0
+ let pattern = a:1
+ else
+ let pattern = ''
+ endif
+ if exists('s:debugString_'.pattern)
+ let s:debugString_{pattern} = ''
+ endif
+ endfunction " }}}
" Tex_ShowVariableValue: debugging help {{{
" provides a way to examine script local variables from outside the script.
***************
*** 189,192 ****
--- 246,312 ----
" }}}
+
+ " ==============================================================================
+ " Helper functions for grepping
+ " ==============================================================================
+ " Tex_Grep: shorthand for :grep or :vimgrep {{{
+ function! Tex_Grep(string, where)
+ if v:version >= 700
+ exec 'silent! vimgrep! /'.a:string.'/ '.a:where
+ else
+ exec 'silent! grep! '.Tex_EscapeForGrep(a:string).' '.a:where
+ endif
+ endfunction
+
+ " }}}
+ " Tex_Grepadd: shorthand for :grepadd or :vimgrepadd {{{
+ function! Tex_Grepadd(string, where)
+ if v:version >= 700
+ exec 'silent! vimgrepadd! /'.a:string.'/ '.a:where
+ else
+ exec "silent! grepadd! ".Tex_EscapeForGrep(a:string).' '.a:where
+ endif
+ endfunction
+
+ " }}}
+ " Tex_EscapeForGrep: escapes back-slashes and doublequotes the correct number of times {{{
+ " Description: This command escapes the backslash and double quotes in a
+ " search pattern the correct number of times so it can be used in the ``:grep``
+ " command. This command is meant to be used as::
+ "
+ " exec "silent! grep ".Tex_EscapeForGrep(pattern)." file"
+ "
+ " The input argument to this function should be the string which you want
+ " the external command to finally see. For example, to search for a string
+ " ``'\bibitem'``, the grep command needs to be passed a string like
+ " ``'\\bibitem'``. Examples::
+ "
+ " Tex_EscapeForGrep('\\bibitem') " correct
+ " Tex_EscapeForGrep('\bibitem') " wrong
+ " Tex_EscapeForGrep("\\bibitem") " wrong
+ " Tex_EscapeForGrep('\<word\>') " correct
+ "
+ function! Tex_EscapeForGrep(string)
+ let retVal = a:string
+
+ " The shell halves the backslashes.
+ if &shell =~ 'sh'
+ let retVal = escape(retVal, "\\")
+
+ " If shellxquote is set, then the backslashes are halved yet again.
+ if &shellxquote == '"'
+ let retVal = escape(retVal, "\"\\")
+ endif
+
+ endif
+ " escape special characters which bash/cmd.exe might interpret
+ let retVal = escape(retVal, "<>")
+
+ return retVal
+ endfunction " }}}
+
+ " ==============================================================================
+ " Uncategorized helper functions
+ " ==============================================================================
" Tex_Strntok: extract the n^th token from a list {{{
" example: Strntok('1,23,3', ',', 2) = 23
***************
*** 385,482 ****
let s:incnum = a:val
endfunction " }}}
- " Tex_EscapeForGrep: escapes back-slashes and doublequotes the correct number of times {{{
- " Description: This command escapes the backslash and double quotes in a
- " search pattern the correct number of times so it can be used in the ``:grep``
- " command. This command is meant to be used as::
- "
- " exec "silent! grep ".Tex_EscapeForGrep(pattern)." file"
- "
- " The input argument to this function should be the string which you want
- " the external command to finally see. For example, to search for a string
- " ``'\bibitem'``, the grep command needs to be passed a string like
- " ``'\\bibitem'``. Examples::
- "
- " Tex_EscapeForGrep('\\bibitem') " correct
- " Tex_EscapeForGrep('\bibitem') " wrong
- " Tex_EscapeForGrep("\\bibitem") " wrong
- " Tex_EscapeForGrep('\<word\>') " correct
- "
- function! Tex_EscapeForGrep(string)
- let retVal = a:string
-
- " The shell halves the backslashes.
- if &shell =~ 'sh'
- let retVal = escape(retVal, "\\")
-
- " If shellxquote is set, then the backslashes are halved yet again.
- if &shellxquote == '"'
- let retVal = escape(retVal, "\"\\")
- endif
-
- endif
- " escape special characters which bash/cmd.exe might interpret
- let retVal = escape(retVal, "<>")
-
- return retVal
- endfunction " }}}
- " Functions for debugging {{{
- " Tex_Debug: appends the argument into s:debugString {{{
- " Description:
- "
- " Do not want a memory leak! Set this to zero so that latex-suite always
- " starts out in a non-debugging mode.
- if !exists('g:Tex_Debug')
- let g:Tex_Debug = 0
- endif
- function! Tex_Debug(str, ...)
- if !g:Tex_Debug
- return
- endif
- if a:0 > 0
- let pattern = a:1
- else
- let pattern = ''
- endif
- if !exists('s:debugString_'.pattern)
- let s:debugString_{pattern} = ''
- endif
- let s:debugString_{pattern} = s:debugString_{pattern}.a:str."\n"
-
- let s:debugString_ = (exists('s:debugString_') ? s:debugString_ : '')
- \ . pattern.' : '.a:str."\n"
-
- if Tex_GetVarValue('Tex_DebugLog') != ''
- exec 'redir! >> '.Tex_GetVarValue('Tex_DebugLog')
- silent! echo pattern.' : '.a:str
- redir END
- endif
- endfunction " }}}
- " Tex_PrintDebug: prings s:debugString {{{
- " Description:
- "
- function! Tex_PrintDebug(...)
- if a:0 > 0
- let pattern = a:1
- else
- let pattern = ''
- endif
- if exists('s:debugString_'.pattern)
- echo s:debugString_{pattern}
- endif
- endfunction " }}}
- " Tex_ClearDebug: clears the s:debugString string {{{
- " Description:
- "
- function! Tex_ClearDebug(...)
- if a:0 > 0
- let pattern = a:1
- else
- let pattern = ''
- endif
- if exists('s:debugString_'.pattern)
- let s:debugString_{pattern} = ''
- endif
- endfunction " }}}
- " }}}
" Tex_FindInRtp: check if file exists in &rtp {{{
" Description: Checks if file exists in globpath(&rtp, ...) and cuts off the
--- 505,508 ----
***************
*** 610,614 ****
" keep that as a stable point.
function! Tex_Version()
! return "Latex-Suite: version 1.6.13"
endfunction
--- 636,640 ----
" keep that as a stable point.
function! Tex_Version()
! return "Latex-Suite: version 1.6.14"
endfunction
Index: texviewer.vim
===================================================================
RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite/texviewer.vim,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** texviewer.vim 13 Jun 2004 18:12:40 -0000 1.8
--- texviewer.vim 25 Sep 2005 09:32:28 -0000 1.9
***************
*** 78,82 ****
call Tex_Debug("Tex_Complete: searching for \\labels in all .tex files in the present directory", "view")
call Tex_Debug("Tex_Complete: silent! grep! ".Tex_EscapeForGrep('\\label{'.s:prefix)." *.tex", 'view')
! exec "silent! grep! ".Tex_EscapeForGrep('\\label{'.s:prefix)." *.tex"
else
call Tex_Debug("Tex_Complete: calling Tex_GrepHelper", "view")
--- 78,82 ----
call Tex_Debug("Tex_Complete: searching for \\labels in all .tex files in the present directory", "view")
call Tex_Debug("Tex_Complete: silent! grep! ".Tex_EscapeForGrep('\\label{'.s:prefix)." *.tex", 'view')
! call Tex_Grep('\\label{'.s:prefix, '*.tex')
else
call Tex_Debug("Tex_Complete: calling Tex_GrepHelper", "view")
***************
*** 149,153 ****
endif
call Tex_Debug("silent! grep! ".Tex_EscapeForGrep('\<'.s:word.'\>')." *.tex", 'view')
! exec "silent! grep! ".Tex_EscapeForGrep('\<'.s:word.'\>')." *.tex"
call <SID>Tex_SetupCWindow()
--- 149,153 ----
endif
call Tex_Debug("silent! grep! ".Tex_EscapeForGrep('\<'.s:word.'\>')." *.tex", 'view')
! call Tex_Grep('\<'.s:word.'\>', '*.tex')
call <SID>Tex_SetupCWindow()
***************
*** 156,171 ****
elseif a:where == 'tex'
" Process :TLook command
! exe "silent! grep! ".Tex_EscapeForGrep(a:what)." *.tex"
call <SID>Tex_SetupCWindow()
elseif a:where == 'bib'
" Process :TLookBib command
! exe "silent! grep! ".Tex_EscapeForGrep(a:what)." *.bib"
! exe "silent! grepadd! ".Tex_EscapeForGrep(a:what)." *.bbl"
call <SID>Tex_SetupCWindow()
elseif a:where == 'all'
" Process :TLookAll command
! exe "silent! grep! ".Tex_EscapeForGrep(a:what)." *"
call <SID>Tex_SetupCWindow()
endif
--- 156,171 ----
elseif a:where == 'tex'
" Process :TLook command
! call Tex_Grep(a:what, "*.tex")
call <SID>Tex_SetupCWindow()
elseif a:where == 'bib'
" Process :TLookBib command
! call Tex_Grep(a:what, "*.bib")
! call Tex_Grepadd(a:what, "*.bbl")
call <SID>Tex_SetupCWindow()
elseif a:where == 'all'
" Process :TLookAll command
! call Tex_Grep(a:what, "*")
call <SID>Tex_SetupCWindow()
endif
***************
*** 364,368 ****
let viewfile = matchstr(getline('.'), '^\f*\ze|\d')
! let viewline = matchstr(getline('.'), '|\zs\d\+\ze|')
" Hilight current line in cwindow
--- 364,368 ----
let viewfile = matchstr(getline('.'), '^\f*\ze|\d')
! let viewline = matchstr(getline('.'), '|\zs\d\+\ze')
" Hilight current line in cwindow
***************
*** 541,545 ****
lcd %:p:h
" use the appropriate syntax for the .bib file.
! exec "silent! grepadd! ".Tex_EscapeForGrep('@.*{'.a:prefix)." %"
else
let thisbufnum = bufnr('%')
--- 541,545 ----
lcd %:p:h
" use the appropriate syntax for the .bib file.
! call Tex_Grepadd('@.*{'.a:prefix, "%")
else
let thisbufnum = bufnr('%')
***************
*** 549,553 ****
call Tex_Debug('finding .bbl file ['.bufname('.').']', 'view')
lcd %:p:h
! exec "silent! grepadd! ".Tex_EscapeForGrep('\\bibitem{'.a:prefix)." %"
endif
endif
--- 549,553 ----
call Tex_Debug('finding .bbl file ['.bufname('.').']', 'view')
lcd %:p:h
! call Tex_Grepadd('\\bibitem{'.a:prefix, "%")
endif
endif
***************
*** 574,578 ****
lcd %:p:h
call Tex_Debug("silent! grepadd! ".Tex_EscapeForGrep('\\bibitem{'.a:prefix)." %", 'view')
! exec "silent! grepadd! ".Tex_EscapeForGrep('\\bibitem{'.a:prefix)." %"
q
--- 574,578 ----
lcd %:p:h
call Tex_Debug("silent! grepadd! ".Tex_EscapeForGrep('\\bibitem{'.a:prefix)." %", 'view')
! call Tex_Grepadd('\\bibitem{'.a:prefix, "%")
q
***************
*** 621,625 ****
lcd %:p:h
! exec "silent! grepadd! ".Tex_EscapeForGrep('\\label{'.a:prefix)." %"
" Then recursively grep for all \include'd or \input'ed files.
--- 621,625 ----
lcd %:p:h
! call Tex_Grepadd('\\label{'.a:prefix, "%")
" Then recursively grep for all \include'd or \input'ed files.
***************
*** 640,651 ****
if bufnr('%') != thisbufnum
call Tex_Debug('Tex_ScanFileForLabels: scanning recursively in ['.bufname('%').']', 'view')
! let foundCiteFile = Tex_ScanFileForLabels(a:prefix)
endif
q
- if foundCiteFile
- return 1
- endif
endwhile
endfunction " }}}
--- 640,648 ----
if bufnr('%') != thisbufnum
call Tex_Debug('Tex_ScanFileForLabels: scanning recursively in ['.bufname('%').']', 'view')
! call Tex_ScanFileForLabels(a:prefix)
endif
q
endwhile
endfunction " }}}
|