README

Path: README
Last Update: Thu Mar 10 01:23:10 CET 2005

Irb enhancements

Copyright and License

Copyright © 2005 by Csaba Henk

Released under the same terms of license as Ruby.

It’s a demo!

The following is just a demo of something more complex soon to come, so I didn’t rake the effort to provide proper installation scripts.

Use it right from the source dir, or install manually. All you want know is written here. Except if you are interested in the code, for that look into the files ending ".rb" :)

irb-enhanced.rb

Its main purpose is implementing bash-style multiline command line editing for irb.

It defines two config options, IRB.conf[:MULTILINE] and IRB.conf[:DRY], with respective accessor methods from irb topelevel, conf.multiline / conf.multiline= and conf.dry / conf.dry=.

If conf.multiline == true, then after finishing a multiline command in irb, it’s stored in irb’s command history in one.

If conf.dry == true, then repeating the same command multiple times won’t add it multiple times to the readline history. It can be useful if you use a command for its side effect, eg. polling some event.

There is also a method rlsplit added to irb’s toplevel. rlsplit 3 will split the previous command into two parts, and store it in the history that way: the first part will consist of the first three lines, the other part is the rest. You can also use it as rlspilt 0.3, then the splitting happens at the 30% of the previous command (in terms of lines). You can also specify a second argument: eg, if you type rlspilt 3, 2, then the splitting operation is applied not on the previous command, but on the one before that. It’s useful if you want to change one small thing in the middle of a lenghty code block (editing such beasts in irb makes sense with multiline). It’s a bit coarse way of line editing, but that’s what you can have ‘till someone ports mwh’s excellent pyrepl lib (a readline-a-like in python) to ruby.

Usage

 ruby -r irb-enhanced -e IRB.start

irb-completion-enhanced.rb

Context-sensitive completion for irb.

Uses irb’s lexer for finding out what type of completion is to be used.

  • within a string which is prefixed by require, completion lets you choose among ruby scripts (and c extensions) which can be required, according to $:
  • otherwise, if you are within a string, filename completion is performed
  • within backticks ("`") the first word is completed as an executable in your ENV["PATH"]
  • in other cases usual method/variable name completion is applied

There is one more feature: an attribute named watch_ancestors of IRB::InputCompletor. If is it set to true, method name completion will behave in the familiar way. If set to false, only the own methods of the object (and its class) are shown. And if it’s nil, then each hit on the tab key switches between these two behaviours (this latter is the default). This is useful eg. when you want to explore a new ruby class (I guess at such an occasion your focus is not on being notified to the fact that the object responds to is_complex_yaml? …)

Gotchas

If IRB::InputCompletor.watch_ancestors == nil, sometimes completion seems to be stuck: only one method name shown, but it doesn’t get completed. If this happens, hit the right arrow key after tab (repeat this twice in worst case).

Compilation

irb-completion-enhanced relies on having access to readlines’ rl_line_buffer variable, which is not provided by current ruby readline bindings. So you have to compile an extension which provides this. The easy way is to use ruby-inline:

www.zenspider.com/ZSS/Products/RubyInline

If you have that installed properly, you don’t have to worry about anything, just require irb-completion-enhanced. If for some reason you want to have this extension separately, then take a look into the readline_line_buffer directory.

The extension has been tested on Linux, FreeBSD, Solaris, and Cygwin.

Usage:

I didn’t like in the original irb/completion that requiring it bears the side effect that it right there takes over the scene. So now you have to make it happen explicitly. That is, do

 require 'irb-completion-enhanced'
 IRB::InputCompletor.setup

That’s all for now.

Get me at csaba-ruby Q creo o hu

[Validate]