[PATCH 1/3 v2] emacs: Rework crypto switch toggle.
authorDavid Edmondson <dme@dme.org>
Mon, 30 Jan 2012 11:31:31 +0000 (11:31 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:39 +0000 (09:43 -0800)
3b/4dbb6bc8d78d0137fc3922d50ae53b0418d8e7 [new file with mode: 0644]

diff --git a/3b/4dbb6bc8d78d0137fc3922d50ae53b0418d8e7 b/3b/4dbb6bc8d78d0137fc3922d50ae53b0418d8e7
new file mode 100644 (file)
index 0000000..9101750
--- /dev/null
@@ -0,0 +1,295 @@
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 80640431FBC\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 03:31:43 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id Q7IANF0a3Cth for <notmuch@notmuchmail.org>;\r
+       Mon, 30 Jan 2012 03:31:41 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 23BD0429E4E\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 03:31:41 -0800 (PST)\r
+Received: by werb10 with SMTP id b10so3697705wer.26\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 03:31:39 -0800 (PST)\r
+Received: by 10.216.139.205 with SMTP id c55mr6757525wej.31.1327923099843;\r
+       Mon, 30 Jan 2012 03:31:39 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+       (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+       by mx.google.com with ESMTPS id x7sm4505818wif.10.2012.01.30.03.31.37\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 30 Jan 2012 03:31:37 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id BA8919FDD7; Mon, 30 Jan 2012 11:31:35 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3 v2] emacs: Rework crypto switch toggle.\r
+Date: Mon, 30 Jan 2012 11:31:31 +0000\r
+Message-Id: <1327923093-31065-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1327923093-31065-1-git-send-email-dme@dme.org>\r
+References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
+       <1327923093-31065-1-git-send-email-dme@dme.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 30 Jan 2012 11:31:43 -0000\r
+\r
+Re-work the existing crypto switch toggle to be based on a persistant\r
+buffer-local variable.\r
+\r
+To allow this, modify `notmuch-show-refresh-view' to erase and re-draw\r
+in the current buffer rather than killing the current buffer and\r
+creating a new one. (This will also allow more per-buffer behaviour in\r
+future patches.)\r
+\r
+Add a binding ('$') to toggle crypto processing of the current buffer\r
+and remove the prefix argument approach that achieves a similar\r
+result.\r
+---\r
+ emacs/notmuch-show.el |  105 +++++++++++++++++++++++-------------------------\r
+ emacs/notmuch.el      |    7 +--\r
+ 2 files changed, 53 insertions(+), 59 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 84ac624..53f6ae4 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -124,6 +124,17 @@ indentation."\r
+                (const :tag "View interactively"\r
+                       notmuch-show-interactively-view-part)))\r
\r
++(defvar notmuch-show-thread-id nil)\r
++(make-variable-buffer-local 'notmuch-show-thread-id)\r
++(defvar notmuch-show-parent-buffer nil)\r
++(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
++(defvar notmuch-show-query-context nil)\r
++(make-variable-buffer-local 'notmuch-show-query-context)\r
++\r
++(defvar notmuch-show-process-crypto nil)\r
++(make-variable-buffer-local 'notmuch-show-process-crypto)\r
++(put 'notmuch-show-process-crypto 'permanent-local t)\r
++\r
+ (defmacro with-current-notmuch-show-message (&rest body)\r
+   "Evaluate body with current buffer set to the text of current message"\r
+   `(save-excursion\r
+@@ -410,14 +421,11 @@ message at DEPTH in the current thread."\r
\r
+ (defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
+   (declare (indent 2))\r
+-  (let ((process-crypto (make-symbol "process-crypto")))\r
+-    `(let ((,process-crypto notmuch-show-process-crypto))\r
+-       (with-temp-buffer\r
+-       (setq notmuch-show-process-crypto ,process-crypto)\r
+-       ;; Always acquires the part via `notmuch part', even if it is\r
+-       ;; available in the JSON output.\r
+-       (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
+-       ,@body))))\r
++  `(with-temp-buffer\r
++     ;; Always acquires the part via `notmuch part', even if it is\r
++     ;; available in the JSON output.\r
++     (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
++     ,@body))\r
\r
+ (defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
+   (notmuch-with-temp-part-buffer message-id nth\r
+@@ -599,7 +607,7 @@ current buffer, if possible."\r
+              (sigstatus (car (plist-get part :sigstatus))))\r
+         (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
+       ;; if we're not adding sigstatus, tell the user how they can get it\r
+-      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
++      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
+@@ -625,7 +633,7 @@ current buffer, if possible."\r
+                    (sigstatus (car (plist-get part :sigstatus))))\r
+               (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
+       ;; if we're not adding encstatus, tell the user how they can get it\r
+-      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))\r
++      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
+@@ -752,8 +760,6 @@ current buffer, if possible."\r
\r
+ ;; Helper for parts which are generally not included in the default\r
+ ;; JSON output.\r
+-;; Uses the buffer-local variable notmuch-show-process-crypto to\r
+-;; determine if parts should be decrypted first.\r
+ (defun notmuch-show-get-bodypart-internal (message-id part-number)\r
+   (let ((args '("show" "--format=raw"))\r
+       (part-arg (format "--part=%s" part-number)))\r
+@@ -907,6 +913,15 @@ current buffer, if possible."\r
+     ;; criteria.\r
+     (notmuch-show-message-visible msg (plist-get msg :match))))\r
\r
++(defun notmuch-show-toggle-process-crypto ()\r
++  "Toggle the processing of cryptographic MIME parts."\r
++  (interactive)\r
++  (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))\r
++  (message (if notmuch-show-process-crypto\r
++             "Processing cryptographic MIME parts."\r
++           "Not processing cryptographic MIME parts."))\r
++  (notmuch-show-refresh-view))\r
++\r
+ (defun notmuch-show-insert-tree (tree depth)\r
+   "Insert the message tree TREE at depth DEPTH in the current thread."\r
+   (let ((msg (car tree))\r
+@@ -922,15 +937,6 @@ current buffer, if possible."\r
+   "Insert the forest of threads FOREST."\r
+   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
\r
+-(defvar notmuch-show-thread-id nil)\r
+-(make-variable-buffer-local 'notmuch-show-thread-id)\r
+-(defvar notmuch-show-parent-buffer nil)\r
+-(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
+-(defvar notmuch-show-query-context nil)\r
+-(make-variable-buffer-local 'notmuch-show-query-context)\r
+-(defvar notmuch-show-buffer-name nil)\r
+-(make-variable-buffer-local 'notmuch-show-buffer-name)\r
+-\r
+ (defun notmuch-show-buttonise-links (start end)\r
+   "Buttonise URLs and mail addresses between START and END.\r
\r
+@@ -950,7 +956,7 @@ a corresponding notmuch search."\r
+                       'face goto-address-mail-face))))\r
\r
+ ;;;###autoload\r
+-(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch)\r
++(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)\r
+   "Run \"notmuch show\" with the given thread ID and display results.\r
\r
+ The optional PARENT-BUFFER is the notmuch-search buffer from\r
+@@ -965,24 +971,20 @@ non-nil.\r
+ The optional BUFFER-NAME provides the name of the buffer in\r
+ which the message thread is shown. If it is nil (which occurs\r
+ when the command is called interactively) the argument to the\r
+-function is used.\r
+-\r
+-The optional CRYPTO-SWITCH toggles the value of the\r
+-notmuch-crypto-process-mime customization variable for this show\r
+-buffer."\r
++function is used."\r
+   (interactive "sNotmuch show: ")\r
+-  (let* ((process-crypto (if crypto-switch\r
+-                           (not notmuch-crypto-process-mime)\r
+-                         notmuch-crypto-process-mime)))\r
+-    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
+-\r
+-(defun notmuch-show-worker (thread-id parent-buffer query-context buffer-name process-crypto)\r
+-  (let* ((buffer-name (generate-new-buffer-name\r
+-                     (or buffer-name\r
+-                         (concat "*notmuch-" thread-id "*"))))\r
+-       (buffer (get-buffer-create buffer-name))\r
+-       (inhibit-read-only t))\r
+-    (switch-to-buffer buffer)\r
++  (let ((buffer-name (generate-new-buffer-name\r
++                    (or buffer-name\r
++                        (concat "*notmuch-" thread-id "*")))))\r
++    (switch-to-buffer (get-buffer-create buffer-name))\r
++    ;; Set the default value for `notmuch-show-process-crypto' in this\r
++    ;; buffer.\r
++    (setq notmuch-show-process-crypto notmuch-crypto-process-mime)\r
++    (notmuch-show-worker thread-id parent-buffer query-context)))\r
++\r
++(defun notmuch-show-worker (thread-id parent-buffer query-context)\r
++  (let ((inhibit-read-only t))\r
++\r
+     (notmuch-show-mode)\r
+     ;; Don't track undo information for this buffer\r
+     (set 'buffer-undo-list t)\r
+@@ -990,8 +992,6 @@ buffer."\r
+     (setq notmuch-show-thread-id thread-id)\r
+     (setq notmuch-show-parent-buffer parent-buffer)\r
+     (setq notmuch-show-query-context query-context)\r
+-    (setq notmuch-show-buffer-name buffer-name)\r
+-    (setq notmuch-show-process-crypto process-crypto)\r
\r
+     (erase-buffer)\r
+     (goto-char (point-min))\r
+@@ -1021,21 +1021,15 @@ buffer."\r
\r
+     (notmuch-show-mark-read)))\r
\r
+-(defun notmuch-show-refresh-view (&optional crypto-switch)\r
+-  "Refresh the current view (with crypto switch if prefix given).\r
++(defun notmuch-show-refresh-view ()\r
++  "Refresh the current view.\r
\r
+-Kills the current buffer and reruns notmuch show with the same\r
+-thread id.  If a prefix is given, crypto processing is toggled."\r
+-  (interactive "P")\r
+-  (let ((thread-id notmuch-show-thread-id)\r
+-      (parent-buffer notmuch-show-parent-buffer)\r
+-      (query-context notmuch-show-query-context)\r
+-      (buffer-name notmuch-show-buffer-name)\r
+-      (process-crypto (if crypto-switch\r
+-                          (not notmuch-show-process-crypto)\r
+-                        notmuch-show-process-crypto)))\r
+-    (notmuch-kill-this-buffer)\r
+-    (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))\r
++Refreshes the current view, observing changes in cryptographic preferences."\r
++  (interactive)\r
++  (let ((inhibit-read-only t))\r
++    (erase-buffer))\r
++  (notmuch-show-worker notmuch-show-thread-id notmuch-show-parent-buffer\r
++                     notmuch-show-query-context))\r
\r
+ (defvar notmuch-show-stash-map\r
+   (let ((map (make-sparse-keymap)))\r
+@@ -1085,6 +1079,7 @@ thread id.  If a prefix is given, crypto processing is toggled."\r
+       (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)\r
+       (define-key map (kbd "RET") 'notmuch-show-toggle-message)\r
+       (define-key map "#" 'notmuch-show-print-message)\r
++      (define-key map "$" 'notmuch-show-toggle-process-crypto)\r
+       map)\r
+       "Keymap for \"notmuch show\" buffers.")\r
+ (fset 'notmuch-show-mode-map notmuch-show-mode-map)\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 72f78ed..9d8bebd 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -463,9 +463,9 @@ Complete list of currently available key bindings:\r
+   "Return a list of authors for the current region"\r
+   (notmuch-search-properties-in-region 'notmuch-search-subject beg end))\r
\r
+-(defun notmuch-search-show-thread (&optional crypto-switch)\r
++(defun notmuch-search-show-thread ()\r
+   "Display the currently selected thread."\r
+-  (interactive "P")\r
++  (interactive)\r
+   (let ((thread-id (notmuch-search-find-thread-id))\r
+       (subject (notmuch-search-find-subject)))\r
+     (if (> (length thread-id) 0)\r
+@@ -479,8 +479,7 @@ Complete list of currently available key bindings:\r
+                        (concat "*"\r
+                                (truncate-string-to-width subject 32 nil nil t)\r
+                                "*")\r
+-                       32 nil nil t))\r
+-                    crypto-switch)\r
++                       32 nil nil t)))\r
+       (message "End of search results."))))\r
\r
+ (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)\r
+-- \r
+1.7.8.3\r
+\r