]> git.neil.brown.name Git - edlib.git/commitdiff
doc-email: support linecount
authorNeilBrown <neil@brown.name>
Sat, 3 Jun 2023 00:59:38 +0000 (10:59 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 05:40:21 +0000 (15:40 +1000)
doc-email-view now intercepts linecount requests and ensures they happen
against the view, rather against the raw document.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
doc-email.c
lib-linecount.c

index f9703a51ffda17b6962647e0e3f9e0e24a4322b5..86e3c685084a13b0cae220c8605d66287f0358d2 100644 (file)
@@ -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
index bafd220eb9e2482c5afb6302aa256b48e6da258b..e95d46568e0aed1bb447d6fe1c4c02e10f12cba5 100644 (file)
@@ -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)
index 43c3f88e3700a0a0b8d67667b32fbf480cbb4f2d..2572086601507eafcd45b8707e8147ca23f1f656 100644 (file)
@@ -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 */