Add a transpose-chars command in edit mode (C-t in emacs mode only). From Kalle

Olavi Niemitalo.
This commit is contained in:
Nicholas Marriott 2009-09-02 06:33:20 +00:00
parent c089e19020
commit 61b7dc522d
4 changed files with 17 additions and 1 deletions

View File

@ -57,6 +57,7 @@ struct mode_key_cmdstr mode_key_cmdstr_edit[] = {
{ MODEKEYEDIT_STARTOFLINE, "start-of-line" },
{ MODEKEYEDIT_SWITCHMODE, "switch-mode" },
{ MODEKEYEDIT_SWITCHMODEAPPEND, "switch-mode-append" },
{ MODEKEYEDIT_TRANSPOSECHARS, "transpose-chars" },
{ 0, NULL }
};
@ -200,6 +201,7 @@ const struct mode_key_entry mode_key_emacs_edit[] = {
{ '\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 },
{ '\031' /* C-y */, 0, MODEKEYEDIT_PASTE },
{ '\033' /* Escape */, 0, MODEKEYEDIT_CANCEL },

View File

@ -763,7 +763,7 @@ void
status_prompt_key(struct client *c, int key)
{
struct paste_buffer *pb;
char *s, *first, *last, word[64];
char *s, *first, *last, word[64], swapc;
size_t size, n, off, idx;
size = strlen(c->prompt_buffer);
@ -933,6 +933,18 @@ status_prompt_key(struct client *c, int key)
c->flags |= CLIENT_STATUS;
break;
case MODEKEYEDIT_TRANSPOSECHARS:
idx = c->prompt_index;
if (idx < size)
idx++;
if (idx >= 2) {
swapc = c->prompt_buffer[idx - 2];
c->prompt_buffer[idx - 2] = c->prompt_buffer[idx - 1];
c->prompt_buffer[idx - 1] = swapc;
c->prompt_index = idx;
c->flags |= CLIENT_STATUS;
}
break;
case MODEKEYEDIT_ENTER:
if (*c->prompt_buffer != '\0')
status_prompt_add_history(c);

1
tmux.1
View File

@ -497,6 +497,7 @@ The following keys are supported as appropriate for the mode:
.It Li "Search forward" Ta "/" Ta "C-s"
.It Li "Start of line" Ta "0" Ta "C-a"
.It Li "Start selection" Ta "Space" Ta "C-Space"
.It Li "Transpose chars" Ta "" Ta "C-t"
.El
.Pp
These key bindings are defined in a set of named tables:

1
tmux.h
View File

@ -379,6 +379,7 @@ enum mode_key_cmd {
MODEKEYEDIT_STARTOFLINE,
MODEKEYEDIT_SWITCHMODE,
MODEKEYEDIT_SWITCHMODEAPPEND,
MODEKEYEDIT_TRANSPOSECHARS,
/* Menu (choice) keys. */
MODEKEYCHOICE_CANCEL,