Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f6 / 65d9c40107e997f0a8965612b1a04d7feae9da
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 327DA431FAF\r
6         for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 21:11:36 -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 UXG2gd6eqeGq for <notmuch@notmuchmail.org>;\r
16         Tue,  7 Feb 2012 21:11:35 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
18         [18.9.25.12])\r
19         by olra.theworths.org (Postfix) with ESMTP id DA816431FAE\r
20         for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 21:11:34 -0800 (PST)\r
21 X-AuditID: 1209190c-b7fad6d000000920-ff-4f320406ca0c\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 43.56.02336.604023F4; Wed,  8 Feb 2012 00:11:34 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q185BXKA025143; \r
27         Wed, 8 Feb 2012 00:11:34 -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 q185BWS8025291\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Wed, 8 Feb 2012 00:11:33 -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 1RuznM-0001BY-8V; Wed, 08 Feb 2012 00:10:16 -0500\r
37 Date: Wed, 8 Feb 2012 00:10:16 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: David Edmondson <dme@dme.org>\r
40 Subject: Re: [PATCH v7 1/8] emacs: Rework crypto switch toggle.\r
41 Message-ID: <20120208051016.GB27039@mit.edu>\r
42 References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
43         <1328520082-26659-1-git-send-email-dme@dme.org>\r
44         <1328520082-26659-2-git-send-email-dme@dme.org>\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: <1328520082-26659-2-git-send-email-dme@dme.org>\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFupnleLIzCtJLcpLzFFi42IRYrdT12VjMfI3WLxJ0GLfnS1MFtdvzmR2\r
52         YPLY9fwvk8ezVbeYA5iiuGxSUnMyy1KL9O0SuDJ2ft7BUjA9oaJ13y7mBsZ/vl2MHBwSAiYS\r
53         N7YVdDFyApliEhfurWcDsYUE9jFKfJxp1sXIBWSvZ5To2/ODFcI5wSRxYukeNghnCaPEpmkN\r
54         YC0sAioSa3Z3MYLYbAIaEtv2LwezRQQUJf5/W8EOYjMLSEt8+93MBGILC9hLPDi5gBnE5hXQ\r
55         kXgwYycTxND5jBL39iyESghKnJz5hAWiWUvixr+XTCBngwxa/o8DJMwpYCOxqPMh2C5RoBum\r
56         nNzGNoFRaBaS7llIumchdC9gZF7FKJuSW6Wbm5iZU5yarFucnJiXl1qka6iXm1mil5pSuokR\r
57         FNackjw7GN8cVDrEKMDBqMTDy3HI0F+INbGsuDL3EKMkB5OSKO86JiN/Ib6k/JTKjMTijPii\r
58         0pzU4kOMEhzMSiK8S4OAynlTEiurUovyYVLSHCxK4rwqWu/8hATSE0tSs1NTC1KLYLIyHBxK\r
59         Erx5zEBDBYtS01Mr0jJzShDSTBycIMN5gIY3gtTwFhck5hZnpkPkTzHqcnw+9fk8oxBLXn5e\r
60         qpQ47ySQIgGQoozSPLg5sHT0ilEc6C1h3pkgVTzAVAY36RXQEiagJSlMIB8UlyQipKQaGOdv\r
61         8BZpPfk2uyGE/+bXqjl1h4PinlhPLz7mcOFD9RmxN+19DudfvM3fNn3rPfUdxxw9mlYs5LSu\r
62         n70483dYX9envxpt7779jJyyjHftsyntPDpJU8trj1xSvqH16lnMbNmspS9fRpz79/ra3q87\r
63         AxvlDH/n5dS+4I6U+q6k5Msa7zGPcbEVr4gSS3FGoqEWc1FxIgDBEkkZIgMAAA==\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: Wed, 08 Feb 2012 05:11:36 -0000\r
78 \r
79 Seems reasonable.  I'm definitely in favor of erasing buffers instead\r
80 of killing and recreating them.  Two questions below.\r
81 \r
82 Quoth David Edmondson on Feb 06 at  9:21 am:\r
83 > Re-work the existing crypto switch toggle to be based on a persistant\r
84 > buffer-local variable.\r
85\r
86 > To allow this, modify `notmuch-show-refresh-view' to erase and re-draw\r
87 > in the current buffer rather than killing the current buffer and\r
88 > creating a new one. (This will also allow more per-buffer behaviour in\r
89 > future patches.)\r
90\r
91 > Add a binding ('$') to toggle crypto processing of the current buffer\r
92 > and remove the prefix argument approach that achieves a similar\r
93 > result.\r
94 > ---\r
95 >  emacs/notmuch-show.el |  126 ++++++++++++++++++++++++------------------------\r
96 >  emacs/notmuch.el      |    7 +--\r
97 >  2 files changed, 66 insertions(+), 67 deletions(-)\r
98\r
99 > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
100 > index 7469e2e..4b29dbd 100644\r
101 > --- a/emacs/notmuch-show.el\r
102 > +++ b/emacs/notmuch-show.el\r
103 > @@ -125,6 +125,22 @@ indentation."\r
104 >                (const :tag "View interactively"\r
105 >                       notmuch-show-interactively-view-part)))\r
106 >  \r
107 > +(defvar notmuch-show-thread-id nil)\r
108 > +(make-variable-buffer-local 'notmuch-show-thread-id)\r
109 > +(put 'notmuch-show-thread-id 'permanent-local t)\r
110 > +\r
111 > +(defvar notmuch-show-parent-buffer nil)\r
112 > +(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
113 > +(put 'notmuch-show-parent-buffer 'permanent-local t)\r
114 > +\r
115 > +(defvar notmuch-show-query-context nil)\r
116 > +(make-variable-buffer-local 'notmuch-show-query-context)\r
117 > +(put 'notmuch-show-query-context 'permanent-local t)\r
118 > +\r
119 > +(defvar notmuch-show-process-crypto nil)\r
120 > +(make-variable-buffer-local 'notmuch-show-process-crypto)\r
121 > +(put 'notmuch-show-process-crypto 'permanent-local t)\r
122 > +\r
123 \r
124 Do these need to be permanent-local given that refreshing is now done\r
125 by erasing the buffer instead of killing it?\r
126 \r
127 >  (defmacro with-current-notmuch-show-message (&rest body)\r
128 >    "Evaluate body with current buffer set to the text of current message"\r
129 >    `(save-excursion\r
130 > @@ -421,14 +437,11 @@ message at DEPTH in the current thread."\r
131 >  \r
132 >  (defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
133 >    (declare (indent 2))\r
134 > -  (let ((process-crypto (make-symbol "process-crypto")))\r
135 > -    `(let ((,process-crypto notmuch-show-process-crypto))\r
136 > -       (with-temp-buffer\r
137 > -      (setq notmuch-show-process-crypto ,process-crypto)\r
138 > -      ;; Always acquires the part via `notmuch part', even if it is\r
139 > -      ;; available in the JSON output.\r
140 > -      (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
141 > -      ,@body))))\r
142 > +  `(with-temp-buffer\r
143 > +     ;; Always acquires the part via `notmuch part', even if it is\r
144 > +     ;; available in the JSON output.\r
145 > +     (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
146 > +     ,@body))\r
147 \r
148 Why is the piping of notmuch-show-process-crypto no longer necessary?\r
149 It's still buffer-local, and hence will be nil in the temp buffer.\r
150 \r
151 >  \r
152 >  (defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
153 >    (notmuch-with-temp-part-buffer message-id nth\r
154 > @@ -610,7 +623,7 @@ current buffer, if possible."\r
155 >              (sigstatus (car (plist-get part :sigstatus))))\r
156 >         (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
157 >        ;; if we're not adding sigstatus, tell the user how they can get it\r
158 > -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
159 > +      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
160 >  \r
161 >    (let ((inner-parts (plist-get part :content))\r
162 >       (start (point)))\r
163 > @@ -636,7 +649,7 @@ current buffer, if possible."\r
164 >                    (sigstatus (car (plist-get part :sigstatus))))\r
165 >               (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
166 >        ;; if we're not adding encstatus, tell the user how they can get it\r
167 > -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
168 > +      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
169 >  \r
170 >    (let ((inner-parts (plist-get part :content))\r
171 >       (start (point)))\r
172 > @@ -763,8 +776,6 @@ current buffer, if possible."\r
173 >  \r
174 >  ;; Helper for parts which are generally not included in the default\r
175 >  ;; JSON output.\r
176 > -;; Uses the buffer-local variable notmuch-show-process-crypto to\r
177 > -;; determine if parts should be decrypted first.\r
178 >  (defun notmuch-show-get-bodypart-internal (message-id part-number)\r
179 >    (let ((args '("show" "--format=raw"))\r
180 >       (part-arg (format "--part=%s" part-number)))\r
181 > @@ -918,6 +929,15 @@ current buffer, if possible."\r
182 >      ;; criteria.\r
183 >      (notmuch-show-message-visible msg (plist-get msg :match))))\r
184 >  \r
185 > +(defun notmuch-show-toggle-process-crypto ()\r
186 > +  "Toggle the processing of cryptographic MIME parts."\r
187 > +  (interactive)\r
188 > +  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))\r
189 > +  (message (if notmuch-show-process-crypto\r
190 > +            "Processing cryptographic MIME parts."\r
191 > +          "Not processing cryptographic MIME parts."))\r
192 > +  (notmuch-show-refresh-view))\r
193 > +\r
194 >  (defun notmuch-show-insert-tree (tree depth)\r
195 >    "Insert the message tree TREE at depth DEPTH in the current thread."\r
196 >    (let ((msg (car tree))\r
197 > @@ -933,15 +953,6 @@ current buffer, if possible."\r
198 >    "Insert the forest of threads FOREST."\r
199 >    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
200 >  \r
201 > -(defvar notmuch-show-thread-id nil)\r
202 > -(make-variable-buffer-local 'notmuch-show-thread-id)\r
203 > -(defvar notmuch-show-parent-buffer nil)\r
204 > -(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
205 > -(defvar notmuch-show-query-context nil)\r
206 > -(make-variable-buffer-local 'notmuch-show-query-context)\r
207 > -(defvar notmuch-show-buffer-name nil)\r
208 > -(make-variable-buffer-local 'notmuch-show-buffer-name)\r
209 > -\r
210 >  (defun notmuch-show-buttonise-links (start end)\r
211 >    "Buttonise URLs and mail addresses between START and END.\r
212 >  \r
213 > @@ -961,7 +972,7 @@ a corresponding notmuch search."\r
214 >                       'face goto-address-mail-face))))\r
215 >  \r
216 >  ;;;###autoload\r
217 > -(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch)\r
218 > +(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)\r
219 >    "Run \"notmuch show\" with the given thread ID and display results.\r
220 >  \r
221 >  The optional PARENT-BUFFER is the notmuch-search buffer from\r
222 > @@ -976,46 +987,41 @@ non-nil.\r
223 >  The optional BUFFER-NAME provides the name of the buffer in\r
224 >  which the message thread is shown. If it is nil (which occurs\r
225 >  when the command is called interactively) the argument to the\r
226 > -function is used.\r
227 > -\r
228 > -The optional CRYPTO-SWITCH toggles the value of the\r
229 > -notmuch-crypto-process-mime customization variable for this show\r
230 > -buffer."\r
231 > +function is used."\r
232 >    (interactive "sNotmuch show: ")\r
233 > -  (let* ((process-crypto (if crypto-switch\r
234 > -                          (not notmuch-crypto-process-mime)\r
235 > -                        notmuch-crypto-process-mime)))\r
236 > -    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
237 > -\r
238 > -(defun notmuch-show-worker (thread-id parent-buffer query-context buffer-name process-crypto)\r
239 > -  (let* ((buffer-name (generate-new-buffer-name\r
240 > -                    (or buffer-name\r
241 > -                        (concat "*notmuch-" thread-id "*"))))\r
242 > -      (buffer (get-buffer-create buffer-name))\r
243 > -      (inhibit-read-only t))\r
244 > -    (switch-to-buffer buffer)\r
245 > +  (let ((buffer-name (generate-new-buffer-name\r
246 > +                   (or buffer-name\r
247 > +                       (concat "*notmuch-" thread-id "*")))))\r
248 > +    (switch-to-buffer (get-buffer-create buffer-name))\r
249 > +    ;; Set the default value for `notmuch-show-process-crypto' in this\r
250 > +    ;; buffer.\r
251 > +    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
252 > +\r
253 > +    (setq notmuch-show-thread-id thread-id\r
254 > +       notmuch-show-parent-buffer parent-buffer\r
255 > +       notmuch-show-query-context query-context)\r
256 > +    (notmuch-show-worker)))\r
257 > +\r
258 > +(defun notmuch-show-worker ()\r
259 > +  (let ((inhibit-read-only t))\r
260 > +\r
261 >      (notmuch-show-mode)\r
262 >      ;; Don't track undo information for this buffer\r
263 >      (set 'buffer-undo-list t)\r
264 >  \r
265 > -    (setq notmuch-show-thread-id thread-id)\r
266 > -    (setq notmuch-show-parent-buffer parent-buffer)\r
267 > -    (setq notmuch-show-query-context query-context)\r
268 > -    (setq notmuch-show-buffer-name buffer-name)\r
269 > -    (setq notmuch-show-process-crypto process-crypto)\r
270 > -\r
271 >      (erase-buffer)\r
272 >      (goto-char (point-min))\r
273 >      (save-excursion\r
274 > -      (let* ((basic-args (list thread-id))\r
275 > -          (args (if query-context\r
276 > -                    (append (list "\'") basic-args (list "and (" query-context ")\'"))\r
277 > +      (let* ((basic-args (list notmuch-show-thread-id))\r
278 > +          (args (if notmuch-show-query-context\r
279 > +                    (append (list "\'") basic-args\r
280 > +                            (list "and (" notmuch-show-query-context ")\'"))\r
281 >                    (append (list "\'") basic-args (list "\'")))))\r
282 >       (notmuch-show-insert-forest (notmuch-query-get-threads args))\r
283 >       ;; If the query context reduced the results to nothing, run\r
284 >       ;; the basic query.\r
285 >       (when (and (eq (buffer-size) 0)\r
286 > -                query-context)\r
287 > +                notmuch-show-query-context)\r
288 >         (notmuch-show-insert-forest\r
289 >          (notmuch-query-get-threads basic-args))))\r
290 >  \r
291 > @@ -1032,21 +1038,14 @@ buffer."\r
292 >  \r
293 >      (notmuch-show-mark-read)))\r
294 >  \r
295 > -(defun notmuch-show-refresh-view (&optional crypto-switch)\r
296 > -  "Refresh the current view (with crypto switch if prefix given).\r
297 > +(defun notmuch-show-refresh-view ()\r
298 > +  "Refresh the current view.\r
299 >  \r
300 > -Kills the current buffer and reruns notmuch show with the same\r
301 > -thread id.  If a prefix is given, crypto processing is toggled."\r
302 > -  (interactive "P")\r
303 > -  (let ((thread-id notmuch-show-thread-id)\r
304 > -     (parent-buffer notmuch-show-parent-buffer)\r
305 > -     (query-context notmuch-show-query-context)\r
306 > -     (buffer-name notmuch-show-buffer-name)\r
307 > -     (process-crypto (if crypto-switch\r
308 > -                         (not notmuch-show-process-crypto)\r
309 > -                       notmuch-show-process-crypto)))\r
310 > -    (notmuch-kill-this-buffer)\r
311 > -    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
312 > +Refreshes the current view, observing changes in cryptographic preferences."\r
313 > +  (interactive)\r
314 > +  (let ((inhibit-read-only t))\r
315 > +    (erase-buffer))\r
316 > +  (notmuch-show-worker))\r
317 >  \r
318 >  (defvar notmuch-show-stash-map\r
319 >    (let ((map (make-sparse-keymap)))\r
320 > @@ -1097,6 +1096,7 @@ thread id.  If a prefix is given, crypto processing is toggled."\r
321 >       (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)\r
322 >       (define-key map (kbd "RET") 'notmuch-show-toggle-message)\r
323 >       (define-key map "#" 'notmuch-show-print-message)\r
324 > +     (define-key map "$" 'notmuch-show-toggle-process-crypto)\r
325 >       map)\r
326 >        "Keymap for \"notmuch show\" buffers.")\r
327 >  (fset 'notmuch-show-mode-map notmuch-show-mode-map)\r
328 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
329 > index cd04ffd..ff0db99 100644\r
330 > --- a/emacs/notmuch.el\r
331 > +++ b/emacs/notmuch.el\r
332 > @@ -463,9 +463,9 @@ Complete list of currently available key bindings:\r
333 >    "Return a list of authors for the current region"\r
334 >    (notmuch-search-properties-in-region 'notmuch-search-subject beg end))\r
335 >  \r
336 > -(defun notmuch-search-show-thread (&optional crypto-switch)\r
337 > +(defun notmuch-search-show-thread ()\r
338 >    "Display the currently selected thread."\r
339 > -  (interactive "P")\r
340 > +  (interactive)\r
341 >    (let ((thread-id (notmuch-search-find-thread-id))\r
342 >       (subject (notmuch-prettify-subject (notmuch-search-find-subject))))\r
343 >      (if (> (length thread-id) 0)\r
344 > @@ -473,8 +473,7 @@ Complete list of currently available key bindings:\r
345 >                     (current-buffer)\r
346 >                     notmuch-search-query-string\r
347 >                     ;; Name the buffer based on the subject.\r
348 > -                   (concat "*" (truncate-string-to-width subject 30 nil nil t) "*")\r
349 > -                   crypto-switch)\r
350 > +                   (concat "*" (truncate-string-to-width subject 30 nil nil t) "*"))\r
351 >        (message "End of search results."))))\r
352 >  \r
353 >  (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)\r