]> git.ipfire.org Git - thirdparty/readline.git/commitdiff
commit readline-20160425 snapshot
authorChet Ramey <chet.ramey@case.edu>
Mon, 8 Aug 2016 19:45:28 +0000 (15:45 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 8 Aug 2016 19:45:28 +0000 (15:45 -0400)
19 files changed:
CHANGES
complete.c
display.c
doc/readline.3
doc/rltech.texi
doc/rluser.texi
doc/version.texi
examples/hist_erasedups.c
examples/hist_purgecmd.c
funmap.c
histexpand.c
histlib.h
misc.c
readline.c
readline.h
rltty.c
text.c
vi_keymap.c
vi_mode.c

diff --git a/CHANGES b/CHANGES
index 4edf8f7bd32cf4e78b3a85cf4d9e8096d4d9a40f..266cd531f705f97c4d98235fc895070ceb07a5e1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -93,6 +93,10 @@ dd. Fixed a redisplay bug with prompt strings containing invisible characters
 ee. Readline prints more descriptive error messages when it encounters errors
     while reading an inputrc file.
 
+ff. Fixed a bug in the character insertion code that attempts to optimize
+    typeahead when it reads a character that is not bound to self-insert and
+    resets the key sequence state.
+
 2.  New Features in Readline
 
 a.  The history truncation code now uses the same error recovery mechansim as
index d0bbe7df7b74b5357b0be23d8341fbb7f080277a..0a81129b877eabe68836dd4104c05d3826a3ca2a 100644 (file)
@@ -214,7 +214,7 @@ int _rl_colored_stats = 0;
 
 /* Non-zero means to use a color (currently magenta) to indicate the common
    prefix of a set of possible word completions. */
-int _rl_colored_completion_prefix = 1;
+int _rl_colored_completion_prefix = 0;
 #endif
 
 /* If non-zero, when completing in the middle of a word, don't insert
@@ -807,7 +807,7 @@ fnprint (to_print, prefix_bytes, real_pathname)
 {
   int printed_len, w;
   const char *s;
-  int common_prefix_len;
+  int common_prefix_len, print_len;
 #if defined (HANDLE_MULTIBYTE)
   mbstate_t ps;
   const char *end;
@@ -815,7 +815,8 @@ fnprint (to_print, prefix_bytes, real_pathname)
   int width;
   wchar_t wc;
 
-  end = to_print + strlen (to_print) + 1;
+  print_len = strlen (to_print);
+  end = to_print + print_len + 1;
   memset (&ps, 0, sizeof (mbstate_t));
 #endif
 
@@ -825,7 +826,7 @@ fnprint (to_print, prefix_bytes, real_pathname)
      possible completions.  Only cut off prefix_bytes if we're going to be
      printing the ellipsis, which takes precedence over coloring the
      completion prefix (see print_filename() below). */
-  if (_rl_completion_prefix_display_length > 0 && to_print[prefix_bytes] == '\0')
+  if (_rl_completion_prefix_display_length > 0 && prefix_bytes >= print_len)
     prefix_bytes = 0;
 
 #if defined (COLOR_SUPPORT)
@@ -1571,9 +1572,12 @@ rl_display_match_list (matches, len, max)
   if (_rl_completion_prefix_display_length > 0)
     {
       t = printable_part (matches[0]);
-      temp = strrchr (t, '/');         /* check again in case of /usr/src/ */
+      /* check again in case of /usr/src/ */
+      temp = rl_filename_completion_desired ? strrchr (t, '/') : 0;
       common_length = temp ? fnwidth (temp) : fnwidth (t);
       sind = temp ? strlen (temp) : strlen (t);
+      if (common_length > max || sind > max)
+       common_length = sind = 0;
 
       if (common_length > _rl_completion_prefix_display_length && common_length > ELLIPSIS_LEN)
        max -= common_length - ELLIPSIS_LEN;
@@ -1584,9 +1588,11 @@ rl_display_match_list (matches, len, max)
   else if (_rl_colored_completion_prefix > 0)
     {
       t = printable_part (matches[0]);
-      temp = strrchr (t, '/');
+      temp = rl_filename_completion_desired ? strrchr (t, '/') : 0;
       common_length = temp ? fnwidth (temp) : fnwidth (t);
       sind = temp ? RL_STRLEN (temp+1) : RL_STRLEN (t);                /* want portion after final slash */
+      if (common_length > max || sind > max)
+       common_length = sind = 0;
     }
 #endif
 
@@ -1635,8 +1641,13 @@ rl_display_match_list (matches, len, max)
                  printed_len = print_filename (temp, matches[l], sind);
 
                  if (j + 1 < limit)
-                   for (k = 0; k < max - printed_len; k++)
-                     putc (' ', rl_outstream);
+                   {
+                     if (max <= printed_len)
+                       putc (' ', rl_outstream);
+                     else
+                       for (k = 0; k < max - printed_len; k++)
+                         putc (' ', rl_outstream);
+                   }
                }
              l += count;
            }
