xref: /vim-8.2.3635/runtime/indent/css.vim (revision 19a09a18)
1" Vim indent file
2" Language:	    CSS
3" Maintainer:	    Nikolai Weibull <[email protected]>
4" URL:		    http://www.pcppopper.org/vim/indent/pcp/css/
5" Latest Revision:  2004-04-25
6" arch-tag:	    ccfd77a0-1c9a-43f7-a407-bbe704541442
7
8" Only load this indent file when no other was loaded.
9if exists("b:did_indent")
10  finish
11endif
12
13let b:did_indent = 1
14
15setlocal indentexpr=GetCSSIndent()
16setlocal indentkeys-=:,0# indentkeys-=e
17
18" Only define the function once.
19if exists("*GetCSSIndent")
20  finish
21endif
22
23function! s:LookupLine(lnum)
24  " find a non-blank line above the current line
25  let lnum = prevnonblank(a:lnum - 1)
26
27  if lnum == 0
28    return 0
29  endif
30
31  let line = getline(lnum)
32
33  " if the line has an end comment sequence we need to find a line
34  " that isn't affected by the comment.
35  if line =~ '\*/'
36    while line !~ '/\*'
37      let lnum = lnum - 1
38      let line = getline(lnum)
39    endwhile
40  endif
41
42  " if the line we found only contained the comment and whitespace
43  " we need to find another line to use...
44  if line =~ '^\s*/\*'
45    return s:LookupLine(lnum)
46  else
47    return lnum
48  endif
49endfunction
50
51function GetCSSIndent()
52  let lnum = s:LookupLine(v:lnum)
53
54  if lnum == 0
55    return 0
56  endif
57
58  " remove commented stuff from line
59  let line = substitute(getline(lnum), '/\*.\*/', '', 'eg')
60
61  let ind = indent(lnum)
62
63  " check for opening brace on the previous line
64  " skip if it also contains a closing brace...
65  if line =~ '{\(.*}\)\@!'
66    let ind = ind + &sw
67  endif
68
69  let line = getline(v:lnum)
70
71  " check for closing brace first on current line
72  if line =~ '^\s*}'
73    let ind	= ind - &sw
74  endif
75
76  return ind
77endfunction
78
79" vim: set sts=2 sw=2:
80