Skip to content

Commit

Permalink
Fix eruby indentation when 'shiftwidth' is 0
Browse files Browse the repository at this point in the history
For #239

This change is based on commit
9d95f29
  • Loading branch information
roryokane committed Nov 30, 2014
1 parent 9d95f29 commit cde61fa
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions indent/eruby.vim
Expand Up @@ -42,6 +42,13 @@ if exists("*GetErubyIndent")
endif

function! GetErubyIndent(...)
" The value of a single shift-width
if exists('*shiftwidth')
let sw = shiftwidth()
else
let sw = &sw
endif

if a:0 && a:1 == '.'
let v:lnum = line('.')
elseif a:0 && a:1 =~ '^\d'
Expand Down Expand Up @@ -70,24 +77,24 @@ function! GetErubyIndent(...)
let line = getline(lnum)
let cline = getline(v:lnum)
if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
let ind = ind - &sw
let ind = ind - sw
endif
if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
let ind = ind - &sw
let ind = ind - sw
endif
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
let ind = ind + &sw
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
let ind = ind + sw
endif
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
let ind = ind + &sw
let ind = ind + sw
endif
if line !~# '^\s*<%' && line =~# '%>\s*$'
let ind = ind - &sw
let ind = ind - sw
endif
if cline =~# '^\s*[-=]\=%>\s*$'
let ind = ind - &sw
let ind = ind - sw
endif
return ind
endfunction
Expand Down

0 comments on commit cde61fa

Please sign in to comment.