#endif
#define abs(x) (((x) >= 0) ? (x) : -(x))
-extern HIST_ENTRY *saved_line_for_history;
+extern HIST_ENTRY *_rl_saved_line_for_history;
/* Functions imported from the rest of the library. */
extern int _rl_free_history_entry __P((HIST_ENTRY *));
rl_undo_list = (UNDO_LIST *)entry->data;
rl_end = line_len;
- if (saved_line_for_history)
- _rl_free_history_entry (saved_line_for_history);
- saved_line_for_history = (HIST_ENTRY *)NULL;
+ if (_rl_saved_line_for_history)
+ _rl_free_history_entry (_rl_saved_line_for_history);
+ _rl_saved_line_for_history = (HIST_ENTRY *)NULL;
}
/* Search the history list for STRING starting at absolute history position
{
int ret, old;
+ if (pos < 0)
+ return -1;
+
old = where_history ();
- history_set_pos (pos);
+ if (history_set_pos (pos) == 0)
+ return -1;
+ RL_SETSTATE(RL_STATE_SEARCH);
if (*string == '^')
ret = history_search_prefix (string + 1, dir);
else
ret = history_search (string, dir);
+ RL_UNSETSTATE(RL_STATE_SEARCH);
if (ret != -1)
ret = where_history ();
if (string == 0 || *string == '\0' || noninc_history_pos < 0)
{
- ding ();
+ rl_ding ();
return;
}
if (pos == -1)
{
/* Search failed, current history position unchanged. */
- maybe_unsave_line ();
+ rl_maybe_unsave_line ();
rl_clear_message ();
rl_point = 0;
- ding ();
+ rl_ding ();
return;
}
int saved_point, c;
char *p;
- maybe_save_line ();
+ rl_maybe_save_line ();
saved_point = rl_point;
/* Use the line buffer to read the search string. */
rl_message (p, 0, 0);
free (p);
-#define SEARCH_RETURN rl_restore_prompt (); return
+#define SEARCH_RETURN rl_restore_prompt (); RL_UNSETSTATE(RL_STATE_NSEARCH); return
+ RL_SETSTATE(RL_STATE_NSEARCH);
/* Read the search string. */
- while (c = rl_read_key ())
+ while (1)
{
+ RL_SETSTATE(RL_STATE_MOREINPUT);
+ c = rl_read_key ();
+ RL_UNSETSTATE(RL_STATE_MOREINPUT);
+
+ if (c == 0)
+ break;
+
switch (c)
{
case CTRL('H'):
case RUBOUT:
if (rl_point == 0)
{
- maybe_unsave_line ();
+ rl_maybe_unsave_line ();
rl_clear_message ();
rl_point = saved_point;
SEARCH_RETURN;
case CTRL('C'):
case CTRL('G'):
- maybe_unsave_line ();
+ rl_maybe_unsave_line ();
rl_clear_message ();
rl_point = saved_point;
- ding ();
+ rl_ding ();
SEARCH_RETURN;
default:
{
if (!noninc_search_string)
{
- ding ();
+ rl_ding ();
SEARCH_RETURN;
}
}
rl_restore_prompt ();
noninc_dosearch (noninc_search_string, dir);
+ RL_UNSETSTATE(RL_STATE_NSEARCH);
}
/* Search forward through the history list for a string. If the vi-mode
{
if (!noninc_search_string)
{
- ding ();
+ rl_ding ();
return (-1);
}
noninc_dosearch (noninc_search_string, 1);
{
if (!noninc_search_string)
{
- ding ();
+ rl_ding ();
return (-1);
}
noninc_dosearch (noninc_search_string, -1);
HIST_ENTRY *temp;
int ret, oldpos;
- maybe_save_line ();
+ rl_maybe_save_line ();
temp = (HIST_ENTRY *)NULL;
/* Search COUNT times through the history for a line whose prefix
/* If we didn't find anything at all, return. */
if (temp == 0)
{
- maybe_unsave_line ();
- ding ();
+ rl_maybe_unsave_line ();
+ rl_ding ();
/* If you don't want the saved history line (last match) to show up
in the line buffer after the search fails, change the #if 0 to
#if 1 */
rl_line_buffer[rl_end] = '\0';
}
#else
- rl_point = rl_history_search_len; /* maybe_unsave_line changes it */
+ rl_point = rl_history_search_len; /* rl_maybe_unsave_line changes it */
#endif
return 1;
}
strncpy (history_search_string + 1, rl_line_buffer, rl_point);
history_search_string[rl_point + 1] = '\0';
}
+ _rl_free_saved_history_line ();
}
/* Search forward in the history for the string of characters