codekingpro/portable-devtools
114k
1" Vim indent file2" Language: Eiffel3" Maintainer: Jocelyn Fiat <jfiat@eiffel.com>4" Previous-Maintainer: David Clarke <gadicath@dishevelled.net>5" Contributions from: Takuya Fujiwara6" Contributions from: Thilo Six7" $Date: 2017/03/08 06:00:00 $8" $Revision: 1.4 $9" URL: https://github.com/eiffelhub/vim-eiffel10 11" Only load this indent file when no other was loaded.12if exists("b:did_indent")13 finish14endif15let b:did_indent = 116 17setlocal indentexpr=GetEiffelIndent()18setlocal nolisp19setlocal nosmartindent20setlocal nocindent21setlocal autoindent22setlocal comments=:--23setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until24setlocal indentkeys+==creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant25setlocal indentkeys+==invariant,=do,=local,=export26 27let b:undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comments< "28 29" Define some stuff30" keywords grouped by indenting31let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'32let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|loop\|from\|across\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|local\|invariant\|variant\|rename\|redefine\|do\|export\)\>'33let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>'34let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>'35let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$'36let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>'37 38 39" Only define the function once.40if exists("*GetEiffelIndent")41 finish42endif43 44let s:keepcpo= &cpo45set cpo&vim46 47function GetEiffelIndent()48 49 " Eiffel Class indenting50 "51 " Find a non-blank line above the current line.52 let lnum = prevnonblank(v:lnum - 1)53 54 " At the start of the file use zero indent.55 if lnum == 056 return 057 endif58 59 " trust the user's indenting60 if getline(lnum) =~ s:trust_user_indent61 return -162 endif63 64 " Add a 'shiftwidth' after lines that start with an indent word65 let ind = indent(lnum)66 if getline(lnum) =~ s:relative_indent67 let ind = ind + shiftwidth()68 endif69 70 " Indent to single indent71 if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent72 \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>'73 let ind = shiftwidth()74 endif75 76 " Indent to double indent77 if getline(v:lnum) =~ s:inheritance_dent78 let ind = 2 * shiftwidth()79 endif80 81 " Indent line after the first line of the function definition82 if getline(lnum) =~ s:single_dent83 let ind = ind + shiftwidth()84 endif85 86 " The following should always be at the start of a line, no indenting87 if getline(v:lnum) =~ s:no_indent88 let ind = 089 endif90 91 " Subtract a 'shiftwidth', if this isn't the first thing after the 'is'92 " or first thing after the 'do'93 if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent94 \ && getline(v:lnum - 1) !~ '^\s*do\>'95 let ind = ind - shiftwidth()96 endif97 98 " Subtract a shiftwidth for end statements99 if getline(v:lnum) =~ '^\s*end\>'100 let ind = ind - shiftwidth()101 endif102 103 " set indent of zero end statements that are at an indent of 3, this should104 " only ever be the class's end.105 if getline(v:lnum) =~ '^\s*end\>' && ind == shiftwidth()106 let ind = 0107 endif108 109 return ind110endfunction111 112let &cpo = s:keepcpo113unlet s:keepcpo114 115" vim:sw=2116 