From ed0bbf0dc29e0107da604c83eebde4e17521c588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 13 May 2016 23:46:16 +0200 Subject: vis-lua: add win:map function for window local key mappings Based on a patch by Josh Wainwright. Close #306 --- vis-lua.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'vis-lua.c') 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 }, }; -- cgit v1.2.3