summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-02 00:47:57 +0000
committerkouji <kouji@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-02 00:47:57 +0000
commit7c602ea07f5b89eac209b6c6a53f695e12f9f0ce (patch)
treef28a5383be7b98b8ac7e019889db79e44a4f0392
parent517f225306008bc31253726afee606dff7baba6d (diff)
* ext/readline/readline.c (Readline.special_prefixes=)
(Readline.special_prefixes): new function. An original patch was created by nagachika. [Feature #5784] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/readline/extconf.rb1
-rw-r--r--ext/readline/readline.c77
-rw-r--r--test/readline/test_readline.rb4
4 files changed, 88 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c2d49bd256e..684fc5f1fb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed May 2 09:46:09 2012 Kouji Takao <kouji@takao7.net>
+
+ * ext/readline/readline.c (Readline.special_prefixes=)
+ (Readline.special_prefixes): new function. An original patch was
+ created by nagachika. [Feature #5784]
+
Tue May 1 22:18:45 2012 Kouji Takao <kouji.takao@gmail.com>
* ext/readline/readline.c (Readline.pre_input_hook)
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index 3a854d6609c..7968de35f50 100644
--- a/ext/readline/extconf.rb
+++ b/ext/readline/extconf.rb
@@ -84,6 +84,7 @@ have_readline_var("rl_point")
/mswin|bccwin|mingw/ !~ RUBY_PLATFORM && have_readline_var("rl_catch_sigwinch")
/mswin|bccwin|mingw/ !~ RUBY_PLATFORM && have_readline_var("rl_catch_signals")
have_readline_var("rl_pre_input_hook")
+have_readline_var("rl_special_prefixes")
have_readline_func("rl_cleanup_after_signal")
have_readline_func("rl_free_line_state")
have_readline_func("rl_clear_signals")
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 64922c6c0f9..3b1a6c1d6ad 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -64,6 +64,9 @@ static ID id_orig_prompt, id_last_prompt;
#if defined(HAVE_RL_PRE_INPUT_HOOK)
static ID id_pre_input_hook;
#endif
+#if defined(HAVE_RL_SPECIAL_PREFIXES)
+static ID id_special_prefixes;
+#endif
#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION
# define rl_filename_completion_function filename_completion_function
@@ -1179,6 +1182,73 @@ readline_s_get_completer_word_break_characters(VALUE self, VALUE str)
#define readline_s_get_completer_word_break_characters rb_f_notimplement
#endif
+#if defined(HAVE_RL_SPECIAL_PREFIXES)
+/*
+ * call-seq:
+ * Readline.special_prefixes = string
+ *
+ * Sets the list of characters that are word break characters, but
+ * should be left in text when it is passed to the completion
+ * function. Programs can use this to help determine what kind of
+ * completing to do. For instance, Bash sets this variable to "$@" so
+ * that it can complete shell variables and hostnames.
+ *
+ * See GNU Readline's rl_special_prefixes variable.
+ *
+ * Raises NotImplementedError if the using readline library does not support.
+ *
+ * Raises SecurityError exception if $SAFE is 4.
+ */
+static VALUE
+readline_s_set_special_prefixes(VALUE self, VALUE str)
+{
+ rb_secure(4);
+ if (!NIL_P(str)) {
+ OutputStringValue(str);
+ str = rb_str_dup_frozen(str);
+ RBASIC(str)->klass = 0;
+ }
+ rb_ivar_set(mReadline, id_special_prefixes, str);
+ if (NIL_P(str)) {
+ rl_special_prefixes = NULL;
+ }
+ else {
+ rl_special_prefixes = RSTRING_PTR(str);
+ }
+ return self;
+}
+
+/*
+ * call-seq:
+ * Readline.special_prefixes -> string
+ *
+ * Gets the list of characters that are word break characters, but
+ * should be left in text when it is passed to the completion
+ * function.
+ *
+ * See GNU Readline's rl_special_prefixes variable.
+ *
+ * Raises NotImplementedError if the using readline library does not support.
+ *
+ * Raises SecurityError exception if $SAFE is 4.
+ */
+static VALUE
+readline_s_get_special_prefixes(VALUE self)
+{
+ VALUE str;
+ rb_secure(4);
+ str = rb_ivar_get(mReadline, id_special_prefixes);
+ if (!NIL_P(str)) {
+ str = rb_str_dup_frozen(str);
+ RBASIC(str)->klass = rb_cString;
+ }
+ return str;
+}
+#else
+#define readline_s_set_special_prefixes rb_f_notimplement
+#define readline_s_get_special_prefixes rb_f_notimplement
+#endif
+
#ifdef HAVE_RL_BASIC_QUOTE_CHARACTERS
/*
* call-seq:
@@ -1645,6 +1715,9 @@ Init_readline()
#if defined(HAVE_RL_PRE_INPUT_HOOK)
id_pre_input_hook = rb_intern("pre_input_hook");
#endif
+#if defined(HAVE_RL_SPECIAL_PREFIXES)
+ id_special_prefixes = rb_intern("special_prefixes");
+#endif
mReadline = rb_define_module("Readline");
rb_define_module_function(mReadline, "readline",
@@ -1711,6 +1784,10 @@ Init_readline()
readline_s_insert_text, 1);
rb_define_singleton_method(mReadline, "redisplay",
readline_s_redisplay, 0);
+ rb_define_singleton_method(mReadline, "special_prefixes=",
+ readline_s_set_special_prefixes, 1);
+ rb_define_singleton_method(mReadline, "special_prefixes",
+ readline_s_get_special_prefixes, 0);
#if USE_INSERT_IGNORE_ESCAPE
CONST_ID(id_orig_prompt, "orig_prompt");
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index 98922a21206..107cddface4 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -52,6 +52,8 @@ class TestReadline < Test::Unit::TestCase
["pre_input_hook"],
["insert_text", ""],
["redisplay"],
+ ["special_prefixes=", "$"],
+ ["special_prefixes"],
]
method_args.each do |method_name, *args|
assert_raise(SecurityError, NotImplementedError,
@@ -309,6 +311,7 @@ class TestReadline < Test::Unit::TestCase
# basic_quote_characters
# completer_quote_characters
# filename_quote_characters
+ # special_prefixes
def test_some_characters_methods
method_names = [
"basic_word_break_characters",
@@ -316,6 +319,7 @@ class TestReadline < Test::Unit::TestCase
"basic_quote_characters",
"completer_quote_characters",
"filename_quote_characters",
+ "special_prefixes",
]
method_names.each do |method_name|
begin