Key repeating is now a property of the key binding not of the command. Repeat

is turned on when the key is bound with the -r flag to bind-key. next/previous-
window no longer repeat by default as it turned out to annoy me.
pull/1/head
Nicholas Marriott 2009-03-28 14:08:09 +00:00
parent 587badecdb
commit cb2ac5c269
12 changed files with 89 additions and 83 deletions

View File

@ -1,3 +1,10 @@
28 March 2009
* Key repeating is now a property of the key binding not of the command.
Repeat is turned on when the key is bound with the -r flag to bind-key.
next/previous-window no longer repeat by default as it turned out to annoy
me.
27 March 2009
* Clear using ED when redrawing the screen. I foolishly assumed using spaces
@ -1145,7 +1152,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.261 2009-03-28 10:15:01 nicm Exp $
$Id: CHANGES,v 1.262 2009-03-28 14:08:09 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

3
TODO
View File

@ -90,9 +90,8 @@
- better support for stupid margin terminals. strcmp for cons25 sucks, how can
these be autodetected?
- refer to windows by name etc (duplicates? fnmatch?)
- n/p repeat is annoying, turn off
- repeat should be a key flag and should be configurable (bind -r)
- document repeat behaviour and -r on bind-key
- document status-keys
- document break-pane
- document -8 flag

View File

@ -1,4 +1,4 @@
/* $Id: cmd-bind-key.c,v 1.19 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-bind-key.c,v 1.20 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -33,12 +33,13 @@ size_t cmd_bind_key_print(struct cmd *, char *, size_t);
struct cmd_bind_key_data {
int key;
int can_repeat;
struct cmd_list *cmdlist;
};
const struct cmd_entry cmd_bind_key_entry = {
"bind-key", "bind",
"key command [arguments]",
"[-r] key command [arguments]",
0,
NULL,
cmd_bind_key_parse,
@ -56,11 +57,15 @@ cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
int opt;
self->data = data = xmalloc(sizeof *data);
data->can_repeat = 0;
data->cmdlist = NULL;
while ((opt = getopt(argc, argv, "")) != -1) {
while ((opt = getopt(argc, argv, "r")) != -1) {
switch (opt) {
default:
case 'r':
data->can_repeat = 1;
break;
default:
goto usage;
}
}
@ -97,7 +102,7 @@ cmd_bind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
if (data == NULL)
return (0);
key_bindings_add(data->key, data->cmdlist);
key_bindings_add(data->key, data->can_repeat, data->cmdlist);
data->cmdlist = NULL; /* avoid free */
return (0);

View File

