3 " Maintainer: Jean Privat <jean@pryen.org>
5 " This file is part of NIT ( http://www.nitlanguage.org ).
7 " Copyright 2009 Jean Privat <jean@pryen.org>
9 " Licensed under the Apache License, Version 2.0 (the "License");
10 " you may not use this file except in compliance with the License.
11 " You may obtain a copy of the License at
13 " http://www.apache.org/licenses/LICENSE-2.0
15 " Unless required by applicable law or agreed to in writing, software
16 " distributed under the License is distributed on an "AS IS" BASIS,
17 " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 " See the License for the specific language governing permissions and
19 " limitations under the License.
21 " Only load this indent file when no other was loaded.
22 if exists("b:did_indent")
27 setlocal indentexpr=GetNITIndent()
29 setlocal nosmartindent
33 setlocal indentkeys+==end,=else,=do,=var,=with,=then,=special,=class,=interface,=universal
37 let s:relative_indent = '\<\(do\|then\|else\|if\)\s*$\|^\s*\(\<\(redef\|private\)\>\s*\)\?\(\<abstract\>\s*\)\?\<\(class\|interface\|universal\|special\)\>'
39 let s:outdent = '^\s*\(else\|then\|with\|end\)\>'
41 let s:no_indent = '^\s*\(class\|import\|special\)\>'
43 " Only define the function once.
44 if exists("*GetNITIndent")
48 function GetNITIndent()
49 " Find a non-blank line above the current line.
50 let lnum = prevnonblank(v:lnum - 1)
52 " At the start of the file use zero indent.
57 let cline = getline(v:lnum) " The line to indent
58 let prevline=getline(lnum) " The previous nonempty line
59 let ind = indent(lnum) " The previous nonempty indent level
61 " Add a 'shiftwidth' after lines that start with an indent word
62 if prevline =~ s:relative_indent
66 " Subtract a 'shiftwidth', for lines that start with an outdent word
71 " The following should always be at the start of a line, no indenting
72 if cline =~ s:no_indent
76 " Subtract a shiftwidth for end statements
77 if prevline =~ '$\s*end\s*\(#|$\)'