robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ad527392ab
master
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. 7if exists ( "b:did_indent" ) 8finish 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" ) 19finish 20endif 21 22let s: cpo_save = & cpo 23set cpo & vim 24 25let s: syn_blocks = '\<SnortRuleTypeBody\>' 26 27function s: IsInBlock ( lnum ) 28return synIDattr ( synID ( a: lnum , 1 , 1 ), 'name' ) =~ s: syn_blocks 29endfunction 30 31function GetHogIndent () 32let prevlnum = prevnonblank ( v: lnum - 1 ) 33 34" Comment blocks have identical indent 35if getline ( v: lnum ) =~ '^\s*#' && getline ( prevlnum ) =~ '^\s*#' 36return indent ( prevlnum ) 37endif 38 39" Ignore comment lines when calculating indent 40while getline ( prevlnum ) =~ '^\s*#' 41let prevlnum = prevnonblank ( prevlnum - 1 ) 42if ! prevlnum 43return previndent 44endif 45endwhile 46 47" Continuation of a line that wasn't indented 48let prevline = getline ( prevlnum ) 49if prevline =~ '^\k\+.*\\\s*$' 50return shiftwidth () 51endif 52 53" Continuation of a line that was indented 54if prevline =~ '\k\+.*\\\s*$' 55return indent ( prevlnum ) 56endif 57 58" Indent the next line if previous line contained a start of a block 59" definition ('{' or '('). 60if prevline =~ '^\k\+[^#]*{}\@!\s*$' " TODO || prevline =~ '^\k\+[^#]*()\@!\s*$' 61return shiftwidth () 62endif 63 64" Match inside of a block 65if s: IsInBlock ( v: lnum ) 66if prevline =~ "^\k\+.*$" 67return shiftwidth () 68else 69return indent ( prevlnum ) 70endif 71endif 72 73return 0 74endfunction 75 76let & cpo = s: cpo_save 77unlet s: cpo_save