From: NeilBrown Date: Tue, 8 Dec 2015 03:36:16 +0000 (+1100) Subject: Use a callback to return string from doc:get-attr X-Git-Tag: lca2016~106 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=aed9af9c3ab2873e4a496eb9992b1592652aeca7;p=edlib.git Use a callback to return string from doc:get-attr Signed-off-by: NeilBrown --- diff --git a/core-doc.c b/core-doc.c index 87791127..9f7a6598 100644 --- a/core-doc.c +++ b/core-doc.c @@ -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 4f5cc256..30c34cf8 100644 --- 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, diff --git a/doc-dir.c b/doc-dir.c index b2bed138..25752a0c 100644 --- 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; } diff --git a/doc-text.c b/doc-text.c index 254c4ff0..5cb55bf1 100644 --- a/doc-text.c +++ b/doc-text.c @@ -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; }