From 0a7698206c674685c28512d8b7995c546ded0cbf Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 8 Dec 2015 17:32:28 +1100 Subject: [PATCH] Use callbacks to return pane from render-*-attach commands. Signed-off-by: NeilBrown --- core-pane.c | 23 ++++++++++++++--------- render-complete.c | 3 +-- render-format.c | 22 ++++++++++++++-------- render-hex.c | 5 +++-- render-lines.c | 4 ++-- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/core-pane.c b/core-pane.c index 46a0a0fb..cf5bd456 100644 --- a/core-pane.c +++ b/core-pane.c @@ -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) { diff --git a/render-complete.c b/render-complete.c index 74f82ee7..4d21f0c3 100644 --- a/render-complete.c +++ b/render-complete.c @@ -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) diff --git a/render-format.c b/render-format.c index 3df04bcc..1666e9ac 100644 --- a/render-format.c +++ b/render-format.c @@ -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) diff --git a/render-hex.c b/render-hex.c index 6b7da759..c98c7934 100644 --- a/render-hex.c +++ b/render-hex.c @@ -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) diff --git a/render-lines.c b/render-lines.c index 5aef7d9f..ceaed3d5 100644 --- a/render-lines.c +++ b/render-lines.c @@ -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) -- 2.39.5