vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

eruby.vim (2958B)


      1 " Vim indent file
      2 " Language:		eRuby
      3 " Maintainer:		Tim Pope <vimNOSPAM@tpope.org>
      4 " URL:			https://github.com/vim-ruby/vim-ruby
      5 " Last Change:		2019 Jan 06
      6 
      7 if exists("b:did_indent")
      8   finish
      9 endif
     10 
     11 runtime! indent/ruby.vim
     12 unlet! b:did_indent
     13 setlocal indentexpr=
     14 
     15 if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
     16   exe "runtime! indent/".b:eruby_subtype.".vim"
     17 else
     18   runtime! indent/html.vim
     19 endif
     20 unlet! b:did_indent
     21 
     22 " Force HTML indent to not keep state.
     23 let b:html_indent_usestate = 0
     24 
     25 if &l:indentexpr == ''
     26   if &l:cindent
     27     let &l:indentexpr = 'cindent(v:lnum)'
     28   else
     29     let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
     30   endif
     31 endif
     32 let b:eruby_subtype_indentexpr = &l:indentexpr
     33 
     34 let b:did_indent = 1
     35 
     36 setlocal indentexpr=GetErubyIndent()
     37 setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
     38 
     39 " Only define the function once.
     40 if exists("*GetErubyIndent")
     41   finish
     42 endif
     43 
     44 " this file uses line continuations
     45 let s:cpo_sav = &cpo
     46 set cpo&vim
     47 
     48 function! GetErubyIndent(...)
     49   " The value of a single shift-width
     50   if exists('*shiftwidth')
     51     let sw = shiftwidth()
     52   else
     53     let sw = &sw
     54   endif
     55 
     56   if a:0 && a:1 == '.'
     57     let v:lnum = line('.')
     58   elseif a:0 && a:1 =~ '^\d'
     59     let v:lnum = a:1
     60   endif
     61   let vcol = col('.')
     62   call cursor(v:lnum,1)
     63   let inruby = searchpair('<%','','%>','W')
     64   call cursor(v:lnum,vcol)
     65   if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>'
     66     let ind = GetRubyIndent(v:lnum)
     67   else
     68     exe "let ind = ".b:eruby_subtype_indentexpr
     69 
     70     " Workaround for Andy Wokula's HTML indent. This should be removed after
     71     " some time, since the newest version is fixed in a different way.
     72     if b:eruby_subtype_indentexpr =~# '^HtmlIndent('
     73 	  \ && exists('b:indent')
     74 	  \ && type(b:indent) == type({})
     75 	  \ && has_key(b:indent, 'lnum')
     76       " Force HTML indent to not keep state
     77       let b:indent.lnum = -1
     78     endif
     79   endif
     80   let lnum = prevnonblank(v:lnum-1)
     81   let line = getline(lnum)
     82   let cline = getline(v:lnum)
     83   if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
     84     let ind = ind - sw
     85   endif
     86   if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
     87     let ind = ind - sw
     88   endif
     89   if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
     90     let ind = ind + sw
     91   elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
     92     let ind = ind + sw
     93   endif
     94   if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
     95     let ind = ind + sw
     96   endif
     97   if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
     98 	\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
     99     let ind = ind - sw
    100   endif
    101   if cline =~# '^\s*[-=]\=%>\s*$'
    102     let ind = ind - sw
    103   endif
    104   return ind
    105 endfunction
    106 
    107 let &cpo = s:cpo_sav
    108 unlet! s:cpo_sav
    109 
    110 " vim:set sw=2 sts=2 ts=8 noet: