aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-05-04 17:37:48 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-04 17:45:11 +0200
commitb04b66e0ab5646342241b2535768337d9d12a93a (patch)
treecdbc89b8a011d199db056a1b6e1086850c15eb03
parent2f8ef4704c924ad30e67054ebf838a520c829760 (diff)
downloadvis-b04b66e0ab5646342241b2535768337d9d12a93a.tar.gz
vis-b04b66e0ab5646342241b2535768337d9d12a93a.tar.xz
vis-lua: add new theme_change event hook
-rw-r--r--README.md1
-rw-r--r--vis-lua.c26
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;
}