[macruby-changes] [4860] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 31 15:52:15 PDT 2010
Revision: 4860
http://trac.macosforge.org/projects/ruby/changeset/4860
Author: eloy.de.enige at gmail.com
Date: 2010-10-31 15:52:13 -0700 (Sun, 31 Oct 2010)
Log Message:
-----------
Enable auto-indentation by default and fix a regression.
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:52:06 UTC (rev 4859)
+++ DietRB/trunk/lib/irb/formatter.rb 2010-10-31 22:52:13 UTC (rev 4860)
@@ -26,7 +26,7 @@
def initialize
@prompt = :default
@inspect = true
- @auto_indent = false
+ @auto_indent = true
@filter_from_backtrace = [SOURCE_ROOT]
end
@@ -69,14 +69,15 @@
source = context.source
old_level = source.level
yield
- level = source.level < old_level ? source.level : old_level
- line = source.buffer[-1]
- new_line = indentation(level)
- new_line << line.lstrip
- unless line == new_line && level == old_level
- source.buffer[-1] = new_line
- new_prompt = prompt(context, true, level)
- [new_prompt, new_line]
+ if line = source.buffer[-1]
+ # only if the level raises do we use the new value
+ level = source.level < old_level ? source.level : old_level
+ new_line = "#{indentation(level)}#{line.lstrip}"
+ # don't return anything if the new line and level are the same
+ unless line == new_line && level == old_level
+ source.buffer[-1] = new_line
+ [prompt(context, true, level), new_line]
+ end
end
end
end
Modified: DietRB/trunk/spec/formatter_spec.rb
===================================================================
--- DietRB/trunk/spec/formatter_spec.rb 2010-10-31 22:52:06 UTC (rev 4859)
+++ DietRB/trunk/spec/formatter_spec.rb 2010-10-31 22:52:13 UTC (rev 4860)
@@ -6,6 +6,7 @@
before do
@formatter = IRB::Formatter.new
@context = IRB::Context.new(main)
+ @formatter.auto_indent = false
end
it "returns a prompt string, displaying line number and code indentation level" do
@@ -129,5 +130,9 @@
@formatter.reindent_last_line(@context) { @context.source << " def foo" }.should == nil
@formatter.reindent_last_line(@context) { @context.source << " end" }.should_not == nil
end
+
+ it "returns nil if the source buffer is empty" do
+ @formatter.reindent_last_line(@context) {}.should == nil
+ end
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101031/55c61b45/attachment.html>
More information about the macruby-changes
mailing list