/* kill.c -- kill ring management. */
-/* Copyright (C) 1994 Free Software Foundation, Inc.
+/* Copyright (C) 1994-2017 Free Software Foundation, Inc.
- This file is part of the GNU Readline Library, a library for
- reading lines of text with interactive input and history editing.
+ This file is part of the GNU Readline Library (Readline), a library
+ for reading lines of text with interactive input and history editing.
- 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 2, or
+ Readline 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 3 of the License, or
(at your option) any later version.
- The GNU Readline Library is distributed in the hope that it will be
- useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ Readline is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
- 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,
- 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Readline. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#define READLINE_LIBRARY
#if defined (HAVE_CONFIG_H)
/* How to say that you only want to save a certain amount
of kill material. */
int
-rl_set_retained_kills (num)
- int num;
+rl_set_retained_kills (int num)
{
return 0;
}
non-zero, and the last command was a kill, the text is appended to the
current kill ring slot, otherwise prepended. */
static int
-_rl_copy_to_kill_ring (text, append)
- char *text;
- int append;
+_rl_copy_to_kill_ring (char *text, int append)
{
char *old, *new;
int slot;
/* First, find the slot to work with. */
- if (_rl_last_command_was_kill == 0)
+ if (_rl_last_command_was_kill == 0 || rl_kill_ring == 0)
{
/* Get a new slot. */
if (rl_kill_ring == 0)
if (slot == rl_max_kills)
{
register int i;
- free (rl_kill_ring[0]);
+ xfree (rl_kill_ring[0]);
for (i = 0; i < slot; i++)
rl_kill_ring[i] = rl_kill_ring[i + 1];
}
else
{
slot = rl_kill_ring_length += 1;
- rl_kill_ring = (char **)xrealloc (rl_kill_ring, slot * sizeof (char *));
+ rl_kill_ring = (char **)xrealloc (rl_kill_ring, (slot + 1) * sizeof (char *));
}
rl_kill_ring[--slot] = (char *)NULL;
}
slot = rl_kill_ring_length - 1;
/* If the last command was a kill, prepend or append. */
- if (_rl_last_command_was_kill && rl_editing_mode != vi_mode)
+ if (_rl_last_command_was_kill && rl_kill_ring[slot] && rl_editing_mode != vi_mode)
{
old = rl_kill_ring[slot];
new = (char *)xmalloc (1 + strlen (old) + strlen (text));
strcpy (new, text);
strcat (new, old);
}
- free (old);
- free (text);
+ xfree (old);
+ xfree (text);
rl_kill_ring[slot] = new;
}
else
last command was not a kill command, then a new slot is made for
this kill. */
int
-rl_kill_text (from, to)
- int from, to;
+rl_kill_text (int from, int to)
{
char *text;
/* Delete the word at point, saving the text in the kill ring. */
int
-rl_kill_word (count, key)
- int count, key;
+rl_kill_word (int count, int key)
{
int orig_point;
/* Rubout the word before point, placing it on the kill ring. */
int
-rl_backward_kill_word (count, ignore)
- int count, ignore;
+rl_backward_kill_word (int count, int key)
{
int orig_point;
if (count < 0)
- return (rl_kill_word (-count, ignore));
+ return (rl_kill_word (-count, key));
else
{
orig_point = rl_point;
- rl_backward_word (count, ignore);
+ rl_backward_word (count, key);
if (rl_point != orig_point)
rl_kill_text (orig_point, rl_point);
/* Kill from here to the end of the line. If DIRECTION is negative, kill
back to the line start instead. */
int
-rl_kill_line (direction, ignore)
- int direction, ignore;
+rl_kill_line (int direction, int key)
{
int orig_point;
if (direction < 0)
- return (rl_backward_kill_line (1, ignore));
+ return (rl_backward_kill_line (1, key));
else
{
orig_point = rl_point;
- rl_end_of_line (1, ignore);
+ rl_end_of_line (1, key);
if (orig_point != rl_point)
rl_kill_text (orig_point, rl_point);
rl_point = orig_point;
/* Kill backwards to the start of the line. If DIRECTION is negative, kill
forwards to the line end instead. */
int
-rl_backward_kill_line (direction, ignore)
- int direction, ignore;
+rl_backward_kill_line (int direction, int key)
{
int orig_point;
if (direction < 0)
- return (rl_kill_line (1, ignore));
+ return (rl_kill_line (1, key));
else
{
- if (!rl_point)
+ if (rl_point == 0)
rl_ding ();
else
{
orig_point = rl_point;
- rl_beg_of_line (1, ignore);
+ rl_beg_of_line (1, key);
if (rl_point != orig_point)
rl_kill_text (orig_point, rl_point);
if (rl_editing_mode == emacs_mode)
/* Kill the whole line, no matter where point is. */
int
-rl_kill_full_line (count, ignore)
- int count, ignore;
+rl_kill_full_line (int count, int key)
{
rl_begin_undo_group ();
rl_point = 0;
/* This does what C-w does in Unix. We can't prevent people from
using behaviour that they expect. */
int
-rl_unix_word_rubout (count, key)
- int count, key;
+rl_unix_word_rubout (int count, int key)
{
int orig_point;
rl_point--;
while (rl_point && (whitespace (rl_line_buffer[rl_point - 1]) == 0))
- rl_point--;
+ rl_point--; /* XXX - multibyte? */
}
rl_kill_text (orig_point, rl_point);
if (rl_editing_mode == emacs_mode)
rl_mark = rl_point;
}
+
+ return 0;
+}
+
+/* This deletes one filename component in a Unix pathname. That is, it
+ deletes backward to directory separator (`/') or whitespace. */
+int
+rl_unix_filename_rubout (int count, int key)
+{
+ int orig_point, c;
+
+ if (rl_point == 0)
+ rl_ding ();
+ else
+ {
+ orig_point = rl_point;
+ if (count <= 0)
+ count = 1;
+
+ while (count--)
+ {
+ c = rl_line_buffer[rl_point - 1];
+ while (rl_point && (whitespace (c) || c == '/'))
+ {
+ rl_point--;
+ c = rl_line_buffer[rl_point - 1];
+ }
+
+ while (rl_point && (whitespace (c) == 0) && c != '/')
+ {
+ rl_point--; /* XXX - multibyte? */
+ c = rl_line_buffer[rl_point - 1];
+ }
+ }
+
+ rl_kill_text (orig_point, rl_point);
+ if (rl_editing_mode == emacs_mode)
+ rl_mark = rl_point;
+ }
+
return 0;
}
into the line at all, and if you aren't, then you know what you are
doing. */
int
-rl_unix_line_discard (count, key)
- int count, key;
+rl_unix_line_discard (int count, int key)
{
if (rl_point == 0)
rl_ding ();
/* Copy the text in the `region' to the kill ring. If DELETE is non-zero,
delete the text from the line as well. */
static int
-region_kill_internal (delete)
- int delete;
+region_kill_internal (int delete)
{
char *text;
/* Copy the text in the region to the kill ring. */
int
-rl_copy_region_to_kill (count, ignore)
- int count, ignore;
+rl_copy_region_to_kill (int count, int key)
{
return (region_kill_internal (0));
}
/* Kill the text between the point and mark. */
int
-rl_kill_region (count, ignore)
- int count, ignore;
+rl_kill_region (int count, int key)
{
int r, npoint;
/* Copy COUNT words to the kill ring. DIR says which direction we look
to find the words. */
static int
-_rl_copy_word_as_kill (count, dir)
- int count, dir;
+_rl_copy_word_as_kill (int count, int dir)
{
int om, op, r;
}
int
-rl_copy_forward_word (count, key)
- int count, key;
+rl_copy_forward_word (int count, int key)
{
if (count < 0)
return (rl_copy_backward_word (-count, key));
}
int
-rl_copy_backward_word (count, key)
- int count, key;
+rl_copy_backward_word (int count, int key)
{
if (count < 0)
return (rl_copy_forward_word (-count, key));
/* Yank back the last killed text. This ignores arguments. */
int
-rl_yank (count, ignore)
- int count, ignore;
+rl_yank (int count, int key)
{
if (rl_kill_ring == 0)
{
_rl_abort_internal ();
- return -1;
+ return 1;
}
_rl_set_mark_at_pos (rl_point);
delete that text from the line, rotate the index down, and
yank back some other text. */
int
-rl_yank_pop (count, key)
- int count, key;
+rl_yank_pop (int count, int key)
{
int l, n;
!rl_kill_ring)
{
_rl_abort_internal ();
- return -1;
+ return 1;
}
l = strlen (rl_kill_ring[rl_kill_index]);
else
{
_rl_abort_internal ();
- return -1;
+ return 1;
}
}
+#if defined (VI_MODE)
+int
+rl_vi_yank_pop (int count, int key)
+{
+ int l, n;
+
+ if (((rl_last_func != rl_vi_yank_pop) && (rl_last_func != rl_vi_put)) ||
+ !rl_kill_ring)
+ {
+ _rl_abort_internal ();
+ return 1;
+ }
+
+ l = strlen (rl_kill_ring[rl_kill_index]);
+ n = rl_point - l;
+ if (n >= 0 && STREQN (rl_line_buffer + n, rl_kill_ring[rl_kill_index], l))
+ {
+ rl_delete_text (n, rl_point);
+ rl_point = n;
+ rl_kill_index--;
+ if (rl_kill_index < 0)
+ rl_kill_index = rl_kill_ring_length - 1;
+ rl_vi_put (1, 'p');
+ return 0;
+ }
+ else
+ {
+ _rl_abort_internal ();
+ return 1;
+ }
+}
+#endif /* VI_MODE */
+
/* Yank the COUNTh argument from the previous history line, skipping
HISTORY_SKIP lines before looking for the `previous line'. */
static int
-rl_yank_nth_arg_internal (count, ignore, history_skip)
- int count, ignore, history_skip;
+rl_yank_nth_arg_internal (int count, int key, int history_skip)
{
register HIST_ENTRY *entry;
char *arg;
if (entry == 0)
{
rl_ding ();
- return -1;
+ return 1;
}
arg = history_arg_extract (count, count, entry->line);
if (!arg || !*arg)
{
rl_ding ();
- return -1;
+ FREE (arg);
+ return 1;
}
rl_begin_undo_group ();
inserts it right *after* rl_point. */
if (rl_editing_mode == vi_mode)
{
- rl_vi_append_mode (1, ignore);
+ rl_vi_append_mode (1, key);
rl_insert_text (" ");
}
#endif /* VI_MODE */
rl_insert_text (arg);
- free (arg);
+ xfree (arg);
rl_end_undo_group ();
return 0;
/* Yank the COUNTth argument from the previous history line. */
int
-rl_yank_nth_arg (count, ignore)
- int count, ignore;
+rl_yank_nth_arg (int count, int key)
{
- return (rl_yank_nth_arg_internal (count, ignore, 0));
+ return (rl_yank_nth_arg_internal (count, key, 0));
}
/* Yank the last argument from the previous history line. This `knows'
how rl_yank_nth_arg treats a count of `$'. With an argument, this
behaves the same as rl_yank_nth_arg. */
int
-rl_yank_last_arg (count, key)
- int count, key;
+rl_yank_last_arg (int count, int key)
{
static int history_skip = 0;
static int explicit_arg_p = 0;
{
if (undo_needed)
rl_do_undo ();
- if (count < 1)
+ if (count < 0) /* XXX - was < 1 */
direction = -direction;
history_skip += direction;
if (history_skip < 0)
return retval;
}
-/* A special paste command for users of Cygnus's cygwin32. */
-#if defined (__CYGWIN__)
+/* Having read the special escape sequence denoting the beginning of a
+ `bracketed paste' sequence, read the rest of the pasted input until the
+ closing sequence and insert the pasted text as a single unit without
+ interpretation. */
+char *
+_rl_bracketed_text (size_t *lenp)
+{
+ int c;
+ size_t len, cap;
+ char *buf;
+
+ len = 0;
+ buf = xmalloc (cap = 64);
+ buf[0] = '\0';
+
+ RL_SETSTATE (RL_STATE_MOREINPUT);
+ while ((c = rl_read_key ()) >= 0)
+ {
+ if (RL_ISSTATE (RL_STATE_MACRODEF))
+ _rl_add_macro_char (c);
+
+ if (c == '\r') /* XXX */
+ c = '\n';
+
+ if (len == cap)
+ buf = xrealloc (buf, cap *= 2);
+
+ buf[len++] = c;
+ if (len >= BRACK_PASTE_SLEN && c == BRACK_PASTE_LAST &&
+ STREQN (buf + len - BRACK_PASTE_SLEN, BRACK_PASTE_SUFF, BRACK_PASTE_SLEN))
+ {
+ len -= BRACK_PASTE_SLEN;
+ break;
+ }
+ }
+ RL_UNSETSTATE (RL_STATE_MOREINPUT);
+
+ if (c >= 0)
+ {
+ if (len == cap)
+ buf = xrealloc (buf, cap + 1);
+ buf[len] = '\0';
+ }
+
+ if (lenp)
+ *lenp = len;
+ return (buf);
+}
+
+int
+rl_bracketed_paste_begin (int count, int key)
+{
+ int retval, c;
+ size_t len, cap;
+ char *buf;
+
+ buf = _rl_bracketed_text (&len);
+ retval = rl_insert_text (buf) == len ? 0 : 1;
+
+ xfree (buf);
+ return (retval);
+}
+
+/* A special paste command for Windows users. */
+#if defined (_WIN32)
#include <windows.h>
int
-rl_paste_from_clipboard (count, key)
- int count, key;
+rl_paste_from_clipboard (int count, int key)
{
char *data, *ptr;
int len;
_rl_set_mark_at_pos (rl_point);
rl_insert_text (ptr);
if (ptr != data)
- free (ptr);
+ xfree (ptr);
CloseClipboard ();
}
return (0);
}
-#endif /* __CYGWIN__ */
+#endif /* _WIN32 */