xinetd.vim 1.2 KB

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