lib/textbringer/modes/ruby_mode.rb in textbringer-1.0.0 vs lib/textbringer/modes/ruby_mode.rb in textbringer-1.0.1

- old
+ new

@@ -1,7 +1,5 @@ -# frozen_string_literal: true - require "ripper" module Textbringer CONFIG[:ruby_indent_level] = 2 CONFIG[:ruby_indent_tabs_mode] = false @@ -173,11 +171,11 @@ end end private - INDENT_BEG_RE = /^([ \t]*)((class|module|def|if|unless|case|while|until|for|begin|end)\b|\})/ + INDENT_BEG_RE = /^([ \t]*)(class|module|def|if|unless|case|while|until|for|begin|end)\b/ def space_width(s) s.gsub(/\t/, " " * @buffer[:tab_width]).size end @@ -207,10 +205,13 @@ base_indentation = beginning_of_indentation start_pos = @buffer.point start_line = @buffer.current_line tokens = Ripper.lex(@buffer.substring(start_pos, bol_pos)) _, event, text = tokens.last + if event == :on_nl + _, event, text = tokens[-2] + end if event == :on_tstring_beg || event == :on_heredoc_beg || event == :on_regexp_beg || (event == :on_regexp_end && text.size > 1) || event == :on_tstring_content @@ -241,10 +242,10 @@ if line.nil? indentation = base_indentation else indentation = base_indentation + @buffer[:indent_level] end - if @buffer.looking_at?(/[ \t]*([}\])]|(end|else|elsif|when|rescue|ensure)\b)/) + if @buffer.looking_at?(/[ \t]*([}\])]|(end|else|elsif|when|in|rescue|ensure)\b)/) indentation -= @buffer[:indent_level] end _, last_event, last_text = tokens.reverse_each.find { |_, e, _| e != :on_sp && e != :on_nl && e != :on_ignored_nl }