| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ setlocal nosmartindent | |||
| 22 | 22 | ||
| 23 | 23 | " Now, set up our indentation expression and keys that trigger it. | |
| 24 | 24 | setlocal indentexpr=GetRubyIndent(v:lnum) | |
| 25 | - setlocal indentkeys=0{,0},0),0],!^F,o,O,e,: | ||
| 25 | + setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,. | ||
| 26 | 26 | setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end | |
| 27 | 27 | setlocal indentkeys+==private,=protected,=public | |
| 28 | 28 | ||
@@ -120,6 +120,9 @@ let s:block_regex = | |||
| 120 | 120 | ||
| 121 | 121 | let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex | |
| 122 | 122 | ||
| 123 | + " Regex that describes a leading operator (only a method call's dot for now) | ||
| 124 | + let s:leading_operator_regex = '^\s*[.]' | ||
| 125 | + | ||
| 123 | 126 | " 2. Auxiliary Functions {{{1 | |
| 124 | 127 | " ====================== | |
| 125 | 128 | ||
@@ -179,7 +182,11 @@ function s:GetMSL(lnum) | |||
| 179 | 182 | " Otherwise, terminate search as we have found our MSL already. | |
| 180 | 183 | let line = getline(lnum) | |
| 181 | 184 | ||
| 182 | - if s:Match(lnum, s:splat_regex) | ||
| 185 | + if s:Match(msl, s:leading_operator_regex) | ||
| 186 | + " If the current line starts with a leading operator, keep its indent | ||
| 187 | + " and keep looking for an MSL. | ||
| 188 | + let msl = lnum | ||
| 189 | + elseif s:Match(lnum, s:splat_regex) | ||
| 183 | 190 | " If the above line looks like the "*" of a splat, use the current one's | |
| 184 | 191 | " indentation. | |
| 185 | 192 | " | |
@@ -442,6 +449,11 @@ function GetRubyIndent(...) | |||
| 442 | 449 | return 0 | |
| 443 | 450 | endif | |
| 444 | 451 | ||
| 452 | + " If the current line starts with a leading operator, add a level of indent. | ||
| 453 | + if s:Match(clnum, s:leading_operator_regex) | ||
| 454 | + return indent(s:GetMSL(clnum)) + &sw | ||
| 455 | + endif | ||
| 456 | + | ||
| 445 | 457 | " 3.3. Work on the previous line. {{{2 | |
| 446 | 458 | " ------------------------------- | |
| 447 | 459 | ||
@@ -481,6 +493,12 @@ function GetRubyIndent(...) | |||
| 481 | 493 | return indent(s:GetMSL(lnum)) + &sw | |
| 482 | 494 | endif | |
| 483 | 495 | ||
| 496 | + " If the previous line started with a leading operator, use its MSL's level | ||
| 497 | + " of indent | ||
| 498 | + if s:Match(lnum, s:leading_operator_regex) | ||
| 499 | + return indent(s:GetMSL(lnum)) | ||
| 500 | + endif | ||
| 501 | + | ||
| 484 | 502 | " If the previous line ended with the "*" of a splat, add a level of indent | |
| 485 | 503 | if line =~ s:splat_regex | |
| 486 | 504 | return indent(lnum) + &sw | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,22 @@ | |||
| 1 | 1 | require 'spec_helper' | |
| 2 | 2 | ||
| 3 | 3 | describe "Indenting" do | |
| 4 | + specify "method chaining" do | ||
| 5 | + assert_correct_indenting <<-EOF | ||
| 6 | + some_object. | ||
| 7 | + method_one. | ||
| 8 | + method_two. | ||
| 9 | + method_three | ||
| 10 | + EOF | ||
| 11 | + | ||
| 12 | + assert_correct_indenting <<-EOF | ||
| 13 | + some_object | ||
| 14 | + .method_one | ||
| 15 | + .method_two | ||
| 16 | + .method_three | ||
| 17 | + EOF | ||
| 18 | + end | ||
| 19 | + | ||
| 4 | 20 | specify "arrays" do | |
| 5 | 21 | assert_correct_indenting <<-EOF | |
| 6 | 22 | foo = [one, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments