vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 6169eb12ebac5750a54e3a54692ad6007c708b65 parent 45db529b45f81b5b357c27f1a247822e8dce3328 Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 4 May 2016 17:37:48 +0200 vis-lua: add new theme_change event hook Diffstat:
| M | README.md | | | 1 | + |
| M | vis-lua.c | | | 26 | +++++++++----------------- |
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md @@ -586,6 +586,7 @@ At this time there exists no API stability guarantees. - `quit()` - `win_open(win)` - `win_close(win)` + - `theme_change(name)` - `files()` iterator - `win` currently focused window - `windows()` iterator diff --git a/vis-lua.c b/vis-lua.c @@ -1224,25 +1224,17 @@ void vis_lua_win_close(Vis *vis, Win *win) { bool vis_theme_load(Vis *vis, const char *name) { lua_State *L = vis->lua; - if (!L) - return false; + vis_lua_event_get(L, "theme_change"); + if (lua_isfunction(L, -1)) { + if (name) + lua_pushstring(L, name); + else + lua_pushnil(L); + pcall(vis, L, 1, 0); + } + lua_pop(L, 1); /* package.loaded['themes/'..name] = nil * require 'themes/'..name */ - lua_pushstring(L, "themes/"); - lua_pushstring(L, name); - lua_concat(L, 2); - lua_getglobal(L, "package"); - lua_getfield(L, -1, "loaded"); - lua_pushvalue(L, -3); - lua_pushnil(L); - lua_settable(L, -3); - lua_pop(L, 2); - lua_getglobal(L, "require"); - lua_pushvalue(L, -2); - if (pcall(vis, L, 1, 0)) - return false; - for (Win *win = vis->windows; win; win = win->next) - view_syntax_set(win->view, view_syntax_get(win->view)); return true; }