Merge branch 'vim-with-runtime' into feat/quickfix-title
[vim_extended.git] / runtime / indent / matlab.vim
blob7bccc7c0a7f2476ef296726cb0011e96b9d1ef6c
1 " Matlab indent file
2 " Language:     Matlab
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")
8   finish
9 endif
10 let b:did_indent = 1
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")
20   finish
21 endif
23 function GetMatlabIndent(lnum)
24   " Give up if this line is explicitly joined.
25   if getline(a:lnum - 1) =~ '\\$'
26     return -1
27   endif
29   " Search backwards for the first non-empty line.
30   let plnum = a:lnum - 1
31   while plnum > 0 && getline(plnum) =~ '^\s*$'
32     let plnum = plnum - 1
33   endwhile
35   if plnum == 0
36     " This is the first non-empty line, use zero indent.
37     return 0
38   endif
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
50     else
51       " Otherwise, trust the user
52       return -1
53     endif
54 "  endif
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
62     else
63       " Otherwise, trust the user
64       return -1
65     endif
66   endif
70   " If we got to here, it means that the user takes the standardversion, so we return it
71   return curind
72 endfunction
74 " vim:sw=2