]> git.neil.brown.name Git - edlib.git/commitdiff
call macro changes step 2: call_home()
authorNeilBrown <neil@brown.name>
Thu, 21 Sep 2017 02:23:58 +0000 (04:23 +0200)
committerNeilBrown <neil@brown.name>
Thu, 21 Sep 2017 02:23:58 +0000 (04:23 +0200)
call_home7() and call_home9() are gone

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
display-ncurses.c
doc-docs.c
doc-email.c
doc-multipart.c
lib-crop.c
lib-linecount.c
mode-emacs.c
render-lines.c

index ae5b0eccc75aefb21e00ccae4735c6f49998783f..bb7d07290582ea7e1885a3bfb1403e1da8ddcf92 100644 (file)
@@ -581,7 +581,7 @@ DEF_CMD(doc_do_revisit)
         */
        if (!ci->home->parent)
                return -1;
-       return call_home(ci->home->parent, ci->key, ci->home, ci->numeric, ci->mark, NULL);
+       return call_home(ci->home->parent, ci->key, ci->home, ci->numeric, ci->mark);
 }
 
 DEF_CMD(doc_mymark)
@@ -772,8 +772,8 @@ DEF_CMD(doc_handle)
        }
 
        if (strcmp(ci->key, "Replace") == 0) {
-               return call_home7(dd->doc, "doc:replace", ci->focus, 1, ci->mark, ci->str,
-                                 ci->extra, NULL, dd->point, NULL);
+               return call_home(dd->doc, "doc:replace", ci->focus, 1, ci->mark, ci->str,
+                                ci->extra, dd->point);
        }
 
        if (strcmp(ci->key, "get-attr") == 0) {
@@ -797,9 +797,10 @@ DEF_CMD(doc_handle)
            strncmp(ci->key, "Notify:doc:", 11) != 0)
                /* doesn't get sent to the doc */
                return 0;
-       return call_home9(dd->doc, ci->key, ci->focus, ci->numeric,
-                         ci->mark ?: dd->point, ci->str, ci->extra, ci->str2,
-                         ci->mark2, ci->comm2, ci->x, ci->y);
+       return call_home(dd->doc, ci->key, ci->focus, ci->numeric,
+                        ci->mark ?: dd->point, ci->str,
+                        ci->extra, ci->mark2, ci->str2,
+                        ci->comm2, ci->x, ci->y);
 }
 
 static struct pane *doc_assign(struct pane *p safe, struct pane *doc safe,
@@ -846,7 +847,7 @@ struct pane *doc_new(struct pane *p safe, char *type, struct pane *parent)
        snprintf(buf, sizeof(buf), "attach-doc-%s", type);
        np = call_pane(buf, p, 0, NULL, 0);
        if (np && parent)
-               call_home(np, "doc:set-parent", parent, 0, NULL, NULL);
+               call_home(np, "doc:set-parent", parent);
        return np;
 }
 
diff --git a/core.h b/core.h
index a2a6127ca7a66d2e8c5b981d3338e22ca09fd6b0..dab6b09be8e60a2416ff173531f2d16f21a6968b 100644 (file)
--- a/core.h
+++ b/core.h
@@ -477,6 +477,29 @@ static inline void doc_del_view(struct pane *p safe, int num)
 #define call2(key, focus) \
        do_call(key, focus, 0, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, NULL)
 
