Permalink
Browse files

Indent |(a, b)| blocks correctly

Oddly enough, this also fixes a long-standing issue with nested blocks,
noticeable in the change in etc/examples/indent/nested_hashes.rb.
  • Loading branch information...
1 parent 90f3523 commit 643805906520dfe88747394c84dec2b5ecbe0205 @AndrewRadev AndrewRadev committed Apr 21, 2012
@@ -0,0 +1,25 @@
+proc do |(a, b)|
+ puts a
+ puts b
+end
+
+proc do |foo, (a, b), bar|
+ puts a
+ puts b
+end
+
+define_method "something" do |param|
+ if param == 42
+ do_something
+ else
+ do_something_else
+ end
+end
+
+def foo
+ opts.on('--coordinator host=HOST[,port=PORT]',
+ 'Specify the HOST and the PORT of the coordinator') do |str|
+ h = sub_opts_to_hash(str)
+ puts h
+ end
+end
@@ -1,6 +0,0 @@
-def foo
- opts.on('--coordinator host=HOST[,port=PORT]',
- 'Specify the HOST and the PORT of the coordinator') do |str|
- h = sub_opts_to_hash(str)
- end
-end
@@ -46,8 +46,8 @@ class Foo
var.
func1(:param => 'value') {
func1_5(:param => 'value')
- var.func2(:param => 'value') {
- puts "test"
- }
+ var.func2(:param => 'value') {
+ puts "test"
+ }
}
end
View
@@ -93,7 +93,7 @@ let s:bracket_continuation_regex = '\%([({[]\)\s*\%(#.*\)\=$'
" Regex that defines blocks.
let s:block_regex =
- \ '\%(\<do:\@!\>\|{\)\s*\%(|\%([*@&]\=\h\w*,\=\s*\)\%(,\s*[*@&]\=\h\w*\)*|\)\=\s*\%(#.*\)\=$'
+ \ '\%(\<do:\@!\>\|{\)\s*\%(|\s*(\=\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(\=\s*[*@&]\=\h\w*)\=\)*|\)\=\s*\%(#.*\)\=$'
" 2. Auxiliary Functions {{{1
" ======================
@@ -152,15 +152,41 @@ function s:GetMSL(lnum)
if 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.
+ "
+ " Example:
+ " method_call one,
+ " two,
+ " three
+ "
let msl = lnum
elseif line =~ s:non_bracket_continuation_regex && (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_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.
+ "
+ " Example:
+ " method_call one,
+ " two {
+ " three
+ "
return lnum
elseif line =~ s:bracket_continuation_regex && (msl_body =~ s:bracket_continuation_regex || msl_body =~ s:block_regex)
" If both lines are bracket continuations (the current may also be a
" block-starter), use the current one's and stop here
+ "
+ " Example:
+ " method_call(
+ " other_method_call(
+ " foo
+ return msl
+ elseif line =~ s:block_regex && msl_body !~ s:continuation_regex && msl_body !~ s:block_regex
+ " If the previous line is a block-starter and the current one is
+ " mostly ordinary, use the current one as the MSL.
+ "
+ " Example:
+ " method_call do
+ " something
+ " something_else
return msl
else
let col = match(line, s:continuation_regex) + 1

0 comments on commit 6438059

Please sign in to comment.