3 " Maintainer: Christophe Poucet <christophe.poucet@pandora.be>
4 " Last Change: 6 January, 2001
6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent")
12 " Some preliminary setting
13 setlocal indentkeys=!
\x06,o,O=end,=case,=else,=elseif,=otherwise,=catch
16 setlocal indentexpr=GetMatlabIndent(v:lnum)
18 " Only define the function once.
19 if exists("*GetMatlabIndent")
23 function GetMatlabIndent(lnum)
24 " Give up if this line is explicitly joined.
25 if getline(a:lnum - 1) =~ '\\$'
29 " Search backwards for the first non-empty line.
30 let plnum = a:lnum - 1
31 while plnum > 0 && getline(plnum) =~ '^\s*$'
36 " This is the first non-empty line, use zero indent.
40 let curind = indent(plnum)
42 " If the current line is a stop-block statement...
43 if getline(v:lnum) =~ '^\s*\(end\|else\|elseif\|case\|otherwise\|catch\)\>'
44 " See if this line does not follow the line right after an openblock
45 if getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
46 " See if the user has already dedented
47 elseif indent(v:lnum) > curind - &sw
48 " If not, recommend one dedent
49 let curind = curind - &sw
51 " Otherwise, trust the user
56 " If the previous line opened a block
57 elseif getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
58 " See if the user has already indented
59 if indent(v:lnum) < curind + &sw
60 "If not, recommend indent
61 let curind = curind + &sw
63 " Otherwise, trust the user
70 " If we got to here, it means that the user takes the standardversion, so we return it