The editing facilities in the search prompt in tmux's copy mode are kept
to a minimum.  However, since deleting to the beginning of the prompt
with `C-u' and deleting the previous letter with `C-h' work as usual, I
would have expected that `C-w' would work as well and delete to the
beginning of the previous word.  Currently `C-w' is silently ignored.

The patch below follows the logic of the MODEKEYEDIT_DELETEWORD case in
status_prompt_key(), in status.c, line 1040.  It is a bit simpler
because the cursor position is always at the end of the input string.

Index: tmux.1
===================================================================
RCS file: /cvs/src/usr.bin/tmux/tmux.1,v
retrieving revision 1.404
diff -u -p -r1.404 tmux.1
--- tmux.1      25 Oct 2014 08:47:04 -0000      1.404
+++ tmux.1      3 Nov 2014 10:58:52 -0000
@@ -887,6 +887,7 @@ The following keys are supported as appr
 .It Li "Cursor to top line" Ta "H" Ta "M-R"
 .It Li "Cursor up" Ta "k" Ta "Up"
 .It Li "Delete entire line" Ta "d" Ta "C-u"
+.It Li "Delete previous word" Ta "C-w" Ta "C-w"
 .It Li "Delete/Copy to end of line" Ta "D" Ta "C-k"
 .It Li "End of line" Ta "$" Ta "C-e"
 .It Li "Go to line" Ta ":" Ta "g"
Index: window-copy.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/window-copy.c,v
retrieving revision 1.117
diff -u -p -r1.117 window-copy.c
--- window-copy.c       22 Oct 2014 23:18:53 -0000      1.117
+++ window-copy.c       3 Nov 2014 10:58:52 -0000
@@ -28,7 +28,7 @@ struct screen *window_copy_init(struct w
 void   window_copy_free(struct window_pane *);
 void   window_copy_resize(struct window_pane *, u_int, u_int);
 void   window_copy_key(struct window_pane *, struct session *, int);
-int    window_copy_key_input(struct window_pane *, int);
+int    window_copy_key_input(struct window_pane *, struct session *, int);
 int    window_copy_key_numeric_prefix(struct window_pane *, int);
 void   window_copy_mouse(
            struct window_pane *, struct session *, struct mouse_event *);
@@ -411,7 +411,7 @@ window_copy_key(struct window_pane *wp, 
                data->inputtype = WINDOW_COPY_OFF;
                window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
        } else if (data->inputtype != WINDOW_COPY_OFF) {
-               if (window_copy_key_input(wp, key) != 0)
+               if (window_copy_key_input(wp, sess, key) != 0)
                        goto input_off;
                return;
        }
@@ -763,13 +763,14 @@ input_off:
 }
 
 int
-window_copy_key_input(struct window_pane *wp, int key)
+window_copy_key_input(struct window_pane *wp, struct session *sess, int key)
 {
        struct window_copy_mode_data    *data = wp->modedata;
        struct screen                   *s = &data->screen;
        size_t                           inputlen, n;
        int                              np;
        struct paste_buffer             *pb;
+       const char                      *wsep = NULL;
        u_char                           ch;
 
        switch (mode_key_lookup(&data->mdata, key, NULL)) {
@@ -780,6 +781,27 @@ window_copy_key_input(struct window_pane
                inputlen = strlen(data->inputstr);
                if (inputlen > 0)
                        data->inputstr[inputlen - 1] = '\0';
+               break;
+       case MODEKEYEDIT_DELETEWORD:
+               if ((inputlen = strlen(data->inputstr)) == 0)
+                       break;
+               wsep = options_get_string(&sess->options, "word-separators");
+               /* Find a non-separator. */
+               while (inputlen != 0) {
+                       inputlen--;
+                       if (!strchr(wsep, data->inputstr[inputlen]))
+                               break;
+               }
+               /* Find the separator at the beginning of the word. */
+               while (inputlen != 0) {
+                       inputlen--;
+                       if (strchr(wsep, data->inputstr[inputlen])) {
+                               /* Go back to the word. */
+                               inputlen++;
+                               break;
+                       }
+               }
+               data->inputstr[inputlen] = '\0';
                break;
        case MODEKEYEDIT_DELETELINE:
                *data->inputstr = '\0';

Reply via email to