summaryrefslogtreecommitdiff
path: root/ext/readline
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 /ext/readline
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
Diffstat (limited to 'ext/readline')
-rw-r--r--ext/readline/extconf.rb1
-rw-r--r--ext/readline/readline.c77
2 files changed, 78 insertions, 0 deletions
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index 3a854d6609..7968de35f5 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 64922c6c0f..3b1a6c1d6a 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");