Imported from ../bash-2.05.tar.gz.
[platform/upstream/bash.git] / lib / readline / kill.c
index a150e3c..3ced8fb 100644 (file)
@@ -7,7 +7,7 @@
 
    The GNU Readline Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU General Public License
 
    The GNU Readline 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
+   as published by the Free Software Foundation; either version 2, or
    (at your option) any later version.
 
    The GNU Readline Library is distributed in the hope that it will be
    (at your option) any later version.
 
    The GNU Readline Library is distributed in the hope that it will be
@@ -18,7 +18,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,
    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)
 #define READLINE_LIBRARY
 
 #if defined (HAVE_CONFIG_H)
 #include "readline.h"
 #include "history.h"
 
 #include "readline.h"
 #include "history.h"
 
-extern int _rl_last_command_was_kill;
-extern int rl_editing_mode;
-extern int rl_explicit_arg;
-extern Function *rl_last_func;
-
-extern void _rl_init_argument ();
-extern int _rl_set_mark_at_pos ();
-extern void _rl_fix_point ();
-extern void _rl_abort_internal ();
-
-extern char *xmalloc (), *xrealloc ();
+#include "rlprivate.h"
+#include "xmalloc.h"
 
 /* **************************************************************** */
 /*                                                                 */
 
 /* **************************************************************** */
 /*                                                                 */
@@ -273,7 +264,7 @@ rl_backward_kill_line (direction, ignore)
   else
     {
       if (!rl_point)
   else
     {
       if (!rl_point)
-       ding ();
+       rl_ding ();
       else
        {
          rl_beg_of_line (1, ignore);
       else
        {
          rl_beg_of_line (1, ignore);
@@ -308,7 +299,7 @@ rl_unix_word_rubout (count, key)
   int orig_point;
 
   if (rl_point == 0)
   int orig_point;
 
   if (rl_point == 0)
-    ding ();
+    rl_ding ();
   else
     {
       orig_point = rl_point;
   else
     {
       orig_point = rl_point;
@@ -340,7 +331,7 @@ rl_unix_line_discard (count, key)
      int count, key;
 {
   if (rl_point == 0)
      int count, key;
 {
   if (rl_point == 0)
-    ding ();
+    rl_ding ();
   else
     {
       rl_kill_text (rl_point, 0);
   else
     {
       rl_kill_text (rl_point, 0);
@@ -385,10 +376,12 @@ int
 rl_kill_region (count, ignore)
      int count, ignore;
 {
 rl_kill_region (count, ignore)
      int count, ignore;
 {
-  int r;
+  int r, npoint;
 
 
+  npoint = (rl_point < rl_mark) ? rl_point : rl_mark;
   r = region_kill_internal (1);
   _rl_fix_point (1);
   r = region_kill_internal (1);
   _rl_fix_point (1);
+  rl_point = npoint;
   return r;
 }
 
   return r;
 }
 
@@ -503,7 +496,9 @@ rl_yank_nth_arg_internal (count, ignore, history_skip)
 {
   register HIST_ENTRY *entry;
   char *arg;
 {
   register HIST_ENTRY *entry;
   char *arg;
-  int i;
+  int i, pos;
+
+  pos = where_history ();
 
   if (history_skip)
     {
 
   if (history_skip)
     {
@@ -512,25 +507,19 @@ rl_yank_nth_arg_internal (count, ignore, history_skip)
     }
 
   entry = previous_history ();
     }
 
   entry = previous_history ();
-  if (entry)
-    {
-      if (history_skip)
-       {
-         for (i = 0; i < history_skip; i++)
-           next_history ();
-       }
-      next_history ();
-    }
-  else
+
+  history_set_pos (pos);
+
+  if (entry == 0)
     {
     {
-      ding ();
+      rl_ding ();
       return -1;
     }
 
   arg = history_arg_extract (count, count, entry->line);
   if (!arg || !*arg)
     {
       return -1;
     }
 
   arg = history_arg_extract (count, count, entry->line);
   if (!arg || !*arg)
     {
-      ding ();
+      rl_ding ();
       return -1;
     }
 
       return -1;
     }
 
@@ -572,6 +561,8 @@ rl_yank_last_arg (count, key)
   static int explicit_arg_p = 0;
   static int count_passed = 1;
   static int direction = 1;
   static int explicit_arg_p = 0;
   static int count_passed = 1;
   static int direction = 1;
+  static int undo_needed = 0;
+  int retval;
 
   if (rl_last_func != rl_yank_last_arg)
     {
 
   if (rl_last_func != rl_yank_last_arg)
     {
@@ -582,23 +573,26 @@ rl_yank_last_arg (count, key)
     }
   else
     {
     }
   else
     {
-      rl_do_undo ();
+      if (undo_needed)
+       rl_do_undo ();
       if (count < 1)
         direction = -direction;
       history_skip += direction;
       if (history_skip < 0)
        history_skip = 0;
       if (count < 1)
         direction = -direction;
       history_skip += direction;
       if (history_skip < 0)
        history_skip = 0;
-      count_passed = count;
     }
  
   if (explicit_arg_p)
     }
  
   if (explicit_arg_p)
-    return (rl_yank_nth_arg_internal (count, key, history_skip));
+    retval = rl_yank_nth_arg_internal (count_passed, key, history_skip);
   else
   else
-    return (rl_yank_nth_arg_internal ('$', key, history_skip));
+    retval = rl_yank_nth_arg_internal ('$', key, history_skip);
+
+  undo_needed = retval == 0;
+  return retval;
 }
 
 /* A special paste command for users of Cygnus's cygwin32. */
 }
 
 /* A special paste command for users of Cygnus's cygwin32. */
-#if defined (__CYGWIN32__)
+#if defined (__CYGWIN__)
 #include <windows.h>
 
 int
 #include <windows.h>
 
 int
@@ -631,4 +625,4 @@ rl_paste_from_clipboard (count, key)
     }
   return (0);
 }
     }
   return (0);
 }
-#endif /* __CYGWIN32__ */
+#endif /* __CYGWIN__ */