]> git.neil.brown.name Git - edlib.git/commitdiff
change get_str from a doc_operations to a command.
authorNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 01:48:10 +0000 (12:48 +1100)
committerNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 01:59:35 +0000 (12:59 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
doc-dir.c
doc-text.c
emacs-search.c
lib-popup.c
mode-emacs.c

index bdff4988ab1397fbf2fdd5c7fcbf979442dc5098..2acc1f938523818496791b9579b24d94b5c8eab8 100644 (file)
@@ -318,11 +318,6 @@ static wint_t docs_step(struct doc *doc, struct mark *m, bool forward, bool move
                return ' ';
 }
 
-static char *docs_getstr(struct doc *d, struct mark *from, struct mark *to)
-{
-       return NULL;
-}
-
 static void docs_setref(struct doc *doc, struct mark *m, bool start)
 {
 
@@ -380,7 +375,6 @@ static struct doc_operations docs_ops = {
        .replace   = docs_replace,
        .reundo    = docs_reundo,
        .step      = docs_step,
-       .get_str   = docs_getstr,
        .set_ref   = docs_setref,
        .same_ref  = docs_sameref,
        .get_attr  = docs_get_attr,
diff --git a/core.h b/core.h
index bc9d2779e47aab0104b755ef70e0065bc7d661f0..0abe1a7cf1c41665e626603d22fe94a26b035fa0 100644 (file)
--- a/core.h
+++ b/core.h
@@ -88,7 +88,6 @@ struct doc_operations {
                                   char *str, bool *first);
        int             (*reundo)(struct point *pos, bool undo);
        wint_t          (*step)(struct doc *d, struct mark *m, bool forward, bool move);
-       char            *(*get_str)(struct doc *d, struct mark *from, struct mark *to);
        void            (*set_ref)(struct doc *d, struct mark *m, bool start);
        int             (*same_ref)(struct doc *d, struct mark *a, struct mark *b);
        /* get/set attr operate on the attributes of the char immediately
@@ -365,10 +364,21 @@ static inline int doc_load_file(struct doc *d, struct point *p,
        ci.key = "doc:load-file";
        return key_lookup(d->map, &ci);
 }
-static inline char *doc_getstr(struct doc *d, struct mark *from, struct mark *to)
+static inline char *doc_getstr(struct point *from, struct mark *to)
 {
-       return d->ops->get_str(d, from, to);
+       struct cmd_info ci = {0};
+       struct doc *d = from->doc;
+       int ret;
+
+       ci.key = "doc:get-str";
+       ci.pointp = &from;
+       ci.mark = to;
+       ret = key_lookup(d->map, &ci);
+       if (!ret)
+               return NULL;
+       return ci.str;
 }
+
 static inline char *doc_attr(struct doc *d, struct mark *m, bool forward, char *attr)
 {
        return d->ops->get_attr(d, m, forward, attr);
index f8f983dcf76b46e5d5a37c53538529aae540c64f..cee657b9d8a382531ace9d47530e9a8fd31a1774 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -302,11 +302,6 @@ static wint_t dir_step(struct doc *doc, struct mark *m, bool forward, bool move)
        return ret;
 }
 
-static char *dir_getstr(struct doc *d, struct mark *from, struct mark *to)
-{
-       return NULL;
-}
-
 static void dir_setref(struct doc *doc, struct mark *m, bool start)
 {
        struct directory *dr = container_of(doc, struct directory, doc);
@@ -493,7 +488,6 @@ static struct doc_operations dir_ops = {
        .replace   = dir_replace,
        .reundo    = dir_reundo,
        .step      = dir_step,
-       .get_str   = dir_getstr,
        .set_ref   = dir_setref,
        .same_ref  = dir_sameref,
        .get_attr  = dir_get_attr,
index e1b2af49a384db7e477e6ff77f5c72881356a8d8..f79212ce6cff43d0b170861a85601c4f98d2de99 100644 (file)
@@ -997,13 +997,26 @@ static int count_bytes(struct text *t, struct mark *from, struct mark *to)
        return l;
 }
 
-static char *text_getstr(struct doc *d, struct mark *from, struct mark *to)
+DEF_CMD(text_get_str)
 {
+       struct point *pt = *ci->pointp;
+       struct doc *d = pt->doc;
+       struct mark *from = NULL, *to = NULL;
        struct text *t = container_of(d, struct text, doc);
        struct text_chunk *c, *first, *last;
        char *ret;
        int l = 0, head, tail;
 
+       if (ci->mark) {
+               if (mark_ordered(&pt->m, ci->mark)) {
+                       from = &pt->m;
+                       to = ci->mark;
+               } else {
+                       from = ci->mark;
+                       to = &pt->m;
+               }
+       }
+
        first = list_first_entry_or_null(&t->text, struct text_chunk, lst);
        head = 0;
        if (from && from->ref.c) {
@@ -1044,7 +1057,8 @@ static char *text_getstr(struct doc *d, struct mark *from, struct mark *to)
                        break;
        }
        ret[l] = 0;
-       return ret;
+       ci->str = ret;
+       return 1;
 }
 
 static void text_setref(struct doc *d, struct mark *m, bool start)
@@ -1413,7 +1427,6 @@ static struct doc_operations text_ops = {
        .replace   = text_replace,
        .reundo    = text_reundo,
        .step      = text_step,
-       .get_str   = text_getstr,
        .set_ref   = text_setref,
        .same_ref  = text_sameref,
        .get_attr  = text_get_attr,
@@ -1540,4 +1553,5 @@ void edlib_init(struct editor *ed)
 
        key_add(text_map, "doc:load-file", &text_load_file);
        key_add(text_map, "doc:same-file", &text_same_file);
+       key_add(text_map, "doc:get-str", &text_get_str);
 }
index 2057018f36c0394897f2ecbaaeb2c99094547083..e2006a51669d1aa1163ac6d7b6cce0923197220a 100644 (file)
@@ -52,7 +52,7 @@ DEF_CMD(search_forward)
        }
        s = malloc(sizeof(*s));
        s->m = esi->start;
-       str = doc_getstr((*ci->pointp)->doc, NULL, NULL);
+       str = doc_getstr(*ci->pointp, NULL);
        s->len = strlen(str);
        free(str);
        s->next = esi->s;
@@ -75,7 +75,7 @@ DEF_CMD(search_retreat)
 
        if (esi->s == NULL)
                return 0;
-       str = doc_getstr((*ci->pointp)->doc, NULL, NULL);
+       str = doc_getstr(*ci->pointp, NULL);
        if (strlen(str) > esi->s->len) {
                free(str);
                return 0;
@@ -170,7 +170,7 @@ REDEF_CMD(search_again)
        d->ops->set_attr(esi->end, "highlight", NULL);
        ci2.pointp = &esi->end;
        ci2.mark = mark_dup(esi->start, 1);
-       ci2.str = doc_getstr((*ci->pointp)->doc, NULL, NULL);
+       ci2.str = doc_getstr(*ci->pointp, NULL);
        ci2.key = "text-search";
        ret = key_lookup(pane2ed(esi->target)->commands, &ci2);
        if (ret == 0)
index 6b5fc5b721c1689a5f800da3df76236297f13ae8..3df337bfb4c2c1de55e233e7320ec46a34cb4f1d 100644 (file)
@@ -31,7 +31,7 @@
 
 struct popup_info {
        struct pane     *target, *popup;
-       struct doc      *doc;
+       struct point    *point;
        char            *style;
 };
 
@@ -63,8 +63,8 @@ DEF_CMD(popup_handle)
        struct popup_info *ppi = p->data;
 
        if (strcmp(ci->key, "Close") == 0) {
-               if (ppi->doc)
-                       doc_destroy(ppi->doc);
+               if (ppi->point)
+                       doc_destroy(ppi->point->doc);
                free(ppi);
                return 1;
        }
@@ -88,11 +88,11 @@ DEF_CMD(popup_handle)
                        ci2.key = "PopupDone";
                ci2.numeric = 1;
                ci2.str = ci->str;
-               if (ppi->doc)
-                       ci2.str = doc_getstr(ppi->doc, NULL, NULL);
+               if (ppi->point)
+                       ci2.str = doc_getstr(ppi->point, NULL);
                ci2.mark = NULL;
                key_handle_focus(&ci2);
-               if (ppi->doc)
+               if (ppi->point)
                        free(ci2.str);
                pane_close(ppi->popup);
                return 1;
@@ -158,7 +158,7 @@ DEF_CMD(popup_attach)
        ppi->target = ci->focus;
        ppi->popup = pane_register(root, z, &popup_handle, ppi, NULL);
        ppi->style = style;
-       ppi->doc = NULL;
+       ppi->point = NULL;
        popup_resize(ppi->popup, style);
        for (i = 0, j = 0; i < 4; i++) {
                if (strchr(style, "TLBR"[i]) == NULL)
@@ -169,13 +169,13 @@ DEF_CMD(popup_attach)
        attr_set_str(&ppi->popup->attrs, "render-wrap", "no", -1);
 
        if (ci->pointp) {
-               pt = *ci->pointp;
+               p = pane_attach(ppi->popup, "view", *ci->pointp, NULL);
        } else {
                pt = doc_new(pane2ed(root), "text");
                doc_set_name(pt->doc, "*popup*");
-               ppi->doc = pt->doc;
+               p = pane_attach(ppi->popup, "view", pt, NULL);
+               point_new(pt->doc, &ppi->point);
        }
-       p = pane_attach(ppi->popup, "view", pt, NULL);
        render_attach(NULL, p);
        pane_focus(p);
        ci2.key = "local-set-key";
index 560e54210909354b4d18cfa3c4011431a82978e9..03359d14f18b2c1568be28b1e475703d93a3acfa 100644 (file)
@@ -344,7 +344,7 @@ DEF_CMD(emacs_file_complete)
         * popup menu
         */
        struct doc *doc = (*ci->pointp)->doc;
-       char *str = doc_getstr(doc, NULL, NULL);
+       char *str = doc_getstr(*ci->pointp, NULL);
        char *d, *b, *c;
        int fd;
        struct pane *par, *pop;
@@ -478,7 +478,7 @@ DEF_CMD(emacs_doc_complete)
         * Attach the 'docs' document as a completing popup menu
         */
        struct doc *doc = (*ci->pointp)->doc;
-       char *str = doc_getstr(doc, NULL, NULL);
+       char *str = doc_getstr(*ci->pointp, NULL);
        struct pane *par, *pop;
        struct cmd_info ci2 = {0};
        struct point *pt, **ptp;