Keys in status line (p in vi mode, M-y in emacs) to paste the first line of the upper paste buffer. Suggested by Dan Colish.

pull/1/head
Nicholas Marriott 2009-05-14 19:36:56 +00:00
parent 8931f0018a
commit cba338ac13
4 changed files with 44 additions and 8 deletions

View File

@ -1,5 +1,7 @@
14 May 2009 14 May 2009
* Keys in status line (p in vi mode, M-y in emacs) to paste the first line
of the upper paste buffer. Suggested by Dan Colish.
* clear-history command to clear a pane's history. * clear-history command to clear a pane's history.
* Don't force wrapping with \n when asked, let the cursor code figure it out. * Don't force wrapping with \n when asked, let the cursor code figure it out.
Should fix terminals which use this to detect line breaks. Should fix terminals which use this to detect line breaks.
@ -1255,7 +1257,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.287 2009-05-14 16:56:23 nicm Exp $ $Id: CHANGES,v 1.288 2009-05-14 19:36:56 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

View File

@ -1,4 +1,4 @@
/* $Id: mode-key.c,v 1.11 2009-05-04 17:58:27 nicm Exp $ */ /* $Id: mode-key.c,v 1.12 2009-05-14 19:36:56 nicm Exp $ */
/* /*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -54,6 +54,13 @@ mode_key_lookup(struct mode_key_data *mdata, int key)
enum mode_key_cmd enum mode_key_cmd
mode_key_lookup_vi(struct mode_key_data *mdata, int key) mode_key_lookup_vi(struct mode_key_data *mdata, int key)
{ {
if (KEYC_ISESC(key)) {
key = KEYC_REMOVEESC(key);
if (mdata->flags & MODEKEY_CANEDIT)
mdata->flags ^= MODEKEY_EDITMODE;
}
if (mdata->flags & MODEKEY_EDITMODE) { if (mdata->flags & MODEKEY_EDITMODE) {
switch (key) { switch (key) {
case '\003': case '\003':
@ -131,6 +138,8 @@ mode_key_lookup_vi(struct mode_key_data *mdata, int key)
case 'k': case 'k':
case KEYC_UP: case KEYC_UP:
return (MODEKEYCMD_UP); return (MODEKEYCMD_UP);
case 'p':
return (MODEKEYCMD_PASTE);
} }
return (MODEKEYCMD_NONE); return (MODEKEYCMD_NONE);
@ -173,6 +182,8 @@ mode_key_lookup_emacs(struct mode_key_data *mdata, int key)
return (MODEKEYCMD_NEXTPAGE); return (MODEKEYCMD_NEXTPAGE);
case KEYC_ADDESC('f'): case KEYC_ADDESC('f'):
return (MODEKEYCMD_NEXTWORD); return (MODEKEYCMD_NEXTWORD);
case '\031':
return (MODEKEYCMD_PASTE);
case KEYC_ADDESC('v'): case KEYC_ADDESC('v'):
case KEYC_PPAGE: case KEYC_PPAGE:
return (MODEKEYCMD_PREVIOUSPAGE); return (MODEKEYCMD_PREVIOUSPAGE);

View File

@ -1,4 +1,4 @@
/* $Id: status.c,v 1.79 2009-05-13 23:29:45 nicm Exp $ */ /* $Id: status.c,v 1.80 2009-05-14 19:36:56 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -673,9 +673,9 @@ status_prompt_redraw(struct client *c)
void void
status_prompt_key(struct client *c, int key) status_prompt_key(struct client *c, int key)
{ {
char *s, *first, *last; struct paste_buffer *pb;
size_t size, n, off, idx; char *s, *first, *last, word[64];
char word[64]; size_t size, n, off, idx;
size = strlen(c->prompt_buffer); size = strlen(c->prompt_buffer);
switch (mode_key_lookup(&c->prompt_mdata, key)) { switch (mode_key_lookup(&c->prompt_mdata, key)) {
@ -805,6 +805,28 @@ status_prompt_key(struct client *c, int key)
c->prompt_index = strlen(c->prompt_buffer); c->prompt_index = strlen(c->prompt_buffer);
c->flags |= CLIENT_STATUS; c->flags |= CLIENT_STATUS;
break; break;
case MODEKEYCMD_PASTE:
if ((pb = paste_get_top(&c->session->buffers)) == NULL)
break;
if ((last = strchr(pb->data, '\n')) == NULL)
last = strchr(pb->data, '\0');
n = last - pb->data;
c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + n + 1);
if (c->prompt_index == size) {
memcpy(c->prompt_buffer + c->prompt_index, pb->data, n);
c->prompt_index += n;
c->prompt_buffer[c->prompt_index] = '\0';
} else {
memmove(c->prompt_buffer + c->prompt_index + n,
c->prompt_buffer + c->prompt_index,
size + 1 - c->prompt_index);
memcpy(c->prompt_buffer + c->prompt_index, pb->data, n);
c->prompt_index += n;
}
c->flags |= CLIENT_STATUS;
break;
case MODEKEYCMD_CHOOSE: case MODEKEYCMD_CHOOSE:
if (*c->prompt_buffer != '\0') { if (*c->prompt_buffer != '\0') {
status_prompt_add_history(c); status_prompt_add_history(c);

5
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.315 2009-05-14 16:56:23 nicm Exp $ */ /* $Id: tmux.h,v 1.316 2009-05-14 19:36:56 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -422,7 +422,7 @@ struct msg_resize_data {
/* Editing keys. */ /* Editing keys. */
enum mode_key_cmd { enum mode_key_cmd {
MODEKEYCMD_BACKSPACE, MODEKEYCMD_BACKSPACE = 0x1000,
MODEKEYCMD_CHOOSE, MODEKEYCMD_CHOOSE,
MODEKEYCMD_CLEARSELECTION, MODEKEYCMD_CLEARSELECTION,
MODEKEYCMD_COMPLETE, MODEKEYCMD_COMPLETE,
@ -435,6 +435,7 @@ enum mode_key_cmd {
MODEKEYCMD_NEXTWORD, MODEKEYCMD_NEXTWORD,
MODEKEYCMD_NONE, MODEKEYCMD_NONE,
MODEKEYCMD_OTHERKEY, MODEKEYCMD_OTHERKEY,
MODEKEYCMD_PASTE,
MODEKEYCMD_PREVIOUSPAGE, MODEKEYCMD_PREVIOUSPAGE,
MODEKEYCMD_PREVIOUSWORD, MODEKEYCMD_PREVIOUSWORD,
MODEKEYCMD_QUIT, MODEKEYCMD_QUIT,