Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id AEA41431FBC for ; Sun, 2 Dec 2012 16:59:04 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.224 X-Spam-Level: X-Spam-Status: No, score=0.224 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, HS_INDEX_PARAM=0.023, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PEcaEqbEhoq8 for ; Sun, 2 Dec 2012 16:59:00 -0800 (PST) Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com [74.125.82.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8C1A1431FC0 for ; Sun, 2 Dec 2012 16:58:52 -0800 (PST) Received: by mail-wg0-f47.google.com with SMTP id dq11so1088819wgb.2 for ; Sun, 02 Dec 2012 16:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5wd9b27rjZYb3raJe7qIguUAH0rI2LNuqZOy14ACoVs=; b=v4bVfzUySonKeR4Jha9t5iFtfA/7TQ8oYUvnwuVG+Aqgg/EcGSS6dGoO4u/JrQT/CG 37ux78gYnXoCq8pKIkVt1iRGCd5SqMU+V1Utl43n3MivSNvW+Gnh4JEA1ZC9Kmb9dAet Pa5iuKhTzGk/gVKjWIiZN04gq574X+LY03qGqJX/aCGTe9b6apCUXxzBa723iI0FJRPS DPU/ovWGE1nePYkQLKGXvTTkZ/0BrOa5mTTcToWIucdfzAcA+/vLWTvsVAeX/N956mj0 v1lN4FkZNAxaT3Y7N5/lMKPjwEAgZNYSW4Fx0vrrfs6XuBT+kF25VelzaArhvHCCx5ao qT2A== Received: by 10.180.73.80 with SMTP id j16mr6912588wiv.5.1354496331325; Sun, 02 Dec 2012 16:58:51 -0800 (PST) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPS id en20sm10287474wid.4.2012.12.02.16.58.49 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 02 Dec 2012 16:58:50 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v2 2/3] emacs: allow the user to toggle the visibility of multipart/alternative parts Date: Mon, 3 Dec 2012 00:58:36 +0000 Message-Id: <1354496317-24564-3-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1354496317-24564-1-git-send-email-markwalters1009@gmail.com> References: <1354496317-24564-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Dec 2012 00:59:04 -0000 This patch adds a keybinding to the buttons in the notmuch-show emacs buffer to allow the user to toggle the visibility of each part of a message in the show buffer. This is particularly useful for multipart/alternative parts where the parts are not really alternatives but contain different information. --- emacs/notmuch-show.el | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 39 insertions(+), 9 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index cc0487c..9a33d28 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -154,6 +154,11 @@ indentation." (make-variable-buffer-local 'notmuch-show-indent-content) (put 'notmuch-show-indent-content 'permanent-local t) +(defvar notmuch-show-message-multipart/alternative-display-parts nil + "A list of message-ids/parts where the user has overridden notmuch display choice") +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-parts) +(put 'notmuch-show-message-multipart/alternative-display-parts 'permanent-local t) + (defcustom notmuch-show-stash-mlarchive-link-alist '(("Gmane" . "http://mid.gmane.org/") ("MARC" . "http://marc.info/?i=") @@ -469,6 +474,7 @@ message at DEPTH in the current thread." (define-key map "v" 'notmuch-show-part-button-view) (define-key map "o" 'notmuch-show-part-button-interactively-view) (define-key map "|" 'notmuch-show-part-button-pipe) + (define-key map "t" 'notmuch-show-part-button-internally-show) map) "Submap for button commands") (fset 'notmuch-show-part-button-map notmuch-show-part-button-map) @@ -545,6 +551,16 @@ message at DEPTH in the current thread." (let ((handle (mm-make-handle (current-buffer) (list content-type)))) (mm-pipe-part handle)))) +(defun notmuch-show-internally-show-part (message-id nth &optional filename content-type) + "Set a part to be displayed internally" + (let ((current-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts message-id))) + (setq notmuch-show-message-multipart/alternative-display-parts + (lax-plist-put notmuch-show-message-multipart/alternative-display-parts message-id + (if (memq nth current-parts) + (delq nth current-parts) + (cons nth current-parts))))) + (notmuch-show-refresh-view)) + (defun notmuch-show-multipart/*-to-list (part) (mapcar (lambda (inner-part) (plist-get inner-part :content-type)) (plist-get part :content))) @@ -557,12 +573,12 @@ message at DEPTH in the current thread." ;; This inserts all parts of the chosen type rather than just one, ;; but it's not clear that this is the wrong thing to do - which ;; should be chosen if there are more than one that match? + (mapc (lambda (inner-part) (let ((inner-type (plist-get inner-part :content-type))) - (if (or notmuch-show-all-multipart/alternative-parts - (string= chosen-type inner-type)) - (notmuch-show-insert-bodypart msg inner-part depth) - (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)")))) + (notmuch-show-insert-bodypart msg inner-part depth + (not (or notmuch-show-all-multipart/alternative-parts + (string= chosen-type inner-type)))))) inner-parts) (when notmuch-show-indent-multipart @@ -830,11 +846,20 @@ message at DEPTH in the current thread." (setq handlers (cdr handlers)))) t) -(defun notmuch-show-insert-bodypart (msg part depth) - "Insert the body part PART at depth DEPTH in the current thread." - (let ((content-type (downcase (plist-get part :content-type))) +(defun notmuch-show-insert-bodypart (msg part depth &optional not-shown) + "Insert the body part PART at depth DEPTH in the current thread. + +If not-shown is TRUE then do not show the part unless the user +has overridden the default for this part" + (let ((user-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts + (notmuch-id-to-query (plist-get msg :id)))) + (content-type (downcase (plist-get part :content-type))) (nth (plist-get part :id))) - (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)) + (when (memq nth user-parts) + (setq not-shown (not not-shown))) + (if not-shown + (notmuch-show-insert-part-header nth content-type content-type nil " (not shown)") + (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))) ;; Some of the body part handlers leave point somewhere up in the ;; part, so we make sure that we're down at the end. (goto-char (point-max)) @@ -1185,7 +1210,8 @@ non-nil) then the state of the buffer (open/closed messages) is reset based on the original query." (interactive "P") (let ((inhibit-read-only t) - (state (unless reset-state + (state (if reset-state + (setq notmuch-show-message-multipart/alternative-display-parts nil) (notmuch-show-capture-state)))) (erase-buffer) (notmuch-show-build-buffer) @@ -1980,6 +2006,10 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')." (interactive) (notmuch-show-part-button-internal button #'notmuch-show-pipe-part)) +(defun notmuch-show-part-button-internally-show (&optional button) + (interactive) + (notmuch-show-part-button-internal button #'notmuch-show-internally-show-part)) + (defun notmuch-show-part-button-internal (button handler) (let ((button (or button (button-at (point))))) (if button -- 1.7.9.1