2015-07-18 17:05:45 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ruby') == -1
|
|
|
|
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
" Vim indent file
|
|
|
|
" Language: eRuby
|
|
|
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
|
|
|
" URL: https://github.com/vim-ruby/vim-ruby
|
|
|
|
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
|
|
|
|
2018-07-08 09:16:28 -04:00
|
|
|
if get(b:, 'did_indent') =~# '\<eruby\>'
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
runtime! indent/ruby.vim
|
|
|
|
unlet! b:did_indent
|
|
|
|
setlocal indentexpr=
|
|
|
|
|
2018-07-08 09:16:28 -04:00
|
|
|
if &filetype =~# '^eruby\>'
|
|
|
|
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
|
|
|
|
exe "runtime! indent/".b:eruby_subtype.".vim"
|
|
|
|
else
|
|
|
|
runtime! indent/html.vim
|
|
|
|
endif
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
2018-07-08 09:16:28 -04:00
|
|
|
let b:did_indent = get(b:, 'did_indent', 1) . '.eruby'
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
|
2014-02-04 13:13:11 -05:00
|
|
|
" Force HTML indent to not keep state.
|
|
|
|
let b:html_indent_usestate = 0
|
|
|
|
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04: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
|
|
|
|
|
|
|
|
setlocal indentexpr=GetErubyIndent()
|
|
|
|
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
|
|
|
|
|
2016-09-11 07:24:17 -04:00
|
|
|
" this file uses line continuations
|
|
|
|
let s:cpo_sav = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
function! GetErubyIndent(...)
|
2014-12-09 17:09:20 -05:00
|
|
|
" The value of a single shift-width
|
|
|
|
if exists('*shiftwidth')
|
|
|
|
let sw = shiftwidth()
|
|
|
|
else
|
|
|
|
let sw = &sw
|
|
|
|
endif
|
|
|
|
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
if a:0 && a:1 == '.'
|
|
|
|
let v:lnum = line('.')
|
|
|
|
elseif a:0 && a:1 =~ '^\d'
|
|
|
|
let v:lnum = a:1
|
|
|
|
endif
|
|
|
|
let vcol = col('.')
|
|
|
|
call cursor(v:lnum,1)
|
|
|
|
let inruby = searchpair('<%','','%>','W')
|
|
|
|
call cursor(v:lnum,vcol)
|
|
|
|
if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>'
|
|
|
|
let ind = GetRubyIndent(v:lnum)
|
|
|
|
else
|
|
|
|
exe "let ind = ".b:eruby_subtype_indentexpr
|
|
|
|
|
2014-02-04 13:13:11 -05:00
|
|
|
" Workaround for Andy Wokula's HTML indent. This should be removed after
|
|
|
|
" some time, since the newest version is fixed in a different way.
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
if b:eruby_subtype_indentexpr =~# '^HtmlIndent('
|
|
|
|
\ && exists('b:indent')
|
|
|
|
\ && type(b:indent) == type({})
|
|
|
|
\ && has_key(b:indent, 'lnum')
|
|
|
|
" Force HTML indent to not keep state
|
|
|
|
let b:indent.lnum = -1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let lnum = prevnonblank(v:lnum-1)
|
|
|
|
let line = getline(lnum)
|
|
|
|
let cline = getline(v:lnum)
|
|
|
|
if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind - sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
|
|
|
if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind - sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
|
|
|
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind + sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind + sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
|
|
|
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind + sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
2016-01-28 12:07:33 -05:00
|
|
|
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
|
2017-03-23 06:28:19 -04:00
|
|
|
\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind - sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
|
|
|
if cline =~# '^\s*[-=]\=%>\s*$'
|
2014-12-09 17:09:20 -05:00
|
|
|
let ind = ind - sw
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
endif
|
|
|
|
return ind
|
|
|
|
endfunction
|
|
|
|
|
2016-09-11 07:24:17 -04:00
|
|
|
let &cpo = s:cpo_sav
|
|
|
|
unlet! s:cpo_sav
|
|
|
|
|
Add support for basic languages
coffee, cucumbeer, eruby, haml, haskell, javascript,
json, less, nginx, ocaml, ruby, sass, scss, slim,
stylus, textile, tmux
2013-09-12 10:17:03 -04:00
|
|
|
" vim:set sw=2 sts=2 ts=8 noet:
|
2015-07-18 17:05:45 -04:00
|
|
|
|
|
|
|
endif
|