+/* Often the 'home' arg is not need and defaults to 'focus', so it is at the
+ * end of 'call'.  Often enough it has an important place, so have a set of
+ * macros with 'home' first
+ */
+#define call_home(...) VFUNC(call_home, __VA_ARGS__)
+#define call_home12(home, key, focus, numeric, mark, str, extra, mark2, str2, comm2, x, y) \
+       do_call(key, focus, numeric, mark, str, extra, mark2, str2, comm2, x, y, home)
+#define call_home10(home, key, focus, numeric, mark, str, extra, mark2, str2, comm2) \
+       do_call(key, focus, numeric, mark, str, extra, mark2, str2, comm2, 0, 0, home)
+#define call_home9(home, key, focus, numeric, mark, str, extra, mark2, str2) \
+       do_call(key, focus, numeric, mark, str, extra, mark2, str2, NULL, 0, 0, home)
+#define call_home8(home, key, focus, numeric, mark, str, extra, mark2) \
+       do_call(key, focus, numeric, mark, str, extra, mark2, NULL, NULL, 0, 0, home)
+#define call_home7(home, key, focus, numeric, mark, str, extra) \
+       do_call(key, focus, numeric, mark, str, extra, NULL, NULL, NULL, 0, 0, home)
+#define call_home6(home, key, focus, numeric, mark, str) \
+       do_call(key, focus, numeric, mark, str, 0, NULL, NULL, NULL, 0, 0, home)
+#define call_home5(home, key, focus, numeric, mark) \
+       do_call(key, focus, numeric, mark, NULL, 0, NULL, NULL, NULL, 0, 0, home)
+#define call_home4(home, key, focus, numeric) \
+       do_call(key, focus, numeric, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, home)
+#define call_home3(home, key, focus) \
+       do_call(key, focus, 0, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, home)
 
 
 static inline int do_call(char *key safe, struct pane *focus safe, int numeric, struct mark *m,
@@ -492,50 +515,6 @@ static inline int do_call(char *key safe, struct pane *focus safe, int numeric,
        return key_handle(&ci);
 }
 
-static inline int call_home7(struct pane *home safe, char *key safe, struct pane *focus safe,
-                            int numeric, struct mark *m, char *str, int extra, char *str2, struct mark *m2, struct command *comm)
-{
-       struct cmd_info ci = {.key=key, .focus=focus, .home=home, .comm = safe_cast 0};
-
-       ci.numeric = numeric;
-       ci.mark = m;
-       ci.str = str;
-       ci.extra = extra;
-       ci.str2 = str2;
-       ci.mark2 = m2;
-       ci.comm2 = comm;
-       return key_handle(&ci);
-}
-
-static inline int call_home9(struct pane *home safe, char *key safe, struct pane *focus safe,
-                            int numeric, struct mark *m, char *str, int extra, char *str2, struct mark *m2, struct command *comm, int x, int y)
-{
-       struct cmd_info ci = {.key=key, .focus=focus, .home=home, .comm = safe_cast 0};
-
-       ci.numeric = numeric;
-       ci.mark = m;
-       ci.str = str;
-       ci.extra = extra;
-       ci.str2 = str2;
-       ci.mark2 = m2;
-       ci.comm2 = comm;
-       ci.x = x;
-       ci.y = y;
-       return key_handle(&ci);
-}
-
-static inline int call_home(struct pane *home safe, char *key safe, struct pane *focus safe,
-                           int numeric, struct mark *m, struct command *comm)
-{
-       struct cmd_info ci = {.key=key, .focus=focus, .home=home, .comm = safe_cast 0};
-
-       ci.numeric = numeric;
-       ci.mark = m;
-       ci.comm2 = comm;
-       return key_handle(&ci);
-}
-
-
 static inline int call_xy(char *key safe, struct pane *focus safe, int numeric,
                          char *str, char *str2, int x, int y)
 {
index 65d47d2b68995ff6a6d4f44a56d0c493d88402db..4d9b3027c386a77987a56005c5c23b7e7bb4df6f 100644 (file)
@@ -226,8 +226,8 @@ static struct pane *ncurses_init(struct pane *ed)
 
        getmaxyx(stdscr, p->h, p->w);
 
-       call_home(p, "event:read", p, 0, NULL, &input_handle);
-       call_home(p, "event:signal", p, SIGWINCH, NULL, &handle_winch);
+       call_home(p, "event:read", p, 0, NULL, NULL, 0, NULL, NULL, &input_handle);
+       call_home(p, "event:signal", p, SIGWINCH, NULL, NULL, 0, NULL, NULL, &handle_winch);
        pane_damaged(p, DAMAGED_SIZE);
        return p;
 }
index ec3f2e565bb350c7b70c4b49fafd8df3867ca8b0..9034d13b59b9dfd74fd9d5da6dd05c5a8673e3ec 100644 (file)
@@ -108,7 +108,7 @@ static void doc_save(struct pane *p safe, struct pane *focus safe)
                call("Message", focus, 0, NULL,
                     "File not modified - no need to save.");
        else
-               call_home(p, "doc:save-file", focus, 0, NULL, NULL);
+               call_home(p, "doc:save-file", focus);
 }
 
 static void check_name(struct docs *docs safe, struct pane *pane safe)
