[macruby-changes] [4852] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Oct 31 15:51:11 PDT 2010


Revision: 4852
          http://trac.macosforge.org/projects/ruby/changeset/4852
Author:   eloy.de.enige at gmail.com
Date:     2010-10-31 15:51:10 -0700 (Sun, 31 Oct 2010)
Log Message:
-----------
Only return the re-indented line if it changed.

Modified Paths:
--------------
    DietRB/trunk/lib/irb/formatter.rb
    DietRB/trunk/spec/formatter_spec.rb

Modified: DietRB/trunk/lib/irb/formatter.rb
===================================================================
--- DietRB/trunk/lib/irb/formatter.rb	2010-10-31 22:51:03 UTC (rev 4851)
+++ DietRB/trunk/lib/irb/formatter.rb	2010-10-31 22:51:10 UTC (rev 4852)
@@ -33,12 +33,12 @@
     
     def prompt(context, indent = false)
       prompt = case @prompt
-      when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.source.level]
+      when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.level]
       when :simple  then SIMPLE_PROMPT
       else
         NO_PROMPT
       end
-      indent ? (prompt + indentation(context.source.level)) : prompt
+      indent ? (prompt + indentation(context.level)) : prompt
     end
     
     def inspect_object(object)
@@ -60,9 +60,10 @@
     def reindent_last_line_in_source(source)
       old_level = source.level
       yield
+      line      = source.buffer[-1]
       new_line  = indentation(source.level < old_level ? source.level : old_level)
-      new_line += source.buffer[-1].lstrip
-      source.buffer[-1] = new_line
+      new_line += line.lstrip
+      source.buffer[-1] = new_line unless new_line == line
     end
 
     def result(object)

Modified: DietRB/trunk/spec/formatter_spec.rb
===================================================================
--- DietRB/trunk/spec/formatter_spec.rb	2010-10-31 22:51:03 UTC (rev 4851)
+++ DietRB/trunk/spec/formatter_spec.rb	2010-10-31 22:51:10 UTC (rev 4852)
@@ -12,8 +12,8 @@
     @formatter.prompt(@context).should == "irb(main):001:0> "
     @context.instance_variable_set(:@line, 23)
     @formatter.prompt(@context).should == "irb(main):023:0> "
-    @context.source << "def foo"
-    @formatter.prompt(@context).should == "irb(main):023:1> "
+    @context.process_line("def foo")
+    @formatter.prompt(@context).should == "irb(main):024:1> "
   end
   
   it "describes the context's object in the prompt" do
@@ -103,4 +103,9 @@
     end
     source.to_s.should == lines.map(&:last).join("\n")
   end
+
+  it "returns nil if the last line was not reindented" do
+    @context.source << "class A"
+    @formatter.reindent_last_line_in_source(@context.source) { @context.source << "  def foo" }.should == nil
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101031/dae3c15f/attachment-0001.html>


More information about the macruby-changes mailing list