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