@@ -388,10 +388,8 @@ DEF_CMD(docs_callback)
                if (p == doc->doc.home)
                        /* The docs doc is attached separately */
                        return 0;
-               call_home(p, "doc:set-parent", doc->collection,
-                         0, NULL, NULL);
-               call_home(p, "Request:Notify:doc:status-changed", doc->collection,
-                         0, NULL, NULL);
+               call_home(p, "doc:set-parent", doc->collection);
+               call_home(p, "Request:Notify:doc:status-changed", doc->collection);
                if (p->parent)
                        doc_checkname(p, doc, ci->numeric);
                return 0;
@@ -838,8 +836,7 @@ DEF_CMD(attach_docs)
        call_comm("global-set-command", ci->home, 0, NULL,
                  "doc:appeared-docs-register", 0, &doc->callback);
 
-       call_home(p, "doc:set-parent", doc->collection,
-                 0, NULL, NULL);
+       call_home(p, "doc:set-parent", doc->collection);
 
        return comm_call(ci->comm2, "callback:doc", doc->doc.home, 0, NULL, NULL, 0);
 }
index 02b6462f0aaba498632ce45958dd9ee31447f997..703046639f915f1b3b97b5bb269b595a746d1889 100644 (file)
@@ -364,8 +364,8 @@ static int handle_text_plain(struct pane *p safe, char *type, char *xfer,
        else
                attr_set_str(&h->attrs, "email:actions", "hide:open");
 
-       call_home(mp, "multipart-add", h, hidden, NULL, NULL);
-       call_home(mp, "multipart-add", spacer, 0, NULL, NULL);
+       call_home(mp, "multipart-add", h, hidden);
+       call_home(mp, "multipart-add", spacer, 0);
        return 1;
 }
 
