annotate runtime/indent/tex.vim @ 4437:eb6ab7e78925

Update runtime files.
author Bram Moolenaar <bram@vim.org>
date Fri, 17 May 2013 18:14:19 +0200
parents 2cfb68fa26cd
children 1bf1b88968a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: LaTeX
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
3 " Maintainer: YiChao Zhou <broken.zhou AT gmail.com>
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 " Created: Sat, 16 Feb 2002 16:50:19 +0100
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
5 " Last Change: 2012 Mar 18 19:19:50
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
6 " Version: 0.7
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
7 " Please email me if you found something we can do. Bug report and
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
8 " feature request is welcome.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
9
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
10 " Last Update: {{{
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
11 " 25th Sep 2002, by LH :
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 " (*) better support for the option
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 " (*) use some regex instead of several '||'.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 " Oct 9th, 2003, by JT:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 " (*) don't change indentation of lines starting with '%'
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
16 " 2005/06/15, Moshe Kaminsky <kaminsky AT math.huji.ac.il>
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 " (*) New variables:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 " g:tex_items, g:tex_itemize_env, g:tex_noindent_env
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
19 " 2011/3/6, by Zhou YiChao <broken.zhou AT gmail.com>
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 " (*) Don't change indentation of lines starting with '%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 " I don't see any code with '%' and it doesn't work properly
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 " so I add some code.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 " (*) New features: Add smartindent-like indent for "{}" and "[]".
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 " (*) New variables: g:tex_indent_brace
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
25 " 2011/9/25, by Zhou Yichao <broken.zhou AT gmail.com>
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 " (*) Bug fix: smartindent-like indent for "[]"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 " (*) New features: Align with "&".
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
28 " (*) New variable: g:tex_indent_and.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
29 " 2011/10/23 by Zhou Yichao <broken.zhou AT gmail.com>
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 " (*) Bug fix: improve the smartindent-like indent for "{}" and
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 " "[]".
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
32 " 2012/02/27 by Zhou Yichao <broken.zhou AT gmail.com>
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
33 " (*) Bug fix: support default folding marker.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
34 " (*) Indent with "&" is not very handy. Make it not enable by
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
35 " default.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
36 " 2012/03/06 by Zhou Yichao <broken.zhou AT gmail.com>
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
37 " (*) Modify "&" behavior and make it default again. Now "&"
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
38 " won't align when there are more then one "&" in the previous
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
39 " line.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
40 " (*) Add indent "\left(" and "\right)"
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
41 " (*) Trust user when in "verbatim" and "lstlisting"
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
42 " 2012/03/11 by Zhou Yichao <broken.zhou AT gmail.com>
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
43 " (*) Modify "&" so that only indent when current line start with
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
44 " "&".
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
45 " 2012/03/12 by Zhou Yichao <broken.zhou AT gmail.com>
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
46 " (*) Modify indentkeys.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
47 " 2012/03/18 by Zhou Yichao <broken.zhou AT gmail.com>
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
48 " (*) Add &cpo
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
49 " 2013/05/02 by Zhou Yichao <broken.zhou AT gmail.com>
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
50 " (*) Fix problem about GetTeXIndent checker. Thank Albert Netymk
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
51 " for reporting this.
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
52 " }}}
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
54 " Document: {{{
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 " To set the following options (ok, currently it's just one), add a line like
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 " let g:tex_indent_items = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 " to your ~/.vimrc.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 " * g:tex_indent_brace
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 " If this variable is unset or non-zero, it will use smartindent-like style
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 " for "{}" and "[]"
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
64 "
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 " * g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 " If this variable is set, item-environments are indented like Emacs does
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 " it, i.e., continuation lines are indented with a shiftwidth.
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
69 "
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 " NOTE: I've already set the variable below; delete the corresponding line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 " if you don't like this behaviour.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 " Per default, it is unset.
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
74 "
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 " set unset
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 " ----------------------------------------------------------------
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
77 " \begin{itemize} \begin{itemize}
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 " \item blablabla \item blablabla
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
79 " bla bla bla bla bla bla
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 " \item blablabla \item blablabla
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
81 " bla bla bla bla bla bla
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
82 " \end{itemize} \end{itemize}
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 " * g:tex_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 "
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
87 " A list of tokens to be considered as commands for the beginning of an item
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
88 " command. The tokens should be separated with '\|'. The initial '\' should
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 " be escaped. The default is '\\bibitem\|\\item'.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 " * g:tex_itemize_env
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
92 "
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
93 " A list of environment names, separated with '\|', where the items (item
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
94 " commands matching g:tex_items) may appear. The default is
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 " 'itemize\|description\|enumerate\|thebibliography'.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 " * g:tex_noindent_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 "
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
99 " A list of environment names. separated with '\|', where no indentation is
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 " required. The default is 'document\|verbatim'.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 " * g:tex_indent_and
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 " If this variable is unset or zero, vim will try to align the line with first
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 " "&". This is pretty useful when you use environment like table or align.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 " Note that this feature need to search back some line, so vim may become
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 " a little slow.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 "
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
109 " }}}
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
110
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
111 " Only define the function once
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 if exists("b:did_indent")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 finish
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 endif
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
115
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
116 let s:cpo_save = &cpo
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
117 set cpo&vim
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
118
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
119 " Define global variable {{{
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
120
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 let b:did_indent = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 if !exists("g:tex_indent_items")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 let g:tex_indent_items = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 if !exists("g:tex_indent_brace")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 let g:tex_indent_brace = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 if !exists("g:tex_indent_and")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 let g:tex_indent_and = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 if !exists("g:tex_itemize_env")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 if !exists('g:tex_items')
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
137 let g:tex_items = '\\bibitem\|\\item'
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 else
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 let g:tex_items = ''
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
143 if !exists("g:tex_indent_paretheses")
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
144 let g:tex_indent_paretheses = 1
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
145 endif
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
146
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 if !exists("g:tex_noindent_env")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 let g:tex_noindent_env = 'document\|verbatim\|lstlisting'
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
149 endif "}}}
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
151 " VIM Setting " {{{
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 setlocal autoindent
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 setlocal nosmartindent
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 setlocal indentexpr=GetTeXIndent()
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
155 setlocal indentkeys&
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
156 exec 'setlocal indentkeys+=[,(,{,),},],\&' . substitute(g:tex_items, '^\|\(\\|\)', ',=', 'g')
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
157 let g:tex_items = '^\s*' . substitute(g:tex_items, '^\(\^\\s\*\)*', '', '')
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
158 " }}}
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
160 function! GetTeXIndent() " {{{
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 " Find a non-blank line above the current line.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 let lnum = prevnonblank(v:lnum - 1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 " Comment line is not what we need.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 while lnum != 0 && getline(lnum) =~ '^\s*%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 let lnum = prevnonblank(lnum - 1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 endwhile
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 " At the start of the file use zero indent.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 if lnum == 0
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
171 return 0
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
174 let line = substitute(getline(lnum), '%.*', ' ','g') " last line
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
175 let cline = substitute(getline(v:lnum), '%.*', ' ', 'g') " current line
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
177 " We are in verbatim, so do what our user what.
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
178 if synIDattr(synID(v:lnum, indent(v:lnum), 1), "name") == "texZone"
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
179 if empty(cline)
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
180 return indent(lnum)
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
181 else
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
182 return indent(v:lnum)
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
183 end
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
184 endif
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
185
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 " You want to align with "&"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 if g:tex_indent_and
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
188 " Align only when current line start with "&"
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
189 if line =~ '&.*\\\\' && cline =~ '^\s*&'
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 return indent(v:lnum) + stridx(line, "&") - stridx(cline, "&")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 " set line & lnum to the line which doesn't contain "&"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 while lnum != 0 && (stridx(line, "&") != -1 || line =~ '^\s*%')
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 let lnum = prevnonblank(lnum - 1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 let line = getline(lnum)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 endwhile
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 if lnum == 0
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
202 return 0
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 let ind = indent(lnum)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 " New code for comment: retain the indent of current line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 if cline =~ '^\s*%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 return indent(v:lnum)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 " Add a 'shiftwidth' after beginning of environments.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 " Don't add it for \begin{document} and \begin{verbatim}
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
214 ""if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 " LH modification : \begin does not always start a line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216 " ZYC modification : \end after \begin won't cause wrong indent anymore
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 if line =~ '\\begin{.*}' && line !~ g:tex_noindent_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 let ind = ind + &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 " Add another sw for item-environments
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 if line =~ g:tex_itemize_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 let ind = ind + &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 " Subtract a 'shiftwidth' when an environment ends
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
229 if cline =~ '\\end{.*}' && cline !~ g:tex_noindent_env
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 " Remove another sw for item-environments
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 if cline =~ g:tex_itemize_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 let ind = ind - &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238 let ind = ind - &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 if g:tex_indent_brace
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 let sum1 = 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 for i in range(0, strlen(line)-1)
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
244 if line[i] == "}" || line[i] == "]" ||
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
245 \ strpart(line, i, 7) == '\right)'
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246 let sum1 = max([0, sum1-1])
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 endif
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
248 if line[i] == "{" || line[i] == "[" ||
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
249 \ strpart(line, i, 6) == '\left('
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 let sum1 += 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 endfor
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 let sum2 = 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 for i in reverse(range(0, strlen(cline)-1))
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
256 if cline[i] == "{" || cline[i] == "[" ||
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
257 \ strpart(cline, i, 6) == '\left('
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 let sum2 = max([0, sum2-1])
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 endif
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
260 if cline[i] == "}" || cline[i] == "]" ||
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
261 \ strpart(cline, i, 7) == '\right)'
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 let sum2 += 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 endfor
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
266 let ind += (sum1 - sum2) * &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
269 if g:tex_indent_paretheses
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
270 endif
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 " Special treatment for 'item'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 " ----------------------------
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 " '\item' or '\bibitem' itself:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 if cline =~ g:tex_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 let ind = ind - &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 " lines following to '\item' are intented once again:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 if line =~ g:tex_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 let ind = ind + &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 return ind
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
290 endfunction "}}}
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
292 let &cpo = s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
293 unlet s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
294
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 " vim: set sw=4 textwidth=80: