class RubyLex
def indent_difference(lines, line_results, line_index)
def indent_difference(lines, line_results, line_index) loop do _tokens, prev_opens, _next_opens, min_depth = line_results[line_index] open_token = prev_opens.last if !open_token || (open_token.event != :on_heredoc_beg && !free_indent_token?(open_token)) # If the leading whitespace is an indent, return the difference indent_level = calc_indent_level(prev_opens.take(min_depth)) calculated_indent = 2 * indent_level actual_indent = lines[line_index][/^ */].size return actual_indent - calculated_indent elsif open_token.event == :on_heredoc_beg && open_token.tok.match?(/^<<[^-~]/) return 0 end # If the leading whitespace is not an indent but part of a multiline token # Calculate base_indent of the multiline token's beginning line line_index = open_token.pos[0] - 1 end end