]> git.neil.brown.name Git - edlib.git/commitdiff
Store command in cmd_info
authorNeilBrown <neil@brown.name>
Sun, 15 Nov 2015 22:55:30 +0000 (09:55 +1100)
committerNeilBrown <neil@brown.name>
Sun, 15 Nov 2015 22:55:30 +0000 (09:55 +1100)
This allows us to repeat a command several times without repeating the
lookup sequence every time.  This (hopefullys) makes sense for using
commands for drawing on a display.

Signed-off-by: NeilBrown <neil@brown.name>
19 files changed:
core-doc.c
core-keymap.c
core-mark.c
core-pane.c
core.h
display-ncurses.c
doc-dir.c
doc-text.c
emacs-search.c
lib-keymap.c
lib-line-count.c
lib-popup.c
lib-search.c
lib-tile.c
lib-view.c
mode-emacs.c
render-dir.c
render-hex.c
render-text.c

index dfec20103a3d46aa269bd35bfaecd719cb5b2280..4997c010bf9e646ad6fee74931cbfb661e14ee35 100644 (file)
@@ -105,7 +105,8 @@ void doc_close_views(struct doc *d)
                ci.pointp = &ptp;
                pt.doc = d;
                c = d->views[i].notify;
-               c->func(c, &ci);
+               ci.comm = c;
+               c->func(&ci);
        }
 }
 
@@ -361,7 +362,7 @@ static struct doc_operations docs_ops = {
        .set_attr  = docs_set_attr,
 };
 
-static int docs_open(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_open)
 {
        struct pane *p = ci->home;
        struct point *pt;
@@ -384,7 +385,6 @@ static int docs_open(struct command *c, struct cmd_info *ci)
                return 0;
        }
 }
-DEF_CMD(comm_open, docs_open);
 
 void doc_make_docs(struct editor *ed)
 {
index e4d32ed1b41a55a4ab30292465c38fa5ae93eee7..39792a08af308466693e85599c221b5160859ea8 100644 (file)
@@ -235,9 +235,9 @@ struct modmap {
        struct command comm;
 };
 
-static int key_prefix(struct command *comm, struct cmd_info *ci)
+static int key_prefix(struct cmd_info *ci)
 {
-       struct modmap *m = container_of(comm, struct modmap, comm);
+       struct modmap *m = container_of(ci->comm, struct modmap, comm);
 
        pane_set_mode(ci->home, m->name, m->transient);
        return 1;
@@ -284,7 +284,8 @@ int key_lookup(struct map *m, struct cmd_info *ci)
                comm = GETCOMM(m->comms[pos-1]);
        } else
                return 0;
-       return comm->func(comm, ci);
+       ci->comm = comm;
+       return comm->func(ci);
 }
 
 int key_handle(struct cmd_info *ci)
@@ -292,12 +293,16 @@ int key_handle(struct cmd_info *ci)
        struct pane *p = ci->focus;
        int ret = 0;
 
+       if (ci->comm)
+               return ci->comm->func(ci);
+
        if (!ci->pointp)
                ci->pointp = pane_point(p);
        while (ret == 0 && p) {
                if (p->handle) {
                        ci->home = p;
-                       ret = p->handle->func(p->handle, ci);
+                       ci->comm = p->handle;
+                       ret = p->handle->func(ci);
                }
                if (ret)
                        /* 'p' might have been destroyed */
@@ -323,6 +328,7 @@ int key_handle_focus(struct cmd_info *ci)
                p = p->focus;
        }
        ci->focus = p;
+       ci->comm = NULL;
        return key_handle(ci);
 }
 
@@ -357,5 +363,6 @@ int key_handle_xy(struct cmd_info *ci)
        ci->x = x;
        ci->y = y;
        ci->focus = p;
+       ci->comm = NULL;
        return key_handle(ci);
 }
index 9f7b1af2336ebc9d6d487af555d77bbb512ed7d6..f2907f71b36dc86e2fed65df73b54d5f1e36acb2 100644 (file)
@@ -659,13 +659,14 @@ void point_notify_change(struct point *p, struct mark *m)
 
                if (!c)
                        continue;
+               ci.comm = c;
                while (TLIST_TYPE(tl) == GRP_LIST)
                        tl = TLIST_PTR(tl->prev);
                if (TLIST_TYPE(tl) == GRP_MARK)
                        ci.mark = tlist_entry(tl, struct mark, view);
                else
                        ci.mark = NULL;
-               c->func(c, &ci);
+               c->func(&ci);
                while (TLIST_TYPE(tl) == GRP_MARK &&
                       (mark_ordered(m, ci.mark) || mark_same(d, m, ci.mark))) {
                        do
@@ -674,7 +675,7 @@ void point_notify_change(struct point *p, struct mark *m)
 
                        if (TLIST_TYPE(tl) == GRP_MARK) {
                                ci.mark = tlist_entry(tl, struct mark, view);
-                               c->func(c, &ci);
+                               c->func(&ci);
                        }
                }
 
@@ -684,7 +685,7 @@ void point_notify_change(struct point *p, struct mark *m)
                        if (TLIST_TYPE(tl) == GRP_MARK) {
                                ci.mark = tlist_entry(tl, struct mark, view);
                                if (mark_same(d, ci.mark, mark_of_point(p)))
-                                       c->func(c, &ci);
+                                       c->func(&ci);
                                else
                                        break;
                        }
@@ -727,7 +728,8 @@ void doc_notify_change(struct doc *d, struct mark *m)
                                        ci.mark = tlist_entry(tl, struct mark, view);
                                else
                                        ci.mark = NULL;
-                               c->func(c, &ci);
+                               ci.comm = c;
+                               c->func(&ci);
                        }
                        break;
                }
@@ -739,7 +741,8 @@ void doc_notify_change(struct doc *d, struct mark *m)
                        remaining -= 1;
                        if (c) {
                                ci.mark = m;
-                               c->func(c, &ci);
+                               ci.comm = c;
+                               c->func(&ci);
                        }
                }
                if (m->all.pprev == &d->marks.first)
index b4917d151fe8f3e04435f82995470031b7bfc5a0..e28598b3b6631ff69b0bf590dfbf39f66ef69864 100644 (file)
@@ -107,7 +107,8 @@ static void __pane_refresh(struct cmd_info *ci)
                if (ci->extra & DAMAGED_CONTENT)
                        ci->extra |= DAMAGED_CURSOR;
                damage &= DAMAGED_SIZE;
-               if (p->handle->func(p->handle, ci))
+               ci->comm = p->handle;
+               if (p->handle->func(ci))
                        damage |= ci->extra;
        }
        p->damaged = 0;
@@ -147,7 +148,8 @@ void pane_close(struct pane *p)
                ci.key = "Close";
                ci.focus = ci.home = p;
                ci.pointp = pane_point(p);
-               p->handle->func(p->handle, &ci);
+               ci.comm = p->handle;
+               p->handle->func(&ci);
        }
        pane_damaged(p->parent, DAMAGED_SIZE);
        attr_free(&p->attrs);
@@ -169,8 +171,9 @@ int pane_clone(struct pane *from, struct pane *parent)
        ci.key = "Clone";
        ci.focus = parent;
        ci.home = from;
+       ci.comm = from->handle;
        if (from->handle)
-               return from->handle->func(from->handle, &ci);
+               return from->handle->func(&ci);
        return 0;
 }
 
diff --git a/core.h b/core.h
index 3a518630b4014b43f1a7b4584f521e3a76d5e279..41030cf15d420d4601919ae6874b8024bebc22c3 100644 (file)
--- a/core.h
+++ b/core.h
@@ -206,11 +206,17 @@ void attr_free(struct attrset **setp);
 
 /* Commands */
 struct command {
-       int     (*func)(struct command *comm, struct cmd_info *ci);
+       int     (*func)(struct cmd_info *ci);
 };
 
