From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9DC896DE1532 for ; Sat, 20 Feb 2016 10:24:51 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.277 X-Spam-Level: X-Spam-Status: No, score=-0.277 tagged_above=-999 required=5 tests=[AWL=0.293, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ItOnu4E_a5Xm for ; Sat, 20 Feb 2016 10:24:49 -0800 (PST) Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by arlo.cworth.org (Postfix) with ESMTPS id 7611E6DE10C1 for ; Sat, 20 Feb 2016 10:24:49 -0800 (PST) Received: by mail-wm0-f52.google.com with SMTP id g62so119127957wme.1 for ; Sat, 20 Feb 2016 10:24:49 -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:in-reply-to:references; bh=NWbHPw2HiMGgOpd2+kAthzIAOeQpq3oddYpX6iaclWM=; b=K6GH0HoyyTrmfo91vDAOBwWlufxryyDIUOwk6BrMoIlHUP1xT6xTnPUqKzdNT0RxTN V3dwyfYCuhJpu0ig41Zs3AvJxnhbIsH3NwF23s1QmtHhwXUb9BloPUeeR3OMuSv5URpn RNGDa73i7x6dmKsmIVyfWG3GKgNWBNTwSUDNQOv/tO8asGsK7p/CD27ZzWmvgQ+Md5AY NP4p6h4VUYSfSzwPaZTNjWtNBASxoldPtSqKsx+9udGjSzt05jxFHrvy1XyP3HInbCaV lyf7WpGsa49HvO+V/SMVYX/u7W+/aVtUdeATpFO1QRC0qkn8EuTp9z3AnhMiPRHGWe8n NnkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NWbHPw2HiMGgOpd2+kAthzIAOeQpq3oddYpX6iaclWM=; b=CIe7eencPj5HmGeb+8zE+QKN6Hu6LMpcjAsdKXkjtI1plBjYvVWaV1FtWuqeF0609O 0L4hudJeEfI8QgMIkrq36oW5si7fe560DjyUo0cO0P1oYpYQs4SUSiDYc+le/kyfwnCd Dqa221crYKlHwx2GIQOciGJloVVvHJP/bDaKuUGPJ0s6n0So59Hh8IKY7HL/8UIUfb7S eOE2U36CZjRQn9DIyccLu0Krwz/aKjQoKdZTEHygNVg/vPG4cEjGP+Xj3VD6d4GqCEdW BzlW1xfonhLJyAz3vIYe/jH3sj7OT+Vf2tLNWuB5dYJ0YGGzjMUXaZe+IA8VmPJ28SX2 QjXA== X-Gm-Message-State: AG10YORdDwPUBCW1APTd0PdLq6Mgx8tmYzYuqbmy33U4bVDvE4lg6lNahOfZJc6BhnSx6g== X-Received: by 10.194.142.135 with SMTP id rw7mr9489023wjb.84.1455992688186; Sat, 20 Feb 2016 10:24:48 -0800 (PST) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id u9sm13132517wmd.4.2016.02.20.10.24.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Feb 2016 10:24:46 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v6 1/6] emacs/show: Re-arrange determination if a part header is necessary Date: Sat, 20 Feb 2016 18:24:35 +0000 Message-Id: <1455992680-24978-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455992680-24978-1-git-send-email-markwalters1009@gmail.com> References: <1455992680-24978-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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: Sat, 20 Feb 2016 18:24:51 -0000 From: David Edmondson Move the determination of whether a part header is required to a distinct function. --- emacs/notmuch-show.el | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 4629c64..9d9c89f 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -921,6 +921,22 @@ (defun notmuch-show-lazy-part (part-args button) ;; 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 hide) + "Return non-NIL if a header button should be inserted for this part." + ;; Show all part buttons except for the first part if it is text/plain. + (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. @@ -931,20 +947,16 @@ (defun notmuch-show-insert-bodypart (msg part depth &optional hide) 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)) (long (and (notmuch-match-content-type mime-type "text/*") (> notmuch-show-max-text-part-size 0) (> (length (plist-get part :content)) notmuch-show-max-text-part-size))) (beg (point)) - ;; 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))) + ;; We show the part button if notmuch-show-insert-header-p + ;; says to, unless HIDE is 'no-buttons. + (button (when (and (not (equal hide 'no-buttons)) + (notmuch-show-insert-header-p part hide)) (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))) ;; Hide the part initially if HIDE is t, or if it is too long ;; and we have a button to allow toggling (thus reply which -- 2.1.4