@ -1,4 +1,4 @@
/* $Id: cmd-down-pane.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-down-pane.c,v 1.4 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -29,7 +29,7 @@ int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_down_pane_entry = {
"down-pane", "downp",
CMD_TARGET_WINDOW_USAGE,
CMD_CANREPEAT,
0,
cmd_target_init,
cmd_target_parse,
cmd_down_pane_exec,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-next-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-next-window.c,v 1.16 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,7 +30,7 @@ int cmd_next_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_next_window_entry = {
"next-window", "next",
CMD_TARGET_SESSION_USAGE,
CMD_CANREPEAT|CMD_AFLAG,
CMD_AFLAG,
cmd_next_window_init,
cmd_target_parse,
cmd_next_window_exec,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-previous-window.c,v 1.15 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-previous-window.c,v 1.16 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,7 +30,7 @@ int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_previous_window_entry = {
"previous-window", "prev",
CMD_TARGET_SESSION_USAGE,
CMD_CANREPEAT|CMD_AFLAG,
CMD_AFLAG,
cmd_previous_window_init,
cmd_target_parse,
cmd_previous_window_exec,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-resize-pane-down.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-resize-pane-down.c,v 1.7 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,7 +32,7 @@ int cmd_resize_pane_down_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_down_entry = {
"resize-pane-down", "resizep-down",
CMD_PANE_WINDOW_USAGE " [adjustment]",
CMD_ARG01|CMD_CANREPEAT,
CMD_ARG01,
cmd_resize_pane_down_init,
cmd_pane_parse,
cmd_resize_pane_down_exec,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-resize-pane-up.c,v 1.6 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-resize-pane-up.c,v 1.7 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -32,7 +32,7 @@ int cmd_resize_pane_up_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_up_entry = {
"resize-pane-up", "resizep-up",
CMD_PANE_WINDOW_USAGE " [adjustment]",
CMD_ARG01|CMD_CANREPEAT,
CMD_ARG01,
cmd_resize_pane_up_init,
cmd_pane_parse,
cmd_resize_pane_up_exec,

View File

@ -1,4 +1,4 @@
/* $Id: cmd-up-pane.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
/* $Id: cmd-up-pane.c,v 1.4 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -29,7 +29,7 @@ int cmd_up_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_up_pane_entry = {
"up-pane", "upp",
CMD_TARGET_WINDOW_USAGE,
CMD_CANREPEAT,
0,
cmd_target_init,
cmd_target_parse,
cmd_up_pane_exec,

View File

@ -1,4 +1,4 @@
/* $Id: key-bindings.c,v 1.62 2009-03-07 09:29:54 nicm Exp $ */
/* $Id: key-bindings.c,v 1.63 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -44,7 +44,7 @@ key_bindings_lookup(int key)
}
void
key_bindings_add(int key, struct cmd_list *cmdlist)
key_bindings_add(int key, int can_repeat, struct cmd_list *cmdlist)
{
struct key_binding *bd;
@ -54,6 +54,7 @@ key_bindings_add(int key, struct cmd_list *cmdlist)
SPLAY_INSERT(key_bindings, &key_bindings, bd);
} else
cmd_list_free(bd->cmdlist);
bd->can_repeat = can_repeat;
bd->cmdlist = cmdlist;
}
@ -75,54 +76,55 @@ key_bindings_init(void)
{
struct {
int key;
int can_repeat;
const struct cmd_entry *entry;
} table[] = {
{ '!', &cmd_break_pane_entry },
{ '"', &cmd_split_window_entry },
{ '#', &cmd_list_buffers_entry },
{ '&', &cmd_kill_window_entry },
{ ',', &cmd_command_prompt_entry },
{ '-', &cmd_delete_buffer_entry },
{ '.', &cmd_command_prompt_entry },
{ '0', &cmd_select_window_entry },
{ '1', &cmd_select_window_entry },
{ '2', &cmd_select_window_entry },
{ '3', &cmd_select_window_entry },
{ '4', &cmd_select_window_entry },
{ '5', &cmd_select_window_entry },
{ '6', &cmd_select_window_entry },
{ '7', &cmd_select_window_entry },
{ '8', &cmd_select_window_entry },
{ '9', &cmd_select_window_entry },
{ ':', &cmd_command_prompt_entry },
{ '=', &cmd_scroll_mode_entry },
{ '?', &cmd_list_keys_entry },
{ '[', &cmd_copy_mode_entry },
{ '\'', &cmd_select_prompt_entry },
{ ']', &cmd_paste_buffer_entry },
{ 'c', &cmd_new_window_entry },
{ 'd', &cmd_detach_client_entry },
{ 'f', &cmd_command_prompt_entry },
{ 'l', &cmd_last_window_entry },
{ 'n', &cmd_next_window_entry },
{ 'o', &cmd_down_pane_entry },
{ 'p', &cmd_previous_window_entry },
{ 'r', &cmd_refresh_client_entry },
{ 's', &cmd_choose_session_entry },
{ 't', &cmd_clock_mode_entry },
{ 'w', &cmd_choose_window_entry },
{ 'x', &cmd_kill_pane_entry, },
{ '\032', &cmd_suspend_client_entry },
{ KEYC_PPAGE, &cmd_scroll_mode_entry },
{ KEYC_ADDESC('n'), &cmd_next_window_entry },
{ KEYC_ADDESC('p'), &cmd_previous_window_entry },
{ KEYC_UP, &cmd_up_pane_entry },
{ KEYC_DOWN, &cmd_down_pane_entry },
{ KEYC_ADDESC(KEYC_UP), &cmd_resize_pane_up_entry },
{ KEYC_ADDESC(KEYC_DOWN), &cmd_resize_pane_down_entry },
{ KEYC_ADDCTL(KEYC_UP), &cmd_resize_pane_up_entry },
{ KEYC_ADDCTL(KEYC_DOWN), &cmd_resize_pane_down_entry },
{ META, &cmd_send_prefix_entry },
{ '!', 0, &cmd_break_pane_entry },
{ '"', 0, &cmd_split_window_entry },
{ '#', 0, &cmd_list_buffers_entry },
{ '&', 0, &cmd_kill_window_entry },
{ ',', 0, &cmd_command_prompt_entry },
{ '-', 0, &cmd_delete_buffer_entry },
{ '.', 0, &cmd_command_prompt_entry },
{ '0', 0, &cmd_select_window_entry },
{ '1', 0, &cmd_select_window_entry },
{ '2', 0, &cmd_select_window_entry },
{ '3', 0, &cmd_select_window_entry },
{ '4', 0, &cmd_select_window_entry },
{ '5', 0, &cmd_select_window_entry },
{ '6', 0, &cmd_select_window_entry },
{ '7', 0, &cmd_select_window_entry },
{ '8', 0, &cmd_select_window_entry },
{ '9', 0, &cmd_select_window_entry },
{ ':', 0, &cmd_command_prompt_entry },
{ '=', 0, &cmd_scroll_mode_entry },
{ '?', 0, &cmd_list_keys_entry },
{ '[', 0, &cmd_copy_mode_entry },
{ '\'', 0, &cmd_select_prompt_entry },
{ ']', 0, &cmd_paste_buffer_entry },
{ 'c', 0, &cmd_new_window_entry },
{ 'd', 0, &cmd_detach_client_entry },
{ 'f', 0, &cmd_command_prompt_entry },
{ 'l', 0, &cmd_last_window_entry },
{ 'n', 0, &cmd_next_window_entry },
{ 'o', 0, &cmd_down_pane_entry },
{ 'p', 0, &cmd_previous_window_entry },
{ 'r', 0, &cmd_refresh_client_entry },
{ 's', 0, &cmd_choose_session_entry },
{ 't', 0, &cmd_clock_mode_entry },
{ 'w', 0, &cmd_choose_window_entry },
{ 'x', 0, &cmd_kill_pane_entry, },
{ '\032', 0, &cmd_suspend_client_entry },
{ META, 0, &cmd_send_prefix_entry },
{ KEYC_PPAGE, 0, &cmd_scroll_mode_entry },
{ KEYC_ADDESC('n'), 0, &cmd_next_window_entry },
{ KEYC_ADDESC('p'), 0, &cmd_previous_window_entry },
{ KEYC_UP, 1, &cmd_up_pane_entry },
{ KEYC_DOWN, 1, &cmd_down_pane_entry },
{ KEYC_ADDESC(KEYC_UP), 1, &cmd_resize_pane_up_entry },
{ KEYC_ADDESC(KEYC_DOWN), 1, &cmd_resize_pane_down_entry },
{ KEYC_ADDCTL(KEYC_UP), 1, &cmd_resize_pane_up_entry },
{ KEYC_ADDCTL(KEYC_DOWN), 1, &cmd_resize_pane_down_entry },
};
u_int i;
struct cmd *cmd;
@ -141,7 +143,7 @@ key_bindings_init(void)
cmd->entry->init(cmd, table[i].key);
TAILQ_INSERT_HEAD(cmdlist, cmd, qentry);
key_bindings_add(table[i].key, cmdlist);
key_bindings_add(table[i].key, table[i].can_repeat, cmdlist);
}
}

View File

@ -1,4 +1,4 @@
/* $Id: server.c,v 1.129 2009-03-27 17:04:04 nicm Exp $ */
/* $Id: server.c,v 1.130 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -690,7 +690,7 @@ server_handle_client(struct client *c)
struct timeval tv;
struct key_binding *bd;
struct cmd *cmd;
int key, prefix, status, xtimeout, can_repeat;
int key, prefix, status, xtimeout;
int mode;
u_char mouse[3];
@ -748,15 +748,8 @@ server_handle_client(struct client *c)
continue;
}
/* Check repeat flag. */
can_repeat = 1;
TAILQ_FOREACH(cmd, bd->cmdlist, qentry) {
if (!(cmd->entry->flags & CMD_CANREPEAT))
can_repeat = 0;
}
/* If already repeating, but this key can't repeat, skip it. */
if (c->flags & CLIENT_REPEAT && !can_repeat) {
if (c->flags & CLIENT_REPEAT && !bd->can_repeat) {
c->flags &= ~CLIENT_REPEAT;
if (key == prefix)
c->flags |= CLIENT_PREFIX;
@ -766,7 +759,7 @@ server_handle_client(struct client *c)
}
/* If this key can repeat, reset the repeat flags and timer. */
if (xtimeout != 0 && can_repeat) {
if (xtimeout != 0 && bd->can_repeat) {
c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;
tv.tv_sec = xtimeout / 1000;

6
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.285 2009-03-28 10:15:01 nicm Exp $ */
/* $Id: tmux.h,v 1.286 2009-03-28 14:08:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -888,7 +888,6 @@ struct cmd_entry {
#define CMD_CANTNEST 0x2
#define CMD_ARG1 0x4
#define CMD_ARG01 0x8
#define CMD_CANREPEAT 0x10
#define CMD_KFLAG 0x10
#define CMD_DFLAG 0x20
#define CMD_GFLAG 0x40
@ -944,6 +943,7 @@ struct cmd_pane_data {
struct key_binding {
int key;
struct cmd_list *cmdlist;
int can_repeat;
SPLAY_ENTRY(key_binding) entry;
};
@ -1291,7 +1291,7 @@ extern struct key_bindings key_bindings;
int key_bindings_cmp(struct key_binding *, struct key_binding *);
SPLAY_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp);
struct key_binding *key_bindings_lookup(int);
void key_bindings_add(int, struct cmd_list *);
void key_bindings_add(int, int, struct cmd_list *);
void key_bindings_remove(int);
void key_bindings_init(void);
void key_bindings_free(void);