From: NeilBrown Date: Sat, 3 Jun 2023 00:59:38 +0000 (+1000) Subject: doc-email: support linecount X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=04bd9a7e182c18c7facd80c55a1638dc5d8bc436;p=edlib.git doc-email: support linecount doc-email-view now intercepts linecount requests and ensures they happen against the view, rather against the raw document. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index f9703a51..86e3c685 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -404,7 +404,7 @@ Module features ### line count -- [ ] count-lines seems to go very slowly in base64/utf-8 email +- [X] count-lines seems to go very slowly in base64/utf-8 email - [ ] Always do word-count async. ### lib-utf-8 @@ -507,7 +507,7 @@ Module features - [ ] in notmuch I searched in a message (mimepart), then enter to choose, then 'q' and crash. - [ ] A multipart still had an active view. -- [ ] linecount is spinning somewhere. +- [X] linecount is spinning somewhere. Doc is multipart, chars are garbage. underlying is b64 Email has large attachments This might have been because b64 was slow, but I don't really want diff --git a/doc-email.c b/doc-email.c index bafd220e..e95d4656 100644 --- a/doc-email.c +++ b/doc-email.c @@ -1093,7 +1093,7 @@ DEF_CMD(email_char) DEF_CMD(email_content) { - /* Call the multipart doc:content telling in + /* Call the multipart doc:content telling it * what is invisible, marking all spacers as invisible */ struct pane *p = ci->home; @@ -1209,6 +1209,8 @@ DEF_CMD(email_view_set_attr) 1, m2); call("view:changed", ci->focus, 0, m1, NULL, 0, m2); call("Notify:clip", ci->focus, 0, m1, NULL, 0, m2); + /* for CountLines */ + pane_notify("doc:replaced", ci->home, 0, m1, NULL, 0, m2); mark_free(m1); mark_free(m2); @@ -1228,6 +1230,42 @@ DEF_CMD(email_view_set_attr) return Efallthrough; } +DEF_CMD(email_request) +{ + /* Someone wants to count lines - attach the line count here, + * rather than let it fall through to document. + */ + pane_add_notify(ci->focus, ci->home, ksuffix(ci, "doc:request:")); + if (strcmp(ci->key, "doc:request:doc:replaced") == 0) + /* Though for doc:replaced, we want the doc to respond too */ + return Efallthrough; + return 1; +} + +DEF_CMD(email_countlines) +{ + return pane_notify(ksuffix(ci, "doc:notify:"), + ci->home, + ci->num, ci->mark, ci->str, + ci->num2, ci->mark2, ci->str2, ci->comm2); +} + +DEF_CMD(status_changed) +{ + /* line-count sent a status-change message */ + call("doc:status-changed", ci->focus->parent); + return 1; +} + +DEF_CMD(doc_replaced) +{ + /* doc sent a doc;replaced message */ + pane_notify("doc:replaced", ci->home, + ci->num, ci->mark, ci->str, + ci->num2, ci->mark2, ci->str2, ci->comm2); + return 1; +} + DEF_CMD(attach_email_view) { struct pane *p; @@ -1263,6 +1301,9 @@ DEF_CMD(attach_email_view) free(evi); return Efail; } + /* get doc:replaced from the email so I can pass it to linecount */ + home_call(ci->focus, "doc:request:doc:replaced", p); + pane_add_notify(p, p, "doc:status-changed"); attr_set_str(&p->attrs, "render-hide-CR", "yes"); return comm_call(ci->comm2, "callback:attach", p); } @@ -1284,6 +1325,11 @@ static void email_init_map(void) key_add(email_view_map, "email:select:hide", &email_select_hide); key_add(email_view_map, "email:select:full", &email_select_full); key_add(email_view_map, "email:select:extras", &email_select_extras); + key_add(email_view_map, "doc:request:doc:CountLines", &email_request); + key_add(email_view_map, "doc:request:doc:replaced", &email_request); + key_add(email_view_map, "doc:notify:doc:CountLines", &email_countlines); + key_add(email_view_map, "doc:status-changed", &status_changed); + key_add(email_view_map, "doc:replaced", &doc_replaced); } void edlib_init(struct pane *ed safe) diff --git a/lib-linecount.c b/lib-linecount.c index 43c3f88e..25720866 100644 --- a/lib-linecount.c +++ b/lib-linecount.c @@ -264,11 +264,8 @@ DEF_CMD(linecount_notify_goto) DEF_CMD(count_lines) { - char *type = pane_attr_get(ci->focus, "doc-type"); char *view = pane_attr_get(ci->focus, "view-default"); /* FIXME this type-check is a HACK */ - if (type && strcmp(type, "email") == 0) - return 1; if (view && strcmp(view, "make-viewer") == 0) return 1; /* FIXME optimise this away most of the time */