" Vim indent file " Language: Netcool Probe Rules File " Maintainer: Scott R. Keszler " Info: $Id$ " URL: http://srkconsulting.com/netcool_vim " Anon SVN: $HeadURL$ " Release Coordinator: Scott R. Keszler " ---------------------------------------------------------------------------- " " Rules file indenting is fairly simple: " Indent after any '{' not inside a string $(variable), or comment " Outdent on any '}' that is the first non-whitespace character on the line " Indent after a case keyword " Outdent 2nd+ case keywords, indent after " Outdent the default case keyword, indent after " Outdent the '}' ending a switch statement to the switch's level " obligatory opening if exists("b:did_indent") finish endif let b:did_indent = 1 setlocal indentexpr=GetRulesIndent() setlocal indentkeys={,},0#,!^F,o,O,<:> if exists("*GetRulesIndent") finish endif let s:cpo_save = &cpo set cpo&vim function GetRulesIndent() " Get the line to be indented let cline = getline(v:lnum) " Don't reindent coments on first column if cline =~ '^#' return 0 endif " Get the indent of the previous line. " Find a non-blank, non-^#-comment line above the current line. let pnum = prevnonblank(v:lnum - 1) " Hit the start of the file, use zero indent. if pnum == 0 return 0 endif " Skip comments on 1st column let skippin = 1 while skippin if (getline(pnum) =~ '^#') let pnum = prevnonblank(pnum - 1) if pnum == 0 return 0 endif else let skippin = 0 endif endwhile let pline = getline(pnum) let dent = indent(pnum) " Indent blocks enclosed by {} " opening { must be the last thing on the line, except comments if pline =~ '^[^#]*{\s*\%(#.*\)\=$' let dent += &sw endif " closing } must be the first non-whitespace character on the line if cline =~ '^\s*}' let dent -= &sw " are we closing a switch? " move cursor back to the close_brace call cursor(line('.'),col('.') - 1) " find the matching open_brace let mnum = searchpair('{','','}','bW',"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment\\|string'") if mnum > 0 if getline(mnum) =~ 'switch\s*([^()]*)\s*{' || getline(mnum - 1) =~ 'switch\s*([^()]*)\s*\%(#.*\)\=$' " yes, closing a switch, so outdent again let dent = indent(mnum) return dent endif else endif endif " Add a shiftwidth after case and case default if pline =~ '^\s*\(case\s\+"[^"]*"\s*:\|default\s*:\)\c' let dent += &sw endif " Subtract a shiftwidth on case and case default lines if cline =~ '^\s*\(case\s\+"[^"]*"\s*:\|default\s*:\)\c' " if this is the first case statment, don't outdent if pline !~ '{\s*\%(#.*\)\=$' let dent -= &sw endif endif return dent endfunction let &cpo = s:cpo_save unlet s:cpo_save " vi: ts=8 sw=3 et: