blob: 472665275b1bb3b224be82523477e1c63fdbb0ff [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: Eiffel
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003" Maintainer: Jocelyn Fiat <eiffel@djoce.net>
4" Previous-Maintainer: David Clarke <gadicath@dishevelled.net>
Bram Moolenaar5c736222010-01-06 20:54:52 +01005" $Date: 2004/12/09 21:33:52 $
6" $Revision: 1.3 $
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00007" URL: http://www.djoce.net/page/vim/
Bram Moolenaar8e52a592012-05-18 21:49:28 +02008" Last Change: 2012 May 18
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
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
Bram Moolenaar071d4272004-06-13 20:20:40 +000025
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
Bram Moolenaar8e52a592012-05-18 21:49:28 +020040let s:keepcpo= &cpo
41set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
43function GetEiffelIndent()
44
45 " Eiffel Class indenting
46 "
47 " Find a non-blank line above the current line.
48 let lnum = prevnonblank(v:lnum - 1)
49
50 " At the start of the file use zero indent.
51 if lnum == 0
52 return 0
53 endif
54
55 " trust the user's indenting
56 if getline(lnum) =~ s:trust_user_indent
57 return -1
58 endif
59
60 " Add a 'shiftwidth' after lines that start with an indent word
61 let ind = indent(lnum)
62 if getline(lnum) =~ s:relative_indent
63 let ind = ind + &sw
64 endif
65
66 " Indent to single indent
67 if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent
68 \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>'
69 let ind = &sw
70 endif
71
72 " Indent to double indent
73 if getline(v:lnum) =~ s:inheritance_dent
74 let ind = 2 * &sw
75 endif
76
77 " Indent line after the first line of the function definition
78 if getline(lnum) =~ s:single_dent
79 let ind = ind + &sw
80 endif
81
82 " The following should always be at the start of a line, no indenting
83 if getline(v:lnum) =~ s:no_indent
84 let ind = 0
85 endif
86
87 " Subtract a 'shiftwidth', if this isn't the first thing after the 'is'
88 " or first thing after the 'do'
89 if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent
90 \ && getline(v:lnum - 1) !~ '^\s*do\>'
91 let ind = ind - &sw
92 endif
93
94 " Subtract a shiftwidth for end statements
95 if getline(v:lnum) =~ '^\s*end\>'
96 let ind = ind - &sw
97 endif
98
99 " set indent of zero end statements that are at an indent of 3, this should
100 " only ever be the class's end.
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +0000101 if getline(v:lnum) =~ '^\s*end\>' && ind == &sw
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102 let ind = 0
103 endif
104
105 return ind
106endfunction
107
Bram Moolenaar8e52a592012-05-18 21:49:28 +0200108let &cpo = s:keepcpo
109unlet s:keepcpo
110
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111" vim:sw=2