summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-11-15 23:34:13 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-11-15 23:34:13 +0000
commitf73241c0c6b1eb631e14abd783b50c4016e0d90e (patch)
tree54a54f58295640cb0b88fc436cdccaf7fddfe603 /usr.bin
parente441c8a0a0bed9932e90a500ff03476334cb3d60 (diff)
Add word movement and editing command for command prompt editing, from
Ben Boeckel.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/mode-key.c25
-rw-r--r--usr.bin/tmux/status.c103
-rw-r--r--usr.bin/tmux/tmux.h6
3 files changed, 122 insertions, 12 deletions
diff --git a/usr.bin/tmux/mode-key.c b/usr.bin/tmux/mode-key.c
index 77d0a9b3922..ded1e4c78fb 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.39 2011/08/16 09:47:18 nicm Exp $ */
+/* $OpenBSD: mode-key.c,v 1.40 2011/11/15 23:34:12 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -49,11 +49,15 @@ const struct mode_key_cmdstr mode_key_cmdstr_edit[] = {
{ MODEKEYEDIT_DELETE, "delete" },
{ MODEKEYEDIT_DELETELINE, "delete-line" },
{ MODEKEYEDIT_DELETETOENDOFLINE, "delete-end-of-line" },
+ { MODEKEYEDIT_DELETEWORD, "delete-word" },
{ MODEKEYEDIT_ENDOFLINE, "end-of-line" },
{ MODEKEYEDIT_ENTER, "enter" },
{ MODEKEYEDIT_HISTORYDOWN, "history-down" },
{ MODEKEYEDIT_HISTORYUP, "history-up" },
+ { MODEKEYEDIT_NEXTWORD, "next-word" },
+ { MODEKEYEDIT_NEXTWORDEND, "next-word-end" },
{ MODEKEYEDIT_PASTE, "paste" },
+ { MODEKEYEDIT_PREVIOUSWORD, "previous-word" },
{ MODEKEYEDIT_STARTOFLINE, "start-of-line" },
{ MODEKEYEDIT_SWITCHMODE, "switch-mode" },
{ MODEKEYEDIT_SWITCHMODEAPPEND, "switch-mode-append" },
@@ -127,7 +131,8 @@ const struct mode_key_entry mode_key_vi_edit[] = {
{ '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL },
{ '\010' /* C-h */, 0, MODEKEYEDIT_BACKSPACE },
{ '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
- { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
+ { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
+ { '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD },
{ '\033' /* Escape */, 0, MODEKEYEDIT_SWITCHMODE },
{ '\r', 0, MODEKEYEDIT_ENTER },
{ KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE },
@@ -145,13 +150,16 @@ const struct mode_key_entry mode_key_vi_edit[] = {
{ '\r', 1, MODEKEYEDIT_ENTER },
{ '^', 1, MODEKEYEDIT_STARTOFLINE },
{ 'a', 1, MODEKEYEDIT_SWITCHMODEAPPEND },
+ { 'b', 1, MODEKEYEDIT_PREVIOUSWORD },
{ 'd', 1, MODEKEYEDIT_DELETELINE },
+ { 'e', 1, MODEKEYEDIT_NEXTWORDEND },
{ 'h', 1, MODEKEYEDIT_CURSORLEFT },
{ 'i', 1, MODEKEYEDIT_SWITCHMODE },
{ 'j', 1, MODEKEYEDIT_HISTORYDOWN },
{ 'k', 1, MODEKEYEDIT_HISTORYUP },
{ 'l', 1, MODEKEYEDIT_CURSORRIGHT },
{ 'p', 1, MODEKEYEDIT_PASTE },
+ { 'w', 1, MODEKEYEDIT_NEXTWORD },
{ KEYC_BSPACE, 1, MODEKEYEDIT_BACKSPACE },
{ KEYC_DC, 1, MODEKEYEDIT_DELETE },
{ KEYC_DOWN, 1, MODEKEYEDIT_HISTORYDOWN },
@@ -259,18 +267,21 @@ const struct mode_key_entry mode_key_emacs_edit[] = {
{ '\002' /* C-b */, 0, MODEKEYEDIT_CURSORLEFT },
{ '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL },
{ '\004' /* C-d */, 0, MODEKEYEDIT_DELETE },
- { '\005' /* C-e */, 0, MODEKEYEDIT_ENDOFLINE },
+ { '\005' /* C-e */, 0, MODEKEYEDIT_ENDOFLINE },
{ '\006' /* C-f */, 0, MODEKEYEDIT_CURSORRIGHT },
- { '\010' /* C-H */, 0, MODEKEYEDIT_BACKSPACE },
- { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
- { '\013' /* C-k */, 0, MODEKEYEDIT_DELETETOENDOFLINE },
+ { '\010' /* C-H */, 0, MODEKEYEDIT_BACKSPACE },
+ { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
+ { '\013' /* C-k */, 0, MODEKEYEDIT_DELETETOENDOFLINE },
{ '\016' /* C-n */, 0, MODEKEYEDIT_HISTORYDOWN },
{ '\020' /* C-p */, 0, MODEKEYEDIT_HISTORYUP },
{ '\024' /* C-t */, 0, MODEKEYEDIT_TRANSPOSECHARS },
- { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
+ { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
+ { '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD },
{ '\031' /* C-y */, 0, MODEKEYEDIT_PASTE },
{ '\033' /* Escape */, 0, MODEKEYEDIT_CANCEL },
{ '\r', 0, MODEKEYEDIT_ENTER },
+ { 'b' | KEYC_ESCAPE, 0, MODEKEYEDIT_PREVIOUSWORD },
+ { 'f' | KEYC_ESCAPE, 0, MODEKEYEDIT_NEXTWORDEND },
{ 'm' | KEYC_ESCAPE, 0, MODEKEYEDIT_STARTOFLINE },
{ KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE },
{ KEYC_DC, 0, MODEKEYEDIT_DELETE },
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index b02cf061075..6d28a34b4e4 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.80 2011/11/15 23:19:51 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.81 2011/11/15 23:34:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -973,9 +973,12 @@ status_prompt_redraw(struct client *c)
void
status_prompt_key(struct client *c, int key)
{
+ struct session *sess = c->session;
+ struct options *oo = &sess->options;
struct paste_buffer *pb;
- char *s, *first, *last, word[64], swapc;
- const char *histstr;
+ char *s, *first, *last, word[64], swapc;
+ const char *histstr;
+ const char *wsep;
u_char ch;
size_t size, n, off, idx;
@@ -1092,11 +1095,103 @@ status_prompt_key(struct client *c, int key)
c->flags |= CLIENT_STATUS;
}
break;
+ case MODEKEYEDIT_DELETEWORD:
+ wsep = options_get_string(oo, "word-separators");
+ idx = c->prompt_index;
+
+ /* Find a non-separator. */
+ while (idx != 0) {
+ idx--;
+ if (!strchr(wsep, c->prompt_buffer[idx]))
+ break;
+ }
+
+ /* Find the separator at the beginning of the word. */
+ while (idx != 0) {
+ idx--;
+ if (strchr(wsep, c->prompt_buffer[idx])) {
+ /* Go back to the word. */
+ idx++;
+ break;
+ }
+ }
+
+ memmove(c->prompt_buffer + idx,
+ c->prompt_buffer + c->prompt_index,
+ size + 1 - c->prompt_index);
+ memset(c->prompt_buffer + size - (c->prompt_index - idx),
+ '\0', c->prompt_index - idx);
+ c->prompt_index = idx;
+ c->flags |= CLIENT_STATUS;
+ break;
+ case MODEKEYEDIT_NEXTWORD:
+ wsep = options_get_string(oo, "word-separators");
+
+ /* Find a separator. */
+ while (c->prompt_index != size) {
+ c->prompt_index++;
+ if (strchr(wsep, c->prompt_buffer[c->prompt_index]))
+ break;
+ }
+
+ /* Find the word right after the separation. */
+ while (c->prompt_index != size) {
+ c->prompt_index++;
+ if (!strchr(wsep, c->prompt_buffer[c->prompt_index]))
+ break;
+ }
+
+ c->flags |= CLIENT_STATUS;
+ break;
+ case MODEKEYEDIT_NEXTWORDEND:
+ wsep = options_get_string(oo, "word-separators");
+
+ /* Find a word. */
+ while (c->prompt_index != size) {
+ c->prompt_index++;
+ if (!strchr(wsep, c->prompt_buffer[c->prompt_index]))
+ break;
+ }
+
+ /* Find the separator at the end of the word. */
+ while (c->prompt_index != size) {
+ c->prompt_index++;
+ if (strchr(wsep, c->prompt_buffer[c->prompt_index])) {
+ /* Go back to the word. */
+ c->prompt_index--;
+ break;
+ }
+ }
+
+ c->flags |= CLIENT_STATUS;
+ break;
+ case MODEKEYEDIT_PREVIOUSWORD:
+ wsep = options_get_string(oo, "word-separators");
+
+ /* Find a non-separator. */
+ while (c->prompt_index != 0) {
+ c->prompt_index--;
+ if (!strchr(wsep, c->prompt_buffer[c->prompt_index]))
+ break;
+ }
+
+ /* Find the separator at the beginning of the word. */
+ while (c->prompt_index != 0) {
+ c->prompt_index--;
+ if (strchr(wsep, c->prompt_buffer[c->prompt_index])) {
+ /* Go back to the word. */
+ c->prompt_index++;
+ break;
+ }
+ }
+
+ c->flags |= CLIENT_STATUS;
+ break;
case MODEKEYEDIT_HISTORYUP:
histstr = status_prompt_up_history(&c->prompt_hindex);
if (histstr == NULL)
break;
- xfree(c->prompt_buffer);
+ xfree(c->prompt_buffer);
c->prompt_buffer = xstrdup(histstr);
c->prompt_index = strlen(c->prompt_buffer);
c->flags |= CLIENT_STATUS;
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 488e8149fa9..0da30cc69e3 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.298 2011/11/15 23:19:51 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.299 2011/11/15 23:34:12 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -442,11 +442,15 @@ enum mode_key_cmd {
MODEKEYEDIT_DELETE,
MODEKEYEDIT_DELETELINE,
MODEKEYEDIT_DELETETOENDOFLINE,
+ MODEKEYEDIT_DELETEWORD,
MODEKEYEDIT_ENDOFLINE,
MODEKEYEDIT_ENTER,
MODEKEYEDIT_HISTORYDOWN,
MODEKEYEDIT_HISTORYUP,
+ MODEKEYEDIT_NEXTWORD,
+ MODEKEYEDIT_NEXTWORDEND,
MODEKEYEDIT_PASTE,
+ MODEKEYEDIT_PREVIOUSWORD,
MODEKEYEDIT_STARTOFLINE,
MODEKEYEDIT_SWITCHMODE,
MODEKEYEDIT_SWITCHMODEAPPEND,