diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-03-19 11:51:00 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-03-19 14:58:06 +0100 |
| commit | 42f04699d6df2d5b144533737a8f2f7e0814ad85 (patch) | |
| tree | 3d69b94c221e3b91749b7f09b7f4da89839206ca /vis-lua.c | |
| parent | 8919fd1cbeef89aa3a5fce9c00aa708335e1de85 (diff) | |
| download | vis-42f04699d6df2d5b144533737a8f2f7e0814ad85.tar.gz vis-42f04699d6df2d5b144533737a8f2f7e0814ad85.tar.xz | |
Move :set syntax option implementation to lua
It is no longer possible to change the used syntax by assigning to the
`win.syntax = name` field, instead the function win:set_syntax(name)`
should be called.
The distinction between filetype and syntax lexer to use should probably
be clarified/cleaned up at some point.
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 56 |
1 files changed, 1 insertions, 55 deletions
@@ -160,7 +160,6 @@ 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, size_t horizon) { } -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; } void vis_lua_win_status(Vis *vis, Win *win) { window_status_update(vis, win); } @@ -1395,12 +1394,6 @@ static const struct luaL_Reg registers_funcs[] = { * The cursors of this window. * @tfield Array(Cursor) cursors */ -/*** - * The file type associated with this window. - * - * Setting this field to a valid lexer name will automatically active it. - * @tfield string syntax the syntax lexer name or `nil` if unset - */ static int window_index(lua_State *L) { Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW); @@ -1438,33 +1431,11 @@ static int window_index(lua_State *L) { obj_ref_new(L, win->view, VIS_LUA_TYPE_CURSORS); return 1; } - - if (strcmp(key, "syntax") == 0) { - const char *syntax = vis_window_syntax_get(win); - lua_pushstring(L, syntax); - return 1; - } } return index_common(L); } -static int window_newindex(lua_State *L) { - Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW); - - if (lua_isstring(L, 2)) { - const char *key = lua_tostring(L, 2); - if (strcmp(key, "syntax") == 0) { - const char *syntax = NULL; - if (!lua_isnil(L, 3)) - syntax = luaL_checkstring(L, 3); - vis_window_syntax_set(win, syntax); - return 0; - } - } - return newindex_common(L); -} - static int window_cursors_iterator_next(lua_State *L) { Cursor **handle = lua_touserdata(L, lua_upvalueindex(1)); if (!*handle) @@ -1578,7 +1549,7 @@ static int window_draw(lua_State *L) { static const struct luaL_Reg window_funcs[] = { { "__index", window_index }, - { "__newindex", window_newindex }, + { "__newindex", newindex_common }, { "cursors_iterator", window_cursors_iterator }, { "map", window_map }, { "style_define", window_style_define }, @@ -2758,31 +2729,6 @@ void vis_lua_win_highlight(Vis *vis, Win *win, size_t horizon) { } /*** - * Window syntax/filetype change. - * @function win_syntax - * @tparam Window win the affected window - * @tparam string syntax the lexer name or `nil` if syntax highlighting should be disabled for this window - * @treturn bool whether the syntax change was successful - */ -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_LUA_TYPE_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; -} - -/*** * Window status bar redraw. * @function win_status * @tparam Window win the affected window |
