aboutsummaryrefslogtreecommitdiff
path: root/indent
diff options
context:
space:
mode:
authorMax Christian Pohle2016-05-09 17:00:35 +0200
committerMax Christian Pohle2016-05-09 17:00:35 +0200
commitc2a13ef3f498d90fb9f46b830e14c31156635676 (patch)
treee125ca03554399949d6ca0fd27b7cf1953cbf02c /indent
parent8fd5f60d660f385b766b9c0e7ac874632c1cea1f (diff)
downloadvim-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/.keep1
-rw-r--r--indent/html5.vim387
-rw-r--r--indent/php.vim37
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.
27if exists("b:did_indent")
28 finish
29endif
30runtime! indent/javascript.vim
31let s:jsindent = &indentexpr
32unlet b:did_indent
33runtime! indent/css.vim
34let s:cssindent = &indentexpr
35let b:did_indent = 1
36
37" [-- local settings (must come before aborting the script) --]
38setlocal indentexpr=HtmlIndentGet(v:lnum)
39setlocal indentkeys=o,O,*<Return>,<>>,{,},!^F
40
41
42let s:tags = []
43
44" [-- <ELEMENT ? - - ...> --]
45call add(s:tags, 'a')
46call add(s:tags, 'abbr')
47call add(s:tags, 'acronym')
48call add(s:tags, 'address')
49call add(s:tags, 'b')
50call add(s:tags, 'bdo')
51call add(s:tags, 'big')
52call add(s:tags, 'blockquote')
53call add(s:tags, 'button')
54call add(s:tags, 'caption')
55call add(s:tags, 'center')
56call add(s:tags, 'cite')
57call add(s:tags, 'code')
58call add(s:tags, 'colgroup')
59call add(s:tags, 'del')
60call add(s:tags, 'dfn')
61call add(s:tags, 'dir')
62call add(s:tags, 'div')
63call add(s:tags, 'dl')
64call add(s:tags, 'dt')
65call add(s:tags, 'dd')
66call add(s:tags, 'em')
67call add(s:tags, 'fieldset')
68call add(s:tags, 'font')
69call add(s:tags, 'form')
70call add(s:tags, 'frameset')
71call add(s:tags, 'h1')
72call add(s:tags, 'h2')
73call add(s:tags, 'h3')
74call add(s:tags, 'h4')
75call add(s:tags, 'h5')
76call add(s:tags, 'h6')
77call add(s:tags, 'i')
78call add(s:tags, 'iframe')
79call add(s:tags, 'ins')
80call add(s:tags, 'kbd')
81call add(s:tags, 'label')
82call add(s:tags, 'legend')
83call add(s:tags, 'li')
84call add(s:tags, 'map')
85call add(s:tags, 'menu')
86call add(s:tags, 'noframes')
87call add(s:tags, 'noscript')
88call add(s:tags, 'object')
89call add(s:tags, 'ol')
90call add(s:tags, 'optgroup')
91call add(s:tags, 'p')
92" call add(s:tags, 'pre')
93call add(s:tags, 'q')
94call add(s:tags, 's')
95call add(s:tags, 'samp')
96call add(s:tags, 'script')
97call add(s:tags, 'select')
98call add(s:tags, 'small')
99call add(s:tags, 'span')
100call add(s:tags, 'strong')
101call add(s:tags, 'style')
102call add(s:tags, 'sub')
103call add(s:tags, 'sup')
104call add(s:tags, 'table')
105call add(s:tags, 'textarea')
106call add(s:tags, 'title')
107call add(s:tags, 'tt')
108call add(s:tags, 'u')
109call add(s:tags, 'ul')
110call add(s:tags, 'var')
111
112" New HTML 5 elements
113call add(s:tags, 'article')
114call add(s:tags, 'aside')
115call add(s:tags, 'audio')
116call add(s:tags, 'canvas')
117call add(s:tags, 'datalist')
118call add(s:tags, 'details')
119call add(s:tags, 'figcaption')
120call add(s:tags, 'figure')
121call add(s:tags, 'footer')
122call add(s:tags, 'header')
123call add(s:tags, 'hgroup')
124call add(s:tags, 'main')
125call add(s:tags, 'mark')
126call add(s:tags, 'meter')
127call add(s:tags, 'nav')
128call add(s:tags, 'output')
129call add(s:tags, 'progress')
130call add(s:tags, 'picture')
131call add(s:tags, 'rb')
132call add(s:tags, 'rp')
133call add(s:tags, 'rt')
134call add(s:tags, 'rtc')
135call add(s:tags, 'ruby')
136call add(s:tags, 'section')
137call add(s:tags, 'source')
138call add(s:tags, 'summary')
139call add(s:tags, 'time')
140call add(s:tags, 'video')
141call add(s:tags, 'bdi')
142call add(s:tags, 'data')
143
144" Web Component
145call add(s:tags, 'template')
146
147" Common inline used SVG elements
148call add(s:tags, 'clipPath')
149call add(s:tags, 'defs')
150call add(s:tags, 'desc')
151call add(s:tags, 'filter')
152call add(s:tags, 'foreignObject')
153call add(s:tags, 'g')
154call add(s:tags, 'linearGradient')
155call add(s:tags, 'marker')
156call add(s:tags, 'mask')
157call add(s:tags, 'pattern')
158call add(s:tags, 'radialGradient')
159call add(s:tags, 'svg')
160call add(s:tags, 'switch')
161call add(s:tags, 'symbol')
162call add(s:tags, 'text')
163call add(s:tags, 'textPath')
164call add(s:tags, 'tref')
165call add(s:tags, 'tspan')
166
167call add(s:tags, 'html')
168call add(s:tags, 'head')
169call add(s:tags, 'body')
170
171call add(s:tags, 'thead')
172call add(s:tags, 'tbody')
173call add(s:tags, 'tfoot')
174call add(s:tags, 'tr')
175call add(s:tags, 'th')
176call add(s:tags, 'td')
177
178
179
180let 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
188if exists('g:html_exclude_tags')
189 for tag in g:html_exclude_tags
190 call remove(s:tags, index(s:tags, tag))
191 endfor
192endif
193let s:html_indent_tags = join(s:tags, '\|')
194let s:html_indent_tags = s:html_indent_tags.'\|\w\+\(-\w\+\)\+'
195if exists('g:html_indent_tags')
196 let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
197endif
198
199let s:cpo_save = &cpo
200set cpo-=C
201
202" [-- count indent-increasing tags of line a:lnum --]
203fun! <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)
208endfun
209
210" [-- count indent-decreasing tags of line a:lnum --]
211fun! <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)
216endfun
217
218" [-- count indent-increasing '{' of (java|css) line a:lnum --]
219fun! <SID>HtmlIndentOpenAlt(lnum)
220 return strlen(substitute(getline(a:lnum), '[^{]\+', '', 'g'))
221endfun
222
223" [-- count indent-decreasing '}' of (java|css) line a:lnum --]
224fun! <SID>HtmlIndentCloseAlt(lnum)
225 return strlen(substitute(getline(a:lnum), '[^}]\+', '', 'g'))
226endfun
227
228" [-- return the sum of indents respecting the syntax of a:lnum --]
229fun! <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
249endfun
250
251fun! 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)
382endfun
383
384let &cpo = s:cpo_save
385unlet 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.
3if exists("b:did_indent")
4 finish
5endif
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:
8if exists('s:doing_indent_inits')
9 finish
10endif
11let s:doing_indent_inits = 1
12runtime! indent/html.vim
13unlet b:did_indent
14runtime! indent/php.vim
15unlet s:doing_indent_inits
16function! 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
35endfunction
36setlocal indentexpr=GetPhpHtmlIndent(v:lnum)
37setlocal indentkeys+=<>>
..