robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
946c2a8ee8
master
1" Vim indent file 2" Language: Eiffel 3" Maintainer: Jocelyn Fiat <jfiat@eiffel.com> 4" Previous-Maintainer: David Clarke <gadicath@dishevelled.net> 5" Contributions from: Takuya Fujiwara 6" Contributions from: Thilo Six 7" $Date: 2017/03/08 06:00:00 $ 8" $Revision: 1.4 $ 9" URL: https://github.com/eiffelhub/vim-eiffel 10 11" Only load this indent file when no other was loaded. 12if exists ( "b:did_indent" ) 13finish 14endif 15let b: did_indent = 1 16 17setlocal indentexpr = GetEiffelIndent () 18setlocal nolisp 19setlocal nosmartindent 20setlocal nocindent 21setlocal autoindent 22setlocal comments = :-- 23setlocal indentkeys += =end,=else,=ensure,=require,=check,=loop,=until 24setlocal indentkeys += =creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant 25setlocal indentkeys += =invariant,=do,=local,=export 26 27let b: undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comments< " 28 29" Define some stuff 30" keywords grouped by indenting 31let 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" ) 41finish 42endif 43 44let s: keepcpo = & cpo 45set cpo & vim 46 47function GetEiffelIndent () 48 49" Eiffel Class indenting 50" 51" Find a non-blank line above the current line. 52let lnum = prevnonblank ( v: lnum - 1 ) 53 54" At the start of the file use zero indent. 55if lnum == 0 56return 0 57endif 58 59" trust the user's indenting 60if getline ( lnum ) =~ s: trust_user_indent 61return -1 62endif 63 64" Add a 'shiftwidth' after lines that start with an indent word 65let ind = indent ( lnum ) 66if getline ( lnum ) =~ s: relative_indent 67let ind = ind + shiftwidth () 68endif 69 70" Indent to single indent 71if getline ( v: lnum ) =~ s: single_dent && getline ( v: lnum ) !~ s: relative_indent 72 \&& getline ( v: lnum ) !~ '\s*\<\(and\|or\|implies\)\>' 73let ind = shiftwidth () 74endif 75 76" Indent to double indent 77if getline ( v: lnum ) =~ s: inheritance_dent 78let ind = 2 * shiftwidth () 79endif 80 81" Indent line after the first line of the function definition 82if getline ( lnum ) =~ s: single_dent 83let ind = ind + shiftwidth () 84endif 85 86" The following should always be at the start of a line, no indenting 87if getline ( v: lnum ) =~ s: no_indent 88let ind = 0 89endif 90 91" Subtract a 'shiftwidth', if this isn't the first thing after the 'is' 92" or first thing after the 'do' 93if getline ( v: lnum ) =~ s: outdent && getline ( v: lnum - 1 ) !~ s: single_dent 94 \&& getline ( v: lnum - 1 ) !~ '^\s*do\>' 95let ind = ind - shiftwidth () 96endif 97 98" Subtract a shiftwidth for end statements 99if getline ( v: lnum ) =~ '^\s*end\>' 100let ind = ind - shiftwidth () 101endif 102 103" set indent of zero end statements that are at an indent of 3, this should 104" only ever be the class's end. 105if getline ( v: lnum ) =~ '^\s*end\>' && ind == shiftwidth () 106let ind = 0 107endif 108 109return ind 110endfunction 111 112let & cpo = s: keepcpo 113unlet s: keepcpo 114 115" vim:sw=2