aboutsummaryrefslogtreecommitdiff
path: root/vis-text-objects.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-02-17 21:34:00 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-02-18 16:50:40 +0100
commit498723377cbf5cdb36d8b64f41b219a515a84175 (patch)
treedbd82e2cc0fe74f7e63859735a4febd14e09cff2 /vis-text-objects.c
parent55e285783ef99befcc01d7ed6f5594f87d6d8f6c (diff)
downloadvis-498723377cbf5cdb36d8b64f41b219a515a84175.tar.gz
vis-498723377cbf5cdb36d8b64f41b219a515a84175.tar.xz
Add infrastructure to register custom text object functions
Diffstat (limited to 'vis-text-objects.c')
-rw-r--r--vis-text-objects.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/vis-text-objects.c b/vis-text-objects.c
index 5869e86..ebb7384 100644
--- a/vis-text-objects.c
+++ b/vis-text-objects.c
@@ -2,13 +2,32 @@
#include "text-objects.h"
#include "util.h"
+int vis_textobject_register(Vis *vis, int type, void *data,
+ Filerange (*textobject)(Vis*, Win*, void*, size_t pos)) {
+
+ TextObject *obj = calloc(1, sizeof *obj);
+ if (!obj)
+ return -1;
+
+ obj->user = textobject;
+ obj->type = type;
+ obj->data = data;
+
+ if (array_add(&vis->textobjects, obj))
+ return LENGTH(vis_textobjects) + array_length(&vis->textobjects) - 1;
+ free(obj);
+ return -1;
+}
+
bool vis_textobject(Vis *vis, enum VisTextObject id) {
- if (id < LENGTH(vis_textobjects)) {
+ if (id < LENGTH(vis_textobjects))
vis->action.textobj = &vis_textobjects[id];
- action_do(vis, &vis->action);
- return true;
- }
- return false;
+ else
+ vis->action.textobj = array_get(&vis->textobjects, id - LENGTH(vis_textobjects));
+ if (!vis->action.textobj)
+ return false;
+ action_do(vis, &vis->action);
+ return true;
}
static Filerange search_forward(Vis *vis, Text *txt, size_t pos) {