vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 5ef854b5c76c6d74647391210b2c19f6815f788e
parent 3ef65ec57a6b3c3fc24b715fb86f82e9ec51a562
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun,  1 May 2016 11:56:47 +0200

vis-lua: expose vis:feedkeys API

Diffstat:
MREADME.md | 1+
Mvis-lua.c | 10++++++++++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -598,6 +598,7 @@ At this time there exists no API stability guarantees. - `motion(id)` select/execute a motion - `command_register(name, function(argv, force, win, cursor, range))` hook up a Lua function to `:name` command - `map(mode, key, function)` map a Lua function to `key` in `mode` + - `feedkeys(keys)` interpret `keys` as if they were read from the keyboard. If called from a key handling function, the keys will only be processed *after* the current key handling function has returned. - `file` - `content(pos, len)` or `content({start, finish})` - `insert(pos, data)` diff --git a/vis-lua.c b/vis-lua.c @@ -510,6 +510,15 @@ static int command_register(lua_State *L) { return 1; } +static int feedkeys(lua_State *L) { + Vis *vis = obj_ref_check(L, 1, "vis"); + const char *keys = luaL_checkstring(L, 2); + if (vis) + vis_keys_feed(vis, keys); + lua_pushboolean(L, vis != NULL); + return 1; +} + static int vis_index(lua_State *L) { Vis *vis = obj_ref_check(L, 1, "vis"); if (!vis) { @@ -583,6 +592,7 @@ static const struct luaL_Reg vis_lua[] = { { "textobject", textobject }, { "textobject_register", textobject_register }, { "command_register", command_register }, + { "feedkeys", feedkeys }, { "__index", vis_index }, { "__newindex", vis_newindex }, { NULL, NULL },