Mercurial > vim
comparison runtime/ftplugin/tex.vim @ 799:6beb2c667935
updated for version 7.0b
author | vimboss |
---|---|
date | Fri, 24 Mar 2006 22:21:52 +0000 |
parents | 3fc0f57ecb91 |
children | 6bb1fa855dc9 |
comparison
equal
deleted
inserted
replaced
798:95dac6af3b3a | 799:6beb2c667935 |
---|---|
1 " LaTeX filetype plugin | 1 " LaTeX filetype plugin |
2 " Language: LaTeX (ft=tex) | 2 " Language: LaTeX (ft=tex) |
3 " Maintainer: Benji Fisher, Ph.D. <benji@member.AMS.org> | 3 " Maintainer: Benji Fisher, Ph.D. <benji@member.AMS.org> |
4 " Version: 1.2 | 4 " Version: 1.3 |
5 " Last Change: Tue 11 May 2004 04:49:20 PM EDT | 5 " Last Change: Wed 22 Mar 2006 09:36:32 AM EST |
6 " URL: http://www.vim.org/script.php?script_id=411 | 6 " URL: http://www.vim.org/script.php?script_id=411 |
7 | 7 |
8 " Only do this when not done yet for this buffer | 8 " Only do this when not done yet for this buffer. |
9 if exists("b:did_ftplugin") | 9 if exists("b:did_ftplugin") |
10 finish | 10 finish |
11 endif | 11 endif |
12 | 12 |
13 " Don't load another plugin for this buffer | 13 " Start with plain TeX. This will also define b:did_ftplugin . |
14 let b:did_ftplugin = 1 | 14 source $VIMRUNTIME/ftplugin/plaintex.vim |
15 | 15 |
16 " Avoid problems if running in 'compatible' mode. | |
16 let s:save_cpo = &cpo | 17 let s:save_cpo = &cpo |
17 set cpo&vim | 18 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 | 19 |
78 " Allow "[d" to be used to find a macro definition: | 20 " Allow "[d" to be used to find a macro definition: |
79 " Recognize plain TeX \def as well as LaTeX \newcommand and \renewcommand . | 21 " Recognize plain TeX \def as well as LaTeX \newcommand and \renewcommand . |
80 " I may as well add the AMS-LaTeX DeclareMathOperator as well. | 22 " I may as well add the AMS-LaTeX DeclareMathOperator as well. |
81 let &l:define='\\\([egx]\|char\|mathchar\|count\|dimen\|muskip\|skip\|toks\)\=' | 23 let &l:define .= '\|\\\(re\)\=new\(boolean\|command\|counter\|environment\|font' |
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*{\=' | 24 \ . '\|if\|length\|savebox\|theorem\(style\)\=\)\s*\*\=\s*{\=' |
87 \ . '\|DeclareMathOperator\s*{\=\s*' | 25 \ . '\|DeclareMathOperator\s*{\=\s*' |
88 | 26 |
89 " Tell Vim how to recognize LaTeX \include{foo} and plain \input bar : | 27 " Tell Vim how to recognize LaTeX \include{foo} and plain \input bar : |
90 setlocal include=\\\\input\\\\|\\\\include{ | 28 let &l:include .= '\|\\include{' |
91 setlocal suffixesadd=.tex | |
92 " On some file systems, "{" and "}" are inluded in 'isfname'. In case the | 29 " On some file systems, "{" and "}" are inluded in 'isfname'. In case the |
93 " TeX file has \include{fname} (LaTeX only), strip everything except "fname". | 30 " TeX file has \include{fname} (LaTeX only), strip everything except "fname". |
94 let &l:includeexpr = "substitute(v:fname, '^.\\{-}{\\|}.*', '', 'g')" | 31 let &l:includeexpr = "substitute(v:fname, '^.\\{-}{\\|}.*', '', 'g')" |
95 " fun! TexIncludeExpr() | |
96 " let fname = substitute(v:fname, '}.*', '', '') | |
97 " return fname | |
98 " endfun | |
99 | 32 |
100 " The following lines enable the macros/matchit.vim plugin for | 33 " The following lines enable the macros/matchit.vim plugin for |
101 " extended matching with the % key. | 34 " extended matching with the % key. |
102 " TODO: Customize this based on b:tex_flavor . | 35 " ftplugin/plaintex.vim already defines b:match_skip and b:match_ignorecase |
36 " and matches \(, \), \[, and \]. | |
103 if exists("loaded_matchit") | 37 if exists("loaded_matchit") |
104 let b:match_ignorecase = 0 | 38 let b:match_words .= '\\begin\s*\({\a\+\*\=}\):\\end\s*\1' |
105 \ | let b:match_skip = 'r:\\\@<!\%(\\\\\)*%' | |
106 \ | let b:match_words = '(:),\[:],{:},\\(:\\),\\\[:\\],' . | |
107 \ '\\begin\s*\({\a\+\*\=}\):\\end\s*\1' | |
108 endif " exists("loaded_matchit") | 39 endif " exists("loaded_matchit") |
109 | 40 |
110 let &cpo = s:save_cpo | 41 let &cpo = s:save_cpo |
111 | 42 |
112 " vim:sts=2:sw=2: | 43 " vim:sts=2:sw=2: |