home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / indent / eruby.vim < prev    next >
Encoding:
Text File  |  2010-08-15  |  2.1 KB  |  82 lines

  1. " Vim indent file
  2. " Language:        eRuby
  3. " Maintainer:        Tim Pope <vimNOSPAM@tpope.org>
  4. " Last Change:        2010 May 28
  5. " URL:            http://vim-ruby.rubyforge.org
  6. " Anon CVS:        See above site
  7. " Release Coordinator:    Doug Kearns <dougkearns@gmail.com>
  8.  
  9. if exists("b:did_indent")
  10.   finish
  11. endif
  12.  
  13. runtime! indent/ruby.vim
  14. unlet! b:did_indent
  15. setlocal indentexpr=
  16.  
  17. if exists("b:eruby_subtype")
  18.   exe "runtime! indent/".b:eruby_subtype.".vim"
  19. else
  20.   runtime! indent/html.vim
  21. endif
  22. unlet! b:did_indent
  23.  
  24. if &l:indentexpr == ''
  25.   if &l:cindent
  26.     let &l:indentexpr = 'cindent(v:lnum)'
  27.   else
  28.     let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
  29.   endif
  30. endif
  31. let b:eruby_subtype_indentexpr = &l:indentexpr
  32.  
  33. let b:did_indent = 1
  34.  
  35. setlocal indentexpr=GetErubyIndent()
  36. setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
  37.  
  38. " Only define the function once.
  39. if exists("*GetErubyIndent")
  40.   finish
  41. endif
  42.  
  43. function! GetErubyIndent(...)
  44.   if a:0 && a:1 == '.'
  45.     let v:lnum = line('.')
  46.   elseif a:0 && a:1 =~ '^\d'
  47.     let v:lnum = a:1
  48.   endif
  49.   let vcol = col('.')
  50.   call cursor(v:lnum,1)
  51.   let inruby = searchpair('<%','','%>','W')
  52.   call cursor(v:lnum,vcol)
  53.   if inruby && getline(v:lnum) !~ '^<%\|^\s*-\=%>'
  54.     let ind = GetRubyIndent()
  55.   else
  56.     exe "let ind = ".b:eruby_subtype_indentexpr
  57.   endif
  58.   let lnum = prevnonblank(v:lnum-1)
  59.   let line = getline(lnum)
  60.   let cline = getline(v:lnum)
  61.   if cline =~# '^\s*<%-\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
  62.     let ind = ind - &sw
  63.   endif
  64.   if line =~# '\S\s*<%-\=\s*\%(}\|end\).\{-\}\s*\%(-\=%>\|$\)'
  65.     let ind = ind - &sw
  66.   endif
  67.   if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*-\=%>'
  68.     let ind = ind + &sw
  69.   elseif line =~# '<%-\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
  70.     let ind = ind + &sw
  71.   endif
  72.   if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
  73.     let ind = ind + &sw
  74.   endif
  75.   if cline =~# '^\s*-\=%>\s*$'
  76.     let ind = ind - &sw
  77.   endif
  78.   return ind
  79. endfunction
  80.  
  81. " vim:set sw=2 sts=2 ts=8 noet:
  82.