From 11ede8254974aba6e1ef318ab90374fb85e6bf5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 12 Jan 2016 15:48:17 +0100 Subject: vis: cleanup key binding definitions This removes the tree based mode structures and instead merges all keybindings in flat modes which uses some more memory but will allow (per mode) run-time configurable key bindings. Make sure to update/remove config.h. --- vis-cmds.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'vis-cmds.c') diff --git a/vis-cmds.c b/vis-cmds.c index f7af52d..7b1e0e7 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -864,9 +864,9 @@ bool print_keybinding(const char *key, void *value, void *data) { return text_appendf(txt, " %-15s\t%s\n", key, desc ? desc : ""); } -static void print_mode(Mode *mode, Text *txt, bool recursive) { - if (recursive && mode->parent) - print_mode(mode->parent, txt, recursive); +static void print_mode(Mode *mode, Text *txt) { + if (!map_empty(mode->bindings)) + text_appendf(txt, "\n %s\n\n", mode->name); map_iterate(mode->bindings, print_keybinding, txt); } @@ -885,20 +885,10 @@ static bool cmd_help(Vis *vis, Filerange *range, enum CmdOpt opt, const char *ar text_appendf(txt, " %-15s\t%s\n", mode->name, mode->help); } - for (int i = 0; i < LENGTH(vis_modes); i++) { - Mode *mode = &vis_modes[i]; - if (mode->isuser && !map_empty(mode->bindings)) { - text_appendf(txt, "\n %s\n\n", mode->name); - print_mode(mode, txt, i == VIS_MODE_NORMAL || - i == VIS_MODE_INSERT); - } - } - - text_appendf(txt, "\n Text objects\n\n"); - print_mode(&vis_modes[VIS_MODE_TEXTOBJ], txt, false); - - text_appendf(txt, "\n Motions\n\n"); - print_mode(&vis_modes[VIS_MODE_MOVE], txt, false); + print_mode(&vis_modes[VIS_MODE_NORMAL], txt); + print_mode(&vis_modes[VIS_MODE_OPERATOR_PENDING], txt); + print_mode(&vis_modes[VIS_MODE_VISUAL], txt); + print_mode(&vis_modes[VIS_MODE_INSERT], txt); text_appendf(txt, "\n :-Commands\n\n"); for (Command *cmd = cmds; cmd && cmd->name[0]; cmd++) -- cgit v1.2.3