From 69345edd77b3ff98a99b36de8063f9e5febad3eb Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 7 Jul 2012 00:53:09 +0200 Subject: Add support for copy/paste registers This adds support for vim-style copy/paste registers which allows cutting and copying multiple items without having to overwrite the copy/paste buffer. Registers can be specified using the quote key ('"'). To access a register, type '"x' before a command where "x" is the name of a register. If you want to copy the currently selected item into register 1, type '"1c'. Valid registers are 0-9, a-z, "-" and "_". Note that the latter is the so-called black hole register, which works similar to the black hole register in vim. The register prefix key is currently hardcoded and cannot be configured. Signed-off-by: Lukas Fleischer --- src/keys.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/keys.c') diff --git a/src/keys.c b/src/keys.c index 579ddc8..38b6780 100644 --- a/src/keys.c +++ b/src/keys.c @@ -180,12 +180,13 @@ enum key keys_get_action(int pressed) return actions[pressed]; } -enum key keys_getch(WINDOW * win, int *count) +enum key keys_getch(WINDOW * win, int *count, int *reg) { int ch = '0'; - if (count) { + if (count && reg) { *count = 0; + *reg = 0; do { *count = *count * 10 + ch - '0'; ch = wgetch(win); @@ -194,8 +195,23 @@ enum key keys_getch(WINDOW * win, int *count) if (*count == 0) *count = 1; - } else + + if (ch == '"') { + ch = wgetch(win); + if (ch >= '1' && ch <= '9') { + *reg = ch - '1' + 1; + } + else if (ch >= 'a' && ch <= 'z') { + *reg = ch - 'a' + 10; + } + else if (ch == '_') { + *reg = REG_BLACK_HOLE; + } + ch = wgetch(win); + } + } else { ch = wgetch(win); + } switch (ch) { case KEY_RESIZE: @@ -524,7 +540,7 @@ void keys_popup_info(enum key key) #define WINCOL (col - 4) infowin = popup(WINROW, WINCOL, (row - WINROW) / 2, (col - WINCOL) / 2, keydef[key].label, info[key], 1); - keys_getch(infowin, NULL); + keys_getch(infowin, NULL, NULL); delwin(infowin); #undef WINROW #undef WINCOL -- cgit v1.2.3-54-g00ecf