Skip to content
Browse files

Basic "<<"-style heredoc indenting

If the closing delimiter is at column 0, keep it that way.
  • Loading branch information...
1 parent 5c3213a commit beb12893e3909462a3cb098b4c778626e61ba025 @AndrewRadev AndrewRadev committed May 12, 2013
Showing with 31 additions and 0 deletions.
  1. +13 −0 indent/ruby.vim
  2. +18 −0 spec/indent/basic_spec.rb
View
13 indent/ruby.vim
@@ -124,6 +124,11 @@ function s:IsInStringOrDocumentation(lnum, col)
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_stringdoc
endfunction
+" Check if the character at lnum:col is inside a string delimiter
+function s:IsInStringDelimiter(lnum, col)
+ return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'rubyStringDelimiter'
+endfunction
+
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
function s:PrevNonBlankNonString(lnum)
let in_block = 0
@@ -376,6 +381,14 @@ function GetRubyIndent(...)
return indent('.')
endif
+ " If we are at the closing delimiter of a "<<" heredoc-style string, set the
+ " indent to 0.
+ if line =~ '^\k\+\s*$'
+ \ && s:IsInStringDelimiter(clnum, 1)
+ \ && search('\V<<'.line, 'nbW') > 0
+ return 0
+ endif
+
" 3.3. Work on the previous line. {{{2
" -------------------------------
View
18 spec/indent/basic_spec.rb
@@ -21,4 +21,22 @@
something_else
EOF
end
+
+ specify "heredocs" do
+ assert_correct_indenting <<-EOF
+ def one
+ two = <<-THREE
+ four
+ THREE
+ end
+ EOF
+
+ assert_correct_indenting <<-EOF
+ def one
+ two = <<THREE
+ four
+ THREE
+ end
+ EOF
+ end
end

0 comments on commit beb1289

Please sign in to comment.
Something went wrong with that request. Please try again.