annotate runtime/indent/tex.vim @ 3224:8b8ef1fed009

Update runtime files.
author Bram Moolenaar <bram@vim.org>
date Wed, 14 Dec 2011 21:17:39 +0100
parents
children 91e53bcb7946
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
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Maintainer: Zhou YiChao <broken.zhou@gmail.com>
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 " Created: Sat, 16 Feb 2002 16:50:19 +0100
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 " Last Change: Tue, 25 Sep 2011
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 " Last Update: 25th Sep 2002, by LH :
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 " (*) better support for the option
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 " (*) use some regex instead of several '||'.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 " Oct 9th, 2003, by JT:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 " (*) don't change indentation of lines starting with '%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 " 2005/06/15, Moshe Kaminsky <kaminsky@math.huji.ac.il>
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 " (*) New variables:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 " g:tex_items, g:tex_itemize_env, g:tex_noindent_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 " 2011/3/6, by Zhou YiChao <broken.zhou@gmail.com>
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 " (*) Don't change indentation of lines starting with '%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 " 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
17 " so I add some code.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 " (*) New features: Add smartindent-like indent for "{}" and "[]".
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 " (*) New variables: g:tex_indent_brace
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 " 2011/9/25, by Zhou Yichao <broken.zhou@gmail.com>
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 " (*) Bug fix: smartindent-like indent for "[]"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 " (*) New features: Align with "&".
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 " (*) New variable: g:tex_indent_and
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 " 2011/10/23 by Zhou Yichao <broken.zhou@gmail.com>
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 " (*) Bug fix: improve the smartindent-like indent for "{}" and
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 " "[]".
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 " Version: 0.62
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 " Options: {{{
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 " 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
33 " let g:tex_indent_items = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 " to your ~/.vimrc.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 " * g:tex_indent_brace
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 " 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
39 " for "{}" and "[]"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 " * g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 " If this variable is set, item-environments are indented like Emacs does
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 " it, i.e., continuation lines are indented with a shiftwidth.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 " NOTE: I've already set the variable below; delete the corresponding line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 " if you don't like this behaviour.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 " Per default, it is unset.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 " set unset
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 " ----------------------------------------------------------------
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 " \begin{itemize} \begin{itemize}
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 " \item blablabla \item blablabla
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 " bla bla bla bla bla bla
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 " \item blablabla \item blablabla
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 " bla bla bla bla bla bla
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 " \end{itemize} \end{itemize}
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 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 " * g:tex_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 " A list of tokens to be considered as commands for the beginning of an item
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 " command. The tokens should be separated with '\|'. The initial '\' should
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 " be escaped. The default is '\\bibitem\|\\item'.
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 " * g:tex_itemize_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 " A list of environment names, separated with '\|', where the items (item
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 " commands matching g:tex_items) may appear. The default is
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 " 'itemize\|description\|enumerate\|thebibliography'.
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 " * g:tex_noindent_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 " A list of environment names. separated with '\|', where no indentation is
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 " required. The default is 'document\|verbatim'.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 " * g:tex_indent_and
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 "
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 " 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
81 " "&". This is pretty useful when you use environment like table or align.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 " 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
83 " a little slow.
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 " }}}
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 if exists("b:did_indent")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 finish
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 let b:did_indent = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 " Delete the next line to avoid the special indention of items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 if !exists("g:tex_indent_items")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 let g:tex_indent_items = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 if !exists("g:tex_indent_brace")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 let g:tex_indent_brace = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 if !exists("g:tex_indent_and")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 let g:tex_indent_and = 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 if !exists("g:tex_itemize_env")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 if !exists('g:tex_items')
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 let g:tex_items = '\\bibitem\|\\item'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 else
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 let g:tex_items = ''
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 if !exists("g:tex_noindent_env")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 let g:tex_noindent_env = 'document\|verbatim\|lstlisting'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 setlocal autoindent
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 setlocal nosmartindent
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 setlocal indentexpr=GetTeXIndent()
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 exec 'setlocal indentkeys+=},],\&' . substitute(g:tex_items, '^\|\(\\|\)', ',=', 'g')
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 let g:tex_items = '^\s*' . g:tex_items
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
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 " Only define the function once
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 if exists("*GetTeXIndent") | finish
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 function GetTeXIndent()
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 " Find a non-blank line above the current line.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 let lnum = prevnonblank(v:lnum - 1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 " Comment line is not what we need.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 while lnum != 0 && getline(lnum) =~ '^\s*%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 let lnum = prevnonblank(lnum - 1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 endwhile
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 " At the start of the file use zero indent.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 if lnum == 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 return 0
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
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 let line = getline(lnum) " last line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 let cline = getline(v:lnum) " current line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 " You want to align with "&"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 if g:tex_indent_and
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 " Align with last line if last line has a "&"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 if stridx(cline, "&") != -1 && stridx(line, "&") != -1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 return indent(v:lnum) + stridx(line, "&") - stridx(cline, "&")
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 " set line & lnum to the line which doesn't contain "&"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 while lnum != 0 && (stridx(line, "&") != -1 || line =~ '^\s*%')
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 let lnum = prevnonblank(lnum - 1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 let line = getline(lnum)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 endwhile
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 if lnum == 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 return 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 let ind = indent(lnum)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 " New code for comment: retain the indent of current line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 if cline =~ '^\s*%'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 return indent(v:lnum)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 " Add a 'shiftwidth' after beginning of environments.
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 " Don't add it for \begin{document} and \begin{verbatim}
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 ""if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 " LH modification : \begin does not always start a line
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 " ZYC modification : \end after \begin won't cause wrong indent anymore
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 if line =~ '\\begin{.*}' && line !~ g:tex_noindent_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 \ && line !~ '\\begin{.\{-}}.*\\end{.*}'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 let ind = ind + &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 " Add another sw for item-environments
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 if line =~ g:tex_itemize_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 let ind = ind + &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 " Subtract a 'shiftwidth' when an environment ends
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 if cline =~ '^\s*\\end' && cline !~ g:tex_noindent_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 " Remove another sw for item-environments
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 if cline =~ g:tex_itemize_env
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 let ind = ind - &sw
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 endif
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 let ind = ind - &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 if g:tex_indent_brace
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 " Add a 'shiftwidth' after a "{" or "[".
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 let sum1 = 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 for i in range(0, strlen(line)-1)
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 if line[i] == "}" || line[i] == "]"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 let sum1 = max([0, sum1-1])
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 if line[i] == "{" || line[i] == "["
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 let sum1 += 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 endfor
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216 let sum2 = 0
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 for i in reverse(range(0, strlen(cline)-1))
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 if cline[i] == "{" || cline[i] == "["
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 let sum2 = max([0, sum2-1])
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 if cline[i] == "}" || cline[i] == "]"
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 let sum2 += 1
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 endfor
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 let ind += (sum1 - sum2) * &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 " Special treatment for 'item'
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 " ----------------------------
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 if g:tex_indent_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 " '\item' or '\bibitem' itself:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236 if cline =~ g:tex_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237 let ind = ind - &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 " lines following to '\item' are intented once again:
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 if line =~ g:tex_items
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 let ind = ind + &sw
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245 endif
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 return ind
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
248 endfunction
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 " vim: set sw=4 textwidth=80: