aboutsummaryrefslogtreecommitdiff
path: root/vis-lua.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-05-21 00:19:35 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-22 00:05:30 +0200
commitffcdfc2012a9cbc9a104a75e8e87bcf5fa5de2e1 (patch)
tree0089d3f4e51f3523bcacda33e1fefbcdad996953 /vis-lua.c
parent1d2005c82f19f2094ffb57394832754160b9bbc6 (diff)
downloadvis-ffcdfc2012a9cbc9a104a75e8e87bcf5fa5de2e1.tar.gz
vis-ffcdfc2012a9cbc9a104a75e8e87bcf5fa5de2e1.tar.xz
vis: move syntax highlighting to pure Lua code
Diffstat (limited to 'vis-lua.c')
-rw-r--r--vis-lua.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 1988075..c239f63 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -28,6 +28,8 @@ void vis_lua_file_save(Vis *vis, File *file) { }
void vis_lua_file_close(Vis *vis, File *file) { }
void vis_lua_win_open(Vis *vis, Win *win) { }
void vis_lua_win_close(Vis *vis, Win *win) { }
+void vis_lua_win_highlight(Vis *vis, Win *win) { }
+bool vis_lua_win_syntax(Vis *vis, Win *win, const char *syntax) { return true; }
bool vis_theme_load(Vis *vis, const char *name) { return true; }
#else
@@ -618,7 +620,7 @@ static int window_index(lua_State *L) {
}
if (strcmp(key, "syntax") == 0) {
- const char *syntax = view_syntax_get(win->view);
+ const char *syntax = vis_window_syntax_get(win);
if (syntax)
lua_pushstring(L, syntax);
else
@@ -640,7 +642,7 @@ static int window_newindex(lua_State *L) {
const char *syntax = NULL;
if (!lua_isnil(L, 3))
syntax = luaL_checkstring(L, 3);
- view_syntax_set(win->view, syntax);
+ vis_window_syntax_set(win, syntax);
return 0;
}
}
@@ -1274,6 +1276,34 @@ void vis_lua_win_close(Vis *vis, Win *win) {
lua_pop(L, 1);
}
+void vis_lua_win_highlight(Vis *vis, Win *win) {
+ lua_State *L = vis->lua;
+ vis_lua_event_get(L, "win_highlight");
+ if (lua_isfunction(L, -1)) {
+ obj_ref_new(L, win, "vis.window");
+ pcall(vis, L, 1, 0);
+ }
+ lua_pop(L, 1);
+}
+
+bool vis_lua_win_syntax(Vis *vis, Win *win, const char *syntax) {
+ lua_State *L = vis->lua;
+ bool ret = false;
+ vis_lua_event_get(L, "win_syntax");
+ if (lua_isfunction(L, -1)) {
+ obj_ref_new(L, win, "vis.window");
+ if (syntax)
+ lua_pushstring(L, syntax);
+ else
+ lua_pushnil(L);
+ pcall(vis, L, 2, 1);
+ ret = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+ return ret;
+}
+
bool vis_theme_load(Vis *vis, const char *name) {
lua_State *L = vis->lua;
vis_lua_event_get(L, "theme_change");