Mercurial > vim
annotate runtime/indent/tex.vim @ 35171:76c328389c46 default tip
Added tag v9.1.0411 for changeset ed3a90cecb19f1d38b0a9bbb9bf6ed60bace72f4
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 12 May 2024 09:30:05 +0200 |
parents | 5c220cf30f1f |
children |
rev | line source |
---|---|
13937 | 1 " Vim indent file |
2 " Language: LaTeX | |
3 " Maintainer: Yichao Zhou <broken.zhou AT gmail.com> | |
4 " Created: Sat, 16 Feb 2002 16:50:19 +0100 | |
5 " Version: 1.0.0 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
6 " Please email me if you found something I can do. Comments, bug report and |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
7 " feature request are welcome. |
3445 | 8 |
13937 | 9 " Last Update: {{{ |
3445 | 10 " 25th Sep 2002, by LH : |
3224 | 11 " (*) better support for the option |
12 " (*) use some regex instead of several '||'. | |
13 " Oct 9th, 2003, by JT: | |
14 " (*) don't change indentation of lines starting with '%' | |
3445 | 15 " 2005/06/15, Moshe Kaminsky <kaminsky AT math.huji.ac.il> |
3224 | 16 " (*) New variables: |
17 " g:tex_items, g:tex_itemize_env, g:tex_noindent_env | |
13937 | 18 " 2011/3/6, by Yichao Zhou <broken.zhou AT gmail.com> |
3224 | 19 " (*) Don't change indentation of lines starting with '%' |
20 " I don't see any code with '%' and it doesn't work properly | |
21 " so I add some code. | |
22 " (*) New features: Add smartindent-like indent for "{}" and "[]". | |
23 " (*) New variables: g:tex_indent_brace | |
13937 | 24 " 2011/9/25, by Yichao Zhou <broken.zhou AT gmail.com> |
3224 | 25 " (*) Bug fix: smartindent-like indent for "[]" |
26 " (*) New features: Align with "&". | |
3445 | 27 " (*) New variable: g:tex_indent_and. |
13937 | 28 " 2011/10/23 by Yichao Zhou <broken.zhou AT gmail.com> |
3224 | 29 " (*) Bug fix: improve the smartindent-like indent for "{}" and |
30 " "[]". | |
13937 | 31 " 2012/02/27 by Yichao Zhou <broken.zhou AT gmail.com> |
3445 | 32 " (*) Bug fix: support default folding marker. |
33 " (*) Indent with "&" is not very handy. Make it not enable by | |
34 " default. | |
13937 | 35 " 2012/03/06 by Yichao Zhou <broken.zhou AT gmail.com> |
3445 | 36 " (*) Modify "&" behavior and make it default again. Now "&" |
37 " won't align when there are more then one "&" in the previous | |
38 " line. | |
39 " (*) Add indent "\left(" and "\right)" | |
40 " (*) Trust user when in "verbatim" and "lstlisting" | |
13937 | 41 " 2012/03/11 by Yichao Zhou <broken.zhou AT gmail.com> |
3445 | 42 " (*) Modify "&" so that only indent when current line start with |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
43 " "&". |
13937 | 44 " 2012/03/12 by Yichao Zhou <broken.zhou AT gmail.com> |
3445 | 45 " (*) Modify indentkeys. |
13937 | 46 " 2012/03/18 by Yichao Zhou <broken.zhou AT gmail.com> |
3445 | 47 " (*) Add &cpo |
13937 | 48 " 2013/05/02 by Yichao Zhou <broken.zhou AT gmail.com> |
4437 | 49 " (*) Fix problem about GetTeXIndent checker. Thank Albert Netymk |
50 " for reporting this. | |
13937 | 51 " 2014/06/23 by Yichao Zhou <broken.zhou AT gmail.com> |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
52 " (*) Remove the feature g:tex_indent_and because it is buggy. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
53 " (*) If there is not any obvious indentation hints, we do not |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
54 " alert our user's current indentation. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
55 " (*) g:tex_indent_brace now only works if the open brace is the |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
56 " last character of that line. |
13937 | 57 " 2014/08/03 by Yichao Zhou <broken.zhou AT gmail.com> |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
58 " (*) Indent current line if last line has larger indentation |
13937 | 59 " 2016/11/08 by Yichao Zhou <broken.zhou AT gmail.com> |
60 " (*) Fix problems for \[ and \]. Thanks Bruno for reporting. | |
61 " 2017/04/30 by Yichao Zhou <broken.zhou AT gmail.com> | |
62 " (*) Fix a bug between g:tex_noindent_env and g:tex_indent_items | |
63 " Now g:tex_noindent_env='document\|verbatim\|itemize' (Emacs | |
64 " style) is supported. Thanks Miles Wheeler for reporting. | |
65 " 2018/02/07 by Yichao Zhou <broken.zhou AT gmail.com> | |
66 " (*) Make indentation more smart in the normal mode | |
20552 | 67 " 2020/04/26 by Yichao Zhou <broken.zhou AT gmail.com> |
68 " (*) Fix a bug related to \[ & \]. Thanks Manuel Boni for | |
69 " reporting. | |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
25773
diff
changeset
|
70 " 2023/08/28 by Vim Project |
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
25773
diff
changeset
|
71 " (*) Set b:undo_indent. |
3445 | 72 " }}} |
13937 | 73 |
74 " Document: {{{ | |
75 " | |
20552 | 76 " For proper latex experience, please put |
77 " let g:tex_flavor = "latex" | |
78 " into your vimrc. | |
13937 | 79 " |
80 " * g:tex_indent_brace | |
81 " | |
82 " If this variable is unset or non-zero, it will use smartindent-like style | |
83 " for "{}" and "[]". Now this only works if the open brace is the last | |
84 " character of that line. | |
85 " | |
86 " % Example 1 | |
87 " \usetikzlibrary{ | |
88 " external | |
89 " } | |
90 " | |
91 " % Example 2 | |
92 " \tikzexternalize[ | |
93 " prefix=tikz] | |
94 " | |
95 " * g:tex_indent_items | |
96 " | |
97 " If this variable is set, item-environments are indented like Emacs does | |
98 " it, i.e., continuation lines are indented with a shiftwidth. | |
99 " | |
100 " set unset | |
101 " ------------------------------------------------------ | |
102 " \begin{itemize} \begin{itemize} | |
103 " \item blablabla \item blablabla | |
104 " bla bla bla bla bla bla | |
105 " \item blablabla \item blablabla | |
106 " bla bla bla bla bla bla | |
107 " \end{itemize} \end{itemize} | |
108 " | |
109 " | |
110 " * g:tex_items | |
111 " | |
112 " A list of tokens to be considered as commands for the beginning of an item | |
113 " command. The tokens should be separated with '\|'. The initial '\' should | |
114 " be escaped. The default is '\\bibitem\|\\item'. | |
115 " | |
116 " * g:tex_itemize_env | |
117 " | |
118 " A list of environment names, separated with '\|', where the items (item | |
119 " commands matching g:tex_items) may appear. The default is | |
120 " 'itemize\|description\|enumerate\|thebibliography'. | |
121 " | |
122 " * g:tex_noindent_env | |
123 " | |
124 " A list of environment names. separated with '\|', where no indentation is | |
125 " required. The default is 'document\|verbatim'. | |
126 " }}} | |
127 | |
128 " Only define the function once | |
3224 | 129 if exists("b:did_indent") |
130 finish | |
131 endif | |
3445 | 132 |
133 let s:cpo_save = &cpo | |
134 set cpo&vim | |
13937 | 135 |
136 " Define global variable {{{ | |
137 | |
3224 | 138 let b:did_indent = 1 |
139 | |
140 if !exists("g:tex_indent_items") | |
141 let g:tex_indent_items = 1 | |
142 endif | |
143 if !exists("g:tex_indent_brace") | |
144 let g:tex_indent_brace = 1 | |
145 endif | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
146 if !exists("g:tex_max_scan_line") |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
147 let g:tex_max_scan_line = 60 |
3224 | 148 endif |
149 if g:tex_indent_items | |
150 if !exists("g:tex_itemize_env") | |
151 let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography' | |
152 endif | |
153 if !exists('g:tex_items') | |
13937 | 154 let g:tex_items = '\\bibitem\|\\item' |
3224 | 155 endif |
156 else | |
157 let g:tex_items = '' | |
158 endif | |
159 | |
160 if !exists("g:tex_noindent_env") | |
161 let g:tex_noindent_env = 'document\|verbatim\|lstlisting' | |
3445 | 162 endif "}}} |
13937 | 163 |
164 " VIM Setting " {{{ | |
3224 | 165 setlocal autoindent |
166 setlocal nosmartindent | |
167 setlocal indentexpr=GetTeXIndent() | |
3445 | 168 setlocal indentkeys& |
169 exec 'setlocal indentkeys+=[,(,{,),},],\&' . substitute(g:tex_items, '^\|\(\\|\)', ',=', 'g') | |
170 let g:tex_items = '^\s*' . substitute(g:tex_items, '^\(\^\\s\*\)*', '', '') | |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
25773
diff
changeset
|
171 let b:undo_indent = "setlocal autoindent< indentexpr< indentkeys< smartindent<" |
13937 | 172 " }}} |
13912 | 173 |
13937 | 174 function! GetTeXIndent() " {{{ |
3224 | 175 " Find a non-blank line above the current line. |
176 let lnum = prevnonblank(v:lnum - 1) | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
177 let cnum = v:lnum |
3224 | 178 |
179 " Comment line is not what we need. | |
180 while lnum != 0 && getline(lnum) =~ '^\s*%' | |
181 let lnum = prevnonblank(lnum - 1) | |
182 endwhile | |
183 | |
184 " At the start of the file use zero indent. | |
185 if lnum == 0 | |
13937 | 186 return 0 |
3224 | 187 endif |
188 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
189 let line = substitute(getline(lnum), '\s*%.*', '','g') " last line |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
190 let cline = substitute(getline(v:lnum), '\s*%.*', '', 'g') " current line |
3224 | 191 |
20552 | 192 let ccol = 1 |
193 while cline[ccol] =~ '\s' | |
194 let ccol += 1 | |
195 endwhile | |
196 | |
3445 | 197 " We are in verbatim, so do what our user what. |
20552 | 198 if synIDattr(synID(v:lnum, ccol, 1), "name") == "texZone" |
3445 | 199 if empty(cline) |
200 return indent(lnum) | |
201 else | |
202 return indent(v:lnum) | |
20552 | 203 endif |
3445 | 204 endif |
13937 | 205 |
3224 | 206 if lnum == 0 |
13937 | 207 return 0 |
3224 | 208 endif |
209 | |
210 let ind = indent(lnum) | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
211 let stay = 1 |
3224 | 212 |
213 " New code for comment: retain the indent of current line | |
214 if cline =~ '^\s*%' | |
215 return indent(v:lnum) | |
216 endif | |
217 | |
13937 | 218 " Add a 'shiftwidth' after beginning of environments. |
219 " Don't add it for \begin{document} and \begin{verbatim} | |
220 " if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim' | |
221 " LH modification : \begin does not always start a line | |
222 " ZYC modification : \end after \begin won't cause wrong indent anymore | |
223 if line =~ '\\begin{.*}' | |
224 if line !~ g:tex_noindent_env | |
225 let ind = ind + shiftwidth() | |
226 let stay = 0 | |
227 endif | |
3224 | 228 |
229 if g:tex_indent_items | |
230 " Add another sw for item-environments | |
231 if line =~ g:tex_itemize_env | |
11518 | 232 let ind = ind + shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
233 let stay = 0 |
3224 | 234 endif |
235 endif | |
236 endif | |
237 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
238 if cline =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
239 let retn = s:GetEndIndentation(v:lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
240 if retn != -1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
241 return retn |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
242 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
243 end |
3224 | 244 " Subtract a 'shiftwidth' when an environment ends |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
245 if cline =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
246 \ && cline !~ g:tex_noindent_env |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
247 \ && cline !~ '\\begin{.*}.*\\end{.*}' |
3224 | 248 if g:tex_indent_items |
249 " Remove another sw for item-environments | |
250 if cline =~ g:tex_itemize_env | |
11518 | 251 let ind = ind - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
252 let stay = 0 |
3224 | 253 endif |
254 endif | |
255 | |
11518 | 256 let ind = ind - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
257 let stay = 0 |
3224 | 258 endif |
259 | |
260 if g:tex_indent_brace | |
13937 | 261 if line =~ '[[{]$' |
11518 | 262 let ind += shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
263 let stay = 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
264 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
265 |
20552 | 266 if cline =~ '^\s*\\\?[\]}]' && s:CheckPairedIsLastCharacter(v:lnum, ccol) |
11518 | 267 let ind -= shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
268 let stay = 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
269 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
270 |
13937 | 271 if line !~ '^\s*\\\?[\]}]' |
20552 | 272 for i in range(1, strlen(line)-1) |
13937 | 273 let char = line[i] |
274 if char == ']' || char == '}' | |
275 if s:CheckPairedIsLastCharacter(lnum, i) | |
276 let ind -= shiftwidth() | |
277 let stay = 0 | |
278 endif | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
279 endif |
13937 | 280 endfor |
281 endif | |
3445 | 282 endif |
3224 | 283 |
284 " Special treatment for 'item' | |
285 " ---------------------------- | |
286 | |
287 if g:tex_indent_items | |
288 " '\item' or '\bibitem' itself: | |
289 if cline =~ g:tex_items | |
11518 | 290 let ind = ind - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
291 let stay = 0 |
3224 | 292 endif |
25773 | 293 " lines following to '\item' are indented once again: |
3224 | 294 if line =~ g:tex_items |
11518 | 295 let ind = ind + shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
296 let stay = 0 |
3224 | 297 endif |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
298 endif |
3224 | 299 |
13937 | 300 if stay && mode() == 'i' |
301 " If there is no obvious indentation hint, and indentation is triggered | |
302 " in insert mode, we trust our user. | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
303 if empty(cline) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
304 return ind |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
305 else |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
306 return max([indent(v:lnum), s:GetLastBeginIndentation(v:lnum)]) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
307 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
308 else |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
309 return ind |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
310 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
311 endfunction "}}} |
13937 | 312 |
313 function! s:GetLastBeginIndentation(lnum) " {{{ | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
314 let matchend = 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
315 for lnum in range(a:lnum-1, max([a:lnum - g:tex_max_scan_line, 1]), -1) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
316 let line = getline(lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
317 if line =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
318 let matchend += 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
319 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
320 if line =~ '\\begin{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
321 let matchend -= 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
322 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
323 if matchend == 0 |
13937 | 324 if line =~ g:tex_noindent_env |
325 return indent(lnum) | |
326 endif | |
13912 | 327 if line =~ g:tex_itemize_env |
328 return indent(lnum) + 2 * shiftwidth() | |
329 endif | |
11518 | 330 return indent(lnum) + shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
331 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
332 endfor |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
333 return -1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
334 endfunction |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
335 |
13937 | 336 function! s:GetEndIndentation(lnum) " {{{ |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
337 if getline(a:lnum) =~ '\\begin{.*}.*\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
338 return -1 |
3224 | 339 endif |
340 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
341 let min_indent = 100 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
342 let matchend = 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
343 for lnum in range(a:lnum-1, max([a:lnum-g:tex_max_scan_line, 1]), -1) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
344 let line = getline(lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
345 if line =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
346 let matchend += 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
347 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
348 if line =~ '\\begin{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
349 let matchend -= 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
350 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
351 if matchend == 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
352 return indent(lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
353 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
354 if !empty(line) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
355 let min_indent = min([min_indent, indent(lnum)]) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
356 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
357 endfor |
11518 | 358 return min_indent - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
359 endfunction |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
360 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
361 " Most of the code is from matchparen.vim |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
362 function! s:CheckPairedIsLastCharacter(lnum, col) "{{{ |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
363 let c_lnum = a:lnum |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
364 let c_col = a:col+1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
365 |
13937 | 366 let line = getline(c_lnum) |
367 if line[c_col-1] == '\' | |
368 let c_col = c_col + 1 | |
369 endif | |
370 let c = line[c_col-1] | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
371 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
372 let plist = split(&matchpairs, '.\zs[:,]') |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
373 let i = index(plist, c) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
374 if i < 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
375 return 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
376 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
377 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
378 " Figure out the arguments for searchpairpos(). |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
379 if i % 2 == 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
380 let s_flags = 'nW' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
381 let c2 = plist[i + 1] |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
382 else |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
383 let s_flags = 'nbW' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
384 let c2 = c |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
385 let c = plist[i - 1] |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
386 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
387 if c == '[' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
388 let c = '\[' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
389 let c2 = '\]' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
390 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
391 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
392 " Find the match. When it was just before the cursor move it there for a |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
393 " moment. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
394 let save_cursor = winsaveview() |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
395 call cursor(c_lnum, c_col) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
396 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
397 " When not in a string or comment ignore matches inside them. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
398 " We match "escape" for special items, such as lispEscapeSpecial. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
399 let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' . |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
400 \ '=~? "string\\|character\\|singlequote\\|escape\\|comment"' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
401 execute 'if' s_skip '| let s_skip = 0 | endif' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
402 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
403 let stopline = max([0, c_lnum - g:tex_max_scan_line]) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
404 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
405 " Limit the search time to 300 msec to avoid a hang on very long lines. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
406 " This fails when a timeout is not supported. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
407 try |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
408 let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, 100) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
409 catch /E118/ |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
410 endtry |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
411 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
412 call winrestview(save_cursor) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
413 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
414 if m_lnum > 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
415 let line = getline(m_lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
416 return strlen(line) == m_col |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
417 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
418 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
419 return 0 |
13937 | 420 endfunction "}}} |
421 | |
3237 | 422 let &cpo = s:cpo_save |
423 unlet s:cpo_save | |
424 | |
3224 | 425 " vim: set sw=4 textwidth=80: |