mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Add a -x flag to copy-selection, append-selection and start-named-buffer
to prevent it exiting copy mode after copying. From J Raynor with a few tweaks by me.
This commit is contained in:
		| @@ -104,18 +104,34 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key) | |||||||
| 		return (CMD_RETURN_ERROR); | 		return (CMD_RETURN_ERROR); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (cmd != MODEKEYCOPY_COPYPIPE) { | 	switch (cmd) { | ||||||
| 		if (args->argc != 2) { | 	case MODEKEYCOPY_APPENDSELECTION: | ||||||
| 			cmdq_error(cmdq, "no argument allowed"); | 	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 argument"); | ||||||
| 				return (CMD_RETURN_ERROR); | 				return (CMD_RETURN_ERROR); | ||||||
| 			} | 			} | ||||||
| 		arg = NULL; | 		} | ||||||
| 	} else { | 		break; | ||||||
|  | 	case MODEKEYCOPY_COPYPIPE: | ||||||
| 		if (args->argc != 3) { | 		if (args->argc != 3) { | ||||||
| 			cmdq_error(cmdq, "no argument given"); | 			cmdq_error(cmdq, "no argument given"); | ||||||
| 			return (CMD_RETURN_ERROR); | 			return (CMD_RETURN_ERROR); | ||||||
| 		} | 		} | ||||||
| 		arg = args->argv[2]; | 		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; | 	mtmp.key = key; | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -987,15 +987,27 @@ command and keys modified or removed with | |||||||
| .Ic bind-key | .Ic bind-key | ||||||
| and | and | ||||||
| .Ic unbind-key . | .Ic unbind-key . | ||||||
| One command accepts an argument, | If | ||||||
| .Ic copy-pipe , | .Ic append-selection , | ||||||
| which copies the selection and pipes it to a command. | .Ic copy-selection , | ||||||
|  | or | ||||||
|  | .Ic start-named-buffer | ||||||
|  | are given the | ||||||
|  | .Fl x | ||||||
|  | flag, | ||||||
|  | .Nm | ||||||
|  | will not exit copy mode after copying. | ||||||
|  | .Ic copy-pipe | ||||||
|  | copies the selection and pipes it to a command. | ||||||
| For example the following will bind | For example the following will bind | ||||||
|  | .Ql C-w | ||||||
|  | not to exit after copying and | ||||||
| .Ql C-q | .Ql C-q | ||||||
| to copy the selection into | to copy the selection into | ||||||
| .Pa /tmp | .Pa /tmp | ||||||
| as well as the paste buffer: | as well as the paste buffer: | ||||||
| .Bd -literal -offset indent | .Bd -literal -offset indent | ||||||
|  | bind-key -temacs-copy C-w copy-selection -x | ||||||
| bind-key -temacs-copy C-q copy-pipe "cat >/tmp/out" | bind-key -temacs-copy C-q copy-pipe "cat >/tmp/out" | ||||||
| .Ed | .Ed | ||||||
| .Pp | .Pp | ||||||
|   | |||||||
| @@ -147,6 +147,7 @@ struct window_copy_mode_data { | |||||||
| 	enum window_copy_input_type inputtype; | 	enum window_copy_input_type inputtype; | ||||||
| 	const char     *inputprompt; | 	const char     *inputprompt; | ||||||
| 	char	       *inputstr; | 	char	       *inputstr; | ||||||
|  | 	int		inputexit; | ||||||
|  |  | ||||||
| 	int		numprefix; | 	int		numprefix; | ||||||
|  |  | ||||||
| @@ -424,9 +425,13 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) | |||||||
| 	case MODEKEYCOPY_APPENDSELECTION: | 	case MODEKEYCOPY_APPENDSELECTION: | ||||||
| 		if (sess != NULL) { | 		if (sess != NULL) { | ||||||
| 			window_copy_append_selection(wp, NULL); | 			window_copy_append_selection(wp, NULL); | ||||||
|  | 			if (arg == NULL) { | ||||||
| 				window_pane_reset_mode(wp); | 				window_pane_reset_mode(wp); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  | 			window_copy_clear_selection(wp); | ||||||
|  | 			window_copy_redraw_screen(wp); | ||||||
|  | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case MODEKEYCOPY_CANCEL: | 	case MODEKEYCOPY_CANCEL: | ||||||
| 		window_pane_reset_mode(wp); | 		window_pane_reset_mode(wp); | ||||||
| @@ -572,9 +577,13 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) | |||||||
| 	case MODEKEYCOPY_COPYSELECTION: | 	case MODEKEYCOPY_COPYSELECTION: | ||||||
| 		if (sess != NULL) { | 		if (sess != NULL) { | ||||||
| 			window_copy_copy_selection(wp, NULL); | 			window_copy_copy_selection(wp, NULL); | ||||||
|  | 			if (arg == NULL) { | ||||||
| 				window_pane_reset_mode(wp); | 				window_pane_reset_mode(wp); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
|  | 			window_copy_clear_selection(wp); | ||||||
|  | 			window_copy_redraw_screen(wp); | ||||||
|  | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case MODEKEYCOPY_STARTOFLINE: | 	case MODEKEYCOPY_STARTOFLINE: | ||||||
| 		window_copy_cursor_start_of_line(wp); | 		window_copy_cursor_start_of_line(wp); | ||||||
| @@ -718,6 +727,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) | |||||||
| 		goto input_on; | 		goto input_on; | ||||||
| 	case MODEKEYCOPY_STARTNAMEDBUFFER: | 	case MODEKEYCOPY_STARTNAMEDBUFFER: | ||||||
| 		data->inputtype = WINDOW_COPY_NAMEDBUFFER; | 		data->inputtype = WINDOW_COPY_NAMEDBUFFER; | ||||||
|  | 		data->inputexit = (arg == NULL); | ||||||
| 		data->inputprompt = "Buffer"; | 		data->inputprompt = "Buffer"; | ||||||
| 		*data->inputstr = '\0'; | 		*data->inputstr = '\0'; | ||||||
| 		goto input_on; | 		goto input_on; | ||||||
| @@ -828,8 +838,13 @@ window_copy_key_input(struct window_pane *wp, int key) | |||||||
| 		case WINDOW_COPY_NAMEDBUFFER: | 		case WINDOW_COPY_NAMEDBUFFER: | ||||||
| 			window_copy_copy_selection(wp, data->inputstr); | 			window_copy_copy_selection(wp, data->inputstr); | ||||||
| 			*data->inputstr = '\0'; | 			*data->inputstr = '\0'; | ||||||
|  | 			if (data->inputexit) { | ||||||
| 				window_pane_reset_mode(wp); | 				window_pane_reset_mode(wp); | ||||||
| 				return (0); | 				return (0); | ||||||
|  | 			} | ||||||
|  | 			window_copy_clear_selection(wp); | ||||||
|  | 			window_copy_redraw_screen(wp); | ||||||
|  | 			break; | ||||||
| 		case WINDOW_COPY_GOTOLINE: | 		case WINDOW_COPY_GOTOLINE: | ||||||
| 			window_copy_goto_line(wp, data->inputstr); | 			window_copy_goto_line(wp, data->inputstr); | ||||||
| 			*data->inputstr = '\0'; | 			*data->inputstr = '\0'; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm