Mercurial > vim
annotate runtime/indent/tex.vim @ 21044:dc2ca403a217 v8.2.1073
patch 8.2.1073: Vim9: no line break allowed in () expression
Commit: https://github.com/vim/vim/commit/7a4981b93642b5b62018cd8150b3fb0dfa2417d4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 27 20:46:29 2020 +0200
patch 8.2.1073: Vim9: no line break allowed in () expression
Problem: Vim9: no line break allowed in () expression.
Solution: Skip a line break.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Jun 2020 21:00:03 +0200 |
parents | 74e3316c1d5a |
children | 11b656e74444 |
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. | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
70 " |
3445 | 71 " }}} |
13937 | 72 |
73 " Document: {{{ | |
74 " | |
20552 | 75 " For proper latex experience, please put |
76 " let g:tex_flavor = "latex" | |
77 " into your vimrc. | |
13937 | 78 " |
79 " * g:tex_indent_brace | |
80 " | |
81 " If this variable is unset or non-zero, it will use smartindent-like style | |
82 " for "{}" and "[]". Now this only works if the open brace is the last | |
83 " character of that line. | |
84 " | |
85 " % Example 1 | |
86 " \usetikzlibrary{ | |
87 " external | |
88 " } | |
89 " | |
90 " % Example 2 | |
91 " \tikzexternalize[ | |
92 " prefix=tikz] | |
93 " | |
94 " * g:tex_indent_items | |
95 " | |
96 " If this variable is set, item-environments are indented like Emacs does | |
97 " it, i.e., continuation lines are indented with a shiftwidth. | |
98 " | |
99 " set unset | |
100 " ------------------------------------------------------ | |
101 " \begin{itemize} \begin{itemize} | |
102 " \item blablabla \item blablabla | |
103 " bla bla bla bla bla bla | |
104 " \item blablabla \item blablabla | |
105 " bla bla bla bla bla bla | |
106 " \end{itemize} \end{itemize} | |
107 " | |
108 " | |
109 " * g:tex_items | |
110 " | |
111 " A list of tokens to be considered as commands for the beginning of an item | |
112 " command. The tokens should be separated with '\|'. The initial '\' should | |
113 " be escaped. The default is '\\bibitem\|\\item'. | |
114 " | |
115 " * g:tex_itemize_env | |
116 " | |
117 " A list of environment names, separated with '\|', where the items (item | |
118 " commands matching g:tex_items) may appear. The default is | |
119 " 'itemize\|description\|enumerate\|thebibliography'. | |
120 " | |
121 " * g:tex_noindent_env | |
122 " | |
123 " A list of environment names. separated with '\|', where no indentation is | |
124 " required. The default is 'document\|verbatim'. | |
125 " }}} | |
126 | |
127 " Only define the function once | |
3224 | 128 if exists("b:did_indent") |
129 finish | |
130 endif | |
3445 | 131 |
132 let s:cpo_save = &cpo | |
133 set cpo&vim | |
13937 | 134 |
135 " Define global variable {{{ | |
136 | |
3224 | 137 let b:did_indent = 1 |
138 | |
139 if !exists("g:tex_indent_items") | |
140 let g:tex_indent_items = 1 | |
141 endif | |
142 if !exists("g:tex_indent_brace") | |
143 let g:tex_indent_brace = 1 | |
144 endif | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
145 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
|
146 let g:tex_max_scan_line = 60 |
3224 | 147 endif |
148 if g:tex_indent_items | |
149 if !exists("g:tex_itemize_env") | |
150 let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography' | |
151 endif | |
152 if !exists('g:tex_items') | |
13937 | 153 let g:tex_items = '\\bibitem\|\\item' |
3224 | 154 endif |
155 else | |
156 let g:tex_items = '' | |
157 endif | |
158 | |
159 if !exists("g:tex_noindent_env") | |
160 let g:tex_noindent_env = 'document\|verbatim\|lstlisting' | |
3445 | 161 endif "}}} |
13937 | 162 |
163 " VIM Setting " {{{ | |
3224 | 164 setlocal autoindent |
165 setlocal nosmartindent | |
166 setlocal indentexpr=GetTeXIndent() | |
3445 | 167 setlocal indentkeys& |
168 exec 'setlocal indentkeys+=[,(,{,),},],\&' . substitute(g:tex_items, '^\|\(\\|\)', ',=', 'g') | |
169 let g:tex_items = '^\s*' . substitute(g:tex_items, '^\(\^\\s\*\)*', '', '') | |
13937 | 170 " }}} |
13912 | 171 |
13937 | 172 function! GetTeXIndent() " {{{ |
3224 | 173 " Find a non-blank line above the current line. |
174 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
|
175 let cnum = v:lnum |
3224 | 176 |
177 " Comment line is not what we need. | |
178 while lnum != 0 && getline(lnum) =~ '^\s*%' | |
179 let lnum = prevnonblank(lnum - 1) | |
180 endwhile | |
181 | |
182 " At the start of the file use zero indent. | |
183 if lnum == 0 | |
13937 | 184 return 0 |
3224 | 185 endif |
186 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
187 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
|
188 let cline = substitute(getline(v:lnum), '\s*%.*', '', 'g') " current line |
3224 | 189 |
20552 | 190 let ccol = 1 |
191 while cline[ccol] =~ '\s' | |
192 let ccol += 1 | |
193 endwhile | |
194 | |
3445 | 195 " We are in verbatim, so do what our user what. |
20552 | 196 if synIDattr(synID(v:lnum, ccol, 1), "name") == "texZone" |
3445 | 197 if empty(cline) |
198 return indent(lnum) | |
199 else | |
200 return indent(v:lnum) | |
20552 | 201 endif |
3445 | 202 endif |
13937 | 203 |
3224 | 204 if lnum == 0 |
13937 | 205 return 0 |
3224 | 206 endif |
207 | |
208 let ind = indent(lnum) | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
209 let stay = 1 |
3224 | 210 |
211 " New code for comment: retain the indent of current line | |
212 if cline =~ '^\s*%' | |
213 return indent(v:lnum) | |
214 endif | |
215 | |
13937 | 216 " Add a 'shiftwidth' after beginning of environments. |
217 " Don't add it for \begin{document} and \begin{verbatim} | |
218 " if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim' | |
219 " LH modification : \begin does not always start a line | |
220 " ZYC modification : \end after \begin won't cause wrong indent anymore | |
221 if line =~ '\\begin{.*}' | |
222 if line !~ g:tex_noindent_env | |
223 let ind = ind + shiftwidth() | |
224 let stay = 0 | |
225 endif | |
3224 | 226 |
227 if g:tex_indent_items | |
228 " Add another sw for item-environments | |
229 if line =~ g:tex_itemize_env | |
11518 | 230 let ind = ind + shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
231 let stay = 0 |
3224 | 232 endif |
233 endif | |
234 endif | |
235 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
236 if cline =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
237 let retn = s:GetEndIndentation(v:lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
238 if retn != -1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
239 return retn |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
240 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
241 end |
3224 | 242 " 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
|
243 if cline =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
244 \ && cline !~ g:tex_noindent_env |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
245 \ && cline !~ '\\begin{.*}.*\\end{.*}' |
3224 | 246 if g:tex_indent_items |
247 " Remove another sw for item-environments | |
248 if cline =~ g:tex_itemize_env | |
11518 | 249 let ind = ind - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
250 let stay = 0 |
3224 | 251 endif |
252 endif | |
253 | |
11518 | 254 let ind = ind - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
255 let stay = 0 |
3224 | 256 endif |
257 | |
258 if g:tex_indent_brace | |
13937 | 259 if line =~ '[[{]$' |
11518 | 260 let ind += shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
261 let stay = 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
262 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
263 |
20552 | 264 if cline =~ '^\s*\\\?[\]}]' && s:CheckPairedIsLastCharacter(v:lnum, ccol) |
11518 | 265 let ind -= shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
266 let stay = 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
267 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
268 |
13937 | 269 if line !~ '^\s*\\\?[\]}]' |
20552 | 270 for i in range(1, strlen(line)-1) |
13937 | 271 let char = line[i] |
272 if char == ']' || char == '}' | |
273 if s:CheckPairedIsLastCharacter(lnum, i) | |
274 let ind -= shiftwidth() | |
275 let stay = 0 | |
276 endif | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
277 endif |
13937 | 278 endfor |
279 endif | |
3445 | 280 endif |
3224 | 281 |
282 " Special treatment for 'item' | |
283 " ---------------------------- | |
284 | |
285 if g:tex_indent_items | |
286 " '\item' or '\bibitem' itself: | |
287 if cline =~ g:tex_items | |
11518 | 288 let ind = ind - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
289 let stay = 0 |
3224 | 290 endif |
291 " lines following to '\item' are intented once again: | |
292 if line =~ g:tex_items | |
11518 | 293 let ind = ind + shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
294 let stay = 0 |
3224 | 295 endif |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
296 endif |
3224 | 297 |
13937 | 298 if stay && mode() == 'i' |
299 " If there is no obvious indentation hint, and indentation is triggered | |
300 " 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
|
301 if empty(cline) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
302 return ind |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
303 else |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
304 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
|
305 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
306 else |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
307 return ind |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
308 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
309 endfunction "}}} |
13937 | 310 |
311 function! s:GetLastBeginIndentation(lnum) " {{{ | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
312 let matchend = 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
313 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
|
314 let line = getline(lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
315 if line =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
316 let matchend += 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
317 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
318 if line =~ '\\begin{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
319 let matchend -= 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
320 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
321 if matchend == 0 |
13937 | 322 if line =~ g:tex_noindent_env |
323 return indent(lnum) | |
324 endif | |
13912 | 325 if line =~ g:tex_itemize_env |
326 return indent(lnum) + 2 * shiftwidth() | |
327 endif | |
11518 | 328 return indent(lnum) + shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
329 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
330 endfor |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
331 return -1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
332 endfunction |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
333 |
13937 | 334 function! s:GetEndIndentation(lnum) " {{{ |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
335 if getline(a:lnum) =~ '\\begin{.*}.*\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
336 return -1 |
3224 | 337 endif |
338 | |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
339 let min_indent = 100 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
340 let matchend = 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
341 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
|
342 let line = getline(lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
343 if line =~ '\\end{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
344 let matchend += 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
345 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
346 if line =~ '\\begin{.*}' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
347 let matchend -= 1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
348 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
349 if matchend == 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
350 return indent(lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
351 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
352 if !empty(line) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
353 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
|
354 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
355 endfor |
11518 | 356 return min_indent - shiftwidth() |
8392
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
357 endfunction |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
358 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
359 " 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
|
360 function! s:CheckPairedIsLastCharacter(lnum, col) "{{{ |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
361 let c_lnum = a:lnum |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
362 let c_col = a:col+1 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
363 |
13937 | 364 let line = getline(c_lnum) |
365 if line[c_col-1] == '\' | |
366 let c_col = c_col + 1 | |
367 endif | |
368 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
|
369 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
370 let plist = split(&matchpairs, '.\zs[:,]') |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
371 let i = index(plist, c) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
372 if i < 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
373 return 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
374 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
375 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
376 " Figure out the arguments for searchpairpos(). |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
377 if i % 2 == 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
378 let s_flags = 'nW' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
379 let c2 = plist[i + 1] |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
380 else |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
381 let s_flags = 'nbW' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
382 let c2 = c |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
383 let c = plist[i - 1] |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
384 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
385 if c == '[' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
386 let c = '\[' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
387 let c2 = '\]' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
388 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
389 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
390 " 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
|
391 " moment. |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
392 let save_cursor = winsaveview() |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
393 call cursor(c_lnum, c_col) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
394 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
395 " 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
|
396 " 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
|
397 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
|
398 \ '=~? "string\\|character\\|singlequote\\|escape\\|comment"' |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
399 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
|
400 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
401 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
|
402 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
403 " 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
|
404 " 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
|
405 try |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
406 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
|
407 catch /E118/ |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
408 endtry |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
409 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
410 call winrestview(save_cursor) |
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 if m_lnum > 0 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
413 let line = getline(m_lnum) |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
414 return strlen(line) == m_col |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
415 endif |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
416 |
1bf1b88968a2
commit https://github.com/vim/vim/commit/328da0dcb7be34b594725eef6dc98d3ea6516d69
Christian Brabandt <cb@256bit.org>
parents:
4437
diff
changeset
|
417 return 0 |
13937 | 418 endfunction "}}} |
419 | |
3237 | 420 let &cpo = s:cpo_save |
421 unlet s:cpo_save | |
422 | |
3224 | 423 " vim: set sw=4 textwidth=80: |