[PATCH v6 1/8] emacs: Rework crypto switch toggle.
authorDavid Edmondson <dme@dme.org>
Thu, 2 Feb 2012 11:23:46 +0000 (11:23 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:56 +0000 (09:43 -0800)
44/ef085a796ec05f9e7a6a6a93387fb415ca00a7 [new file with mode: 0644]

diff --git a/44/ef085a796ec05f9e7a6a6a93387fb415ca00a7 b/44/ef085a796ec05f9e7a6a6a93387fb415ca00a7
new file mode 100644 (file)
index 0000000..c42382f
--- /dev/null
@@ -0,0 +1,321 @@
+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 C628E431FBF\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 03:24:02 -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 juLtUXFMUmtQ for <notmuch@notmuchmail.org>;\r
+       Thu,  2 Feb 2012 03:24:00 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+       [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 8AE7B431FAE\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 03:24:00 -0800 (PST)\r
+Received: by wibhi8 with SMTP id hi8so1799272wib.26\r
+       for <notmuch@notmuchmail.org>; Thu, 02 Feb 2012 03:23:58 -0800 (PST)\r
+Received: by 10.180.24.7 with SMTP id q7mr3860255wif.14.1328181838916;\r
+       Thu, 02 Feb 2012 03:23:58 -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 x7sm25951099wif.10.2012.02.02.03.23.56\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 02 Feb 2012 03:23:56 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 9E0FEA04A4; Thu,  2 Feb 2012 11:23:54 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v6 1/8] emacs: Rework crypto switch toggle.\r
+Date: Thu,  2 Feb 2012 11:23:46 +0000\r
+Message-Id: <1328181833-14988-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1328181833-14988-1-git-send-email-dme@dme.org>\r
+References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
+       <1328181833-14988-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: Thu, 02 Feb 2012 11:24:03 -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 |  126 ++++++++++++++++++++++++------------------------\r
+ emacs/notmuch.el      |    7 +--\r
+ 2 files changed, 66 insertions(+), 67 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index de9421e..b6329d2 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -125,6 +125,22 @@ 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
++(put 'notmuch-show-thread-id 'permanent-local t)\r
++\r
++(defvar notmuch-show-parent-buffer nil)\r
++(make-variable-buffer-local 'notmuch-show-parent-buffer)\r
++(put 'notmuch-show-parent-buffer 'permanent-local t)\r
++\r
++(defvar notmuch-show-query-context nil)\r
++(make-variable-buffer-local 'notmuch-show-query-context)\r
++(put 'notmuch-show-query-context 'permanent-local t)\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
+@@ -411,14 +427,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
+@@ -600,7 +613,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
+@@ -626,7 +639,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
+@@ -753,8 +766,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
+@@ -908,6 +919,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
+@@ -923,15 +943,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
+@@ -951,7 +962,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
+@@ -966,46 +977,41 @@ 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
++\r
++    (setq notmuch-show-thread-id thread-id\r
++        notmuch-show-parent-buffer parent-buffer\r
++        notmuch-show-query-context query-context)\r
++    (notmuch-show-worker)))\r
++\r
++(defun notmuch-show-worker ()\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
\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
+     (save-excursion\r
+-      (let* ((basic-args (list thread-id))\r
+-           (args (if query-context\r
+-                     (append (list "\'") basic-args (list "and (" query-context ")\'"))\r
++      (let* ((basic-args (list notmuch-show-thread-id))\r
++           (args (if notmuch-show-query-context\r
++                     (append (list "\'") basic-args\r
++                             (list "and (" notmuch-show-query-context ")\'"))\r
+                    (append (list "\'") basic-args (list "\'")))))\r
+       (notmuch-show-insert-forest (notmuch-query-get-threads args))\r
+       ;; If the query context reduced the results to nothing, run\r
+       ;; the basic query.\r
+       (when (and (eq (buffer-size) 0)\r
+-                 query-context)\r
++                 notmuch-show-query-context)\r
+         (notmuch-show-insert-forest\r
+          (notmuch-query-get-threads basic-args))))\r
\r
+@@ -1022,21 +1028,14 @@ 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))\r
\r
+ (defvar notmuch-show-stash-map\r
+   (let ((map (make-sparse-keymap)))\r
+@@ -1087,6 +1086,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