Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: Eiffel |
Bram Moolenaar | c873442 | 2012-06-01 22:38:45 +0200 | [diff] [blame] | 3 | " Maintainer: Jocelyn Fiat <jfiat@eiffel.com> |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 4 | " Previous-Maintainer: David Clarke <gadicath@dishevelled.net> |
Bram Moolenaar | c873442 | 2012-06-01 22:38:45 +0200 | [diff] [blame] | 5 | " Contributions from: Thilo Six |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 6 | " $Date: 2004/12/09 21:33:52 $ |
| 7 | " $Revision: 1.3 $ |
Bram Moolenaar | c873442 | 2012-06-01 22:38:45 +0200 | [diff] [blame] | 8 | " URL: https://github.com/eiffelhub/vim-eiffel |
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 | |
Bram Moolenaar | c873442 | 2012-06-01 22:38:45 +0200 | [diff] [blame] | 26 | let b:undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comments< " |
| 27 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 28 | " Define some stuff |
| 29 | " keywords grouped by indenting |
| 30 | let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$' |
| 31 | 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\)\>' |
| 32 | let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>' |
| 33 | let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>' |
| 34 | let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$' |
| 35 | let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>' |
| 36 | |
| 37 | |
| 38 | " Only define the function once. |
| 39 | if exists("*GetEiffelIndent") |
| 40 | finish |
| 41 | endif |
Bram Moolenaar | c873442 | 2012-06-01 22:38:45 +0200 | [diff] [blame] | 42 | |
Bram Moolenaar | 8e52a59 | 2012-05-18 21:49:28 +0200 | [diff] [blame] | 43 | let s:keepcpo= &cpo |
| 44 | set cpo&vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 45 | |
| 46 | function GetEiffelIndent() |
| 47 | |
| 48 | " Eiffel Class indenting |
| 49 | " |
| 50 | " Find a non-blank line above the current line. |
| 51 | let lnum = prevnonblank(v:lnum - 1) |
| 52 | |
| 53 | " At the start of the file use zero indent. |
| 54 | if lnum == 0 |
| 55 | return 0 |
| 56 | endif |
| 57 | |
| 58 | " trust the user's indenting |
| 59 | if getline(lnum) =~ s:trust_user_indent |
| 60 | return -1 |
| 61 | endif |
| 62 | |
| 63 | " Add a 'shiftwidth' after lines that start with an indent word |
| 64 | let ind = indent(lnum) |
| 65 | if getline(lnum) =~ s:relative_indent |
| 66 | let ind = ind + &sw |
| 67 | endif |
| 68 | |
| 69 | " Indent to single indent |
| 70 | if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent |
| 71 | \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>' |
| 72 | let ind = &sw |
| 73 | endif |
| 74 | |
| 75 | " Indent to double indent |
| 76 | if getline(v:lnum) =~ s:inheritance_dent |
| 77 | let ind = 2 * &sw |
| 78 | endif |
| 79 | |
| 80 | " Indent line after the first line of the function definition |
| 81 | if getline(lnum) =~ s:single_dent |
| 82 | let ind = ind + &sw |
| 83 | endif |
| 84 | |
| 85 | " The following should always be at the start of a line, no indenting |
| 86 | if getline(v:lnum) =~ s:no_indent |
| 87 | let ind = 0 |
| 88 | endif |
| 89 | |
| 90 | " Subtract a 'shiftwidth', if this isn't the first thing after the 'is' |
| 91 | " or first thing after the 'do' |
| 92 | if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent |
| 93 | \ && getline(v:lnum - 1) !~ '^\s*do\>' |
| 94 | let ind = ind - &sw |
| 95 | endif |
| 96 | |
| 97 | " Subtract a shiftwidth for end statements |
| 98 | if getline(v:lnum) =~ '^\s*end\>' |
| 99 | let ind = ind - &sw |
| 100 | endif |
| 101 | |
| 102 | " set indent of zero end statements that are at an indent of 3, this should |
| 103 | " only ever be the class's end. |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 104 | if getline(v:lnum) =~ '^\s*end\>' && ind == &sw |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 105 | let ind = 0 |
| 106 | endif |
| 107 | |
| 108 | return ind |
| 109 | endfunction |
| 110 | |
Bram Moolenaar | 8e52a59 | 2012-05-18 21:49:28 +0200 | [diff] [blame] | 111 | let &cpo = s:keepcpo |
| 112 | unlet s:keepcpo |
| 113 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 114 | " vim:sw=2 |