summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/readline/readline.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 7480feccc6..3114b38bd3 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -69,6 +69,7 @@ static ID id_orig_prompt, id_last_prompt;
#endif
static int (*history_get_offset_func)(int);
+static int (*history_replace_offset_func)(int);
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
static int readline_completion_append_character;
#endif
@@ -1308,7 +1309,7 @@ hist_set(VALUE self, VALUE index, VALUE str)
i += history_length;
}
if (i >= 0) {
- entry = replace_history_entry(i, RSTRING_PTR(str), NULL);
+ entry = replace_history_entry(history_replace_offset_func(i), RSTRING_PTR(str), NULL);
}
if (entry == NULL) {
rb_raise(rb_eIndexError, "invalid index");
@@ -1623,6 +1624,7 @@ Init_readline()
*/
rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
history_get_offset_func = history_get_offset_history_base;
+ history_replace_offset_func = history_get_offset_0;
#if defined HAVE_RL_LIBRARY_VERSION
version = rb_str_new_cstr(rl_library_version);
#if defined HAVE_CLEAR_HISTORY || defined HAVE_REMOVE_HISTORY
@@ -1632,7 +1634,12 @@ Init_readline()
if (history_get(history_get_offset_func(0)) == NULL) {
history_get_offset_func = history_get_offset_0;
}
-#if defined HAVE_CLEAR_HISTORY
+#ifdef HAVE_REPLACE_HISTORY_ENTRY
+ if (replace_history_entry(0, "a", NULL) == NULL) {
+ history_replace_offset_func = history_get_offset_history_base;
+ }
+#endif
+#ifdef HAVE_CLEAR_HISTORY
clear_history();
#else
{