mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
517f225306
commit
7c602ea07f
4 changed files with 88 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue