From 2ed81ae22baa941bf9bcdae3df624f1a3350e2d7 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 13 May 2014 07:54:20 +0000 Subject: [PATCH] Add a copy mode key binding to copy to a named buffer. From J Raynor. --- usr.bin/tmux/mode-key.c | 4 +++- usr.bin/tmux/tmux.1 | 3 ++- usr.bin/tmux/tmux.h | 3 ++- usr.bin/tmux/window-copy.c | 18 +++++++++++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/usr.bin/tmux/mode-key.c b/usr.bin/tmux/mode-key.c index c22b4eef2b1..f4d3c89016a 100644 --- a/usr.bin/tmux/mode-key.c +++ b/usr.bin/tmux/mode-key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mode-key.c,v 1.58 2014/03/31 21:39:31 nicm Exp $ */ +/* $OpenBSD: mode-key.c,v 1.59 2014/05/13 07:54:20 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -141,6 +141,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_copy[] = { { MODEKEYCOPY_SEARCHREVERSE, "search-reverse" }, { MODEKEYCOPY_SEARCHUP, "search-backward" }, { MODEKEYCOPY_SELECTLINE, "select-line" }, + { MODEKEYCOPY_STARTNAMEDBUFFER, "start-named-buffer" }, { MODEKEYCOPY_STARTNUMBERPREFIX, "start-number-prefix" }, { MODEKEYCOPY_STARTOFLINE, "start-of-line" }, { MODEKEYCOPY_STARTSELECTION, "begin-selection" }, @@ -257,6 +258,7 @@ struct mode_key_tree mode_key_tree_vi_choice; /* vi copy mode keys. */ const struct mode_key_entry mode_key_vi_copy[] = { { ' ', 0, MODEKEYCOPY_STARTSELECTION }, + { '"', 0, MODEKEYCOPY_STARTNAMEDBUFFER }, { '$', 0, MODEKEYCOPY_ENDOFLINE }, { ',', 0, MODEKEYCOPY_JUMPREVERSE }, { ';', 0, MODEKEYCOPY_JUMPAGAIN }, diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index e20f848350e..842dbea0cd1 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.392 2014/05/13 07:34:35 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.393 2014/05/13 07:54:20 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -849,6 +849,7 @@ The following keys are supported as appropriate for the mode: .It Sy "Function" Ta Sy "vi" Ta Sy "emacs" .It Li "Append selection" Ta "A" Ta "" .It Li "Back to indentation" Ta "^" Ta "M-m" +.It Li "Copy to named buffer" Ta \&" Ta "" .It Li "Bottom of history" Ta "G" Ta "M-<" .It Li "Clear selection" Ta "Escape" Ta "C-g" .It Li "Copy selection" Ta "Enter" Ta "M-w" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ea09031fe66..42f863d74de 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.461 2014/05/13 07:34:35 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.462 2014/05/13 07:54:20 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -583,6 +583,7 @@ enum mode_key_cmd { MODEKEYCOPY_SEARCHREVERSE, MODEKEYCOPY_SEARCHUP, MODEKEYCOPY_SELECTLINE, + MODEKEYCOPY_STARTNAMEDBUFFER, MODEKEYCOPY_STARTNUMBERPREFIX, MODEKEYCOPY_STARTOFLINE, MODEKEYCOPY_STARTSELECTION, diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 73f931cf9b6..8d36667ccfe 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.108 2014/05/13 07:34:35 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.109 2014/05/13 07:54:20 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -61,8 +61,8 @@ void window_copy_copy_pipe(struct window_pane *, struct session *, void window_copy_copy_selection(struct window_pane *, const char *); void window_copy_append_selection(struct window_pane *, const char *); void window_copy_clear_selection(struct window_pane *); -void window_copy_copy_line( - struct window_pane *, char **, size_t *, u_int, u_int, u_int); +void window_copy_copy_line(struct window_pane *, char **, size_t *, u_int, + u_int, u_int); int window_copy_in_set(struct window_pane *, u_int, u_int, const char *); u_int window_copy_find_length(struct window_pane *, u_int); void window_copy_cursor_start_of_line(struct window_pane *); @@ -95,6 +95,7 @@ const struct window_mode window_copy_mode = { enum window_copy_input_type { WINDOW_COPY_OFF, + WINDOW_COPY_NAMEDBUFFER, WINDOW_COPY_NUMERICPREFIX, WINDOW_COPY_SEARCHUP, WINDOW_COPY_SEARCHDOWN, @@ -677,6 +678,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) case WINDOW_COPY_JUMPBACK: case WINDOW_COPY_JUMPTOFORWARD: case WINDOW_COPY_JUMPTOBACK: + case WINDOW_COPY_NAMEDBUFFER: case WINDOW_COPY_NUMERICPREFIX: break; case WINDOW_COPY_SEARCHUP: @@ -712,6 +714,11 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) data->inputprompt = "Goto Line"; *data->inputstr = '\0'; goto input_on; + case MODEKEYCOPY_STARTNAMEDBUFFER: + data->inputtype = WINDOW_COPY_NAMEDBUFFER; + data->inputprompt = "Buffer"; + *data->inputstr = '\0'; + goto input_on; case MODEKEYCOPY_STARTNUMBERPREFIX: key &= KEYC_MASK_KEY; if (key >= '0' && key <= '9') { @@ -815,6 +822,11 @@ window_copy_key_input(struct window_pane *wp, int key) data->searchtype = data->inputtype; data->searchstr = xstrdup(data->inputstr); break; + case WINDOW_COPY_NAMEDBUFFER: + window_copy_copy_selection(wp, data->inputstr); + *data->inputstr = '\0'; + window_pane_reset_mode(wp); + return (0); case WINDOW_COPY_GOTOLINE: window_copy_goto_line(wp, data->inputstr); *data->inputstr = '\0'; -- 2.20.1