1" Vim indent file
2" Language:         xinetd.conf(5) configuration file
3" Maintainer:       Nikolai Weibull <now@bitwi.se>
4" Latest Revision:  2006-12-20
5
6if exists("b:did_indent")
7  finish
8endif
9let b:did_indent = 1
10
11setlocal indentexpr=GetXinetdIndent()
12setlocal indentkeys=0{,0},!^F,o,O
13setlocal nosmartindent
14
15if exists("*GetXinetdIndent")
16  finish
17endif
18
19function s:count_braces(lnum, count_open)
20  let n_open = 0
21  let n_close = 0
22  let line = getline(a:lnum)
23  let pattern = '[{}]'
24  let i = match(line, pattern)
25  while i != -1
26    if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)'
27      if line[i] == '{'
28        let n_open += 1
29      elseif line[i] == '}'
30        if n_open > 0
31          let n_open -= 1
32        else
33          let n_close += 1
34        endif
35      endif
36    endif
37    let i = match(line, pattern, i + 1)
38  endwhile
39  return a:count_open ? n_open : n_close
40endfunction
41
42function GetXinetdIndent()
43  let pnum = prevnonblank(v:lnum - 1)
44  if pnum == 0
45    return 0
46  endif
47
48  return indent(pnum) + s:count_braces(pnum, 1) * &sw
49        \ - s:count_braces(v:lnum, 0) * &sw
50endfunction
51