PatchSet 784

Date: 2010/11/11 20:54:06
Author: nicm
Branch: HEAD
Tag: (none)
Log:
Flag to flush all key bindings from Rob Paisley.

Members:
        cmd-unbind-key.c:1.7->1.8
        tmux.1:1.188->1.189
This commit is contained in:
Nicholas Marriott 2010-12-06 21:51:02 +00:00
parent 3a4b82d27a
commit fe4f760eba
2 changed files with 38 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $Id: cmd-unbind-key.c,v 1.22 2010-01-25 17:12:44 tcunha Exp $ */
/* $Id: cmd-unbind-key.c,v 1.23 2010-12-06 21:51:02 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -33,13 +33,14 @@ int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *);
struct cmd_unbind_key_data {
int key;
int flag_all;
int command_key;
char *tablename;
};
const struct cmd_entry cmd_unbind_key_entry = {
"unbind-key", "unbind",
"[-cn] [-t key-table] key",
"[-acn] [-t key-table] key",
0, "",
NULL,
cmd_unbind_key_parse,
@ -55,11 +56,15 @@ cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
int opt, no_prefix = 0;
self->data = data = xmalloc(sizeof *data);
data->flag_all = 0;
data->command_key = 0;
data->tablename = NULL;
while ((opt = getopt(argc, argv, "cnt:")) != -1) {
while ((opt = getopt(argc, argv, "acnt:")) != -1) {
switch (opt) {
case 'a':
data->flag_all = 1;
break;
case 'c':
data->command_key = 1;
break;
@ -76,15 +81,20 @@ cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
}
argc -= optind;
argv += optind;
if (argc != 1)
if (data->flag_all && (argc != 0 || data->tablename))
goto usage;
if (!data->flag_all && argc != 1)
goto usage;
if ((data->key = key_string_lookup_string(argv[0])) == KEYC_NONE) {
xasprintf(cause, "unknown key: %s", argv[0]);
goto error;
if (!data->flag_all) {
data->key = key_string_lookup_string(argv[0]);
if (data->key == KEYC_NONE) {
xasprintf(cause, "unknown key: %s", argv[0]);
goto error;
}
if (!no_prefix)
data->key |= KEYC_PREFIX;
}
if (!no_prefix)
data->key |= KEYC_PREFIX;
return (0);
@ -100,13 +110,23 @@ int
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{
struct cmd_unbind_key_data *data = self->data;
struct key_binding *bd;
if (data == NULL)
return (0);
if (data->tablename != NULL)
return (cmd_unbind_key_table(self, ctx));
if (data->flag_all) {
while (!SPLAY_EMPTY(&key_bindings)) {
bd = SPLAY_ROOT(&key_bindings);
SPLAY_REMOVE(key_bindings, &key_bindings, bd);
cmd_list_free(bd->cmdlist);
xfree(bd);
}
} else {
if (data->tablename != NULL)
return (cmd_unbind_key_table(self, ctx));
key_bindings_remove(data->key);
key_bindings_remove(data->key);
}
return (0);
}

9
tmux.1
View File

@ -1,4 +1,4 @@
.\" $Id: tmux.1,v 1.270 2010-12-06 21:49:57 nicm Exp $
.\" $Id: tmux.1,v 1.271 2010-12-06 21:51:02 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: November 1 2010 $
.Dd $Mdocdate: November 11 2010 $
.Dt TMUX 1
.Os
.Sh NAME
@ -1479,7 +1479,7 @@ All arguments are sent sequentially from first to last.
Send the prefix key to a window as if it was pressed.
If multiple prefix keys are configured, only the first is sent.
.It Xo Ic unbind-key
.Op Fl cn
.Op Fl acn
.Op Fl t Ar key-table
.Ar key
.Xc
@ -1493,6 +1493,9 @@ the primary key bindings are modified; in this case, if
is specified, the command bound to
.Ar key
without a prefix (if any) is removed.
If
.Fl a
is present, all key bindings are removed.
.Pp
If
.Fl t