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
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"
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")
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")
32 function GetMmaIndent()
34 " Hit the start of the file, use zero indent.
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)
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\+[\[({]'
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
60 " and find it's partner's indent
61 let ind = indent(searchpair('\[','',']','bWn'))
63 elseif getline(v:lnum) =~ '[^(]*)$'
65 let ind = indent(searchpair('(','',')','bWn'))
67 " and finally, close { blocks if si ain't already set
68 elseif getline(v:lnum) =~ '[^{]*}'
70 let ind = indent(searchpair('{','','}','bWn'))