| 
									
										
										
										
											2005-09-25 22:16:38 +00:00
										 |  |  | " Vim indent file | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | " Language:		eRuby | 
					
						
							|  |  |  | " Maintainer:		Tim Pope <vimNOSPAM@tpope.info> | 
					
						
							| 
									
										
										
										
											2006-04-15 20:25:09 +00:00
										 |  |  | " Info:			$Id$ | 
					
						
							|  |  |  | " URL:			http://vim-ruby.rubyforge.org | 
					
						
							|  |  |  | " Anon CVS:		See above site | 
					
						
							|  |  |  | " Release Coordinator:	Doug Kearns <dougkearns@gmail.com> | 
					
						
							| 
									
										
										
										
											2005-09-25 22:16:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | runtime! indent/ruby.vim | 
					
						
							|  |  |  | unlet! b:did_indent | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  | setlocal indentexpr= | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  | if exists("b:eruby_subtype") | 
					
						
							|  |  |  |   exe "runtime! indent/".b:eruby_subtype.".vim" | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   runtime! indent/html.vim | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | unlet! b:did_indent | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  | if &l:indentexpr == '' | 
					
						
							|  |  |  |   if &l:cindent | 
					
						
							|  |  |  |     let &l:indentexpr = 'cindent(v:lnum)' | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))' | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | let b:eruby_subtype_indentexpr = &l:indentexpr | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  | setlocal indentexpr=GetErubyIndent() | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Only define the function once. | 
					
						
							|  |  |  | if exists("*GetErubyIndent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  | function! GetErubyIndent(...) | 
					
						
							|  |  |  |   if a:0 && a:1 == '.' | 
					
						
							|  |  |  |     let v:lnum = line('.') | 
					
						
							|  |  |  |   elseif a:0 && a:1 =~ '^\d' | 
					
						
							|  |  |  |     let v:lnum = a:1 | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   let vcol = col('.') | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  |   call cursor(v:lnum,1) | 
					
						
							| 
									
										
										
										
											2008-06-24 21:16:56 +00:00
										 |  |  |   let inruby = searchpair('<%','','%>','W') | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  |   call cursor(v:lnum,vcol) | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |   if inruby && getline(v:lnum) !~ '^<%\|^\s*-\=%>' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |     let ind = GetRubyIndent() | 
					
						
							|  |  |  |   else | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  |     exe "let ind = ".b:eruby_subtype_indentexpr | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  |   let lnum = prevnonblank(v:lnum-1) | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   let line = getline(lnum) | 
					
						
							| 
									
										
										
										
											2007-05-10 17:26:28 +00:00
										 |  |  |   let cline = getline(v:lnum) | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |   if cline =~# '<%-\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |     let ind = ind - &sw | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |   if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*-\=%>' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |     let ind = ind + &sw | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |   elseif line =~# '<%-\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |     let ind = ind + &sw | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |   if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |     let ind = ind + &sw | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if cline =~# '^\s*-\=%>\s*$' | 
					
						
							|  |  |  |     let ind = ind - &sw | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   return ind | 
					
						
							|  |  |  | endfunction | 
					
						
							| 
									
										
										
										
											2006-04-15 20:25:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:16:56 +00:00
										 |  |  | " vim:set sw=2 sts=2 ts=8 noet: |