@@ -467,10 +467,10 @@ static int handle_multipart(struct pane *p safe, char *type safe,
 
                if (!hdr)
                        break;
-               call_home7(hdr, "get-header", hdr, 0, NULL, "content-type",
-                          0, "cmd", NULL, NULL);
-               call_home7(hdr, "get-header", hdr, 0, NULL, "content-transfer-encoding",
-                          0, "cmd", NULL, NULL);
+               call_home(hdr, "get-header", hdr, 0, NULL, "content-type",
+                         0, NULL, "cmd");
+               call_home(hdr, "get-header", hdr, 0, NULL, "content-transfer-encoding",
+                         0, NULL, "cmd");
                ptype = attr_find(hdr->attrs, "rfc822-content-type");
                pxfer = attr_find(hdr->attrs, "rfc822-content-transfer-encoding");
 
@@ -561,15 +561,15 @@ DEF_CMD(open_email)
        point = vmark_new(doc, MARK_POINT);
        if (!point)
                goto out;
-       call_home7(h2, "get-header", doc, 0, point, "From", 0, NULL, NULL, NULL);
-       call_home7(h2, "get-header", doc, 0, point, "Date", 0, NULL, NULL, NULL);
-       call_home7(h2, "get-header", doc, 0, point, "Subject", 0, "text", NULL, NULL);
-       call_home7(h2, "get-header", doc, 0, point, "To", 0, "list", NULL, NULL);
-       call_home7(h2, "get-header", doc, 0, point, "Cc", 0, "list", NULL, NULL);
-
-       call_home7(h2, "get-header", h2, 0, NULL, "MIME-Version", 0, "cmd", NULL, NULL);
-       call_home7(h2, "get-header", h2, 0, NULL, "content-type", 0, "cmd", NULL, NULL);
-       call_home7(h2, "get-header", h2, 0, NULL, "content-transfer-encoding", 0, "cmd", NULL, NULL);
+       call_home(h2, "get-header", doc, 0, point, "From");
+       call_home(h2, "get-header", doc, 0, point, "Date");
+       call_home(h2, "get-header", doc, 0, point, "Subject", 0, NULL, "text");
+       call_home(h2, "get-header", doc, 0, point, "To", 0, NULL, "list");
+       call_home(h2, "get-header", doc, 0, point, "Cc", 0, NULL, "list");
+
+       call_home(h2, "get-header", h2, 0, NULL, "MIME-Version", 0, NULL, "cmd");
+       call_home(h2, "get-header", h2, 0, NULL, "content-type", 0, NULL, "cmd");
+       call_home(h2, "get-header", h2, 0, NULL, "content-transfer-encoding", 0, NULL, "cmd");
        mime = attr_find(h2->attrs, "rfc822-mime-version");
        if (mime)
                mime = get_822_word(mime);
@@ -583,8 +583,8 @@ DEF_CMD(open_email)
        if (!p)
                goto out;
        attr_set_str(&doc->attrs, "email:actions", "hide");
-       call_home(p, "multipart-add", doc, 0, NULL, NULL);
-       call_home(p, "multipart-add", ei->spacer, 0, NULL, NULL);
+       call_home(p, "multipart-add", doc);
+       call_home(p, "multipart-add", ei->spacer);
        call("doc:set:autoclose", doc, 1, NULL, NULL, 0);
 
        if (handle_content(ei->email, type, xfer, start, end, p, ei->spacer, 0) == 0)
index 3bd2581355a0312018acf9fb022bb4507f3241e2..d7c81ccda301443d21748f15c3e58ae904a635db 100644 (file)
@@ -221,9 +221,9 @@ DEF_CMD(mp_same)
                         * Assume part is not empty...
                         */
                        return 2;
-               return call_home7(mpi->parts[ci->mark->ref.docnum].pane,
-                                 "doc:mark-same", ci->focus, 0, d1.m, NULL,
-                                 0, NULL, d2.m, NULL);
+               return call_home(mpi->parts[ci->mark->ref.docnum].pane,
+                                "doc:mark-same", ci->focus, 0, d1.m, NULL,
+                                0, d2.m);
        }
 
        /* Marks are in different visible documents.
@@ -257,9 +257,9 @@ DEF_CMD(mp_step)
            !mpi->parts[m->ref.docnum].visible)
                ret = -1;
        else
-               ret = call_home7(mpi->parts[m->ref.docnum].pane,
-                                ci->key, ci->focus, ci->numeric, m1, ci->str,
-                                ci->extra,ci->str2, NULL, ci->comm2);
+               ret = call_home(mpi->parts[m->ref.docnum].pane,
+                               ci->key, ci->focus, ci->numeric, m1, ci->str,
+                               ci->extra, NULL, ci->str2, ci->comm2);
        while (ret == CHAR_RET(WEOF) || ret == -1) {
                if (!ci->extra && m == ci->mark) {
                        /* don't change ci->mark when not moving */
@@ -285,9 +285,9 @@ DEF_CMD(mp_step)
                    !mpi->parts[m->ref.docnum].visible)
                        ret = -1;
                else
-                       ret = call_home7(mpi->parts[m->ref.docnum].pane,
-                                        ci->key, ci->focus, ci->numeric, m1, ci->str,
-                                        ci->extra,ci->str2, NULL, ci->comm2);
+                       ret = call_home(mpi->parts[m->ref.docnum].pane,
+                                       ci->key, ci->focus, ci->numeric, m1, ci->str,
+                                       ci->extra, NULL, ci->str2, ci->comm2);
        }
        if (ci->extra)
                reset_mark(ci->mark);
@@ -369,9 +369,9 @@ DEF_CMD(mp_attr)
                      (d > ci->mark->ref.docnum), m1);
        }
 
