summaryrefslogtreecommitdiffstats
path: root/runtime/indent/css.vim
blob: 610c725c69b9ce8f74e0982e10f2965b3778487d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
" Vim indent file
" Language:	    CSS
" Maintainer:	    Nikolai Weibull <source@pcppopper.org>
" URL:		    http://www.pcppopper.org/vim/indent/pcp/css/
" Latest Revision:  2004-04-25
" arch-tag:	    ccfd77a0-1c9a-43f7-a407-bbe704541442

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
  finish
endif

let b:did_indent = 1

setlocal indentexpr=GetCSSIndent()
setlocal indentkeys-=:,0# indentkeys-=e

" Only define the function once.
if exists("*GetCSSIndent")
  finish
endif

function! s:LookupLine(lnum)
  " find a non-blank line above the current line
  let lnum = prevnonblank(a:lnum - 1)

  if lnum == 0
    return 0
  endif

  let line = getline(lnum)

  " if the line has an end comment sequence we need to find a line
  " that isn't affected by the comment.
  if line =~ '\*/'
    while line !~ '/\*'
      let lnum = lnum - 1
      let line = getline(lnum)
    endwhile
  endif

  " if the line we found only contained the comment and whitespace
  " we need to find another line to use...
  if line =~ '^\s*/\*'
    return s:LookupLine(lnum)
  else
    return lnum
  endif
endfunction

function GetCSSIndent()
  let lnum = s:LookupLine(v:lnum)

  if lnum == 0
    return 0
  endif

  " remove commented stuff from line
  let line = substitute(getline(lnum), '/\*.\*/', '', 'eg')

  let ind = indent(lnum)

  " check for opening brace on the previous line
  " skip if it also contains a closing brace...
  if line =~ '{\(.*}\)\@!'
    let ind = ind + &sw
  endif

  let line = getline(v:lnum)

  " check for closing brace first on current line
  if line =~ '^\s*}'
    let ind	= ind - &sw
  endif

  return ind
endfunction

" vim: set sts=2 sw=2: