Update of /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25857
Modified Files:
main.vim texviewer.vim
Added Files:
outline.py
Log Message:
New: A major new feature for making \ref completion easier. Instead of a
flat list of all the \label's which becomes almost impossible to use
in large projects, present the list of \label's in a tree form
according to the document sectioning. This makes it easier to
logically "zoom" into the relevant \labels without having to wade
through gobs and gobs of irrelevant results.
outline.py is a new python script which needs to run in order to get
this to work. The file should be an executable present in the same
path as outline.vim. Since the file was added on a windows machine,
its not clear how CVS will treat the permissions.
New: The filenames are now completed relative to the master tex file
location. This is how latex wants the filenames.
--- NEW FILE: outline.py ---
#!/usr/bin/python
# Part of Latex-Suite
#
# Copyright: Srinath Avadhanula
# Description:
# This file implements a simple outline creation for latex documents.
import re
import os
import sys
# getFileContents {{{
def getFileContents(argin, ext=''):
if type(argin) is str:
fname = argin + ext
else:
if argin.group(2) == 'include':
fname = argin.group(3) + ext
else:
fname = argin.group(3)
contents = open(fname).read()
# TODO what are all the ways in which a tex file can include another?
pat = re.compile(r'^\\(@?)(include|input){(.*?)}', re.M)
contents = re.sub(pat, lambda input: getFileContents(input, ext), contents)
return ('%%==== FILENAME: %s' % fname) + '\n' + contents
# }}}
# createOutline {{{
def createOutline(contents, prefix):
"""
Prints a formatted outline of the latex document on the standard
output. The output is of the form:
1. Introduction
1.1 Introduction section
> eqn:firsteqn
: 2 == 2
> fig:figure1
: Caption for the figure
1.2 Second section name of introduction
If ``prefix`` is given, then only labels which start with it are
listed.
"""
# This is the hierarchical list of the sectioning of a latex document.
outline_cmds = ['chapter', 'section', 'subsection', 'subsubsection']
outline_nums = {}
for cmd in outline_cmds:
outline_nums[cmd] = 0
pres_depth = 0
fname = ''
prev_txt = ''
inside_env = 0
prev_env = ''
for line in contents.splitlines():
# remember which file we are currently "in"
if re.match('%==== FILENAME: ', line):
fname = re.search('%==== FILENAME: (.*)', line).group(1)
# throw away everything after the %
line = re.sub('%.*', '', line)
if not line:
continue
# throw away leading white-space
line = line.lstrip()
# we found a label!
m = re.search(r'\\label{(%s.*?)}' % prefix, line)
if m:
# add the current line (except the \label command) to the text
# which will be displayed below this label
prev_txt += re.search(r'(^.*?)\\label{', line).group(1)
# for the figure environment however, just display the caption.
# instead of everything since the \begin command.
if prev_env == 'figure':
cm = re.search(r'\caption(\[.*?\]\s*)?{(.*?)}', prev_txt)
if cm:
prev_txt = cm.group(2)
# print a nice formatted text entry like so
#
# > eqn:label
# : e^{i\pi} + 1 = 0
#
# Use the current "section depth" for the leading indentation.
print '>%s%s\t\t<%s>' % (' '*(2*pres_depth+6),
m.group(1), fname)
print ':%s%s' % (' '*(2*pres_depth+8), prev_txt)
prev_txt = ''
# We found a TOC command, i.e one of \chapter, \section etc.
# We need to increase the numbering for the level which we just
# encoutered and reset all the nested levels to zero. Thus if we
# encounter a \section, the section number increments and the
# subsection numbers etc reset to 0.
ntot = len(outline_cmds)
sec_txt = ''
for i in range(ntot):
m = re.search(r'\\' + outline_cmds[i] + '{(.*?)}', line)
if m:
outline_nums[outline_cmds[i]] += 1
for j in range(i+1, ntot):
outline_nums[outline_cmds[j]] = 0
# At the same time we form a string like
#
# 3.2.4 The section name
#
sec_txt = ''
for k in range(0, i+1):
sec_txt += '%d.' % outline_nums[outline_cmds[k]]
sec_txt += (' ' + m.group(1))
pres_depth = i
print '%s%s\t<<<%d' % (' '*2*pres_depth, sec_txt, pres_depth+1)
break
# If we just encoutered the start or end of an environment or a
# label, then do not remember this line.
# NOTE: This assumes that there is no equation text on the same
# line as the \begin or \end command. The text on the same line as
# the \label was already handled.
if re.search(r'\\begin{(equation|eqnarray|align|figure)', line):
prev_txt = ''
prev_env = re.search(r'\\begin{(.*?)}', line).group(1)
inside_env = 1
elif re.search(r'\\label', line):
prev_txt = ''
elif re.search(r'\\end{(equation|eqnarray|align|figure)', line):
inside_env = 0
prev_env = ''
else:
# If we are inside an environment, then the text displayed with
# the label is the complete text within the environment,
# otherwise its just the previous line.
if inside_env:
prev_txt += line
else:
prev_txt = line
# }}}
if __name__ == "__main__":
fname = sys.argv[1]
if len(sys.argv) > 2:
prefix = sys.argv[2]
else:
prefix = ''
[head, tail] = os.path.split(fname)
if head:
os.chdir(head)
[root, ext] = os.path.splitext(tail)
contents = getFileContents(root, ext)
createOutline(contents, prefix)
# vim: fdm=marker
Index: main.vim
===================================================================
RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite/main.vim,v
retrieving revision 1.86
retrieving revision 1.87
diff -C2 -d -r1.86 -r1.87
*** main.vim 22 Dec 2005 21:32:38 -0000 1.86
--- main.vim 28 Dec 2005 01:17:12 -0000 1.87
***************
*** 636,640 ****
" keep that as a stable point.
function! Tex_Version()
! return "Latex-Suite: version 1.7.01"
endfunction
--- 636,640 ----
" keep that as a stable point.
function! Tex_Version()
! return "Latex-Suite: version 1.8.01"
endfunction
Index: texviewer.vim
===================================================================
RCS file: /cvsroot/vim-latex/vimfiles/ftplugin/latex-suite/texviewer.vim,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** texviewer.vim 22 Dec 2005 21:27:20 -0000 1.11
--- texviewer.vim 28 Dec 2005 01:17:13 -0000 1.12
***************
*** 8,12 ****
" CVS: $Id$
" ============================================================================
-
" Tex_SetTexViewerMaps: sets maps for this ftplugin {{{
function! Tex_SetTexViewerMaps()
--- 8,11 ----
***************
*** 54,57 ****
--- 53,60 ----
unlet! s:typeoption
+ if Tex_GetVarValue('Tex_WriteBeforeCompletion') == 1
+ wall
+ endif
+
if a:where == "text"
" What to do after <F9> depending on context
***************
*** 75,93 ****
if exists("s:type") && s:type =~ 'ref'
! if Tex_GetVarValue('Tex_UseSimpleLabelSearch') == 1
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')
elseif Tex_GetVarValue('Tex_ProjectSourceFiles') != ''
call Tex_Debug('Tex_Complete: searching for \\labels in all Tex_ProjectSourceFiles', 'view')
call Tex_CD(Tex_GetMainFileName(':p:h'))
call Tex_Grep('\\label{'.s:prefix, Tex_GetVarValue('Tex_ProjectSourceFiles'))
else
call Tex_Debug("Tex_Complete: calling Tex_GrepHelper", "view")
silent! grep! ____HIGHLY_IMPROBABLE___ %
call Tex_GrepHelper(s:prefix, 'label')
endif
redraw!
- call <SID>Tex_SetupCWindow()
elseif exists("s:type") && s:type =~ 'cite'
--- 78,105 ----
if exists("s:type") && s:type =~ 'ref'
! if Tex_GetVarValue('Tex_UseOutlineCompletion') == 1
! call Tex_Debug("Tex_Complete: using outline search method", "view")
! call Tex_StartOutlineCompletion()
!
! elseif Tex_GetVarValue('Tex_UseSimpleLabelSearch') == 1
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')
+ call <SID>Tex_SetupCWindow()
+
elseif Tex_GetVarValue('Tex_ProjectSourceFiles') != ''
call Tex_Debug('Tex_Complete: searching for \\labels in all Tex_ProjectSourceFiles', 'view')
call Tex_CD(Tex_GetMainFileName(':p:h'))
call Tex_Grep('\\label{'.s:prefix, Tex_GetVarValue('Tex_ProjectSourceFiles'))
+ call <SID>Tex_SetupCWindow()
+
else
call Tex_Debug("Tex_Complete: calling Tex_GrepHelper", "view")
silent! grep! ____HIGHLY_IMPROBABLE___ %
call Tex_GrepHelper(s:prefix, 'label')
+ call <SID>Tex_SetupCWindow()
endif
+
redraw!
elseif exists("s:type") && s:type =~ 'cite'
***************
*** 216,226 ****
" Description:
function! Tex_CompleteFileName(filename, ext)
! call Tex_Debug('getting filename = '.a:filename, 'view')
- let completeword = Tex_RelPath(a:filename, expand('%:p'))
if a:ext == 'noext'
! let completeword = fnamemodify(completeword, ':r')
endif
call Tex_CompleteWord(completeword)
endfunction " }}}
--- 228,239 ----
" Description:
function! Tex_CompleteFileName(filename, ext)
! call Tex_Debug('+Tex_CompleteFileName: getting filename '.a:filename, 'view')
if a:ext == 'noext'
! let completeword = fnamemodify(a:filename, ':r')
endif
+ let completeword = Tex_RelPath(completeword, Tex_GetMainFileName(':p:h'))
+ call Tex_Debug(":Tex_CompleteFileName: completing with ".completeword, "view")
call Tex_CompleteWord(completeword)
endfunction " }}}
***************
*** 691,698 ****
endfunction " }}}
! com! -nargs=0 TClearCiteHist unlet! s:citeSearchHistory
! " this statement has to be at the end.
! let s:doneOnce = 1
" vim:fdm=marker:nowrap:noet:ff=unix:ts=4:sw=4
--- 704,798 ----
endfunction " }}}
! " ==============================================================================
! " Functions for presenting an outlined version for completion
! " ==============================================================================
! " Tex_StartOutlineCompletion: sets up an outline window {{{
! " get the place where this plugin resides for setting cpt and dict options.
! " these lines need to be outside the function.
! let s:path = expand('<sfile>:p:h')
!
! function! Tex_StartOutlineCompletion()
! let mainfname = Tex_GetMainFileName(':p')
!
! " open the buffer
! let _report = &report
! let _cmdheight=&cmdheight
! let _lazyredraw = &lazyredraw
! set report=1000
! set cmdheight=1
! set lazyredraw
!
! bot split __OUTLINE__
!
! setlocal modifiable
! setlocal noswapfile
! setlocal buftype=nowrite
! setlocal bufhidden=delete
! setlocal nowrap
! setlocal foldmethod=marker
! setlocal foldmarker=<<<,>>>
!
! " delete everything in it to the blackhole
! % d _
! " read in the output of the outline command
! exec '0r!'.s:path.'/outline.py '.mainfname.' '.s:prefix
! 0
!
! call Tex_SetupOutlineSyntax()
!
! exec 'nnoremap <buffer> <cr> '
! \ .':cd '.s:origdir.'<CR>'
! \ .':call Tex_FinishOutlineCompletion()<CR>'
! exec 'nnoremap <buffer> q '
! \ .':cd '.s:origdir.'<CR>'
! \ .':close<CR>'
!
! " once the buffer is initialized, go back to the original settings.
! setlocal nomodifiable
! setlocal nomodified
! let &report = _report
! let &cmdheight = _cmdheight
! let &lazyredraw = _lazyredraw
! endfunction " }}}
! " Tex_SetupOutlineSyntax: sets up the syntax items for the outline {{{
! " Description:
! function! Tex_SetupOutlineSyntax()
! syn match outlineFileName "<\f\+>$" contained
! syn match foldMarkers "<<<\d$" contained
! syn match firstSemiColon '^:' contained
! syn match firstAngle '^>' contained
!
! syn match sectionNames '\(\d\.\)\+ .*' contains=foldMarkers
! syn match previousLine '^:.*' contains=firstSemiColon
! syn match labelLine '^>.*' contains=firstAngle,outlineFileName
!
! hi def link outlineFileName Ignore
! hi def link foldMarkers Ignore
! hi def link firstSemiColon Ignore
! hi def link firstAngle Ignore
!
! hi def link sectionNames Type
! hi def link previousLine Special
! hi def link labelLine Comment
! endfunction " }}}
! " Tex_FinishOutlineCompletion: inserts the reference back in the text {{{
! function! Tex_FinishOutlineCompletion()
! if getline('.') !~ '^[>:]'
! return
! endif
!
! if getline('.') =~ '^>'
! let ref_complete = matchstr(getline('.'), '^>\s\+\zs\S\+\ze')
! elseif getline('.') =~ '^:'
! let ref_complete = matchstr(getline(line('.')-1), '^>\s\+\zs\S\+\ze')
! endif
!
! let ref_remaining = strpart(ref_complete, strlen(s:prefix))
! close
! call Tex_CompleteWord(ref_remaining)
! endfunction " }}}
!
! com! -nargs=0 TClearCiteHist unlet! s:citeSearchHistory
" vim:fdm=marker:nowrap:noet:ff=unix:ts=4:sw=4
|