Re: [PATCH v7 1/8] emacs: Rework crypto switch toggle.
authorDavid Edmondson <dme@dme.org>
Wed, 8 Feb 2012 06:21:34 +0000 (06:21 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:15 +0000 (09:44 -0800)
ae/12a862b81de09e1d1bdaa54aaeaf572c69cd0d [new file with mode: 0644]

diff --git a/ae/12a862b81de09e1d1bdaa54aaeaf572c69cd0d b/ae/12a862b81de09e1d1bdaa54aaeaf572c69cd0d
new file mode 100644 (file)
index 0000000..9c6d348
--- /dev/null
@@ -0,0 +1,384 @@
+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 4945C431FAF\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 22:21:49 -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 jYfvQOpyu5lp for <notmuch@notmuchmail.org>;\r
+       Tue,  7 Feb 2012 22:21:45 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ A84A7431FAE   for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 22:21:44 -0800\r
+ (PST)\r
+Received: by eeke51 with SMTP id e51so101098eek.26\r
+       for <notmuch@notmuchmail.org>; Tue, 07 Feb 2012 22:21:42 -0800 (PST)\r
+Received: by 10.14.17.213 with SMTP id j61mr8118761eej.110.1328682102748;\r
+       Tue, 07 Feb 2012 22:21:42 -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 z47sm1595473eeh.9.2012.02.07.22.21.40\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 07 Feb 2012 22:21:41 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id AF6C0A37F7; Wed,  8 Feb 2012 06:21:38 +0000 (GMT)\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH v7 1/8] emacs: Rework crypto switch toggle.\r
+In-Reply-To: <20120208051016.GB27039@mit.edu>\r
+References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
+       <1328520082-26659-1-git-send-email-dme@dme.org>\r
+       <1328520082-26659-2-git-send-email-dme@dme.org>\r
+       <20120208051016.GB27039@mit.edu>\r
+User-Agent: Notmuch/0.11.1+153~gdd83b99 (http://notmuchmail.org)\r
+       Emacs/24.0.92.1 (x86_64-pc-linux-gnu)\r
+From: David Edmondson <dme@dme.org>\r
+Date: Wed, 08 Feb 2012 06:21:34 +0000\r
+Message-ID: <cunvcnh3kwh.fsf@hotblack-desiato.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha1; protocol="application/pgp-signature"\r
+Cc: notmuch@notmuchmail.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: Wed, 08 Feb 2012 06:21:53 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Wed, 8 Feb 2012 00:10:16 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Seems reasonable.  I'm definitely in favor of erasing buffers instead\r
+> of killing and recreating them.  Two questions below.\r
+\r
+Thanks for the review.\r
+\r
+> Quoth David Edmondson on Feb 06 at  9:21 am:\r
+> > Re-work the existing crypto switch toggle to be based on a persistant\r
+> > buffer-local variable.\r
+> >=20\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
+> >=20\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
+-------\r
+> >  emacs/notmuch.el      |    7 +--\r
+> >  2 files changed, 66 insertions(+), 67 deletions(-)\r
+> >=20\r
+> > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> > index 7469e2e..4b29dbd 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
+> >=20=20\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
+>=20\r
+> Do these need to be permanent-local given that refreshing is now done\r
+> by erasing the buffer instead of killing it?\r
+\r
+Yes. `notmuch-show-worker' (which does the refreshing) still calls\r
+`notmuch-show-mode', which still calls `kill-all-local-variables'.\r
+\r
+Tidying that is for another patch.\r
+\r
+> >  (defmacro with-current-notmuch-show-message (&rest body)\r
+> >    "Evaluate body with current buffer set to the text of current messag=\r
+e"\r
+> >    `(save-excursion\r
+> > @@ -421,14 +437,11 @@ message at DEPTH in the current thread."\r
+> >=20=20\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
+>=20\r
+> Why is the piping of notmuch-show-process-crypto no longer necessary?\r
+> It's still buffer-local, and hence will be nil in the temp buffer.\r
+\r
+It's a bug. v8 after breakfast.\r
+\r
+> >=20=20\r
+> >  (defun notmuch-show-save-part (message-id nth &optional filename conte=\r
+nt-type)\r
+> >    (notmuch-with-temp-part-buffer message-id nth\r
+> > @@ -610,7 +623,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=\r
+ it\r
+> > -      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
+o process cryptographic mime parts.")))\r
+> > +      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
+o process cryptographic MIME parts.")))\r
+> >=20=20\r
+> >    (let ((inner-parts (plist-get part :content))\r
+> >    (start (point)))\r
+> > @@ -636,7 +649,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=\r
+ it\r
+> > -      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
+o process cryptographic mime parts.")))\r
+> > +      (button-put button 'help-echo "Set notmuch-crypto-process-mime t=\r
+o process cryptographic MIME parts.")))\r
+> >=20=20\r
+> >    (let ((inner-parts (plist-get part :content))\r
+> >    (start (point)))\r
+> > @@ -763,8 +776,6 @@ current buffer, if possible."\r
+> >=20=20\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=3Draw"))\r
+> >    (part-arg (format "--part=3D%s" part-number)))\r
+> > @@ -918,6 +929,15 @@ current buffer, if possible."\r
+> >      ;; criteria.\r
+> >      (notmuch-show-message-visible msg (plist-get msg :match))))\r
+> >=20=20\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
+> > @@ -933,15 +953,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
+> >=20=20\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
+> >=20=20\r
+> > @@ -961,7 +972,7 @@ a corresponding notmuch search."\r
+> >                    'face goto-address-mail-face))))\r
+> >=20=20\r
+> >  ;;;###autoload\r
+> > -(defun notmuch-show (thread-id &optional parent-buffer query-context b=\r
+uffer-name crypto-switch)\r
+> > +(defun notmuch-show (thread-id &optional parent-buffer query-context b=\r
+uffer-name)\r
+> >    "Run \"notmuch show\" with the given thread ID and display results.\r
+> >=20=20\r
+> >  The optional PARENT-BUFFER is the notmuch-search buffer from\r
+> > @@ -976,46 +987,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-=\r
+name process-crypto)))\r
+> > -\r
+> > -(defun notmuch-show-worker (thread-id parent-buffer query-context buff=\r
+er-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
+> >=20=20\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
+\'"))\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
+> >=20=20\r
+> > @@ -1032,21 +1038,14 @@ buffer."\r
+> >=20=20\r
+> >      (notmuch-show-mark-read)))\r
+> >=20=20\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
+> >=20=20\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-=\r
+name process-crypto)))\r
+> > +Refreshes the current view, observing changes in cryptographic prefere=\r
+nces."\r
+> > +  (interactive)\r
+> > +  (let ((inhibit-read-only t))\r
+> > +    (erase-buffer))\r
+> > +  (notmuch-show-worker))\r
+> >=20=20\r
+> >  (defvar notmuch-show-stash-map\r
+> >    (let ((map (make-sparse-keymap)))\r
+> > @@ -1097,6 +1096,7 @@ thread id.  If a prefix is given, crypto processi=\r
+ng 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 cd04ffd..ff0db99 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
+> >=20=20\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-prettify-subject (notmuch-search-find-subject))))\r
+> >      (if (> (length thread-id) 0)\r
+> > @@ -473,8 +473,7 @@ Complete list of currently available key bindings:\r
+> >                  (current-buffer)\r
+> >                  notmuch-search-query-string\r
+> >                  ;; Name the buffer based on the subject.\r
+> > -                (concat "*" (truncate-string-to-width subject 30 nil nil t) "*=\r
+")\r
+> > -                crypto-switch)\r
+> > +                (concat "*" (truncate-string-to-width subject 30 nil nil t) "*=\r
+"))\r
+> >        (message "End of search results."))))\r
+> >=20=20\r
+> >  (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.11 (GNU/Linux)\r
+\r
+iEYEARECAAYFAk8yFG4ACgkQaezQq/BJZRbXOgCeM4wQB0VrfV5AXYmuYhL+RKet\r
+bFIAn0VHsotEKKltcFE4k1+M5E3Xrj4c\r
+=N2k6\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r