@@ -1683,6 +1694,8 @@ rl_display_match_list (matches, len, max)
                        return;
                    }
                }
+             else if (max <= printed_len)
+               putc (' ', rl_outstream);
              else
                for (k = 0; k < max - printed_len; k++)
                  putc (' ', rl_outstream);
index f261933d1c23bf782496677d4e18f0b13f3a7532..a409574a7116633e8e2eefebe82a53139d9dac31 100644 (file)
--- a/display.c
+++ b/display.c
@@ -826,7 +826,7 @@ rl_redisplay ()
        lpos -= _rl_col_width (local_prompt, n0, num, 1) - wadjust;
       else
 #endif
-       lpos -= _rl_screenwidth - wadjust;
+       lpos -= _rl_screenwidth;        /* all physical cursor positions */
     }
 
   prompt_last_screen_line = newlines;
@@ -2027,6 +2027,34 @@ rl_on_new_line ()
   return 0;
 }
 
+/* Clear all screen lines occupied by the current readline line buffer
+   (visible line) */
+int
+rl_clear_visible_line ()
+{
+  int curr_line;
+
+  /* Make sure we move to column 0 so we clear the entire line */
+#if defined (__MSDOS__)
+  putc ('\r', rl_outstream);
+#else
+  tputs (_rl_term_cr, 1, _rl_output_character_function);
+#endif
+  _rl_last_c_pos = 0;
+
+  /* Move to the last screen line of the current visible line */
+  _rl_move_vert (_rl_vis_botlin);
+
+  /* And erase screen lines going up to line 0 (first visible line) */
+  for (curr_line = _rl_last_v_pos; curr_line >= 0; curr_line--)
+    {
+      _rl_move_vert (curr_line);
+      _rl_clear_to_eol (0);
+    }
+
+  return 0;
+}
+
 /* Tell the update routines that we have moved onto a new line with the
    prompt already displayed.  Code originally from the version of readline
    distributed with CLISP.  rl_expand_prompt must have already been called
index 765c8fae9501960bc75b0ce935f24633ff3dfba3..b57f00b90b0baecbaa9e1f90fcdf303d916d228e 100644 (file)
@@ -6,9 +6,9 @@
 .\"    Case Western Reserve University
 .\"    chet.ramey@case.edu
 .\"
-.\"    Last Change: Wed Nov 19 18:32:58 EST 2014
+.\"    Last Change: Sun Feb 28 15:42:34 EST 2016
 .\"
-.TH READLINE 3 "2014 November 19" "GNU Readline 6.3"
+.TH READLINE 3 "2016 February 28" "GNU Readline 7.0"
 .\"
 .\" File Name macro.  This used to be `.PN', for Path Name,
 .\" but Sun doesn't seem to like that very much.
@@ -416,12 +416,19 @@ If set to \fBOn\fP, readline will convert characters with the
 eighth bit set to an ASCII key sequence
 by stripping the eighth bit and prefixing it with an
 escape character (in effect, using escape as the \fImeta prefix\fP).
+The default is \fIOn\fP, but readline will set it to \fIOff\fP if the
+locale contains eight-bit characters.
 .TP
 .B disable\-completion (Off)
 If set to \fBOn\fP, readline will inhibit word completion.  Completion 
 characters will be inserted into the line as if they had been
 mapped to \fBself-insert\fP.
 .TP
+.B echo\-control\-characters (On)
+When set to \fBOn\fP, on operating systems that indicate they support it,
+readline echoes a character corresponding to a signal generated from the
+keyboard.
+.TP
 .B editing\-mode (emacs)
 Controls whether readline begins with a set of key bindings similar
 to \fIEmacs\fP or \fIvi\fP.
@@ -431,11 +438,6 @@ can be set to either
 or
 .BR vi .
 .TP
-.B echo\-control\-characters (On)
-When set to \fBOn\fP, on operating systems that indicate they support it,
-readline echoes a character corresponding to a signal generated from the
-keyboard.
-.TP
 .B enable\-bracketed\-paste (Off)
 When set to \fBOn\fP, readline will configure the terminal in a way
 that will enable it to insert each paste into the editing buffer as a
@@ -469,6 +471,8 @@ are saved.
 If set to a value less than zero, the number of history entries is not
 limited.
 By default, the number of history entries is not limited.
+If an attempt is made to set \fIhistory\-size\fP to a non-numeric value,
+the maximum number of history entries will be set to 500.
 .TP
 .B horizontal\-scroll\-mode (Off)
 When set to \fBOn\fP, makes readline use a single line for display,
@@ -481,6 +485,8 @@ it will not clear the eighth bit in the characters it reads),
 regardless of what the terminal claims it can support.  The name
 .B meta\-flag
 is a synonym for this variable.
+The default is \fIOff\fP, but readline will set it to \fIOn\fP if the 
+locale contains eight-bit characters.
 .TP
 .B isearch\-terminators (``C\-[ C\-J'')
 The string of characters that should terminate an incremental
@@ -551,6 +557,8 @@ the list.
 If set to \fBOn\fP, readline will display characters with the
 eighth bit set directly rather than as a meta-prefixed escape
 sequence.
+The default is \fIOff\fP, but readline will set it to \fIOn\fP if the
+locale contains eight-bit characters.
 .TP
 .B page\-completions (On)
 If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager
index cc985d5386de8390c9c2815ef5dca0943c7fe84e..9b21e2794cb4331a13454f0cba21cfbb24446cea 100644 (file)
@@ -963,6 +963,10 @@ redisplay.
 It should be used after setting @var{rl_already_prompted}.
 @end deftypefun
 
+@deftypefun int rl_clear_visible_line (void)
+Clear the screen lines corresponding to the current line's contents.
+@end deftypefun
+
 @deftypefun int rl_reset_line_state (void)
 Reset the display state to a clean state and redisplay the current line
 starting on a new line.
@@ -1136,6 +1140,14 @@ that the terminal editing characters are bound to @code{rl_insert}.
 The bindings are performed in @var{kmap}.
 @end deftypefun
 
+@deftypefun int rl_tty_set_echoing (int value)
+Set Readline's idea of whether or not it is echoing output to its output
+stream (@var{rl_outstream}).  If @var{value} is 0, Readline does not display
+output to @var{rl_outstream}; any other value enables output.  The initial
+value is set when Readline initializes the terminal settings.
+This function returns the previous value.
+@end deftypefun
+
 @deftypefun int rl_reset_terminal (const char *terminal_name)
 Reinitialize Readline's idea of the terminal settings using
 @var{terminal_name} as the terminal type (e.g., @code{vt100}).
index d8513c64a4c8f291c0f5371efffa8775bee84b40..4c094c88c69bd19dfe9c5124d8331fa295413da0 100644 (file)
@@ -499,7 +499,9 @@ The default limit is @code{100}.
 If set to @samp{on}, Readline will convert characters with the
 eighth bit set to an @sc{ascii} key sequence by stripping the eighth
 bit and prefixing an @key{ESC} character, converting them to a
-meta-prefixed key sequence.  The default value is @samp{on}.
+meta-prefixed key sequence.  The default value is @samp{on}, but
+will be set to @samp{off} if the locale is one that contains
+eight-bit characters.
 
 @item disable-completion
 @vindex disable-completion
@@ -507,6 +509,12 @@ If set to @samp{On}, Readline will inhibit word completion.
 Completion  characters will be inserted into the line as if they had
 been mapped to @code{self-insert}.  The default is @samp{off}.
 
+@item echo-control-characters
+@vindex echo-control-characters
+When set to @samp{on}, on operating systems that indicate they support it,
+readline echoes a character corresponding to a signal generated from the
+keyboard.  The default is @samp{on}.
+
 @item editing-mode
 @vindex editing-mode
 The @code{editing-mode} variable controls which default set of
@@ -525,12 +533,6 @@ non-printing characters, which can be used to embed a terminal control
 sequence into the mode string.
 The default is @samp{@@}.
 
-@item echo-control-characters
-@vindex echo-control-characters
-When set to @samp{on}, on operating systems that indicate they support it,
-readline echoes a character corresponding to a signal generated from the
-keyboard.  The default is @samp{on}.
-
 @item enable-bracketed-paste
 @vindex enable-bracketed-paste
 When set to @samp{On}, Readline will configure the terminal in a way
@@ -571,6 +573,8 @@ are saved.
 If set to a value less than zero, the number of history entries is not
 limited.
 By default, the number of history entries is not limited.
+If an attempt is made to set @var{history-size} to a non-numeric value,
+the maximum number of history entries will be set to 500.
 
 @item horizontal-scroll-mode
 @vindex horizontal-scroll-mode
@@ -586,8 +590,9 @@ this variable is set to @samp{off}.
 If set to @samp{on}, Readline will enable eight-bit input (it
 will not clear the eighth bit in the characters it reads),
 regardless of what the terminal claims it can support.  The
-default value is @samp{off}.  The name @code{meta-flag} is a
-synonym for this variable.
+default value is @samp{off}, but Readline will set it to @samp{on} if the 
+locale contains eight-bit characters.
+The name @code{meta-flag} is a synonym for this variable.
 
 @item isearch-terminators
 @vindex isearch-terminators
@@ -666,7 +671,9 @@ the list.  The default is @samp{off}.
 @vindex output-meta
 If set to @samp{on}, Readline will display characters with the
 eighth bit set directly rather than as a meta-prefixed escape
-sequence.  The default is @samp{off}.
+sequence.
+The default is @samp{off}, but Readline will set it to @samp{on} if the
+locale contains eight-bit characters.
 
 @item page-completions
 @vindex page-completions
index 4baf924fe33848a8d75a461e40f5b168762512ca..766864aef1cd24460b8c99b5b8c780b77dbdf9cb 100644 (file)
@@ -4,7 +4,7 @@ Copyright (C) 1988-2016 Free Software Foundation, Inc.
 
 @set EDITION 7.0
 @set VERSION 7.0
-@set UPDATED 25 January 2016
-@set UPDATED-MONTH January 2016
+@set UPDATED 20 April 2016
+@set UPDATED-MONTH April 2016
 
-@set LASTCHANGE Mon Jan 25 10:08:41 EST 2016
+@set LASTCHANGE Wed Apr 20 13:32:48 PDT 2016
index 02d617e3c6ea86c6cd7c73353f28b8fa1b29b93f..2ecee899c3b0bb1e7b0c9a3be05fec1aa2529abf 100644 (file)
@@ -38,8 +38,6 @@
 #define STREQN(a, b, n) ((n == 0) ? (1) \
                                   : ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
 
-extern int history_offset;
-                                  
 static void
 usage()
 {
index 94becd8a5e11e051204e74b8b852e18a502bbe6a..d836d146ebd58aecd106485e901cf82bf03f8e31 100644 (file)
@@ -41,8 +41,6 @@
 #define STREQN(a, b, n) ((n == 0) ? (1) \
                                   : ((a)[0] == (b)[0] && strncmp(a, b, n) == 0))
 
-extern int history_offset;
-
 #define PURGE_REGEXP   0x01
 
 static void
index 21c12f53a292a191c9df9a8e2f669e1542d1085a..34b1d6ba79fb827a0c2d20c475f764523ec15068 100644 (file)
--- a/funmap.c
+++ b/funmap.c
@@ -1,6 +1,6 @@
 /* funmap.c -- attach names to functions. */
 
