aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 18259ef..a28efc7 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -376,12 +376,7 @@ static int open(lua_State *L) {
return 1;
}
-static int map(lua_State *L) {
- Vis *vis = obj_ref_check(L, 1, "vis");
- if (!vis) {
- lua_pushnil(L);
- return 1;
- }
+static int keymap(lua_State *L, Vis *vis, Win *win) {
KeyBinding *binding = NULL;
KeyAction *action = NULL;
@@ -410,8 +405,13 @@ static int map(lua_State *L) {
binding->action = action;
- if (!vis_mode_map(vis, mode, true, key, binding))
- goto err;
+ if (win) {
+ if (!vis_window_mode_map(win, mode, true, key, binding))
+ goto err;
+ } else {
+ if (!vis_mode_map(vis, mode, true, key, binding))
+ goto err;
+ }
lua_pushboolean(L, true);
return 1;
@@ -422,6 +422,15 @@ err:
return 1;
}
+static int map(lua_State *L) {
+ Vis *vis = obj_ref_check(L, 1, "vis");
+ if (!vis) {
+ lua_pushboolean(L, false);
+ return 1;
+ }
+ return keymap(L, vis, NULL);
+}
+
static int motion(lua_State *L) {
Vis *vis = obj_ref_check(L, 1, "vis");
enum VisMotion id = luaL_checkunsigned(L, 2);
@@ -682,10 +691,20 @@ static int window_cursors_iterator(lua_State *L) {
return 1;
}
+static int window_map(lua_State *L) {
+ Win *win = obj_ref_check(L, 1, "vis.window");
+ if (!win) {
+ lua_pushboolean(L, false);
+ return 1;
+ }
+ return keymap(L, win->vis, win);
+}
+
static const struct luaL_Reg window_funcs[] = {
{ "__index", window_index },
{ "__newindex", window_newindex },
{ "cursors_iterator", window_cursors_iterator },
+ { "map", window_map },
{ NULL, NULL },
};