-#define        CMD(func) {func}
-#define        DEF_CMD(comm, func) static struct command comm = CMD(func)
+#define CMD(_name) {_name ## _func }
+#define DEF_CMD(_name) \
+       static int _name ## _func(struct cmd_info *ci); \
+       static struct command _name = CMD(_name);       \
+       static int _name ## _func(struct cmd_info *ci)
+#define REDEF_CMD(_name) \
+       static int _name ## _func(struct cmd_info *ci)
+
 #define        ARRAY_SIZE(ra) (sizeof(ra) / sizeof(ra[0]))
 
 /* Each event (above) is accompanied by a cmd_info structure.
@@ -230,6 +236,7 @@ struct cmd_info {
        char            *str, *str2;
        struct mark     *mark;
        struct point    **pointp;
+       struct command  *comm;
 };
 #define        NO_NUMERIC      (INT_MAX/2)
 #define        RPT_NUM(ci)     ((ci)->numeric == NO_NUMERIC ? 1 : (ci)->numeric)
index 4385f3b65ddbe9c95093f5a1e495acb644110881..580ff429aae97e02d7bbcfe9b50b3d1779b5f899 100644 (file)
@@ -70,7 +70,7 @@ static void ncurses_flush(int fd, short ev, void *P)
        refresh();
 }
 
-static int nc_misc(struct command *c, struct cmd_info *ci)
+DEF_CMD(nc_misc)
 {
        struct pane *p = ci->home;
        struct display_data *dd = p->data;
@@ -127,7 +127,7 @@ static int cvt_attrs(char *attrs)
        return attr;
 }
 
-static int do_ncurses_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(ncurses_handle)
 {
        struct pane *p = ci->home;
        int damage = ci->extra;
@@ -136,7 +136,7 @@ static int do_ncurses_handle(struct command *c, struct cmd_info *ci)
        struct timeval tv;
 
        if (strcmp(ci->key, "Misc") == 0)
-               return nc_misc(c, ci);
+               return nc_misc.func(ci);
 
        if (strcmp(ci->key, "Close") == 0) {
                ncurses_end();
@@ -169,7 +169,6 @@ static int do_ncurses_handle(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(ncurses_handle, do_ncurses_handle);
 
 static void handle_winch(int sig, short ev, void *null);
 static struct pane *ncurses_init(struct editor *ed)
@@ -417,13 +416,12 @@ static void input_handle(int fd, short ev, void *P)
        pane_refresh(p);
 }
 
-static int display_ncurses(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_ncurses)
 {
        struct pane *p = ncurses_init(pane2ed(ci->home));
        ci->focus = p;
        return 1;
 }
-DEF_CMD(comm_ncurses, display_ncurses);
 
 void edlib_init(struct editor *ed)
 {
index 15ca87dd1745c41cdf4fe6e6b20336eaac04f918..ab3660c450005e4f264a46c95740a097c53f5a3e 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -112,7 +112,7 @@ static void load_dir(struct list_head *lst, int fd)
        closedir(dir);
 }
 
-static int dir_new(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_new)
 {
        struct directory *dr = malloc(sizeof(*dr));
        doc_init(&dr->doc);
@@ -124,7 +124,6 @@ static int dir_new(struct command *c, struct cmd_info *ci)
        point_new(&dr->doc, ci->pointp);
        return 1;
 }
-DEF_CMD(comm_new, dir_new);
 
 static void dir_replace(struct point *pos, struct mark *end,
                         char *str, bool *first)
@@ -423,7 +422,7 @@ static struct doc_operations dir_ops = {
        .destroy   = dir_destroy,
 };
 
-static int doc_dir_open(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_open)
 {
        struct pane *p = ci->home;
        struct point *pt = p->point;
@@ -449,7 +448,6 @@ static int doc_dir_open(struct command *c, struct cmd_info *ci)
        pane_focus(p);
        return 1;
 }
-DEF_CMD(comm_open, doc_dir_open);
 
 void edlib_init(struct editor *ed)
 {
index 4614525a41f613d2bf1e90f95e33a9a3297c0947..99d4cd41bb6e52640bc00ef8d45202ac63e05017 100644 (file)
@@ -931,7 +931,7 @@ static int text_sameref(struct doc *d, struct mark *a, struct mark *b)
        return text_ref_same(t, &a->ref, &b->ref);
 }
 
-static int text_new(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_new)
 {
        struct text *t = malloc(sizeof(*t));
        t->alloc = NULL;
@@ -945,7 +945,6 @@ static int text_new(struct command *c, struct cmd_info *ci)
        point_new(&t->doc, ci->pointp);
        return 1;
 }
-DEF_CMD(comm_new, text_new);
 
 static int count_bytes(struct text *t, struct mark *from, struct mark *to)
 {
index b116d35cc832fd2ef7d9e66f921f89c03faf4b68..98c98149d1c39b123f9875a4319e231f6e348d17 100644 (file)
@@ -37,8 +37,9 @@ struct es_info {
 
 static struct map *es_map;
 
-static int do_search_again(struct command *c, struct cmd_info *ci);
-static int do_search_forward(struct command *c, struct cmd_info *ci)
+static int do_search_again(struct cmd_info *ci);
+
+DEF_CMD(search_forward)
 {
        struct es_info *esi = ci->home->data;
        struct doc *d = esi->end->doc;
@@ -65,9 +66,8 @@ static int do_search_forward(struct command *c, struct cmd_info *ci)
        point_notify_change(*ci->pointp, NULL);
        return 1;
 }
-DEF_CMD(search_forward, do_search_forward);
 
-static int do_search_retreat(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_retreat)
 {
        struct es_info *esi = ci->home->data;
        char *str;
@@ -88,9 +88,8 @@ static int do_search_retreat(struct command *c, struct cmd_info *ci)
        point_notify_change(*ci->pointp, NULL);
        return 1;
 }
-DEF_CMD(search_retreat, do_search_retreat);
 
-static int do_search_add(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_add)
 {
        struct es_info *esi = ci->home->data;
        struct doc *d = esi->end->doc;
@@ -125,22 +124,19 @@ static int do_search_add(struct command *c, struct cmd_info *ci)
        } while (strcmp(ci->key, "C-Chr-C") != 0 && wch != ' ');
        return 1;
 }
-DEF_CMD(search_add, do_search_add);
 
-static int do_search_backward(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_backward)
 {
        return 1;
 }
-DEF_CMD(search_backward, do_search_backward);
 
-static int do_search_refresh(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_refresh)
 {
        pane_check_size(ci->focus);
        return 1;
 }
-DEF_CMD(search_refresh, do_search_refresh);
 
-static int do_search_close(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_close)
 {
        struct es_info *esi = ci->focus->data;
 
@@ -157,12 +153,11 @@ static int do_search_close(struct command *c, struct cmd_info *ci)
        }
        return 1;
 }
-DEF_CMD(search_close, do_search_close);
 
-static int do_search_again(struct command *c, struct cmd_info *ci)
+static int do_search_again(struct cmd_info *ci)
 {
        /* document has changed, retry search */
-       struct es_info *esi = container_of(c, struct es_info, watch);
+       struct es_info *esi = container_of(ci->comm, struct es_info, watch);
        struct cmd_info ci2 = {0};
        struct doc *d = esi->end->doc;
        struct pane *p;
@@ -173,7 +168,7 @@ static int do_search_again(struct command *c, struct cmd_info *ci)
                struct doc *d = (*ci->pointp)->doc;
 
                /* No marks to remove */
-               doc_del_view(d, c);
+               doc_del_view(d, ci->comm);
                return 0;
        }
 
@@ -226,13 +221,12 @@ static void emacs_search_init_map(void)
        key_add(es_map, "Close", &search_close);
 }
 
-static int do_search_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_handle)
 {
        return key_lookup(es_map, ci);
 }
-DEF_CMD(search_handle, do_search_handle);
 
-static int emacs_search(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_search)
 {
        struct pane *p;
        struct es_info *esi;
@@ -268,9 +262,8 @@ static int emacs_search(struct command *c, struct cmd_info *ci)
        ci->home = p;
        return 1;
 }
-DEF_CMD(comm_emacs_search, emacs_search);
 
 void emacs_search_init(struct editor *ed)
 {
-       key_add(ed->commands, "attach-emacs-search", &comm_emacs_search);
+       key_add(ed->commands, "attach-emacs-search", &emacs_search);
 }
index 01b65ca6d8dc61a5a9971ce06c58d48e27d2715c..0b637bd15045ed50a6c710a478dd0473f645346f 100644 (file)
@@ -33,9 +33,9 @@ struct key_data {
        int             global;
 };
 
-static int keymap_attach(struct command *c, struct cmd_info *ci);
+static int keymap_attach_func(struct cmd_info *ci);
 
-static int key_do_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(keymap_handle)
 {
        struct key_data *kd = ci->home->data;
        int i;
@@ -71,7 +71,7 @@ static int key_do_handle(struct command *c, struct cmd_info *ci)
                        struct pane *p = ci->focus;
                        struct cmd_info ci2 = {0};
                        ci2.focus = p;
-                       keymap_attach(NULL, &ci2);
+                       keymap_attach_func(&ci2);
                        pane_attach(p, "local-keymap", NULL, NULL);
                        return key_handle_focus(ci);
                }
@@ -113,16 +113,17 @@ static int key_do_handle(struct command *c, struct cmd_info *ci)
        }
 
        for (i = 0; i < kd->cmdcount; i++) {
-               int ret = kd->cmds[i]->func(kd->cmds[i], ci);
+               int ret;
+               ci->comm = kd->cmds[i];
+               ret = kd->cmds[i]->func(ci);
                if (ret)
                        return ret;
        }
 
        return key_lookup(kd->map, ci);
 }
-DEF_CMD(key_handle, key_do_handle);
 
-static int keymap_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(keymap_attach)
 {
        struct key_data *kd = malloc(sizeof(*kd));
        struct pane *p;
@@ -131,18 +132,17 @@ static int keymap_attach(struct command *c, struct cmd_info *ci)
        kd->cmds = NULL;
        kd->globalcmd = NULL;
        kd->cmdcount = 0;
-       kd->global = c ? 1 : 0;
+       kd->global = ci->comm ? 1 : 0;
        p = ci->focus;
        while (pane_child(p))
                p = pane_child(p);
-       p = pane_register(p, 0, &key_handle, kd, NULL);
+       p = pane_register(p, 0, &keymap_handle, kd, NULL);
        pane_check_size(p);
        ci->home = p;
        return 1;
 }
-DEF_CMD(comm_attach, keymap_attach);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "attach-global-keymap", &comm_attach);
+       key_add(ed->commands, "attach-global-keymap", &keymap_attach);
 }
index ab5708f8b3327bdaa8db7efdd08dd61c56465933..ac8d06e4db67dd4e82840599452e3c4eb0b560c4 100644 (file)
@@ -79,7 +79,7 @@ static void do_count(struct doc *d, struct mark *start, struct mark *end,
        mark_free(m);
 }
 
-static int count_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(count_notify)
 {
        if (strcmp(ci->key, "Replace") == 0) {
                if (ci->mark != NULL) {
@@ -92,16 +92,15 @@ static int count_notify(struct command *c, struct cmd_info *ci)
        if (strcmp(ci->key, "Release") == 0) {
                struct doc *d = (*ci->pointp)->doc;
                struct mark *m;
-               int i = doc_find_view(d, c);
+               int i = doc_find_view(d, ci->comm);
                if (i < 0)
                        return 0;
                while ((m = doc_first_mark(d, i)) != NULL)
                        mark_free(m);
-               doc_del_view(d, c);
+               doc_del_view(d, ci->comm);
        }
        return 0;
 }
-static struct command count_cmd = {count_notify};
 
 static int need_recalc(struct doc *d, struct mark *m)
 {
@@ -127,13 +126,13 @@ static int need_recalc(struct doc *d, struct mark *m)
 
 static void count_calculate(struct doc *d, struct mark *start, struct mark *end)
 {
-       int type = doc_find_view(d, &count_cmd);
+       int type = doc_find_view(d, &count_notify);
        int lines, words, chars, l, w, c;
        struct mark *m, *m2;
        struct attrset **attrs;
 
        if (type < 0)
-               type = doc_add_view(d, &count_cmd);
+               type = doc_add_view(d, &count_notify);
 
        m = doc_first_mark(d, type);
        if (m == NULL) {
@@ -218,7 +217,7 @@ done:
        attr_set_int(attrs, "chars", chars);
 }
 
-static int do_count_lines(struct command *c, struct cmd_info *ci)
+DEF_CMD(count_lines)
 {
        struct point *pt = *ci->pointp;
        struct doc *d = pt->doc;
@@ -230,9 +229,8 @@ static int do_count_lines(struct command *c, struct cmd_info *ci)
                count_calculate(d, NULL, ci->mark);
        return 1;
 }
-DEF_CMD(comm_count, do_count_lines);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "CountLines", &comm_count);
+       key_add(ed->commands, "CountLines", &count_lines);
 }
index d98d105db3646d7e82f1fc243264c157a493cf24..ef499e3e821cb361a79811fb2ac5f95650c7ce36 100644 (file)
@@ -57,7 +57,7 @@ static void popup_resize(struct pane *p, char *style)
        pane_resize(p, x, y, w, h);
 }
 
-static int do_popup_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(popup_handle)
 {
        struct pane *p = ci->home;
        struct popup_info *ppi = p->data;
@@ -103,9 +103,8 @@ static int do_popup_handle(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(popup_handle, do_popup_handle);
 
-static int popup_quote(struct command *c, struct cmd_info *ci)
+DEF_CMD(popup_quote)
 {
        struct cmd_info ci2 = *ci;
 
@@ -115,9 +114,8 @@ static int popup_quote(struct command *c, struct cmd_info *ci)
                ci2.key = "popup:Abort";
        return key_handle_focus(&ci2);
 }
-DEF_CMD(comm_quote, popup_quote);
 
-static int popup_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(popup_attach)
 {
        /* attach a popup.  It can be attach to the view or the display,
         * can be in a corner, in a side, or central, and be 1 line or
@@ -182,10 +180,9 @@ static int popup_attach(struct command *c, struct cmd_info *ci)
        ci->home = p;
        return 1;
 }
-DEF_CMD(comm_attach, popup_attach);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "attach-popup", &comm_attach);
-       key_add(ed->commands, "popup:quote", &comm_quote);
+       key_add(ed->commands, "attach-popup", &popup_attach);
+       key_add(ed->commands, "popup:quote", &popup_quote);
 }
index 6d63e569ec091993acfee1c633b7d7d12731c7ed..1aa1f2811194b9923a5c440a623129216aad2a78 100644 (file)
@@ -12,7 +12,7 @@
 #include "core.h"
 #include "rexel.h"
 
-static int text_search(struct command *c, struct cmd_info *ci)
+DEF_CMD(text_search)
 {
        struct point *pt;
        struct mark *m;
@@ -50,9 +50,8 @@ static int text_search(struct command *c, struct cmd_info *ci)
        free(rxl);
        return 1;
 }
-DEF_CMD(comm_search, text_search);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "text-search", &comm_search);
+       key_add(ed->commands, "text-search", &text_search);
 }
index aadc4a92ea3cdc6113b54bf35596b44febbdaf05..315b5fcb18008542a699c8b693f34412b1e97b7c 100644 (file)
@@ -49,7 +49,7 @@ static void tile_adjust(struct pane *p);
 static void tile_avail(struct pane *p, struct pane *ignore);
 static int tile_destroy(struct pane *p);
 
-static int do_tile_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_handle)
 {
        struct pane *p = ci->home;
        int damage = ci->extra;
@@ -75,9 +75,8 @@ static int do_tile_handle(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(tile_handle, do_tile_handle);
 
-static int tile_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_attach)
 {
        struct pane *display = ci->focus;
        struct tileinfo *ti = malloc(sizeof(*ti));
@@ -92,7 +91,6 @@ static int tile_attach(struct command *c, struct cmd_info *ci)
        attr_set_str(&p->attrs, "borders", "BL", -1);
        return 1;
 }
-DEF_CMD(comm_attach, tile_attach);
 
 static struct pane *tile_split(struct pane *p, int horiz, int after)
 {
@@ -501,7 +499,7 @@ static int tile_grow(struct pane *p, int horiz, int size)
        return 1;
 }
 
-static int tile_command(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_command)
 {
        struct pane *p = ci->home;
        struct pane *p2;
@@ -550,9 +548,8 @@ static int tile_command(struct command *c, struct cmd_info *ci)
                return 0;
        return 1;
 }
-DEF_CMD(comm_tile, tile_command);
 
-static int tile_other(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_other)
 {
        /* Choose some other tile.  If there aren't any, make one.
         * Result is returned in ci->focus
@@ -574,13 +571,13 @@ static int tile_other(struct command *c, struct cmd_info *ci)
                ci->focus = p2;
        return 1;
 }
-DEF_CMD(comm_other, tile_other);
+
 void edlib_init(struct editor *ed)
 {
        tile_map = key_alloc();
 
-       key_add(tile_map, "WindowOP", &comm_tile);
-       key_add(tile_map, "OtherPane", &comm_other);
+       key_add(tile_map, "WindowOP", &tile_command);
+       key_add(tile_map, "OtherPane", &tile_other);
 
-       key_add(ed->commands, "attach-tile", &comm_attach);
+       key_add(ed->commands, "attach-tile", &tile_attach);
 }
index 16e61d181b8fd69fa8bb43e1683797eedb9b2a8a..1fbed7657731be106de8b3ee70d767b7e47b46fc 100644 (file)
@@ -36,7 +36,7 @@ enum {
 };
 
 static struct map *view_map;
-static struct pane *view_attach(struct pane *par, struct point *pt, int border);
+static struct pane *do_view_attach(struct pane *par, struct point *pt, int border);
 
 static int view_refresh(struct cmd_info *ci)
 {
@@ -121,7 +121,7 @@ static int view_refresh(struct cmd_info *ci)
        return 0;
 }
 
-static int do_view_handle(struct command *cm, struct cmd_info *ci)
+DEF_CMD(view_handle)
 {
        struct pane *p = ci->home;
        struct point *pt;
@@ -152,7 +152,7 @@ static int do_view_handle(struct command *cm, struct cmd_info *ci)
                if (!p->point)
                        return 0;
                point_dup(p->point, &pt);
-               p2 = view_attach(parent, pt, vd->border);
+               p2 = do_view_attach(parent, pt, vd->border);
                c = pane_child(pane_child(p));
                if (c)
                        return pane_clone(c, p2);
@@ -162,9 +162,8 @@ static int do_view_handle(struct command *cm, struct cmd_info *ci)
                return view_refresh(ci);
        return 0;
 }
-DEF_CMD(view_handle, do_view_handle);
 
-static int do_view_null(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_null)
 {
        struct pane *p = ci->home;
        struct view_data *vd = p->data;
@@ -194,13 +193,12 @@ static int do_view_null(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(view_null, do_view_null);
 
 static struct pane *view_reattach(struct pane *p, struct point *pt);
 
-static int view_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_notify)
 {
-       struct view_data *vd = container_of(c, struct view_data, ch_notify);
+       struct view_data *vd = container_of(ci->comm, struct view_data, ch_notify);
 
        if (strcmp(ci->key, "Replace") == 0) {
                pane_damaged(vd->pane, DAMAGED_CONTENT);
@@ -240,7 +238,7 @@ static struct pane *view_reattach(struct pane *par, struct point *pt)
        return p;
 }
 
-static struct pane *view_attach(struct pane *par, struct point *pt, int border)
+static struct pane *do_view_attach(struct pane *par, struct point *pt, int border)
 {
        struct view_data *vd;
        struct pane *p;
@@ -250,7 +248,7 @@ static struct pane *view_attach(struct pane *par, struct point *pt, int border)
 
        vd = malloc(sizeof(*vd));
        vd->border = border;
-       vd->ch_notify.func = view_notify;
+       vd->ch_notify = view_notify;
        pt->owner = &pt;
        p = pane_register(par, 0, &view_handle, vd, NULL);
        vd->pane = p;
@@ -259,7 +257,7 @@ static struct pane *view_attach(struct pane *par, struct point *pt, int border)
        return view_reattach(p, pt);
 }
 
-static int do_view_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_attach)
 {
        int borders = 0;
        char *borderstr = pane_attr_get(ci->focus, "borders");
@@ -270,12 +268,11 @@ static int do_view_attach(struct command *c, struct cmd_info *ci)
        if (strchr(borderstr, 'L')) borders |= BORDER_LEFT;
        if (strchr(borderstr, 'R')) borders |= BORDER_RIGHT;
 
-       ci->home = view_attach(ci->focus, *ci->pointp, borders);
+       ci->home = do_view_attach(ci->focus, *ci->pointp, borders);
        return ci->home != NULL;
 }
-DEF_CMD(comm_attach, do_view_attach);
 
-static int view_char(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_char)
 {
        struct point *pt = *ci->pointp;
        int rpt = RPT_NUM(ci);
@@ -293,9 +290,8 @@ static int view_char(struct command *c, struct cmd_info *ci)
 
        return 1;
 }
-DEF_CMD(comm_char, view_char);
 
-static int view_word(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_word)
 {
        struct point *pt = *ci->pointp;
        int rpt = RPT_NUM(ci);
@@ -332,9 +328,8 @@ static int view_word(struct command *c, struct cmd_info *ci)
 
        return 1;
 }
-DEF_CMD(comm_word, view_word);
 
-static int view_WORD(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_WORD)
 {
        struct point *pt = *ci->pointp;
        int rpt = RPT_NUM(ci);
@@ -362,9 +357,8 @@ static int view_WORD(struct command *c, struct cmd_info *ci)
 
        return 1;
 }
-DEF_CMD(comm_WORD, view_WORD);
 
-static int view_eol(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_eol)
 {
        struct point *pt = *ci->pointp;
        wint_t ch = 1;
@@ -390,9 +384,8 @@ static int view_eol(struct command *c, struct cmd_info *ci)
        }
        return 1;
 }
-DEF_CMD(comm_eol, view_eol);
 
-static int view_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_line)
 {
        struct point *pt = *ci->pointp;
        wint_t ch = 1;
@@ -412,9 +405,8 @@ static int view_line(struct command *c, struct cmd_info *ci)
        }
        return 1;
 }
-DEF_CMD(comm_line, view_line);
 
-static int view_file(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_file)
 {
        struct point *pt = *ci->pointp;
        wint_t ch = 1;
@@ -434,9 +426,8 @@ static int view_file(struct command *c, struct cmd_info *ci)
        }
        return 1;
 }
-DEF_CMD(comm_file, view_file);
 
-static int view_page(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_page)
 {
        struct point *pt = *ci->pointp;
        wint_t ch = 1;
@@ -457,9 +448,8 @@ static int view_page(struct command *c, struct cmd_info *ci)
        }
        return 1;
 }
-DEF_CMD(comm_page, view_page);
 
-static int view_replace(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_replace)
 {
        struct point *pt = *ci->pointp;
        bool first_change = (ci->extra == 0);
@@ -467,9 +457,8 @@ static int view_replace(struct command *c, struct cmd_info *ci)
        doc_replace(pt, ci->mark, ci->str, &first_change);
        return 1;
 }
-DEF_CMD(comm_replace, view_replace);
 
-static int view_click(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_click)
 {
        struct pane *p = ci->home;
        struct view_data *vd = p->data;
@@ -503,24 +492,23 @@ static int view_click(struct command *c, struct cmd_info *ci)
                return 0;
        return key_handle_focus(&ci2);
 }
-DEF_CMD(comm_click, view_click);
 
 void edlib_init(struct editor *ed)
 {
        view_map = key_alloc();
 
-       key_add(view_map, "Move-Char", &comm_char);
-       key_add(view_map, "Move-Word", &comm_word);
-       key_add(view_map, "Move-WORD", &comm_WORD);
-       key_add(view_map, "Move-EOL", &comm_eol);
-       key_add(view_map, "Move-Line", &comm_line);
-       key_add(view_map, "Move-File", &comm_file);
-       key_add(view_map, "Move-View-Large", &comm_page);
+       key_add(view_map, "Move-Char", &view_char);
+       key_add(view_map, "Move-Word", &view_word);
+       key_add(view_map, "Move-WORD", &view_WORD);
+       key_add(view_map, "Move-EOL", &view_eol);
+       key_add(view_map, "Move-Line", &view_line);
+       key_add(view_map, "Move-File", &view_file);
+       key_add(view_map, "Move-View-Large", &view_page);
 
-       key_add(view_map, "Replace", &comm_replace);
+       key_add(view_map, "Replace", &view_replace);
 
-       key_add(view_map, "Click-1", &comm_click);
-       key_add(view_map, "Press-1", &comm_click);
+       key_add(view_map, "Click-1", &view_click);
+       key_add(view_map, "Press-1", &view_click);
 
-       key_add(ed->commands, "attach-view", &comm_attach);
+       key_add(ed->commands, "attach-view", &view_attach);
 }
index 39f55d868a042aaf009a56318b64191b6bb920ac..3424b98010056633387f8c7e75d6dbf146be4a03 100644 (file)
@@ -16,8 +16,8 @@
 
 #include "core.h"
 
-static int emacs_move(struct command *c, struct cmd_info *ci);
-static int emacs_delete(struct command *c, struct cmd_info *ci);
+REDEF_CMD(emacs_move);
+REDEF_CMD(emacs_delete);
 
 static struct move_command {
        struct command  cmd;
@@ -66,9 +66,9 @@ static struct move_command {
         "C-Chr-K", NULL, NULL},
 };
 
-static int emacs_move(struct command *c, struct cmd_info *ci)
+REDEF_CMD(emacs_move)
 {
-       struct move_command *mv = container_of(c, struct move_command, cmd);
+       struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
        struct pane *cursor_pane = pane_with_cursor(ci->home, NULL, NULL);
        struct point *pt = *ci->pointp;
        int old_x = -1;
@@ -110,9 +110,9 @@ static int emacs_move(struct command *c, struct cmd_info *ci)
        return ret;
 }
 
-static int emacs_delete(struct command *c, struct cmd_info *ci)
+REDEF_CMD(emacs_delete)
 {
-       struct move_command *mv = container_of(c, struct move_command, cmd);
+       struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
        struct cmd_info ci2 = {0};
        int ret = 0;
        struct mark *m;
@@ -146,7 +146,7 @@ static int emacs_delete(struct command *c, struct cmd_info *ci)
        return ret;
 }
 
-static int emacs_str(struct command *c, struct cmd_info *ci);
+REDEF_CMD(emacs_str);
 static struct str_command {
        struct command  cmd;
        char            *type;
@@ -170,9 +170,9 @@ static struct str_command {
        {CMD(emacs_str), "NOP", NULL, "emCX4-C-Chr-G"},
 };
 
-static int emacs_str(struct command *c, struct cmd_info *ci)
+REDEF_CMD(emacs_str)
 {
-       struct str_command *sc = container_of(c, struct str_command, cmd);
+       struct str_command *sc = container_of(ci->comm, struct str_command, cmd);
        struct cmd_info ci2;
 
        ci2 = *ci;
@@ -181,7 +181,7 @@ static int emacs_str(struct command *c, struct cmd_info *ci)
        return key_handle_focus(&ci2);
 }
 
-static int emacs_insert(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_insert)
 {
        char str[5];
        struct cmd_info ci2 = {0};
@@ -201,7 +201,6 @@ static int emacs_insert(struct command *c, struct cmd_info *ci)
 
        return ret;
 }
-DEF_CMD(comm_insert, emacs_insert);
 
 static struct {
        char *key;
@@ -213,7 +212,7 @@ static struct {
        {NULL, NULL}
 };
 
-static int emacs_insert_other(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_insert_other)
 {
        struct pane *p = ci->home;
        struct cmd_info ci2 = {0};
@@ -237,25 +236,22 @@ static int emacs_insert_other(struct command *c, struct cmd_info *ci)
        pane_set_extra(p, 0); /* A newline starts a new undo */
        return ret;
 }
-DEF_CMD(comm_insert_other, emacs_insert_other);
 
-static int emacs_undo(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_undo)
 {
        struct point *pt = *ci->pointp;
        doc_undo(pt, 0);
        return 1;
 }
-DEF_CMD(comm_undo, emacs_undo);
 
-static int emacs_redo(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_redo)
 {
        struct point *pt = *ci->pointp;
        doc_undo(pt, 1);
        return 1;
 }
-DEF_CMD(comm_redo, emacs_redo);
 
-static int emacs_findfile(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_findfile)
 {
        int fd;
        struct pane *p, *par;
@@ -333,9 +329,8 @@ static int emacs_findfile(struct command *c, struct cmd_info *ci)
        pane_focus(p);
        return 1;
 }
-DEF_CMD(comm_findfile, emacs_findfile);
 
-static int emacs_finddoc(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_finddoc)
 {
        struct pane *p, *par;
        struct doc *d;
@@ -392,9 +387,8 @@ static int emacs_finddoc(struct command *c, struct cmd_info *ci)
        render_attach(NULL, p);
        return 1;
 }
-DEF_CMD(comm_finddoc, emacs_finddoc);
 
-static int emacs_viewdocs(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_viewdocs)
 {
        struct pane *p, *par;
        struct doc *d;
@@ -421,18 +415,16 @@ static int emacs_viewdocs(struct command *c, struct cmd_info *ci)
        render_attach(NULL, p);
        return 1;
 }
-DEF_CMD(comm_viewdocs, emacs_viewdocs);
 
-static int emacs_meta(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_meta)
 {
        pane_set_mode(ci->home, "M-", 1);
        pane_set_numeric(ci->home, ci->numeric);
        pane_set_extra(ci->home, ci->extra);
        return 1;
 }
-DEF_CMD(comm_meta, emacs_meta);
 
-static int emacs_num(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_num)
 {
        int rpt = RPT_NUM(ci);
        char *last = ci->key + strlen(ci->key)-1;
@@ -444,9 +436,8 @@ static int emacs_num(struct command *c, struct cmd_info *ci)
        pane_set_extra(ci->home, ci->extra);
        return 1;
 }
-DEF_CMD(comm_num, emacs_num);
 
-static int emacs_kill_doc(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_kill_doc)
 {
        struct doc *d;
        if (!ci->pointp)
@@ -456,9 +447,8 @@ static int emacs_kill_doc(struct command *c, struct cmd_info *ci)
        doc_destroy(d);
        return 1;
 }
-DEF_CMD(comm_kill_doc, emacs_kill_doc);
 
-static int emacs_search(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_search)
 {
        struct cmd_info ci2 = {0};
 
@@ -490,7 +480,6 @@ static int emacs_search(struct command *c, struct cmd_info *ci)
        mark_free(ci2.mark);
        return 1;
 }
-DEF_CMD(comm_search, emacs_search);
 
 static struct map *emacs_map;
 
@@ -503,7 +492,7 @@ static void emacs_init(void)
 
        key_add(m, "C-Chr-X", cx_cmd);
        key_add(m, "emCX-Chr-4", cx4_cmd);
-       key_add(m, "ESC", &comm_meta);
+       key_add(m, "ESC", &emacs_meta);
 
        for (i = 0; i < ARRAY_SIZE(move_commands); i++) {
                struct move_command *mc = &move_commands[i];
@@ -519,40 +508,39 @@ static void emacs_init(void)
                key_add(m, sc->k, &sc->cmd);
        }
 
-       key_add_range(m, "Chr- ", "Chr-~", &comm_insert);
-       key_add(m, "Tab", &comm_insert_other);
-       key_add(m, "LF", &comm_insert_other);
-       key_add(m, "Return", &comm_insert_other);
+       key_add_range(m, "Chr- ", "Chr-~", &emacs_insert);
+       key_add(m, "Tab", &emacs_insert_other);
+       key_add(m, "LF", &emacs_insert_other);
+       key_add(m, "Return", &emacs_insert_other);
 
-       key_add(m, "C-Chr-_", &comm_undo);
-       key_add(m, "M-C-Chr-_", &comm_redo);
+       key_add(m, "C-Chr-_", &emacs_undo);
+       key_add(m, "M-C-Chr-_", &emacs_redo);
 
-       key_add(m, "emCX-C-Chr-F", &comm_findfile);
-       key_add(m, "emCX4-C-Chr-F", &comm_findfile);
-       key_add(m, "emCX4-Chr-f", &comm_findfile);
-       key_add(m, "File Found", &comm_findfile);
-       key_add(m, "File Found Other Window", &comm_findfile);
+       key_add(m, "emCX-C-Chr-F", &emacs_findfile);
+       key_add(m, "emCX4-C-Chr-F", &emacs_findfile);
+       key_add(m, "emCX4-Chr-f", &emacs_findfile);
+       key_add(m, "File Found", &emacs_findfile);
+       key_add(m, "File Found Other Window", &emacs_findfile);
 
-       key_add(m, "emCX-Chr-b", &comm_finddoc);
-       key_add(m, "emCX4-Chr-b", &comm_finddoc);
-       key_add(m, "Doc Found", &comm_finddoc);
-       key_add(m, "Doc Found Other Window", &comm_finddoc);
-       key_add(m, "emCX-C-Chr-B", &comm_viewdocs);
+       key_add(m, "emCX-Chr-b", &emacs_finddoc);
+       key_add(m, "emCX4-Chr-b", &emacs_finddoc);
+       key_add(m, "Doc Found", &emacs_finddoc);
+       key_add(m, "Doc Found Other Window", &emacs_finddoc);
+       key_add(m, "emCX-C-Chr-B", &emacs_viewdocs);
 
-       key_add(m, "emCX-Chr-k", &comm_kill_doc);
+       key_add(m, "emCX-Chr-k", &emacs_kill_doc);
 
-       key_add(m, "C-Chr-S", &comm_search);
-       key_add(m, "Search String", &comm_search);
+       key_add(m, "C-Chr-S", &emacs_search);
+       key_add(m, "Search String", &emacs_search);
 
-       key_add_range(m, "M-Chr-0", "M-Chr-9", &comm_num);
+       key_add_range(m, "M-Chr-0", "M-Chr-9", &emacs_num);
        emacs_map = m;
 }
 
-static int do_mode_emacs(struct command *c, struct cmd_info *ci)
+DEF_CMD(mode_emacs)
 {
        return key_lookup(emacs_map, ci);
 }
-DEF_CMD(mode_emacs, do_mode_emacs);
 
 void emacs_search_init(struct editor *ed);
 void edlib_init(struct editor *ed)
index e3c841fa1083ba0bfadfff63a17b3e25e1849fb4..e2088b530973f1272bd01b8389aecd3933bd42dd 100644 (file)
@@ -27,7 +27,7 @@ struct dir_data {
 };
 
 static struct map *dr_map;
-static void render_dir_attach(struct pane *parent, struct point **ptp);
+static void do_render_dir_attach(struct pane *parent, struct point **ptp);
 
 static int put_str(struct pane *p, char *buf, char *attrs, int x, int y)
 {
@@ -243,7 +243,7 @@ static struct mark *find_top(struct point **ptp, struct pane *p,
        return start;
 }
 
-static int do_render_dir_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_handle)
 {
        struct pane *p = ci->home;
        struct dir_data *dd = p->data;
@@ -271,7 +271,7 @@ static int do_render_dir_handle(struct command *c, struct cmd_info *ci)
                struct pane *parent = ci->focus;
                struct pane *c;
 
-               render_dir_attach(parent, NULL);
+               do_render_dir_attach(parent, NULL);
                c = pane_child(p);
                if (c)
                        return pane_clone(c, parent->focus);
@@ -298,11 +298,10 @@ static int do_render_dir_handle(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(render_dir_handle, do_render_dir_handle);
 
-static int render_dir_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_notify)
 {
-       struct dir_data *dd = container_of(c, struct dir_data, type);
+       struct dir_data *dd = container_of(ci->comm, struct dir_data, type);
 
        if (strcmp(ci->key, "Replace") == 0) {
                if (ci->mark == dd->top)
@@ -318,7 +317,7 @@ static int render_dir_notify(struct command *c, struct cmd_info *ci)
        return 0;
 }
 
-static int render_dir_move(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_move)
 {
        struct pane *p = ci->home;
        int rpt = RPT_NUM(ci);
@@ -343,9 +342,8 @@ static int render_dir_move(struct command *c, struct cmd_info *ci)
        pane_damaged(p, DAMAGED_CONTENT);
        return 1;
 }
-DEF_CMD(comm_move, render_dir_move);
 
-static int render_dir_follow_point(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_follow_point)
 {
        struct pane *p = ci->home;
        struct dir_data *dd = p->data;
@@ -356,9 +354,8 @@ static int render_dir_follow_point(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(comm_follow, render_dir_follow_point);
 
-static int render_dir_set_cursor(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_set_cursor)
 {
        struct pane *p = ci->home;
        struct point *pt = *ci->pointp;
@@ -370,9 +367,8 @@ static int render_dir_set_cursor(struct command *c, struct cmd_info *ci)
        pane_focus(p);
        return 1;
 }
-DEF_CMD(comm_cursor, render_dir_set_cursor);
 
-static int render_dir_move_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_move_line)
 {
        struct point *pt = *ci->pointp;
        struct dir_data *dd = ci->home->data;
@@ -392,9 +388,8 @@ static int render_dir_move_line(struct command *c, struct cmd_info *ci)
 
        return 1;
 }
-DEF_CMD(comm_line, render_dir_move_line);
 
-static int render_dir_move_horiz(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_move_horiz)
 {
        /* Horizonal movement - adjust ->rpos within fields, or
         * move to next line
@@ -427,9 +422,8 @@ static int render_dir_move_horiz(struct command *c, struct cmd_info *ci)
        }
        return 1;
 }
-DEF_CMD(comm_horiz, render_dir_move_horiz);
 
-static int render_dir_open(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_open)
 {
        struct cmd_info ci2 = *ci;
 
@@ -438,9 +432,8 @@ static int render_dir_open(struct command *c, struct cmd_info *ci)
                ci2.str = "hex";
        return key_handle_focus(&ci2);
 }
-DEF_CMD(comm_open, render_dir_open);
 
-static int render_dir_reload(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_reload)
 {
        struct point **ptp = ci->pointp;
        struct doc *d;
@@ -452,31 +445,29 @@ static int render_dir_reload(struct command *c, struct cmd_info *ci)
                d->ops->load_file(d, NULL, -1, NULL);
        return 1;
 }
-DEF_CMD(comm_reload, render_dir_reload);
-
 static void render_dir_register_map(void)
 {
        dr_map = key_alloc();
 
-       key_add_range(dr_map, "Move-", "Move-\377", &comm_follow);
-       key_add(dr_map, "Move-View-Small", &comm_move);
-       key_add(dr_map, "Move-View-Large", &comm_move);
-       key_add(dr_map, "Move-CursorXY", &comm_cursor);
-       key_add(dr_map, "Click-1", &comm_cursor);
-       key_add(dr_map, "Press-1", &comm_cursor);
-       key_add(dr_map, "Move-Line", &comm_line);
-       key_add(dr_map, "Move-Char", &comm_horiz);
-       key_add(dr_map, "Move-Word", &comm_horiz);
-       key_add(dr_map, "Move-WORD", &comm_horiz);
-
-       key_add(dr_map, "Replace", &comm_follow);
-
-       key_add(dr_map, "Chr-f", &comm_open);
-       key_add(dr_map, "Chr-h", &comm_open);
-       key_add(dr_map, "Chr-g", &comm_reload);
+       key_add_range(dr_map, "Move-", "Move-\377", &render_dir_follow_point);
+       key_add(dr_map, "Move-View-Small", &render_dir_move);
+       key_add(dr_map, "Move-View-Large", &render_dir_move);
+       key_add(dr_map, "Move-CursorXY", &render_dir_set_cursor);
+       key_add(dr_map, "Click-1", &render_dir_set_cursor);
+       key_add(dr_map, "Press-1", &render_dir_set_cursor);
+       key_add(dr_map, "Move-Line", &render_dir_move_line);
+       key_add(dr_map, "Move-Char", &render_dir_move_horiz);
+       key_add(dr_map, "Move-Word", &render_dir_move_horiz);
+       key_add(dr_map, "Move-WORD", &render_dir_move_horiz);
+
+       key_add(dr_map, "Replace", &render_dir_follow_point);
+
+       key_add(dr_map, "Chr-f", &render_dir_open);
+       key_add(dr_map, "Chr-h", &render_dir_open);
+       key_add(dr_map, "Chr-g", &render_dir_reload);
 }
 
-static void render_dir_attach(struct pane *parent, struct point **ptp)
+static void do_render_dir_attach(struct pane *parent, struct point **ptp)
 {
        struct dir_data *dd = malloc(sizeof(*dd));
        struct pane *p;
@@ -488,7 +479,7 @@ static void render_dir_attach(struct pane *parent, struct point **ptp)
        dd->top = NULL;
        dd->bot = NULL;
        dd->ignore_point = 0;
-       dd->type.func = render_dir_notify;
+       dd->type = render_dir_notify;
        dd->typenum = doc_add_view((*ptp)->doc, &dd->type);
        p = pane_register(parent, 0, &render_dir_handle, dd, NULL);
        dd->pane = p;
@@ -498,14 +489,14 @@ static void render_dir_attach(struct pane *parent, struct point **ptp)
        if (!dr_map)
                render_dir_register_map();
 }
-static int do_render_dir_attach(struct command *c, struct cmd_info *ci)
+
+DEF_CMD(render_dir_attach)
 {
-       render_dir_attach(ci->focus, ci->pointp);
+       do_render_dir_attach(ci->focus, ci->pointp);
        return 1;
 }
-DEF_CMD(comm_attach, do_render_dir_attach);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "render-dir-attach", &comm_attach);
+       key_add(ed->commands, "render-dir-attach", &render_dir_attach);
 }
index 26c75bfdad0ee5e2ee5f15951f705727f9567bb4..7852cdc143f5ab6adf83f5a5acbe530bbd9a052b 100644 (file)
@@ -27,7 +27,7 @@ struct he_data {
 };
 
 static struct map *he_map;
-static void render_hex_attach(struct pane *parent, struct point **ptp);
+static void do_render_hex_attach(struct pane *parent, struct point **ptp);
 
 static int put_str(struct pane *p, char *buf, char *attrs, int x, int y)
 {
@@ -206,7 +206,7 @@ found:
        return 0;
 }
 
-static int do_render_hex_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_handle)
 {
        struct pane *p = ci->home;
        struct he_data *he = p->data;
@@ -234,7 +234,7 @@ static int do_render_hex_handle(struct command *c, struct cmd_info *ci)
                struct pane *parent = ci->focus;
                struct pane *c;
 
-               render_hex_attach(parent, NULL);
+               do_render_hex_attach(parent, NULL);
                c = pane_child(p);
                if (c)
                        return pane_clone(c, parent->focus);
@@ -244,11 +244,10 @@ static int do_render_hex_handle(struct command *c, struct cmd_info *ci)
                return hex_refresh(ci);
        return 0;
 }
-DEF_CMD(render_hex_handle, do_render_hex_handle);
 
-static int render_hex_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_notify)
 {
-       struct he_data *he = container_of(c, struct he_data, type);
+       struct he_data *he = container_of(ci->comm, struct he_data, type);
 
        if (strcmp(ci->key, "Replace") == 0) {
                if (he->bot == NULL || ci->mark == NULL ||
@@ -267,7 +266,7 @@ static int render_hex_notify(struct command *c, struct cmd_info *ci)
        return 0;
 }
 
-static int render_hex_move(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_move)
 {
        struct pane *p = ci->home;
        int rpt = RPT_NUM(ci);
@@ -288,9 +287,8 @@ static int render_hex_move(struct command *c, struct cmd_info *ci)
        pane_damaged(p, DAMAGED_CONTENT);
        return 1;
 }
-DEF_CMD(comm_move, render_hex_move);
 
-static int render_hex_follow_point(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_follow_point)
 {
        struct pane *p = ci->home;
        struct he_data *he = p->data;
@@ -301,9 +299,8 @@ static int render_hex_follow_point(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(comm_follow, render_hex_follow_point);
 
-static int render_hex_set_cursor(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_set_cursor)
 {
        struct pane *p = ci->home;
        struct point *pt = *ci->pointp;
@@ -335,9 +332,8 @@ static int render_hex_set_cursor(struct command *c, struct cmd_info *ci)
        pane_focus(p);
        return 1;
 }
-DEF_CMD(comm_cursor, render_hex_set_cursor);
 
-static int render_hex_move_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_move_line)
 {
        /* MV_CHAR 16 times repeat count */
        struct cmd_info ci2 = {0};
@@ -348,9 +344,8 @@ static int render_hex_move_line(struct command *c, struct cmd_info *ci)
        return key_handle_focus(&ci2);
 
 }
-DEF_CMD(comm_line, render_hex_move_line);
 
-static int render_hex_eol(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_eol)
 {
        struct point *pt = *ci->pointp;
        wint_t ch = 1;
@@ -382,25 +377,24 @@ static int render_hex_eol(struct command *c, struct cmd_info *ci)
        he->ignore_point = 0;
        return 1;
 }
-DEF_CMD(comm_eol, render_hex_eol);
 
 static void render_hex_register_map(void)
 {
        he_map = key_alloc();
 
-       key_add_range(he_map, "Move-", "Move-\377", &comm_follow);
-       key_add(he_map, "Move-View-Small", &comm_move);
-       key_add(he_map, "Move-View-Large", &comm_move);
-       key_add(he_map, "Move-CursorXY", &comm_cursor);
-       key_add(he_map, "Click-1", &comm_cursor);
-       key_add(he_map, "Press-1", &comm_cursor);
-       key_add(he_map, "Move-Line", &comm_line);
+       key_add_range(he_map, "Move-", "Move-\377", &render_hex_follow_point);
+       key_add(he_map, "Move-View-Small", &render_hex_move);
+       key_add(he_map, "Move-View-Large", &render_hex_move);
+       key_add(he_map, "Move-CursorXY", &render_hex_set_cursor);
+       key_add(he_map, "Click-1", &render_hex_set_cursor);
+       key_add(he_map, "Press-1", &render_hex_set_cursor);
+       key_add(he_map, "Move-Line", &render_hex_move_line);
 
-       key_add(he_map, "Move-EOL", &comm_eol);
-       key_add(he_map, "Replace", &comm_follow);
+       key_add(he_map, "Move-EOL", &render_hex_eol);
+       key_add(he_map, "Replace", &render_hex_follow_point);
 }
 
-static void render_hex_attach(struct pane *parent, struct point **ptp)
+static void do_render_hex_attach(struct pane *parent, struct point **ptp)
 {
        struct he_data *he = malloc(sizeof(*he));
        struct pane *p;
@@ -413,7 +407,7 @@ static void render_hex_attach(struct pane *parent, struct point **ptp)
        he->top = NULL;
        he->bot = NULL;
        he->ignore_point = 0;
-       he->type.func = render_hex_notify;
+       he->type = render_hex_notify;
        he->typenum = doc_add_view((*ptp)->doc, &he->type);
        p = pane_register(parent, 0, &render_hex_handle, he, NULL);
        he->pane = p;
@@ -421,14 +415,14 @@ static void render_hex_attach(struct pane *parent, struct point **ptp)
        if (!he_map)
                render_hex_register_map();
 }
-static int do_render_hex_attach(struct command *c, struct cmd_info *ci)
+
+DEF_CMD(render_hex_attach)
 {
-       render_hex_attach(ci->focus, ci->pointp);
+       do_render_hex_attach(ci->focus, ci->pointp);
        return 1;
 }
-DEF_CMD(comm_attach, do_render_hex_attach);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "render-hex-attach", &comm_attach);
+       key_add(ed->commands, "render-hex-attach", &render_hex_attach);
 }
index d2463f4c19714dbebc810d85b9e319e2fcb8d545..c2fd2ba80ad63e88ce79b1aa6f5aacfb59db8b02 100644 (file)
@@ -32,7 +32,7 @@ struct rt_data {
 };
 
 static struct map *rt_map;
-static void render_text_attach(struct pane *p, struct point **pt);
+static void do_render_text_attach(struct pane *p, struct point **pt);
 
 static int rt_fore(struct doc *d, struct pane *p, struct mark *m, int *x, int *y, int draw)
 {
@@ -287,7 +287,7 @@ found:
        return 0;
 }
 
-static int do_render_text_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_handle)
 {
        struct pane *p = ci->home;
        struct rt_data *rt = p->data;
@@ -314,7 +314,7 @@ static int do_render_text_handle(struct command *c, struct cmd_info *ci)
                struct pane *parent = ci->focus;
                struct pane *c;
 
-               render_text_attach(parent, NULL);
+               do_render_text_attach(parent, NULL);
                c = pane_child(p);
                if (c)
                        return pane_clone(c, parent->focus);
@@ -324,11 +324,10 @@ static int do_render_text_handle(struct command *c, struct cmd_info *ci)
                return text_refresh(ci);
        return 0;
 }
-DEF_CMD(render_text_handle, do_render_text_handle);
 
-static int render_text_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_notify)
 {
-       struct rt_data *rt = container_of(c, struct rt_data, type);
+       struct rt_data *rt = container_of(ci->comm, struct rt_data, type);
 
        if (strcmp(ci->key, "Replace") == 0) {
                if (ci->mark == rt->top)
@@ -344,7 +343,7 @@ static int render_text_notify(struct command *c, struct cmd_info *ci)
        return 0;
 }
 
-static int render_text_move(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_move)
 {
        struct pane *p = ci->home;
        int rpt = RPT_NUM(ci);
@@ -370,9 +369,8 @@ static int render_text_move(struct command *c, struct cmd_info *ci)
        pane_damaged(p, DAMAGED_CONTENT);
        return 1;
 }
-DEF_CMD(comm_move, render_text_move);
 
-static int render_text_move_pos(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_move_pos)
 {
        struct pane *p = ci->home;
        struct rt_data *rt = p->data;
@@ -392,9 +390,8 @@ static int render_text_move_pos(struct command *c, struct cmd_info *ci)
        pane_damaged(p, DAMAGED_CONTENT);
        return 1;
 }
-DEF_CMD(comm_move_pos, render_text_move_pos);
 
-static int render_text_follow_point(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_follow_point)
 {
        struct pane *p = ci->home;
        struct rt_data *rt = p->data;
@@ -408,9 +405,8 @@ static int render_text_follow_point(struct command *c, struct cmd_info *ci)
        }
        return 0;
 }
-DEF_CMD(comm_follow, render_text_follow_point);
 
-static int render_text_set_cursor(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_set_cursor)
 {
        struct pane *p = ci->home;
        struct point *pt = *ci->pointp;
@@ -422,9 +418,8 @@ static int render_text_set_cursor(struct command *c, struct cmd_info *ci)
        pane_focus(p);
        return 1;
 }
-DEF_CMD(comm_cursor, render_text_set_cursor);
 
-static int render_text_move_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_move_line)
 {
        struct pane *p = ci->home;
        /* MV_EOL repeatedly, then move to match cursor */
@@ -469,25 +464,24 @@ static int render_text_move_line(struct command *c, struct cmd_info *ci)
        pane_damaged(p, DAMAGED_CURSOR);
        return 1;
 }
-DEF_CMD(comm_line, render_text_move_line);
 
 static void render_text_register_map(void)
 {
        rt_map = key_alloc();
 
-       key_add_range(rt_map, "Move-", "Move-\377", &comm_follow);
-       key_add(rt_map, "Move-View-Small", &comm_move);
-       key_add(rt_map, "Move-View-Large", &comm_move);
-       key_add(rt_map, "Move-View-Pos", &comm_move_pos);
-       key_add(rt_map, "Move-CursorXY", &comm_cursor);
-       key_add(rt_map, "Click-1", &comm_cursor);
-       key_add(rt_map, "Press-1", &comm_cursor);
-       key_add(rt_map, "Move-Line", &comm_line);
+       key_add_range(rt_map, "Move-", "Move-\377", &render_text_follow_point);
+       key_add(rt_map, "Move-View-Small", &render_text_move);
+       key_add(rt_map, "Move-View-Large", &render_text_move);
+       key_add(rt_map, "Move-View-Pos", &render_text_move_pos);
+       key_add(rt_map, "Move-CursorXY", &render_text_set_cursor);
+       key_add(rt_map, "Click-1", &render_text_set_cursor);
+       key_add(rt_map, "Press-1", &render_text_set_cursor);
+       key_add(rt_map, "Move-Line", &render_text_move_line);
 
-       key_add(rt_map, "Replace", &comm_follow);
+       key_add(rt_map, "Replace", &render_text_follow_point);
 }
 
-static void render_text_attach(struct pane *parent, struct point **ptp)
+static void do_render_text_attach(struct pane *parent, struct point **ptp)
 {
        struct rt_data *rt = malloc(sizeof(*rt));
        struct pane *p;
@@ -500,7 +494,7 @@ static void render_text_attach(struct pane *parent, struct point **ptp)
        rt->bot = NULL;
        rt->ignore_point = 0;
        rt->target_x = -1;
-       rt->type.func = render_text_notify;
+       rt->type = render_text_notify;
        rt->typenum = doc_add_view((*ptp)->doc, &rt->type);
        p = pane_register(parent, 0, &render_text_handle, rt, NULL);
        rt->pane = p;
@@ -508,14 +502,14 @@ static void render_text_attach(struct pane *parent, struct point **ptp)
        if (!rt_map)
                render_text_register_map();
 }
-static int do_render_text_attach(struct command *c, struct cmd_info *ci)
+
+DEF_CMD(render_text_attach)
 {
-       render_text_attach(ci->focus, ci->pointp);
+       do_render_text_attach(ci->focus, ci->pointp);
        return 1;
 }
-DEF_CMD(comm_attach, do_render_text_attach);
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "render-text-attach", &comm_attach);
+       key_add(ed->commands, "render-text-attach", &render_text_attach);
 }