]> git.neil.brown.name Git - edlib.git/commitdiff
Make 'step' a command.
authorNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 08:48:47 +0000 (19:48 +1100)
committerNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 08:48:47 +0000 (19:48 +1100)
This is the most-used command, I really have to optimise this one day.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core-mark.c
core.h
doc-dir.c
doc-text.c

index 3e615844f667afe89d542bdedaf0f6a3d3869ad7..2d3e342e2bb51d353e79ed75ccfcf823ac119a5a 100644 (file)
@@ -274,8 +274,13 @@ struct docs {
        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) {
@@ -298,9 +303,10 @@ static wint_t docs_step(struct doc *doc, struct mark *m, bool forward, bool move
        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)
@@ -366,7 +372,6 @@ DEF_CMD(docs_get_attr)
 }
 
 static struct doc_operations docs_ops = {
-       .step      = docs_step,
 };
 
 DEF_CMD(docs_open)
@@ -436,6 +441,7 @@ void doc_make_docs(struct editor *ed)
        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;
 
@@ -454,7 +460,7 @@ static void docs_release(struct doc *d)
             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);
                }
 }
@@ -474,7 +480,7 @@ static void docs_attach(struct doc *d)
             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);
                }
 }
index 066c94b5b15d7032bafb3db1d052d0dcac8f5801..4539d4450a00f9e5ba6e215c1cb9782a0a7d4f2b 100644 (file)
@@ -478,6 +478,27 @@ void mark_backward_over(struct mark *m, struct mark *mp)
        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;
@@ -487,7 +508,7 @@ wint_t mark_next(struct doc *d, struct mark *m)
               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;
 
@@ -507,7 +528,7 @@ wint_t mark_prev(struct doc *d, struct mark *m)
               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 &&
diff --git a/core.h b/core.h
index ea677c83870db08f2849b1c75f38b74f1b0c73df..b18777f92d90cecc94db8c750ccbd5db5570722e 100644 (file)
--- a/core.h
+++ b/core.h
@@ -84,7 +84,6 @@ struct doc {
 };
 
 struct doc_operations {
-       wint_t          (*step)(struct doc *d, struct mark *m, bool forward, bool move);
 };
 
 void doc_init(struct doc *d);
@@ -158,6 +157,8 @@ int mark_same(struct doc *d, struct mark *m1, struct mark *m2);
 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);
@@ -341,11 +342,11 @@ struct pane *pane_final_child(struct pane *p);
 
 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)
index b400bd1744b794feb69d5c1c0913a429524639cc..5f1e843c1391eafa53009e1e1927aa74612fb919 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -259,8 +259,13 @@ DEF_CMD(dir_same_file)
        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;
@@ -289,7 +294,8 @@ static wint_t dir_step(struct doc *doc, struct mark *m, bool forward, bool move)
        }
        if (move && ret != WEOF)
                m->ref.d = d;
-       return ret;
+       ci->extra = ret;
+       return 1;
 }
 
 DEF_CMD(dir_set_ref)
@@ -488,7 +494,6 @@ DEF_CMD(dir_destroy)
 
 
 static struct doc_operations dir_ops = {
-       .step      = dir_step,
 };
 
 DEF_CMD(dir_open)
@@ -564,4 +569,5 @@ void edlib_init(struct editor *ed)
        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);
 }
index fa780fb24a7a811568e1d501622fe3c98be9e0e3..26841fd8057824b6054b37e009678ec699a9ee6b 100644 (file)
@@ -957,8 +957,13 @@ static wint_t text_prev(struct text *t, struct doc_ref *r)
        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;
@@ -970,7 +975,8 @@ static wint_t text_step(struct doc *d, struct mark *m, bool forward, bool move)
                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)
@@ -1518,7 +1524,6 @@ DEF_CMD(text_destroy)
 }
 
 static struct doc_operations text_ops = {
-       .step      = text_step,
 };
 
 #define LARGE_LINE 4096
@@ -1649,4 +1654,5 @@ void edlib_init(struct editor *ed)
        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);
 }