]> git.neil.brown.name Git - edlib.git/commitdiff
Use callbacks to return pane from render-*-attach commands.
authorNeilBrown <neil@brown.name>
Tue, 8 Dec 2015 06:32:28 +0000 (17:32 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-pane.c
render-complete.c
render-format.c
render-hex.c
render-lines.c

index 46a0a0fb26002ebb4bf3bb15a0292ab19651fa45..cf5bd456b6f6e04f26992f4906ffb01e9075eeb8 100644 (file)
@@ -387,11 +387,22 @@ struct pane *pane_with_cursor(struct pane *p, int *oxp, int *oyp)
        return ret;
 }
 
+DEF_CMD(pane_callback)
+{
+       struct call_return *cr = container_of(ci->comm, struct call_return, c);
+       cr->p = ci->focus;
+       return 1;
+}
+
 struct pane *render_attach(char *name, struct pane *parent)
 {
        char buf[100];
        struct cmd_info ci = {0};
        int ret;
+       struct call_return cr;
+
+       cr.c = pane_callback;
+       cr.p = NULL;
 
        /* always attach a renderer as a leaf */
        parent = pane_final_child(parent);
@@ -403,15 +414,16 @@ struct pane *render_attach(char *name, struct pane *parent)
        sprintf(buf, "render-%s-attach", name);
        ci.key = buf;
        ci.focus = parent;
+       ci.comm2 = &cr.c;
        ret = key_lookup(pane2ed(parent)->commands, &ci);
        if (ret)
-               return ci.focus;
+               return cr.p;
        sprintf(buf, "render-%s", name);
        editor_load_module(pane2ed(parent), buf);
        sprintf(buf, "render-%s-attach", name);
        ret = key_lookup(pane2ed(parent)->commands, &ci);
        if (ret)
-               return ci.focus;
+               return cr.p;
        return NULL;
 }
 
@@ -431,13 +443,6 @@ void pane_set_extra(struct pane *p, int extra)
        call5("Mode:set-extra", p, 0, NULL, NULL, extra);
 }
 
-DEF_CMD(pane_callback)
-{
-       struct call_return *cr = container_of(ci->comm, struct call_return, c);
-       cr->p = ci->focus;
-       return 1;
-}
-
 struct pane *pane_attach(struct pane *p, char *type, struct pane *dp,
                         char *arg)
 {
index 74f82ee7010b9a6ef47d149a5293a8587a06fbad..4d21f0c392282188c668686a3e08828fff14e100 100644 (file)
@@ -369,8 +369,7 @@ REDEF_CMD(complete_attach)
        pane_check_size(complete);
        cd->prefix = strdup("");
 
-       ci->focus = complete;
-       return 1;
+       return comm_call(ci->comm2, "callback:attach", complete, 0, NULL, NULL, 0);
 }
 
 void edlib_init(struct editor *ed)
index 3df04bcc33a2d6809321d2b9955018a7889dd20c..1666e9ac42e1e166187c08e7b044d6111e77df5f 100644 (file)
@@ -20,8 +20,6 @@ struct rf_data {
        int fields;
 };
 
-DEF_CMD(render_format_attach);
-
 DEF_CMD(render_line)
 {
        char *body = pane_attr_get(ci->focus, "line-format");
@@ -176,14 +174,16 @@ DEF_CMD(format_close)
        return 1;
 }
 
+static struct pane *do_render_format_attach(struct pane *parent);
 DEF_CMD(format_clone)
 {
        struct pane *c;
+       struct pane *p;
 
-       render_format_attach_func(ci);
+       p = do_render_format_attach(ci->focus);
        c = pane_child(ci->home);
        if (c)
-               return pane_clone(c, ci->focus);
+               return pane_clone(c, p);
        return 1;
 }
 
@@ -265,11 +265,10 @@ static void render_format_register_map(void)
 
 DEF_LOOKUP_CMD(render_format_handle, rf_map);
 
-REDEF_CMD(render_format_attach)
+static struct pane *do_render_format_attach(struct pane *parent)
 {
        struct rf_data *rf = malloc(sizeof(*rf));
        struct pane *p;
-       struct pane *parent = ci->focus;
 
        if (!rf_map)
                render_format_register_map();
@@ -278,9 +277,16 @@ REDEF_CMD(render_format_attach)
        p = pane_register(parent, 0, &render_format_handle.c, rf, NULL);
        attr_set_str(&p->attrs, "render-wrap", "no", -1);
        render_attach("lines", p);
+       return p;
+}
 
-       ci->focus = p;
-       return 1;
+DEF_CMD(render_format_attach)
+{
+       struct pane *p;
+
+       p = do_render_format_attach(ci->focus);
+
+       return comm_call(ci->comm2, "callback:attach", p, 0, NULL, NULL, 0);
 }
 
 void edlib_init(struct editor *ed)
index 6b7da759dbd0a22821d7d805abea5d9b57fdf4d3..c98c79349b4b905519fc8b236873bf5f661ee307 100644 (file)
@@ -241,8 +241,9 @@ static struct pane *do_render_hex_attach(struct pane *parent)
 
 DEF_CMD(render_hex_attach)
 {
-       ci->focus = do_render_hex_attach(ci->focus);
-       return 1;
+       return comm_call(ci->comm2, "callback:attach",
+                        do_render_hex_attach(ci->focus),
+                        0, NULL, NULL, 0);
 }
 
 void edlib_init(struct editor *ed)
index 5aef7d9fcd97848be23d5607608e75fda3516530..ceaed3d500f78457d54ce9f68dafdd5e4d752d29 100644 (file)
@@ -955,8 +955,8 @@ REDEF_CMD(render_lines_attach)
        rl->typenum = doc_add_view(ci->focus, &rl->type, 0);
        rl->pane = pane_register(ci->focus, 0, &render_lines_handle.c, rl, NULL);
 
-       ci->focus = rl->pane;
-       return 1;
+       return comm_call(ci->comm2, "callback:attach", rl->pane,
+                        0, NULL, NULL, 0);
 }
 
 void edlib_init(struct editor *ed)