From 4db25f1b8d2f0e74699c48d38a7e0076365ff944 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 13 Sep 2011 18:56:10 -0700 Subject: [PATCH] Always edit a blank file with -t --- lib/pry/default_commands/introspection.rb | 10 ++++++---- test/test_default_commands/test_introspection.rb | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index faa683ff..a0f5cb2e 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -139,11 +139,13 @@ class Pry # edit of local code, eval'd within pry. if !opts.ex? && args.empty? - content = if !eval_string.empty? + content = if opts.t? + "" + elsif eval_string.strip != "" eval_string - elsif !opts.t? - _pry_.input_array.reverse_each.find{ |x| x && x.strip != "" } # No present? in 1.8 - end || "" + else + _pry_.input_array.reverse_each.find{ |x| x && x.strip != "" } || "" + end line = content.lines.count diff --git a/test/test_default_commands/test_introspection.rb b/test/test_default_commands/test_introspection.rb index 78dc426e..beac04cb 100644 --- a/test/test_default_commands/test_introspection.rb +++ b/test/test_default_commands/test_introspection.rb @@ -187,6 +187,11 @@ describe "Pry::DefaultCommands::Introspection" do @contents.should == "\n" end + it "should use a blank file if -t is specified even half-way through an expression" do + mock_pry("def a;", "edit -t") + @contents.should == "\n" + end + it "should position the cursor at the end of the expression" do mock_pry("def a; 2;"," end", "edit") @line.should == 2