]> git.neil.brown.name Git - edlib.git/commitdiff
Use a callback to return mark for mark_at_point.
authorNeilBrown <neil@brown.name>
Tue, 8 Dec 2015 02:01:47 +0000 (13:01 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
This might seem a bit forced, but I really think callbacks
like this are the best generic approach.  I hope.

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

index d678b4fd7c2b963539175fe5b0bedd1cd73bb84e..87791127c74e5f2b9dc4349a6d1dfb0883557a4f 100644 (file)
@@ -378,19 +378,23 @@ DEF_CMD(doc_handle)
 
        if (strcmp(ci->key, "doc:dup-point") == 0) {
                struct mark *pt = dd->point;
+               struct mark *m;
                if (ci->mark && ci->mark->viewnum == MARK_POINT)
                        pt = ci->mark;
-               ci->mark = NULL;
-               if (pt) {
-                       if (ci->extra == MARK_POINT)
-                               ci->mark = point_dup(pt);
-                       else if (ci->extra == MARK_UNGROUPED)
-                               ci->mark = mark_dup(pt, 1);
-                       else
-                               ci->mark = do_mark_at_point(dd->doc, pt,
-                                                           ci->extra);
-               }
-               return 1;
+
+               if (!pt || !ci->comm2)
+                       return -1;
+
+               if (ci->extra == MARK_POINT)
+                       m = point_dup(pt);
+               else if (ci->extra == MARK_UNGROUPED)
+                       m = mark_dup(pt, 1);
+               else
+                       m = do_mark_at_point(dd->doc, pt,
+                                            ci->extra);
+
+               return comm_call(ci->comm2, "callback:dup-point", ci->focus,
+                                0, m, NULL, 0);
        }
 
        if (strcmp(ci->key, "Move-to") == 0) {
index da1183dc81f37f02c646d3e24a8a745c0f482319..18b642fe285676540ea598d0732c8b25742e2027 100644 (file)
@@ -159,9 +159,24 @@ struct mark *do_mark_at_point(struct doc *d, struct mark *pt, int view)
        return ret;
 }
 
+DEF_CMD(dup_point_callback)
+{
+       struct call_return *cr = container_of(ci->comm, struct call_return, c);
+       cr->m = ci->mark;
+       return 1;
+}
+
 struct mark *mark_at_point(struct pane *p, struct mark *pm, int view)
 {
-       return call_mark("doc:dup-point", p, 0, pm, view);
+       struct call_return cr;
+       int ret;
+
+       cr.c = dup_point_callback;
+       cr.m = NULL;
+       ret = call_comm("doc:dup-point", p, 0, pm, NULL, view, &cr.c);
+       if (ret <= 0)
+               return NULL;
+       return cr.m;
 }
 
 struct mark *point_dup(struct mark *p)
diff --git a/core.h b/core.h
index 3374748d6ff0f908f806f553bf2659874d6560de..4f5cc2563599c7f0cb6cd8df5f2174e3810b74ab 100644 (file)
--- a/core.h
+++ b/core.h
@@ -498,6 +498,11 @@ static inline int call5(char *key, struct pane *focus, int numeric, struct mark
        return key_handle_focus(&ci);
 }
 
+struct call_return {
+       struct command c;
+       struct mark *m;
+};
+
 static inline int call_comm(char *key, struct pane *focus, int numeric, struct mark *m,
                            char *str, int extra, struct command *comm)
 {
@@ -513,19 +518,19 @@ static inline int call_comm(char *key, struct pane *focus, int numeric, struct m
        return key_handle_focus(&ci);
 }
 
-static inline struct mark *call_mark(char *key, struct pane *focus, int numeric,
-                                    struct mark *m, int extra)
+static inline int comm_call(struct command *comm, char *key, struct pane *focus,
+                           int numeric, struct mark *m, char *str, int extra)
 {
        struct cmd_info ci = {0};
 
        ci.key = key;
        ci.focus = focus;
        ci.numeric = numeric;
-       ci.extra = extra;
        ci.mark = m;
-       if (!key_handle_focus(&ci))
-               return NULL;
-       return ci.mark;
+       ci.str = str;
+       ci.extra = extra;
+       ci.comm = comm;
+       return comm->func(&ci);
 }
 
 static inline struct pane *call_pane(char *key, struct pane *focus, int numeric,