Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 44 / ef085a796ec05f9e7a6a6a93387fb415ca00a7
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 C628E431FBF\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 03:24:02 -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 juLtUXFMUmtQ for <notmuch@notmuchmail.org>;\r
16         Thu,  2 Feb 2012 03:24:00 -0800 (PST)\r
17 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
18         [209.85.212.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 8AE7B431FAE\r
21         for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 03:24:00 -0800 (PST)\r
22 Received: by wibhi8 with SMTP id hi8so1799272wib.26\r
23         for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 03:23:58 -0800 (PST)\r
24 Received: by 10.180.24.7 with SMTP id q7mr3860255wif.14.1328181838916;\r
25         Thu, 02 Feb 2012 03:23:58 -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 x7sm25951099wif.10.2012.02.02.03.23.56\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Thu, 02 Feb 2012 03:23:56 -0800 (PST)\r
31 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
32         id 9E0FEA04A4; Thu,  2 Feb 2012 11:23:54 +0000 (GMT)\r
33 From: David Edmondson <dme@dme.org>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH v6 1/8] emacs: Rework crypto switch toggle.\r
36 Date: Thu,  2 Feb 2012 11:23:46 +0000\r
37 Message-Id: <1328181833-14988-2-git-send-email-dme@dme.org>\r
38 X-Mailer: git-send-email 1.7.8.3\r
39 In-Reply-To: <1328181833-14988-1-git-send-email-dme@dme.org>\r
40 References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
41         <1328181833-14988-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: Thu, 02 Feb 2012 11:24:03 -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 |  126 ++++++++++++++++++++++++------------------------\r
69  emacs/notmuch.el      |    7 +--\r
70  2 files changed, 66 insertions(+), 67 deletions(-)\r
71 \r
72 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
73 index de9421e..b6329d2 100644\r
74 --- a/emacs/notmuch-show.el\r
75 +++ b/emacs/notmuch-show.el\r
76 @@ -125,6 +125,22 @@ 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 +(put 'notmuch-show-thread-id 'permanent-local t)\r
83 +\r
84 +(defvar notmuch-show-parent-buffer nil)\r
85 +(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
86 +(put 'notmuch-show-parent-buffer 'permanent-local t)\r
87 +\r
88 +(defvar notmuch-show-query-context nil)\r
89 +(make-variable-buffer-local 'notmuch-show-query-context)\r
90 +(put 'notmuch-show-query-context 'permanent-local t)\r
91 +\r
92 +(defvar notmuch-show-process-crypto nil)\r
93 +(make-variable-buffer-local 'notmuch-show-process-crypto)\r
94 +(put 'notmuch-show-process-crypto 'permanent-local t)\r
95 +\r
96  (defmacro with-current-notmuch-show-message (&rest body)\r
97    "Evaluate body with current buffer set to the text of current message"\r
98    `(save-excursion\r
99 @@ -411,14 +427,11 @@ message at DEPTH in the current thread."\r
100  \r
101  (defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
102    (declare (indent 2))\r
103 -  (let ((process-crypto (make-symbol "process-crypto")))\r
104 -    `(let ((,process-crypto notmuch-show-process-crypto))\r
105 -       (with-temp-buffer\r
106 -        (setq notmuch-show-process-crypto ,process-crypto)\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 +  `(with-temp-buffer\r
112 +     ;; Always acquires the part via `notmuch part', even if it is\r
113 +     ;; available in the JSON output.\r
114 +     (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
115 +     ,@body))\r
116  \r
117  (defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
118    (notmuch-with-temp-part-buffer message-id nth\r
119 @@ -600,7 +613,7 @@ current buffer, if possible."\r
120                (sigstatus (car (plist-get part :sigstatus))))\r
121           (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
122        ;; if we're not adding sigstatus, tell the user how they can get it\r
123 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
124 +      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
125  \r
126    (let ((inner-parts (plist-get part :content))\r
127         (start (point)))\r
128 @@ -626,7 +639,7 @@ current buffer, if possible."\r
129                      (sigstatus (car (plist-get part :sigstatus))))\r
130                 (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
131        ;; if we're not adding encstatus, tell the user how they can get it\r
132 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
133 +      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
134  \r
135    (let ((inner-parts (plist-get part :content))\r
136         (start (point)))\r
137 @@ -753,8 +766,6 @@ current buffer, if possible."\r
138  \r
139  ;; Helper for parts which are generally not included in the default\r
140  ;; JSON output.\r
141 -;; Uses the buffer-local variable notmuch-show-process-crypto to\r
142 -;; determine if parts should be decrypted first.\r
143  (defun notmuch-show-get-bodypart-internal (message-id part-number)\r
144    (let ((args '("show" "--format=raw"))\r
145         (part-arg (format "--part=%s" part-number)))\r
146 @@ -908,6 +919,15 @@ current buffer, if possible."\r
147      ;; criteria.\r
148      (notmuch-show-message-visible msg (plist-get msg :match))))\r
149  \r
150 +(defun notmuch-show-toggle-process-crypto ()\r
151 +  "Toggle the processing of cryptographic MIME parts."\r
152 +  (interactive)\r
153 +  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))\r
154 +  (message (if notmuch-show-process-crypto\r
155 +              "Processing cryptographic MIME parts."\r
156 +            "Not processing cryptographic MIME parts."))\r
157 +  (notmuch-show-refresh-view))\r
158 +\r
159  (defun notmuch-show-insert-tree (tree depth)\r
160    "Insert the message tree TREE at depth DEPTH in the current thread."\r
161    (let ((msg (car tree))\r
162 @@ -923,15 +943,6 @@ current buffer, if possible."\r
163    "Insert the forest of threads FOREST."\r
164    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
165  \r
166 -(defvar notmuch-show-thread-id nil)\r
167 -(make-variable-buffer-local 'notmuch-show-thread-id)\r
168 -(defvar notmuch-show-parent-buffer nil)\r
169 -(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
170 -(defvar notmuch-show-query-context nil)\r
171 -(make-variable-buffer-local 'notmuch-show-query-context)\r
172 -(defvar notmuch-show-buffer-name nil)\r
173 -(make-variable-buffer-local 'notmuch-show-buffer-name)\r
174 -\r
175  (defun notmuch-show-buttonise-links (start end)\r
176    "Buttonise URLs and mail addresses between START and END.\r
177  \r
178 @@ -951,7 +962,7 @@ a corresponding notmuch search."\r
179                         'face goto-address-mail-face))))\r
180  \r
181  ;;;###autoload\r
182 -(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch)\r
183 +(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)\r
184    "Run \"notmuch show\" with the given thread ID and display results.\r
185  \r
186  The optional PARENT-BUFFER is the notmuch-search buffer from\r
187 @@ -966,46 +977,41 @@ non-nil.\r
188  The optional BUFFER-NAME provides the name of the buffer in\r
189  which the message thread is shown. If it is nil (which occurs\r
190  when the command is called interactively) the argument to the\r
191 -function is used.\r
192 -\r
193 -The optional CRYPTO-SWITCH toggles the value of the\r
194 -notmuch-crypto-process-mime customization variable for this show\r
195 -buffer."\r
196 +function is used."\r
197    (interactive "sNotmuch show: ")\r
198 -  (let* ((process-crypto (if crypto-switch\r
199 -                            (not notmuch-crypto-process-mime)\r
200 -                          notmuch-crypto-process-mime)))\r
201 -    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
202 -\r
203 -(defun notmuch-show-worker (thread-id parent-buffer query-context buffer-name process-crypto)\r
204 -  (let* ((buffer-name (generate-new-buffer-name\r
205 -                      (or buffer-name\r
206 -                          (concat "*notmuch-" thread-id "*"))))\r
207 -        (buffer (get-buffer-create buffer-name))\r
208 -        (inhibit-read-only t))\r
209 -    (switch-to-buffer buffer)\r
210 +  (let ((buffer-name (generate-new-buffer-name\r
211 +                     (or buffer-name\r
212 +                         (concat "*notmuch-" thread-id "*")))))\r
213 +    (switch-to-buffer (get-buffer-create buffer-name))\r
214 +    ;; Set the default value for `notmuch-show-process-crypto' in this\r
215 +    ;; buffer.\r
216 +    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
217 +\r
218 +    (setq notmuch-show-thread-id thread-id\r
219 +         notmuch-show-parent-buffer parent-buffer\r
220 +         notmuch-show-query-context query-context)\r
221 +    (notmuch-show-worker)))\r
222 +\r
223 +(defun notmuch-show-worker ()\r
224 +  (let ((inhibit-read-only t))\r
225 +\r
226      (notmuch-show-mode)\r
227      ;; Don't track undo information for this buffer\r
228      (set 'buffer-undo-list t)\r
229  \r
230 -    (setq notmuch-show-thread-id thread-id)\r
231 -    (setq notmuch-show-parent-buffer parent-buffer)\r
232 -    (setq notmuch-show-query-context query-context)\r
233 -    (setq notmuch-show-buffer-name buffer-name)\r
234 -    (setq notmuch-show-process-crypto process-crypto)\r
235 -\r
236      (erase-buffer)\r
237      (goto-char (point-min))\r
238      (save-excursion\r
239 -      (let* ((basic-args (list thread-id))\r
240 -            (args (if query-context\r
241 -                      (append (list "\'") basic-args (list "and (" query-context ")\'"))\r
242 +      (let* ((basic-args (list notmuch-show-thread-id))\r
243 +            (args (if notmuch-show-query-context\r
244 +                      (append (list "\'") basic-args\r
245 +                              (list "and (" notmuch-show-query-context ")\'"))\r
246                      (append (list "\'") basic-args (list "\'")))))\r
247         (notmuch-show-insert-forest (notmuch-query-get-threads args))\r
248         ;; If the query context reduced the results to nothing, run\r
249         ;; the basic query.\r
250         (when (and (eq (buffer-size) 0)\r
251 -                  query-context)\r
252 +                  notmuch-show-query-context)\r
253           (notmuch-show-insert-forest\r
254            (notmuch-query-get-threads basic-args))))\r
255  \r
256 @@ -1022,21 +1028,14 @@ buffer."\r
257  \r
258      (notmuch-show-mark-read)))\r
259  \r
260 -(defun notmuch-show-refresh-view (&optional crypto-switch)\r
261 -  "Refresh the current view (with crypto switch if prefix given).\r
262 +(defun notmuch-show-refresh-view ()\r
263 +  "Refresh the current view.\r
264  \r
265 -Kills the current buffer and reruns notmuch show with the same\r
266 -thread id.  If a prefix is given, crypto processing is toggled."\r
267 -  (interactive "P")\r
268 -  (let ((thread-id notmuch-show-thread-id)\r
269 -       (parent-buffer notmuch-show-parent-buffer)\r
270 -       (query-context notmuch-show-query-context)\r
271 -       (buffer-name notmuch-show-buffer-name)\r
272 -       (process-crypto (if crypto-switch\r
273 -                           (not notmuch-show-process-crypto)\r
274 -                         notmuch-show-process-crypto)))\r
275 -    (notmuch-kill-this-buffer)\r
276 -    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
277 +Refreshes the current view, observing changes in cryptographic preferences."\r
278 +  (interactive)\r
279 +  (let ((inhibit-read-only t))\r
280 +    (erase-buffer))\r
281 +  (notmuch-show-worker))\r
282  \r
283  (defvar notmuch-show-stash-map\r
284    (let ((map (make-sparse-keymap)))\r
285 @@ -1087,6 +1086,7 @@ thread id.  If a prefix is given, crypto processing is toggled."\r
286         (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)\r
287         (define-key map (kbd "RET") 'notmuch-show-toggle-message)\r
288         (define-key map "#" 'notmuch-show-print-message)\r
289 +       (define-key map "$" 'notmuch-show-toggle-process-crypto)\r
290         map)\r
291        "Keymap for \"notmuch show\" buffers.")\r
292  (fset 'notmuch-show-mode-map notmuch-show-mode-map)\r
293 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
294 index 72f78ed..9d8bebd 100644\r
295 --- a/emacs/notmuch.el\r
296 +++ b/emacs/notmuch.el\r
297 @@ -463,9 +463,9 @@ Complete list of currently available key bindings:\r
298    "Return a list of authors for the current region"\r
299    (notmuch-search-properties-in-region 'notmuch-search-subject beg end))\r
300  \r
301 -(defun notmuch-search-show-thread (&optional crypto-switch)\r
302 +(defun notmuch-search-show-thread ()\r
303    "Display the currently selected thread."\r
304 -  (interactive "P")\r
305 +  (interactive)\r
306    (let ((thread-id (notmuch-search-find-thread-id))\r
307         (subject (notmuch-search-find-subject)))\r
308      (if (> (length thread-id) 0)\r
309 @@ -479,8 +479,7 @@ Complete list of currently available key bindings:\r
310                          (concat "*"\r
311                                  (truncate-string-to-width subject 32 nil nil t)\r
312                                  "*")\r
313 -                        32 nil nil t))\r
314 -                     crypto-switch)\r
315 +                        32 nil nil t)))\r
316        (message "End of search results."))))\r
317  \r
318  (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)\r
319 -- \r
320 1.7.8.3\r
321 \r