annotate runtime/indent/mma.vim @ 6847:18ec2c5a5ce7 v7.4.744

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