xinetd.vim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. " Vim indent file
  2. " Language: xinetd.conf(5) configuration file
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
  5. " Last Change: 2022 April 25
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. setlocal indentexpr=GetXinetdIndent()
  11. setlocal indentkeys=0{,0},!^F,o,O
  12. setlocal nosmartindent
  13. let b:undo_indent = "setl inde< indk< si<"
  14. if exists("*GetXinetdIndent")
  15. finish
  16. endif
  17. let s:keepcpo= &cpo
  18. set cpo&vim
  19. function 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
  40. endfunction
  41. function GetXinetdIndent()
  42. let pnum = prevnonblank(v:lnum - 1)
  43. if pnum == 0
  44. return 0
  45. endif
  46. return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
  47. \ - s:count_braces(v:lnum, 0) * shiftwidth()
  48. endfunction
  49. let &cpo = s:keepcpo
  50. unlet s:keepcpo