diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb index b8e9e0f..62d3559 100644 --- a/ext/readline/extconf.rb +++ b/ext/readline/extconf.rb @@ -83,6 +83,7 @@ have_readline_var("rl_point") /mswin|bccwin|mingw/ !~ RUBY_PLATFORM && have_readline_var("rl_event_hook") /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_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 423e585..81a3e51 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -61,6 +61,9 @@ static ID completion_proc, completion_case_fold; #if USE_INSERT_IGNORE_ESCAPE static ID id_orig_prompt, id_last_prompt; #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 @@ -1069,6 +1072,43 @@ 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) +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; +} + +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: @@ -1531,6 +1571,9 @@ Init_readline() completion_proc = rb_intern(COMPLETION_PROC); completion_case_fold = rb_intern(COMPLETION_CASE_FOLD); +#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", @@ -1589,6 +1632,10 @@ Init_readline() readline_s_get_filename_quote_characters, 0); rb_define_singleton_method(mReadline, "refresh_line", readline_s_refresh_line, 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 dcb83e9..df4cc7b 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -70,6 +70,8 @@ class TestReadline < Test::Unit::TestCase ["point"], ["set_screen_size", 1, 1], ["get_screen_size"], + ["special_prefixes=", "$"], + ["special_prefixes"], ] method_args.each do |method_name, *args| assert_raise(SecurityError, NotImplementedError, @@ -286,6 +288,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", @@ -293,6 +296,7 @@ class TestReadline < Test::Unit::TestCase "basic_quote_characters", "completer_quote_characters", "filename_quote_characters", + "special_prefixes", ] method_names.each do |method_name| begin