[ANN] Irb enhancements

Hi list!

I have some enhancements for irb:

* support for bash-style multiline editing (multiline commands are
stored in one history entry)

* context sensitive completion:

  - 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

... and some further nuances.

See a more detailed description in

http://www.creo.hu/~csaba/ruby/irb-enhancements/doc/files/README.html

Check it out at

http://www.creo.hu/~csaba/ruby/

Csaba

Cs. Henk wrote:

Hi list!

I have some enhancements for irb:

* support for bash-style multiline editing (multiline commands are
stored in one history entry)

I've wanted this for a long time! (Stupid me, I thought zsh was the only shell with multiline editing.)

* context sensitive completion:

Looking forward to checking this out too.

Hi list!

Hi!

I have some enhancements for irb:

Thanks for the enhancements. I'm also modifying irb, mainly
to provide a handy database shell based on RubyonRails' active_record
package. I'm also interested in cleaning up irb.rb to
allow easy customization of its command interpreter (ie allow irb
to do something other than to only eval input).

If you haven't already, I'd recommend the following:
http://rubygarden.org/ruby?Irb/TipsAndTricks: command history
http://sheepman.parfait.ne.jp/20050215.html: paging output
http://raa.ruby-lang.org/project/irbsh/: raa project for irb tweaking

If you, myself and others make considerable enhancements it
might be a good idea to start up an irb-enhancement project on rubyforge.

Gabriel

···

On Wed, Mar 09, 2005 at 09:28:44PM +0900, Cs. Henk wrote:
--
my looovely website -- http://www.chwhat.com
BTW, IF chwhat.com goes down email me at gabriel.horner@cern.ch

Joel VanderWerf wrote:

* support for bash-style multiline editing (multiline commands are
stored in one history entry)

I've wanted this for a long time! (Stupid me, I thought zsh was the only shell with multiline editing.)

Yay for zsh!

I agree, these ri enhancements are really cool. I thought I was the only one who missed all the fancy zsh features when I dropped into IRB. :slight_smile:

Ben

I wrote "bash style", which is not the same as "zsh style".

According to my classification, there are three type of multiline
editing models (actual keymaps are irrelevant as far as the
classification goes, of course):

* bash style: after entering a multiline command, the up arrow (or
ctrl-p) brings back the whole multiline command in one. Then it behaves
as one long line, you can move left and right within the line.

* zsh style: after entering a multiline command, the up arrow (or
ctrl-p) brings back the whole multiline command in one. Then it behaves
as an array of lines, up/down arrow moves between the lines, and
left/right arrow moves within a line. As I know, there is no way to go
back in one step from one multiline block to the other, you have to
climb up linewise. While in general it's better than bash style, this
latter behaviour could be quite painful after a ten line class
definition. Maybe not an issue for a shell, but is an issue for irb.

* pyrepl style: after entering a multiline command, ctrl-p
brings back the whole multiline command in one, Then it behaves as an
array of lines, up/down arrow moves between the lines, and left/right
arrow moves within a line. Hitting ctrl-p/ctrl-n always moves between
multiline blocks.

So the most advanced model is that of pyrepl. Tell me if I missed
something and these things are also possible in zsh (or bash).

By the way, if you don't know what pyrepl is: it's mwh's excellent
readline-a-like in python. Worth to check out, at least to play with
these features (but if I happen to do something with python, I can't
imagine that without pyrepl -- you can imagine, getting multiline
editing right is much more an issue with python than with everything
else). You find it at http://codespeak.net/pyrepl/, just unpack the
tarball, cd into the top dir, and type "python pythoni".

My idea is that pyrepl should be ported to ruby eventually. Not only it
has the mentioned features, but then we would have a totally accessible
and controllable access to readline functionality in pure ruby, and one
wouldn't need to meditate which other parts of readline should have a ruby
binding for being able to implement this idea or that.

Csaba

···

On Thu, Mar 10, 2005 at 03:28:47AM +0900, Joel VanderWerf wrote:

>* support for bash-style multiline editing (multiline commands are
>stored in one history entry)

I've wanted this for a long time! (Stupid me, I thought zsh was the only
shell with multiline editing.)

If you haven't already, I'd recommend the following:
http://rubygarden.org/ruby?Irb/TipsAndTricks: command history
http://sheepman.parfait.ne.jp/20050215.html: paging output
http://raa.ruby-lang.org/project/irbsh/: raa project for irb tweaking

I've heard only of the first one (and I'm applying that, too).

If you, myself and others make considerable enhancements it
might be a good idea to start up an irb-enhancement project on rubyforge.

That sounds to be a good idea. Unfortunately, I won't have the time to
maintain such a thing. I don't mind if someone else uses the name
irb-enhancement (this stuff I contributed now is not a regular project,
just the pure irb-related stuff distilled out of something else I'm
working on).

If someone would start such a project, what I can imagine of my part is
that I'd help merging my code into the facelifted irb.

Csaba

···

On Thu, Mar 10, 2005 at 06:22:29PM +0900, Gabriel Horner wrote:

Cs. Henk wrote:

