blob: d7667a8346d66a0a1fdb27af1b7668a031f962a0 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: Eiffel
Bram Moolenaarc8734422012-06-01 22:38:45 +02003" Maintainer: Jocelyn Fiat <jfiat@eiffel.com>
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00004" Previous-Maintainer: David Clarke <gadicath@dishevelled.net>
Bram Moolenaar036986f2017-03-16 17:41:02 +01005" Contributions from: Takuya Fujiwara
Bram Moolenaarc8734422012-06-01 22:38:45 +02006" Contributions from: Thilo Six
Bram Moolenaar036986f2017-03-16 17:41:02 +01007" $Date: 2017/03/08 06:00:00 $
8" $Revision: 1.4 $
Bram Moolenaarc8734422012-06-01 22:38:45 +02009" URL: https://github.com/eiffelhub/vim-eiffel
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
11" Only load this indent file when no other was loaded.
12if exists("b:did_indent")
13 finish
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
Bram Moolenaar071d4272004-06-13 20:20:40 +000026
Bram Moolenaarc8734422012-06-01 22:38:45 +020027let b:undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comments< "
28
Bram Moolenaar071d4272004-06-13 20:20:40 +000029" Define some stuff
30" keywords grouped by indenting
31let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'
Bram Moolenaar036986f2017-03-16 17:41:02 +010032let 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\)\>'
Bram Moolenaar071d4272004-06-13 20:20:40 +000033let 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 finish
42endif
Bram Moolenaarc8734422012-06-01 22:38:45 +020043
Bram Moolenaar8e52a592012-05-18 21:49:28 +020044let s:keepcpo= &cpo
45set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000046
47function GetEiffelIndent()
48
49 " Eiffel Class indenting
50 "
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 == 0
56 return 0
57 endif
58
59 " trust the user's indenting
60 if getline(lnum) =~ s:trust_user_indent
61 return -1
62 endif
63
64 " Add a 'shiftwidth' after lines that start with an indent word
65 let ind = indent(lnum)
66 if getline(lnum) =~ s:relative_indent
Bram Moolenaar036986f2017-03-16 17:41:02 +010067 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 endif
69
70 " Indent to single indent
71 if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent
72 \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>'
Bram Moolenaar036986f2017-03-16 17:41:02 +010073 let ind = shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000074 endif
75
76 " Indent to double indent
77 if getline(v:lnum) =~ s:inheritance_dent
Bram Moolenaar036986f2017-03-16 17:41:02 +010078 let ind = 2 * shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000079 endif
80
81 " Indent line after the first line of the function definition
82 if getline(lnum) =~ s:single_dent
Bram Moolenaar036986f2017-03-16 17:41:02 +010083 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000084 endif
85
86 " The following should always be at the start of a line, no indenting
87 if getline(v:lnum) =~ s:no_indent
88 let ind = 0
89 endif
90
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_dent
94 \ && getline(v:lnum - 1) !~ '^\s*do\>'
Bram Moolenaar036986f2017-03-16 17:41:02 +010095 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000096 endif
97
98 " Subtract a shiftwidth for end statements
99 if getline(v:lnum) =~ '^\s*end\>'
Bram Moolenaar036986f2017-03-16 17:41:02 +0100100 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101 endif
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.
Bram Moolenaar036986f2017-03-16 17:41:02 +0100105 if getline(v:lnum) =~ '^\s*end\>' && ind == shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106 let ind = 0
107 endif
108
109 return ind
110endfunction
111
Bram Moolenaar8e52a592012-05-18 21:49:28 +0200112let &cpo = s:keepcpo
113unlet s:keepcpo
114
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115" vim:sw=2