]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
changes to history-search-forward, history-search backward to make the final history...
authorChet Ramey <chet.ramey@case.edu>
Mon, 21 Mar 2022 15:00:53 +0000 (11:00 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 21 Mar 2022 15:00:53 +0000 (11:00 -0400)
CWRU/CWRU.chlog
lib/readline/nls.c
lib/readline/readline.c
lib/readline/search.c

index 36e5bd1dc2cc48e0ff153361fda5a35c1a7812cf..1b1d006a30fb88d5802cff08ef0f414a2e3bb74b 100644 (file)
@@ -3364,3 +3364,25 @@ bashline.c
          string does *not* exist as a filename before removing those
          characters from the set that must be backslash-quoted. See change
          from 1/1/2022
+
+                                  3/18
+                                  ----
+lib/readline/search.c
+       - make_history_line_current: don't free rl_undo_list or
+         _rl_saved_line_for_history; don't unconditionally save the history
+         line. This reverts some of the changes to support setting the
+         history position in history-search-backward
+       - rl_history_search_internal: only free the saved history line if we
+         were the ones who created it
+
+                                  3/21
+                                  ----
+lib/readline/nls.c
+       - xmalloc.h: include for systems without setlocale(), so xfree has a
+         prototype. Report and fix from AndrĂ¡s Kucsma <r0maikx02b@gmail.com>
+
+lib/readline/search.c
+       - _rl_history_search_internal: use previous-history/next-history to
+         move to the found history line instead of directly calling
+         history_set_pos. This makes the behavior more similar to incremental
+         search
index fd093b6c3e14ea11ae467d505d667582fbe85ca0..8447c10f10317b7838134452428abebf9b5dc989 100644 (file)
@@ -1,6 +1,6 @@
 /* nls.c -- skeletal internationalization code. */
 
-/* Copyright (C) 1996-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.      
@@ -53,6 +53,7 @@
 #include "readline.h"
 #include "rlshell.h"
 #include "rlprivate.h"
+#include "xmalloc.h"
 
 static int utf8locale (char *);
 
index 888612c6bec6b30aa88da2e072f609a8ea4e0111..f11406146d3de2fd1a6d214ab70866ca87c614c9 100644 (file)
@@ -489,7 +489,11 @@ 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 1  /* XXX */
+  if (entry && rl_undo_list)
+#else
   if (entry && rl_undo_list && _rl_history_search_pos != where_history ())
+#endif
     {
       temp = savestring (the_line);
       rl_revert_line (1, 0);
index 22451663bbe42055e0c8ab9dd94d5d56d81548e5..22a044fe3d15d25b6366da902b57b90bb14ddb68 100644 (file)
@@ -84,17 +84,6 @@ static int _rl_nsearch_dispatch (_rl_search_cxt *, int);
 static void
 make_history_line_current (HIST_ENTRY *entry)
 {
-  /* 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_free_undo_list ();  
-
-  /* This will need to free the saved undo list associated with the original
-     (pre-search) line buffer. */
-  if (_rl_saved_line_for_history)
-    _rl_free_saved_history_line ();
-
-  rl_maybe_save_line ();
-
   /* 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);
@@ -107,6 +96,8 @@ make_history_line_current (HIST_ENTRY *entry)
        current editing buffer. */
     rl_free_undo_list ();
 #endif
+
+    /* XXX - free the saved line for history here? */
 }
 
 /* Search the history list for STRING starting at absolute history position
@@ -195,6 +186,7 @@ noninc_dosearch (char *string, int dir, int flags)
     history_set_pos (oldpos);
 
   make_history_line_current (entry);
+  /* make_history_line_current used to do this. */
   _rl_free_saved_history_line ();
 
   if (_rl_enable_active_region && ((flags & SF_PATTERN) == 0) && ind > 0 && ind < rl_end)
@@ -525,9 +517,11 @@ static int
 rl_history_search_internal (int count, int dir)
 {
   HIST_ENTRY *temp;
-  int ret, oldpos, newcol;
+  int ret, oldpos, newcol, had_saved_line, origpos;
   char *t;
 
+  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. */
@@ -563,6 +557,7 @@ rl_history_search_internal (int count, int dir)
   /* If we didn't find anything at all, return. */
   if (temp == 0)
     {
+      /* XXX - check had_saved_line here? */
       rl_maybe_unsave_line ();
       rl_ding ();
       /* If you don't want the saved history line (last match) to show up
@@ -585,11 +580,17 @@ 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 ();
+
   /* 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. */
-  rl_maybe_replace_line ();
-  history_set_pos (_rl_history_search_pos);    /* XXX */
+  if (_rl_history_search_pos < origpos)
+    rl_get_previous_history (origpos - _rl_history_search_pos, 0);
+  else
+    rl_get_next_history (_rl_history_search_pos - origpos, 0);
 
   /* decide where to put rl_point -- need to change this for pattern search */
   if (_rl_history_search_flags & ANCHORED_SEARCH)