annotate runtime/ftplugin/tex.vim @ 590:de152391f6f9

updated for version 7.0167
author vimboss
date Sun, 11 Dec 2005 21:33:32 +0000
parents 3fc0f57ecb91
children 6beb2c667935
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " LaTeX filetype plugin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: LaTeX (ft=tex)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Benji Fisher, Ph.D. <benji@member.AMS.org>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Version: 1.2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " Last Change: Tue 11 May 2004 04:49:20 PM EDT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " URL: http://www.vim.org/script.php?script_id=411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " Only do this when not done yet for this buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 if exists("b:did_ftplugin")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " Don't load another plugin for this buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 let b:did_ftplugin = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 let s:save_cpo = &cpo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 set cpo&vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " This may be used to set b:tex_flavor. A more complete version can be found
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 " in foo.vim (see http://www.vim.org/script.php?script_id=72).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 if !exists("*s:GetModelines")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 fun! s:GetModelines(pat, ...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Long but simple: set start line and finish line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 let EOF = line("$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 if a:0 > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let start = a:1 | let finish = a:2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 elseif a:0 == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 if a:1 > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 let finish = a:1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let start = EOF + a:1 + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 if !exists("start") || start < 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let start = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 if !exists("finish") || finish > EOF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let finish = EOF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let n = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 silent! execute start .",". finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 \ 'g/' . escape(a:pat, "/") . "/let n=line('.')"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if n
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 execute "normal!\<C-O>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 return n . ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif " !exists("*GetModelines")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " Define the buffer-local variable b:tex_flavor to "tex" (for plain) or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " "latex".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " 1. Check the first line of the file for "%&<format>".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " 2. Check the first 1000 lines for "\begin{document}".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 " 3. Check for a global variable g:tex_flavor, can be set in user's vimrc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " 4. Default to "latex".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " 5. Strip "pdf" and change "plain" to "tex".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 if getline(1) =~ '^%&\s*\k\+'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 let b:tex_flavor = matchstr(getline(1), '%&\s*\zs\k\+')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 elseif s:GetModelines('\\begin\s*{\s*document\s*}', 1000) != "0:"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 let b:tex_flavor = "latex"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 elseif exists("g:tex_flavor")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 let b:tex_flavor = g:tex_flavor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let b:tex_flavor = "latex"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let b:tex_flavor = substitute(b:tex_flavor, 'pdf', '', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 if b:tex_flavor == "plain"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 let b:tex_flavor = "tex"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 " Set 'comments' to format dashed lists in comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 setlocal com=sO:%\ -,mO:%\ \ ,eO:%%,:%
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " Set 'commentstring' to recognize the % comment character:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 " (Thanks to Ajit Thakkar.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 setlocal cms=%%s
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 " Allow "[d" to be used to find a macro definition:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " Recognize plain TeX \def as well as LaTeX \newcommand and \renewcommand .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 " I may as well add the AMS-LaTeX DeclareMathOperator as well.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 let &l:define='\\\([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 \ . 'def\|\\font\|\\\(future\)\=let'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 \ . '\|\\new\(count\|dimen\|skip\|muskip\|box\|toks\|read\|write'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 \ . '\|fam\|insert\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 \ . '\|\\\(re\)\=new\(boolean\|command\|counter\|environment\|font'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 \ . '\|if\|length\|savebox\|theorem\(style\)\=\)\s*\*\=\s*{\='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 \ . '\|DeclareMathOperator\s*{\=\s*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 " Tell Vim how to recognize LaTeX \include{foo} and plain \input bar :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 setlocal include=\\\\input\\\\|\\\\include{
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 setlocal suffixesadd=.tex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 " On some file systems, "{" and "}" are inluded in 'isfname'. In case the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 " TeX file has \include{fname} (LaTeX only), strip everything except "fname".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 let &l:includeexpr = "substitute(v:fname, '^.\\{-}{\\|}.*', '', 'g')"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 " fun! TexIncludeExpr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " let fname = substitute(v:fname, '}.*', '', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 " return fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 " endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 " The following lines enable the macros/matchit.vim plugin for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 " extended matching with the % key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 " TODO: Customize this based on b:tex_flavor .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 if exists("loaded_matchit")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 let b:match_ignorecase = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 \ | let b:match_skip = 'r:\\\@<!\%(\\\\\)*%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 \ | let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 \ '\\begin\s*\({\a\+\*\=}\):\\end\s*\1'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 endif " exists("loaded_matchit")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 let &cpo = s:save_cpo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 " vim:sts=2:sw=2: