Install vim73
[msysgit/mtrensch.git] / share / vim / vim73 / indent / mma.vim
blob356b87618d8f9bf121847e3cec674f67693b7e56
1 " Vim indent file
2 " Language:     Mathematica
3 " Author:       steve layland <layland@wolfram.com>
4 " Last Change:  Sat May  10 18:56:22 CDT 2005
5 " Source:       http://vim.sourceforge.net/scripts/script.php?script_id=1274
6 "               http://members.wolfram.com/layland/vim/indent/mma.vim
8 " NOTE:
9 " Empty .m files will automatically be presumed to be Matlab files
10 " unless you have the following in your .vimrc:
12 "       let filetype_m="mma"
14 " Credits:
15 " o steve hacked this out of a random indent file in the Vim 6.1
16 "   distribution that he no longer remembers...sh.vim?  Thanks!
18 " Only load this indent file when no other was loaded.
19 if exists("b:did_indent")
20     finish
21 endif
22 let b:did_indent = 1
24 setlocal indentexpr=GetMmaIndent()
25 setlocal indentkeys+=0[,0],0(,0)
26 setlocal nosi "turn off smart indent so we don't over analyze } blocks
28 if exists("*GetMmaIndent")
29     finish
30 endif
32 function GetMmaIndent()
34     " Hit the start of the file, use zero indent.
35     if v:lnum == 0
36         return 0
37     endif
39      " Find a non-blank line above the current line.
40     let lnum = prevnonblank(v:lnum - 1)
42     " use indenting as a base
43     let ind = indent(v:lnum)
44     let lnum = v:lnum
46     " if previous line has an unmatched bracket, or ( indent.
47     " doesn't do multiple parens/blocks/etc...
49     " also, indent only if this line if this line isn't starting a new
50     " block... TODO - fix this with indentkeys?
51     if getline(v:lnum-1) =~ '\\\@<!\%(\[[^\]]*\|([^)]*\|{[^}]*\)$' && getline(v:lnum) !~ '\s\+[\[({]'
52         let ind = ind+&sw
53     endif
55     " if this line had unmatched closing block,
56     " indent to the matching opening block
57     if getline(v:lnum) =~ '[^[]*]\s*$'
58         " move to the closing bracket
59         call search(']','bW')
60         " and find it's partner's indent
61         let ind = indent(searchpair('\[','',']','bWn'))
62     " same for ( blocks
63     elseif getline(v:lnum) =~ '[^(]*)$'
64         call search(')','bW')
65         let ind = indent(searchpair('(','',')','bWn'))
67     " and finally, close { blocks if si ain't already set
68     elseif getline(v:lnum) =~ '[^{]*}'
69         call search('}','bW')
70         let ind = indent(searchpair('{','','}','bWn'))
71     endif
73     return ind
74 endfunction