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