Project

General

Profile

Actions

Feature #1095

closed

Readline.completion_proc = nil を許可する。

Added by kouji (Kouji Takao) about 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
[ruby-dev:37880]

Description

=begin
高尾宏治です。

Readline.readlineの補完候補を取得する Proc を Readline.completion_proc= で指定できます。
しかし、補完候補を取得する処理をデフォルトのものに戻す方法がありません。
Readline.completion_proc に nil をセットできればデフォルトの挙動になるので、
それを許可しようと思います。以下のような記述ができるようになります。

begin
Readline.completion_proc = Proc.new { |s|
...
}
s = Readline.readline
ensure
Readline.completion_proc = nil
end

現在は、Readline.completion_proc= メソッドの中で、
引き数で指定されたオブジェクトが call メソッドをもっているかどうかチェックしているので、

Readline.completion_proc = nil

で ArgumentError 例外が発生します。
nilの場合は特別扱いして、completion_proc に代入できるようにしようと思います。
いかがでしょうか。

Index: readline.c

--- readline.c (revision 21997)
+++ readline.c (working copy)
@@ -304,6 +304,8 @@

  • should take input-string, and return an array of completion
  • candidates.
    • Set default if +proc+ is nil.
    • Raises ArgumentError exception if +proc+ does not respond to call method.
    • Raises SecurityError exception if $SAFE is 4.
      @@ -312,7 +314,7 @@
      readline_s_set_completion_proc(VALUE self, VALUE proc)
      {
      rb_secure(4);
  • if (!rb_respond_to(proc, rb_intern("call")))
  • if (!NIL_P(proc) && !rb_respond_to(proc, rb_intern("call")))
    rb_raise(rb_eArgError, "argument must respond to `call'");
    return rb_ivar_set(mReadline, completion_proc, proc);
    }
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0