Re: [PATCH 1/3] Adding an S-expression structured output printer.
[notmuch-archives.git] / 47 / 0545517d3033aaaf408186debb3f0ef684c314
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 38A64429E3B\r
6         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:38:19 -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 Vsmwy80TgiSq for <notmuch@notmuchmail.org>;\r
18         Mon, 16 Jan 2012 13:38:18 -0800 (PST)\r
19 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
20         [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 3E067429E35\r
23         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:38:18 -0800 (PST)\r
24 Received: by wibhr12 with SMTP id hr12so2856430wib.26\r
25         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:38:16 -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=bSqktpaw0Qj/uqiS+bZKqqkMbjsjE4tPx7wTmn2xVgc=;\r
29         b=oH02X+H+uKaEjRpTY2sKjZqSH1xuGcviaFFadDNDX1SFS/PqiUc5Vq2IswKcKgO9h3\r
30         5safu+E/RZeGhLofrgB+RAodixNVMUGD4uFZS+P/z8qHSMdA1XYKKVkTMMMn1LWzBg2o\r
31         PtnzV1oWD6o8aJGUvFdyjPjQvBDOJTvDQHKrE=\r
32 Received: by 10.180.86.5 with SMTP id l5mr23235588wiz.17.1326749896751;\r
33         Mon, 16 Jan 2012 13:38:16 -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  fv6sm36977689wib.8.2012.01.16.13.38.15 (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Mon, 16 Jan 2012 13:38:16 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v2] Make buttons for attachments allow viewing as well as\r
41         saving\r
42 Date: Mon, 16 Jan 2012 21:38:30 +0000\r
43 Message-Id: <1326749910-30437-1-git-send-email-markwalters1009@gmail.com>\r
44 X-Mailer: git-send-email 1.7.2.3\r
45 In-Reply-To: <87obu3fhyz.fsf@qmul.ac.uk>\r
46 References: <87obu3fhyz.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: Mon, 16 Jan 2012 21:38:19 -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 |   89 +++++++++++++++++++++++++++++++++++++++---------\r
77  1 files changed, 72 insertions(+), 17 deletions(-)\r
78 \r
79 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
80 index 03c1f6b..6935525 100644\r
81 --- a/emacs/notmuch-show.el\r
82 +++ b/emacs/notmuch-show.el\r
83 @@ -281,10 +281,21 @@ message at DEPTH in the current thread."\r
84         (run-hooks 'notmuch-show-markup-headers-hook)))))\r
85  \r
86  (define-button-type 'notmuch-show-part-button-type\r
87 -  'action 'notmuch-show-part-button-action\r
88 +  'action 'notmuch-show-part-button-default\r
89 +  'keymap 'notmuch-show-part-button-map\r
90    'follow-link t\r
91    'face 'message-mml)\r
92  \r
93 +(defvar notmuch-show-part-button-map\r
94 +  (let ((map (make-sparse-keymap)))\r
95 +       (set-keymap-parent map button-map)\r
96 +       (define-key map "s" 'notmuch-show-part-button-save)\r
97 +       (define-key map "v" 'notmuch-show-part-button-view)\r
98 +       (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
99 +    map)\r
100 +  "Submap for button commands")\r
101 +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
102 +\r
103  (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
104    (let ((button))\r
105      (setq button\r
106 @@ -299,29 +310,43 @@ message at DEPTH in the current thread."\r
107                    " ]")\r
108            :type 'notmuch-show-part-button-type\r
109            :notmuch-part nth\r
110 -          :notmuch-filename name))\r
111 +          :notmuch-filename name\r
112 +          :notmuch-content-type content-type))\r
113      (insert "\n")\r
114      ;; return button\r
115      button))\r
116  \r
117  ;; Functions handling particular MIME parts.\r
118  \r
119 +;; this function is kept for the tests and any external users\r
120  (defun notmuch-show-save-part (message-id nth &optional filename)\r
121 +  (notmuch-show-part-action 'notmuch-show-part-save-action message-id nth nil filename))\r
122 +\r
123 +(defun notmuch-show-part-action (action message-id nth content-type &optional filename)\r
124    (let ((process-crypto notmuch-show-process-crypto))\r
125      (with-temp-buffer\r
126        (setq notmuch-show-process-crypto process-crypto)\r
127        ;; Always acquires the part via `notmuch part', even if it is\r
128        ;; available in the JSON output.\r
129        (insert (notmuch-show-get-bodypart-internal message-id nth))\r
130 -      (let ((file (read-file-name\r
131 -                  "Filename to save as: "\r
132 -                  (or mailcap-download-directory "~/")\r
133 -                  nil nil\r
134 -                  filename)))\r
135 -       ;; Don't re-compress .gz & al.  Arguably we should make\r
136 -       ;; `file-name-handler-alist' nil, but that would chop\r
137 -       ;; ange-ftp, which is reasonable to use here.\r
138 -       (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))\r
139 +      (cond ((eq action 'notmuch-show-part-save-action)\r
140 +            (let ((file (read-file-name\r
141 +                         "Filename to save as: "\r
142 +                         (or mailcap-download-directory "~/")\r
143 +                         nil nil\r
144 +                         filename)))\r
145 +              ;; Don't re-compress .gz & al.  Arguably we should make\r
146 +              ;; `file-name-handler-alist' nil, but that would chop\r
147 +              ;; ange-ftp, which is reasonable to use here.\r
148 +              (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))\r
149 +           ((eq action 'notmuch-show-part-view-action)\r
150 +            ;; set mm-inlined-types to nil to force an external viewer\r
151 +            (let ((handle (mm-make-handle (current-buffer) (list content-type)))\r
152 +                  (mm-inlined-types nil))\r
153 +              (mm-display-part handle)))\r
154 +           ((eq action 'notmuch-show-part-interactively-view-action)\r
155 +            (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
156 +              (mm-interactively-view-part handle)))))))\r
157  \r
158  (defun notmuch-show-mm-display-part-inline (msg part nth content-type)\r
159    "Use the mm-decode/mm-view functions to display a part in the\r
160 @@ -1502,12 +1527,42 @@ buffer."\r
161  \r
162  ;; Commands typically bound to buttons.\r
163  \r
164 -(defun notmuch-show-part-button-action (button)\r
165 -  (let ((nth (button-get button :notmuch-part)))\r
166 -    (if nth\r
167 -       (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
168 -                               (button-get button :notmuch-filename))\r
169 -      (message "Not a valid part (is it a fake part?)."))))\r
170 +(defcustom notmuch-show-part-button-default-action 'notmuch-show-part-save-action\r
171 +  "Default part header button action (on ENTER or mouse click)."\r
172 +  :group 'notmuch\r
173 +  :type '(choice (const :tag "Save part"\r
174 +                       notmuch-show-part-save-action)\r
175 +                (const :tag "View part"\r
176 +                       notmuch-show-part-view-action)\r
177 +                (const :tag "View interactively"\r
178 +                       notmuch-show-part-interactively-view-action)))\r
179 +\r
180 +(defun notmuch-show-part-button-default (&optional button)\r
181 +  (interactive)\r
182 +  (notmuch-show-part-button notmuch-show-part-button-default-action button))\r
183 +\r
184 +(defun notmuch-show-part-button-save (&optional button)\r
185 +  (interactive)\r
186 +  (notmuch-show-part-button 'notmuch-show-part-save-action button))\r
187 +\r
188 +(defun notmuch-show-part-button-view (&optional button)\r
189 +  (interactive)\r
190 +  (notmuch-show-part-button 'notmuch-show-part-view-action button))\r
191 +\r
192 +(defun notmuch-show-part-button-interactively-view (&optional button)\r
193 +  (interactive)\r
194 +  (notmuch-show-part-button 'notmuch-show-part-interactively-view-action button))\r
195 +\r
196 +(defun notmuch-show-part-button (action &optional button)\r
197 +  (interactive)\r
198 +  (let ((button (or button (button-at (point)))))\r
199 +    (if button\r
200 +      (let ((nth (button-get button :notmuch-part)))\r
201 +       (if nth\r
202 +           (notmuch-show-part-action action (notmuch-show-get-message-id) nth\r
203 +                                   (button-get button :notmuch-content-type)\r
204 +                                   (button-get button :notmuch-filename))\r
205 +         (message "Not a valid part (is it a fake part?)."))))))\r
206  \r
207  ;;\r
208  \r
209 -- \r
210 1.7.2.3\r
211 \r