From b04b66e0ab5646342241b2535768337d9d12a93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 4 May 2016 17:37:48 +0200 Subject: vis-lua: add new theme_change event hook --- README.md | 1 + vis-lua.c | 26 +++++++++----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c63c46a..be11bde 100644 --- 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 index 992be07..9a2642f 100644 --- 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; } -- cgit v1.2.3