From cba338ac138331b42f2cfd741f4137329751555c Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 14 May 2009 19:36:56 +0000 Subject: 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. --- status.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'status.c') diff --git a/status.c b/status.c index 1f60256b..6d8a7838 100644 --- a/status.c +++ b/status.c @@ -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 @@ -673,9 +673,9 @@ status_prompt_redraw(struct client *c) void status_prompt_key(struct client *c, int key) { - char *s, *first, *last; - size_t size, n, off, idx; - char word[64]; + struct paste_buffer *pb; + char *s, *first, *last, word[64]; + size_t size, n, off, idx; size = strlen(c->prompt_buffer); 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->flags |= CLIENT_STATUS; 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: if (*c->prompt_buffer != '\0') { status_prompt_add_history(c); -- cgit v1.2.3