From: Mark Walters Date: Sun, 26 May 2013 07:57:40 +0000 (+0100) Subject: [PATCH v2 2/3] emacs: show: move the insertion of the header button to the top level X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=52274be9e703a4f604b1bc13fb3303f6104c9d76;p=notmuch-archives.git [PATCH v2 2/3] emacs: show: move the insertion of the header button to the top level --- diff --git a/9a/d8df5e19b017893df098e294f6902fd5b306e9 b/9a/d8df5e19b017893df098e294f6902fd5b306e9 new file mode 100644 index 000000000..b5bb7e85d --- /dev/null +++ b/9a/d8df5e19b017893df098e294f6902fd5b306e9 @@ -0,0 +1,281 @@ +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 59FAA431FC7 + for ; Sun, 26 May 2013 00:58:01 -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 wEG0wouZ+YXW for ; + Sun, 26 May 2013 00:57:54 -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 1312B431FC3 + for ; Sun, 26 May 2013 00:57:50 -0700 (PDT) +Received: by mail-we0-f174.google.com with SMTP id x50so1784351wes.19 + for ; Sun, 26 May 2013 00:57:50 -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=5deIOURr9/x56MeQ/miGVz2B4O/kqcucYUJYlG40EX4=; + b=kFZP6Jhg/3MsGmRBrN3iRCZqJ8juQS4BVb9koxMb4crZDbjJHHAerFfpLti6agJJoH + pKzchJFozkf8EuCyBg+W+3WRNhgj7Gl3ff/uvcUu+uQhW62R/oNoG5EPQOmRMuCLsyMh + gpe48V6ig8I237P6N5naXGySwt9jh9KcWIwq7xjkYKDK8/mvCTsaACYbN3uPsr9zLjfr + 5ISOFv4dMBjrJaCoESywZngCSVrzm8lJZ0cRWTBwD+xxoUldAwvco/pXmRGD0YYhz0SW + Vb89nWkjeKhVGTM+7X0hQvGIw1pnWVvyEhZRnzOtR/7sEvJkduImZtX97NJh3BiIv1or + 1BjQ== +X-Received: by 10.180.108.175 with SMTP id hl15mr4125371wib.19.1369555069946; + Sun, 26 May 2013 00:57:49 -0700 (PDT) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPSA id m3sm9324588wij.5.2013.05.26.00.57.48 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 26 May 2013 00:57:49 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/3] emacs: show: move the insertion of the header button + to the top level +Date: Sun, 26 May 2013 08:57:40 +0100 +Message-Id: <1369555061-21361-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1369555061-21361-1-git-send-email-markwalters1009@gmail.com> +References: <1369555061-21361-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: Sun, 26 May 2013 07:58:01 -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. + +The patch is large but mostly simple. The only things of note are that +we let the text/plain handler insert part buttons itself (as it does +not always insert one and it applies motmuch-wash to the whole part +including the button. Also this is by far the most important case so +this reduces the risk of annoying side effects. +--- + emacs/notmuch-show.el | 87 +++++++++++++++++++++++------------------------- + 1 files changed, 42 insertions(+), 45 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 51bda31..591ad56 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -576,8 +576,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 declared-type button) + (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) + (inner-parts (plist-get part :content)) + (start (point))) +@@ -654,8 +653,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 declared-type button) + (let ((inner-parts (plist-get part :content)) + (start (point))) + +@@ -674,16 +672,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 declared-type 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))) +@@ -696,20 +693,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 declared-type 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))) +@@ -722,8 +718,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 declared-type button) + (let ((inner-parts (plist-get part :content)) + (start (point))) + ;; Show all of the parts. +@@ -735,8 +730,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 declared-type button) + (let* ((message (car (plist-get part :content))) + (body (car (plist-get message :body))) + (start (point))) +@@ -757,7 +751,7 @@ 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) ++(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type button) + (let ((start (point))) + ;; If this text/plain part is not the first part in the message, + ;; insert a header to make this clear. +@@ -770,8 +764,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 declared-type 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 +@@ -794,8 +787,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 declared-type button) ++ (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type 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, +@@ -813,7 +806,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 declared-type 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 +@@ -821,11 +814,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 declared-type 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 declared-type 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) + +@@ -848,13 +840,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 declared-type 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 declared-type button) + (error (progn + (insert "!!! Bodypart insert error: ") + (insert (error-message-string err)) +@@ -882,6 +874,9 @@ 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." ++ ++ ;; We handle text/plain specially as its code does things before ++ ;; inserting a part button (and does not always insert a part button). + (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)) +@@ -889,9 +884,11 @@ If HIDE is non-nil then initially hide this part." + "text/x-diff") + content-type)) + (nth (plist-get part :id)) +- (beg (point))) ++ (beg (point)) ++ (button (unless (string= mime-type "text/plain") ++ (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 content-type 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.9.1 +