Skip to content

Commit

Permalink
vis-lua: expose vis:textobject(id)
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Feb 18, 2016
1 parent b3862a3 commit 55e2857
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ static int motion_register(lua_State *L) {
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) {
Expand Down Expand Up @@ -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 },
Expand Down
4 changes: 3 additions & 1 deletion vis-text-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 55e2857

Please sign in to comment.