]> git.neil.brown.name Git - edlib.git/commitdiff
use callbacks to return a pane from 'attach' commands.
authorNeilBrown <neil@brown.name>
Tue, 8 Dec 2015 06:22:13 +0000 (17:22 +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
core.h
emacs-search.c
lib-input.c
lib-keymap.c
lib-messageline.c
lib-popup.c
lib-tile.c
lib-view.c

index 9b0a83bc48c296da11407bac5ce7fe72dd5c55ab..46a0a0fb26002ebb4bf3bb15a0292ab19651fa45 100644 (file)
@@ -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 aded137d1ae366d0715759db5ee4b0735bbf085c..68ddb24e92fba98da425d37e865e437e2ff7fdc9 100644 (file)
--- 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;
index 8e5e73ba66ef24fa284a967d64540a377ac50a05..4f2f1ffcbb8839a94bfdd51d68c4b96adf2e9408 100644 (file)
@@ -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;
 }
 
index e09b578ba6df4550d9ae4c29292b97b237546448..0f004308f42e4b8438fa75f05f4a1d86594fbb02 100644 (file)
@@ -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)
index 1d4d1b49c2d3a1bcd89755e06c8eefd83cb9a70d..010510947ad7483bc65f6860cba11e9c17f321a1 100644 (file)
@@ -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)
index 9243cd30615225bc962c00dd374453bc431762f5..b381dd54f96f348d55e09a4f21e080915c7054fe 100644 (file)
@@ -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);
 }
 
 
index f818fb1ec605764c47aaa9c54d84eed3f9d1b855..6f12e57ddceaafe701a8935212b67e8d0d6d7044 100644 (file)
@@ -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)
index d0f2d34189fa662cb6416c9426b5c856433ac4c7..038be78e132c883e423316160b957cfdab44798d 100644 (file)
@@ -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)
index c8eb859247b6ce3d46224b436927480fc4633ebd..3b6b94f11597c69df500e9e7716ff326871cd801 100644 (file)
@@ -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)