-       ret = call_home7(mpi->parts[d].pane,
-                        ci->key, ci->focus, ci->numeric, m1, ci->str,
-                        ci->extra,ci->str2, NULL, ci->comm2);
+       ret = call_home(mpi->parts[d].pane,
+                       ci->key, ci->focus, ci->numeric, m1, ci->str,
+                       ci->extra, NULL, ci->str2, ci->comm2);
        if (d != ci->mark->ref.docnum)
                mark_free(m1);
        return ret;
@@ -480,7 +480,7 @@ DEF_CMD(mp_add)
                change_part(mpi, ci->mark, n, 0);
 
        pane_add_notify(ci->home, ci->focus, "Notify:Close");
-       call_home(ci->focus, "Request:Notify:doc:viewers", ci->home, 0, NULL, NULL);
+       call_home(ci->focus, "Request:Notify:doc:viewers", ci->home);
 
        return 1;
 }
index 7d2b826b2e6d0c422a9c5df44b96769a9863d81e..e1f7700757a1c37ec4cfbc8599a3c7397ca2a9f0 100644 (file)
@@ -70,11 +70,11 @@ DEF_CMD(crop_handle)
                return 0;
 
        if (strcmp(ci->key, "doc:write-file") == 0)
-               return call_home7(p, ci->key, ci->focus, ci->numeric,
-                                 ci->mark ?: cd->start,
-                                 ci->str, ci->extra, ci->str2,
-                                 ci->mark2 ?: cd->end,
-                                 ci->comm2);
+               return call_home(p, ci->key, ci->focus, ci->numeric,
+                                ci->mark ?: cd->start,
+                                ci->str, ci->extra,
+                                ci->mark2 ?: cd->end, ci->str2,
+                                ci->comm2);
 
        if (!ci->mark && !ci->mark2)
                /* No mark, do give it straight to parent */
index 648712428fc10f3a9094b0c6761c568efda6750b..9e8c759b05d1e00603b53432d914543dd1bb27cf 100644 (file)
@@ -256,9 +256,8 @@ DEF_CMD(count_lines)
                cli = calloc(1, sizeof(*cli));
                cli->view_num = doc_add_view(ci->focus);
                p = pane_register(NULL, 0, &handle_count_lines, cli, NULL);
-               call_home(ci->focus, "Request:Notify:doc:Replace", p, 0, NULL, NULL);
-               call_home(ci->focus, "Request:Notify:doc:CountLines", p,
-                         0, NULL, NULL);
+               call_home(ci->focus, "Request:Notify:doc:Replace", p);
+               call_home(ci->focus, "Request:Notify:doc:CountLines", p);
                call("Notify:doc:CountLines", ci->focus, 1, ci->mark);
        }
        if (ci->mark)
index 42f90ad85481ed28561ae537cfefd85a8f1a7014..f22c0c12b69fce8d7243f44852a9da3689af7139 100644 (file)
@@ -730,7 +730,7 @@ DEF_CMD(emacs_shell)
        p = call_pane("doc:attach", doc, 0, NULL, 0);
        if (!p)
                return -1;
-       call_home(p, "doc:assign", doc, 0, NULL, NULL);
+       call_home(p, "doc:assign", doc);
        call_pane7("attach-shellcmd", p, 0, NULL, 0, ci->str, NULL);
        doc_attach_view(par, doc, "default:viewer");
        return 1;
index af013fac2e51ea6bf851b5c99a78a0a26b03e4e2..7e86dfd0a1abc72c220d4c85cb53c219d25646bd 100644 (file)
@@ -1143,7 +1143,7 @@ restart:
                if (call("Draw:image", focus, 1, NULL, s+6, 0) <= 0)
                        pane_clear(p, NULL);
        } else if (strncmp(s, "call:", 5) == 0) {
-               if (call_home(focus, s+5, p, 0, m, NULL) <= 0)
+               if (call_home(focus, s+5, p, 0, m) <= 0)
                        pane_clear(p, NULL);
        } else
                pane_clear(p, NULL);