Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / cf / 4f579beb38c07f215823de546876543c066ddc
1 Return-Path: <markwalters1009@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 6E4D6431FBD\r
6         for <notmuch@notmuchmail.org>; Mon, 17 Dec 2012 13:55:11 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id nopHsOVNPWCU for <notmuch@notmuchmail.org>;\r
18         Mon, 17 Dec 2012 13:55:09 -0800 (PST)\r
19 Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com\r
20  [74.125.82.47])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  5C8C7431FBF    for <notmuch@notmuchmail.org>; Mon, 17 Dec 2012 13:55:04 -0800\r
23  (PST)\r
24 Received: by mail-wg0-f47.google.com with SMTP id dq11so2813118wgb.2\r
25         for <notmuch@notmuchmail.org>; Mon, 17 Dec 2012 13:55:03 -0800 (PST)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=6Xcd3O6gONiAvzQULez5Hpig+jpas4M9nNDOblAr7dA=;\r
29         b=TUUau4fcLA3PtNQqBgw6Z8dWByXdOYTkqNWDo0eM9KVIFboBdTUF6mBr0/e05H8Mr0\r
30         SmsAJokve/YPVA+h7AimE7bbBe/tQImA+d3PnokGNm7mzDxko0WA1hNuMpiBJp4lbwa7\r
31         QNvhFoPkpQ877xZFQ5kb1/fqnmQyc62qPyE9n37w3w0iocBE1m4DB9SXJVl2RzmgwEyo\r
32         UqH2qIGZV7CS3qhpJZELaVvajwT/ItOnYebaiiLDUnGxgMT62A5cAI+Rwi2+dqXL2h5k\r
33         k58tozrjHbMQc9yNsBvGumX2CG+z99DQEVdrsi6Y6+ljWNsDjQECQNuDwBByLmCf6ipG\r
34         XQjg==\r
35 Received: by 10.194.122.98 with SMTP id lr2mr19881705wjb.55.1355781303171;\r
36         Mon, 17 Dec 2012 13:55:03 -0800 (PST)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPS id bd7sm14589810wib.8.2012.12.17.13.55.01\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Mon, 17 Dec 2012 13:55:02 -0800 (PST)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v4 2/5] emacs: show: add overlays for each part\r
44 Date: Mon, 17 Dec 2012 21:54:44 +0000\r
45 Message-Id: <1355781287-6010-3-git-send-email-markwalters1009@gmail.com>\r
46 X-Mailer: git-send-email 1.7.9.1\r
47 In-Reply-To: <1355781287-6010-1-git-send-email-markwalters1009@gmail.com>\r
48 References: <1355781287-6010-1-git-send-email-markwalters1009@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Mon, 17 Dec 2012 21:55:12 -0000\r
62 \r
63 This makes notmuch-show-insert-bodypart add an overlay for any\r
64 non-trivial part with a button header (currently the first text/plain\r
65 part does not have a button). At this point the overlay is available\r
66 to the button but there is no action using it yet.\r
67 \r
68 In addition the argument HIDE is passed down to\r
69 notmuch-show-insert-part-overlays to request that the part be hidden\r
70 by default but this is not acted on yet.\r
71 ---\r
72  emacs/notmuch-show.el |   62 +++++++++++++++++++++++++++++++++++++------------\r
73  1 files changed, 47 insertions(+), 15 deletions(-)\r
74 \r
75 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
76 index c39d2fb..7a81519 100644\r
77 --- a/emacs/notmuch-show.el\r
78 +++ b/emacs/notmuch-show.el\r
79 @@ -567,11 +567,10 @@ message at DEPTH in the current thread."\r
80      ;; but it's not clear that this is the wrong thing to do - which\r
81      ;; should be chosen if there are more than one that match?\r
82      (mapc (lambda (inner-part)\r
83 -           (let ((inner-type (plist-get inner-part :content-type)))\r
84 -             (if (or notmuch-show-all-multipart/alternative-parts\r
85 -                     (string= chosen-type inner-type))\r
86 -                 (notmuch-show-insert-bodypart msg inner-part depth)\r
87 -               (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))\r
88 +           (let* ((inner-type (plist-get inner-part :content-type))\r
89 +                 (hide (not (or notmuch-show-all-multipart/alternative-parts\r
90 +                          (string= chosen-type inner-type)))))\r
91 +             (notmuch-show-insert-bodypart msg inner-part depth hide)))\r
92           inner-parts)\r
93  \r
94      (when notmuch-show-indent-multipart\r
95 @@ -839,17 +838,50 @@ message at DEPTH in the current thread."\r
96        (setq handlers (cdr handlers))))\r
97    t)\r
98  \r
99 -(defun notmuch-show-insert-bodypart (msg part depth)\r
100 -  "Insert the body part PART at depth DEPTH in the current thread."\r
101 +(defun notmuch-show-create-part-overlays (msg beg end hide)\r
102 +  "Add an overlay to the part between BEG and END"\r
103 +  (let* ((button (button-at beg))\r
104 +        (part-beg (and button (1+ (button-end button)))))\r
105 +\r
106 +    ;; If the part contains no text we do not make it toggleable. We\r
107 +    ;; also need to check that the button is a genuine part button not\r
108 +    ;; a notmuch-wash button.\r
109 +    (when (and button (/= part-beg end) (button-get button :base-label))\r
110 +      (let ((base-label (button-get button :base-label))\r
111 +           (overlay (make-overlay part-beg end))\r
112 +           (message-invis-spec (plist-get msg :message-invis-spec))\r
113 +           (invis-spec (make-symbol "notmuch-part-region")))\r
114 +\r
115 +       (overlay-put overlay 'invisible (list invis-spec message-invis-spec))\r
116 +       (overlay-put overlay 'priority 10)\r
117 +       ;; Now we have to add invis-spec to every overlay this\r
118 +       ;; overlay contains, otherwise these inner overlays will\r
119 +       ;; override this one.\r
120 +       (dolist (inner (overlays-in part-beg end))\r
121 +         (when (and (>= (overlay-start inner) part-beg)\r
122 +                          (<= (overlay-end inner) end))\r
123 +                 (overlay-put inner 'invisible\r
124 +                              (cons invis-spec (overlay-get inner 'invisible)))))\r
125 +\r
126 +       (button-put button 'invisibility-spec invis-spec)\r
127 +       (button-put button 'overlay overlay)))))\r
128 +\r
129 +(defun notmuch-show-insert-bodypart (msg part depth &optional hide)\r
130 +  "Insert the body part PART at depth DEPTH in the current thread.\r
131 +\r
132 +If HIDE is non-nil then initially hide this part."\r
133    (let ((content-type (downcase (plist-get part :content-type)))\r
134 -       (nth (plist-get part :id)))\r
135 -    (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))\r
136 -  ;; Some of the body part handlers leave point somewhere up in the\r
137 -  ;; part, so we make sure that we're down at the end.\r
138 -  (goto-char (point-max))\r
139 -  ;; Ensure that the part ends with a carriage return.\r
140 -  (unless (bolp)\r
141 -    (insert "\n")))\r
142 +       (nth (plist-get part :id))\r
143 +       (beg (point)))\r
144 +\r
145 +    (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)\r
146 +    ;; Some of the body part handlers leave point somewhere up in the\r
147 +    ;; part, so we make sure that we're down at the end.\r
148 +    (goto-char (point-max))\r
149 +    ;; Ensure that the part ends with a carriage return.\r
150 +    (unless (bolp)\r
151 +      (insert "\n"))\r
152 +    (notmuch-show-create-part-overlays msg beg (point) hide)))\r
153  \r
154  (defun notmuch-show-insert-body (msg body depth)\r
155    "Insert the body BODY at depth DEPTH in the current thread."\r
156 -- \r
157 1.7.9.1\r
158 \r