" Vim indent file, another yet!" Language: Eiffel" Maintainer: Huang Liang <huangl@tfol.net> " Ref Maintainer: Jocelyn Fiat <eiffel@djoce.net>" Previous-Maintainer: David Clarke <gadicath@dishevelled.net>" $Date: 2006/12/28 21:33:52 $" $Revision: 1.0 $" URL: http://www.djoce.net/page/vim/" Last Change: 2006 dec 28 : rewrite the indent rule" Only load this indent file when no other was loaded.if exists("b:did_indent") "finishendiflet b:did_indent = 2setlocal indentexpr=GetEiffelIndent()setlocal nolispsetlocal nosmartindentsetlocal nocindentsetlocal autoindentsetlocal comments=:--setlocal indentkeys=osetlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=untilsetlocal indentkeys+==creation,=feature,=inherit,=insert, =class,=is,=redefine,=rename,=variantsetlocal indentkeys+==invariant,=do,=local,=export,=indexing" Define some stuff" keywords grouped by indentinglet s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|insert\|loop\|from\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|once\|external\|alias\|local\|invariant\|variant\|rename\|redefine\|export\)\>'let s:outdent = '^\s*\(else\|invariant\|variant\|do\|once\|external\|alias\|require\|ensure\|until\|loop\|local\)\>'let s:no_indent = '^\s*\(\(\(\w\+ \)\?class\)\|feature\|creation\|inherit\|insert\|indexing\)\>'let s:single_dent = '.*is\s*\(--.*\)\=$'let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>'" Only define the function once.if exists("*GetEiffelIndent") "finishendiffunction! s:GetPrevNonCommentLineNum( line_num ) " Skip lines starting with a comment let SKIP_LINES = '^\s*--.*$' let nline = a:line_num while nline > 0 let nline = prevnonblank(nline-1) if getline(nline) !~? SKIP_LINES break endif endwhile return nlineendfunctionfunction! GetEiffelIndent() " Eiffel Class indenting " " if v:lnum == 0 return 0 endif let this_codeline = getline( v:lnum) " The following should always be at the start of a line, no indenting " Section word : class, feature, creation, inherit, insert, create, indexing if this_codeline =~ s:no_indent return 0 endif " Indent to single indent if this_codeline =~ s:single_dent && this_codeline !~ '\s*\<\(and\|or\|implies\)\>' return &sw endif " Indent to double indent if this_codeline =~ s:inheritance_dent return 2 * &sw endif " Find a non-blank/non-comment line above the current line. let prev_codeline_num = s:GetPrevNonCommentLineNum(v:lnum) let prev_codeline = getline(prev_codeline_num) let ind = indent(prev_codeline_num) if this_codeline =~ s:outdent if prev_codeline =~ s:single_dent return 2 * &sw endif " Subtract a 'shiftwidth', if this isn't the first thing after the 'is' " or first thing after the 'do' if prev_codeline !~ '^\s*do\>' && prev_codeline !~ s:relative_indent return ind - &sw endif return ind endif " Subtract a shiftwidth for end "statements if this_codeline =~ '^\s*end\>' let this_ind = indent(v:lnum) if this_ind > &sw return ind - &sw else return this_ind endif endif " Indent line after the first line of the function definition if prev_codeline =~ s:single_dent return ind + 2 * &sw endif " Add a 'shiftwidth' after lines that start with an indent word if prev_codeline =~ s:relative_indent return ind + &sw endif if prev_codeline =~ s:no_indent return &sw endif return ind " trust the user's indenting "if prev_codeline =~ s:trust_user_indent " return -1 "endifendfunction" vim:sw=2

评论