> You could maybe make copy-selection accept an argument like copy-pipe. I
> wouldn't make it do the full getopt dance just yet but just accepting
> "-n" or "-x" or something might work.

I've attached a patch that allows you to pass -x to the key bindings
for append-selection, copy-selection, and start-named-buffer so all 3
can be used to do a copy without leaving copy mode.
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 5d68d48..7e83c69 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -104,18 +104,34 @@ 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");
-			return (CMD_RETURN_ERROR);
+	switch(cmd) {
+	case MODEKEYCOPY_APPENDSELECTION:
+	case MODEKEYCOPY_COPYSELECTION:
+	case MODEKEYCOPY_STARTNAMEDBUFFER:
+		if (args->argc == 2)
+			arg = NULL;
+		else {
+			arg = args->argv[2];
+			if (strcmp(arg, "-x") != 0) {
+				cmdq_error(cmdq, "unknown option");
+				return (CMD_RETURN_ERROR);
+			}
 		}
-		arg = NULL;
-	} else {
+		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';
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to