From b9364015a00b014e0f1ee6827597fed83e558387 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Fri, 31 May 2013 19:26:43 +0100 Subject: [PATCH] [PATCH v3 2/5] emacs: show: move the insertion of the header button to the top level --- 28/971d9165716bf8b85731d2579554fbc3085ad1 | 292 ++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 28/971d9165716bf8b85731d2579554fbc3085ad1 diff --git a/28/971d9165716bf8b85731d2579554fbc3085ad1 b/28/971d9165716bf8b85731d2579554fbc3085ad1 new file mode 100644 index 000000000..a7373d58c --- /dev/null +++ b/28/971d9165716bf8b85731d2579554fbc3085ad1 @@ -0,0 +1,292 @@ +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 B8577429E37 + for ; Fri, 31 May 2013 11:27:27 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 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, + 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 rquC8vM5X4m8 for ; + Fri, 31 May 2013 11:27:21 -0700 (PDT) +Received: from mail-we0-f174.google.com (mail-we0-f174.google.com + [74.125.82.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id BA5CE431E82 + for ; Fri, 31 May 2013 11:27:19 -0700 (PDT) +Received: by mail-we0-f174.google.com with SMTP id q58so11013wes.19 + for ; Fri, 31 May 2013 11:27:18 -0700 (PDT) +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=sRQMfgY5zcTiPpY3xxDQ7CzvbManorE350bGLelpo3I=; + b=Li0GWw/sv/wqhTjrNmhGShC2srqZd7O5RyF6KaFyojU+MTOiyAa+EAGow5+VuCDZbx + sctZU+D43k90yR4ilpTFqQ+GpYkyayKKl8ffzKH+AUH4Ki83akvqdZT5qzDWx/TN3FC0 + JCqXeiVDsWBavBt/ZLGlCH76RCB0x+uN0MUe6R0fP8WeDVVLbJbEqhxUceXcq1BlLWZ4 + sRvmESfVqIqcX31j5WmXGNN1WsFZAIlSKGZ81hG6DK9dggr9DJmJYnCbHDn+woW9vDb3 + 1iMqXqTrXb3t9Mx+P1/87nZT+Hi9ILHg1QltuMumqLEjbH4m4KUHz0o3XEa+otgprLcL + a9lw== +X-Received: by 10.181.11.194 with SMTP id ek2mr4510494wid.27.1370024838686; + Fri, 31 May 2013 11:27:18 -0700 (PDT) +Received: from localhost (92.40.240.237.threembb.co.uk. [92.40.240.237]) + by mx.google.com with ESMTPSA id hl6sm5736692wib.2.2013.05.31.11.27.16 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Fri, 31 May 2013 11:27:18 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org, Austin Clements , + Adam Wolfe Gordon +Subject: [PATCH v3 2/5] emacs: show: move the insertion of the header button + to the top level +Date: Fri, 31 May 2013 19:26:43 +0100 +Message-Id: <1370024806-6616-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1370024806-6616-1-git-send-email-markwalters1009@gmail.com> +References: <1370024806-6616-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: Fri, 31 May 2013 18:27:28 -0000 + +Previously each of the part insertion handlers inserted the part +button themselves. Move this up into +notmuch-show-insert-bodypart. Since a small number of the handlers +modify the button (the encryption/signature ones) we need to pass the +header button as an argument into the individual part insertion +handlers. However, the declared-type argument was only used for the +text for the part buttons we can now omit it. + +The patch is large but mostly simple. The only things of note are that +we let the text/plain handler applies notmuch-wash to the whole part +including the part button (otherwise rendering is slightly changed and +tests fail). +--- + emacs/notmuch-show.el | 97 ++++++++++++++++++++++++------------------------- + 1 file changed, 47 insertions(+), 50 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index fd14469..be3aeac 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -572,8 +572,7 @@ message at DEPTH in the current thread." + (mapcar (lambda (inner-part) (plist-get inner-part :content-type)) + (plist-get part :content))) + +-(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type) +- (notmuch-show-insert-part-header nth declared-type content-type nil) ++(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button) + (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) + (inner-parts (plist-get part :content)) + (start (point))) +@@ -650,8 +649,7 @@ message at DEPTH in the current thread." + content-type) + nil))) + +-(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type) +- (notmuch-show-insert-part-header nth declared-type content-type nil) ++(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth button) + (let ((inner-parts (plist-get part :content)) + (start (point))) + +@@ -670,16 +668,15 @@ message at DEPTH in the current thread." + (indent-rigidly start (point) 1))) + t) + +-(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type) +- (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil))) +- (button-put button 'face 'notmuch-crypto-part-header) +- ;; add signature status button if sigstatus provided +- (if (plist-member part :sigstatus) +- (let* ((from (notmuch-show-get-header :From msg)) +- (sigstatus (car (plist-get part :sigstatus)))) +- (notmuch-crypto-insert-sigstatus-button sigstatus from)) +- ;; if we're not adding sigstatus, tell the user how they can get it +- (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))) ++(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button) ++ (button-put button 'face 'notmuch-crypto-part-header) ++ ;; add signature status button if sigstatus provided ++ (if (plist-member part :sigstatus) ++ (let* ((from (notmuch-show-get-header :From msg)) ++ (sigstatus (car (plist-get part :sigstatus)))) ++ (notmuch-crypto-insert-sigstatus-button sigstatus from)) ++ ;; if we're not adding sigstatus, tell the user how they can get it ++ (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")) + + (let ((inner-parts (plist-get part :content)) + (start (point))) +@@ -692,20 +689,19 @@ message at DEPTH in the current thread." + (indent-rigidly start (point) 1))) + t) + +-(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type) +- (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil))) +- (button-put button 'face 'notmuch-crypto-part-header) +- ;; add encryption status button if encstatus specified +- (if (plist-member part :encstatus) +- (let ((encstatus (car (plist-get part :encstatus)))) +- (notmuch-crypto-insert-encstatus-button encstatus) +- ;; add signature status button if sigstatus specified +- (if (plist-member part :sigstatus) +- (let* ((from (notmuch-show-get-header :From msg)) +- (sigstatus (car (plist-get part :sigstatus)))) +- (notmuch-crypto-insert-sigstatus-button sigstatus from)))) +- ;; if we're not adding encstatus, tell the user how they can get it +- (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))) ++(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button) ++ (button-put button 'face 'notmuch-crypto-part-header) ++ ;; add encryption status button if encstatus specified ++ (if (plist-member part :encstatus) ++ (let ((encstatus (car (plist-get part :encstatus)))) ++ (notmuch-crypto-insert-encstatus-button encstatus) ++ ;; add signature status button if sigstatus specified ++ (if (plist-member part :sigstatus) ++ (let* ((from (notmuch-show-get-header :From msg)) ++ (sigstatus (car (plist-get part :sigstatus)))) ++ (notmuch-crypto-insert-sigstatus-button sigstatus from)))) ++ ;; if we're not adding encstatus, tell the user how they can get it ++ (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")) + + (let ((inner-parts (plist-get part :content)) + (start (point))) +@@ -718,8 +714,7 @@ message at DEPTH in the current thread." + (indent-rigidly start (point) 1))) + t) + +-(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type) +- (notmuch-show-insert-part-header nth declared-type content-type nil) ++(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth button) + (let ((inner-parts (plist-get part :content)) + (start (point))) + ;; Show all of the parts. +@@ -731,8 +726,7 @@ message at DEPTH in the current thread." + (indent-rigidly start (point) 1))) + t) + +-(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type) +- (notmuch-show-insert-part-header nth declared-type content-type nil) ++(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth button) + (let* ((message (car (plist-get part :content))) + (body (car (plist-get message :body))) + (start (point))) +@@ -753,12 +747,13 @@ message at DEPTH in the current thread." + (indent-rigidly start (point) 1))) + t) + +-(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type) +- (let ((start (point))) +- ;; If this text/plain part is not the first part in the message, +- ;; insert a header to make this clear. +- (if (> nth 1) +- (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))) ++(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth button) ++ ;; For backward compatibility we want to apply the text/plain hook ++ ;; to the whole of the part including the part button if there is ++ ;; one. ++ (let ((start (if button ++ (button-start button) ++ (point)))) + (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto)) + (save-excursion + (save-restriction +@@ -766,8 +761,7 @@ message at DEPTH in the current thread." + (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth)))) + t) + +-(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type) +- (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)) ++(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button) + (insert (with-temp-buffer + (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto)) + ;; notmuch-get-bodypart-content provides "raw", non-converted +@@ -790,8 +784,8 @@ message at DEPTH in the current thread." + t) + + ;; For backwards compatibility. +-(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type) +- (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type)) ++(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth button) ++ (notmuch-show-insert-part-text/calendar msg part content-type nth depth button)) + + (defun notmuch-show-get-mime-type-of-application/octet-stream (part) + ;; If we can deduce a MIME type from the filename of the attachment, +@@ -809,7 +803,7 @@ message at DEPTH in the current thread." + nil)) + nil)))) + +-(defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type) ++(defun notmuch-show-insert-part-text/html (msg part content-type nth depth button) + ;; text/html handler to work around bugs in renderers and our + ;; invisibile parts code. In particular w3m sets up a keymap which + ;; "leaks" outside the invisible region and causes strange effects +@@ -817,11 +811,10 @@ message at DEPTH in the current thread." + ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map + ;; remains). + (let ((mm-inline-text-html-with-w3m-keymap nil)) +- (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type))) ++ (notmuch-show-insert-part-*/* msg part content-type nth depth button))) + +-(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type) ++(defun notmuch-show-insert-part-*/* (msg part content-type nth depth button) + ;; This handler _must_ succeed - it is the handler of last resort. +- (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename)) + (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto) + t) + +@@ -844,13 +837,13 @@ message at DEPTH in the current thread." + + ;; + + +-(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type) ++(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button) + (let ((handlers (notmuch-show-handlers-for content-type))) + ;; Run the content handlers until one of them returns a non-nil + ;; value. + (while (and handlers + (not (condition-case err +- (funcall (car handlers) msg part content-type nth depth declared-type) ++ (funcall (car handlers) msg part content-type nth depth button) + (error (progn + (insert "!!! Bodypart insert error: ") + (insert (error-message-string err)) +@@ -878,6 +871,7 @@ message at DEPTH in the current thread." + "Insert the body part PART at depth DEPTH in the current thread. + + If HIDE is non-nil then initially hide this part." ++ + (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)) +@@ -885,9 +879,12 @@ If HIDE is non-nil then initially hide this part." + "text/x-diff") + content-type)) + (nth (plist-get part :id)) +- (beg (point))) ++ (beg (point)) ++ ;; We omit the part button for the first (or only) part if this is text/plain. ++ (button (unless (and (string= mime-type "text/plain") (<= nth 1)) ++ (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))) + +- (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type) ++ (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button) + ;; 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)) +-- +1.7.10.4 + -- 2.26.2