Mercurial > vim
annotate runtime/indent/eiffel.vim @ 26196:75bc457099c4
Added tag v8.2.3629 for changeset 41b3718d84c349077ae008b51ce75c8c11e358d5
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 20 Nov 2021 20:15:04 +0100 |
parents | d0a20101ecb2 |
children |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Eiffel | |
3557 | 3 " Maintainer: Jocelyn Fiat <jfiat@eiffel.com> |
26 | 4 " Previous-Maintainer: David Clarke <gadicath@dishevelled.net> |
11160 | 5 " Contributions from: Takuya Fujiwara |
3557 | 6 " Contributions from: Thilo Six |
11160 | 7 " $Date: 2017/03/08 06:00:00 $ |
8 " $Revision: 1.4 $ | |
3557 | 9 " URL: https://github.com/eiffelhub/vim-eiffel |
7 | 10 |
11 " Only load this indent file when no other was loaded. | |
12 if exists("b:did_indent") | |
13 finish | |
14 endif | |
15 let b:did_indent = 1 | |
16 | |
17 setlocal indentexpr=GetEiffelIndent() | |
18 setlocal nolisp | |
19 setlocal nosmartindent | |
20 setlocal nocindent | |
21 setlocal autoindent | |
22 setlocal comments=:-- | |
23 setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until | |
24 setlocal indentkeys+==creation,=feature,=inherit,=class,=is,=redefine,=rename,=variant | |
25 setlocal indentkeys+==invariant,=do,=local,=export | |
26 | |
3557 | 27 let b:undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comments< " |
28 | |
7 | 29 " Define some stuff |
30 " keywords grouped by indenting | |
31 let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$' | |
11160 | 32 let 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\)\>' |
7 | 33 let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>' |
34 let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>' | |
35 let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$' | |
36 let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>' | |
37 | |
38 | |
39 " Only define the function once. | |
40 if exists("*GetEiffelIndent") | |
41 finish | |
42 endif | |
3557 | 43 |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
44 let s:keepcpo= &cpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
45 set cpo&vim |
7 | 46 |
47 function 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 | |
11160 | 67 let ind = ind + shiftwidth() |
7 | 68 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\)\>' | |
11160 | 73 let ind = shiftwidth() |
7 | 74 endif |
75 | |
76 " Indent to double indent | |
77 if getline(v:lnum) =~ s:inheritance_dent | |
11160 | 78 let ind = 2 * shiftwidth() |
7 | 79 endif |
80 | |
81 " Indent line after the first line of the function definition | |
82 if getline(lnum) =~ s:single_dent | |
11160 | 83 let ind = ind + shiftwidth() |
7 | 84 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\>' | |
11160 | 95 let ind = ind - shiftwidth() |
7 | 96 endif |
97 | |
98 " Subtract a shiftwidth for end statements | |
99 if getline(v:lnum) =~ '^\s*end\>' | |
11160 | 100 let ind = ind - shiftwidth() |
7 | 101 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. | |
11160 | 105 if getline(v:lnum) =~ '^\s*end\>' && ind == shiftwidth() |
7 | 106 let ind = 0 |
107 endif | |
108 | |
109 return ind | |
110 endfunction | |
111 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
112 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
113 unlet s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2034
diff
changeset
|
114 |
7 | 115 " vim:sw=2 |