]> git.neil.brown.name Git - edlib.git/commitdiff
rfc822header: only include one space after , in a list
authorNeilBrown <neil@brown.name>
Tue, 29 Aug 2023 09:33:19 +0000 (19:33 +1000)
committerNeilBrown <neil@brown.name>
Tue, 29 Aug 2023 09:33:19 +0000 (19:33 +1000)
There is no need to copy all spaces after a comma verbatim.  Precisely
one is what we want for the wrap point.

Signed-off-by: NeilBrown <neil@brown.name>
lib-rfc822header.c

index 8030c84ae95ca70910928161edd84511c90d5566..11dbae80d1470c303ff3a5dfde38bb8ca4e11b93 100644 (file)
@@ -300,22 +300,18 @@ static void copy_header(struct pane *doc safe,
                                b[i] = ' ';
                call("doc:replace", p, 1, NULL, b, 0, point);
                if (ch == ',' && is_list) {
-                       /* This comma is no in a quoted word, so it really marks
-                        * part of a list, and together with following spaces
-                        * is a wrap-point.
+                       /* This comma is not in a quoted word, so it really marks
+                        * part of a list, and so is a wrap-point.  Consume any
+                        * following spaces and include just one space in
+                        * the result.
                         */
                        struct mark *p2 = mark_dup(point);
-                       int cnt = 1;
                        doc_prev(p, p2);
-                       while ((ch = doc_following(doc, m)) == ' ') {
-                               call("doc:replace", p, 1, NULL, " ", 0, point);
+                       while ((ch = doc_following(doc, m)) == ' ')
                                doc_next(doc, m);
-                               cnt += 1;
-                       }
-                       if (ch == '\n' || ch == '\r')
-                               cnt += 1;
-                       snprintf(buf, sizeof(buf), "%d", cnt);
-                       call("doc:set-attr", p, 1, p2, "render:rfc822header-wrap", 0, NULL, buf);
+                       call("doc:replace", p, 1, NULL, " ", 0, point);
+                       call("doc:set-attr", p, 1, p2,
+                            "render:rfc822header-wrap", 0, NULL, "2");
                        mark_free(p2);
                }
        }