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