<commit_before>
require 'ripl/rc/u'
require 'ripl/rc/multiline' # dependency

module Ripl::Rc::MultilineHistory
  include Ripl::Rc::U

  def print_eval_error(e)
    return super if MultilineHistory.disabled?
    catch(:rc_multiline_cont) do
      return super
    end
    history.pop
    throw :rc_multiline_cont
  end

  def loop_eval(input)
    return super if MultilineHistory.disabled?
    if @rc_multiline_buffer.empty?
      super
    else
      history.pop
      history << "\n" + @rc_multiline_buffer.join("\n") + "\n#{input}"
      super
    end
  end
end

Ripl::Shell.include(Ripl::Rc::MultilineHistory)
<commit_msg>multiline_history.rb: even more smart multiline history...<commit_after>
require 'ripl/rc/u'
require 'ripl/rc/multiline' # dependency

module Ripl::Rc::MultilineHistory
  include Ripl::Rc::U

  def loop_eval(input)
    return super if MultilineHistory.disabled?
    result = super # might throw
    unless @rc_multiline_buffer.empty?
      (@rc_multiline_buffer.size + (@rc_multiline_trash || 0)).
        times{ history.pop }
       @rc_multiline_trash = 0
      history << "\n" + @rc_multiline_buffer.join("\n")
    end
    result
  end

  def handle_interrupt
    return super if MultilineHistory.disabled?
    unless @rc_multiline_buffer.empty?
      @rc_multiline_trash ||= 0
      @rc_multiline_trash  += 1
    end
    super
  end
end

Ripl::Shell.include(Ripl::Rc::MultilineHistory)

{'fraction_non_alphanumeric': 0.1059322033898305, 'fraction_numerical': 0.002824858757062147, 'mean_word_length': 3.4143302180685358, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865762', 'n_tokens_mistral': 520, 'n_tokens_neox': 480, 'n_words': 102}