--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\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 B8B9D431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 25 Oct 2012 01:09:35 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.224\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.224 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ HS_INDEX_PARAM=0.023, 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 GVWLE-NwvY5R for <notmuch@notmuchmail.org>;\r
+ Thu, 25 Oct 2012 01:09:34 -0700 (PDT)\r
+Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com\r
+ [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 805AB431FB6 for <notmuch@notmuchmail.org>; Thu, 25 Oct 2012 01:09:34 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f45.google.com with SMTP id dq12so897880wgb.2\r
+ for <notmuch@notmuchmail.org>; Thu, 25 Oct 2012 01:09:34 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=h/qeN0c4LCP9QLKd8DlGceDUWyKHZ7WpnaiVtjcMaDg=;\r
+ b=XWDgaoOfjGiFZk5lEokPhkNgLGcgDG8lYVg9O5qze93DJEWAMB15zhaAK6ojLF4BX0\r
+ rSkvtB1jpz6vtcSdXKBvkSBqWpeWYZJY17xSGMpN7cq4R9FAUUYKl0BW4GCgZ+ZTP+li\r
+ BjdWUd8nv9WxK9+4rjccDjJX/z941M/HC5Aw3GBtoWEOxXf7ba4nZe6Vu4bkpzJjaWvj\r
+ 07rR8hQ2gfeXpamlVSQOOWWfmlB1EhJj7k2W+MfHilYzZBzJCKa1KCWwPcDZiblzL7Fr\r
+ vKCWHux0EiBAs8lS34Z0U2kstcrkbb61JWtuE47sW0f1mp3InxoD833IOC1o9Sw4jd+F\r
+ HsSQ==\r
+Received: by 10.180.82.72 with SMTP id g8mr8438486wiy.20.1351152574147;\r
+ Thu, 25 Oct 2012 01:09:34 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPS id b7sm8758781wiz.3.2012.10.25.01.09.32\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Thu, 25 Oct 2012 01:09:33 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH (draft) 1/2] emacs: allow the user to toggle the visibility of\r
+ multipart/alternative parts\r
+Date: Thu, 25 Oct 2012 09:09:22 +0100\r
+Message-Id: <1351152563-27277-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1351152563-27277-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1351152563-27277-1-git-send-email-markwalters1009@gmail.com>\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, 25 Oct 2012 08:09:36 -0000\r
+\r
+This patch adds a keybinding to the buttons in the notmuch-show emacs\r
+buffer to allow the user to toggle the visibility of each part of a\r
+message in the show buffer. This is particularly useful for\r
+multipart/alternative parts where the parts are not really\r
+alternatives but contain different information.\r
+---\r
+ emacs/notmuch-show.el | 47 +++++++++++++++++++++++++++++++++++++++--------\r
+ 1 files changed, 39 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 0f54259..9157669 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -155,6 +155,10 @@ indentation."\r
+ (make-variable-buffer-local 'notmuch-show-indent-content)\r
+ (put 'notmuch-show-indent-content 'permanent-local t)\r
+ \r
++(defvar notmuch-show-message-multipart/alternative-display-parts nil)\r
++(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-parts)\r
++(put 'notmuch-show-message-multipart/alternative-display-parts 'permanent-local t)\r
++\r
+ (defcustom notmuch-show-stash-mlarchive-link-alist\r
+ '(("Gmane" . "http://mid.gmane.org/")\r
+ ("MARC" . "http://marc.info/?i=")\r
+@@ -455,6 +459,7 @@ message at DEPTH in the current thread."\r
+ (define-key map "v" 'notmuch-show-part-button-view)\r
+ (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
+ (define-key map "|" 'notmuch-show-part-button-pipe)\r
++ (define-key map "t" 'notmuch-show-part-button-internally-show)\r
+ map)\r
+ "Submap for button commands")\r
+ (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
+@@ -531,6 +536,16 @@ message at DEPTH in the current thread."\r
+ (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
+ (mm-pipe-part handle))))\r
+ \r
++(defun notmuch-show-internally-show-part (message-id nth &optional filename content-type)\r
++ "Set a part to be displayed internally"\r
++ (let ((current-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts message-id)))\r
++ (setq notmuch-show-message-multipart/alternative-display-parts\r
++ (lax-plist-put notmuch-show-message-multipart/alternative-display-parts message-id\r
++ (if (memq nth current-parts)\r
++ (delq nth current-parts)\r
++ (cons nth current-parts)))))\r
++ (notmuch-show-refresh-view))\r
++\r
+ (defun notmuch-show-multipart/*-to-list (part)\r
+ (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
+ (plist-get part :content)))\r
+@@ -543,12 +558,15 @@ message at DEPTH in the current thread."\r
+ ;; This inserts all parts of the chosen type rather than just one,\r
+ ;; but it's not clear that this is the wrong thing to do - which\r
+ ;; should be chosen if there are more than one that match?\r
++\r
++ ;; The variable user-parts says which parts should override the\r
++ ;; default so we use xor (handcoded since lisp does not have it).\r
++\r
+ (mapc (lambda (inner-part)\r
+ (let ((inner-type (plist-get inner-part :content-type)))\r
+- (if (or notmuch-show-all-multipart/alternative-parts\r
+- (string= chosen-type inner-type))\r
+- (notmuch-show-insert-bodypart msg inner-part depth)\r
+- (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))\r
++ (notmuch-show-insert-bodypart msg inner-part depth\r
++ (not (or notmuch-show-all-multipart/alternative-parts\r
++ (string= chosen-type inner-type))))))\r
+ inner-parts)\r
+ \r
+ (when notmuch-show-indent-multipart\r
+@@ -806,11 +824,20 @@ message at DEPTH in the current thread."\r
+ (setq handlers (cdr handlers))))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-bodypart (msg part depth)\r
+- "Insert the body part PART at depth DEPTH in the current thread."\r
+- (let ((content-type (downcase (plist-get part :content-type)))\r
++(defun notmuch-show-insert-bodypart (msg part depth &optional not-shown)\r
++ "Insert the body part PART at depth DEPTH in the current thread.\r
++\r
++If not-shown is TRUE then do not show the part unless the user\r
++has overridden the default for this part"\r
++ (let ((user-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts\r
++ (notmuch-id-to-query (plist-get msg :id))))\r
++ (content-type (downcase (plist-get part :content-type)))\r
+ (nth (plist-get part :id)))\r
+- (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))\r
++ (when (memq nth user-parts)\r
++ (setq not-shown (not not-shown)))\r
++ (if not-shown\r
++ (notmuch-show-insert-part-header nth content-type content-type nil " (not shown)")\r
++ (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)))\r
+ ;; Some of the body part handlers leave point somewhere up in the\r
+ ;; part, so we make sure that we're down at the end.\r
+ (goto-char (point-max))\r
+@@ -1895,6 +1922,10 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')."\r
+ (interactive)\r
+ (notmuch-show-part-button-internal button #'notmuch-show-pipe-part))\r
+ \r
++(defun notmuch-show-part-button-internally-show (&optional button)\r
++ (interactive)\r
++ (notmuch-show-part-button-internal button #'notmuch-show-internally-show-part))\r
++\r
+ (defun notmuch-show-part-button-internal (button handler)\r
+ (let ((button (or button (button-at (point)))))\r
+ (if button\r
+-- \r
+1.7.9.1\r
+\r