annotate runtime/indent/css.vim @ 1460:b0dabd584b8f v7.1.175

updated for version 7.1-175
author vimboss
date Sun, 09 Dec 2007 19:26:44 +0000
parents 7cdd85615e4e
children b6471224d2af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
2 " Language: CSS
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 389
diff changeset
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
4 " Latest Revision: 2006-12-20
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 setlocal indentexpr=GetCSSIndent()
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
12 setlocal indentkeys=0{,0},!^F,o,O
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
13 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 if exists("*GetCSSIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
19 function s:prevnonblanknoncomment(lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
20 let lnum = a:lnum
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
21 while lnum > 1
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
22 let lnum = prevnonblank(lnum)
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
23 let line = getline(lnum)
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
24 if line =~ '\*/'
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
25 while lnum > 1 && line !~ '/\*'
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
26 let lnum -= 1
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
27 endwhile
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
28 if line =~ '^\s*/\*'
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
29 let lnum -= 1
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
30 else
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
31 break
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
32 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
33 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
34 break
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
35 endif
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
36 endwhile
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
37 return lnum
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
38 endfunction
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
39
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
40 function s:count_braces(lnum, count_open)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
41 let n_open = 0
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
42 let n_close = 0
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
43 let line = getline(a:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
44 let pattern = '[{}]'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
45 let i = match(line, pattern)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
46 while i != -1
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
47 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
48 if line[i] == '{'
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
49 let n_open += 1
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
50 elseif line[i] == '}'
1189
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
51 if n_open > 0
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
52 let n_open -= 1
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
53 else
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
54 let n_close += 1
7cdd85615e4e updated for version 7.1b
vimboss
parents: 856
diff changeset
55 endif
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
56 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
57 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
58 let i = match(line, pattern, i + 1)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
59 endwhile
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
60 return a:count_open ? n_open : n_close
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
61 endfunction
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
62
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 7
diff changeset
63 function GetCSSIndent()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
64 let line = getline(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
65 if line =~ '^\s*\*'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
66 return cindent(v:lnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
67 elseif line =~ '^\s*}'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
68 return indent(v:lnum) - &sw
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
69 endif
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
70
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
71 let pnum = s:prevnonblanknoncomment(v:lnum - 1)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
72 if pnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
76 let ind = indent(pnum) + s:count_braces(pnum, 1) * &sw
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
78 let pline = getline(pnum)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
79 if pline =~ '}\s*$'
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 375
diff changeset
80 let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * &sw
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 endfunction