Approved by Jim Blandy:
[deliverable/binutils-gdb.git] / readline / isearch.c
index 7decf9595b0f5aed3a50c7d95ae4882b57dc9aef..952c10ddf8eab91c65649f8200d5d4d0c8b7104b 100644 (file)
@@ -12,7 +12,7 @@
 
    The Library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 1, or (at your option)
+   the Free Software Foundation; either version 2, or (at your option)
    any later version.
 
    The Library is distributed in the hope that it will be useful, but
@@ -23,7 +23,7 @@
    The GNU General Public License is often shipped with GNU software, and
    is generally kept in a file called COPYING or LICENSE.  If you do not
    have a copy of the license, write to the Free Software Foundation,
-   675 Mass Ave, Cambridge, MA 02139, USA. */
+   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
 #define READLINE_LIBRARY
 
 #if defined (HAVE_CONFIG_H)
 #include "readline.h"
 #include "history.h"
 
-/* Variables imported from other files in the readline library. */
-extern Keymap _rl_keymap;
-extern HIST_ENTRY *saved_line_for_history;
-extern int rl_line_buffer_len;
-extern int rl_point, rl_end;
-extern char *rl_line_buffer;
-
-extern void _rl_save_prompt ();
-extern void _rl_restore_prompt ();
+#include "rlprivate.h"
+#include "xmalloc.h"
 
-extern int rl_execute_next ();
-extern void rl_extend_line_buffer ();
+/* Variables exported to other files in the readline library. */
+unsigned char *_rl_isearch_terminators = (unsigned char *)NULL;
 
-extern int _rl_input_available ();
-
-extern char *xmalloc (), *xrealloc ();
+/* Variables imported from other files in the readline library. */
+extern HIST_ENTRY *saved_line_for_history;
 
-static int rl_search_history ();
+/* Forward declarations */
+static int rl_search_history __P((int, int));
 
 /* Last line found by the current incremental search, so we don't `find'
    identical lines many times in a row. */
@@ -178,12 +171,20 @@ rl_search_history (direction, invoking_key)
   /* Non-zero if we are doing a reverse search. */
   int reverse;
 
+  /* The list of characters which terminate the search, but are not
+     subsequently executed.  If the variable isearch-terminators has
+     been set, we use that value, otherwise we use ESC and C-J. */
+  unsigned char *isearch_terminators;
+
   orig_point = rl_point;
   last_found_line = orig_line = where_history ();
   reverse = direction < 0;
   hlist = history_list ();
   allocated_line = (char *)NULL;
 
+  isearch_terminators = _rl_isearch_terminators ? _rl_isearch_terminators
+                                               : (unsigned char *)"\033\012";
+
   /* Create an arrary of pointers to the lines that we want to search. */
   maybe_replace_line ();
   i = 0;
@@ -211,7 +212,7 @@ rl_search_history (direction, invoking_key)
   /* The line where we start the search. */
   i = orig_line;
 
-  _rl_save_prompt ();
+  rl_save_prompt ();
 
   /* Initialize search parameters. */
   search_string = xmalloc (search_string_size = 128);
@@ -246,10 +247,18 @@ rl_search_history (direction, invoking_key)
            c =  !reverse ? -1 : -2;
        }
 
+#if 0
       /* Let NEWLINE (^J) terminate the search for people who don't like
         using ESC.  ^M can still be used to terminate the search and
         immediately execute the command. */
       if (c == ESC || c == NEWLINE)
+#else
+      /* The characters in isearch_terminators (set from the user-settable
+        variable isearch-terminators) are used to terminate the search but
+        not subsequently execute the character as a command.  The default
+        value is "\033\012" (ESC and C-J). */
+      if (strchr (isearch_terminators, c))
+#endif
        {
          /* ESC still terminates the search, but if there is pending
             input or if input arrives within 0.1 seconds (on systems
@@ -291,7 +300,7 @@ rl_search_history (direction, invoking_key)
          strcpy (rl_line_buffer, lines[orig_line]);
          rl_point = orig_point;
          rl_end = strlen (rl_line_buffer);
-         _rl_restore_prompt();
+         rl_restore_prompt();
          rl_clear_message ();
          if (allocated_line)
            free (allocated_line);
@@ -409,15 +418,15 @@ rl_search_history (direction, invoking_key)
   /* First put back the original state. */
   strcpy (rl_line_buffer, lines[orig_line]);
 
-  _rl_restore_prompt ();
+  rl_restore_prompt ();
 
   /* Free the search string. */
   free (search_string);
 
   if (last_found_line < orig_line)
-    rl_get_previous_history (orig_line - last_found_line);
+    rl_get_previous_history (orig_line - last_found_line, 0);
   else
-    rl_get_next_history (last_found_line - orig_line);
+    rl_get_next_history (last_found_line - orig_line, 0);
 
   /* If the string was not found, put point at the end of the line. */
   if (line_index < 0)
This page took 0.024076 seconds and 4 git commands to generate.