vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit e3615b63dbe3f126f20e793a918b9d2cb30bdc64 parent 73f1fc752ea505af4c15161caf7314fa7f30ff8c Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 21 Apr 2016 22:43:38 +0200 vis-lua: allow selection modification by assigning to cursor.selection Diffstat:
| M | README.md | | | 2 | +- |
| M | vis-lua.c | | | 9 | +++++++++ |
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md @@ -617,7 +617,7 @@ At this time there exists no API stability guarantees. - `to(line, col)` - `pos` bytes from start of file (0 based) - `number` one based index of cursor - - `selection` a `range` + - `selection` read/write access to selection represented as a `range` - `range` denoted by absolute postions in bytes from the start of the file, an invalid range is represented as `nil` - `start` diff --git a/vis-lua.c b/vis-lua.c @@ -752,6 +752,15 @@ static int window_cursor_newindex(lua_State *L) { view_cursors_to(cur, pos); return 0; } + + if (strcmp(key, "selection") == 0) { + Filerange sel = getrange(L, 3); + if (text_range_valid(&sel)) + view_cursors_selection_set(cur, &sel); + else + view_cursors_selection_clear(cur); + return 0; + } } return newindex_common(L); }