0
|
1 " Vim indent file
|
|
2 " Language: CSS
|
|
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
|
48
|
4 " Latest Revision: 2012-05-30
|
0
|
5
|
|
6 if exists("b:did_indent")
|
|
7 finish
|
|
8 endif
|
|
9 let b:did_indent = 1
|
|
10
|
|
11 setlocal indentexpr=GetCSSIndent()
|
|
12 setlocal indentkeys=0{,0},!^F,o,O
|
|
13 setlocal nosmartindent
|
|
14
|
48
|
15 let b:undo_indent = "setl smartindent< indentkeys< indentexpr<"
|
|
16
|
0
|
17 if exists("*GetCSSIndent")
|
|
18 finish
|
|
19 endif
|
48
|
20 let s:keepcpo= &cpo
|
|
21 set cpo&vim
|
0
|
22
|
|
23 function s:prevnonblanknoncomment(lnum)
|
|
24 let lnum = a:lnum
|
|
25 while lnum > 1
|
|
26 let lnum = prevnonblank(lnum)
|
|
27 let line = getline(lnum)
|
|
28 if line =~ '\*/'
|
|
29 while lnum > 1 && line !~ '/\*'
|
|
30 let lnum -= 1
|
|
31 endwhile
|
|
32 if line =~ '^\s*/\*'
|
|
33 let lnum -= 1
|
|
34 else
|
|
35 break
|
|
36 endif
|
|
37 else
|
|
38 break
|
|
39 endif
|
|
40 endwhile
|
|
41 return lnum
|
|
42 endfunction
|
|
43
|
|
44 function s:count_braces(lnum, count_open)
|
|
45 let n_open = 0
|
|
46 let n_close = 0
|
|
47 let line = getline(a:lnum)
|
|
48 let pattern = '[{}]'
|
|
49 let i = match(line, pattern)
|
|
50 while i != -1
|
|
51 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)'
|
|
52 if line[i] == '{'
|
|
53 let n_open += 1
|
|
54 elseif line[i] == '}'
|
|
55 if n_open > 0
|
|
56 let n_open -= 1
|
|
57 else
|
|
58 let n_close += 1
|
|
59 endif
|
|
60 endif
|
|
61 endif
|
|
62 let i = match(line, pattern, i + 1)
|
|
63 endwhile
|
|
64 return a:count_open ? n_open : n_close
|
|
65 endfunction
|
|
66
|
|
67 function GetCSSIndent()
|
|
68 let line = getline(v:lnum)
|
|
69 if line =~ '^\s*\*'
|
|
70 return cindent(v:lnum)
|
|
71 endif
|
|
72
|
|
73 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
|
|
74 if pnum == 0
|
|
75 return 0
|
|
76 endif
|
|
77
|
48
|
78 return indent(pnum) + s:count_braces(pnum, 1) * &sw
|
|
79 \ - s:count_braces(v:lnum, 0) * &sw
|
|
80 endfunction
|
0
|
81
|
48
|
82 let &cpo = s:keepcpo
|
|
83 unlet s:keepcpo
|