vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit cb0611c25571e6cab88f054c4add4868075f34b7 parent 9b24de3cb319df3c9951e5ef7a73206ea461e0cd Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 10 Feb 2016 22:23:24 +0100 vis: simplify modes implementation Make replace mode a child of insert mode and visual line a child of visual mode. This means any key binding for the former is automatically available in the latter. Also keys can not be unmapped solely from the child modes. Diffstat:
| M | config.def.h | | | 8 | -------- |
| M | vis-modes.c | | | 2 | ++ |
| M | vis-prompt.c | | | 2 | -- |
| M | vis.c | | | 2 | ++ |
4 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/config.def.h b/config.def.h @@ -330,11 +330,6 @@ static const KeyBinding **default_bindings[] = { }, [VIS_MODE_VISUAL_LINE] = (const KeyBinding*[]){ bindings_visual_line, - bindings_visual, - bindings_textobjects, - bindings_operators, - bindings_motions, - bindings_basic, NULL, }, [VIS_MODE_INSERT] = (const KeyBinding*[]){ @@ -345,9 +340,6 @@ static const KeyBinding **default_bindings[] = { }, [VIS_MODE_REPLACE] = (const KeyBinding*[]){ bindings_replace, - bindings_insert, - bindings_readline, - bindings_basic, NULL, }, }; diff --git a/vis-modes.c b/vis-modes.c @@ -159,6 +159,7 @@ Mode vis_modes[] = { }, [VIS_MODE_VISUAL_LINE] = { .name = "VISUAL LINE", + .parent = &vis_modes[VIS_MODE_VISUAL], .status = "--VISUAL LINE--", .help = "", .enter = vis_mode_visual_line_enter, @@ -177,6 +178,7 @@ Mode vis_modes[] = { }, [VIS_MODE_REPLACE] = { .name = "REPLACE", + .parent = &vis_modes[VIS_MODE_INSERT], .status = "--REPLACE--", .help = "", .enter = vis_mode_replace_enter, diff --git a/vis-prompt.c b/vis-prompt.c @@ -166,9 +166,7 @@ void vis_prompt_show(Vis *vis, const char *title) { prompt->parent_mode = vis->mode; vis_window_mode_map(prompt, VIS_MODE_NORMAL, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, "<Enter>", &prompt_enter_binding); - vis_window_mode_map(prompt, VIS_MODE_REPLACE, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_VISUAL, "<Enter>", &prompt_enter_binding); - vis_window_mode_map(prompt, VIS_MODE_VISUAL_LINE, "<Enter>", &prompt_enter_binding); vis_window_mode_map(prompt, VIS_MODE_NORMAL, "<Escape>", &prompt_esc_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, "<Up>", &prompt_up_binding); vis_window_mode_map(prompt, VIS_MODE_INSERT, "<Backspace>", &prompt_backspace_binding); diff --git a/vis.c b/vis.c @@ -662,6 +662,8 @@ static const char *vis_keys_raw(Vis *vis, Buffer *buf, const char *input) { } for (; mode && !binding && !prefix; mode = mode->parent) { + if (!mode->bindings) + continue; binding = map_get(mode->bindings, start); /* "<" is never treated as a prefix because it is used to denote * special key symbols */