From de64dfb92f574bf3c984d0d4d5609cf56308f1d9 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 10 Dec 2015 10:41:39 +1100 Subject: [PATCH] Use callbacks to return pane from "doc-*" Signed-off-by: NeilBrown --- core-doc.c | 13 ++++++++++++- doc-dir.c | 7 +++++-- doc-text.c | 7 +++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core-doc.c b/core-doc.c index cead79a8..e4945f8b 100644 --- a/core-doc.c +++ b/core-doc.c @@ -501,10 +501,18 @@ struct pane *doc_attach(struct pane *parent, struct doc *d) return p; } +DEF_CMD(take_pane) +{ + struct call_return *cr = container_of(ci->comm, struct call_return, c); + cr->p = ci->focus; + return 1; +} + struct doc *doc_new(struct editor *ed, char *type) { char buf[100]; struct cmd_info ci = {0}; + struct call_return cr; struct doc_data *dd; init_doc_defaults(); @@ -512,12 +520,15 @@ struct doc *doc_new(struct editor *ed, char *type) sprintf(buf, "doc-%s", type); ci.key = buf; ci.focus = ci.home = &ed->root; + cr.c = take_pane; + cr.p = NULL; + ci.comm2 = &cr.c; if (!key_lookup(ed->commands, &ci)) { editor_load_module(ed, buf); if (!key_lookup(ed->commands, &ci)) return NULL; } - dd = ci.focus->data; + dd = cr.p->data; return dd->doc; } diff --git a/doc-dir.c b/doc-dir.c index 25752a0c..9bea6ec3 100644 --- a/doc-dir.c +++ b/doc-dir.c @@ -119,13 +119,16 @@ DEF_CMD(dir_new) { struct directory *dr = malloc(sizeof(*dr)); struct editor *ed = pane2ed(ci->focus); + struct pane *p; doc_init(&dr->doc); dr->doc.map = doc_map; INIT_LIST_HEAD(&dr->ents); dr->fname = NULL; - ci->focus = doc_attach(ed->root.focus, &dr->doc); - return 1; + p = doc_attach(ed->root.focus, &dr->doc); + if (p) + return comm_call(ci->comm2, "callback:doc", p, 0, NULL, NULL, 0); + return -1; } DEF_CMD(dir_load_file) diff --git a/doc-text.c b/doc-text.c index 3b3db46f..e9cf3c75 100644 --- a/doc-text.c +++ b/doc-text.c @@ -1054,6 +1054,7 @@ DEF_CMD(text_new) { struct text *t = malloc(sizeof(*t)); struct editor *ed = pane2ed(ci->focus); + struct pane *p; t->alloc = NULL; INIT_LIST_HEAD(&t->text); @@ -1062,8 +1063,10 @@ DEF_CMD(text_new) t->doc.map = text_map; t->fname = NULL; text_new_alloc(t, 0); - ci->focus = doc_attach(ed->root.focus, &t->doc); - return 1; + p = doc_attach(ed->root.focus, &t->doc); + if (p) + return comm_call(ci->comm2, "callback:doc", p, 0, NULL, NULL, 0); + return -1; } static int count_bytes(struct text *t, struct mark *from, struct mark *to) -- 2.39.5