Re: Question re undo
[notmuch-archives.git] / 48 / fa19e532a312175d525935c2cc5eb36cbaa6e7
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 A2657429E5F\r
6         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 15:53:33 -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.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 Egu9nNRoAjY3 for <notmuch@notmuchmail.org>;\r
16         Tue, 17 Jan 2012 15:53:32 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id B890A429E27\r
20         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 15:53:32 -0800 (PST)\r
21 X-AuditID: 12074422-b7fd66d0000008f9-ff-4f1609fc9874\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 91.B6.02297.CF9061F4; Tue, 17 Jan 2012 18:53:32 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q0HNrVqE014300; \r
27         Tue, 17 Jan 2012 18:53:32 -0500\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 q0HNrU9L021213\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Tue, 17 Jan 2012 18:53:31 -0500 (EST)\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 1RnIq6-0008Ki-Db; Tue, 17 Jan 2012 18:53:18 -0500\r
37 Date: Tue, 17 Jan 2012 18:53:18 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Mark Walters <markwalters1009@gmail.com>\r
40 Subject: Re: [PATCH v3] Make buttons for attachments allow viewing as well as\r
41         saving\r
42 Message-ID: <20120117235318.GZ16740@mit.edu>\r
43 References: <87lip5rj43.fsf@qmul.ac.uk>\r
44         <1326843886-18387-1-git-send-email-markwalters1009@gmail.com>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 Content-Disposition: inline\r
48 In-Reply-To: <1326843886-18387-1-git-send-email-markwalters1009@gmail.com>\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT0f3DKeZv8GgHp8XquTwW12/OZHZg\r
52         8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Ms7+/8tUMNWi4nyvTwPjAt0uRk4OCQETic3d\r
53         89ghbDGJC/fWs3UxcnEICexjlPh0eycThLOBUWLZwSesEM5JJokTP+exQDhLGCV+/ZnKAtLP\r
54         IqAq8eLLDWYQm01AQ2Lb/uWMILaIgI7E7UMLwHYwC0hLfPvdzARiCwuESXxt3g5WzwtU8/To\r
55         WrAaIYF0iX/rz7FCxAUlTs58wgLRqyVx499LoF4OsDnL/3GAhDkFvCTeHpkLNkZUQEViyslt\r
56         bBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuqZ6uZkleqkppZsYwUHt\r
57         orSD8edBpUOMAhyMSjy8BZtE/YVYE8uKK3MPMUpyMCmJ8k5mF/MX4kvKT6nMSCzOiC8qzUkt\r
58         PsQowcGsJMLLygyU401JrKxKLcqHSUlzsCiJ86prvfMD+jexJDU7NbUgtQgmK8PBoSTBe4QD\r
59         qFGwKDU9tSItM6cEIc3EwQkynAdoeCfIYt7igsTc4sx0iPwpRkUpcV4FYNoQEgBJZJTmwfXC\r
60         ks4rRnGgV4R5dUGqeIAJC677FdBgJqDBOa1CIINLEhFSUg2ME1dqVp6SfintM/OE4LMt1f7c\r
61         oSd5n2tr1/PEndO9+pmtY8b21JvFWx/xt8h2bpmWcUX6YXXMBB32jqD8gB1WU2MvvKmYbPJa\r
62         /LDh5gkMMYfY1rNe/FrJeEU7uOT4lmiDnY/PbGA7dPL5ssk6ElUMMzJ8w/6Y6bFnLyi9Xp2n\r
63         7PL5M4vMDzcWJZbijERDLeai4kQAtJPkvRUDAAA=\r
64 Cc: notmuch@notmuchmail.org\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Tue, 17 Jan 2012 23:53:33 -0000\r
78 \r
79 Quoth Mark Walters on Jan 17 at 11:44 pm:\r
80 > Define a keymap for attachment buttons to allow multiple actions.\r
81 > Define 3 possible actions:\r
82 >     save attachment: exactly as currently,\r
83 >     view attachment: uses mailcap entry,\r
84 >     view attachment with user chosen program\r
85\r
86 > Keymap on a button is: s for save, v for view and o for view with\r
87 > other program. Default (i.e. enter or mouse button) is save but this\r
88 > is configurable in notmuch customize.\r
89\r
90 > One implementation detail: the view attachment function forces all\r
91 > attachments to be "displayed" using mailcap even if emacs could\r
92 > display them itself. Thus, for example, text/html appears in a browser\r
93 > and text/plain asks whether to save (on a standard debian setup)\r
94 \r
95 Oof, sorry.  Two more tweaks that I really should have caught in the\r
96 previous version.  After that this gets my automatic +1.\r
97 \r
98 > ---\r
99 >  emacs/notmuch-show.el |  106 ++++++++++++++++++++++++++++++++++++++-----------\r
100 >  1 files changed, 82 insertions(+), 24 deletions(-)\r
101\r
102 > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
103 > index 03c1f6b..0aaaf79 100644\r
104 > --- a/emacs/notmuch-show.el\r
105 > +++ b/emacs/notmuch-show.el\r
106 > @@ -281,10 +281,21 @@ message at DEPTH in the current thread."\r
107 >       (run-hooks 'notmuch-show-markup-headers-hook)))))\r
108 >  \r
109 >  (define-button-type 'notmuch-show-part-button-type\r
110 > -  'action 'notmuch-show-part-button-action\r
111 > +  'action 'notmuch-show-part-button-default\r
112 > +  'keymap 'notmuch-show-part-button-map\r
113 >    'follow-link t\r
114 >    'face 'message-mml)\r
115 >  \r
116 > +(defvar notmuch-show-part-button-map\r
117 > +  (let ((map (make-sparse-keymap)))\r
118 > +       (set-keymap-parent map button-map)\r
119 > +       (define-key map "s" 'notmuch-show-part-button-save)\r
120 > +       (define-key map "v" 'notmuch-show-part-button-view)\r
121 > +       (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
122 \r
123 Indentation.\r
124 \r
125 > +    map)\r
126 > +  "Submap for button commands")\r
127 > +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
128 > +\r
129 >  (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
130 >    (let ((button))\r
131 >      (setq button\r
132 > @@ -299,29 +310,48 @@ message at DEPTH in the current thread."\r
133 >                  " ]")\r
134 >          :type 'notmuch-show-part-button-type\r
135 >          :notmuch-part nth\r
136 > -        :notmuch-filename name))\r
137 > +        :notmuch-filename name\r
138 > +        :notmuch-content-type content-type))\r
139 >      (insert "\n")\r
140 >      ;; return button\r
141 >      button))\r
142 >  \r
143 >  ;; Functions handling particular MIME parts.\r
144 >  \r
145 > -(defun notmuch-show-save-part (message-id nth &optional filename)\r
146 > -  (let ((process-crypto notmuch-show-process-crypto))\r
147 > -    (with-temp-buffer\r
148 > -      (setq notmuch-show-process-crypto process-crypto)\r
149 > -      ;; Always acquires the part via `notmuch part', even if it is\r
150 > -      ;; available in the JSON output.\r
151 > -      (insert (notmuch-show-get-bodypart-internal message-id nth))\r
152 > -      (let ((file (read-file-name\r
153 > -                "Filename to save as: "\r
154 > -                (or mailcap-download-directory "~/")\r
155 > -                nil nil\r
156 > -                filename)))\r
157 > -     ;; Don't re-compress .gz & al.  Arguably we should make\r
158 > -     ;; `file-name-handler-alist' nil, but that would chop\r
159 > -     ;; ange-ftp, which is reasonable to use here.\r
160 > -     (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))\r
161 > +(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
162 > +  (declare (indent 2))\r
163 > +  (let ((process-crypto (make-symbol "process-crypto")))\r
164 > +    `(let ((,process-crypto notmuch-show-process-crypto))\r
165 > +       (with-temp-buffer\r
166 > +      (setq notmuch-show-process-crypto ,process-crypto)\r
167 > +      ;; Always acquires the part via `notmuch part', even if it is\r
168 > +      ;; available in the JSON output.\r
169 > +      (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
170 > +      ,@body))))\r
171 > +\r
172 > +(defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
173 > +  (notmuch-with-temp-part-buffer message-id nth\r
174 > +    (let ((file (read-file-name\r
175 > +              "Filename to save as: "\r
176 > +              (or mailcap-download-directory "~/")\r
177 > +              nil nil\r
178 > +              filename)))\r
179 > +      ;; Don't re-compress .gz & al.  Arguably we should make\r
180 > +      ;; `file-name-handler-alist' nil, but that would chop\r
181 > +      ;; ange-ftp, which is reasonable to use here.\r
182 > +      (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))\r
183 > +\r
184 > +(defun notmuch-show-view-part (message-id nth &optional filename content-type )\r
185 > +  (notmuch-with-temp-part-buffer message-id nth\r
186 > +    ;; set mm-inlined-types to nil to force an external viewer\r
187 > +    (let ((handle (mm-make-handle (current-buffer) (list content-type)))\r
188 > +       (mm-inlined-types nil))\r
189 > +      (mm-display-part handle t))))\r
190 > +\r
191 > +(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)\r
192 > +  (notmuch-with-temp-part-buffer message-id nth\r
193 > +    (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
194 > +      (mm-interactively-view-part handle))))\r
195 >  \r
196 >  (defun notmuch-show-mm-display-part-inline (msg part nth content-type)\r
197 >    "Use the mm-decode/mm-view functions to display a part in the\r
198 > @@ -1502,12 +1532,40 @@ buffer."\r
199 >  \r
200 >  ;; Commands typically bound to buttons.\r
201 >  \r
202 > -(defun notmuch-show-part-button-action (button)\r
203 > -  (let ((nth (button-get button :notmuch-part)))\r
204 > -    (if nth\r
205 > -     (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
206 > -                             (button-get button :notmuch-filename))\r
207 > -      (message "Not a valid part (is it a fake part?)."))))\r
208 > +(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part\r
209 > +  "Default part header button action (on ENTER or mouse click)."\r
210 > +  :group 'notmuch\r
211 > +  :type '(choice (const :tag "Save part"\r
212 > +                     notmuch-show-save-part)\r
213 > +              (const :tag "View part"\r
214 > +                     notmuch-show-view-part)\r
215 > +              (const :tag "View interactively"\r
216 > +                     notmuch-show-interactively-view-part)))\r
217 \r
218 defcustoms customarily appear at the top of the file (see the rest of\r
219 the defcustoms in notmuch-show.el)\r
220 \r
221 > +\r
222 > +(defun notmuch-show-part-button-default (&optional button)\r
223 > +  (interactive)\r
224 > +  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))\r
225 > +\r
226 > +(defun notmuch-show-part-button-save (&optional button)\r
227 > +  (interactive)\r
228 > +  (notmuch-show-part-button-internal button #'notmuch-show-save-part))\r
229 > +\r
230 > +(defun notmuch-show-part-button-view (&optional button)\r
231 > +  (interactive)\r
232 > +  (notmuch-show-part-button-internal button #'notmuch-show-view-part))\r
233 > +\r
234 > +(defun notmuch-show-part-button-interactively-view (&optional button)\r
235 > +  (interactive)\r
236 > +  (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))\r
237 > +\r
238 > +(defun notmuch-show-part-button-internal (button handler)\r
239 > +  (let ((button (or button (button-at (point)))))\r
240 > +    (if button\r
241 > +     (let ((nth (button-get button :notmuch-part)))\r
242 > +       (if nth\r
243 > +           (funcall handler (notmuch-show-get-message-id) nth\r
244 > +                    (button-get button :notmuch-filename)\r
245 > +                    (button-get button :notmuch-content-type)))))))\r
246 >  \r
247 >  ;;\r
248 >  \r