diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-09 18:38:47 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-09 18:38:47 +0100 |
| commit | 8bd63d79f8efb51bace7228392f2afe3c99fb229 (patch) | |
| tree | ef6fb828a9200ff70b0d9196c3ed066e973cdb45 /vis-lua.c | |
| parent | defe27d826a797402720909a7e37ed8e1683a046 (diff) | |
| download | vis-8bd63d79f8efb51bace7228392f2afe3c99fb229.tar.gz vis-8bd63d79f8efb51bace7228392f2afe3c99fb229.tar.xz | |
vis-lua: expose input key event in insert and replace modes
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1740,7 +1740,7 @@ static const struct luaL_Reg file_lines_funcs[] = { * `vis.events` table. Users scripts should generally use the [Events](#events) * mechanism instead which multiplexes these core events. * - * @section Core Events + * @section Core_Events */ static void vis_lua_event_get(lua_State *L, const char *name) { @@ -2018,6 +2018,39 @@ void vis_lua_quit(Vis *vis) { } /*** + * Input key event in either input or replace mode. + * @function input + * @tparam string key + * @treturn bool whether the key was cosumed or not + */ +static bool vis_lua_input(Vis *vis, const char *key, size_t len) { + if (vis->win->file->internal) + return false; + lua_State *L = vis->lua; + bool ret = false; + vis_lua_event_get(L, "input"); + if (lua_isfunction(L, -1)) { + lua_pushlstring(L, key, len); + if (pcall(vis, L, 1, 1) != 0) { + ret = lua_isboolean(L, -1) && lua_toboolean(L, -1); + lua_pop(L, 1); + } + } + lua_pop(L, 1); + return ret; +} + +void vis_lua_mode_insert_input(Vis *vis, const char *key, size_t len) { + if (!vis_lua_input(vis, key, len)) + vis_insert_key(vis, key, len); +} + +void vis_lua_mode_replace_input(Vis *vis, const char *key, size_t len) { + if (!vis_lua_input(vis, key, len)) + vis_replace_key(vis, key, len); +} + +/*** * File open. * @function file_open * @tparam File file the file to be opened |
