aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-02-13 11:18:33 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-02-18 16:22:20 +0100
commitb2e2b449d26a794f10929a2861df4c1b33af7966 (patch)
tree81ecce2e25d000197e1bffa974f67fdbbeedca2a /vis.c
parentefc9b14dcee610a494401abf483126c8d6dd9e0a (diff)
downloadvis-b2e2b449d26a794f10929a2861df4c1b33af7966.tar.gz
vis-b2e2b449d26a794f10929a2861df4c1b33af7966.tar.xz
vis: add insfrastructure to support global key mappings
Except for insert/replace mode keys get translated before any key bindings are evaluated. This is useful for non-english/latin keyboard layouts.
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/vis.c b/vis.c
index 848180f..35516de 100644
--- a/vis.c
+++ b/vis.c
@@ -341,6 +341,8 @@ Vis *vis_new(Ui *ui, VisEvent *event) {
goto err;
if (!(vis->search_file = file_new_internal(vis, NULL)))
goto err;
+ if (!(vis->keymap = map_new()))
+ goto err;
vis->mode_prev = vis->mode = &vis_modes[VIS_MODE_NORMAL];
vis->event = event;
if (event && event->vis_start)
@@ -371,6 +373,7 @@ void vis_free(Vis *vis) {
map_free(vis->cmds);
map_free(vis->options);
map_free(vis->actions);
+ map_free(vis->keymap);
buffer_release(&vis->input_queue);
for (int i = 0; i < VIS_MODE_INVALID; i++)
map_free(vis_modes[i].bindings);
@@ -422,6 +425,10 @@ bool vis_action_register(Vis *vis, const KeyAction *action) {
return map_put(vis->actions, action->name, action);
}
+bool vis_keymap_add(Vis *vis, const char *key, const char *mapping) {
+ return map_put(vis->keymap, key, mapping);
+}
+
static void window_jumplist_add(Win *win, size_t pos) {
Mark mark = text_mark_set(win->file->text, pos);
if (mark && win->jumplist)
@@ -763,6 +770,11 @@ static const char *getkey(Vis *vis) {
if (!key)
return NULL;
vis_info_hide(vis);
+ if (!vis->mode->input) {
+ const char *mapped = map_get(vis->keymap, key);
+ if (mapped)
+ return mapped;
+ }
return key;
}