Next step towards customisable mode keys: build each default table of keys into

a named tree on start and use that for lookups. Also add command to string
translation tables and modify list-keys to show the the mode key bindings (new
-t argument).
This commit is contained in:
Nicholas Marriott
2009-07-28 07:03:32 +00:00
parent 2da4864483
commit 86785004ba
10 changed files with 311 additions and 48 deletions

56
tmux.h
View File

@ -356,7 +356,7 @@ struct msg_unlock_data {
char pass[PASS_MAX];
};
/* Editing keys. */
/* Mode key commands. */
enum mode_key_cmd {
MODEKEY_NONE,
MODEKEY_OTHER,
@ -404,6 +404,7 @@ enum mode_key_cmd {
MODEKEYCOPY_UP,
};
/* Entry in the default mode key tables. */
struct mode_key_entry {
int key;
@ -414,16 +415,42 @@ struct mode_key_entry {
* keys to be bound in edit mode.
*/
int mode;
enum mode_key_cmd cmd;
};
/* Data required while mode keys are in use. */
struct mode_key_data {
const struct mode_key_entry *table;
int mode;
struct mode_key_tree *tree;
int mode;
};
#define MODEKEY_EMACS 0
#define MODEKEY_VI 1
/* Binding between a key and a command. */
struct mode_key_binding {
int key;
int mode;
enum mode_key_cmd cmd;
SPLAY_ENTRY(mode_key_binding) entry;
};
SPLAY_HEAD(mode_key_tree, mode_key_binding);
/* Command to string mapping. */
struct mode_key_cmdstr {
enum mode_key_cmd cmd;
const char *name;
};
/* Named mode key table description. */
struct mode_key_table {
const char *name;
struct mode_key_cmdstr *cmdstr;
struct mode_key_tree *tree;
const struct mode_key_entry *table; /* default entries */
};
/* Modes. */
#define MODE_CURSOR 0x1
#define MODE_INSERT 0x2
@ -1061,14 +1088,19 @@ void sighandler(int);
int load_cfg(const char *, char **x);
/* mode-key.c */
extern const struct mode_key_entry mode_key_vi_edit[];
extern const struct mode_key_entry mode_key_vi_choice[];
extern const struct mode_key_entry mode_key_vi_copy[];
extern const struct mode_key_entry mode_key_emacs_edit[];
extern const struct mode_key_entry mode_key_emacs_choice[];
extern const struct mode_key_entry mode_key_emacs_copy[];
void mode_key_init(
struct mode_key_data *, const struct mode_key_entry *);
extern const struct mode_key_table mode_key_tables[];
extern struct mode_key_tree mode_key_tree_vi_edit;
extern struct mode_key_tree mode_key_tree_vi_choice;
extern struct mode_key_tree mode_key_tree_vi_copy;
extern struct mode_key_tree mode_key_tree_emacs_edit;
extern struct mode_key_tree mode_key_tree_emacs_choice;
extern struct mode_key_tree mode_key_tree_emacs_copy;
int mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *);
SPLAY_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp);
const char *mode_key_tostring(struct mode_key_cmdstr *r, enum mode_key_cmd);
void mode_key_init_trees(void);
void mode_key_free_trees(void);
void mode_key_init(struct mode_key_data *, struct mode_key_tree *);
enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int);
/* options.c */