Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undoing auto-indentation

Wnen you use irb with auto indent mode, the end statements get indented one level extra

 def foo
   ...
   end

instead of showing the ordinary indenting convention:

def foo
  ...
end

because you cannot tell irb in advance that you are going to escape one level in the next line. This question has been addressed elsewhere like here or here, but neither gives a satisfactory answer. They just suggest giving up.

However, if we can minimally overwrite some irb methods so that auto indent will insert white spaces not in the prompt area but at the beginning of the line you type in, then by default, irb will still be inserting spaces, but we will be able to erase some spaces with backspace. Is this possible?

Or, if that is not realistic, then is it possible to make irb erase the last line from the screen and redisplay it with proper indentation right after you press Enter on a line including end?

like image 313
sawa Avatar asked May 20 '11 23:05

sawa


1 Answers

Rewriting the last line is possible. Doing it in irb is difficult due to its lack of documentation and consistent api across versions. An irb alternative, ripl, has already solved this issue for itself with an auto-indent plugin. If you want to give ripl and its auto-indenting a try:

$ gem install ripl-auto_indent
$ echo "require 'ripl/auto_indent'" >> ~/.riplrc

# Auto-indent away
$ ripl
>> def foo
>>   puts "it's auto-magic!"
>> end
like image 63
cldwalker Avatar answered Sep 21 '22 13:09

cldwalker