Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / c9 / 5680633fb8ff721b13f2799334f31f5bebbed2
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 89521431FAF\r
6         for <notmuch@notmuchmail.org>; Wed, 28 Mar 2012 22:32:26 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id iVi3+ZVkW7Bg for <notmuch@notmuchmail.org>;\r
16         Wed, 28 Mar 2012 22:32:25 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id 12FF9431FAE\r
20         for <notmuch@notmuchmail.org>; Wed, 28 Mar 2012 22:32:24 -0700 (PDT)\r
21 X-AuditID: 1209190e-b7f7c6d0000008c3-3e-4f73f3e81975\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id E1.70.02243.8E3F37F4; Thu, 29 Mar 2012 01:32:24 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q2T5WNp2008977; \r
27         Thu, 29 Mar 2012 01:32:23 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q2T5WMqH009428\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 29 Mar 2012 01:32:23 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1SD7y9-0006pc-OY; Thu, 29 Mar 2012 01:32:21 -0400\r
37 Date: Thu, 29 Mar 2012 01:32:21 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
40 Subject: Re: [BUG/PATCH v2] emacs: Fix the References header in reply\r
41 Message-ID: <20120329053221.GA2670@mit.edu>\r
42 References: <1332991226-510-1-git-send-email-awg+notmuch@xvx.ca>\r
43         <1332996818-15700-1-git-send-email-awg+notmuch@xvx.ca>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 Content-Disposition: inline\r
47 In-Reply-To: <1332996818-15700-1-git-send-email-awg+notmuch@xvx.ca>\r
48 User-Agent: Mutt/1.5.21 (2010-09-15)\r
49 X-Brightmail-Tracker:\r
50  H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42IRYrdT133xudjf4MZ1Dosje2axW1y/OZPZ\r
51         gcnj2apbzB5NPxazBjBFcdmkpOZklqUW6dslcGWcuNbNWLBNteLNr0+sDYxdcl2MnBwSAiYS\r
52         N2/0sUDYYhIX7q1n62Lk4hAS2Mco8bRpApSzgVHixc2Z7CBVQgInmSRmdUZBJJYwSnz4+ZwV\r
53         JMEioCpx88sfZhCbTUBDYtv+5YwgtoiAlsSP9V/BapgFpCW+/W5mArGFBVwlut6+BovzCmhL\r
54         PH6+jBViQaXEs6OL2SDighInZz5hgejVkrjx7yVQLwfYnOX/OEBMTgFniaYpKiAVogIqElNO\r
55         bmObwCg0C0nzLCTNsxCaFzAyr2KUTcmt0s1NzMwpTk3WLU5OzMtLLdI11svNLNFLTSndxAgK\r
56         ak5Jvh2MXw8qHWIU4GBU4uFV0in2F2JNLCuuzD3EKMnBpCTKm/IJKMSXlJ9SmZFYnBFfVJqT\r
57         WnyIUYKDWUmE1/0cUI43JbGyKrUoHyYlzcGiJM6rpvXOT0ggPbEkNTs1tSC1CCYrw8GhJMEb\r
58         DoxeIcGi1PTUirTMnBKENBMHJ8hwHqDhKSA1vMUFibnFmekQ+VOMuhzr3l25zCjEkpeflyol\r
59         zmsOUiQAUpRRmgc3B5aMXjGKA70lzOsIUsUDTGRwk14BLWECWrLkSD7IkpJEhJRUA+NKu8eH\r
60         Fje7sMb8L9iU/PR2d9OZ9mvvBCd/Wipvxrft3bOG5OefK5QkS8IsOC6yibX8197VpNe6Klb/\r
61         dP3CntXbulQ8HqsdP9VxtWjmJ3WX+V8FbnqsfnLojpLKFsPaNvfmFV97JgjwbAtYqr436ipv\r
62         /cogy6/lEptYT/5YomnmyfR99v43UxqUWIozEg21mIuKEwGPw+coIQMAAA==\r
63 Cc: notmuch@notmuchmail.org\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Thu, 29 Mar 2012 05:32:26 -0000\r
77 \r
78 Quoth Adam Wolfe Gordon on Mar 28 at 10:53 pm:\r
79 > In the new reply code, the References header gets inserted by\r
80 > message.el using a function called message-shorten-references. Unlike\r
81 > all the other header-inserting functions, it doesn't put a newline\r
82 > after the header, causing the next header to end up on the same\r
83 > line. In our case, this header happened to be User-Agent, so it's hard\r
84 > to notice. This is probably a bug in message.el, but we need to work\r
85 > around it.\r
86\r
87 > This fixes the problem by wrapping message-shorten-references in a\r
88 > function that inserts a newline after if necessary. This should\r
89 > protect against the message.el bug being fixed in the future.\r
90 > ---\r
91 \r
92 Ugh.  message-mode is such a rat's nest.  I dug through this and it\r
93 looks like message-shorten-references really is at fault here.\r
94 \r
95 I'm sure you already tracked this down, but for others who may be\r
96 interested, ultimately, the headers are inserted by\r
97 mail-header-format, which calls formatter functions or, if there is no\r
98 formatter, mail-header-format-function.  mail-header-format-function\r
99 inserts a newline after the header and, indeed, mail-header-format\r
100 does not insert anything between headers, so this is clearly up to the\r
101 formatter.  message-shorten-references, however, inserts its header by\r
102 calling message-insert-header, which looks remarkably like\r
103 mail-header-format-function, minus the newline.  Ironically,\r
104 message-shorten-references appears to be the only formatter configured\r
105 by default.\r
106 \r
107 > This version adds the local variables to suppress 'cl warings, per\r
108 > id:"1332995623-9055-1-git-send-email-amdragon@mit.edu".\r
109\r
110 >  emacs/notmuch-mua.el |   26 +++++++++++++++++++++++---\r
111 >  1 files changed, 23 insertions(+), 3 deletions(-)\r
112\r
113 > diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
114 > index 24918d3..0d3fcd3 100644\r
115 > --- a/emacs/notmuch-mua.el\r
116 > +++ b/emacs/notmuch-mua.el\r
117 > @@ -90,6 +90,15 @@ list."\r
118 >       else if (notmuch-match-content-type (plist-get part :content-type) "text/*")\r
119 >         collect part))\r
120 >  \r
121 > +;; There is a bug in emacs 23's message.el that results in a newline\r
122 > +;; not being inserted after the References header, so the next header\r
123 > +;; is concatenated to the end of it. This function fixes the problem,\r
124 > +;; while guarding against the possibility that some current or future\r
125 > +;; version of emacs has the bug fixed.\r
126 > +(defun notmuch-mua-insert-references (header references)\r
127 > +  (message-shorten-references header references)\r
128 > +  (unless (bolp) (insert "\n")))\r
129 > +\r
130 \r
131 Would it be safer to call whatever was associated with References in\r
132 message-header-format-alist, rather than hard-coding\r
133 message-shorten-references?\r
134 \r
135 >  (defun notmuch-mua-reply (query-string &optional sender reply-all)\r
136 >    (let ((args '("reply" "--format=json"))\r
137 >       reply\r
138 > @@ -125,9 +134,16 @@ list."\r
139 >         ;; Overlay the composition window on that being used to read\r
140 >         ;; the original message.\r
141 >         ((same-window-regexps '("\\*mail .*")))\r
142 > -     (notmuch-mua-mail (plist-get reply-headers :To)\r
143 > -                       (plist-get reply-headers :Subject)\r
144 > -                       (notmuch-plist-to-alist reply-headers)))\r
145 > +\r
146 > +     ;; We modify message-header-format-alist to get around a bug in message.el.\r
147 > +     ;; See the comment above on notmuch-mua-insert-references.\r
148 > +     (let ((message-header-format-alist\r
149 > +            (append '((References . notmuch-mua-insert-references))\r
150 \r
151 (cons '(References . notmuch-mua-insert-references) ...)\r
152 \r
153 > +                    (remove-if (lambda (x) (eq (car x) 'References))\r
154 > +                               message-header-format-alist))))\r
155 \r
156 (assq-delete-all 'References (copy-alist message-header-format-alist))?\r
157 \r
158 Hmm.  That's less shorter than I would have expected, but I think it's\r
159 less opaque.\r
160 \r
161 Actually, if I'm reading mail-header-format correctly, the order of\r
162 this alist controls the order of the headers, so maybe what you\r
163 actually want is\r
164 \r
165 (mapcar (lambda (x) (if (eq (car x) 'References)\r
166                         '(References . notmuch-mua-insert-references)\r
167                        x))\r
168         message-header-format-alist)\r
169 \r
170 > +       (notmuch-mua-mail (plist-get reply-headers :To)\r
171 > +                         (plist-get reply-headers :Subject)\r
172 > +                         (notmuch-plist-to-alist reply-headers))))\r
173 >        ;; Insert the message body - but put it in front of the signature\r
174 >        ;; if one is present\r
175 >        (goto-char (point-max))\r
176 > @@ -301,3 +317,7 @@ simply runs the corresponding `message-mode' hook functions."\r
177 >  ;;\r
178 >  \r
179 >  (provide 'notmuch-mua)\r
180 > +\r
181 > +;; Local Variables:\r
182 > +;; byte-compile-warnings: (not cl-functions)\r
183 > +;; End:\r
184 \r
185 This won't be necessary if you use assq-delete-all or mapcar, but if\r
186 you stick with the remove-if, you should also change the\r
187   (eval-when-compile (require 'cl))\r
188 to\r
189   (require 'cl)\r