From: Mark Walters Date: Tue, 4 Dec 2012 23:27:41 +0000 (+0000) Subject: [PATCH 2/3] emacs: show: add overlays for each part X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=85d07dba5cc86b5bc1c24209275aa287777eeb4c;p=notmuch-archives.git [PATCH 2/3] emacs: show: add overlays for each part --- diff --git a/6e/293e07ab7095f803927e16b36f74eb0c0c0fba b/6e/293e07ab7095f803927e16b36f74eb0c0c0fba new file mode 100644 index 000000000..49ffab893 --- /dev/null +++ b/6e/293e07ab7095f803927e16b36f74eb0c0c0fba @@ -0,0 +1,157 @@ +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 6A9C2431FD7 + for ; Tue, 4 Dec 2012 15:28:01 -0800 (PST) +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 kvXQtx8CCDJj for ; + Tue, 4 Dec 2012 15:27:56 -0800 (PST) +Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com + [74.125.82.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 8C230429E32 for ; Tue, 4 Dec 2012 15:27:52 -0800 + (PST) +Received: by mail-wg0-f47.google.com with SMTP id dq11so2243404wgb.2 + for ; Tue, 04 Dec 2012 15:27:51 -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:x-mailer:in-reply-to:references; + bh=jS5XjTdjllp2CsHpn/ESiIKeEE6ByFIsb+xTBvJqaoY=; + b=XvaMOErYMRYJzDDXlpsxCcfz8hQak0WgNBkvgUI9bYeiSdrVR+jKwa004HyW3LkDjE + lkQ7Z+GjzLC/n4qyXYOFcvBTigDA4Q0TDLXPTPxsqtaYO+wR12UOwKRgM+7BHo7Bcp0P + RhElKjdJaSHFrs2PACMdg5LX3ASStPybg/yR/6m/lP/KtxgbYEXPud4Ph8zmA9GGSQif + t7zC0hkP+HM6t2kDZ71J8mJF41vQGzYOLxcfLM0wgQiKMYP9ohxIosjgHhzSacDO3n1K + t6IoVMkMpwXY0clpY5VgZWnB8nnYFPR90qH/GWc3QlVP9TjQLDy1KjCS+5eSJeW0idgN + X5xg== +Received: by 10.180.102.234 with SMTP id fr10mr28383wib.17.1354663671416; + Tue, 04 Dec 2012 15:27:51 -0800 (PST) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPS id eu8sm16989974wib.1.2012.12.04.15.27.50 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 04 Dec 2012 15:27:50 -0800 (PST) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH 2/3] emacs: show: add overlays for each part +Date: Tue, 4 Dec 2012 23:27:41 +0000 +Message-Id: <1354663662-20524-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1354663662-20524-1-git-send-email-markwalters1009@gmail.com> +References: <1354663662-20524-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: Tue, 04 Dec 2012 23:28:01 -0000 + +This make notmuch-show-insert-bodypart add an overlay for any +non-trivial part with a button header (currently the first text/plain +part does not have a button). At this point the overlay is available +to the button but there is no action using it yet. + +In addition a not-shown variable which is used to request the part be +hidden by default down to the overlay but this is not acted on yet. +--- + emacs/notmuch-show.el | 62 +++++++++++++++++++++++++++++++++++++----------- + 1 files changed, 48 insertions(+), 14 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index f8ce037..3215ebc 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -569,10 +569,9 @@ message at DEPTH in the current thread." + ;; should be chosen if there are more than one that match? + (mapc (lambda (inner-part) + (let ((inner-type (plist-get inner-part :content-type))) +- (if (or notmuch-show-all-multipart/alternative-parts +- (string= chosen-type inner-type)) +- (notmuch-show-insert-bodypart msg inner-part depth) +- (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)")))) ++ (notmuch-show-insert-bodypart msg inner-part depth ++ (not (or notmuch-show-all-multipart/alternative-parts ++ (string= chosen-type inner-type)))))) + inner-parts) + + (when notmuch-show-indent-multipart +@@ -840,17 +839,52 @@ message at DEPTH in the current thread." + (setq handlers (cdr handlers)))) + t) + +-(defun notmuch-show-insert-bodypart (msg part depth) +- "Insert the body part PART at depth DEPTH in the current thread." ++(defun notmuch-show-insert-part-overlays (msg beg end not-shown) ++ "Add an overlay to the part between BEG and END" ++ (let* ((button (button-at beg)) ++ (part-beg (and button (1+ (button-end button))))) ++ ++ ;; If the part contains no text we do not make it toggleable. ++ (unless (or (not button) (eq part-beg end)) ++ (let ((base-label (button-get button :base-label)) ++ (overlay (make-overlay part-beg end)) ++ (message-invis-spec (plist-get msg :message-invis-spec)) ++ (invis-spec (make-symbol "notmuch-part-region"))) ++ ++ (overlay-put overlay 'invisible (list invis-spec message-invis-spec)) ++ (overlay-put overlay 'isearch-open-invisible #'notmuch-wash-region-isearch-show) ++ (overlay-put overlay 'priority 10) ++ (overlay-put overlay 'type "part") ++ ;; Now we have to add invis-spec to every overlay this ++ ;; overlay contains, otherwise these inner overlays will ++ ;; override this one. ++ (mapc (lambda (inner) ++ (when (and (>= (overlay-start inner) part-beg) ++ (<= (overlay-end inner) end)) ++ (overlay-put inner 'invisible ++ (cons invis-spec (overlay-get inner 'invisible))))) ++ (overlays-in part-beg end)) ++ ++ (button-put button 'invisibility-spec invis-spec) ++ (button-put button 'overlay overlay)) ++ (goto-char (point-max))))) ++ ++(defun notmuch-show-insert-bodypart (msg part depth &optional not-shown) ++ "Insert the body part PART at depth DEPTH in the current thread. ++ ++If not-shown is TRUE then initially hide this part." + (let ((content-type (downcase (plist-get part :content-type))) +- (nth (plist-get part :id))) +- (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)) +- ;; 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)) +- ;; Ensure that the part ends with a carriage return. +- (unless (bolp) +- (insert "\n"))) ++ (nth (plist-get part :id)) ++ (beg (point))) ++ ++ (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type) ++ ;; 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)) ++ ;; Ensure that the part ends with a carriage return. ++ (unless (bolp) ++ (insert "\n")) ++ (notmuch-show-insert-part-overlays msg beg (point) not-shown))) + + (defun notmuch-show-insert-body (msg body depth) + "Insert the body BODY at depth DEPTH in the current thread." +-- +1.7.9.1 +