]> git.neil.brown.name Git - edlib.git/commitdiff
Change set_attr into a command.
authorNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 05:38:31 +0000 (16:38 +1100)
committerNeilBrown <neil@brown.name>
Tue, 24 Nov 2015 05:38:31 +0000 (16:38 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
doc-dir.c
doc-text.c
emacs-search.c

index 2503a5b42d39de285e358ccbd9bbbacec71a4a88..980408b5367a40f9e595f24465606322c933978c 100644 (file)
@@ -360,17 +360,11 @@ static char *docs_get_attr(struct doc *doc, struct mark *m,
        return doc_attr(d, NULL, 0, attr);
 }
 
-static int docs_set_attr(struct point *p, char *attr, char *val)
-{
-       return 0;
-}
-
 static struct doc_operations docs_ops = {
        .replace   = docs_replace,
        .step      = docs_step,
        .same_ref  = docs_sameref,
        .get_attr  = docs_get_attr,
-       .set_attr  = docs_set_attr,
 };
 
 DEF_CMD(docs_open)
diff --git a/core.h b/core.h
index f759d1f567bc500dc40d7407111975d7e85b7058..fbeb2a59585cf1afee593b60d604be02166fe3f0 100644 (file)
--- a/core.h
+++ b/core.h
@@ -92,7 +92,6 @@ struct doc_operations {
         * after the point/mark.  They fail at EOF.
         */
        char            *(*get_attr)(struct doc *d, struct mark *m, bool forward, char *attr);
-       int             (*set_attr)(struct point *pos, char *attr, char *val);
 };
 
 void doc_init(struct doc *d);
@@ -393,3 +392,16 @@ static inline char *doc_attr(struct doc *d, struct mark *m, bool forward, char *
 {
        return d->ops->get_attr(d, m, forward, attr);
 }
+
+static inline int doc_set_attr(struct point *pt, char *attr, char *val)
+{
+       struct cmd_info ci = {0};
+       struct doc *d = pt->doc;
+
+       ci.key = "doc:set-attr";
+       ci.pointp = &pt;
+       ci.str = attr;
+       ci.str2 = val;
+       return key_lookup(d->map, &ci);
+}
+
index dc2c683f7739b8c884445ce44f53e46a5582d4b4..128773a18c7d4c949b8116cd8b3d771fd78f2d0c 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -462,11 +462,6 @@ static char *dir_get_attr(struct doc *d, struct mark *m,
                return attr_get_str(de->attrs, attr, -1);
 }
 
-static int dir_set_attr(struct point *p, char *attr, char *val)
-{
-       return 0;
-}
-
 DEF_CMD(dir_destroy)
 {
        struct doc *d = (*ci->pointp)->doc;
@@ -489,7 +484,6 @@ static struct doc_operations dir_ops = {
        .step      = dir_step,
        .same_ref  = dir_sameref,
        .get_attr  = dir_get_attr,
-       .set_attr  = dir_set_attr,
 };
 
 DEF_CMD(dir_open)
index 686ac606addea091cf6e6f2c009b81bda3cb0ced..bb84b8776eafeefe9eb8d738c192972e7c160575 100644 (file)
@@ -1446,8 +1446,11 @@ static char *text_get_attr(struct doc *d, struct mark *m,
        return attr_get_str(c->attrs, attr, o);
 }
 
-static int text_set_attr(struct point *p, char *attr, char *val)
+DEF_CMD(text_set_attr)
 {
+       struct point *p = *ci->pointp;
+       char *attr = ci->str;
+       char *val = ci->str2;
        struct text_chunk *c = p->m.ref.c;
        struct text *t = container_of(p->doc, struct text, doc);
        int o = p->m.ref.o;
@@ -1501,7 +1504,6 @@ static struct doc_operations text_ops = {
        .step      = text_step,
        .same_ref  = text_sameref,
        .get_attr  = text_get_attr,
-       .set_attr  = text_set_attr,
 };
 
 #define LARGE_LINE 4096
@@ -1628,4 +1630,5 @@ void edlib_init(struct editor *ed)
        key_add(text_map, "doc:set-ref", &text_set_ref);
        key_add(text_map, "doc:save-file", &text_save_file);
        key_add(text_map, "doc:reundo", &text_reundo);
+       key_add(text_map, "doc:set-attr", &text_set_attr);
 }
index 18088d01402c8485b0191de0552ee551c24a51fa..253b6aa4e219094c8b908fefad377ddd2f687e70 100644 (file)
@@ -99,7 +99,7 @@ DEF_CMD(search_add)
 
        do {
                /* TEMP HACK - please fix */
-               d->ops->set_attr(esi->end, "highlight", NULL);
+               doc_set_attr(esi->end, "highlight", NULL);
                wch = mark_next(d, &esi->end->m);
                if (wch == WEOF)
                        return 1;
@@ -136,7 +136,7 @@ DEF_CMD(search_close)
 
        doc_del_view((*ci->pointp)->doc, &esi->watch);
        /* TEMP HACK - please fix */
-       esi->target->point->doc->ops->set_attr(esi->end, "highlight", NULL);
+       doc_set_attr(esi->end, "highlight", NULL);
        point_free(esi->end);
        mark_free(esi->start);
        while (esi->s) {
@@ -153,7 +153,6 @@ REDEF_CMD(search_again)
        /* document has changed, retry search */
        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;
        char *a, *pfx;
        int ret;
@@ -167,7 +166,7 @@ REDEF_CMD(search_again)
        }
 
        /* TEMP HACK - please fix */
-       d->ops->set_attr(esi->end, "highlight", NULL);
+       doc_set_attr(esi->end, "highlight", NULL);
        ci2.pointp = &esi->end;
        ci2.mark = mark_dup(esi->start, 1);
        ci2.str = doc_getstr(*ci->pointp, NULL);
@@ -180,7 +179,7 @@ REDEF_CMD(search_again)
        } else if (ci2.extra > 0) {
                point_to_mark(esi->end, ci2.mark);
                /* TEMP HACK - please fix */
-               d->ops->set_attr(esi->end, "highlight","fg:red,inverse");
+               doc_set_attr(esi->end, "highlight","fg:red,inverse");
                ci2.key = "Move-View-Pos";
                ci2.focus = esi->target;
                key_handle_focus(&ci2);