Re: [PATCH v4 3/5] Use the S-Expression structured printer in notmuch-show, notmuch...
[notmuch-archives.git] / ae / 12a862b81de09e1d1bdaa54aaeaf572c69cd0d
1 Return-Path: <dme@dme.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 4945C431FAF\r
6         for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 22:21:49 -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 jYfvQOpyu5lp for <notmuch@notmuchmail.org>;\r
16         Tue,  7 Feb 2012 22:21:45 -0800 (PST)\r
17 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
18  [74.125.83.53])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  A84A7431FAE    for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 22:21:44 -0800\r
21  (PST)\r
22 Received: by eeke51 with SMTP id e51so101098eek.26\r
23         for <notmuch@notmuchmail.org>; Tue, 07 Feb 2012 22:21:42 -0800 (PST)\r
24 Received: by 10.14.17.213 with SMTP id j61mr8118761eej.110.1328682102748;\r
25         Tue, 07 Feb 2012 22:21:42 -0800 (PST)\r
26 Received: from hotblack-desiato.hh.sledj.net\r
27         (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
28         by mx.google.com with ESMTPS id z47sm1595473eeh.9.2012.02.07.22.21.40\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Tue, 07 Feb 2012 22:21:41 -0800 (PST)\r
31 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
32         id AF6C0A37F7; Wed,  8 Feb 2012 06:21:38 +0000 (GMT)\r
33 To: Austin Clements <amdragon@MIT.EDU>\r
34 Subject: Re: [PATCH v7 1/8] emacs: Rework crypto switch toggle.\r
35 In-Reply-To: <20120208051016.GB27039@mit.edu>\r
36 References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
37         <1328520082-26659-1-git-send-email-dme@dme.org>\r
38         <1328520082-26659-2-git-send-email-dme@dme.org>\r
39         <20120208051016.GB27039@mit.edu>\r
40 User-Agent: Notmuch/0.11.1+153~gdd83b99 (http://notmuchmail.org)\r
41         Emacs/24.0.92.1 (x86_64-pc-linux-gnu)\r
42 From: David Edmondson <dme@dme.org>\r
43 Date: Wed, 08 Feb 2012 06:21:34 +0000\r
44 Message-ID: <cunvcnh3kwh.fsf@hotblack-desiato.hh.sledj.net>\r
45 MIME-Version: 1.0\r
46 Content-Type: multipart/signed; boundary="=-=-=";\r
47         micalg=pgp-sha1; protocol="application/pgp-signature"\r
48 Cc: notmuch@notmuchmail.org\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Wed, 08 Feb 2012 06:21:53 -0000\r
62 \r
63 --=-=-=\r
64 Content-Type: text/plain\r
65 Content-Transfer-Encoding: quoted-printable\r
66 \r
67 On Wed, 8 Feb 2012 00:10:16 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
68 > Seems reasonable.  I'm definitely in favor of erasing buffers instead\r
69 > of killing and recreating them.  Two questions below.\r
70 \r
71 Thanks for the review.\r
72 \r
73 > Quoth David Edmondson on Feb 06 at  9:21 am:\r
74 > > Re-work the existing crypto switch toggle to be based on a persistant\r
75 > > buffer-local variable.\r
76 > >=20\r
77 > > To allow this, modify `notmuch-show-refresh-view' to erase and re-draw\r
78 > > in the current buffer rather than killing the current buffer and\r
79 > > creating a new one. (This will also allow more per-buffer behaviour in\r
80 > > future patches.)\r
81 > >=20\r
82 > > Add a binding ('$') to toggle crypto processing of the current buffer\r
83 > > and remove the prefix argument approach that achieves a similar\r
84 > > result.\r
85 > > ---\r
86 > >  emacs/notmuch-show.el |  126 ++++++++++++++++++++++++-----------------=\r
87 -------\r
88 > >  emacs/notmuch.el      |    7 +--\r
89 > >  2 files changed, 66 insertions(+), 67 deletions(-)\r
90 > >=20\r
91 > > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
92 > > index 7469e2e..4b29dbd 100644\r
93 > > --- a/emacs/notmuch-show.el\r
94 > > +++ b/emacs/notmuch-show.el\r
95 > > @@ -125,6 +125,22 @@ indentation."\r
96 > >              (const :tag "View interactively"\r
97 > >                     notmuch-show-interactively-view-part)))\r
98 > >=20=20\r
99 > > +(defvar notmuch-show-thread-id nil)\r
100 > > +(make-variable-buffer-local 'notmuch-show-thread-id)\r
101 > > +(put 'notmuch-show-thread-id 'permanent-local t)\r
102 > > +\r
103 > > +(defvar notmuch-show-parent-buffer nil)\r
104 > > +(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
105 > > +(put 'notmuch-show-parent-buffer 'permanent-local t)\r
106 > > +\r
107 > > +(defvar notmuch-show-query-context nil)\r
108 > > +(make-variable-buffer-local 'notmuch-show-query-context)\r
109 > > +(put 'notmuch-show-query-context 'permanent-local t)\r
110 > > +\r
111 > > +(defvar notmuch-show-process-crypto nil)\r
112 > > +(make-variable-buffer-local 'notmuch-show-process-crypto)\r
113 > > +(put 'notmuch-show-process-crypto 'permanent-local t)\r
114 > > +\r
115 >=20\r
116 > Do these need to be permanent-local given that refreshing is now done\r
117 > by erasing the buffer instead of killing it?\r
118 \r
119 Yes. `notmuch-show-worker' (which does the refreshing) still calls\r
120 `notmuch-show-mode', which still calls `kill-all-local-variables'.\r
121 \r
122 Tidying that is for another patch.\r
123 \r
124 > >  (defmacro with-current-notmuch-show-message (&rest body)\r
125 > >    "Evaluate body with current buffer set to the text of current messag=\r
126 e"\r
127 > >    `(save-excursion\r
128 > > @@ -421,14 +437,11 @@ message at DEPTH in the current thread."\r
129 > >=20=20\r
130 > >  (defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
131 > >    (declare (indent 2))\r
132 > > -  (let ((process-crypto (make-symbol "process-crypto")))\r
133 > > -    `(let ((,process-crypto notmuch-show-process-crypto))\r
134 > > -       (with-temp-buffer\r
135 > > -    (setq notmuch-show-process-crypto ,process-crypto)\r
136 > > -    ;; Always acquires the part via `notmuch part', even if it is\r
137 > > -    ;; available in the JSON output.\r
138 > > -    (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
139 > > -    ,@body))))\r
140 > > +  `(with-temp-buffer\r
141 > > +     ;; Always acquires the part via `notmuch part', even if it is\r
142 > > +     ;; available in the JSON output.\r
143 > > +     (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
144 > > +     ,@body))\r
145 >=20\r
146 > Why is the piping of notmuch-show-process-crypto no longer necessary?\r
147 > It's still buffer-local, and hence will be nil in the temp buffer.\r
148 \r
149 It's a bug. v8 after breakfast.\r
150 \r
151 > >=20=20\r
152 > >  (defun notmuch-show-save-part (message-id nth &optional filename conte=\r
153 nt-type)\r
154 > >    (notmuch-with-temp-part-buffer message-id nth\r
155 > > @@ -610,7 +623,7 @@ current buffer, if possible."\r
156 > >            (sigstatus (car (plist-get part :sigstatus))))\r
157 > >       (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
158 > >        ;; if we're not adding sigstatus, tell the user how they can get=\r
159  it\r
160 > > -      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
161 o process cryptographic mime parts.")))\r
162 > > +      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
163 o process cryptographic MIME parts.")))\r
164 > >=20=20\r
165 > >    (let ((inner-parts (plist-get part :content))\r
166 > >     (start (point)))\r
167 > > @@ -636,7 +649,7 @@ current buffer, if possible."\r
168 > >                  (sigstatus (car (plist-get part :sigstatus))))\r
169 > >             (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
170 > >        ;; if we're not adding encstatus, tell the user how they can get=\r
171  it\r
172 > > -      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
173 o process cryptographic mime parts.")))\r
174 > > +      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
175 o process cryptographic MIME parts.")))\r
176 > >=20=20\r
177 > >    (let ((inner-parts (plist-get part :content))\r
178 > >     (start (point)))\r
179 > > @@ -763,8 +776,6 @@ current buffer, if possible."\r
180 > >=20=20\r
181 > >  ;; Helper for parts which are generally not included in the default\r
182 > >  ;; JSON output.\r
183 > > -;; Uses the buffer-local variable notmuch-show-process-crypto to\r
184 > > -;; determine if parts should be decrypted first.\r
185 > >  (defun notmuch-show-get-bodypart-internal (message-id part-number)\r
186 > >    (let ((args '("show" "--format=3Draw"))\r
187 > >     (part-arg (format "--part=3D%s" part-number)))\r
188 > > @@ -918,6 +929,15 @@ current buffer, if possible."\r
189 > >      ;; criteria.\r
190 > >      (notmuch-show-message-visible msg (plist-get msg :match))))\r
191 > >=20=20\r
192 > > +(defun notmuch-show-toggle-process-crypto ()\r
193 > > +  "Toggle the processing of cryptographic MIME parts."\r
194 > > +  (interactive)\r
195 > > +  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))\r
196 > > +  (message (if notmuch-show-process-crypto\r
197 > > +          "Processing cryptographic MIME parts."\r
198 > > +        "Not processing cryptographic MIME parts."))\r
199 > > +  (notmuch-show-refresh-view))\r
200 > > +\r
201 > >  (defun notmuch-show-insert-tree (tree depth)\r
202 > >    "Insert the message tree TREE at depth DEPTH in the current thread."\r
203 > >    (let ((msg (car tree))\r
204 > > @@ -933,15 +953,6 @@ current buffer, if possible."\r
205 > >    "Insert the forest of threads FOREST."\r
206 > >    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest=\r
207 ))\r
208 > >=20=20\r
209 > > -(defvar notmuch-show-thread-id nil)\r
210 > > -(make-variable-buffer-local 'notmuch-show-thread-id)\r
211 > > -(defvar notmuch-show-parent-buffer nil)\r
212 > > -(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
213 > > -(defvar notmuch-show-query-context nil)\r
214 > > -(make-variable-buffer-local 'notmuch-show-query-context)\r
215 > > -(defvar notmuch-show-buffer-name nil)\r
216 > > -(make-variable-buffer-local 'notmuch-show-buffer-name)\r
217 > > -\r
218 > >  (defun notmuch-show-buttonise-links (start end)\r
219 > >    "Buttonise URLs and mail addresses between START and END.\r
220 > >=20=20\r
221 > > @@ -961,7 +972,7 @@ a corresponding notmuch search."\r
222 > >                     'face goto-address-mail-face))))\r
223 > >=20=20\r
224 > >  ;;;###autoload\r
225 > > -(defun notmuch-show (thread-id &optional parent-buffer query-context b=\r
226 uffer-name crypto-switch)\r
227 > > +(defun notmuch-show (thread-id &optional parent-buffer query-context b=\r
228 uffer-name)\r
229 > >    "Run \"notmuch show\" with the given thread ID and display results.\r
230 > >=20=20\r
231 > >  The optional PARENT-BUFFER is the notmuch-search buffer from\r
232 > > @@ -976,46 +987,41 @@ non-nil.\r
233 > >  The optional BUFFER-NAME provides the name of the buffer in\r
234 > >  which the message thread is shown. If it is nil (which occurs\r
235 > >  when the command is called interactively) the argument to the\r
236 > > -function is used.\r
237 > > -\r
238 > > -The optional CRYPTO-SWITCH toggles the value of the\r
239 > > -notmuch-crypto-process-mime customization variable for this show\r
240 > > -buffer."\r
241 > > +function is used."\r
242 > >    (interactive "sNotmuch show: ")\r
243 > > -  (let* ((process-crypto (if crypto-switch\r
244 > > -                        (not notmuch-crypto-process-mime)\r
245 > > -                      notmuch-crypto-process-mime)))\r
246 > > -    (notmuch-show-worker thread-id parent-buffer query-context buffer-=\r
247 name process-crypto)))\r
248 > > -\r
249 > > -(defun notmuch-show-worker (thread-id parent-buffer query-context buff=\r
250 er-name process-crypto)\r
251 > > -  (let* ((buffer-name (generate-new-buffer-name\r
252 > > -                  (or buffer-name\r
253 > > -                      (concat "*notmuch-" thread-id "*"))))\r
254 > > -    (buffer (get-buffer-create buffer-name))\r
255 > > -    (inhibit-read-only t))\r
256 > > -    (switch-to-buffer buffer)\r
257 > > +  (let ((buffer-name (generate-new-buffer-name\r
258 > > +                 (or buffer-name\r
259 > > +                     (concat "*notmuch-" thread-id "*")))))\r
260 > > +    (switch-to-buffer (get-buffer-create buffer-name))\r
261 > > +    ;; Set the default value for `notmuch-show-process-crypto' in this\r
262 > > +    ;; buffer.\r
263 > > +    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
264 > > +\r
265 > > +    (setq notmuch-show-thread-id thread-id\r
266 > > +     notmuch-show-parent-buffer parent-buffer\r
267 > > +     notmuch-show-query-context query-context)\r
268 > > +    (notmuch-show-worker)))\r
269 > > +\r
270 > > +(defun notmuch-show-worker ()\r
271 > > +  (let ((inhibit-read-only t))\r
272 > > +\r
273 > >      (notmuch-show-mode)\r
274 > >      ;; Don't track undo information for this buffer\r
275 > >      (set 'buffer-undo-list t)\r
276 > >=20=20\r
277 > > -    (setq notmuch-show-thread-id thread-id)\r
278 > > -    (setq notmuch-show-parent-buffer parent-buffer)\r
279 > > -    (setq notmuch-show-query-context query-context)\r
280 > > -    (setq notmuch-show-buffer-name buffer-name)\r
281 > > -    (setq notmuch-show-process-crypto process-crypto)\r
282 > > -\r
283 > >      (erase-buffer)\r
284 > >      (goto-char (point-min))\r
285 > >      (save-excursion\r
286 > > -      (let* ((basic-args (list thread-id))\r
287 > > -        (args (if query-context\r
288 > > -                  (append (list "\'") basic-args (list "and (" query-context ")=\r
289 \'"))\r
290 > > +      (let* ((basic-args (list notmuch-show-thread-id))\r
291 > > +        (args (if notmuch-show-query-context\r
292 > > +                  (append (list "\'") basic-args\r
293 > > +                          (list "and (" notmuch-show-query-context ")\'"))\r
294 > >                  (append (list "\'") basic-args (list "\'")))))\r
295 > >     (notmuch-show-insert-forest (notmuch-query-get-threads args))\r
296 > >     ;; If the query context reduced the results to nothing, run\r
297 > >     ;; the basic query.\r
298 > >     (when (and (eq (buffer-size) 0)\r
299 > > -              query-context)\r
300 > > +              notmuch-show-query-context)\r
301 > >       (notmuch-show-insert-forest\r
302 > >        (notmuch-query-get-threads basic-args))))\r
303 > >=20=20\r
304 > > @@ -1032,21 +1038,14 @@ buffer."\r
305 > >=20=20\r
306 > >      (notmuch-show-mark-read)))\r
307 > >=20=20\r
308 > > -(defun notmuch-show-refresh-view (&optional crypto-switch)\r
309 > > -  "Refresh the current view (with crypto switch if prefix given).\r
310 > > +(defun notmuch-show-refresh-view ()\r
311 > > +  "Refresh the current view.\r
312 > >=20=20\r
313 > > -Kills the current buffer and reruns notmuch show with the same\r
314 > > -thread id.  If a prefix is given, crypto processing is toggled."\r
315 > > -  (interactive "P")\r
316 > > -  (let ((thread-id notmuch-show-thread-id)\r
317 > > -   (parent-buffer notmuch-show-parent-buffer)\r
318 > > -   (query-context notmuch-show-query-context)\r
319 > > -   (buffer-name notmuch-show-buffer-name)\r
320 > > -   (process-crypto (if crypto-switch\r
321 > > -                       (not notmuch-show-process-crypto)\r
322 > > -                     notmuch-show-process-crypto)))\r
323 > > -    (notmuch-kill-this-buffer)\r
324 > > -    (notmuch-show-worker thread-id parent-buffer query-context buffer-=\r
325 name process-crypto)))\r
326 > > +Refreshes the current view, observing changes in cryptographic prefere=\r
327 nces."\r
328 > > +  (interactive)\r
329 > > +  (let ((inhibit-read-only t))\r
330 > > +    (erase-buffer))\r
331 > > +  (notmuch-show-worker))\r
332 > >=20=20\r
333 > >  (defvar notmuch-show-stash-map\r
334 > >    (let ((map (make-sparse-keymap)))\r
335 > > @@ -1097,6 +1096,7 @@ thread id.  If a prefix is given, crypto processi=\r
336 ng is toggled."\r
337 > >     (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)\r
338 > >     (define-key map (kbd "RET") 'notmuch-show-toggle-message)\r
339 > >     (define-key map "#" 'notmuch-show-print-message)\r
340 > > +   (define-key map "$" 'notmuch-show-toggle-process-crypto)\r
341 > >     map)\r
342 > >        "Keymap for \"notmuch show\" buffers.")\r
343 > >  (fset 'notmuch-show-mode-map notmuch-show-mode-map)\r
344 > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
345 > > index cd04ffd..ff0db99 100644\r
346 > > --- a/emacs/notmuch.el\r
347 > > +++ b/emacs/notmuch.el\r
348 > > @@ -463,9 +463,9 @@ Complete list of currently available key bindings:\r
349 > >    "Return a list of authors for the current region"\r
350 > >    (notmuch-search-properties-in-region 'notmuch-search-subject beg end=\r
351 ))\r
352 > >=20=20\r
353 > > -(defun notmuch-search-show-thread (&optional crypto-switch)\r
354 > > +(defun notmuch-search-show-thread ()\r
355 > >    "Display the currently selected thread."\r
356 > > -  (interactive "P")\r
357 > > +  (interactive)\r
358 > >    (let ((thread-id (notmuch-search-find-thread-id))\r
359 > >     (subject (notmuch-prettify-subject (notmuch-search-find-subject))))\r
360 > >      (if (> (length thread-id) 0)\r
361 > > @@ -473,8 +473,7 @@ Complete list of currently available key bindings:\r
362 > >                   (current-buffer)\r
363 > >                   notmuch-search-query-string\r
364 > >                   ;; Name the buffer based on the subject.\r
365 > > -                 (concat "*" (truncate-string-to-width subject 30 nil nil t) "*=\r
366 ")\r
367 > > -                 crypto-switch)\r
368 > > +                 (concat "*" (truncate-string-to-width subject 30 nil nil t) "*=\r
369 "))\r
370 > >        (message "End of search results."))))\r
371 > >=20=20\r
372 > >  (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)\r
373 \r
374 --=-=-=\r
375 Content-Type: application/pgp-signature\r
376 \r
377 -----BEGIN PGP SIGNATURE-----\r
378 Version: GnuPG v1.4.11 (GNU/Linux)\r
379 \r
380 iEYEARECAAYFAk8yFG4ACgkQaezQq/BJZRbXOgCeM4wQB0VrfV5AXYmuYhL+RKet\r
381 bFIAn0VHsotEKKltcFE4k1+M5E3Xrj4c\r
382 =N2k6\r
383 -----END PGP SIGNATURE-----\r
384 --=-=-=--\r