Skip to content

Commit f87d14a

Browse files
committed
Deal with continuations in conditions
1 parent 78244da commit f87d14a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

indent/ruby.vim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ let s:end_skip_expr = s:skip_expr .
9090
let s:non_bracket_continuation_regex = '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
9191

9292
" Regex that defines continuation lines.
93-
" TODO: this needs to deal with if ...: and so on
9493
let s:continuation_regex =
9594
\ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
9695

96+
" Regex that defines continuable keywords
97+
let s:continuable_regex =
98+
\ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
99+
\ '\<\%(if\|for\|while\|until\|unless\):\@!\>'
100+
97101
" Regex that defines bracket continuations
98102
let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$'
99103

@@ -488,6 +492,10 @@ function GetRubyIndent(...)
488492
endif
489493
endif
490494

495+
if s:Match(lnum, s:continuable_regex) && s:Match(lnum, s:continuation_regex)
496+
return indent(s:GetMSL(lnum)) + &sw + &sw
497+
endif
498+
491499
" If the previous line ended with a block opening, add a level of indent.
492500
if s:Match(lnum, s:block_regex)
493501
return indent(s:GetMSL(lnum)) + &sw

spec/indent/continuations_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,16 @@ def bar(
176176
'b'
177177
EOF
178178
end
179+
180+
specify "continuation with if" do
181+
# See https://github.com/vim-ruby/vim-ruby/issues/215 for details
182+
assert_correct_indenting <<-EOF
183+
if foo || bar ||
184+
bong &&
185+
baz || bing
186+
puts "foo"
187+
end
188+
EOF
189+
end
190+
179191
end

0 commit comments

Comments
 (0)