aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--vis-lua.c44
2 files changed, 46 insertions, 0 deletions
diff --git a/README.md b/README.md
index 496e2f3..19fe88b 100644
--- a/README.md
+++ b/README.md
@@ -617,6 +617,8 @@ At this time there exists no API stability guarantees.
- `cursor` primary cursor
- `syntax` lexer name used for syntax highlighting or `nil`
- `map(mode, key, function)` map a Lua function to `key` in `mode`, local to the given window
+ - `style_define(id, style)` where `id` is a constant and `style` a string
+ - `style(id, start, end)` apply style to file range, will be cleared after every redraw
- `cursor`
- `line` (1 based), `col` (1 based)
- `to(line, col)`
diff --git a/vis-lua.c b/vis-lua.c
index 1f15eb7..749abaa 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -672,11 +672,36 @@ static int window_map(lua_State *L) {
return keymap(L, win->vis, win);
}
+static int window_style_define(lua_State *L) {
+ Win *win = obj_ref_check(L, 1, "vis.window");
+ bool ret = false;
+ if (win) {
+ enum UiStyle id = luaL_checkunsigned(L, 2);
+ const char *style = luaL_checkstring(L, 3);
+ ret = view_style_define(win->view, id, style);
+ }
+ lua_pushboolean(L, ret);
+ return 1;
+}
+
+static int window_style(lua_State *L) {
+ Win *win = obj_ref_check(L, 1, "vis.window");
+ if (win) {
+ enum UiStyle style = luaL_checkunsigned(L, 2);
+ size_t start = checkpos(L, 3);
+ size_t end = checkpos(L, 4);
+ view_style(win->view, style, start, end);
+ }
+ return 0;
+}
+
static const struct luaL_Reg window_funcs[] = {
{ "__index", window_index },
{ "__newindex", window_newindex },
{ "cursors_iterator", window_cursors_iterator },
{ "map", window_map },
+ { "style_define", window_style_define },
+ { "style", window_style },
{ NULL, NULL },
};
@@ -1138,6 +1163,25 @@ void vis_lua_init(Vis *vis) {
luaL_setfuncs(L, file_lines_funcs, 0);
luaL_newmetatable(L, "vis.window");
luaL_setfuncs(L, window_funcs, 0);
+
+ static const struct {
+ enum UiStyle id;
+ const char *name;
+ } styles[] = {
+ { UI_STYLE_DEFAULT, "STYLE_DEFAULT" },
+ { UI_STYLE_CURSOR, "STYLE_CURSOR" },
+ { UI_STYLE_CURSOR_PRIMARY, "STYLE_CURSOR_PRIMARY" },
+ { UI_STYLE_CURSOR_LINE, "STYLE_CURSOR_LINE" },
+ { UI_STYLE_SELECTION, "STYLE_SELECTION" },
+ { UI_STYLE_LINENUMBER, "STYLE_LINENUMBER" },
+ { UI_STYLE_COLOR_COLUMN, "STYLE_COLOR_COLUMN" },
+ };
+
+ for (size_t i = 0; i < LENGTH(styles); i++) {
+ lua_pushunsigned(L, styles[i].id);
+ lua_setfield(L, -2, styles[i].name);
+ }
+
luaL_newmetatable(L, "vis.window.cursor");
luaL_setfuncs(L, window_cursor_funcs, 0);
luaL_newmetatable(L, "vis.window.cursors");