Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f1 / 7e1d4cddf80a57f992dd1d61c796132171f59e
1 Return-Path: <markwalters1009@gmail.com>\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 E5191431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 20 Jan 2012 01:43:24 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id vUo5Ch3C3ctx for <notmuch@notmuchmail.org>;\r
18         Fri, 20 Jan 2012 01:43:24 -0800 (PST)\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
20  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  D9D1B431FAE    for <notmuch@notmuchmail.org>; Fri, 20 Jan 2012 01:43:23 -0800\r
23  (PST)\r
24 Received: by wgbdt12 with SMTP id dt12so305208wgb.2\r
25         for <notmuch@notmuchmail.org>; Fri, 20 Jan 2012 01:43:21 -0800 (PST)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=av3iizgANb2tz2L1bvavam5oKQWwSY8NSt6Iyk69QHg=;\r
29         b=J133XU0LLd8HWqjnRdDwDg4luA8dManF7/gfm6Vlje3LXlSetTQAqgrWdzX101Ha0P\r
30         8jZZvMf1n0fM4p0cwaQJz0ZwA3cSsnqssSWEi8B2Tx9eRZ3d9REATrzXb+a7jadLx5T2\r
31         kft+DSwDuOhtLPVbPZOyHhFcQAGXScuCTTQ5Y=\r
32 Received: by 10.180.91.201 with SMTP id cg9mr50506607wib.15.1327052601319;\r
33         Fri, 20 Jan 2012 01:43:21 -0800 (PST)\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
35  [94.192.233.223])      by mx.google.com with ESMTPS id\r
36  fy5sm7176826wib.7.2012.01.20.01.43.19  (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Fri, 20 Jan 2012 01:43:20 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v5] Make buttons for attachments allow viewing as well as\r
41         saving\r
42 Date: Fri, 20 Jan 2012 09:44:06 +0000\r
43 Message-Id: <1327052646-3422-1-git-send-email-markwalters1009@gmail.com>\r
44 X-Mailer: git-send-email 1.7.2.3\r
45 In-Reply-To: <877h0mww05.fsf@qmul.ac.uk>\r
46 References: <877h0mww05.fsf@qmul.ac.uk>\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Fri, 20 Jan 2012 09:43:25 -0000\r
60 \r
61 Define a keymap for attachment buttons to allow multiple actions.\r
62 Define 3 possible actions:\r
63     save attachment: exactly as currently,\r
64     view attachment: uses mailcap entry,\r
65     view attachment with user chosen program\r
66 \r
67 Keymap on a button is: s for save, v for view and o for view with\r
68 other program. Default (i.e. enter or mouse button) is save but this\r
69 is configurable in notmuch customize.\r
70 \r
71 One implementation detail: the view attachment function forces all\r
72 attachments to be "displayed" using mailcap even if emacs could\r
73 display them itself. Thus, for example, text/html appears in a browser\r
74 and text/plain asks whether to save (on a standard debian setup)\r
75 ---\r
76  emacs/notmuch-show.el |  116 ++++++++++++++++++++++++++++++++++++++----------\r
77  1 files changed, 92 insertions(+), 24 deletions(-)\r
78 \r
79 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
80 index fc13462..6229432 100644\r
81 --- a/emacs/notmuch-show.el\r
82 +++ b/emacs/notmuch-show.el\r
83 @@ -112,6 +112,16 @@ indentation."\r
84    :type 'boolean\r
85    :group 'notmuch-show)\r
86  \r
87 +(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part\r
88 +  "Default part header button action (on ENTER or mouse click)."\r
89 +  :group 'notmuch-show\r
90 +  :type '(choice (const :tag "Save part"\r
91 +                       notmuch-show-save-part)\r
92 +                (const :tag "View part"\r
93 +                       notmuch-show-view-part)\r
94 +                (const :tag "View interactively"\r
95 +                       notmuch-show-interactively-view-part)))\r
96 +\r
97  (defmacro with-current-notmuch-show-message (&rest body)\r
98    "Evaluate body with current buffer set to the text of current message"\r
99    `(save-excursion\r
100 @@ -283,10 +293,21 @@ message at DEPTH in the current thread."\r
101         (run-hooks 'notmuch-show-markup-headers-hook)))))\r
102  \r
103  (define-button-type 'notmuch-show-part-button-type\r
104 -  'action 'notmuch-show-part-button-action\r
105 +  'action 'notmuch-show-part-button-default\r
106 +  'keymap 'notmuch-show-part-button-map\r
107    'follow-link t\r
108    'face 'message-mml)\r
109  \r
110 +(defvar notmuch-show-part-button-map\r
111 +  (let ((map (make-sparse-keymap)))\r
112 +    (set-keymap-parent map button-map)\r
113 +    (define-key map "s" 'notmuch-show-part-button-save)\r
114 +    (define-key map "v" 'notmuch-show-part-button-view)\r
115 +    (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
116 +    map)\r
117 +  "Submap for button commands")\r
118 +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
119 +\r
120  (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
121    (let ((button))\r
122      (setq button\r
123 @@ -301,29 +322,58 @@ message at DEPTH in the current thread."\r
124                    " ]")\r
125            :type 'notmuch-show-part-button-type\r
126            :notmuch-part nth\r
127 -          :notmuch-filename name))\r
128 +          :notmuch-filename name\r
129 +          :notmuch-content-type content-type))\r
130      (insert "\n")\r
131      ;; return button\r
132      button))\r
133  \r
134  ;; Functions handling particular MIME parts.\r
135  \r
136 -(defun notmuch-show-save-part (message-id nth &optional filename)\r
137 -  (let ((process-crypto notmuch-show-process-crypto))\r
138 -    (with-temp-buffer\r
139 -      (setq notmuch-show-process-crypto process-crypto)\r
140 -      ;; Always acquires the part via `notmuch part', even if it is\r
141 -      ;; available in the JSON output.\r
142 -      (insert (notmuch-show-get-bodypart-internal message-id nth))\r
143 -      (let ((file (read-file-name\r
144 -                  "Filename to save as: "\r
145 -                  (or mailcap-download-directory "~/")\r
146 -                  nil nil\r
147 -                  filename)))\r
148 -       ;; Don't re-compress .gz & al.  Arguably we should make\r
149 -       ;; `file-name-handler-alist' nil, but that would chop\r
150 -       ;; ange-ftp, which is reasonable to use here.\r
151 -       (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))\r
152 +(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
153 +  (declare (indent 2))\r
154 +  (let ((process-crypto (make-symbol "process-crypto")))\r
155 +    `(let ((,process-crypto notmuch-show-process-crypto))\r
156 +       (with-temp-buffer\r
157 +        (setq notmuch-show-process-crypto ,process-crypto)\r
158 +        ;; Always acquires the part via `notmuch part', even if it is\r
159 +        ;; available in the JSON output.\r
160 +        (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
161 +        ,@body))))\r
162 +\r
163 +(defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
164 +  (notmuch-with-temp-part-buffer message-id nth\r
165 +    (let ((file (read-file-name\r
166 +                "Filename to save as: "\r
167 +                (or mailcap-download-directory "~/")\r
168 +                nil nil\r
169 +                filename)))\r
170 +      ;; Don't re-compress .gz & al.  Arguably we should make\r
171 +      ;; `file-name-handler-alist' nil, but that would chop\r
172 +      ;; ange-ftp, which is reasonable to use here.\r
173 +      (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))\r
174 +\r
175 +(defun notmuch-show-view-part (message-id nth &optional filename content-type )\r
176 +  (notmuch-with-temp-part-buffer message-id nth\r
177 +    ;; set mm-inlined-types to nil to force an external viewer\r
178 +    (let ((handle (mm-make-handle (current-buffer) (list content-type)))\r
179 +         (mm-inlined-types nil))\r
180 +      ;; We override mm-save-part as notmuch-show-save-part is better\r
181 +      ;; since it offers the filename. We need to lexically bind\r
182 +      ;; everything we need for notmuch-show-save-part to prevent\r
183 +      ;; potential dynamic shadowing.\r
184 +      (lexical-let ((message-id message-id)\r
185 +                   (nth nth)\r
186 +                   (filename filename)\r
187 +                   (content-type content-type))\r
188 +       (flet ((mm-save-part (&rest args) (notmuch-show-save-part\r
189 +                                          message-id nth filename content-type)))\r
190 +         (mm-display-part handle))))))\r
191 +\r
192 +(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)\r
193 +  (notmuch-with-temp-part-buffer message-id nth\r
194 +    (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
195 +      (mm-interactively-view-part handle))))\r
196  \r
197  (defun notmuch-show-mm-display-part-inline (msg part nth content-type)\r
198    "Use the mm-decode/mm-view functions to display a part in the\r
199 @@ -1504,12 +1554,30 @@ buffer."\r
200  \r
201  ;; Commands typically bound to buttons.\r
202  \r
203 -(defun notmuch-show-part-button-action (button)\r
204 -  (let ((nth (button-get button :notmuch-part)))\r
205 -    (if nth\r
206 -       (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
207 -                               (button-get button :notmuch-filename))\r
208 -      (message "Not a valid part (is it a fake part?)."))))\r
209 +(defun notmuch-show-part-button-default (&optional button)\r
210 +  (interactive)\r
211 +  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))\r
212 +\r
213 +(defun notmuch-show-part-button-save (&optional button)\r
214 +  (interactive)\r
215 +  (notmuch-show-part-button-internal button #'notmuch-show-save-part))\r
216 +\r
217 +(defun notmuch-show-part-button-view (&optional button)\r
218 +  (interactive)\r
219 +  (notmuch-show-part-button-internal button #'notmuch-show-view-part))\r
220 +\r
221 +(defun notmuch-show-part-button-interactively-view (&optional button)\r
222 +  (interactive)\r
223 +  (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))\r
224 +\r
225 +(defun notmuch-show-part-button-internal (button handler)\r
226 +  (let ((button (or button (button-at (point)))))\r
227 +    (if button\r
228 +       (let ((nth (button-get button :notmuch-part)))\r
229 +         (if nth\r
230 +             (funcall handler (notmuch-show-get-message-id) nth\r
231 +                      (button-get button :notmuch-filename)\r
232 +                      (button-get button :notmuch-content-type)))))))\r
233  \r
234  ;;\r
235  \r
236 -- \r
237 1.7.2.3\r
238 \r