* zsh style: after entering a multiline command, the up arrow (or
ctrl-p) brings back the whole multiline command in one. Then it behaves
as an array of lines, up/down arrow moves between the lines, and
left/right arrow moves within a line. As I know, there is no way to go
back in one step from one multiline block to the other, you have to
climb up linewise. While in general it's better than bash style, this
latter behaviour could be quite painful after a ten line class
definition. Maybe not an issue for a shell, but is an issue for irb.

* pyrepl style: after entering a multiline command, ctrl-p
brings back the whole multiline command in one, Then it behaves as an
array of lines, up/down arrow moves between the lines, and left/right
arrow moves within a line. Hitting ctrl-p/ctrl-n always moves between
multiline blocks.

In zsh up-arrow and ctrl-p are both bound (by default) to 'up-line-or-history'. If you're on any given line of a command and hit "meta-x up-history" you'll go to the previous entry, not up lines. Getting the pyrepl behaviour should be as simple as binding Ctrl-P to up-history.

My idea is that pyrepl should be ported to ruby eventually. Not only it
has the mentioned features, but then we would have a totally accessible
and controllable access to readline functionality in pure ruby, and one
wouldn't need to meditate which other parts of readline should have a ruby
binding for being able to implement this idea or that.

Wasn't someone looking at rewriting readline so that we could have a non GPLed readline implemenation for Ruby? In addition to the licensing issue, this would sure make lives easier for OS X users.

Ben

Quoting bg-rubytalk@infofiend.com, on Thu, Mar 10, 2005 at 07:44:25AM +0900:

Wasn't someone looking at rewriting readline so that we could have a non
GPLed readline implemenation for Ruby? In addition to the licensing
issue, this would sure make lives easier for OS X users.

There are BSD-licenced readlines around, with GNU readline compatible
APIs, even.

Cheers,
Sam

In zsh up-arrow and ctrl-p are both bound (by default) to
'up-line-or-history'. If you're on any given line of a command and hit
"meta-x up-history" you'll go to the previous entry, not up lines.
Getting the pyrepl behaviour should be as simple as binding Ctrl-P to
up-history.

Ah, thanks! That's interesting.

However, there are more to pyrepl's line editing than this. If I
remember correctly, I could instert lines in the middle of a previously
typed code block. Quite annoying, I just couldn't get this behaviour
now. Maybe I have the wrong memories?

>My idea is that pyrepl should be ported to ruby eventually. Not only it
>has the mentioned features, but then we would have a totally accessible
>and controllable access to readline functionality in pure ruby, and one
>wouldn't need to meditate which other parts of readline should have a ruby
>binding for being able to implement this idea or that.

Wasn't someone looking at rewriting readline so that we could have a non
GPLed readline implemenation for Ruby? In addition to the licensing
issue, this would sure make lives easier for OS X users.

It's interesting. Is there any pointer to this? GPL, non-GPL, pyrepl
port, doing it from scratch: either case what would make sense then
would be doing it in pure ruby...

Btw, one of the reasons for creating pyrepl was to get readline features
under a non-GPL license. It's liberal license is an entry in the feature
list :slight_smile:

Csaba

···

On Thu, Mar 10, 2005 at 07:44:25AM +0900, Ben Giddings wrote:

Quoting csaba-ml@beastie.creo.hu, on Thu, Mar 10, 2005 at 08:29:54AM +0900:

> Wasn't someone looking at rewriting readline so that we could have a non
> GPLed readline implemenation for Ruby? In addition to the licensing
> issue, this would sure make lives easier for OS X users.

It's interesting. Is there any pointer to this? GPL, non-GPL, pyrepl
port, doing it from scratch: either case what would make sense then
would be doing it in pure ruby...

FYI - a readline-like library I used with the rc shell, worked well, to
my knowledge:

  Tools and applications

License:

   Vrl is copyright (C)1996-2000 by Gert-Jan Vons <gert-jan@bigfoot.com>.
   You can re-use this code if you want, as long as you give me credit.

Cheers,
Sam

Certainly it's good to hear of such things -- I knew only of libedit as
an alternative for readline --, it's just what's the ruby in it? When
you told, "Wasn't someone looking at rewriting readline so that we could
have a non GPLed readline implemenation for Ruby?", you meant that
someone writes an alternative of readline and then it's left to the ruby
community to wrap it? I tought someone does work on something directly
for ruby...

Btw, I heard of attempts of using libedit with ruby instead of readline.
I don't have the link right here, but it's easy to find it in Google's
group search on comp.lang.ruby. Someone had a patchset for this, but the
link to that was dead. Maybe that could be found with some more effort.

Csaba

···

On Thu, Mar 10, 2005 at 09:45:50AM +0900, Sam Roberts wrote:

Quoting csaba-ml@beastie.creo.hu, on Thu, Mar 10, 2005 at 08:29:54AM +0900:
> > Wasn't someone looking at rewriting readline so that we could have a non
> > GPLed readline implemenation for Ruby? In addition to the licensing
> > issue, this would sure make lives easier for OS X users.
>
> It's interesting. Is there any pointer to this? GPL, non-GPL, pyrepl
> port, doing it from scratch: either case what would make sense then
> would be doing it in pure ruby...

FYI - a readline-like library I used with the rc shell, worked well, to
my knowledge:

  Tools and applications