]> git.neil.brown.name Git - edlib.git/commitdiff
Use a callback to return string from doc:get-attr
authorNeilBrown <neil@brown.name>
Tue, 8 Dec 2015 03:36:16 +0000 (14:36 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
doc-dir.c
doc-text.c

index 87791127c74e5f2b9dc4349a6d1dfb0883557a4f..9f7a6598f3812ecde30a6aff5acd83e72115c5e5 100644 (file)
@@ -626,6 +626,32 @@ struct pane *doc_find(struct editor *ed, char *name)
        return NULL;
 }
 
+DEF_CMD(doc_attr_callback)
+{
+       struct call_return *cr = container_of(ci->comm, struct call_return , c);
+       cr->s = ci->str;
+       return 1;
+}
+
+char *doc_attr(struct pane *dp, struct mark *m, bool forward, char *attr)
+{
+       struct cmd_info ci = {0};
+       struct call_return cr;
+
+       ci.key = "doc:get-attr";
+       ci.home = ci.focus = dp;
+       ci.mark = m;
+       ci.numeric = forward ? 1 : 0;
+       ci.str = attr;
+       ci.comm = dp->handle;
+       cr.c = doc_attr_callback;
+       cr.s = NULL;
+       ci.comm2 = &cr.c;
+       if (!dp->handle || dp->handle->func(&ci) == 0)
+               return NULL;
+       return cr.s;
+}
+
 /* the 'docs' document type is special in that there can only ever
  * be one instance - the list of documents.
  * So there is no 'doctype' registered, just a document which can never
@@ -741,7 +767,10 @@ DEF_CMD(docs_get_attr)
        struct mark *m = ci->mark;
        bool forward = ci->numeric != 0;
        char *attr = ci->str;
-       ci->str2 = __docs_get_attr(dd->doc, m, forward, attr);
+       char *val = __docs_get_attr(dd->doc, m, forward, attr);
+
+       comm_call(ci->comm2, "callback:get_attr", ci->focus,
+                 0, NULL, val, 0);
        return 1;
 }
 
diff --git a/core.h b/core.h
index 4f5cc2563599c7f0cb6cd8df5f2174e3810b74ab..30c34cf8fb90e793ac9f2326cddf338fb5fb7ec2 100644 (file)
--- a/core.h
+++ b/core.h
@@ -168,6 +168,7 @@ void mark_backward_over(struct mark *m, struct mark *mp);
 void point_notify_change(struct doc *d, struct mark *p, struct mark *m);
 void doc_notify_change(struct doc *d, struct mark *m);
 void doc_check_consistent(struct doc *d);
+char *doc_attr(struct pane *dp, struct mark *m, bool forward, char *attr);
 void point_to_mark(struct mark *p, struct mark *m);
 void mark_to_mark(struct mark *m, struct mark *target);
 int mark_same(struct doc *d, struct mark *m1, struct mark *m2);
@@ -399,21 +400,6 @@ static inline char *doc_getstr(struct pane *from, struct mark *to)
        return ci.str;
 }
 
-static inline char *doc_attr(struct pane *dp, struct mark *m, bool forward, char *attr)
-{
-       struct cmd_info ci = {0};
-
-       ci.key = "doc:get-attr";
-       ci.home = ci.focus = dp;
-       ci.mark = m;
-       ci.numeric = forward ? 1 : 0;
-       ci.str = attr;
-       ci.comm = dp->handle;
-       if (!dp->handle || dp->handle->func(&ci) == 0)
-               return NULL;
-       return ci.str2;
-}
-
 static inline int doc_set_attr(struct pane *p, struct mark *pt,
                               char *attr, char *val)
 {
@@ -501,6 +487,7 @@ static inline int call5(char *key, struct pane *focus, int numeric, struct mark
 struct call_return {
        struct command c;
        struct mark *m;
+       char *s;
 };
 
 static inline int call_comm(char *key, struct pane *focus, int numeric, struct mark *m,
index b2bed1386b62fb5ed520adb4dc2007cce4d843af..25752a0c739456c30bbadd98f7a456cec9151c86 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -476,8 +476,10 @@ DEF_CMD(dir_get_attr)
        struct mark *m = ci->mark;
        bool forward = ci->numeric != 0;
        char *attr = ci->str;
+       char *val = __dir_get_attr(dd->doc, m, forward, attr);
 
-       ci->str2 = __dir_get_attr(dd->doc, m, forward, attr);
+       comm_call(ci->comm2, "callback:get_attr", ci->focus,
+                 0, NULL, val, 0);
        return 1;
 }
 
index 254c4ff024b0b49bb2a6afca3b4ce880e9e91678..5cb55bf185d8d51e825355216a8668a3051543d5 100644 (file)
@@ -1487,8 +1487,9 @@ DEF_CMD(text_get_attr)
        struct mark *m = ci->mark;
        bool forward = ci->numeric != 0;
        char *attr = ci->str;
+       char *val = __text_get_attr(dd->doc, m, forward, attr);
 
-       ci->str2 = __text_get_attr(dd->doc, m, forward, attr);
+       comm_call(ci->comm2, "callback:get_attr", ci->focus, 0, NULL, val, 0);
        return 1;
 }