A patch for irb, where to submit?

C

Csaba Henk

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>
 
J

Joel VanderWerf

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 ....
 
C

Csaba Henk

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 ....

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." ;) Is it original?
</OT>

Csab
 
M

Michael C. Libby

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)...

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. :)

-Michael
 
C

Csaba Henk

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 :)
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
 
J

Joel VanderWerf

Csaba said:
<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." ;) 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.
 
T

trans. (T. Onoma)

| > <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." ;)
| > 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.
 
M

Mark Hubbart

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)...

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
 
N

Nicholas Van Weerdenburg

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
 
E

Eric Hodel

--Apple-Mail-4-731317465
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

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?

ruby-core mailing list:

(e-mail address removed)

--
Eric Hodel - (e-mail address removed) - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

--Apple-Mail-4-731317465
content-type: application/pgp-signature; x-mac-type=70674453;
name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB6EEVMypVHHlsnwQRAmE+AJ99oxlJQDgWNAui5QFedHOczgTdRwCeM//Y
U6qhQVaOjQ+4pSfIAtVY3Ik=
=Csxe
-----END PGP SIGNATURE-----

--Apple-Mail-4-731317465--
 
C

Csaba Henk

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

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

Csab
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top