diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-05-04 17:37:48 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-05-04 17:45:11 +0200 |
| commit | b04b66e0ab5646342241b2535768337d9d12a93a (patch) | |
| tree | cdbc89b8a011d199db056a1b6e1086850c15eb03 | |
| parent | 2f8ef4704c924ad30e67054ebf838a520c829760 (diff) | |
| download | vis-b04b66e0ab5646342241b2535768337d9d12a93a.tar.gz vis-b04b66e0ab5646342241b2535768337d9d12a93a.tar.xz | |
vis-lua: add new theme_change event hook
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | vis-lua.c | 26 |
2 files changed, 10 insertions, 17 deletions
@@ -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 @@ -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; } |
