diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-03-19 14:05:32 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-03-19 14:58:07 +0100 |
| commit | 5166e81e794c0faa80742ad6806745b13b967a51 (patch) | |
| tree | d2f4cd3ece83311bbea9ea172ea12d8337225fa2 /vis-operators.c | |
| parent | 5fb583f035bb8e699e8980e63050ef1f41f94dd9 (diff) | |
| download | vis-5166e81e794c0faa80742ad6806745b13b967a51.tar.gz vis-5166e81e794c0faa80742ad6806745b13b967a51.tar.xz | |
vis: add infrastructure for user specified operators
Diffstat (limited to 'vis-operators.c')
| -rw-r--r-- | vis-operators.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/vis-operators.c b/vis-operators.c index 8038a2d..494774c 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -245,6 +245,18 @@ static size_t op_filter(Vis *vis, Text *txt, OperatorContext *c) { return text_size(txt) + 1; /* do not change cursor position, would destroy selection */ } +int vis_operator_register(Vis *vis, VisOperatorFunction *func, void *context) { + Operator *op = calloc(1, sizeof *op); + if (!op) + return -1; + op->func = func; + op->context = context; + if (array_add_ptr(&vis->operators, op)) + return VIS_OP_LAST + array_length(&vis->operators) - 1; + free(op); + return -1; +} + bool vis_operator(Vis *vis, enum VisOperator id, ...) { va_list ap; va_start(ap, id); @@ -292,9 +304,16 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { default: break; } - if (id >= LENGTH(vis_operators)) + + const Operator *op = NULL; + if (id < LENGTH(vis_operators)) + op = &vis_operators[id]; + else + op = array_get_ptr(&vis->operators, id - VIS_OP_LAST); + + if (!op) goto err; - const Operator *op = &vis_operators[id]; + if (vis->mode->visual) { vis->action.op = op; vis_do(vis); |
