comparison runtime/indent/mma.vim @ 271:8d34af900bae v7.0072

updated for version 7.0072
author vimboss
date Wed, 18 May 2005 22:24:46 +0000
parents
children 8cd729851562
comparison
equal deleted inserted replaced
270:a20218704019 271:8d34af900bae
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
7 "
8 " NOTE:
9 " Empty .m files will automatically be presumed to be Matlab files
10 " unless you have the following in your .vimrc:
11 "
12 " let filetype_m="mma"
13 "
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!
17
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
23
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
27
28 if exists("*GetMmaIndent")
29 finish
30 endif
31
32 function GetMmaIndent()
33
34 " Hit the start of the file, use zero indent.
35 if v:lnum == 0
36 return 0
37 endif
38
39 " Find a non-blank line above the current line.
40 let lnum = prevnonblank(v:lnum - 1)
41
42 " use indenting as a base
43 let ind = indent(v:lnum)
44 let lnum = v:lnum
45
46 " if previous line has an unmatched bracket, or ( indent.
47 " doesn't do multiple parens/blocks/etc...
48
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
54
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'))
66
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
72
73 return ind
74 endfunction
75