annotate runtime/indent/eruby.vim @ 1668:0b796e045c42 v7.2b.000

updated for version 7.2b-000
author vimboss
date Sun, 13 Jul 2008 17:41:49 +0000
parents 73fe8baea242
children 7bc41231fbc7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents:
diff changeset
1 " Vim indent file
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
2 " Language: eRuby
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.info>
831
f24a95dae8ee updated for version 7.0d05
vimboss
parents: 557
diff changeset
4 " Info: $Id$
f24a95dae8ee updated for version 7.0d05
vimboss
parents: 557
diff changeset
5 " URL: http://vim-ruby.rubyforge.org
f24a95dae8ee updated for version 7.0d05
vimboss
parents: 557
diff changeset
6 " Anon CVS: See above site
f24a95dae8ee updated for version 7.0d05
vimboss
parents: 557
diff changeset
7 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents:
diff changeset
8
7052f11a3dc9 updated for version 7.0150
vimboss
parents:
diff changeset
9 if exists("b:did_indent")
7052f11a3dc9 updated for version 7.0150
vimboss
parents:
diff changeset
10 finish
7052f11a3dc9 updated for version 7.0150
vimboss
parents:
diff changeset
11 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents:
diff changeset
12
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
13 runtime! indent/ruby.vim
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
14 unlet! b:did_indent
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
15 setlocal indentexpr=
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
16
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
17 if exists("b:eruby_subtype")
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
18 exe "runtime! indent/".b:eruby_subtype.".vim"
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
19 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
20 runtime! indent/html.vim
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
21 endif
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
22 unlet! b:did_indent
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
23
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
24 if &l:indentexpr == ''
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
25 if &l:cindent
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
26 let &l:indentexpr = 'cindent(v:lnum)'
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
27 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
28 let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
29 endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
30 endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
31 let b:eruby_subtype_indentexpr = &l:indentexpr
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
32
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
33 let b:did_indent = 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
34
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
35 setlocal indentexpr=GetErubyIndent()
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
36 setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
37
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
38 " Only define the function once.
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
39 if exists("*GetErubyIndent")
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
40 finish
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
41 endif
831
f24a95dae8ee updated for version 7.0d05
vimboss
parents: 557
diff changeset
42
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
43 function! GetErubyIndent(...)
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
44 if a:0 && a:1 == '.'
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
45 let v:lnum = line('.')
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
46 elseif a:0 && a:1 =~ '^\d'
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
47 let v:lnum = a:1
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
48 endif
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
49 let vcol = col('.')
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
50 call cursor(v:lnum,1)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1200
diff changeset
51 let inruby = searchpair('<%','','%>','W')
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
52 call cursor(v:lnum,vcol)
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
53 if inruby && getline(v:lnum) !~ '^<%\|^\s*-\=%>'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
54 let ind = GetRubyIndent()
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
55 else
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
56 exe "let ind = ".b:eruby_subtype_indentexpr
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
57 endif
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
58 let lnum = prevnonblank(v:lnum-1)
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
59 let line = getline(lnum)
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 1121
diff changeset
60 let cline = getline(v:lnum)
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
61 if cline =~# '<%-\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
62 let ind = ind - &sw
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
63 endif
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
64 if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*-\=%>'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
65 let ind = ind + &sw
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
66 elseif line =~# '<%-\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
67 let ind = ind + &sw
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
68 endif
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1620
diff changeset
69 if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
70 let ind = ind + &sw
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
71 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
72 if cline =~# '^\s*-\=%>\s*$'
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
73 let ind = ind - &sw
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
74 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
75 return ind
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
76 endfunction
e63691e7c504 updated for version 7.1a
vimboss
parents: 831
diff changeset
77
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1200
diff changeset
78 " vim:set sw=2 sts=2 ts=8 noet: