7
|
1 " 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
|
|
9 if exists("b:did_ftplugin")
|
|
10 finish
|
|
11 endif
|
|
12
|
|
13 " Don't load another plugin for this buffer
|
|
14 let b:did_ftplugin = 1
|
|
15
|
|
16 let s:save_cpo = &cpo
|
|
17 set 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).
|
|
21 if !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
|
|
48 endif " !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".
|
|
57 if getline(1) =~ '^%&\s*\k\+'
|
|
58 let b:tex_flavor = matchstr(getline(1), '%&\s*\zs\k\+')
|
|
59 elseif s:GetModelines('\\begin\s*{\s*document\s*}', 1000) != "0:"
|
|
60 let b:tex_flavor = "latex"
|
|
61 elseif exists("g:tex_flavor")
|
|
62 let b:tex_flavor = g:tex_flavor
|
|
63 else
|
|
64 let b:tex_flavor = "latex"
|
|
65 endif
|
|
66 let b:tex_flavor = substitute(b:tex_flavor, 'pdf', '', '')
|
|
67 if b:tex_flavor == "plain"
|
|
68 let b:tex_flavor = "tex"
|
|
69 endif
|
|
70
|
|
71 " Set 'comments' to format dashed lists in comments
|
|
72 setlocal com=sO:%\ -,mO:%\ \ ,eO:%%,:%
|
|
73
|
|
74 " Set 'commentstring' to recognize the % comment character:
|
|
75 " (Thanks to Ajit Thakkar.)
|
|
76 setlocal 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.
|
|
81 let &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 :
|
|
90 setlocal include=\\\\input\\\\|\\\\include{
|
|
91 setlocal 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".
|
|
94 let &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 .
|
|
103 if 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'
|
|
108 endif " exists("loaded_matchit")
|
|
109
|
|
110 let &cpo = s:save_cpo
|
|
111
|
|
112 " vim:sts=2:sw=2:
|