From: NeilBrown Date: Tue, 8 Dec 2015 06:22:13 +0000 (+1100) Subject: use callbacks to return a pane from 'attach' commands. X-Git-Tag: lca2016~104 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=61316837bfe66f3551dad4de7d85a0f1d5bb1dd1;p=edlib.git use callbacks to return a pane from 'attach' commands. Signed-off-by: NeilBrown --- diff --git a/core-pane.c b/core-pane.c index 9b0a83bc..46a0a0fb 100644 --- a/core-pane.c +++ b/core-pane.c @@ -431,18 +431,30 @@ 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) { struct cmd_info ci = {0}; struct editor *ed = pane2ed(p); char *com; + struct call_return cr; + + cr.c = pane_callback; + cr.p = NULL; asprintf(&com, "attach-%s", type); ci.key = com; ci.home = dp; ci.focus = p; ci.str = arg; + ci.comm2 = &cr.c; if (!key_lookup(ed->commands, &ci)) { char *mod; if (strcmp(type, "global-keymap")==0) @@ -450,11 +462,10 @@ struct pane *pane_attach(struct pane *p, char *type, struct pane *dp, asprintf(&mod, "lib-%s", type); editor_load_module(ed, mod); free(mod); - if (!key_lookup(ed->commands, &ci)) - ci.focus = NULL; + key_lookup(ed->commands, &ci); } free(com); - return ci.focus; + return cr.p; } void pane_clear(struct pane *p, char *attrs) diff --git a/core.h b/core.h index aded137d..68ddb24e 100644 --- a/core.h +++ b/core.h @@ -476,6 +476,7 @@ struct call_return { struct command c; struct mark *m; char *s; + struct pane *p; }; static inline int call_comm(char *key, struct pane *focus, int numeric, struct mark *m, @@ -498,6 +499,8 @@ static inline int comm_call(struct command *comm, char *key, struct pane *focus, { struct cmd_info ci = {0}; + if (!comm) + return -1; ci.key = key; ci.focus = focus; ci.numeric = numeric; diff --git a/emacs-search.c b/emacs-search.c index 8e5e73ba..4f2f1ffc 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -282,9 +282,10 @@ DEF_CMD(emacs_search) esi->watch = search_again; doc_add_view(ci->focus, &esi->watch, 0); - ci->focus = pane_final_child(ci->focus); - p = pane_register(ci->focus, 0, &search_handle.c, esi, NULL); - ci->focus = p; + p = pane_final_child(ci->focus); + p = pane_register(p, 0, &search_handle.c, esi, NULL); + if (p) + comm_call(ci->comm2, "callback:attach", p, 0, NULL, NULL, 0); return 1; } diff --git a/lib-input.c b/lib-input.c index e09b578b..0f004308 100644 --- a/lib-input.c +++ b/lib-input.c @@ -105,6 +105,7 @@ DEF_LOOKUP_CMD(input_handle, im_map); DEF_CMD(input_attach) { struct input_mode *im = malloc(sizeof(*im)); + struct pane *p; register_map(); @@ -112,8 +113,10 @@ DEF_CMD(input_attach) im->numeric = NO_NUMERIC; im->extra = 0; - ci->focus = pane_register(ci->focus, 0, &input_handle.c, im, NULL); - return 1; + p = pane_register(ci->focus, 0, &input_handle.c, im, NULL); + if (p) + return comm_call(ci->comm2, "callback:attach", p, 0, NULL, NULL, 0); + return -1; } void edlib_init(struct editor *ed) diff --git a/lib-keymap.c b/lib-keymap.c index 1d4d1b49..01051094 100644 --- a/lib-keymap.c +++ b/lib-keymap.c @@ -129,8 +129,9 @@ DEF_CMD(keymap_attach) p = pane_final_child(p); p = pane_register(p, 0, &keymap_handle, kd, NULL); pane_check_size(p); - ci->focus = p; - return 1; + if (p) + return comm_call(ci->comm2, "callback:attach", p, 0, NULL, NULL, 0); + return -1; } void edlib_init(struct editor *ed) diff --git a/lib-messageline.c b/lib-messageline.c index 9243cd30..b381dd54 100644 --- a/lib-messageline.c +++ b/lib-messageline.c @@ -76,12 +76,13 @@ DEF_CMD(messageline_attach) { struct mlinfo *mli = malloc(sizeof(*mli)); struct pane *p = ci->focus; + struct pane *ret; mli->message = NULL; - ci->focus = pane_register(p, 0, &messageline_handle, mli, NULL); + ret = pane_register(p, 0, &messageline_handle, mli, NULL); mli->line = pane_register(p, 1, &messageline_handle, mli, NULL); pane_focus(ci->focus); - return 1; + return comm_call(ci->comm2, "callback:attach", ret, 0, NULL, NULL, 0); } diff --git a/lib-popup.c b/lib-popup.c index f818fb1e..6f12e57d 100644 --- a/lib-popup.c +++ b/lib-popup.c @@ -186,8 +186,7 @@ DEF_CMD(popup_attach) ci2.str2 = "Abort"; key_handle_focus(&ci2); - ci->focus = ppi->popup; - return 1; + return comm_call(ci->comm2, "callback:attach", ppi->popup, 0, NULL, NULL, 0); } void edlib_init(struct editor *ed) diff --git a/lib-tile.c b/lib-tile.c index d0f2d341..038be78e 100644 --- a/lib-tile.c +++ b/lib-tile.c @@ -87,9 +87,8 @@ DEF_CMD(tile_attach) ti->direction = Neither; INIT_LIST_HEAD(&ti->tiles); pane_check_size(p); - ci->focus = p; attr_set_str(&p->attrs, "borders", "BL", -1); - return 1; + return comm_call(ci->comm2, "callback:attach", p, 0, NULL, NULL, 0); } static struct pane *tile_split(struct pane *p, int horiz, int after) diff --git a/lib-view.c b/lib-view.c index c8eb8592..3b6b94f1 100644 --- a/lib-view.c +++ b/lib-view.c @@ -242,8 +242,8 @@ DEF_CMD(view_attach) if (strchr(borderstr, 'L')) borders |= BORDER_LEFT; if (strchr(borderstr, 'R')) borders |= BORDER_RIGHT; - ci->focus = do_view_attach(ci->focus, borders); - return ci->focus != NULL; + return comm_call(ci->comm2, "callback:attach", do_view_attach(ci->focus, borders), + 0, NULL, NULL, 0); } DEF_CMD(view_click)