1" Vim indent file
2" Language:	Eiffel
3" Maintainer:	Jocelyn Fiat <eiffel@djoce.net>
4" Previous-Maintainer:	David Clarke <gadicath@dishevelled.net>
5" $Date: 2004/12/09 21:33:52 $
6" $Revision: 1.3 $
7" URL: http://www.djoce.net/page/vim/
8" Last Change:	2004 Sept 14 : removed specific value for tab (sw)
9
10" Only load this indent file when no other was loaded.
11if exists("b:did_indent")
12  finish
13endif
14let b:did_indent = 1
15
16setlocal indentexpr=GetEiffelIndent()
17setlocal nolisp
18setlocal nosmartindent
19setlocal nocindent
20setlocal autoindent
21setlocal comments=:--
22setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until
23setlocal indentkeys+==creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant
24setlocal indentkeys+==invariant,=do,=local,=export
25
26" Define some stuff
27" keywords grouped by indenting
28let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'
29let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|loop\|from\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|local\|invariant\|variant\|rename\|redefine\|do\|export\)\>'
30let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>'
31let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>'
32let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$'
33let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>'
34
35
36" Only define the function once.
37if exists("*GetEiffelIndent")
38  finish
39endif
40
41function GetEiffelIndent()
42
43  " Eiffel Class indenting
44  "
45  " Find a non-blank line above the current line.
46  let lnum = prevnonblank(v:lnum - 1)
47
48  " At the start of the file use zero indent.
49  if lnum == 0
50    return 0
51  endif
52
53  " trust the user's indenting
54  if getline(lnum) =~ s:trust_user_indent
55    return -1
56  endif
57
58  " Add a 'shiftwidth' after lines that start with an indent word
59  let ind = indent(lnum)
60  if getline(lnum) =~ s:relative_indent
61    let ind = ind + &sw
62  endif
63
64  " Indent to single indent
65  if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent
66	   \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>'
67     let ind = &sw
68  endif
69
70  " Indent to double indent
71  if getline(v:lnum) =~ s:inheritance_dent
72     let ind = 2 * &sw
73  endif
74
75  " Indent line after the first line of the function definition
76  if getline(lnum) =~ s:single_dent
77     let ind = ind + &sw
78  endif
79
80  " The following should always be at the start of a line, no indenting
81  if getline(v:lnum) =~ s:no_indent
82     let ind = 0
83  endif
84
85  " Subtract a 'shiftwidth', if this isn't the first thing after the 'is'
86  " or first thing after the 'do'
87  if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent
88	\ && getline(v:lnum - 1) !~ '^\s*do\>'
89    let ind = ind - &sw
90  endif
91
92  " Subtract a shiftwidth for end statements
93  if getline(v:lnum) =~ '^\s*end\>'
94    let ind = ind - &sw
95  endif
96
97  " set indent of zero end statements that are at an indent of 3, this should
98  " only ever be the class's end.
99  if getline(v:lnum) =~ '^\s*end\>' && ind == &sw
100    let ind = 0
101  endif
102
103  return ind
104endfunction
105
106" vim:sw=2
107