A patch for irb, where to submit?

Hi!

I hacked irb/completion.rb such that now it does filename completion (not
just ruby expression completion). (A word is completed as a filename if it
begins with ./, ../, /, or ~/ .) I think this feature is close to being
essential for those who tend using irb as a better shell (like me)...

Where can I submit it "officially" as patch?

It would be stupid to keep you from using it 'till the above question gets
answered, so here it is (don't be frightened from the 1.9 in the path of the
source file, irb/completion.rb hasn't changed for ages).

<patch>
--- /usr/lib/ruby/1.9/irb/completion.rb 2004-11-29 00:58:22.000000000 -0700
+++ /home/csaba/ruby/irb-completion-hacked.rb 2005-01-13
21:47:55.623699056 -0700
@@ -34,12 +34,36 @@
       "yield",
     ]
       
+ FS = File::SEPARATOR

···

+
+ def self.filecomp(input)
+ fsq = Regexp.quote FS
+ input =~ Regexp.new("(.*)#{fsq}([^#{fsq}]*)$")
+ d, f = $1, $2
+ d.empty? and d = FS
+ d[0] == ?~ and d = File.expand_path(d)
+ can =
+ begin
+ Dir.entries(d).select{|e| e.index(f) == 0 }.map { |e|
+ de=File.join(d,e)
+ de + (File.directory?(de) ? FS : "")
+ }
+ rescue => err
+ warn "Error while doing filename completion: #{err}"
+ end
+ can || []
+ end
+
+
     CompletionProc = proc { |input|
       bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
       
# puts "input: #{input}"

       case input
+ when Regexp.new("^(?:|\.|\.\.|~.*)" + FS)
+ # Smells like a filename
+ filecomp input
       when /^(\/[^\/]*\/)\.([^.]*)$/
        # Regexp
        receiver = $1
</patch>

I wonder if it is possible to restructure completion.rb so that instead of patches, this sort of thing can just be a module that one invokes in one's .irbrc ....

Wow. I've never had method-name completion until I read this post and thought
"but I already have filename completion!" Then I actually RTFM and find that
to get method-name completion I have to require 'irb/completion'.

Which, of course, clobbers filename completion. This patch will be very
nice for keeping filename completion around. So thank you!

How about doing the filename matching if the word starts with " or ' ?

When I'm doing path work I tend to avoid the use of ./, ../, and ~/,
opting for either explicitly declaring a path or just assuming that we
have already chdir'ed to the correct directory.

Just wanted to inject the idea into the discussion, obviously I'll be
patching the patch to do it on my own system. :slight_smile:

-Michael

···

On Fri, Jan 14, 2005 at 02:01:14PM +0900, Csaba Henk wrote:

I hacked irb/completion.rb such that now it does filename completion (not
just ruby expression completion). (A word is completed as a filename if it
begins with ./, ../, /, or ~/ .) I think this feature is close to being
essential for those who tend using irb as a better shell (like me)...

Thank you! I have missed the filename completion ever since I turned
on autocompletion, just never bothered to do anything about it. I'll
be trying it out as soon as I get the chance. I, too, often use irb as
a shell.

cheers,
Mark

···

On Fri, 14 Jan 2005 14:01:14 +0900, Csaba Henk <csaba@phony_for_avoiding_spam.org> wrote:

Hi!

I hacked irb/completion.rb such that now it does filename completion (not
just ruby expression completion). (A word is completed as a filename if it
begins with ./, ../, /, or ~/ .) I think this feature is close to being
essential for those who tend using irb as a better shell (like me)...

ruby-core mailing list:

ruby-core@ruby-lang.org

PGP.sig (186 Bytes)

···

On 13 Jan 2005, at 21:01, Csaba Henk wrote:

Hi!

I hacked irb/completion.rb such that now it does filename completion (not
just ruby expression completion). (A word is completed as a filename if it
begins with ./, ../, /, or ~/ .) I think this feature is close to being
essential for those who tend using irb as a better shell (like me)...

Where can I submit it "officially" as patch?

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Well, as for now you can require 'irb/completion' and the completion
proc defined there will be "mounted" from that on.

An alternative to this could be replacing the completion proc with a proc
factory method and a "mount" method which attaches the produced proc object as
completor.

But to do this, first you have to have a nice pool of requirements (from the
actual users' side) and design ideas along which you would implement the
factory method. And it's all not a hot topic, this seems to be none's itch
to scratch. So what then... can you come up with any different scheme for
completion which might be worth for a refactorization?

I propose my patch because its a humble hack: adds some functionality which
might come handy but doesn't break anything (the chances that you'd need
to complete those filename-beginnigs in a different way in your interactive
code are practically zero). No rocket science, just a slight makeup.

<OT>
Well, it's quite a surprise that you are the one who answered my post...
Just before I read your answer, I decided that I give you my "quote of the week"
award, due to an old post of you, to which I bumped on accidentally... It
says: "If we ever find intelligent creatures somewhere else in the universe,
they will know pi, e, and some dialect of LISP." :wink: Is it original?
</OT>

Csab

···

On 2005-01-14, Joel VanderWerf <vjoel@PATH.Berkeley.EDU> wrote:

I wonder if it is possible to restructure completion.rb so that instead
of patches, this sort of thing can just be a module that one invokes in
one's .irbrc ....

Wow. I've never had method-name completion until I read this post and thought
"but I already have filename completion!" Then I actually RTFM and find that
to get method-name completion I have to require 'irb/completion'.

Which, of course, clobbers filename completion. This patch will be very
nice for keeping filename completion around. So thank you!

I'm glad to have at least one user :slight_smile:

How about doing the filename matching if the word starts with " or ' ?

When I'm doing path work I tend to avoid the use of ./, ../, and ~/,
opting for either explicitly declaring a path or just assuming that we
have already chdir'ed to the correct directory.

Actually my implemetation doesn't care about quotes. It relies only on those
special beginnings (I'd neither begin filenames that way, hadn't my filename
completion relied on them). The reason for doing it so is that this
behaviour was the simplest to code; now I quite like it this way. But feel
free to improve my solution -- I might prefer then your one.

Csab

···

On 2005-01-14, Michael C. Libby <mcl-ruby-talk@andsoforth.com> wrote:

Ah, thx.

Csab

···

On 2005-01-14, Eric Hodel <drbrain@segment7.net> wrote:

Where can I submit it "officially" as patch?

ruby-core mailing list:

ruby-core@ruby-lang.org

Csaba Henk wrote:

<OT>
Well, it's quite a surprise that you are the one who answered my post...
Just before I read your answer, I decided that I give you my "quote of the week"
award, due to an old post of you, to which I bumped on accidentally... It
says: "If we ever find intelligent creatures somewhere else in the universe, they will know pi, e, and some dialect of LISP." :wink: Is it original?
</OT>

I didn't even remember saying that until I looked it up on google, and there is was in the ruby-talk archives. Maybe it's original in phrasing, but surely others have said more or less the same...

Thanks for not quoting the rest of it. It would just feed P*th*n flames.

It has certainly been said before. Who originated the statement I do not know.
It would be interesting to find out.

It was once said that Ruby too borders on this type of universality. Though I
think that's a bit of a stretch. Nonetheless we can be pretty sure that
dialects of Assembly, Lisp, Forth and Prolog are indeed being used or have
been used by I.A. (assuming they exist/had existed).

T.

···

On Friday 14 January 2005 12:50 pm, Joel VanderWerf wrote:

Csaba Henk wrote:
> <OT>
> Well, it's quite a surprise that you are the one who answered my post...
> Just before I read your answer, I decided that I give you my "quote of
> the week" award, due to an old post of you, to which I bumped on
> accidentally... It says: "If we ever find intelligent creatures somewhere
> else in the universe, they will know pi, e, and some dialect of LISP." :wink:
> Is it original? </OT>

Well, that certainly couldn't make it into my "qoute of the week" even if
Python ... :wink:

Csab

···

On 2005-01-14, Joel VanderWerf <vjoel@PATH.Berkeley.EDU> wrote:

Thanks for not quoting the rest of it. It would just feed P*th*n flames.

Ruby has been described as a dialog of lisp, with infix notation.

Macros and access to the AST are probably deal-breakers though for
being a fair statement.

Still, reading about Lisp was as helpful for my understanding Ruby
then reading about Ruby. Blocks and expressions enabling succinctness
and bottom-up programming was the most enlightening "ruby vs. python"
insight I had.

What makes lisp different:
http://www.paulgraham.com/diff.html

Succinctness is Power
http://www.paulgraham.com/power.html

Programming Bottom Up
http://www.paulgraham.com/progbot.html

···

On Sat, 15 Jan 2005 03:03:14 +0900, trans. (T. Onoma) <transami@runbox.com> wrote:

On Friday 14 January 2005 12:50 pm, Joel VanderWerf wrote:
> Csaba Henk wrote:
> > <OT>
> > Well, it's quite a surprise that you are the one who answered my post...
> > Just before I read your answer, I decided that I give you my "quote of
> > the week" award, due to an old post of you, to which I bumped on
> > accidentally... It says: "If we ever find intelligent creatures somewhere
> > else in the universe, they will know pi, e, and some dialect of LISP." :wink:
> > Is it original? </OT>

It has certainly been said before. Who originated the statement I do not know.
It would be interesting to find out.

It was once said that Ruby too borders on this type of universality. Though I
think that's a bit of a stretch. Nonetheless we can be pretty sure that
dialects of Assembly, Lisp, Forth and Prolog are indeed being used or have
been used by I.A. (assuming they exist/had existed).

T.

--
Nicholas Van Weerdenburg