Import readline 7.0 (patch 5)
[deliverable/binutils-gdb.git] / readline / undo.c
index eb042b29fd966e7261a8735f9709fc9627beec57..58363040ce0ddfa7f4265693fc33faeb76dd193c 100644 (file)
@@ -1,7 +1,6 @@
-/* readline.c -- a general facility for reading lines of input
-   with emacs style editing and completion. */
+/* undo.c - manage list of changes to lines, offering opportunity to undo them */
 
-/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2015 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.      
@@ -50,7 +49,7 @@
 #include "rlprivate.h"
 #include "xmalloc.h"
 
-extern void replace_history_data PARAMS((int, histdata_t *, histdata_t *));
+extern void _hs_replace_history_data PARAMS((int, histdata_t *, histdata_t *));
 
 /* Non-zero tells rl_delete_text and rl_insert_text to not add to
    the undo list. */
@@ -101,25 +100,35 @@ rl_add_undo (what, start, end, text)
   rl_undo_list = temp;
 }
 
-/* Free the existing undo list. */
+/* Free an UNDO_LIST */
 void
-rl_free_undo_list ()
+_rl_free_undo_list (ul)
+     UNDO_LIST *ul;
 {
-  UNDO_LIST *release, *orig_list;
+  UNDO_LIST *release;
 
-  orig_list = rl_undo_list;
-  while (rl_undo_list)
+  while (ul)
     {
-      release = rl_undo_list;
-      rl_undo_list = rl_undo_list->next;
+      release = ul;
+      ul = ul->next;
 
       if (release->what == UNDO_DELETE)
        xfree (release->text);
 
       xfree (release);
     }
+}
+
+/* Free the existing undo list. */
+void
+rl_free_undo_list ()
+{
+  UNDO_LIST *release, *orig_list;
+
+  orig_list = rl_undo_list;
+  _rl_free_undo_list (rl_undo_list);
   rl_undo_list = (UNDO_LIST *)NULL;
-  replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL);
+  _hs_replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL);
 }
 
 UNDO_LIST *
@@ -168,6 +177,7 @@ rl_do_undo ()
 {
   UNDO_LIST *release;
   int waiting_for_begin, start, end;
+  HIST_ENTRY *cur, *temp;
 
 #define TRANS(i) ((i) == -1 ? rl_point : ((i) == -2 ? rl_end : (i)))
 
@@ -222,7 +232,19 @@ rl_do_undo ()
 
       release = rl_undo_list;
       rl_undo_list = rl_undo_list->next;
-      replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list);
+
+      /* If we are editing a history entry, make sure the change is replicated
+        in the history entry's line */
+      cur = current_history ();
+      if (cur && cur->data && (UNDO_LIST *)cur->data == release)
+       {
+         temp = replace_history_entry (where_history (), rl_line_buffer, (histdata_t)rl_undo_list);
+         xfree (temp->line);
+         FREE (temp->timestamp);
+         xfree (temp);
+       }
+
+      _hs_replace_history_data (-1, (histdata_t *)release, (histdata_t *)rl_undo_list);
 
       xfree (release);
     }
This page took 0.042078 seconds and 4 git commands to generate.