]> git.neil.brown.name Git - edlib.git/commitdiff
Use callback to return marks from doc:vmark-get
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 00:00:36 +0000 (11:00 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core-mark.c
core.h

index e4945f8b07f3e44e9feeef12e51f8c9d85b90814..63c780d44389c035d401c461e80bbb058d0cdc06 100644 (file)
@@ -437,12 +437,14 @@ DEF_CMD(doc_handle)
        }
 
        if (strcmp(ci->key, "doc:vmark-get") == 0) {
-               ci->mark = do_vmark_first(dd->doc, ci->numeric);
-               ci->mark2 = do_vmark_last(dd->doc, ci->numeric);
+               struct mark *m, *m2;
+               m = do_vmark_first(dd->doc, ci->numeric);
+               m2 = do_vmark_last(dd->doc, ci->numeric);
                if (ci->extra && dd->point)
-                       ci->mark2 = do_vmark_at_point(dd->doc, dd->point,
-                                                     ci->numeric);
-               return 1;
+                       m2 = do_vmark_at_point(dd->doc, dd->point,
+                                              ci->numeric);
+               return comm_call7(ci->comm2, "callback:vmark", ci->focus,
+                                 0, m, NULL, 0, NULL, m2);
        }
 
        ret = key_lookup(dd->doc->map, ci);
index 18b642fe285676540ea598d0732c8b25742e2027..66c960adff378769716f5b67fe40bb07b24ae7e2 100644 (file)
@@ -820,24 +820,36 @@ struct mark *do_vmark_last(struct doc *d, int view)
        return NULL;
 }
 
+DEF_CMD(take_marks)
+{
+       struct call_return *cr = container_of(ci->comm, struct call_return, c);
+       cr->m = ci->mark;
+       cr->m2 = ci->mark2;
+       return 1;
+}
+
 static int vmark_get(struct pane *p, int view,
                     struct mark **first, struct mark **last, struct mark **point)
 {
        struct cmd_info ci = {0};
+       struct call_return cr;
 
        ci.key = "doc:vmark-get";
        ci.focus = p;
        ci.numeric = view;
+       cr.c = take_marks;
+       cr.m = cr.m2 = NULL;
+       ci.comm2 = &cr.c;
        if (point)
                ci.extra = 1;
        if (key_handle_focus(&ci) == 0)
                return 0;
        if (first)
-               *first = ci.mark;
+               *first = cr.m;
        if (point)
-               *point = ci.mark2;
+               *point = cr.m2;
        else if (last)
-               *last = ci.mark2;
+               *last = cr.m2;
        return 1;
 }
 
diff --git a/core.h b/core.h
index 03db70d70043fb05c33170f78118a4eb9ca430d5..382251cc002ae8254feb91a55a6dd8359523843c 100644 (file)
--- a/core.h
+++ b/core.h
@@ -478,7 +478,7 @@ static inline int call5(char *key, struct pane *focus, int numeric, struct mark
 
 struct call_return {
        struct command c;
-       struct mark *m;
+       struct mark *m, *m2;
        char *s;
        struct pane *p;
        int i;
@@ -516,6 +516,27 @@ static inline int comm_call(struct command *comm, char *key, struct pane *focus,
        return comm->func(&ci);
 }
 
+static inline int comm_call7(struct command *comm, char *key,
+                            struct pane *focus,
+                            int numeric, struct mark *m, char *str,
+                            int extra, char *str2, struct mark *m2)
+{
+       struct cmd_info ci = {0};
+
+       if (!comm)
+               return -1;
+       ci.key = key;
+       ci.focus = focus;
+       ci.numeric = numeric;
+       ci.mark = m;
+       ci.mark2 = m2;
+       ci.str = str;
+       ci.str2 = str2;
+       ci.extra = extra;
+       ci.comm = comm;
+       return comm->func(&ci);
+}
+
 static inline int call_extra(char *key, struct pane *focus, int numeric, struct mark *m,
                             int extra)
 {