-/* Copyright (C) 1987-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2016 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.      
@@ -194,6 +194,7 @@ static const FUNMAP default_funmap[] = {
   { "vi-set-mark", rl_vi_set_mark },
   { "vi-subst", rl_vi_subst },
   { "vi-tilde-expand", rl_vi_tilde_expand },
+  { "vi-unix-word-rubout", rl_vi_unix_word_rubout },
   { "vi-yank-arg", rl_vi_yank_arg },
   { "vi-yank-pop", rl_vi_yank_pop },
   { "vi-yank-to", rl_vi_yank_to },
index fdecebcb0e2317d5c1e04aa1b017784e340d37aa..457cdb4cf3a8c343f4e3a531e1fbba8c9a891915 100644 (file)
@@ -1421,7 +1421,7 @@ history_tokenize_word (string, ind)
      const char *string;
      int ind;
 {
-  register int i;
+  register int i, j;
   int delimiter, nestdelim, delimopen;
 
   i = ind;
@@ -1433,6 +1433,22 @@ history_tokenize_word (string, ind)
       return i;
     }
 
+  if (isdigit (string[i]))
+    {
+      j = i;
+      while (string[j] && isdigit (string[j]))
+       j++;
+      if (string[j] == 0)
+       return (j);
+      if (string[j] == '<' || string[j] == '>')
+       i = j;                  /* digit sequence is a file descriptor */
+      else
+       {
+         i = j;
+         goto get_word;        /* digit sequence is part of a word */
+       }
+    }
+
   if (member (string[i], "<>;&|$"))
     {
       int peek = string[i + 1];
@@ -1446,8 +1462,16 @@ history_tokenize_word (string, ind)
          i += 2;
          return i;
        }
