0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
vim/runtime/indent/eruby.vim

74 lines
1.8 KiB
VimL
Raw Normal View History

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
2007-05-10 17:26:28 +00:00
set 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
2007-05-10 17:26:28 +00:00
function! GetErubyIndent()
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)
if inruby && getline(v:lnum) !~ '^<%'
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)
2007-05-05 17:54:07 +00:00
if cline =~# '<%\s*\%(end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
let ind = ind - &sw
endif
if line =~# '\<do\%(\s*|[^|]*|\)\=\s*-\=%>'
let ind = ind + &sw
elseif line =~# '<%\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
let ind = ind + &sw
endif
if line =~# '^\s*<%[=#]\=\s*$' && cline !~# '^\s*end\>'
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: