/* text.c -- text handling commands for readline. */
-/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2009 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)
{
int end = rl_point + count;
#if defined (VI_MODE)
- int lend = rl_end > 0 ? rl_end - (rl_editing_mode == vi_mode) : rl_end;
+ int lend = rl_end > 0 ? rl_end - (VI_COMMAND_MODE()) : rl_end;
#else
int lend = rl_end;
#endif
if (count > 0)
{
+ if (rl_point == rl_end && EMACS_MODE())
+ {
+ rl_ding ();
+ return 0;
+ }
+
point = _rl_find_next_mbchar (rl_line_buffer, rl_point, count, MB_FIND_NONZERO);
#if defined (VI_MODE)
- if (rl_end <= point && rl_editing_mode == vi_mode)
+ if (point >= rl_end && VI_COMMAND_MODE())
point = _rl_find_prev_mbchar (rl_line_buffer, rl_end, MB_FIND_NONZERO);
#endif
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
+ if (c < 0)
+ return -1;
+
#if defined (HANDLE_SIGNALS)
if (RL_ISSTATE (RL_STATE_CALLBACK) == 0)
_rl_restore_tty_signals ();
if (rl_erase_empty_line && rl_point == 0 && rl_end == 0)
return 0;
- if (readline_echoing_p)
+ if (_rl_echoing_p)
_rl_update_final ();
return 0;
}
rl_delete (count, key)
int count, key;
{
- int r;
+ int xpoint;
if (count < 0)
return (_rl_rubout_char (-count, key));
if (count > 1 || rl_explicit_arg)
{
- int orig_point = rl_point;
+ xpoint = rl_point;
if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
rl_forward_char (count, key);
else
rl_forward_byte (count, key);
- r = rl_kill_text (orig_point, rl_point);
- rl_point = orig_point;
- return r;
+ rl_kill_text (xpoint, rl_point);
+ rl_point = xpoint;
}
else
{
- int new_point;
-
- new_point = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
- return (rl_delete_text (rl_point, new_point));
+ xpoint = MB_NEXTCHAR (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);
+ rl_delete_text (rl_point, xpoint);
}
+ return 0;
}
/* Delete the character under the cursor, unless the insertion
#if defined (HANDLE_MULTIBYTE)
wchar_t wc, nwc;
char mb[MB_LEN_MAX+1];
- int mblen, p;
- mbstate_t ps;
+ int mlen;
+ mbstate_t mps;
#endif
start = rl_point;
SWAP (start, end);
#if defined (HANDLE_MULTIBYTE)
- memset (&ps, 0, sizeof (mbstate_t));
+ memset (&mps, 0, sizeof (mbstate_t));
#endif
/* We are going to modify some text, so let's prepare to undo it. */
#if defined (HANDLE_MULTIBYTE)
else
{
- mbrtowc (&wc, rl_line_buffer + start, end - start, &ps);
+ mbrtowc (&wc, rl_line_buffer + start, end - start, &mps);
nwc = (nop == UpCase) ? _rl_to_wupper (wc) : _rl_to_wlower (wc);
if (nwc != wc) /* just skip unchanged characters */
{
- mblen = wcrtomb (mb, nwc, &ps);
- if (mblen > 0)
- mb[mblen] = '\0';
+ mlen = wcrtomb (mb, nwc, &mps);
+ if (mlen > 0)
+ mb[mlen] = '\0';
/* Assume the same width */
- strncpy (rl_line_buffer + start, mb, mblen);
+ strncpy (rl_line_buffer + start, mb, mlen);
}
}
#endif
mb_len = _rl_read_mbchar (mbchar, MB_LEN_MAX);
+ if (mb_len <= 0)
+ return -1;
+
if (count < 0)
return (_rl_char_search_internal (-count, bdir, mbchar, mb_len));
else
c = rl_read_key ();
RL_UNSETSTATE(RL_STATE_MOREINPUT);
+ if (c < 0)
+ return -1;
+
if (count < 0)
return (_rl_char_search_internal (-count, bdir, c));
else