Ah yes you're right, I missed that, the previous diff is fine then.

On Tue, Feb 24, 2015 at 06:02:35PM -0600, J Raynor wrote:
> > I think you want only 2 or 3 arguments to be valid, 4 should be an
> > error. Otherwise this looks fine.
> 
> You already can't pass 4 arguments.  The check for -t in
> cmd_bind_key_exec prevents anything but 2 or 3 args from getting to
> that section of code.
> 
> If you'd prefer the check to be there anyway, then see the attached
> patch.  It checks for argc > 3, but otherwise is the same as before.

> diff --git a/cmd-bind-key.c b/cmd-bind-key.c
> index 5d68d48..3c8a8cd 100644
> --- a/cmd-bind-key.c
> +++ b/cmd-bind-key.c
> @@ -104,18 +104,36 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q 
> *cmdq, int key)
>               return (CMD_RETURN_ERROR);
>       }
>  
> -     if (cmd != MODEKEYCOPY_COPYPIPE) {
> -             if (args->argc != 2) {
> -                     cmdq_error(cmdq, "no argument allowed");
> +     switch(cmd) {
> +     case MODEKEYCOPY_APPENDSELECTION:
> +     case MODEKEYCOPY_COPYSELECTION:
> +     case MODEKEYCOPY_STARTNAMEDBUFFER:
> +             if (args->argc > 3) {
> +                     cmdq_error(cmdq, "too many arguments");
>                       return (CMD_RETURN_ERROR);
> -             }
> -             arg = NULL;
> -     } else {
> +             } else if (args->argc == 3) {
> +                     arg = args->argv[2];
> +                     if (strcmp(arg, "-x") != 0) {
> +                             cmdq_error(cmdq, "unknown option");
> +                             return (CMD_RETURN_ERROR);
> +                     }
> +             } else
> +                     arg = NULL;
> +             break;
> +     case MODEKEYCOPY_COPYPIPE:
>               if (args->argc != 3) {
>                       cmdq_error(cmdq, "no argument given");
>                       return (CMD_RETURN_ERROR);
>               }
>               arg = args->argv[2];
> +             break;
> +     default:
> +             if (args->argc != 2) {
> +                     cmdq_error(cmdq, "no argument allowed");
> +                     return (CMD_RETURN_ERROR);
> +             }
> +             arg = NULL;
> +             break;
>       }
>  
>       mtmp.key = key;
> diff --git a/tmux.1 b/tmux.1
> index f615dd0..ff0632d 100644
> --- a/tmux.1
> +++ b/tmux.1
> @@ -991,9 +991,17 @@ command and keys modified or removed with
>  .Ic bind-key
>  and
>  .Ic unbind-key .
> -One command accepts an argument,
> -.Ic copy-pipe ,
> -which copies the selection and pipes it to a command.
> +The
> +.Ic append-selection ,
> +.Ic copy-selection ,
> +and
> +.Ic start-named-buffer
> +commands accept a
> +.Fl x
> +argument which prevents tmux from exiting copy mode after
> +a selection has been copied.  The
> +.Ic copy-pipe
> +command accepts an argument which copies the selection and pipes it to a 
> command.
>  For example the following will bind
>  .Ql C-q
>  to copy the selection into
> diff --git a/window-copy.c b/window-copy.c
> index 223df88..7f015eb 100644
> --- a/window-copy.c
> +++ b/window-copy.c
> @@ -97,6 +97,7 @@ const struct window_mode window_copy_mode = {
>  enum window_copy_input_type {
>       WINDOW_COPY_OFF,
>       WINDOW_COPY_NAMEDBUFFER,
> +     WINDOW_COPY_NAMEDBUFFER_NOEXIT,
>       WINDOW_COPY_NUMERICPREFIX,
>       WINDOW_COPY_SEARCHUP,
>       WINDOW_COPY_SEARCHDOWN,
> @@ -424,8 +425,13 @@ window_copy_key(struct window_pane *wp, struct session 
> *sess, int key)
>       case MODEKEYCOPY_APPENDSELECTION:
>               if (sess != NULL) {
>                       window_copy_append_selection(wp, NULL);
> -                     window_pane_reset_mode(wp);
> -                     return;
> +                     if (arg == NULL) {
> +                             window_pane_reset_mode(wp);
> +                             return;
> +                     }
> +
> +                     window_copy_clear_selection(wp);
> +                     window_copy_redraw_screen(wp);
>               }
>               break;
>       case MODEKEYCOPY_CANCEL:
> @@ -572,8 +578,13 @@ window_copy_key(struct window_pane *wp, struct session 
> *sess, int key)
>       case MODEKEYCOPY_COPYSELECTION:
>               if (sess != NULL) {
>                       window_copy_copy_selection(wp, NULL);
> -                     window_pane_reset_mode(wp);
> -                     return;
> +                     if (arg == NULL) {
> +                             window_pane_reset_mode(wp);
> +                             return;
> +                     }
> +
> +                     window_copy_clear_selection(wp);
> +                     window_copy_redraw_screen(wp);
>               }
>               break;
>       case MODEKEYCOPY_STARTOFLINE:
> @@ -687,6 +698,7 @@ window_copy_key(struct window_pane *wp, struct session 
> *sess, int key)
>               case WINDOW_COPY_JUMPTOFORWARD:
>               case WINDOW_COPY_JUMPTOBACK:
>               case WINDOW_COPY_NAMEDBUFFER:
> +             case WINDOW_COPY_NAMEDBUFFER_NOEXIT:
>               case WINDOW_COPY_NUMERICPREFIX:
>                       break;
>               case WINDOW_COPY_SEARCHUP:
> @@ -717,7 +729,11 @@ window_copy_key(struct window_pane *wp, struct session 
> *sess, int key)
>               *data->inputstr = '\0';
>               goto input_on;
>       case MODEKEYCOPY_STARTNAMEDBUFFER:
> -             data->inputtype = WINDOW_COPY_NAMEDBUFFER;
> +             if (arg == NULL)
> +                     data->inputtype = WINDOW_COPY_NAMEDBUFFER;
> +             else
> +                     data->inputtype = WINDOW_COPY_NAMEDBUFFER_NOEXIT;
> +
>               data->inputprompt = "Buffer";
>               *data->inputstr = '\0';
>               goto input_on;
> @@ -830,6 +846,11 @@ window_copy_key_input(struct window_pane *wp, int key)
>                       *data->inputstr = '\0';
>                       window_pane_reset_mode(wp);
>                       return (0);
> +             case WINDOW_COPY_NAMEDBUFFER_NOEXIT:
> +                     window_copy_copy_selection(wp, data->inputstr);
> +                     window_copy_clear_selection(wp);
> +                     window_copy_redraw_screen(wp);
> +                     break;
>               case WINDOW_COPY_GOTOLINE:
>                       window_copy_goto_line(wp, data->inputstr);
>                       *data->inputstr = '\0';


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to