vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

hog.vim (1892B)


      1 " 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.
      7 if exists("b:did_indent")
      8     finish
      9 endif
     10 let b:did_indent = 1
     11 let b:undo_indent = 'setlocal smartindent< indentexpr< indentkeys<'
     12 
     13 setlocal nosmartindent
     14 setlocal indentexpr=GetHogIndent()
     15 setlocal indentkeys+=!^F,o,O,0#
     16 
     17 " Only define the function once.
     18 if exists("*GetHogIndent")
     19     finish
     20 endif
     21 
     22 let s:cpo_save = &cpo
     23 set cpo&vim
     24 
     25 let s:syn_blocks = '\<SnortRuleTypeBody\>'
     26 
     27 function s:IsInBlock(lnum)
     28     return synIDattr(synID(a:lnum, 1, 1), 'name') =~ s:syn_blocks 
     29 endfunction
     30 
     31 function 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*$'
     50         return shiftwidth() 
     51     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*$'
     61         return shiftwidth()
     62     endif
     63 
     64     " Match inside of a block
     65     if s:IsInBlock(v:lnum)
     66         if prevline =~ "^\k\+.*$"
     67             return shiftwidth()
     68         else
     69             return indent(prevlnum)
     70         endif
     71     endif
     72 
     73     return 0 
     74 endfunction
     75 
     76 let &cpo = s:cpo_save
     77 unlet s:cpo_save