fix for history-search-backward after previous-history clearing the undo list

This commit is contained in:
Chet Ramey
2022-04-04 09:40:49 -04:00
parent 8f68f9f0ff
commit 505f60f94c
11 changed files with 81 additions and 25 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
/* histlib.h -- internal definitions for the history library. */
/* Copyright (C) 1989-2009,2021 Free Software Foundation, Inc.
/* Copyright (C) 1989-2009,2021-2022 Free Software Foundation, Inc.
This file contains the GNU History Library (History), a set of
routines for managing the text of previously typed lines.
@@ -84,6 +84,7 @@ extern int _hs_history_patsearch (const char *, int, int);
/* history.c */
extern void _hs_replace_history_data (int, histdata_t *, histdata_t *);
extern int _hs_at_end_of_history (void);
/* histfile.c */
extern void _hs_append_history_line (int, const char *);
+7
View File
@@ -165,6 +165,13 @@ history_set_pos (int pos)
history_offset = pos;
return (1);
}
/* Are we currently at the end of the history list? */
int
_hs_at_end_of_history (void)
{
return (the_history == 0 || history_offset == history_length);
}
/* Return the current history array. The caller has to be careful, since this
is the actual array of data, and could be bashed or made corrupt easily.
+7 -1
View File
@@ -388,17 +388,23 @@ _rl_free_saved_history_line (void)
{
if (rl_undo_list && rl_undo_list == (UNDO_LIST *)_rl_saved_line_for_history->data)
rl_undo_list = 0;
/* Have to free this separately because _rl_free_history entry can't:
it doesn't know whether or not this has application data. Only the
callers that know this is _rl_saved_line_for_history can know that
it's an undo list. */
#if defined (HISTORY_SEARCH_SETS_HISTPOS)
if (_rl_saved_line_for_history->data)
{
orig = rl_undo_list;
rl_undo_list = _rl_saved_line_for_history->data;
rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data;
rl_free_undo_list ();
rl_undo_list = orig;
}
#else
if (_rl_saved_line_for_history->data)
_rl_free_undo_list ((UNDO_LIST *)_rl_saved_line_for_history->data);
#endif
_rl_free_history_entry (_rl_saved_line_for_history);
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
}
+1 -1
View File
@@ -492,7 +492,7 @@ readline_internal_teardown (int eof)
/* We don't want to do this if we executed functions that call
history_set_pos to set the history offset to the line containing the
non-incremental search string. */
#if HISTORY_SEARCH_SETS_HISTPOS
#if defined (HISTORY_SEARCH_SETS_HISTPOS)
if (entry && rl_undo_list && _rl_history_search_pos != where_history ())
#else
if (entry && rl_undo_list)
+33 -8
View File
@@ -84,6 +84,15 @@ static int _rl_nsearch_dispatch (_rl_search_cxt *, int);
static void
make_history_line_current (HIST_ENTRY *entry)
{
#if !defined (HISTORY_SEARCH_SETS_HISTPOS)
UNDO_LIST *xlist;
xlist = _rl_saved_line_for_history ? (UNDO_LIST *)_rl_saved_line_for_history->data : 0;
/* At this point, rl_undo_list points to a private search string list. */
if (rl_undo_list && rl_undo_list != (UNDO_LIST *)entry->data && rl_undo_list != xlist)
rl_free_undo_list ();
#endif
/* Now we create a new undo list with a single insert for this text.
WE DON'T CHANGE THE ORIGINAL HISTORY ENTRY UNDO LIST */
_rl_replace_text (entry->line, 0, rl_end);
@@ -97,7 +106,16 @@ make_history_line_current (HIST_ENTRY *entry)
rl_free_undo_list ();
#endif
/* XXX - free the saved line for history here? */
#if !defined (HISTORY_SEARCH_SETS_HISTPOS)
/* This will need to free the saved undo list associated with the original
(pre-search) line buffer.
XXX - look at _rl_free_saved_history_line and consider calling it if
rl_undo_list != xlist (or calling rl_free_undo list directly on
_rl_saved_line_for_history->data) */
if (_rl_saved_line_for_history)
_rl_free_history_entry (_rl_saved_line_for_history);
_rl_saved_line_for_history = (HIST_ENTRY *)NULL;
#endif
}
/* Search the history list for STRING starting at absolute history position
@@ -186,8 +204,10 @@ noninc_dosearch (char *string, int dir, int flags)
history_set_pos (oldpos);
make_history_line_current (entry);
#if !defined (HISTORY_SEARCH_SETS_HISTPOS)
/* make_history_line_current used to do this. */
_rl_free_saved_history_line ();
#endif
if (_rl_enable_active_region && ((flags & SF_PATTERN) == 0) && ind > 0 && ind < rl_end)
{
@@ -517,16 +537,21 @@ static int
rl_history_search_internal (int count, int dir)
{
HIST_ENTRY *temp;
int ret, oldpos, newcol;
UNDO_LIST *origlist;
int ret, oldpos, newcol, had_saved_line, origpos;
int had_saved_line, origpos;
char *t;
#if defined (HISTORY_SEARCH_SETS_HISTPOS)
origpos = where_history ();
had_saved_line = _rl_saved_line_for_history != 0;
rl_maybe_save_line ();
/* This will either be restored from the saved line or set from the
found history line. */
rl_undo_list = 0;
#else
rl_maybe_save_line ();
#endif
temp = (HIST_ENTRY *)NULL;
/* Search COUNT times through the history for a line matching
@@ -581,16 +606,16 @@ rl_history_search_internal (int count, int dir)
/* Copy the line we found into the current line buffer. */
make_history_line_current (temp);
/* Free the saved history line corresponding to the search string */
if (had_saved_line == 0)
_rl_free_saved_history_line ();
#if HISTORY_SEARCH_SETS_HISTPOS
/* XXX - can't make this work the way I want it to yet. Too much assumes
that rl_undo_list corresponds to the current history entry's undo list,
especially the stuff in maybe_save_line and especially maybe_replace_line.
Leaving it commented out for now. */
#if defined (HISTORY_SEARCH_SETS_HISTPOS)
/* Free the saved history line corresponding to the search string */
if (had_saved_line == 0)
_rl_free_saved_history_line ();
/* Make sure we set the current history position to the last line found so
we can do things like operate-and-get-next from here. This is similar to
how incremental search behaves. */
@@ -644,7 +669,7 @@ rl_history_search_reinit (int flags)
strncpy (history_search_string + sind, rl_line_buffer, rl_point);
history_search_string[rl_point + sind] = '\0';
}
_rl_free_saved_history_line ();
_rl_free_saved_history_line (); /* XXX rl_undo_list? */
}
/* Search forward in the history for the string of characters