Module: Ripl::Rc::Multiline

Includes:
U
Defined in:
lib/ripl/rc/multiline.rb

Overview

Constant Summary collapse

ERROR_REGEXP =

test those: ruby -e ‘“’ ruby -e ‘{’ ruby -e ‘[’ ruby -e ‘(’ ruby -e ‘class C’ ruby -e ‘def f’ ruby -e ‘begin’

Regexp.new(
[ # string
  "unterminated string meets end of file",
  # mri and rubinius
  "syntax error, unexpected \\$end",
  # rubinius
  "expecting '.+'( or '.+')*",
  # jruby
  "syntax error, unexpected end-of-file",
].join('|'))

Instance Method Summary collapse

Methods included from U

included

Methods included from SqueezeHistory::Imp

#squeeze_history

Methods included from StripBacktrace::Imp

#cwd, #home, #snip, #strip_backtrace

Methods included from Anchor::Imp

#short_inspect

Methods included from Color::Imp

#black, #blue, #color, #colors, #cyan, #find_color, #green, #magenta, #red, #reset, #white, #yellow

Instance Method Details

#before_loopObject



27
28
29
30
31
# File 'lib/ripl/rc/multiline.rb', line 27

def before_loop
  return super if Multiline.disabled?
  @rc_multiline_buffer = []
  super
end

#handle_interruptObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ripl/rc/multiline.rb', line 73

def handle_interrupt
  return super if Multiline.disabled?
  if @rc_multiline_buffer.empty?
    super
  else
    line = @rc_multiline_buffer.pop
    if @rc_multiline_buffer.empty?
      super
    else
      puts "[removed this line: #{line}]"
      throw :rc_multiline_cont
    end
  end
end

#loop_eval(input) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ripl/rc/multiline.rb', line 61

def loop_eval(input)
  return super if Multiline.disabled?
  if @rc_multiline_buffer.empty?
    super
  else
    @rc_multiline_buffer << input
    history.pop
    history << "\n" + (str = @rc_multiline_buffer.join("\n"))
    super str
  end
end

#loop_onceObject



42
43
44
45
46
47
48
# File 'lib/ripl/rc/multiline.rb', line 42

def loop_once
  return super if Multiline.disabled?
  catch(:rc_multiline_cont) do
    super
    @rc_multiline_buffer.clear
  end
end


50
51
52
53
54
55
56
57
58
59
# File 'lib/ripl/rc/multiline.rb', line 50

def print_eval_error(e)
  return super if Multiline.disabled?
  if e.is_a?(SyntaxError) && e.message =~ ERROR_REGEXP
    @rc_multiline_buffer << @input if @rc_multiline_buffer.empty?
    history.pop
    throw :rc_multiline_cont
  else
    super
  end
end

#promptObject



33
34
35
36
37
38
39
40
# File 'lib/ripl/rc/multiline.rb', line 33

def prompt
  return super if Multiline.disabled?
  if @rc_multiline_buffer.empty?
    super
  else
    "#{' '*(@prompt.size-2)}| "
  end
end