Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f1 / fb7d35a9b8d9cc2035aaf4ac221aaef3d84266
1 Return-Path: <jani@nikula.org>\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 E76D6431FAF\r
6         for <notmuch@notmuchmail.org>; Sun,  1 Sep 2013 11:00:01 -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 EapaY46Xdo85 for <notmuch@notmuchmail.org>;\r
16         Sun,  1 Sep 2013 10:59:57 -0700 (PDT)\r
17 Received: from mail-ea0-f182.google.com (mail-ea0-f182.google.com\r
18         [209.85.215.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 23A89431FBC\r
21         for <notmuch@notmuchmail.org>; Sun,  1 Sep 2013 10:59:57 -0700 (PDT)\r
22 Received: by mail-ea0-f182.google.com with SMTP id o10so1934168eaj.27\r
23         for <notmuch@notmuchmail.org>; Sun, 01 Sep 2013 10:59:54 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
27         bh=o3fPpm1c7gau26V4Wr49v2TqVCsHa+VZ/nxXfHVatr0=;\r
28         b=EaFm1VlSmonEQtvFtWCevkzIqVj3YYsc8Clom5cQGceE76f5WOn8+m1+bnt3yYSnjd\r
29         TQHbZ8az9TSohT1W69W+53CKvCz9fSz3ewUfdCMarjEkvGdG1eJ3ogQOyzSW6DTEl4Nn\r
30         0diQ77VL7F2GnafvtS8QelEg+Sk7DdhAoIoUVYNJfF6NlkOHlJ9c3kLj32zUbxdHZgsk\r
31         fru1tXdEfUW8cS7gp2ftK1tYVmiVzaNlWyhc61P1Z3IbphWED49GVZumgZQm/aCcM4XE\r
32         f9yWfFMQJ9U620UDBGA1wbKpjmWgH7XeRuJzncLL5bzjs+4xVZmrMioAUKBgDXh9ZlEC\r
33         QDRA==\r
34 X-Gm-Message-State:\r
35  ALoCoQmpX7IvdefTdvoxFlbDri014gQdLJ4DL9/KSc3pGxAnLU8fYqmI5OISNyw0XEr68FqKDdK4\r
36 X-Received: by 10.15.73.134 with SMTP id h6mr381537eey.76.1378058393274;\r
37         Sun, 01 Sep 2013 10:59:53 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
39         [88.195.111.91])\r
40         by mx.google.com with ESMTPSA id h52sm15164776eez.3.1969.12.31.16.00.00\r
41         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
42         Sun, 01 Sep 2013 10:59:52 -0700 (PDT)\r
43 From: Jani Nikula <jani@nikula.org>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH] emacs: insert quotable parts in reply as they are displayed\r
46         in show view\r
47 Date: Sun,  1 Sep 2013 20:59:53 +0300\r
48 Message-Id: <1378058393-29590-1-git-send-email-jani@nikula.org>\r
49 X-Mailer: git-send-email 1.8.4.rc3\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sun, 01 Sep 2013 18:00:02 -0000\r
63 \r
64 In reply, insert quotable parts using notmuch-show-insert-bodypart\r
65 instead of calling notmuch-mm-display-part-inline directly to render\r
66 the quoted parts as they are rendered in show view.\r
67 \r
68 We use a temp buffer to not leak text properties from the show\r
69 renderer into the reply. This way we also don't need to worry about\r
70 narrowing or point placement. Credits to Mark Walters\r
71 <markwalters1009@gmail.com> and Austin Clements <amdragon@MIT.EDU> for\r
72 getting this part straight.\r
73 \r
74 The notable change is that replies to text/calendar parts quote the\r
75 pretty printed output of icalendar-import-buffer rather than the ugly\r
76 raw vcalendar.\r
77 \r
78 ---\r
79 \r
80 v2: use (narrow-to-region (point-min) (point)) in\r
81 notmuch-mua-insert-quotable-part instead of adding the ugly recenter\r
82 in notmuch-mua-reply. Thanks to Austin and Mark for figuring this out.\r
83 \r
84 v3: Incorporate id:87eh98twws.fsf@qmul.ac.uk from Mark\r
85 ---\r
86  emacs/notmuch-mua.el  | 17 +++++++++++------\r
87  emacs/notmuch-show.el | 18 +++++++++++++-----\r
88  2 files changed, 24 insertions(+), 11 deletions(-)\r
89 \r
90 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
91 index 2baae5f..ff8149b 100644\r
92 --- a/emacs/notmuch-mua.el\r
93 +++ b/emacs/notmuch-mua.el\r
94 @@ -28,6 +28,8 @@\r
95  \r
96  (eval-when-compile (require 'cl))\r
97  \r
98 +(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth &optional hide))\r
99 +\r
100  ;;\r
101  \r
102  (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)\r
103 @@ -128,12 +130,15 @@ list."\r
104           collect part))\r
105  \r
106  (defun notmuch-mua-insert-quotable-part (message part)\r
107 -  (save-restriction\r
108 -    (narrow-to-region (point) (point))\r
109 -    (notmuch-mm-display-part-inline message part (plist-get part :id)\r
110 -                                   (plist-get part :content-type)\r
111 -                                   notmuch-show-process-crypto)\r
112 -    (goto-char (point-max))))\r
113 +  ;; We don't want text properties leaking from the show renderer into\r
114 +  ;; the reply so we use a temp buffer. Also we don't want hooks, such\r
115 +  ;; as notmuch-wash-*, to be run on the quotable part so we set\r
116 +  ;; notmuch-show-insert-text/plain-hook to nil.\r
117 +  (insert (with-temp-buffer\r
118 +           (let ((notmuch-show-insert-text/plain-hook nil))\r
119 +             ;; Show the part but do not add buttons.\r
120 +             (notmuch-show-insert-bodypart message part 0 'no-buttons))\r
121 +           (buffer-substring-no-properties (point-min) (point-max)))))\r
122  \r
123  ;; There is a bug in emacs 23's message.el that results in a newline\r
124  ;; not being inserted after the References header, so the next header\r
125 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
126 index 2896aae..904b98e 100644\r
127 --- a/emacs/notmuch-show.el\r
128 +++ b/emacs/notmuch-show.el\r
129 @@ -844,7 +844,11 @@ message at DEPTH in the current thread."\r
130  (defun notmuch-show-insert-bodypart (msg part depth &optional hide)\r
131    "Insert the body part PART at depth DEPTH in the current thread.\r
132  \r
133 -If HIDE is non-nil then initially hide this part."\r
134 +HIDE determines whether to show or hide the part and the button\r
135 +as follows: If HIDE is nil, show the part and the button. If HIDE\r
136 +is t, hide the part initially and show the button. If HIDE is\r
137 +'no-buttons, show the part but do not add any buttons (this is\r
138 +useful for quoting in replies)."\r
139  \r
140    (let* ((content-type (downcase (plist-get part :content-type)))\r
141          (mime-type (or (and (string= content-type "application/octet-stream")\r
142 @@ -854,15 +858,19 @@ If HIDE is non-nil then initially hide this part."\r
143                         content-type))\r
144          (nth (plist-get part :id))\r
145          (beg (point))\r
146 -        ;; We omit the part button for the first (or only) part if this is text/plain.\r
147 -        (button (unless (and (string= mime-type "text/plain") (<= nth 1))\r
148 +        ;; Hide the part initially if HIDE is t.\r
149 +        (show-part (not (equal hide t)))\r
150 +        ;; We omit the part button for the first (or only) part if\r
151 +        ;; this is text/plain, or HIDE is 'no-buttons.\r
152 +        (button (unless (or (equal hide 'no-buttons)\r
153 +                            (and (string= mime-type "text/plain") (<= nth 1)))\r
154                    (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))\r
155          (content-beg (point)))\r
156  \r
157      ;; Store the computed mime-type for later use (e.g. by attachment handlers).\r
158      (plist-put part :computed-type mime-type)\r
159  \r
160 -    (if (not hide)\r
161 +    (if show-part\r
162          (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)\r
163        (button-put button :notmuch-lazy-part\r
164                    (list msg part mime-type nth depth button)))\r
165 @@ -875,7 +883,7 @@ If HIDE is non-nil then initially hide this part."\r
166        (insert "\n"))\r
167      ;; We do not create the overlay for hidden (lazy) parts until\r
168      ;; they are inserted.\r
169 -    (if (not hide)\r
170 +    (if show-part\r
171         (notmuch-show-create-part-overlays button content-beg (point))\r
172        (save-excursion\r
173         (notmuch-show-toggle-part-invisibility button)))\r
174 -- \r
175 1.8.4.rc3\r
176 \r