Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enable auto-indentation by default and fix a regression.

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@4860 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 588d14e49f27120c0505bd3383540a0fbba49846 1 parent a4872a9
@alloy alloy authored
Showing with 15 additions and 9 deletions.
  1. +10 −9 lib/irb/formatter.rb
  2. +5 −0 spec/formatter_spec.rb
View
19 lib/irb/formatter.rb
@@ -26,7 +26,7 @@ class Formatter
def initialize
@prompt = :default
@inspect = true
- @auto_indent = false
+ @auto_indent = true
@filter_from_backtrace = [SOURCE_ROOT]
end
@@ -69,14 +69,15 @@ def reindent_last_line(context)
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
View
5 spec/formatter_spec.rb
@@ -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 @@ def object.__id__; 2158110700; end
@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
Please sign in to comment.
Something went wrong with that request. Please try again.