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