Permalink
Browse files

Fix an issue with block continuations

In the new example, the "].each" registers as a block, so the
continuation logic goes upwards and takes the ":one," line into account.

As a solution, a (hopefully) better block_continuation_regex is created
specifically for continuations -- a block opener starting with "]", "}",
or ")" can't be a continuation.
  • Loading branch information...
1 parent 8e7d102 commit 4a90d71c6611e46d05eb110bea8edde983331929 @AndrewRadev AndrewRadev committed Sep 26, 2012
Showing with 17 additions and 4 deletions.
  1. +6 −0 etc/examples/indent/continuations.rb
  2. +11 −4 indent/ruby.vim
@@ -23,3 +23,9 @@
else
other
end
+
+array = [
+ :one,
+].each do |x|
+ puts x.to_s
+end
View
@@ -105,6 +105,8 @@ let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$'
let s:block_regex =
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$'
+let s:block_continuation_regex = '^[^])}\t ].*'.s:block_regex
+
" 2. Auxiliary Functions {{{1
" ======================
@@ -169,7 +171,8 @@ function s:GetMSL(lnum)
" something
"
return msl
- elseif line =~ s:non_bracket_continuation_regex && msl_body =~ s:non_bracket_continuation_regex
+ elseif line =~ s:non_bracket_continuation_regex &&
+ \ msl_body =~ s:non_bracket_continuation_regex
" If the current line is a non-bracket continuation and so is the
" previous one, keep its indent and continue looking for an MSL.
"
@@ -179,7 +182,8 @@ function s:GetMSL(lnum)
" three
"
let msl = lnum
- elseif line =~ s:non_bracket_continuation_regex && (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_regex)
+ elseif line =~ s:non_bracket_continuation_regex &&
+ \ (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_continuation_regex)
" If the current line is a bracket continuation or a block-starter, but
" the previous is a non-bracket one, respect the previous' indentation,
" and stop here.
@@ -190,7 +194,8 @@ function s:GetMSL(lnum)
" three
"
return lnum
- elseif line =~ s:bracket_continuation_regex && (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_regex)
+ elseif line =~ s:bracket_continuation_regex &&
+ \ (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_continuation_regex)
" If both lines are bracket continuations (the current may also be a
" block-starter), use the current one's and stop here
"
@@ -199,7 +204,9 @@ function s:GetMSL(lnum)
" other_method_call(
" foo
return msl
- elseif line =~ s:block_regex && msl_body !~ s:continuation_regex && msl_body !~ s:block_regex
+ elseif line =~ s:block_regex &&
+ \ msl_body !~ s:continuation_regex &&
+ \ msl_body !~ s:block_continuation_regex
" If the previous line is a block-starter and the current one is
" mostly ordinary, use the current one as the MSL.
"

0 comments on commit 4a90d71

Please sign in to comment.