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 1FFA8431FC2 for ; Mon, 12 May 2014 05:29:44 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 ws3jpj2D4Fee for ; Mon, 12 May 2014 05:29:38 -0700 (PDT) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 146AB431FCB for ; Mon, 12 May 2014 05:29:33 -0700 (PDT) Received: by mail-wi0-f173.google.com with SMTP id bs8so4359779wib.6 for ; Mon, 12 May 2014 05:29:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ipdvO6xL3t8JHovYHW3OTwGHJbS5OJkzs4NgmemMm2Y=; b=YsojfmzIinrqYW4N/Mh3mkhfa9mNnBaxP5vp3wPpwsdvbVpfI0Hzx5RXOMtB9RgHLJ nQmu2AdZjXtkzLJAPrA48/z4AzoRc52vDWO3MGGIjR62tkgj24QCmMEOOCLEQWFcUU/t JZ4itzcs1O9Lgmw7kXC/9NPNKxLn4fmQvK4YPbnWyln3/Lp9e7A22dJG9xnECgvvMfor 4D3Rvyhnf6oevi9R3LB4ETUzhkq7acmZDf07hvKI4RTTBFOxoex8FkpNhwNyrSnO5/Bq Dm7/D73eI0pK6iZ+xtj34pbGA0SN9x6ECb0CEh6EG7knlBHSbxNhmbi/C1rUFkxvohcx wZ2A== X-Gm-Message-State: ALoCoQmpQhZzkdvQdMBVSBk0H0/FCyBR2zovZEq11OmV7oHjhe6zyeh9eM+n21GFDb9ejJN9vPKP X-Received: by 10.180.19.201 with SMTP id h9mr3258424wie.17.1399897771659; Mon, 12 May 2014 05:29:31 -0700 (PDT) Received: from hotblack-desiato.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by mx.google.com with ESMTPSA id l12sm17746272wjr.35.2014.05.12.05.29.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 May 2014 05:29:30 -0700 (PDT) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 3625610B308; Mon, 12 May 2014 13:29:29 +0100 (BST) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v3 1/9] emacs/show: Re-arrange determination if a part header is necessary Date: Mon, 12 May 2014 13:29:21 +0100 Message-Id: <1399897769-26809-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 2.0.0.rc0 In-Reply-To: <1399897769-26809-1-git-send-email-dme@dme.org> References: <87sixdujkv.fsf@qmul.ac.uk> <1399897769-26809-1-git-send-email-dme@dme.org> 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, 12 May 2014 12:29:44 -0000 Move the determination of whether a part header is required to a distinct function. --- emacs/notmuch-show.el | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 10fc872..ec99141 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -871,6 +871,21 @@ message at DEPTH in the current thread." ;; showable this returns nil. (notmuch-show-create-part-overlays button part-beg part-end)))) +(defun notmuch-show-mime-type (part) + "Return the correct mime-type to use for PART." + (let ((content-type (downcase (plist-get part :content-type)))) + (or (and (string= content-type "application/octet-stream") + (notmuch-show-get-mime-type-of-application/octet-stream part)) + (and (string= content-type "inline patch") + "text/x-diff") + content-type))) + +(defun notmuch-show-insert-header-p (part) + "Return non-NIL if a header button should be inserted for this part." + (let ((mime-type (notmuch-show-mime-type part))) + (not (and (string= mime-type "text/plain") + (<= (plist-get part :id) 1))))) + (defun notmuch-show-insert-bodypart (msg part depth &optional hide) "Insert the body part PART at depth DEPTH in the current thread. @@ -881,19 +896,15 @@ is t, hide the part initially and show the button. If HIDE is useful for quoting in replies)." (let* ((content-type (downcase (plist-get part :content-type))) - (mime-type (or (and (string= content-type "application/octet-stream") - (notmuch-show-get-mime-type-of-application/octet-stream part)) - (and (string= content-type "inline patch") - "text/x-diff") - content-type)) + (mime-type (notmuch-show-mime-type part)) (nth (plist-get part :id)) (beg (point)) ;; Hide the part initially if HIDE is t. (show-part (not (equal hide t))) ;; We omit the part button for the first (or only) part if ;; this is text/plain, or HIDE is 'no-buttons. - (button (unless (or (equal hide 'no-buttons) - (and (string= mime-type "text/plain") (<= nth 1))) + (button (when (and (not (equal hide 'no-buttons)) + (notmuch-show-insert-header-p part)) (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))) (content-beg (point))) -- 2.0.0.rc0