aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-02-17 21:10:34 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-02-18 16:50:40 +0100
commit55e285783ef99befcc01d7ed6f5594f87d6d8f6c (patch)
tree59859e0e3e8cbdc91882b38f6df1503cb993b288
parentb3862a3dca144d44ed27b74ffc04afa306f88a89 (diff)
downloadvis-55e285783ef99befcc01d7ed6f5594f87d6d8f6c.tar.gz
vis-55e285783ef99befcc01d7ed6f5594f87d6d8f6c.tar.xz
vis-lua: expose vis:textobject(id)
-rw-r--r--vis-lua.c8
-rw-r--r--vis-text-objects.c4
-rw-r--r--vis.h2
3 files changed, 12 insertions, 2 deletions
diff --git a/vis-lua.c b/vis-lua.c
index f253a56..3f3c4a3 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -397,6 +397,13 @@ err:
return 1;
}
+static int textobject(lua_State *L) {
+ Vis *vis = obj_ref_check(L, 1, "vis");
+ enum VisTextObject id = luaL_checkunsigned(L, 2);
+ lua_pushboolean(L, vis && vis_textobject(vis, id));
+ return 1;
+}
+
static int vis_index(lua_State *L) {
Vis *vis = obj_ref_check(L, 1, "vis");
if (!vis) {
@@ -461,6 +468,7 @@ static const struct luaL_Reg vis_lua[] = {
{ "map", map },
{ "motion", motion },
{ "motion_register", motion_register },
+ { "textobject", textobject },
{ "__index", vis_index },
{ "__newindex", vis_newindex },
{ NULL, NULL },
diff --git a/vis-text-objects.c b/vis-text-objects.c
index 8ee2416..5869e86 100644
--- a/vis-text-objects.c
+++ b/vis-text-objects.c
@@ -2,11 +2,13 @@
#include "text-objects.h"
#include "util.h"
-void vis_textobject(Vis *vis, enum VisTextObject id) {
+bool vis_textobject(Vis *vis, enum VisTextObject id) {
if (id < LENGTH(vis_textobjects)) {
vis->action.textobj = &vis_textobjects[id];
action_do(vis, &vis->action);
+ return true;
}
+ return false;
}
static Filerange search_forward(Vis *vis, Text *txt, size_t pos) {
diff --git a/vis.h b/vis.h
index 42bd88a..84779d6 100644
--- a/vis.h
+++ b/vis.h
@@ -315,7 +315,7 @@ enum VisTextObject {
VIS_TEXTOBJECT_INVALID,
};
-void vis_textobject(Vis*, enum VisTextObject);
+bool vis_textobject(Vis*, enum VisTextObject);
/* macro REPEAT and INVALID should be considered as implementation details (TODO: hide them?) */
enum VisMacro {