summaryrefslogtreecommitdiff
path: root/ext/readline
diff options
context:
space:
mode:
authorkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-10 12:13:18 +0000
committerkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-10 12:13:18 +0000
commit89fd52131942b4f5365194344ce32346ace5f112 (patch)
treee749b59f22d3a9e629a3b6b179494241ac83c2f6 /ext/readline
parent5d8b373b05d8710a397c2b8da0406847c5e883ec (diff)
* ext/readline/extconf.rb: checked rl_line_buffer and rl_point in
readline. * ext/readline/readline.c (readline_s_get_line_buffer): new method. (readline_s_get_point): new method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/readline')
-rw-r--r--ext/readline/README.ja27
-rw-r--r--ext/readline/extconf.rb2
-rw-r--r--ext/readline/readline.c52
3 files changed, 75 insertions, 6 deletions
diff --git a/ext/readline/README.ja b/ext/readline/README.ja
index 3c6c6f3..5c8e0da 100644
--- a/ext/readline/README.ja
+++ b/ext/readline/README.ja
@@ -167,16 +167,31 @@ Readline.completion_case_fold -> bool
ユーザの入力を補完する際、大文字と小文字を区別する/しないを取得します。
bool が真ならば区別しません。bool が偽ならば区別します。
- なお、Readline.completion_case_fold= メソッドで指定したオブジェクトを
- そのまま取得するので、次のような動作をします。
+ なお、Readline.completion_case_fold= メソッドで指定したオブジェクトを
+ そのまま取得するので、次のような動作をします。
- require "readline"
-
- Readline.completion_case_fold = "This is a String."
- p Readline.completion_case_fold # => "This is a String."
+ require "readline"
+
+ Readline.completion_case_fold = "This is a String."
+ p Readline.completion_case_fold # => "This is a String."
$SAFE が 4 の場合、例外 SecurityError が発生します。
+Readline.line_buffer -> string
+
+ 入力中の行全体を返します。complete_proc の中で使用することを想定し
+ ています。Readline.line_buffer の長さは GNU Readline の rl_end 変数の
+ 値と一致します。
+
+Readline.point -> int
+
+ 現在のカーソルの位置を返します。
+ Readline モジュールは補完対象の単語の開始位置の情報を提供していません。
+ しかしながら、 completion_proc の中で入力した単語 text と
+ Readline.point を使用することで開始位置を導くことができます。
+
+ 開始位置 = 入力した単語の長さ - Readline.point
+
Readline.vi_editing_mode -> nil
編集モードを vi モードにします。
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index faf539f..d3ccca6 100644
--- a/ext/readline/extconf.rb
+++ b/ext/readline/extconf.rb
@@ -60,6 +60,8 @@ have_readline_var("rl_filename_quote_characters")
have_readline_var("rl_attempted_completion_over")
have_readline_var("rl_library_version")
have_readline_var("rl_editing_mode")
+have_readline_var("rl_line_buffer")
+have_readline_var("rl_point")
# workaround for native windows.
/mswin|bccwin|mingw/ !~ RUBY_PLATFORM && have_readline_var("rl_event_hook")
have_readline_func("rl_cleanup_after_signal")
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index d86a714..d54a280 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -398,6 +398,54 @@ readline_s_get_completion_case_fold(VALUE self)
return rb_attr_get(mReadline, completion_case_fold);
}
+#ifdef HAVE_RL_LINE_BUFFER
+/*
+ * call-seq:
+ * Readline.line_buffer -> string
+ *
+ * Returns the full line that is being edited. This is useful from
+ * within the complete_proc for determining the context of the
+ * completion request.
+ *
+ * The length of +Readline.line_buffer+ and GNU Readline's rl_end are
+ * same.
+ */
+static VALUE
+readline_s_get_line_buffer(VALUE self)
+{
+ rb_secure(4);
+ if (rl_line_buffer == NULL)
+ return Qnil;
+ return rb_tainted_str_new2(rl_line_buffer);
+}
+#else
+#define readline_s_get_line_buffer rb_f_notimplement
+#endif
+
+#ifdef HAVE_RL_POINT
+/*
+ * call-seq:
+ * Readline.point -> int
+ *
+ * Returns the index of the current cursor position in
+ * +Readline.line_buffer+.
+ *
+ * The index in +Readline.line_buffer+ which matches the start of
+ * input-string passed to completion_proc is computed by subtracting
+ * the length of input-string from +Readline.point+.
+ *
+ * start = (the length of input-string) - Readline.point
+ */
+static VALUE
+readline_s_get_point(VALUE self)
+{
+ rb_secure(4);
+ return INT2NUM(rl_point);
+}
+#else
+#define readline_s_get_point rb_f_notimplement
+#endif
+
static char **
readline_attempted_completion_function(const char *text, int start, int end)
{
@@ -1262,6 +1310,10 @@ Init_readline()
readline_s_set_completion_case_fold, 1);
rb_define_singleton_method(mReadline, "completion_case_fold",
readline_s_get_completion_case_fold, 0);
+ rb_define_singleton_method(mReadline, "line_buffer",
+ readline_s_get_line_buffer, 0);
+ rb_define_singleton_method(mReadline, "point",
+ readline_s_get_point, 0);
rb_define_singleton_method(mReadline, "set_screen_size",
readline_s_set_screen_size, 2);
rb_define_singleton_method(mReadline, "get_screen_size",