-      else if ((peek == '&' && (string[i] == '>' || string[i] == '<')) ||
-               (peek == '>' && string[i] == '&'))
+      else if (peek == '&' && (string[i] == '>' || string[i] == '<'))
+       {
+         j = i + 2;
+         while (string[j] && isdigit (string[j]))      /* file descriptor */
+           j++;
+         if (string[j] =='-')          /* <&[digits]-, >&[digits]- */
+           j++;
+         return j;
+       }
+      else if ((peek == '>' && string[i] == '&') || (peek == '|' && string[i] == '>'))
        {
          i += 2;
          return i;
index c938a109cc02c51024927e2da0f017f35275f452..28cad14a58aa7df4879334705221ea856519cc1b 100644 (file)
--- a/histlib.h
+++ b/histlib.h
@@ -76,7 +76,4 @@ extern char *strchr ();
 #define HISTORY_APPEND 0
 #define HISTORY_OVERWRITE 1
 
-/* Some variable definitions shared across history source files. */
-extern int history_offset;
-
 #endif /* !_HISTLIB_H_ */
diff --git a/misc.c b/misc.c
index 4fc57e78cb7d59ef54aad75717d86fe234890079..f7acdee06147895d61d8e43e57b971812f5f729f 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -56,8 +56,6 @@
 static int rl_digit_loop PARAMS((void));
 static void _rl_history_set_point PARAMS((void));
 
-extern int history_offset;
-
 /* Forward declarations used in this file */
 void _rl_free_history_entry PARAMS((HIST_ENTRY *));
 
index 547dd314876ce6a95e32585cb0dbf9ffdc026477..e51df4f0c183ab123106b26eb3555b768d108248 100644 (file)
@@ -965,7 +965,7 @@ _rl_dispatch_subseq (key, map, got_subseq)
          /* Tentative inter-character timeout for potential multi-key
             sequences?  If no input within timeout, abort sequence and
             act as if we got non-matching input. */
-         /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued[B
+         /* _rl_keyseq_timeout specified in milliseconds; _rl_input_queued
             takes microseconds, so multiply by 1000 */
          if (_rl_keyseq_timeout > 0 &&
                (RL_ISSTATE (RL_STATE_INPUTPENDING|RL_STATE_MACROINPUT) == 0) &&
index 3af93ddcae86b68647702a7f8bb7ed1169032ed0..0bd2e04484aee33daa7484c42a3f129108f987af 100644 (file)
@@ -1,6 +1,6 @@
 /* Readline.h -- the names of functions callable from within readline. */
 
-/* Copyright (C) 1987-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2016 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.      
@@ -253,6 +253,7 @@ extern int rl_vi_yank_pop PARAMS((int, int));
 extern int rl_vi_rubout PARAMS((int, int));
 extern int rl_vi_delete PARAMS((int, int));
 extern int rl_vi_back_to_indent PARAMS((int, int));
+extern int rl_vi_unix_word_rubout PARAMS((int, int));
 extern int rl_vi_first_print PARAMS((int, int));
 extern int rl_vi_char_search PARAMS((int, int));
 extern int rl_vi_match PARAMS((int, int));
@@ -378,6 +379,7 @@ extern void rl_redisplay PARAMS((void));
 extern int rl_on_new_line PARAMS((void));
 extern int rl_on_new_line_with_prompt PARAMS((void));
 extern int rl_forced_update_display PARAMS((void));
+extern int rl_clear_visible_line PARAMS((void));
 extern int rl_clear_message PARAMS((void));
 extern int rl_reset_line_state PARAMS((void));
 extern int rl_crlf PARAMS((void));
diff --git a/rltty.c b/rltty.c
index 1cad8bca0d1df6cb576a0dc737c943838ce46612..b1c79294186f55667fce393b46d54c5892d44743 100644 (file)
--- a/rltty.c
+++ b/rltty.c
@@ -1,7 +1,7 @@
 /* rltty.c -- functions to prepare and restore the terminal for readline's
    use. */
 
-/* Copyright (C) 1992-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2016 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.
@@ -714,6 +714,19 @@ rl_deprep_terminal ()
   _rl_release_sigint ();
 }
 #endif /* !NO_TTY_DRIVER */
+
+/* Set readline's idea of whether or not it is echoing output to the terminal,
+   returning the old value. */
+int
+rl_tty_set_echoing (u)
+     int u;
+{
+  int o;
+
+  o = _rl_echoing_p;
+  _rl_echoing_p = u;
+  return o;
+}
 \f
 /* **************************************************************** */
 /*                                                                 */
@@ -876,6 +889,11 @@ _rl_bind_tty_special_chars (kmap, ttybuff)
 #  endif /* VLNEXT && TERMIOS_TTY_DRIVER */
 
 #  if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
+#    if defined (VI_MODE)
+  if (rl_editing_mode == vi_mode)
+    SET_SPECIAL (VWERASE, rl_vi_unix_word_rubout);
+  else
+#    endif
   SET_SPECIAL (VWERASE, rl_unix_word_rubout);
 #  endif /* VWERASE && TERMIOS_TTY_DRIVER */
 }
diff --git a/text.c b/text.c
index d54499dccdc1b0c43b553b9a6a67db5b22534c52..c353252bc9fbe8adee0bf206a994c2d85d9eee73 100644 (file)
--- a/text.c
+++ b/text.c
@@ -572,7 +572,7 @@ rl_refresh_line (ignore1, ignore2)
 
   _rl_clear_to_eol (0);                /* arg of 0 means to not use spaces */
 
-  rl_forced_update_display ();
+  rl_redraw_prompt_last_line ();
   rl_display_fixed = 1;
 
   return 0;
index 60c925d93700bfb11522a7729ff6ea90e7e3a7b4..e5da2e0fa0b572ce0e3aa938b6a1076e2ed787fc 100644 (file)
@@ -1,6 +1,6 @@
 /* vi_keymap.c -- the keymap for vi_mode in readline (). */
 
-/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2016 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.      
@@ -55,7 +55,7 @@ KEYMAP_ENTRY_ARRAY vi_movement_keymap = {
   { ISFUNC, rl_transpose_chars },              /* Control-t */
   { ISFUNC, rl_unix_line_discard },            /* Control-u */
   { ISFUNC, rl_quoted_insert },                        /* Control-v */
-  { ISFUNC, rl_unix_word_rubout },             /* Control-w */
+  { ISFUNC, rl_vi_unix_word_rubout },          /* Control-w */
   { ISFUNC, (rl_command_func_t *)0x0 },                /* Control-x */
   { ISFUNC, rl_yank },                         /* Control-y */
   { ISFUNC, (rl_command_func_t *)0x0 },                /* Control-z */
@@ -334,7 +334,7 @@ KEYMAP_ENTRY_ARRAY vi_insertion_keymap = {
   { ISFUNC, rl_transpose_chars },              /* Control-t */
   { ISFUNC, rl_unix_line_discard },            /* Control-u */
   { ISFUNC, rl_quoted_insert },                        /* Control-v */
-  { ISFUNC, rl_unix_word_rubout },             /* Control-w */
+  { ISFUNC, rl_vi_unix_word_rubout },          /* Control-w */
   { ISFUNC, rl_insert },                       /* Control-x */
   { ISFUNC, rl_yank },                         /* Control-y */
   { ISFUNC, rl_insert },                       /* Control-z */
index 01ab83010a7e0c4d635472c585291c296860cf97..56d2e72fb7f2da12747c93db67404777fd5fd1cd 100644 (file)
--- a/vi_mode.c
+++ b/vi_mode.c
@@ -1,7 +1,7 @@
 /* vi_mode.c -- A vi emulation mode for Bash.
    Derived from code written by Jeff Sparkes (jsparkes@bnr.ca).  */
 
-/* Copyright (C) 1987-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2016 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.      
@@ -1620,6 +1620,62 @@ rl_vi_delete (count, key)
   return (0);
 }
 
+/* This does what Posix specifies vi-mode C-w to do: using whitespace and
+   punctuation characters as the word boundaries. */
+
+#define vi_unix_word_boundary(c)       (whitespace(c) || ispunct(c))
+
+int
+rl_vi_unix_word_rubout (count, key)
+     int count, key;
+{
+  int orig_point;
+
+  if (rl_point == 0)
+    rl_ding ();
+  else
+    {
+      orig_point = rl_point;
+      if (count <= 0)
+       count = 1;
+
+      while (count--)
+       {
+         /* This isn't quite what ksh93 does but it seems to match what the
+            Posix description of sh specifies, with a few accommodations
+            for sequences of whitespace characters between words and at
+            the end of the line. */
+
+         /* Skip over whitespace at the end of the line as a special case */
+         if (rl_point > 0 && (rl_line_buffer[rl_point] == 0) &&
+               whitespace (rl_line_buffer[rl_point - 1]))
+           while (--rl_point > 0 && whitespace (rl_line_buffer[rl_point]))
+             ;
+
+         /* If we're at the start of a word, move back to word boundary so we
+            move back to the `preceding' word */
+         if (rl_point > 0 && (vi_unix_word_boundary (rl_line_buffer[rl_point]) == 0) &&
+               vi_unix_word_boundary (rl_line_buffer[rl_point - 1]))
+           rl_point--;
+
+         /* If we are at a word boundary (whitespace/punct), move backward
+            past a sequence of word boundary characters.  If we are at the
+            end of a word (non-word boundary), move back to a word boundary */
+         if (rl_point > 0 && vi_unix_word_boundary (rl_line_buffer[rl_point]))
+           while (rl_point && vi_unix_word_boundary (rl_line_buffer[rl_point - 1]))
+             rl_point--;
+         else if (rl_point > 0 && vi_unix_word_boundary (rl_line_buffer[rl_point]) == 0)
+           while (rl_point && (vi_unix_word_boundary (rl_line_buffer[rl_point - 1]) == 0))
+             rl_point--;
+       }
+
+      rl_kill_text (orig_point, rl_point);
+    }
+
+  return 0;
+}
+
+
 int
 rl_vi_back_to_indent (count, key)
      int count, key;