diff options
author | Max Christian Pohle | 2016-05-09 17:00:35 +0200 |
---|---|---|
committer | Max Christian Pohle | 2016-05-09 17:00:35 +0200 |
commit | c2a13ef3f498d90fb9f46b830e14c31156635676 (patch) | |
tree | e125ca03554399949d6ca0fd27b7cf1953cbf02c /indent | |
parent | 8fd5f60d660f385b766b9c0e7ac874632c1cea1f (diff) | |
download | vim-karlmarks-c2a13ef3f498d90fb9f46b830e14c31156635676.tar.bz2 vim-karlmarks-c2a13ef3f498d90fb9f46b830e14c31156635676.zip |
moved repository up again
this repo shell be used for vim exclusively
Diffstat (limited to 'indent')
-rw-r--r-- | indent/.keep | 1 | ||||
-rw-r--r-- | indent/html5.vim | 387 | ||||
-rw-r--r-- | indent/php.vim | 37 |
3 files changed, 425 insertions, 0 deletions
diff --git a/indent/.keep b/indent/.keep new file mode 100644 index 0000000..f8e463a --- /dev/null +++ b/indent/.keep | |||
@@ -0,0 +1 @@ | |||
this directory gets used for custom indentation rules. file naming follows the extension of the files the indentation is for and the extension .vim. | |||
diff --git a/indent/html5.vim b/indent/html5.vim new file mode 100644 index 0000000..94baa87 --- /dev/null +++ b/indent/html5.vim | |||
@@ -0,0 +1,387 @@ | |||
1 | " Description: HTML5 and inline SVG indenter | ||
2 | " Changed By: HT de Beer <H.T.de.Beer@gmail.com> | ||
3 | " Last Change: 20121013 | ||
4 | " Added the SVG elements to the list of indenting element. SVG elements | ||
5 | " taken from http://www.w3.org/TR/SVG/eltindex.html | ||
6 | " | ||
7 | " Description: html5 (and html4) indenter | ||
8 | " Changed By: Brian Gershon <brian.five@gmail.com> | ||
9 | " Last Change: 30 Jan 2011 | ||
10 | " | ||
11 | " 1. Started with vim72 html indent file authored by Johannes Zellner (below) | ||
12 | " 2. Added html5 list as described here: | ||
13 | " http://stackoverflow.com/questions/3232518/how-to-update-vim-to-color-code-new-html-elements | ||
14 | " 3. Added this to a fork of https://github.com/othree/html5.vim | ||
15 | " which already provides nice html5 syntax highlighting. | ||
16 | " | ||
17 | " Description: html indenter | ||
18 | " Author: Johannes Zellner <johannes@zellner.org> | ||
19 | " Last Change: Mo, 05 Jun 2006 22:32:41 CEST | ||
20 | " Restoring 'cpo' and 'ic' added by Bram 2006 May 5 | ||
21 | " Globals: | ||
22 | " let g:html_indent_tags = 'html\|p\|time' | ||
23 | " let g:html_exclude_tags = ['html', 'style', 'script', 'body'] | ||
24 | |||
25 | |||
26 | " Only load this indent file when no other was loaded. | ||
27 | if exists("b:did_indent") | ||
28 | finish | ||
29 | endif | ||
30 | runtime! indent/javascript.vim | ||
31 | let s:jsindent = &indentexpr | ||
32 | unlet b:did_indent | ||
33 | runtime! indent/css.vim | ||
34 | let s:cssindent = &indentexpr | ||
35 | let b:did_indent = 1 | ||
36 | |||
37 | " [-- local settings (must come before aborting the script) --] | ||
38 | setlocal indentexpr=HtmlIndentGet(v:lnum) | ||
39 | setlocal indentkeys=o,O,*<Return>,<>>,{,},!^F | ||
40 | |||
41 | |||
42 | let s:tags = [] | ||
43 | |||
44 | " [-- <ELEMENT ? - - ...> --] | ||
45 | call add(s:tags, 'a') | ||
46 | call add(s:tags, 'abbr') | ||
47 | call add(s:tags, 'acronym') | ||
48 | call add(s:tags, 'address') | ||
49 | call add(s:tags, 'b') | ||
50 | call add(s:tags, 'bdo') | ||
51 | call add(s:tags, 'big') | ||
52 | call add(s:tags, 'blockquote') | ||
53 | call add(s:tags, 'button') | ||
54 | call add(s:tags, 'caption') | ||
55 | call add(s:tags, 'center') | ||
56 | call add(s:tags, 'cite') | ||
57 | call add(s:tags, 'code') | ||
58 | call add(s:tags, 'colgroup') | ||
59 | call add(s:tags, 'del') | ||
60 | call add(s:tags, 'dfn') | ||
61 | call add(s:tags, 'dir') | ||
62 | call add(s:tags, 'div') | ||
63 | call add(s:tags, 'dl') | ||
64 | call add(s:tags, 'dt') | ||
65 | call add(s:tags, 'dd') | ||
66 | call add(s:tags, 'em') | ||
67 | call add(s:tags, 'fieldset') | ||
68 | call add(s:tags, 'font') | ||
69 | call add(s:tags, 'form') | ||
70 | call add(s:tags, 'frameset') | ||
71 | call add(s:tags, 'h1') | ||
72 | call add(s:tags, 'h2') | ||
73 | call add(s:tags, 'h3') | ||
74 | call add(s:tags, 'h4') | ||
75 | call add(s:tags, 'h5') | ||
76 | call add(s:tags, 'h6') | ||
77 | call add(s:tags, 'i') | ||
78 | call add(s:tags, 'iframe') | ||
79 | call add(s:tags, 'ins') | ||
80 | call add(s:tags, 'kbd') | ||
81 | call add(s:tags, 'label') | ||
82 | call add(s:tags, 'legend') | ||
83 | call add(s:tags, 'li') | ||
84 | call add(s:tags, 'map') | ||
85 | call add(s:tags, 'menu') | ||
86 | call add(s:tags, 'noframes') | ||
87 | call add(s:tags, 'noscript') | ||
88 | call add(s:tags, 'object') | ||
89 | call add(s:tags, 'ol') | ||
90 | call add(s:tags, 'optgroup') | ||
91 | call add(s:tags, 'p') | ||
92 | " call add(s:tags, 'pre') | ||
93 | call add(s:tags, 'q') | ||
94 | call add(s:tags, 's') | ||
95 | call add(s:tags, 'samp') | ||
96 | call add(s:tags, 'script') | ||
97 | call add(s:tags, 'select') | ||
98 | call add(s:tags, 'small') | ||
99 | call add(s:tags, 'span') | ||
100 | call add(s:tags, 'strong') | ||
101 | call add(s:tags, 'style') | ||
102 | call add(s:tags, 'sub') | ||
103 | call add(s:tags, 'sup') | ||
104 | call add(s:tags, 'table') | ||
105 | call add(s:tags, 'textarea') | ||
106 | call add(s:tags, 'title') | ||
107 | call add(s:tags, 'tt') | ||
108 | call add(s:tags, 'u') | ||
109 | call add(s:tags, 'ul') | ||
110 | call add(s:tags, 'var') | ||
111 | |||
112 | " New HTML 5 elements | ||
113 | call add(s:tags, 'article') | ||
114 | call add(s:tags, 'aside') | ||
115 | call add(s:tags, 'audio') | ||
116 | call add(s:tags, 'canvas') | ||
117 | call add(s:tags, 'datalist') | ||
118 | call add(s:tags, 'details') | ||
119 | call add(s:tags, 'figcaption') | ||
120 | call add(s:tags, 'figure') | ||
121 | call add(s:tags, 'footer') | ||
122 | call add(s:tags, 'header') | ||
123 | call add(s:tags, 'hgroup') | ||
124 | call add(s:tags, 'main') | ||
125 | call add(s:tags, 'mark') | ||
126 | call add(s:tags, 'meter') | ||
127 | call add(s:tags, 'nav') | ||
128 | call add(s:tags, 'output') | ||
129 | call add(s:tags, 'progress') | ||
130 | call add(s:tags, 'picture') | ||
131 | call add(s:tags, 'rb') | ||
132 | call add(s:tags, 'rp') | ||
133 | call add(s:tags, 'rt') | ||
134 | call add(s:tags, 'rtc') | ||
135 | call add(s:tags, 'ruby') | ||
136 | call add(s:tags, 'section') | ||
137 | call add(s:tags, 'source') | ||
138 | call add(s:tags, 'summary') | ||
139 | call add(s:tags, 'time') | ||
140 | call add(s:tags, 'video') | ||
141 | call add(s:tags, 'bdi') | ||
142 | call add(s:tags, 'data') | ||
143 | |||
144 | " Web Component | ||
145 | call add(s:tags, 'template') | ||
146 | |||
147 | " Common inline used SVG elements | ||
148 | call add(s:tags, 'clipPath') | ||
149 | call add(s:tags, 'defs') | ||
150 | call add(s:tags, 'desc') | ||
151 | call add(s:tags, 'filter') | ||
152 | call add(s:tags, 'foreignObject') | ||
153 | call add(s:tags, 'g') | ||
154 | call add(s:tags, 'linearGradient') | ||
155 | call add(s:tags, 'marker') | ||
156 | call add(s:tags, 'mask') | ||
157 | call add(s:tags, 'pattern') | ||
158 | call add(s:tags, 'radialGradient') | ||
159 | call add(s:tags, 'svg') | ||
160 | call add(s:tags, 'switch') | ||
161 | call add(s:tags, 'symbol') | ||
162 | call add(s:tags, 'text') | ||
163 | call add(s:tags, 'textPath') | ||
164 | call add(s:tags, 'tref') | ||
165 | call add(s:tags, 'tspan') | ||
166 | |||
167 | call add(s:tags, 'html') | ||
168 | call add(s:tags, 'head') | ||
169 | call add(s:tags, 'body') | ||
170 | |||
171 | call add(s:tags, 'thead') | ||
172 | call add(s:tags, 'tbody') | ||
173 | call add(s:tags, 'tfoot') | ||
174 | call add(s:tags, 'tr') | ||
175 | call add(s:tags, 'th') | ||
176 | call add(s:tags, 'td') | ||
177 | |||
178 | |||
179 | |||
180 | let s:omittable = [ | ||
181 | \ ['address', 'article', 'aside', 'blockquote', 'dir', 'div', 'dl', 'fieldset', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'], | ||
182 | \ ['dt', 'dd'], | ||
183 | \ ['li'], | ||
184 | \ ['thead', 'tbody', 'tfoot'], | ||
185 | \ ['th', 'td'], | ||
186 | \] | ||
187 | |||
188 | if exists('g:html_exclude_tags') | ||
189 | for tag in g:html_exclude_tags | ||
190 | call remove(s:tags, index(s:tags, tag)) | ||
191 | endfor | ||
192 | endif | ||
193 | let s:html_indent_tags = join(s:tags, '\|') | ||
194 | let s:html_indent_tags = s:html_indent_tags.'\|\w\+\(-\w\+\)\+' | ||
195 | if exists('g:html_indent_tags') | ||
196 | let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags | ||
197 | endif | ||
198 | |||
199 | let s:cpo_save = &cpo | ||
200 | set cpo-=C | ||
201 | |||
202 | " [-- count indent-increasing tags of line a:lnum --] | ||
203 | fun! <SID>HtmlIndentOpen(lnum, pattern) | ||
204 | let s = substitute('x'.getline(a:lnum), | ||
205 | \ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g') | ||
206 | let s = substitute(s, "[^\1].*$", '', '') | ||
207 | return strlen(s) | ||
208 | endfun | ||
209 | |||
210 | " [-- count indent-decreasing tags of line a:lnum --] | ||
211 | fun! <SID>HtmlIndentClose(lnum, pattern) | ||
212 | let s = substitute('x'.getline(a:lnum), | ||
213 | \ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g') | ||
214 | let s = substitute(s, "[^\1].*$", '', '') | ||
215 | return strlen(s) | ||
216 | endfun | ||
217 | |||
218 | " [-- count indent-increasing '{' of (java|css) line a:lnum --] | ||
219 | fun! <SID>HtmlIndentOpenAlt(lnum) | ||
220 | return strlen(substitute(getline(a:lnum), '[^{]\+', '', 'g')) | ||
221 | endfun | ||
222 | |||
223 | " [-- count indent-decreasing '}' of (java|css) line a:lnum --] | ||
224 | fun! <SID>HtmlIndentCloseAlt(lnum) | ||
225 | return strlen(substitute(getline(a:lnum), '[^}]\+', '', 'g')) | ||
226 | endfun | ||
227 | |||
228 | " [-- return the sum of indents respecting the syntax of a:lnum --] | ||
229 | fun! <SID>HtmlIndentSum(lnum, style) | ||
230 | if a:style == match(getline(a:lnum), '^\s*</') | ||
231 | if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>') | ||
232 | let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags) | ||
233 | let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) | ||
234 | if 0 != open || 0 != close | ||
235 | return open - close | ||
236 | endif | ||
237 | endif | ||
238 | endif | ||
239 | |||
240 | if '' != &syntax && | ||
241 | \ synIDattr(synID(a:lnum, 1, 1), 'name') =~ '\(css\|java\).*' && | ||
242 | \ synIDattr(synID(a:lnum, strlen(getline(a:lnum)), 1), 'name') | ||
243 | \ =~ '\(css\|java\).*' | ||
244 | if a:style == match(getline(a:lnum), '^\s*}') | ||
245 | return <SID>HtmlIndentOpenAlt(a:lnum) - <SID>HtmlIndentCloseAlt(a:lnum) | ||
246 | endif | ||
247 | endif | ||
248 | return 0 | ||
249 | endfun | ||
250 | |||
251 | fun! HtmlIndentGet(lnum) | ||
252 | " Find a non-empty line above the current line. | ||
253 | let lnum = prevnonblank(a:lnum - 1) | ||
254 | |||
255 | " Hit the start of the file, use zero indent. | ||
256 | if lnum == 0 | ||
257 | return 0 | ||
258 | endif | ||
259 | |||
260 | let restore_ic = &ic | ||
261 | setlocal ic " ignore case | ||
262 | |||
263 | " [-- special handling for <pre>: no indenting --] | ||
264 | if getline(a:lnum) =~ '\c</pre>' | ||
265 | \ || 0 < searchpair('\c<pre>', '', '\c</pre>', 'nWb') | ||
266 | \ || 0 < searchpair('\c<pre>', '', '\c</pre>', 'nW') | ||
267 | " we're in a line with </pre> or inside <pre> ... </pre> | ||
268 | if restore_ic == 0 | ||
269 | setlocal noic | ||
270 | endif | ||
271 | return -1 | ||
272 | endif | ||
273 | |||
274 | " [-- special handling for <javascript>: use cindent --] | ||
275 | let js = '<script' | ||
276 | let jse = '</script>' | ||
277 | |||
278 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
279 | " by Tye Zdrojewski <zdro@yahoo.com>, 05 Jun 2006 | ||
280 | " ZDR: This needs to be an AND (we are 'after the start of the pair' AND | ||
281 | " we are 'before the end of the pair'). Otherwise, indentation | ||
282 | " before the start of the script block will be affected; the end of | ||
283 | " the pair will still match if we are before the beginning of the | ||
284 | " pair. | ||
285 | " | ||
286 | if 0 < searchpair(js, '', jse, 'nWb') | ||
287 | \ && 0 < searchpair(js, '', jse, 'nW') | ||
288 | " we're inside javascript | ||
289 | if getline(searchpair(js, '', '</script>', 'nWb')) !~ '<script [^>]*type=["'']\?text\/\(html\|\(ng-\)\?template\)' | ||
290 | \ && getline(lnum) !~ js && getline(a:lnum) !~ jse | ||
291 | if restore_ic == 0 | ||
292 | setlocal noic | ||
293 | endif | ||
294 | if s:jsindent == '' | ||
295 | return cindent(a:lnum) | ||
296 | else | ||
297 | execute 'let ind = ' . s:jsindent | ||
298 | return ind | ||
299 | endif | ||
300 | endif | ||
301 | if getline(a:lnum) =~ jse | ||
302 | return indent(searchpair(js, '', jse, 'nWb')) | ||
303 | endif | ||
304 | endif | ||
305 | |||
306 | let css = '<style' | ||
307 | let csse = '</style>' | ||
308 | if 0 < searchpair(css, '', csse, 'nWb') | ||
309 | \ && 0 < searchpair(css, '', csse, 'nW') | ||
310 | " we're inside style | ||
311 | if getline(lnum) !~ css && getline(a:lnum) !~ csse | ||
312 | if restore_ic == 0 | ||
313 | setlocal noic | ||
314 | endif | ||
315 | if s:cssindent == '' | ||
316 | return cindent(a:lnum) | ||
317 | else | ||
318 | execute 'let ind = ' . s:cssindent | ||
319 | return ind | ||
320 | endif | ||
321 | endif | ||
322 | if getline(a:lnum) =~ csse | ||
323 | return indent(searchpair(css, '', csse, 'nWb')) | ||
324 | endif | ||
325 | endif | ||
326 | |||
327 | if getline(lnum) =~ '\c</pre>' | ||
328 | " line before the current line a:lnum contains | ||
329 | " a closing </pre>. --> search for line before | ||
330 | " starting <pre> to restore the indent. | ||
331 | let preline = prevnonblank(search('\c<pre>', 'bW') - 1) | ||
332 | if preline > 0 | ||
333 | if restore_ic == 0 | ||
334 | setlocal noic | ||
335 | endif | ||
336 | |||
337 | if 0 == match(getline(a:lnum), '^\s*</') | ||
338 | return indent(preline) - (1*&sw) | ||
339 | else | ||
340 | return indent(preline) | ||
341 | endif | ||
342 | endif | ||
343 | endif | ||
344 | |||
345 | let ind = <SID>HtmlIndentSum(lnum, -1) | ||
346 | let ind = ind + <SID>HtmlIndentSum(a:lnum, 0) | ||
347 | |||
348 | " Fix for conditional comment | ||
349 | if getline(a:lnum) =~ '\c<!--.*<\(html\|body\).*-->' | ||
350 | let ind = ind - 1 | ||
351 | endif | ||
352 | |||
353 | let lind = indent(lnum) | ||
354 | |||
355 | " for tags in s:omittable | ||
356 | " let tags_exp = '<\(' . join(tags, '\|') . '\)>' | ||
357 | " let close_tags_exp = '</\(' . join(tags, '\|') . '\)>' | ||
358 | " if getline(a:lnum) =~ tags_exp | ||
359 | " let block_start = search('^'.repeat(' ', lind + (&sw * ind - 1)).'\S' , 'bnW') | ||
360 | " let prev_tag = search(tags_exp, 'bW', block_start) | ||
361 | " let prev_closetag = search(close_tags_exp, 'W', a:lnum) | ||
362 | " if prev_tag && !prev_closetag | ||
363 | " let ind = ind - 1 | ||
364 | " endif | ||
365 | " endif | ||
366 | |||
367 | " if getline(a:lnum) =~ '</\w\+>' | ||
368 | " let block_start = search('^'.repeat(' ', lind + (&sw * ind - 1)).'\S' , 'bnW') | ||
369 | " let prev_tag = search(tags_exp, 'bW', block_start) | ||
370 | " let prev_closetag = search(close_tags_exp, 'W', a:lnum) | ||
371 | " if prev_tag && !prev_closetag | ||
372 | " let ind = ind - 1 | ||
373 | " endif | ||
374 | " endif | ||
375 | " endfor | ||
376 | |||
377 | if restore_ic == 0 | ||
378 | setlocal noic | ||
379 | endif | ||
380 | |||
381 | return lind + (&sw * ind) | ||
382 | endfun | ||
383 | |||
384 | let &cpo = s:cpo_save | ||
385 | unlet s:cpo_save | ||
386 | |||
387 | " [-- EOF <runtime>/indent/html.vim --] | ||
diff --git a/indent/php.vim b/indent/php.vim new file mode 100644 index 0000000..ef723a6 --- /dev/null +++ b/indent/php.vim | |||
@@ -0,0 +1,37 @@ | |||
1 | " Better indent support for PHP by making it possible to indent HTML sections | ||
2 | " as well. | ||
3 | if exists("b:did_indent") | ||
4 | finish | ||
5 | endif | ||
6 | " This script pulls in the default indent/php.vim with the :runtime command | ||
7 | " which could re-run this script recursively unless we catch that: | ||
8 | if exists('s:doing_indent_inits') | ||
9 | finish | ||
10 | endif | ||
11 | let s:doing_indent_inits = 1 | ||
12 | runtime! indent/html.vim | ||
13 | unlet b:did_indent | ||
14 | runtime! indent/php.vim | ||
15 | unlet s:doing_indent_inits | ||
16 | function! GetPhpHtmlIndent(lnum) | ||
17 | if exists('*HtmlIndent') | ||
18 | let html_ind = HtmlIndent() | ||
19 | else | ||
20 | let html_ind = HtmlIndentGet(a:lnum) | ||
21 | endif | ||
22 | let php_ind = GetPhpIndent() | ||
23 | " priority one for php indent script | ||
24 | if php_ind > -1 | ||
25 | return php_ind | ||
26 | endif | ||
27 | if html_ind > -1 | ||
28 | if getline(a:num) =~ "^<?" && (0< searchpair('<?', '', '?>', 'nWb') | ||
29 | \ || 0 < searchpair('<?', '', '?>', 'nW')) | ||
30 | return -1 | ||
31 | endif | ||
32 | return html_ind | ||
33 | endif | ||
34 | return -1 | ||
35 | endfunction | ||
36 | setlocal indentexpr=GetPhpHtmlIndent(v:lnum) | ||
37 | setlocal indentkeys+=<>> | ||