--- /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 57A9F431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Jun 2013 21:57:33 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 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
+ 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 8uzrm70-bP0V for <notmuch@notmuchmail.org>;\r
+ Sun, 9 Jun 2013 21:57:27 -0700 (PDT)\r
+Received: from mail-ee0-f47.google.com (mail-ee0-f47.google.com\r
+ [74.125.83.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ A1510431FB6 for <notmuch@notmuchmail.org>; Sun, 9 Jun 2013 21:57:22 -0700\r
+ (PDT)\r
+Received: by mail-ee0-f47.google.com with SMTP id e49so2712674eek.34\r
+ for <notmuch@notmuchmail.org>; Sun, 09 Jun 2013 21:57:21 -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=ZHmWSds/1QERWW6wSNI2NBY/0KFuj22nyIuM3XSWRPI=;\r
+ b=N+kHV55aJhkAgYfwwZMmO0d8rPuFbV07MMS5r5gRLjlFJEI/mlEh7r86NYv6sufelT\r
+ +WE4RlYubgsaNQzUwf0ToAAi05gXnDkxckXuCejIEzoTlC8I0vHbRKaoinRYPn3Ic1lO\r
+ LxlHTbLRyllphez+IoyTRNreeuK4OpYqGK5dPETYnAL1lfDnNHTJclSU+/X2yfgfGVCM\r
+ rJ1SJtkst/Up8f+dTICs+Haq5kX7McDKjpXrnvHa5g5TQe6hv6OIASG9bvX+MPWH2K5Q\r
+ MRaWGFEuh5byH2tONNTQDCKUrdn2YDbktld9NgTFKIpbCw2muKGFjNhGOvaUO7++svf/\r
+ FiGA==\r
+X-Received: by 10.15.73.197 with SMTP id h45mr8834235eey.146.1370840241486;\r
+ Sun, 09 Jun 2013 21:57:21 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id\r
+ y44sm20220825eel.10.2013.06.09.21.57.20 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 09 Jun 2013 21:57:21 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+ Austin Clements <aclements@csail.mit.edu>\r
+Subject: [PATCH v5 2/6] emacs: show: move the insertion of the header button\r
+ to the top level\r
+Date: Mon, 10 Jun 2013 05:57:09 +0100\r
+Message-Id: <1370840233-23258-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1370840233-23258-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1370840233-23258-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: Mon, 10 Jun 2013 04:57:33 -0000\r
+\r
+Previously each of the part insertion handlers inserted the part\r
+button themselves. Move this up into\r
+notmuch-show-insert-bodypart. Since a small number of the handlers\r
+modify the button (the encryption/signature ones) we need to pass the\r
+header button as an argument into the individual part insertion\r
+handlers. However, the declared-type argument was only used for the\r
+text for the part buttons we can now omit it.\r
+\r
+The patch is large but mostly simple. The only things of note are that\r
+we let the text/plain handler applies notmuch-wash to the whole part\r
+including the part button. In particular, notmuch-wash removes leading\r
+blank lines from a text/plain part, but since the button is counted as\r
+part of the part this does not happen with text/plain buttons that\r
+have a button. This is probably a bug in notmuch-wash but changing it\r
+does make several tests fail (that rely on this blank line) so, for\r
+the moment, keep the old behaviour.\r
+---\r
+ emacs/notmuch-show.el | 97 ++++++++++++++++++++++++-------------------------\r
+ 1 files changed, 47 insertions(+), 50 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 209cd4a..c69456a 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -514,8 +514,7 @@ message at DEPTH in the current thread."\r
+ (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
+ (plist-get part :content)))\r
+ \r
+-(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
+- (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)\r
+ (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
+ (inner-parts (plist-get part :content))\r
+ (start (point)))\r
+@@ -592,8 +591,7 @@ message at DEPTH in the current thread."\r
+ content-type)\r
+ nil)))\r
+ \r
+-(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type)\r
+- (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth button)\r
+ (let ((inner-parts (plist-get part :content))\r
+ (start (point)))\r
+ \r
+@@ -612,16 +610,15 @@ message at DEPTH in the current thread."\r
+ (indent-rigidly start (point) 1)))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)\r
+- (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
+- (button-put button 'face 'notmuch-crypto-part-header)\r
+- ;; add signature status button if sigstatus provided\r
+- (if (plist-member part :sigstatus)\r
+- (let* ((from (notmuch-show-get-header :From msg))\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 it\r
+- (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
++(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)\r
++ (button-put button 'face 'notmuch-crypto-part-header)\r
++ ;; add signature status button if sigstatus provided\r
++ (if (plist-member part :sigstatus)\r
++ (let* ((from (notmuch-show-get-header :From msg))\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 it\r
++ (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
+ \r
+ (let ((inner-parts (plist-get part :content))\r
+ (start (point)))\r
+@@ -634,20 +631,19 @@ message at DEPTH in the current thread."\r
+ (indent-rigidly start (point) 1)))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)\r
+- (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
+- (button-put button 'face 'notmuch-crypto-part-header)\r
+- ;; add encryption status button if encstatus specified\r
+- (if (plist-member part :encstatus)\r
+- (let ((encstatus (car (plist-get part :encstatus))))\r
+- (notmuch-crypto-insert-encstatus-button encstatus)\r
+- ;; add signature status button if sigstatus specified\r
+- (if (plist-member part :sigstatus)\r
+- (let* ((from (notmuch-show-get-header :From msg))\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 it\r
+- (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
++(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)\r
++ (button-put button 'face 'notmuch-crypto-part-header)\r
++ ;; add encryption status button if encstatus specified\r
++ (if (plist-member part :encstatus)\r
++ (let ((encstatus (car (plist-get part :encstatus))))\r
++ (notmuch-crypto-insert-encstatus-button encstatus)\r
++ ;; add signature status button if sigstatus specified\r
++ (if (plist-member part :sigstatus)\r
++ (let* ((from (notmuch-show-get-header :From msg))\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 it\r
++ (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
+ \r
+ (let ((inner-parts (plist-get part :content))\r
+ (start (point)))\r
+@@ -660,8 +656,7 @@ message at DEPTH in the current thread."\r
+ (indent-rigidly start (point) 1)))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)\r
+- (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth button)\r
+ (let ((inner-parts (plist-get part :content))\r
+ (start (point)))\r
+ ;; Show all of the parts.\r
+@@ -673,8 +668,7 @@ message at DEPTH in the current thread."\r
+ (indent-rigidly start (point) 1)))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)\r
+- (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth button)\r
+ (let* ((message (car (plist-get part :content)))\r
+ (body (car (plist-get message :body)))\r
+ (start (point)))\r
+@@ -695,12 +689,13 @@ message at DEPTH in the current thread."\r
+ (indent-rigidly start (point) 1)))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type)\r
+- (let ((start (point)))\r
+- ;; If this text/plain part is not the first part in the message,\r
+- ;; insert a header to make this clear.\r
+- (if (> nth 1)\r
+- (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)))\r
++(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth button)\r
++ ;; For backward compatibility we want to apply the text/plain hook\r
++ ;; to the whole of the part including the part button if there is\r
++ ;; one.\r
++ (let ((start (if button\r
++ (button-start button)\r
++ (point))))\r
+ (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
+ (save-excursion\r
+ (save-restriction\r
+@@ -708,8 +703,7 @@ message at DEPTH in the current thread."\r
+ (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type)\r
+- (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))\r
++(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)\r
+ (insert (with-temp-buffer\r
+ (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
+ ;; notmuch-get-bodypart-content provides "raw", non-converted\r
+@@ -732,8 +726,8 @@ message at DEPTH in the current thread."\r
+ t)\r
+ \r
+ ;; For backwards compatibility.\r
+-(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)\r
+- (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type))\r
++(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth button)\r
++ (notmuch-show-insert-part-text/calendar msg part content-type nth depth button))\r
+ \r
+ (defun notmuch-show-get-mime-type-of-application/octet-stream (part)\r
+ ;; If we can deduce a MIME type from the filename of the attachment,\r
+@@ -751,7 +745,7 @@ message at DEPTH in the current thread."\r
+ nil))\r
+ nil))))\r
+ \r
+-(defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-part-text/html (msg part content-type nth depth button)\r
+ ;; text/html handler to work around bugs in renderers and our\r
+ ;; invisibile parts code. In particular w3m sets up a keymap which\r
+ ;; "leaks" outside the invisible region and causes strange effects\r
+@@ -759,11 +753,10 @@ message at DEPTH in the current thread."\r
+ ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map\r
+ ;; remains).\r
+ (let ((mm-inline-text-html-with-w3m-keymap nil))\r
+- (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))\r
++ (notmuch-show-insert-part-*/* msg part content-type nth depth button)))\r
+ \r
+-(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)\r
+ ;; This handler _must_ succeed - it is the handler of last resort.\r
+- (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))\r
+ (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)\r
+ t)\r
+ \r
+@@ -786,13 +779,13 @@ message at DEPTH in the current thread."\r
+ \r
+ ;; \f\r
+\r
+ \r
+-(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button)\r
+ (let ((handlers (notmuch-show-handlers-for content-type)))\r
+ ;; Run the content handlers until one of them returns a non-nil\r
+ ;; value.\r
+ (while (and handlers\r
+ (not (condition-case err\r
+- (funcall (car handlers) msg part content-type nth depth declared-type)\r
++ (funcall (car handlers) msg part content-type nth depth button)\r
+ (error (progn\r
+ (insert "!!! Bodypart insert error: ")\r
+ (insert (error-message-string err))\r
+@@ -820,6 +813,7 @@ message at DEPTH in the current thread."\r
+ "Insert the body part PART at depth DEPTH in the current thread.\r
+ \r
+ If HIDE is non-nil then initially hide this part."\r
++\r
+ (let* ((content-type (downcase (plist-get part :content-type)))\r
+ (mime-type (or (and (string= content-type "application/octet-stream")\r
+ (notmuch-show-get-mime-type-of-application/octet-stream part))\r
+@@ -827,9 +821,12 @@ If HIDE is non-nil then initially hide this part."\r
+ "text/x-diff")\r
+ content-type))\r
+ (nth (plist-get part :id))\r
+- (beg (point)))\r
++ (beg (point))\r
++ ;; We omit the part button for the first (or only) part if this is text/plain.\r
++ (button (unless (and (string= mime-type "text/plain") (<= nth 1))\r
++ (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))))\r
+ \r
+- (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type)\r
++ (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)\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
+-- \r
+1.7.9.1\r
+\r