[PATCH v3 2/5] emacs: show: add overlays for each part
authorMark Walters <markwalters1009@gmail.com>
Sat, 15 Dec 2012 08:15:34 +0000 (08:15 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:14 +0000 (09:52 -0800)
f8/c60a6f01809cf03b4436c9ee7409c854304d1d [new file with mode: 0644]

diff --git a/f8/c60a6f01809cf03b4436c9ee7409c854304d1d b/f8/c60a6f01809cf03b4436c9ee7409c854304d1d
new file mode 100644 (file)
index 0000000..49f6b82
--- /dev/null
@@ -0,0 +1,156 @@
+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 F0AC8431FC2\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 00:15:53 -0800 (PST)\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 msAg503a5g-x for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 00:15:51 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+       [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id B5958429E3A\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 00:15:47 -0800 (PST)\r
+Received: by mail-wi0-f181.google.com with SMTP id hm9so961770wib.2\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 00:15:46 -0800 (PST)\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=zI3e/xD7ruqFjuVI8QrWB/clc/lMkFSkIixLgluXGdU=;\r
+       b=IN8sxuU6GHUl4jZbE2w0vbWlyfoukSPNfhDhR24jpPFkpOmBFGWsJ2Fe2OhjNr5smC\r
+       qyJCXNkcJt14ILt7zt02VX/Xsgx/OC2O2uHRJHSr1srQRMuoY7dowPfFVEDg4sYd1VUU\r
+       giwhyP54acX+FZvSRR7u957iabvewkpbgZng3OAuwK51PKpGbP6sNc4kPUpJekpZGp4H\r
+       XBton5BrkdGqHO2BeHS/joPEA1g8nYl9vKBzz481qpD7ABfOGBIhHTVm0qyGBCjTGEAr\r
+       ln0U1kHXMOFcJRkAtVbk4DzRoEfVnC/gBvCtoQXhPer+jMgyxG7pal1pd+42AGrmUPaq\r
+       5OAA==\r
+Received: by 10.180.88.70 with SMTP id be6mr6462313wib.14.1355559346523;\r
+       Sat, 15 Dec 2012 00:15:46 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id h19sm958302wiv.7.2012.12.15.00.15.45\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 15 Dec 2012 00:15:45 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/5] emacs: show: add overlays for each part\r
+Date: Sat, 15 Dec 2012 08:15:34 +0000\r
+Message-Id: <1355559338-14313-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1355559338-14313-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1355559338-14313-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: Sat, 15 Dec 2012 08:15:54 -0000\r
+\r
+This makes notmuch-show-insert-bodypart add an overlay for any\r
+non-trivial part with a button header (currently the first text/plain\r
+part does not have a button). At this point the overlay is available\r
+to the button but there is no action using it yet.\r
+\r
+In addition the argument HIDE is passed down to\r
+notmuch-show-insert-part-overlays to request that the part be hidden\r
+by default but this is not acted on yet.\r
+---\r
+ emacs/notmuch-show.el |   60 ++++++++++++++++++++++++++++++++++++------------\r
+ 1 files changed, 45 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 06f7ca5..b65c339 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -567,11 +567,10 @@ message at DEPTH in the current thread."\r
+     ;; but it's not clear that this is the wrong thing to do - which\r
+     ;; should be chosen if there are more than one that match?\r
+     (mapc (lambda (inner-part)\r
+-          (let ((inner-type (plist-get inner-part :content-type)))\r
+-            (if (or notmuch-show-all-multipart/alternative-parts\r
+-                    (string= chosen-type inner-type))\r
+-                (notmuch-show-insert-bodypart msg inner-part depth)\r
+-              (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))\r
++          (let* ((inner-type (plist-get inner-part :content-type))\r
++                (hide (not (or notmuch-show-all-multipart/alternative-parts\r
++                         (string= chosen-type inner-type)))))\r
++            (notmuch-show-insert-bodypart msg inner-part depth hide)))\r
+         inner-parts)\r
\r
+     (when notmuch-show-indent-multipart\r
+@@ -839,17 +838,48 @@ message at DEPTH in the current thread."\r
+       (setq handlers (cdr handlers))))\r
+   t)\r
\r
+-(defun notmuch-show-insert-bodypart (msg part depth)\r
+-  "Insert the body part PART at depth DEPTH in the current thread."\r
++(defun notmuch-show-create-part-overlays (msg beg end hide)\r
++  "Add an overlay to the part between BEG and END"\r
++  (let* ((button (button-at beg))\r
++       (part-beg (and button (1+ (button-end button)))))\r
++\r
++    ;; If the part contains no text we do not make it toggleable.\r
++    (when (and button (/= part-beg end))\r
++      (let ((base-label (button-get button :base-label))\r
++          (overlay (make-overlay part-beg end))\r
++          (message-invis-spec (plist-get msg :message-invis-spec))\r
++          (invis-spec (make-symbol "notmuch-part-region")))\r
++\r
++      (overlay-put overlay 'invisible (list invis-spec message-invis-spec))\r
++      (overlay-put overlay 'priority 10)\r
++      ;; Now we have to add invis-spec to every overlay this\r
++      ;; overlay contains, otherwise these inner overlays will\r
++      ;; override this one.\r
++      (dolist (inner (overlays-in part-beg end))\r
++        (when (and (>= (overlay-start inner) part-beg)\r
++                         (<= (overlay-end inner) end))\r
++                (overlay-put inner 'invisible\r
++                             (cons invis-spec (overlay-get inner 'invisible)))))\r
++\r
++      (button-put button 'invisibility-spec invis-spec)\r
++      (button-put button 'overlay overlay)))))\r
++\r
++(defun notmuch-show-insert-bodypart (msg part depth &optional hide)\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
+   (let ((content-type (downcase (plist-get part :content-type)))\r
+-      (nth (plist-get part :id)))\r
+-    (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))\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
+-  ;; Ensure that the part ends with a carriage return.\r
+-  (unless (bolp)\r
+-    (insert "\n")))\r
++      (nth (plist-get part :id))\r
++      (beg (point)))\r
++\r
++    (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)\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
++    ;; Ensure that the part ends with a carriage return.\r
++    (unless (bolp)\r
++      (insert "\n"))\r
++    (notmuch-show-create-part-overlays msg beg (point) hide)))\r
\r
+ (defun notmuch-show-insert-body (msg body depth)\r
+   "Insert the body BODY at depth DEPTH in the current thread."\r
+-- \r
+1.7.9.1\r
+\r