This is the most-used command, I really have to optimise this one day.
Signed-off-by: NeilBrown <neil@brown.name>
struct doc doc;
};
-static wint_t docs_step(struct doc *doc, struct mark *m, bool forward, bool move)
+DEF_CMD(docs_step)
{
+ struct doc *doc = (*ci->pointp)->doc;
+ struct mark *m = ci->mark;
+ bool forward = ci->numeric;
+ bool move = ci->extra;
+
struct doc *d = m->ref.d, *next;
if (forward) {
if (move)
m->ref.d = next;
if (d == NULL)
- return WEOF;
+ ci->extra = WEOF;
else
- return ' ';
+ ci->extra = ' ';
+ return 1;
}
DEF_CMD(docs_set_ref)
}
static struct doc_operations docs_ops = {
- .step = docs_step,
};
DEF_CMD(docs_open)
key_add(docs_map, "doc:set-ref", &docs_set_ref);
key_add(docs_map, "doc:get-attr", &docs_get_attr);
key_add(docs_map, "doc:mark-same", &docs_mark_same);
+ key_add(docs_map, "doc:step", &docs_step);
ds->doc.map = docs_map;
m;
m = doc_next_mark_all(ed->docs, m))
if (m->ref.d == d) {
- docs_step(ed->docs, m, 1, 1);
+ mark_step2(ed->docs, m, 1, 1);
doc_notify_change(ed->docs, m);
}
}
m;
m = doc_next_mark_all(ed->docs, m))
if (d->list.next == &m->ref.d->list) {
- docs_step(ed->docs, m, 0, 1);
+ mark_step2(ed->docs, m, 0, 1);
doc_notify_change(ed->docs, m);
}
}
mp->seq = seq;
}
+wint_t mark_step(struct doc *d, struct mark *m, int forward, int move, struct cmd_info *ci)
+{
+ struct point p, *pt = &p;
+
+ p.doc = d;
+ ci->key = "doc:step";
+ ci->pointp = &pt;
+ ci->mark = m;
+ ci->numeric = forward;
+ ci->extra = move;
+ key_lookup(d->map, ci);
+ return ci->extra;
+}
+
+wint_t mark_step2(struct doc *d, struct mark *m, int forward, int move)
+{
+ struct cmd_info ci = {0};
+
+ return mark_step(d, m, forward, move, &ci);
+}
+
wint_t mark_next(struct doc *d, struct mark *m)
{
wint_t ret;
mark_same(d, m, m2))
mark_forward_over(m, m2);
- ret = d->ops->step(d, m, 1, 1);
+ ret = mark_step2(d, m, 1, 1);
if (ret == WEOF)
return ret;
mark_same(d, m, mp))
mark_backward_over(m, mp);
- ret = d->ops->step(d, m, 0, 1);
+ ret = mark_step2(d, m, 0, 1);
if (ret == WEOF)
return ret;
while ((mp = prev_mark(d, m)) != NULL &&
};
struct doc_operations {
- wint_t (*step)(struct doc *d, struct mark *m, bool forward, bool move);
};
void doc_init(struct doc *d);
int mark_same2(struct doc *d, struct mark *m1, struct mark *m2, struct cmd_info *ci);
struct point *point_new(struct doc *d, struct point **owner);
struct point *point_dup(struct point *p, struct point **owner);
+wint_t mark_step(struct doc *d, struct mark *m, int forward, int move, struct cmd_info *ci);
+wint_t mark_step2(struct doc *d, struct mark *m, int forward, int move);
wint_t mark_next(struct doc *d, struct mark *m);
wint_t mark_prev(struct doc *d, struct mark *m);
struct mark *mark_at_point(struct point *p, int view);
static inline wint_t doc_following(struct doc *d, struct mark *m)
{
- return d->ops->step(d, m, 1, 0);
+ return mark_step2(d, m, 1, 0);
}
static inline wint_t doc_prior(struct doc *d, struct mark *m)
{
- return d->ops->step(d, m, 0, 0);
+ return mark_step2(d, m, 0, 0);
}
static inline void doc_replace(struct point *p, struct mark *m,
char *str, bool *first)
return 1;
}
-static wint_t dir_step(struct doc *doc, struct mark *m, bool forward, bool move)
+DEF_CMD(dir_step)
{
+ struct doc *doc = (*ci->pointp)->doc;
+ struct mark *m = ci->mark;
+ bool forward = ci->numeric;
+ bool move = ci->extra;
+
struct directory *dr = container_of(doc, struct directory, doc);
struct dir_ent *d = m->ref.d;
wint_t ret;
}
if (move && ret != WEOF)
m->ref.d = d;
- return ret;
+ ci->extra = ret;
+ return 1;
}
DEF_CMD(dir_set_ref)
static struct doc_operations dir_ops = {
- .step = dir_step,
};
DEF_CMD(dir_open)
key_add(doc_map, "doc:set-ref", &dir_set_ref);
key_add(doc_map, "doc:get-attr", &dir_get_attr);
key_add(doc_map, "doc:mark-same", &dir_mark_same);
+ key_add(doc_map, "doc:step", &dir_step);
}
return ret;
}
-static wint_t text_step(struct doc *d, struct mark *m, bool forward, bool move)
+DEF_CMD(text_step)
{
+ struct doc *d = (*ci->pointp)->doc;
+ struct mark *m = ci->mark;
+ bool forward = ci->numeric;
+ bool move = ci->extra;
+
struct text *t = container_of(d, struct text, doc);
struct doc_ref r;
wint_t ret;
ret = text_prev(t, &r);
if (ret != WEOF && move)
m->ref = *(struct doc_ref*)&r;
- return ret;
+ ci->extra = ret;
+ return 1;
}
static int text_ref_same(struct text *t, struct doc_ref *r1, struct doc_ref *r2)
}
static struct doc_operations text_ops = {
- .step = text_step,
};
#define LARGE_LINE 4096
key_add(text_map, "doc:get-attr", &text_get_attr);
key_add(text_map, "doc:replace", &text_replace);
key_add(text_map, "doc:mark-same", &text_mark_same);
+ key_add(text_map, "doc:step", &text_step);
}