mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/readline/readline.c (Init_readline): added
Readline.delete_text. [ruby-dev:45789] [Feature #6626] * ext/readline/extconf.rb: check for rl_delete_text() in Readline library. Thanks, Nobuyoshi Nakada, for the patch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ff7772062f
commit
56af74277c
4 changed files with 84 additions and 2 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon Jul 22 09:24:19 2013 Kouji Takao <kouji@takao7.net>
|
||||
|
||||
* ext/readline/readline.c (Init_readline): added
|
||||
Readline.delete_text. [ruby-dev:45789] [Feature #6626]
|
||||
* ext/readline/extconf.rb: check for rl_delete_text() in Readline library.
|
||||
|
||||
Thanks, Nobuyoshi Nakada, for the patch.
|
||||
|
||||
Mon Jul 22 03:15:54 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/date/date_parse.c (rfc2822_cb): check if wday is given, since it
|
||||
|
|
|
@ -93,4 +93,5 @@ readline.have_func("remove_history")
|
|||
readline.have_func("clear_history")
|
||||
readline.have_func("rl_redisplay")
|
||||
readline.have_func("rl_insert_text")
|
||||
readline.have_func("rl_delete_text")
|
||||
create_makefile("readline")
|
||||
|
|
|
@ -558,6 +558,58 @@ readline_s_insert_text(VALUE self, VALUE str)
|
|||
#define readline_s_insert_text rb_f_notimplement
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_RL_DELETE_TEXT)
|
||||
/*
|
||||
* call-seq:
|
||||
* Readline.delete_text([start[, length]]) -> self
|
||||
* Readline.delete_text(start..end) -> self
|
||||
* Readline.delete_text() -> self
|
||||
*
|
||||
* Delete text between start and end in the current line.
|
||||
*
|
||||
* See GNU Readline's rl_delete_text function.
|
||||
*
|
||||
* Raises SecurityError if $SAFE is 4.
|
||||
*/
|
||||
static VALUE
|
||||
readline_s_delete_text(int argc, VALUE *argv, VALUE self)
|
||||
{
|
||||
rb_secure(4);
|
||||
rb_check_arity(argc, 0, 2);
|
||||
if (rl_line_buffer) {
|
||||
char *p, *ptr = rl_line_buffer;
|
||||
long beg = 0, len = strlen(rl_line_buffer);
|
||||
struct RString fakestr;
|
||||
VALUE str = (VALUE)&fakestr;
|
||||
|
||||
fakestr.basic.flags = T_STRING | RSTRING_NOEMBED;
|
||||
fakestr.as.heap.ptr = ptr;
|
||||
fakestr.as.heap.len = len;
|
||||
rb_enc_associate(str, rb_locale_encoding());
|
||||
OBJ_FREEZE(str);
|
||||
if (argc == 2) {
|
||||
beg = NUM2LONG(argv[0]);
|
||||
len = NUM2LONG(argv[1]);
|
||||
num_pos:
|
||||
p = rb_str_subpos(str, beg, &len);
|
||||
if (!p) rb_raise(rb_eArgError, "invalid index");
|
||||
beg = p - ptr;
|
||||
}
|
||||
else if (argc == 1) {
|
||||
len = rb_str_strlen(str);
|
||||
if (!rb_range_beg_len(argv[0], &beg, &len, len, 1)) {
|
||||
beg = NUM2LONG(argv[0]);
|
||||
goto num_pos;
|
||||
}
|
||||
}
|
||||
rl_delete_text(rb_long2int(beg), rb_long2int(beg + len));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
#else
|
||||
#define readline_s_delete_text rb_f_notimplement
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_RL_REDISPLAY)
|
||||
/*
|
||||
* call-seq:
|
||||
|
@ -1747,6 +1799,8 @@ Init_readline()
|
|||
readline_s_get_pre_input_hook, 0);
|
||||
rb_define_singleton_method(mReadline, "insert_text",
|
||||
readline_s_insert_text, 1);
|
||||
rb_define_singleton_method(mReadline, "delete_text",
|
||||
readline_s_delete_text, -1);
|
||||
rb_define_singleton_method(mReadline, "redisplay",
|
||||
readline_s_redisplay, 0);
|
||||
rb_define_singleton_method(mReadline, "special_prefixes=",
|
||||
|
|
|
@ -317,6 +317,25 @@ class TestReadline < Test::Unit::TestCase
|
|||
assert_equal(str, Readline.line_buffer)
|
||||
assert_equal(get_default_internal_encoding,
|
||||
Readline.line_buffer.encoding)
|
||||
|
||||
Readline.delete_text(1, 3)
|
||||
assert_equal("t_insert_text", Readline.line_buffer)
|
||||
Readline.delete_text(11)
|
||||
assert_equal("t_insert_te", Readline.line_buffer)
|
||||
Readline.delete_text(-3...-1)
|
||||
assert_equal("t_inserte", Readline.line_buffer)
|
||||
Readline.delete_text(-3..-1)
|
||||
assert_equal("t_inse", Readline.line_buffer)
|
||||
Readline.delete_text(3..-3)
|
||||
assert_equal("t_ise", Readline.line_buffer)
|
||||
Readline.delete_text(3, 1)
|
||||
assert_equal("t_ie", Readline.line_buffer)
|
||||
Readline.delete_text(1..1)
|
||||
assert_equal("tie", Readline.line_buffer)
|
||||
Readline.delete_text(1...2)
|
||||
assert_equal("te", Readline.line_buffer)
|
||||
Readline.delete_text
|
||||
assert_equal("", Readline.line_buffer)
|
||||
rescue NotImplementedError
|
||||
end
|
||||
end if !/EditLine/n.match(Readline::VERSION)
|
||||
|
@ -358,7 +377,7 @@ class TestReadline < Test::Unit::TestCase
|
|||
assert_equal("hello", line, bug6601)
|
||||
ensure
|
||||
wo.close
|
||||
with_pipe {|r, w| w.write("\C-a\C-k\n")} # clear line_buffer
|
||||
Readline.delete_text
|
||||
Readline::HISTORY.clear
|
||||
end if !/EditLine/n.match(Readline::VERSION)
|
||||
|
||||
|
@ -384,7 +403,7 @@ class TestReadline < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
ensure
|
||||
with_pipe {|r, w| w.write("\C-a\C-k\n")} # clear line_buffer
|
||||
Readline.delete_text
|
||||
Readline::HISTORY.clear
|
||||
end if !/EditLine/n.match(Readline::VERSION)
|
||||
|
||||
|
|
Loading…
Reference in a new issue