Mercurial > hg > RemoteEditor > vim7
comparison runtime/indent/matlab.vim @ 0:76efa0be13f1
Initial revision
author | atsuki |
---|---|
date | Sat, 10 Nov 2007 15:07:22 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76efa0be13f1 |
---|---|
1 " Matlab indent file | |
2 " Language: Matlab | |
3 " Maintainer: Christophe Poucet <christophe.poucet@pandora.be> | |
4 " Last Change: 6 January, 2001 | |
5 | |
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 | |
11 | |
12 " Some preliminary setting | |
13 setlocal indentkeys=!,o,O=end,=case,=else,=elseif,=otherwise,=catch | |
14 | |
15 | |
16 setlocal indentexpr=GetMatlabIndent(v:lnum) | |
17 | |
18 " Only define the function once. | |
19 if exists("*GetMatlabIndent") | |
20 finish | |
21 endif | |
22 | |
23 function GetMatlabIndent(lnum) | |
24 " Give up if this line is explicitly joined. | |
25 if getline(a:lnum - 1) =~ '\\$' | |
26 return -1 | |
27 endif | |
28 | |
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 | |
34 | |
35 if plnum == 0 | |
36 " This is the first non-empty line, use zero indent. | |
37 return 0 | |
38 endif | |
39 | |
40 let curind = indent(plnum) | |
41 | |
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 | |
55 | |
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 | |
67 | |
68 | |
69 | |
70 " If we got to here, it means that the user takes the standardversion, so we return it | |
71 return curind | |
72 endfunction | |
73 | |
74 " vim:sw=2 |