vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit a60eb781ce133af92c4265a41a64e6044c030b81 parent 17e5603e3989cd32863fa3ec2fa2da5cbbb2fa72 Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 19 Sep 2016 14:20:28 +0200 vis-lua: expose file open event to lua The event is only triggerred for new files read from disk (e.g. splitting an existing window will not cause an event to be emitted). Diffstat:
| M | README.md | | | 1 | + |
| M | vis-lua.c | | | 7 | +++++++ |
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md @@ -585,6 +585,7 @@ At this time there exists no API stability guarantees. - `events` hooks - `start()` - `quit()` + - `file_open(file)` - `win_open(win)` - `win_close(win)` - `theme_change(name)` diff --git a/vis-lua.c b/vis-lua.c @@ -1503,6 +1503,13 @@ void vis_lua_quit(Vis *vis) { void vis_lua_file_open(Vis *vis, File *file) { debug("event: file-open: %s %p %p\n", file->name ? file->name : "unnamed", (void*)file, (void*)file->text); + lua_State *L = vis->lua; + vis_lua_event_get(L, "file_open"); + if (lua_isfunction(L, -1)) { + obj_ref_new(L, file, "vis.file"); + pcall(vis, L, 1, 0); + } + lua_pop(L, 1); } void vis_lua_file_save(Vis *vis, File *file) {