Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: Eiffel |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 3 | " Maintainer: Jocelyn Fiat <eiffel@djoce.net> |
| 4 | " Previous-Maintainer: David Clarke <gadicath@dishevelled.net> |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 5 | " $Date: 2004/12/09 21:33:52 $ |
| 6 | " $Revision: 1.3 $ |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 7 | " URL: http://www.djoce.net/page/vim/ |
Bram Moolenaar | 8e52a59 | 2012-05-18 21:49:28 +0200 | [diff] [blame] | 8 | " Last Change: 2012 May 18 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | |
| 10 | " Only load this indent file when no other was loaded. |
| 11 | if exists("b:did_indent") |
| 12 | finish |
| 13 | endif |
| 14 | let b:did_indent = 1 |
| 15 | |
| 16 | setlocal indentexpr=GetEiffelIndent() |
| 17 | setlocal nolisp |
| 18 | setlocal nosmartindent |
| 19 | setlocal nocindent |
| 20 | setlocal autoindent |
| 21 | setlocal comments=:-- |
| 22 | setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until |
| 23 | setlocal indentkeys+==creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant |
| 24 | setlocal indentkeys+==invariant,=do,=local,=export |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 25 | |
| 26 | " Define some stuff |
| 27 | " keywords grouped by indenting |
| 28 | let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$' |
| 29 | let 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\)\>' |
| 30 | let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>' |
| 31 | let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>' |
| 32 | let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$' |
| 33 | let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>' |
| 34 | |
| 35 | |
| 36 | " Only define the function once. |
| 37 | if exists("*GetEiffelIndent") |
| 38 | finish |
| 39 | endif |
Bram Moolenaar | 8e52a59 | 2012-05-18 21:49:28 +0200 | [diff] [blame] | 40 | let s:keepcpo= &cpo |
| 41 | set cpo&vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | |
| 43 | function 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 Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 101 | if getline(v:lnum) =~ '^\s*end\>' && ind == &sw |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 102 | let ind = 0 |
| 103 | endif |
| 104 | |
| 105 | return ind |
| 106 | endfunction |
| 107 | |
Bram Moolenaar | 8e52a59 | 2012-05-18 21:49:28 +0200 | [diff] [blame] | 108 | let &cpo = s:keepcpo |
| 109 | unlet s:keepcpo |
| 110 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 111 | " vim:sw=2 |