diff --git a/vis-lua.c b/vis-lua.c index 96f2fb803..27b491137 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -531,24 +531,6 @@ static void pushrange(lua_State *L, Filerange *r) { lua_settable(L, -3); } -static void pushlinemap(lua_State *L, Win *win) { - if (!win || !win->view) { - lua_pushnil(L); - return; - } - View *view = win->view; - Line *line = view_lines_first(view); - size_t lines = view_height_get(view); - lua_createtable(L, lines, 0); - for (lua_Integer l = 1; l <= lines; l++) { - if (!line) - break; - lua_pushunsigned(L, line->lineno); - lua_seti(L, -2, l); - line = line->next; - } -} - static Filerange getrange(lua_State *L, int index) { Filerange range = text_range_empty(); if (lua_istable(L, index)) { @@ -1852,8 +1834,16 @@ static const struct luaL_Reg registers_funcs[] = { * @tfield Range viewport */ /*** - * A list mapping lines in the viewport to logical lines in the file. - * @tfield list linemap + * The logical line numbers of the first and last visible lines. + * @tfield Range view_lines + */ +/*** + * Viewport height, accounting for window decorations. + * @tfield int view_height + */ +/*** + * Viewport width, accounting for window decorations. + * @tfield int view_width */ /*** * The window width. @@ -1894,8 +1884,21 @@ static int window_index(lua_State *L) { return 1; } - if (strcmp(key, "linemap") == 0) { - pushlinemap(L, win); + if (strcmp(key, "view_lines") == 0) { + Filerange r; + r.start = view_lines_first(win->view)->lineno; + r.end = view_lines_last(win->view)->lineno; + pushrange(L, &r); + return 1; + } + + if (strcmp(key, "view_width") == 0) { + lua_pushunsigned(L, view_width_get(win->view)); + return 1; + } + + if (strcmp(key, "view_height") == 0) { + lua_pushunsigned(L, view_height_get(win->view)); return 1; }