[PATCH v4 2/5] emacs: show: add overlays for each part
authorMark Walters <markwalters1009@gmail.com>
Mon, 17 Dec 2012 21:54:44 +0000 (21:54 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:30 +0000 (09:52 -0800)
cf/4f579beb38c07f215823de546876543c066ddc [new file with mode: 0644]

diff --git a/cf/4f579beb38c07f215823de546876543c066ddc b/cf/4f579beb38c07f215823de546876543c066ddc
new file mode 100644 (file)
index 0000000..7897370
--- /dev/null
@@ -0,0 +1,158 @@
+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 6E4D6431FBD\r
+       for <notmuch@notmuchmail.org>; Mon, 17 Dec 2012 13:55:11 -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 nopHsOVNPWCU for <notmuch@notmuchmail.org>;\r
+       Mon, 17 Dec 2012 13:55:09 -0800 (PST)\r
+Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com\r
+ [74.125.82.47])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 5C8C7431FBF   for <notmuch@notmuchmail.org>; Mon, 17 Dec 2012 13:55:04 -0800\r
+ (PST)\r
+Received: by mail-wg0-f47.google.com with SMTP id dq11so2813118wgb.2\r
+       for <notmuch@notmuchmail.org>; Mon, 17 Dec 2012 13:55:03 -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=6Xcd3O6gONiAvzQULez5Hpig+jpas4M9nNDOblAr7dA=;\r
+       b=TUUau4fcLA3PtNQqBgw6Z8dWByXdOYTkqNWDo0eM9KVIFboBdTUF6mBr0/e05H8Mr0\r
+       SmsAJokve/YPVA+h7AimE7bbBe/tQImA+d3PnokGNm7mzDxko0WA1hNuMpiBJp4lbwa7\r
+       QNvhFoPkpQ877xZFQ5kb1/fqnmQyc62qPyE9n37w3w0iocBE1m4DB9SXJVl2RzmgwEyo\r
+       UqH2qIGZV7CS3qhpJZELaVvajwT/ItOnYebaiiLDUnGxgMT62A5cAI+Rwi2+dqXL2h5k\r
+       k58tozrjHbMQc9yNsBvGumX2CG+z99DQEVdrsi6Y6+ljWNsDjQECQNuDwBByLmCf6ipG\r
+       XQjg==\r
+Received: by 10.194.122.98 with SMTP id lr2mr19881705wjb.55.1355781303171;\r
+       Mon, 17 Dec 2012 13:55:03 -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 bd7sm14589810wib.8.2012.12.17.13.55.01\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 17 Dec 2012 13:55:02 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 2/5] emacs: show: add overlays for each part\r
+Date: Mon, 17 Dec 2012 21:54:44 +0000\r
+Message-Id: <1355781287-6010-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1355781287-6010-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1355781287-6010-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, 17 Dec 2012 21:55:12 -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 |   62 +++++++++++++++++++++++++++++++++++++------------\r
+ 1 files changed, 47 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index c39d2fb..7a81519 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,50 @@ 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. We\r
++    ;; also need to check that the button is a genuine part button not\r
++    ;; a notmuch-wash button.\r
++    (when (and button (/= part-beg end) (button-get button :base-label))\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