From ffcdfc2012a9cbc9a104a75e8e87bcf5fa5de2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 21 May 2016 00:19:35 +0200 Subject: vis: move syntax highlighting to pure Lua code --- vis-lua.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'vis-lua.c') 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"); -- cgit v1.2.3