1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-16 06:47:52 +01:00
vim/runtime/indent/eruby.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
2.9 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
2010-05-28 20:54:39 +02:00
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
2013-06-12 21:29:15 +02:00
" URL: https://github.com/vim-ruby/vim-ruby
2006-04-15 20:25:09 +00:00
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
2019-01-17 16:07:22 +01:00
" Last Change: 2019 Jan 06
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
2019-01-17 16:07:22 +01:00
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
2007-05-10 17:26:28 +00:00
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
" Force HTML indent to not keep state.
let b:html_indent_usestate = 0
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
" this file uses line continuations
let s:cpo_sav = &cpo
set cpo&vim
2008-07-13 17:41:49 +00:00
function! GetErubyIndent(...)
" The value of a single shift-width
2019-01-17 16:07:22 +01:00
if exists('*shiftwidth')
let sw = shiftwidth()
else
let sw = &sw
endif
2008-07-13 17:41:49 +00:00
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)
2013-06-12 21:29:15 +02:00
if inruby && getline(v:lnum) !~ '^<%\|^\s*[-=]\=%>'
let ind = GetRubyIndent(v:lnum)
2007-05-05 17:54:07 +00:00
else
2007-05-10 17:26:28 +00:00
exe "let ind = ".b:eruby_subtype_indentexpr
" Workaround for Andy Wokula's HTML indent. This should be removed after
" some time, since the newest version is fixed in a different way.
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
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)
2013-06-12 21:29:15 +02:00
if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
let ind = ind - sw
2010-05-28 20:54:39 +02:00
endif
2013-06-12 21:29:15 +02:00
if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
let ind = ind - sw
2007-05-05 17:54:07 +00:00
endif
2013-06-12 21:29:15 +02:00
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
let ind = ind + sw
2013-06-12 21:29:15 +02:00
elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
let ind = ind + sw
2007-05-05 17:54:07 +00:00
endif
2008-07-13 17:41:49 +00:00
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
let ind = ind + sw
2007-05-05 17:54:07 +00:00
endif
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
2019-01-17 16:07:22 +01:00
\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
let ind = ind - sw
2013-06-12 21:29:15 +02:00
endif
if cline =~# '^\s*[-=]\=%>\s*$'
let ind = ind - sw
2007-05-05 17:54:07 +00:00
endif
return ind
endfunction
2006-04-15 20:25:09 +00:00
let &cpo = s:cpo_sav
unlet! s:cpo_sav
2008-06-24 21:16:56 +00:00
" vim:set sw=2 sts=2 ts=8 noet: