]> git.neil.brown.name Git - edlib.git/commitdiff
Change doc_{add,del,find}_view into commands.
authorNeilBrown <neil@brown.name>
Wed, 25 Nov 2015 23:14:24 +0000 (10:14 +1100)
committerNeilBrown <neil@brown.name>
Wed, 25 Nov 2015 23:14:24 +0000 (10:14 +1100)
they get send to the document instead of having to find it.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
emacs-search.c
lib-line-count.c
lib-view.c
render-dir.c
render-hex.c
render-lines.c
render-text.c

index 5ab745ffa3662e8f3fa72cc212b1cb7e1911a42c..135fe7fa5c7f3e0c3dfc3fdd4bf7e9f2b3f2cf52 100644 (file)
@@ -30,7 +30,7 @@ struct doc_ref {
 
 #include "core.h"
 
-int doc_add_view(struct doc *d, struct command *c)
+static int do_doc_add_view(struct doc *d, struct command *c, int size)
 {
        struct docview *g;
        int ret;
@@ -63,12 +63,14 @@ int doc_add_view(struct doc *d, struct command *c)
        }
        points_attach(d, ret);
        d->views[ret].space = 0;
+       if (size > 0 && (unsigned)size > sizeof(struct mark))
+               d->views[ret].space = size - sizeof(struct mark);
        d->views[ret].notify = c;
        d->views[ret].marked = 0;
        return ret;
 }
 
-void doc_del_view(struct doc *d, struct command *c)
+static void do_doc_del_view(struct doc *d, struct command *c)
 {
        /* This view should only have points on the list, not typed
         * marks.  Just delete everything and clear the 'notify' pointer
@@ -88,7 +90,7 @@ void doc_del_view(struct doc *d, struct command *c)
        }
 }
 
-int doc_find_view(struct doc *d, struct command *c)
+static int do_doc_find_view(struct doc *d, struct command *c)
 {
        int i;
        for (i = 0 ; i < d->nviews; i++)
@@ -185,6 +187,27 @@ DEF_CMD(doc_handle)
                return 1;
        }
 
+       if (strcmp(ci->key, "doc:add-view") == 0) {
+               if (!ci->comm2)
+                       return -1;
+               ci->extra = do_doc_add_view(d, ci->comm2, ci->extra);
+               return 1;
+       }
+
+       if (strcmp(ci->key, "doc:del-view") == 0) {
+               if (!ci->comm2)
+                       return -1;
+               do_doc_del_view(d, ci->comm2);
+               return 1;
+       }
+
+       if (strcmp(ci->key, "doc:find-view") == 0) {
+               if (!ci->comm2)
+                       return -1;
+               ci->extra = do_doc_find_view(d, ci->comm2);
+               return 1;
+       }
+
        return key_lookup(d->map, ci);
 }
 
diff --git a/core.h b/core.h
index b11346151fe0dcb1f4ba2c62f3ebfcac21774045..16016f48c6bc39ead86087dc14efbb9fcccba08c 100644 (file)
--- a/core.h
+++ b/core.h
@@ -96,9 +96,6 @@ struct doc {
 };
 
 void doc_init(struct doc *d);
-int doc_add_view(struct doc *d, struct command *c);
-void doc_del_view(struct doc *d, struct command *c);
-int doc_find_view(struct doc *d, struct command *c);
 struct pane *doc_new(struct editor *ed, char *type);
 struct pane *doc_from_text(struct pane *parent, char *name, char *text);
 struct pane *doc_open(struct editor *ed, int fd, char *name);
@@ -260,7 +257,7 @@ struct cmd_info {
        char            *str, *str2;
        struct mark     *mark, *mark2;
        struct point    **pointp;
-       struct command  *comm;
+       struct command  *comm, *comm2;
 };
 #define        NO_NUMERIC      (INT_MAX/2)
 #define        RPT_NUM(ci)     ((ci)->numeric == NO_NUMERIC ? 1 : (ci)->numeric)
@@ -412,3 +409,36 @@ static inline int doc_set_attr(struct point *pt, char *attr, char *val)
        return key_handle_focus(&ci);
 }
 
+
+static inline int doc_add_view(struct pane *p, struct command *c, int size)
+{
+       struct cmd_info ci = {0};
+       ci.focus = p;
+       ci.key = "doc:add-view";
+       ci.comm2 = c;
+       ci.extra = size;
+       if (key_handle_focus(&ci) == 0)
+               return -1;
+       return ci.extra;
+}
+
+static inline void doc_del_view(struct pane *p, struct command *c)
+{
+       struct cmd_info ci = {0};
+       ci.focus = p;
+       ci.key = "doc:del-view";
+       ci.comm2 = c;
+       key_handle_focus(&ci);
+}
+
+static inline int doc_find_view(struct pane *p, struct command *c)
+{
+       struct cmd_info ci = {0};
+       ci.focus = p;
+       ci.key = "doc:find-view";
+       ci.comm2 = c;
+       if (key_handle_focus(&ci) == 0)
+               return -1;
+       return ci.extra;
+}
+
index 4079819f3489a9f188a63f14a0a15c7116325b73..24e62d5f157f94c8114e8651518636466b664b44 100644 (file)
@@ -138,7 +138,7 @@ DEF_CMD(search_close)
 {
        struct es_info *esi = ci->focus->data;
 
-       doc_del_view((*ci->pointp)->doc, &esi->watch);
+       doc_del_view(ci->focus, &esi->watch);
        /* TEMP HACK - please fix */
        doc_set_attr(esi->end, "highlight", NULL);
        point_free(esi->end);
@@ -162,10 +162,8 @@ REDEF_CMD(search_again)
        int ret;
 
        if (strcmp(ci->key, "Release") == 0) {
-               struct doc *d = ci->home->data;
-
                /* No marks to remove */
-               doc_del_view(d, ci->comm);
+               doc_del_view(ci->home, ci->comm);
                return 0;
        }
 
@@ -224,7 +222,6 @@ DEF_CMD(emacs_search)
        struct pane *p;
        struct es_info *esi;
        struct cmd_info ci2 = {0};
-       struct point **ptp;
 
        if (!es_map)
                emacs_search_init_map();
@@ -250,8 +247,7 @@ DEF_CMD(emacs_search)
        esi->matched = 0;
        esi->search = ci->focus;
        esi->watch = search_again;
-       ptp = pane_point(ci->focus);
-       doc_add_view((*ptp)->doc, &esi->watch);
+       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);
index 66a1490de26aa8f565208a0da2287c2e21981f42..341de4b2587ef5029a34b6e7c14c5b38378f4235 100644 (file)
@@ -92,12 +92,12 @@ DEF_CMD(count_notify)
        if (strcmp(ci->key, "Release") == 0) {
                struct doc *d = ci->home->data;
                struct mark *m;
-               int i = doc_find_view(d, ci->comm);
+               int i = doc_find_view(ci->home, ci->comm);
                if (i < 0)
                        return 0;
                while ((m = doc_first_mark(d, i)) != NULL)
                        mark_free(m);
-               doc_del_view(d, ci->comm);
+               doc_del_view(ci->home, ci->comm);
        }
        return 0;
 }
@@ -126,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_notify);
+       int type = doc_find_view(d->home, &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_notify);
+               type = doc_add_view(d->home, &count_notify, 0);
 
        m = doc_first_mark(d, type);
        if (m == NULL) {
index 7f689fdd075d2f6196d211a253a462fbe1c989ff..89e56a4063619a7a27cabda4e307e0abe78efdd1 100644 (file)
@@ -124,7 +124,6 @@ static int view_refresh(struct cmd_info *ci)
 DEF_CMD(view_handle)
 {
        struct pane *p = ci->home;
-       struct point *pt;
        struct view_data *vd = p->data;
        int ret;
 
@@ -136,8 +135,7 @@ DEF_CMD(view_handle)
                vd->pane = p; /* FIXME having to do this is horrible */
 
        if (strcmp(ci->key, "Close") == 0) {
-               pt = *ci->pointp;
-               doc_del_view(pt->doc, &vd->ch_notify);
+               doc_del_view(p, &vd->ch_notify);
                free(vd);
                return 1;
        }
@@ -208,9 +206,8 @@ static struct pane *view_reattach(struct pane *par)
 {
        struct view_data *vd = par->data;
        struct pane *p;
-       struct point **ptp = pane_point(par);
 
-       vd->ch_notify_num = doc_add_view((*ptp)->doc, &vd->ch_notify);
+       vd->ch_notify_num = doc_add_view(par, &vd->ch_notify, 0);
 
        p = pane_register(par, 0, &view_null, vd, NULL);
        pane_damaged(p, DAMAGED_SIZE);
index 6607f71e9b0e2aec2c52580e771929ca2a746ce9..b3709444ffc3fceb903987a7c32837405e6d902f 100644 (file)
@@ -27,7 +27,7 @@ struct dir_data {
 };
 
 static struct map *dr_map;
-static struct pane *do_render_dir_attach(struct pane *parent, struct point **ptp);
+static struct pane *do_render_dir_attach(struct pane *parent);
 
 static int put_str(struct pane *p, char *buf, char *attrs, int x, int y)
 {
@@ -248,7 +248,6 @@ DEF_CMD(render_dir_handle)
        struct pane *p = ci->home;
        struct dir_data *dd = p->data;
        struct mark *end = NULL, *top;
-       struct doc *d;
        int ret;
 
        ret = key_lookup(dr_map, ci);
@@ -257,11 +256,11 @@ DEF_CMD(render_dir_handle)
 
        if (strcmp(ci->key, "Close") == 0) {
                struct pane *p = dd->pane;
-               d = (*ci->pointp)->doc;
+
                mark_free(dd->top);
                mark_free(dd->bot);
                dd->pane = NULL;
-               doc_del_view(d, &dd->type);
+               doc_del_view(p, &dd->type);
                p->data = NULL;
                p->handle = NULL;
                free(dd);
@@ -271,7 +270,7 @@ DEF_CMD(render_dir_handle)
                struct pane *parent = ci->focus;
                struct pane *c;
 
-               do_render_dir_attach(parent, NULL);
+               do_render_dir_attach(parent);
                c = pane_child(p);
                if (c)
                        return pane_clone(c, parent->focus);
@@ -460,7 +459,7 @@ static void render_dir_register_map(void)
        key_add(dr_map, "Chr-g", &render_dir_reload);
 }
 
-static struct pane *do_render_dir_attach(struct pane *parent, struct point **ptp)
+static struct pane *do_render_dir_attach(struct pane *parent)
 {
        struct dir_data *dd = malloc(sizeof(*dd));
        struct pane *p;
@@ -468,15 +467,11 @@ static struct pane *do_render_dir_attach(struct pane *parent, struct point **ptp
        if (!dr_map)
                render_dir_register_map();
 
-       if (!ptp)
-               ptp = pane_point(parent);
-       if (!ptp)
-               return NULL;
        dd->top = NULL;
        dd->bot = NULL;
        dd->ignore_point = 0;
        dd->type = render_dir_notify;
-       dd->typenum = doc_add_view((*ptp)->doc, &dd->type);
+       dd->typenum = doc_add_view(parent, &dd->type, 0);
        p = pane_register(parent, 0, &render_dir_handle, dd, NULL);
        dd->pane = p;
        dd->header = 0;
@@ -486,7 +481,7 @@ static struct pane *do_render_dir_attach(struct pane *parent, struct point **ptp
 
 DEF_CMD(render_dir_attach)
 {
-       ci->focus = do_render_dir_attach(ci->focus, ci->pointp);
+       ci->focus = do_render_dir_attach(ci->focus);
        return 1;
 }
 
index dcff62f63f3151d44712949ac2ded38d9d15b4df..43d3077dc0a94ef6dc393ee3164af4f919fa3ca3 100644 (file)
@@ -26,13 +26,12 @@ struct he_data {
 };
 
 static struct map *he_map;
-static struct pane *do_render_hex_attach(struct pane *parent, struct point **ptp);
+static struct pane *do_render_hex_attach(struct pane *parent);
 
 DEF_CMD(render_hex_handle)
 {
        struct pane *p = ci->home;
        struct he_data *he = p->data;
-       struct doc *d;
        int ret;
 
        ret = key_lookup(he_map, ci);
@@ -42,9 +41,8 @@ DEF_CMD(render_hex_handle)
        if (strcmp(ci->key, "Close") == 0) {
                struct pane *p = he->pane;
 
-               d = (*ci->pointp)->doc;
                he->pane = NULL;
-               doc_del_view(d, &he->type);
+               doc_del_view(p, &he->type);
                p->data = NULL;
                p->handle = NULL;
                free(he);
@@ -54,7 +52,7 @@ DEF_CMD(render_hex_handle)
                struct pane *parent = ci->focus;
                struct pane *c;
 
-               do_render_hex_attach(parent, NULL);
+               do_render_hex_attach(parent);
                c = pane_child(p);
                if (c)
                        return pane_clone(c, parent->focus);
@@ -224,7 +222,7 @@ static void render_hex_register_map(void)
        key_add(he_map, "render-line", &render_line);
 }
 
-static struct pane *do_render_hex_attach(struct pane *parent, struct point **ptp)
+static struct pane *do_render_hex_attach(struct pane *parent)
 {
        struct he_data *he = malloc(sizeof(*he));
        struct pane *p;
@@ -232,13 +230,8 @@ static struct pane *do_render_hex_attach(struct pane *parent, struct point **ptp
        if (!he_map)
                render_hex_register_map();
 
-       if (!ptp)
-               ptp = pane_point(parent);
-       if (!ptp)
-               return NULL;
-
        he->type = render_hex_notify;
-       he->typenum = doc_add_view((*ptp)->doc, &he->type);
+       he->typenum = doc_add_view(parent, &he->type, 0);
        p = pane_register(parent, 0, &render_hex_handle, he, NULL);
        attr_set_str(&p->attrs, "render-wrap", "no", -1);
        attr_set_str(&p->attrs, "heading", "<bold>          00 11 22 33 44 55 66 77  88 99 aa bb cc dd ee ff   0 1 2 3 4 5 6 7  8 9 a b c d e f</>", -1);
@@ -250,7 +243,7 @@ static struct pane *do_render_hex_attach(struct pane *parent, struct point **ptp
 
 DEF_CMD(render_hex_attach)
 {
-       ci->focus = do_render_hex_attach(ci->focus, ci->pointp);
+       ci->focus = do_render_hex_attach(ci->focus);
        return 1;
 }
 
index c38b2f8ab1cb6525d5db29d35cb18ccab96f6c74..1ca8d447573fdbc9a968c6cf431e4cb7eb85b2b8 100644 (file)
@@ -631,7 +631,7 @@ DEF_CMD(render_lines_close)
        }
 
        rl->pane = NULL;
-       doc_del_view(d, &rl->type);
+       doc_del_view(p, &rl->type);
        p->data = NULL;
        p->handle = NULL;
        free(rl);
@@ -967,15 +967,10 @@ static void render_lines_register_map(void)
 REDEF_CMD(render_lines_attach)
 {
        struct rl_data *rl = malloc(sizeof(*rl));
-       struct point **ptp;
 
        if (!rl_map)
                render_lines_register_map();
 
-       ptp = ci->pointp;
-       if (!ptp)
-               return -1;
-
        rl->ignore_point = 0;
        rl->top_sol = 0;
        rl->skip_lines = 0;
@@ -986,9 +981,7 @@ REDEF_CMD(render_lines_attach)
        rl->shift_left = 0;
        rl->header_lines = 0;
        rl->type = render_lines_notify;
-       rl->typenum = doc_add_view((*ptp)->doc, &rl->type);
-       (*ptp)->doc->views[rl->typenum].space =
-               sizeof(struct rl_mark) - sizeof(struct mark);
+       rl->typenum = doc_add_view(ci->focus, &rl->type, sizeof(struct rl_mark));
        rl->pane = pane_register(ci->focus, 0, &render_lines_handle.c, rl, NULL);
 
        ci->focus = rl->pane;
index 94992bc1bfc4dd9336dd1ce680a547c5175cce0c..3b0b4d1f96209b4ef2eb838f61fa1675488b83d4 100644 (file)
@@ -32,7 +32,7 @@ struct rt_data {
 };
 
 static struct map *rt_map;
-static struct pane *do_render_text_attach(struct pane *p, struct point **pt);
+static struct pane *do_render_text_attach(struct pane *p);
 
 static int rt_fore(struct doc *d, struct pane *p, struct mark *m, int *x, int *y, int draw)
 {
@@ -291,7 +291,6 @@ DEF_CMD(render_text_handle)
 {
        struct pane *p = ci->home;
        struct rt_data *rt = p->data;
-       struct doc *d;
        int ret;
 
        ret = key_lookup(rt_map, ci);
@@ -300,11 +299,10 @@ DEF_CMD(render_text_handle)
 
        if (strcmp(ci->key, "Close") == 0) {
                struct pane *p = rt->pane;
-               d = (*ci->pointp)->doc;
                mark_free(rt->top);
                mark_free(rt->bot);
                rt->pane = NULL;
-               doc_del_view(d, &rt->type);
+               doc_del_view(p, &rt->type);
                p->data = NULL;
                p->handle = NULL;
                free(rt);
@@ -314,7 +312,7 @@ DEF_CMD(render_text_handle)
                struct pane *parent = ci->focus;
                struct pane *c;
 
-               do_render_text_attach(parent, NULL);
+               do_render_text_attach(parent);
                c = pane_child(p);
                if (c)
                        return pane_clone(c, parent->focus);
@@ -481,7 +479,7 @@ static void render_text_register_map(void)
        key_add(rt_map, "Replace", &render_text_follow_point);
 }
 
-static struct pane *do_render_text_attach(struct pane *parent, struct point **ptp)
+static struct pane *do_render_text_attach(struct pane *parent)
 {
        struct rt_data *rt = malloc(sizeof(*rt));
        struct pane *p;
@@ -489,16 +487,12 @@ static struct pane *do_render_text_attach(struct pane *parent, struct point **pt
        if (!rt_map)
                render_text_register_map();
 
-       if (!ptp)
-               ptp = pane_point(parent);
-       if (!ptp)
-               return NULL;
        rt->top = NULL;
        rt->bot = NULL;
        rt->ignore_point = 0;
        rt->target_x = -1;
        rt->type = render_text_notify;
-       rt->typenum = doc_add_view((*ptp)->doc, &rt->type);
+       rt->typenum = doc_add_view(parent, &rt->type, 0);
        p = pane_register(parent, 0, &render_text_handle, rt, NULL);
        rt->pane = p;
        return p;
@@ -506,7 +500,7 @@ static struct pane *do_render_text_attach(struct pane *parent, struct point **pt
 
 DEF_CMD(render_text_attach)
 {
-       ci->focus = do_render_text_attach(ci->focus, ci->pointp);
+       ci->focus = do_render_text_attach(ci->focus);
        return 1;
 }