diff --git a/lib/pry/commands/amend_line.rb b/lib/pry/commands/amend_line.rb index 71ed5a50..77e92be1 100644 --- a/lib/pry/commands/amend_line.rb +++ b/lib/pry/commands/amend_line.rb @@ -20,6 +20,7 @@ class Pry raise CommandError, "No input to amend." if eval_string.empty? eval_string.replace amended_input(eval_string) + run "fix-indent" run "show-input" end diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb index 216ba425..3490c892 100644 --- a/lib/pry/commands/play.rb +++ b/lib/pry/commands/play.rb @@ -8,8 +8,7 @@ class Pry Usage: play [OPTIONS] [--help] The play command enables you to replay code from files and methods as if they - were entered directly in the Pry REPL. Default action (no options) is to play - the provided string variable. + were entered directly in the Pry REPL. play --lines 149..153 play -i 20 --lines 1..3 @@ -22,8 +21,8 @@ class Pry def options(opt) CodeCollector.inject_options(opt) - opt.on :open, 'When used with the -m switch, it plays the entire method except' \ - ' the last line, leaving the method definition "open". `amend-line`' \ + opt.on :open, 'Plays the select content except except' \ + ' the last line. Useful for replaying methods and leaving the method definition "open". `amend-line`' \ ' can then be used to modify the method.' end @@ -36,13 +35,18 @@ class Pry def perform_play eval_string << (opts.present?(:open) ? restrict_to_lines(content, (0..-2)) : content) + run "fix-indent" + end + + def should_use_default_file? + !args.first && !opts.present?(:in) && !opts.present?(:out) end def content - if args.first - @cc.content - else + if should_use_default_file? file_content + else + @cc.content end end diff --git a/spec/commands/play_spec.rb b/spec/commands/play_spec.rb index 7267d2ad..7a132204 100644 --- a/spec/commands/play_spec.rb +++ b/spec/commands/play_spec.rb @@ -82,7 +82,16 @@ describe "play" do it 'should play a method (a single line)' do pry_tester(@o).process_command 'play test_method --lines 2', @eval_str - @eval_str.should == " :test_method_content\n" + @eval_str.should == ":test_method_content\n" + end + + it 'should properly reindent lines' do + def @o.test_method + 'hello world' + end + + pry_tester(@o).process_command 'play test_method --lines 2', @eval_str + @eval_str.should == "'hello world'\n" end it 'should APPEND to the input buffer when playing a method line, not replace it' do @@ -98,7 +107,7 @@ describe "play" do STR end - it 'should play a method with the (multiple lines)' do + it 'should play a method (multiple lines)' do def @o.test_method @var0 = 10 @var1 = 20 @@ -108,7 +117,7 @@ describe "play" do pry_tester(@o).process_command 'play test_method --lines 3..4', @eval_str - @eval_str.should == unindent(<<-STR, 2) + @eval_str.should == unindent(<<-STR, 0) @var1 = 20 @var2 = 30 STR