Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 40 / b90222af9bb84605ca3d25f70ed7341a5edc7c
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 6E4ED41EB8E\r
6         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 08:31:14 -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 Vv3pZg6Xnyj6 for <notmuch@notmuchmail.org>;\r
16         Mon, 30 Jan 2012 08:31:11 -0800 (PST)\r
17 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
18         [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 2865A431FBC\r
21         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 08:31:11 -0800 (PST)\r
22 Received: by werb10 with SMTP id b10so3999800wer.26\r
23         for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 08:31:10 -0800 (PST)\r
24 Received: by 10.216.135.214 with SMTP id u64mr7186732wei.58.1327941069871;\r
25         Mon, 30 Jan 2012 08:31:09 -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 l12sm32283814wiw.0.2012.01.30.08.31.07\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Mon, 30 Jan 2012 08:31:08 -0800 (PST)\r
31 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
32         id 0E45E9FE47; Mon, 30 Jan 2012 16:31:06 +0000 (GMT)\r
33 From: David Edmondson <dme@dme.org>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH 1/5] emacs: Rework crypto switch toggle.\r
36 Date: Mon, 30 Jan 2012 16:31:00 +0000\r
37 Message-Id: <1327941064-20027-2-git-send-email-dme@dme.org>\r
38 X-Mailer: git-send-email 1.7.8.3\r
39 In-Reply-To: <1327941064-20027-1-git-send-email-dme@dme.org>\r
40 References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
41         <1327941064-20027-1-git-send-email-dme@dme.org>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Mon, 30 Jan 2012 16:31:15 -0000\r
55 \r
56 Re-work the existing crypto switch toggle to be based on a persistant\r
57 buffer-local variable.\r
58 \r
59 To allow this, modify `notmuch-show-refresh-view' to erase and re-draw\r
60 in the current buffer rather than killing the current buffer and\r
61 creating a new one. (This will also allow more per-buffer behaviour in\r
62 future patches.)\r
63 \r
64 Add a binding ('$') to toggle crypto processing of the current buffer\r
65 and remove the prefix argument approach that achieves a similar\r
66 result.\r
67 ---\r
68  emacs/notmuch-show.el |  105 +++++++++++++++++++++++-------------------------\r
69  emacs/notmuch.el      |    7 +--\r
70  2 files changed, 53 insertions(+), 59 deletions(-)\r
71 \r
72 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
73 index 84ac624..53f6ae4 100644\r
74 --- a/emacs/notmuch-show.el\r
75 +++ b/emacs/notmuch-show.el\r
76 @@ -124,6 +124,17 @@ indentation."\r
77                  (const :tag "View interactively"\r
78                         notmuch-show-interactively-view-part)))\r
79  \r
80 +(defvar notmuch-show-thread-id nil)\r
81 +(make-variable-buffer-local 'notmuch-show-thread-id)\r
82 +(defvar notmuch-show-parent-buffer nil)\r
83 +(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
84 +(defvar notmuch-show-query-context nil)\r
85 +(make-variable-buffer-local 'notmuch-show-query-context)\r
86 +\r
87 +(defvar notmuch-show-process-crypto nil)\r
88 +(make-variable-buffer-local 'notmuch-show-process-crypto)\r
89 +(put 'notmuch-show-process-crypto 'permanent-local t)\r
90 +\r
91  (defmacro with-current-notmuch-show-message (&rest body)\r
92    "Evaluate body with current buffer set to the text of current message"\r
93    `(save-excursion\r
94 @@ -410,14 +421,11 @@ message at DEPTH in the current thread."\r
95  \r
96  (defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
97    (declare (indent 2))\r
98 -  (let ((process-crypto (make-symbol "process-crypto")))\r
99 -    `(let ((,process-crypto notmuch-show-process-crypto))\r
100 -       (with-temp-buffer\r
101 -        (setq notmuch-show-process-crypto ,process-crypto)\r
102 -        ;; Always acquires the part via `notmuch part', even if it is\r
103 -        ;; available in the JSON output.\r
104 -        (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
105 -        ,@body))))\r
106 +  `(with-temp-buffer\r
107 +     ;; Always acquires the part via `notmuch part', even if it is\r
108 +     ;; available in the JSON output.\r
109 +     (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
110 +     ,@body))\r
111  \r
112  (defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
113    (notmuch-with-temp-part-buffer message-id nth\r
114 @@ -599,7 +607,7 @@ current buffer, if possible."\r
115                (sigstatus (car (plist-get part :sigstatus))))\r
116           (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
117        ;; if we're not adding sigstatus, tell the user how they can get it\r
118 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
119 +      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
120  \r
121    (let ((inner-parts (plist-get part :content))\r
122         (start (point)))\r
123 @@ -625,7 +633,7 @@ current buffer, if possible."\r
124                      (sigstatus (car (plist-get part :sigstatus))))\r
125                 (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
126        ;; if we're not adding encstatus, tell the user how they can get it\r
127 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
128 +      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
129  \r
130    (let ((inner-parts (plist-get part :content))\r
131         (start (point)))\r
132 @@ -752,8 +760,6 @@ current buffer, if possible."\r
133  \r
134  ;; Helper for parts which are generally not included in the default\r
135  ;; JSON output.\r
136 -;; Uses the buffer-local variable notmuch-show-process-crypto to\r
137 -;; determine if parts should be decrypted first.\r
138  (defun notmuch-show-get-bodypart-internal (message-id part-number)\r
139    (let ((args '("show" "--format=raw"))\r
140         (part-arg (format "--part=%s" part-number)))\r
141 @@ -907,6 +913,15 @@ current buffer, if possible."\r
142      ;; criteria.\r
143      (notmuch-show-message-visible msg (plist-get msg :match))))\r
144  \r
145 +(defun notmuch-show-toggle-process-crypto ()\r
146 +  "Toggle the processing of cryptographic MIME parts."\r
147 +  (interactive)\r
148 +  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))\r
149 +  (message (if notmuch-show-process-crypto\r
150 +              "Processing cryptographic MIME parts."\r
151 +            "Not processing cryptographic MIME parts."))\r
152 +  (notmuch-show-refresh-view))\r
153 +\r
154  (defun notmuch-show-insert-tree (tree depth)\r
155    "Insert the message tree TREE at depth DEPTH in the current thread."\r
156    (let ((msg (car tree))\r
157 @@ -922,15 +937,6 @@ current buffer, if possible."\r
158    "Insert the forest of threads FOREST."\r
159    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
160  \r
161 -(defvar notmuch-show-thread-id nil)\r
162 -(make-variable-buffer-local 'notmuch-show-thread-id)\r
163 -(defvar notmuch-show-parent-buffer nil)\r
164 -(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
165 -(defvar notmuch-show-query-context nil)\r
166 -(make-variable-buffer-local 'notmuch-show-query-context)\r
167 -(defvar notmuch-show-buffer-name nil)\r
168 -(make-variable-buffer-local 'notmuch-show-buffer-name)\r
169 -\r
170  (defun notmuch-show-buttonise-links (start end)\r
171    "Buttonise URLs and mail addresses between START and END.\r
172  \r
173 @@ -950,7 +956,7 @@ a corresponding notmuch search."\r
174                         'face goto-address-mail-face))))\r
175  \r
176  ;;;###autoload\r
177 -(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch)\r
178 +(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)\r
179    "Run \"notmuch show\" with the given thread ID and display results.\r
180  \r
181  The optional PARENT-BUFFER is the notmuch-search buffer from\r
182 @@ -965,24 +971,20 @@ non-nil.\r
183  The optional BUFFER-NAME provides the name of the buffer in\r
184  which the message thread is shown. If it is nil (which occurs\r
185  when the command is called interactively) the argument to the\r
186 -function is used.\r
187 -\r
188 -The optional CRYPTO-SWITCH toggles the value of the\r
189 -notmuch-crypto-process-mime customization variable for this show\r
190 -buffer."\r
191 +function is used."\r
192    (interactive "sNotmuch show: ")\r
193 -  (let* ((process-crypto (if crypto-switch\r
194 -                            (not notmuch-crypto-process-mime)\r
195 -                          notmuch-crypto-process-mime)))\r
196 -    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
197 -\r
198 -(defun notmuch-show-worker (thread-id parent-buffer query-context buffer-name process-crypto)\r
199 -  (let* ((buffer-name (generate-new-buffer-name\r
200 -                      (or buffer-name\r
201 -                          (concat "*notmuch-" thread-id "*"))))\r
202 -        (buffer (get-buffer-create buffer-name))\r
203 -        (inhibit-read-only t))\r
204 -    (switch-to-buffer buffer)\r
205 +  (let ((buffer-name (generate-new-buffer-name\r
206 +                     (or buffer-name\r
207 +                         (concat "*notmuch-" thread-id "*")))))\r
208 +    (switch-to-buffer (get-buffer-create buffer-name))\r
209 +    ;; Set the default value for `notmuch-show-process-crypto' in this\r
210 +    ;; buffer.\r
211 +    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
212 +    (notmuch-show-worker thread-id parent-buffer query-context)))\r
213 +\r
214 +(defun notmuch-show-worker (thread-id parent-buffer query-context)\r
215 +  (let ((inhibit-read-only t))\r
216 +\r
217      (notmuch-show-mode)\r
218      ;; Don't track undo information for this buffer\r
219      (set 'buffer-undo-list t)\r
220 @@ -990,8 +992,6 @@ buffer."\r
221      (setq notmuch-show-thread-id thread-id)\r
222      (setq notmuch-show-parent-buffer parent-buffer)\r
223      (setq notmuch-show-query-context query-context)\r
224 -    (setq notmuch-show-buffer-name buffer-name)\r
225 -    (setq notmuch-show-process-crypto process-crypto)\r
226  \r
227      (erase-buffer)\r
228      (goto-char (point-min))\r
229 @@ -1021,21 +1021,15 @@ buffer."\r
230  \r
231      (notmuch-show-mark-read)))\r
232  \r
233 -(defun notmuch-show-refresh-view (&optional crypto-switch)\r
234 -  "Refresh the current view (with crypto switch if prefix given).\r
235 +(defun notmuch-show-refresh-view ()\r
236 +  "Refresh the current view.\r
237  \r
238 -Kills the current buffer and reruns notmuch show with the same\r
239 -thread id.  If a prefix is given, crypto processing is toggled."\r
240 -  (interactive "P")\r
241 -  (let ((thread-id notmuch-show-thread-id)\r
242 -       (parent-buffer notmuch-show-parent-buffer)\r
243 -       (query-context notmuch-show-query-context)\r
244 -       (buffer-name notmuch-show-buffer-name)\r
245 -       (process-crypto (if crypto-switch\r
246 -                           (not notmuch-show-process-crypto)\r
247 -                         notmuch-show-process-crypto)))\r
248 -    (notmuch-kill-this-buffer)\r
249 -    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
250 +Refreshes the current view, observing changes in cryptographic preferences."\r
251 +  (interactive)\r
252 +  (let ((inhibit-read-only t))\r
253 +    (erase-buffer))\r
254 +  (notmuch-show-worker notmuch-show-thread-id notmuch-show-parent-buffer\r
255 +                      notmuch-show-query-context))\r
256  \r
257  (defvar notmuch-show-stash-map\r
258    (let ((map (make-sparse-keymap)))\r
259 @@ -1085,6 +1079,7 @@ thread id.  If a prefix is given, crypto processing is toggled."\r
260         (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)\r
261         (define-key map (kbd "RET") 'notmuch-show-toggle-message)\r
262         (define-key map "#" 'notmuch-show-print-message)\r
263 +       (define-key map "$" 'notmuch-show-toggle-process-crypto)\r
264         map)\r
265        "Keymap for \"notmuch show\" buffers.")\r
266  (fset 'notmuch-show-mode-map notmuch-show-mode-map)\r
267 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
268 index 72f78ed..9d8bebd 100644\r
269 --- a/emacs/notmuch.el\r
270 +++ b/emacs/notmuch.el\r
271 @@ -463,9 +463,9 @@ Complete list of currently available key bindings:\r
272    "Return a list of authors for the current region"\r
273    (notmuch-search-properties-in-region 'notmuch-search-subject beg end))\r
274  \r
275 -(defun notmuch-search-show-thread (&optional crypto-switch)\r
276 +(defun notmuch-search-show-thread ()\r
277    "Display the currently selected thread."\r
278 -  (interactive "P")\r
279 +  (interactive)\r
280    (let ((thread-id (notmuch-search-find-thread-id))\r
281         (subject (notmuch-search-find-subject)))\r
282      (if (> (length thread-id) 0)\r
283 @@ -479,8 +479,7 @@ Complete list of currently available key bindings:\r
284                          (concat "*"\r
285                                  (truncate-string-to-width subject 32 nil nil t)\r
286                                  "*")\r
287 -                        32 nil nil t))\r
288 -                     crypto-switch)\r
289 +                        32 nil nil t)))\r
290        (message "End of search results."))))\r
291  \r
292  (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)\r
293 -- \r
294 1.7.8.3\r
295 \r