Readline Module and completion_proc

Dear rubyists,

I’ve been playing with the Readline module for the last hours and i’d
like to make a few suggestions:

In the documenation from current CVS[1], it says that completion proc
is a Proc object that should take a string as input parameter.

In fact and contrary to what I thought would be more logical, this object
only receives the last “part of word” typed by the user ie if I type “cd
pro” and then press , i receive “pro” but not the "cd " string
before. As this is used to guess what completion we should offer to the
user, I thought it would be better for the Proc object to also receive
this part of the input (if I know my user is going to cd to somewhere, I
can complete only on matching folders for example).

so completion_proc would be
Readline.complretion_proc = Proc.new{ |last_word, beginning| … }

with last_word being “pro” and beginning "cd " in my example.

Maybe this mail should have been directed to ruby-core. It’s not clear
yet in my mind what belongs to -talk and what belongs to -core.

Let me know if this is some kind of possible enhancement

My ruby is:
% ruby -v
ruby 1.6.7 (2002-03-19) [i386-linux]

1:http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/ext/readline/README?rev=1.1.1.1.6.1&content-type=text/x-cvsweb-markup&only_with_tag=ruby_1_6

Cheers,

···


Pierre Baillet
Linux is user friendly. Linux is not idiot friendly
If you don’t understand that, use Windows

so completion_proc would be
  Readline.complretion_proc = Proc.new{ |last_word, beginning| ... }

Well, completion_proc is just an interface to the function
rl_attempted_completion_function() (see the doc of readline(3))

Guy Decoux

Hello rubylovers,

following this thread, i’ve written a quick patch for readline.c which
allows the Proc object to receive a new supplementaty variable which
contains the current buffer for the input line:

Readline.completion_proc = Proc.new{ |to_complete, current_line| … }

This patch breaks backward compatibility with previous scripts using
Readline but allows greater flexibility concerning the use of Readline
in general.

I don’t know what is the best way to submit a patch, so please let me
know if there is a more formal way. If any guru (Matz, maybe ?!) has a
look at my patch, I’ll be glad to hear your comments. If you are not a
guru, comment anyway, i’d love some feedback!

Cheers,

readline.patch (533 Bytes)

···


Pierre Baillet
Emacs, not just a way of life but a complete waste of disk space
Alan Cox

Hello –

so completion_proc would be
Readline.complretion_proc = Proc.new{ |last_word, beginning| … }

Well, completion_proc is just an interface to the function
rl_attempted_completion_function() (see the doc of readline(3))

Guy, you are perfectly right,
however I think it should be possible to replace the call

ary = rb_funcall(proc, rb_intern(“call”), 1, rb_tainted_str_new2(text));
in
static char **
readline_attempted_completion_function(text, start, end)
in
ext/readline/readline.c

with a call that also provides rl_line_buffer to the Proc.

OR

maybe extending the Readline module to provide read access to
rl_line_buffer at any time during the use of Readline.

It don’t which one is easier to implement.

But as a matter of fact, C coders have access to this rl_line_buffer
variable even when they are in the completion callback, haven’t they ?

Cheers,

···

On Thu, Oct 31, 2002, ts wrote:

Pierre Baillet
Quand on ne sait pas où on va, il faut y aller… et le plus vite possible.
Devise Shadok

But as a matter of fact, C coders have access to this rl_line_buffer
variable even when they are in the completion callback, haven't they ?

Yes, they have access

Guy Decoux

Cheers,

Pierre Baillet
Quand on ne sait pas où on va, il faut y aller… et le plus vite possible.
Devise Shadok

Translated through GavinFish: “When you don’t know where you’re going, you must
go there … as fast as possible.”

What does that mean?

Gavin

···

From: “Pierre Baillet” oct@zoy.org

Hello,

I think that this means exactly what it says. Shadoks (from a french
cartoon) are not know for their cleverness.

···

On Fri, Nov 01, 2002, Gavin Sinclair wrote:

From: “Pierre Baillet” oct@zoy.org

Cheers,

Pierre Baillet
Quand on ne sait pas où on va, il faut y aller… et le plus vite possible.
Devise Shadok

Translated through GavinFish: “When you don’t know where you’re going, you must
go there … as fast as possible.”

What does that mean?

Gavin


Pierre Baillet
Emacs, not just a way of life but a complete waste of disk space
Alan Cox