hog.vim 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. " Vim indent file
  2. " Language: hog (Snort.conf)
  3. " Maintainer: Victor Roemer, <vroemer@badsec.org>
  4. " Last Change: Mar 7, 2013
  5. " Only load this indent file when no other was loaded.
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. let b:did_indent = 1
  10. let b:undo_indent = 'setlocal smartindent< indentexpr< indentkeys<'
  11. setlocal nosmartindent
  12. setlocal indentexpr=GetHogIndent()
  13. setlocal indentkeys+=!^F,o,O,0#
  14. " Only define the function once.
  15. if exists("*GetHogIndent")
  16. finish
  17. endif
  18. let s:cpo_save = &cpo
  19. set cpo&vim
  20. let s:syn_blocks = '\<SnortRuleTypeBody\>'
  21. function s:IsInBlock(lnum)
  22. return synIDattr(synID(a:lnum, 1, 1), 'name') =~ s:syn_blocks
  23. endfunction
  24. function GetHogIndent()
  25. let prevlnum = prevnonblank(v:lnum-1)
  26. " Comment blocks have identical indent
  27. if getline(v:lnum) =~ '^\s*#' && getline(prevlnum) =~ '^\s*#'
  28. return indent(prevlnum)
  29. endif
  30. " Ignore comment lines when calculating indent
  31. while getline(prevlnum) =~ '^\s*#'
  32. let prevlnum = prevnonblank(prevlnum-1)
  33. if !prevlnum
  34. return previndent
  35. endif
  36. endwhile
  37. " Continuation of a line that wasn't indented
  38. let prevline = getline(prevlnum)
  39. if prevline =~ '^\k\+.*\\\s*$'
  40. return shiftwidth()
  41. endif
  42. " Continuation of a line that was indented
  43. if prevline =~ '\k\+.*\\\s*$'
  44. return indent(prevlnum)
  45. endif
  46. " Indent the next line if previous line contained a start of a block
  47. " definition ('{' or '(').
  48. if prevline =~ '^\k\+[^#]*{}\@!\s*$' " TODO || prevline =~ '^\k\+[^#]*()\@!\s*$'
  49. return shiftwidth()
  50. endif
  51. " Match inside of a block
  52. if s:IsInBlock(v:lnum)
  53. if prevline =~ "^\k\+.*$"
  54. return shiftwidth()
  55. else
  56. return indent(prevlnum)
  57. endif
  58. endif
  59. return 0
  60. endfunction
  61. let &cpo = s:cpo_save
  62. unlet s:cpo_save