Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 9a / ddb3c00dc5e2e9b1ed31132ab40f359c8e3be3
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 5841F429E27\r
6         for <notmuch@notmuchmail.org>; Sat,  4 May 2013 06:01:42 -0700 (PDT)\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 S04-YULMZ90Y for <notmuch@notmuchmail.org>;\r
18         Sat,  4 May 2013 06:01:38 -0700 (PDT)\r
19 Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com\r
20  [74.125.82.44])        (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  E5568431FC2    for <notmuch@notmuchmail.org>; Sat,  4 May 2013 06:01:34 -0700\r
23  (PDT)\r
24 Received: by mail-wg0-f44.google.com with SMTP id z12so2270349wgg.23\r
25         for <notmuch@notmuchmail.org>; Sat, 04 May 2013 06:01:33 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
28         :references; bh=6U5D+2I+rcHj/OFpFocWXP1C5uTpnVRglaMZEvjZ0IY=;\r
29         b=v0Qe8/Q4ijuqZhLTj+6syX7xDKQ7RP3w2A4i/QPgngQrMPvlmNXf8MI+eEWQh9j9th\r
30         1N1Nbyxg5EQJuenZaqnOz+o0R6JnPMSxkbblCfZbiUsC1wi7d3xreLEQuy/Jy4nEke4n\r
31         5qU3a4jJ48FnV943c6K85+WxYphTNptHmWOyAZBAKmbZOfQNjN0KPvJdJDWRPz0aOT65\r
32         CQe5lWtQ0t8amXUDgUxhbc200dm1UZT5Ha3bIiwGUf2Gesib5VhbWAHAQTAMJljXAr7j\r
33         m1KDGjPvfukriM4gjS7T6yWFGo5Ula5BsqF/y/qvMEnyESIdTbflcKKX4B7vJ0r7uEfu\r
34         qv/g==\r
35 X-Received: by 10.180.187.206 with SMTP id fu14mr1994939wic.11.1367672493805; \r
36         Sat, 04 May 2013 06:01:33 -0700 (PDT)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPSA id ge7sm3122936wib.6.2013.05.04.06.01.32\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sat, 04 May 2013 06:01:33 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 4/4] emacs: show: implement lazy hidden part handling\r
45 Date: Sat,  4 May 2013 14:01:17 +0100\r
46 Message-Id: <1367672478-12247-5-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 In-Reply-To: <1367672478-12247-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1367672478-12247-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 04 May 2013 13:01:43 -0000\r
63 \r
64 This adds the actual code to do the lazy insertion of hidden parts.\r
65 \r
66 We use a memory inefficient but simple method: when we come to insert\r
67 the part if it is hidden we just store all of the arguments to the\r
68 part insertion function as a button property. This means when we want\r
69 to show the part we can just resume where we left off.\r
70 \r
71 The only slight subtlety/hack is that to simplify the handling of the\r
72 invisibility overlay (for the hiding unhiding later) we do insert some\r
73 dummy text which we remove when we show the part.\r
74 ---\r
75  emacs/notmuch-show.el |   32 ++++++++++++++++++++++++++++++--\r
76  1 files changed, 30 insertions(+), 2 deletions(-)\r
77 \r
78 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
79 index 2c48b24..a14a135 100644\r
80 --- a/emacs/notmuch-show.el\r
81 +++ b/emacs/notmuch-show.el\r
82 @@ -559,6 +559,7 @@ message at DEPTH in the current thread."\r
83          (overlay (button-get button 'overlay)))\r
84      (when overlay\r
85        (let* ((show (overlay-get overlay 'invisible))\r
86 +            (lazy-part (button-get button :notmuch-lazy-part))\r
87              (new-start (button-start button))\r
88              (button-label (button-get button :base-label))\r
89              (old-point (point))\r
90 @@ -569,7 +570,11 @@ message at DEPTH in the current thread."\r
91         (let ((old-end (button-end button)))\r
92           (move-overlay button new-start (point))\r
93           (delete-region (point) old-end))\r
94 -       (goto-char (min old-point (1- (button-end button))))))))\r
95 +       (goto-char (min old-point (1- (button-end button))))\r
96 +       (when (and show lazy-part)\r
97 +         (save-excursion\r
98 +           (button-put button :notmuch-lazy-part nil)\r
99 +           (notmuch-show-lazy-part lazy-part button)))))))\r
100  \r
101  (defun notmuch-show-multipart/*-to-list (part)\r
102    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
103 @@ -857,6 +862,24 @@ message at DEPTH in the current thread."\r
104        (setq handlers (cdr handlers))))\r
105    t)\r
106  \r
107 +(defun notmuch-show-lazy-part (part-args button)\r
108 +  (interactive)\r
109 +  ;; We have to save the depth as we can't find the depth when narrowed\r
110 +  (let ((inhibit-read-only t)\r
111 +       (overlay (button-get button 'overlay))\r
112 +       (depth (notmuch-show-get-depth)))\r
113 +    (save-restriction\r
114 +      (narrow-to-region (overlay-start overlay) (1- (overlay-end overlay)))\r
115 +      (delete-region (overlay-start overlay) (1- (overlay-end overlay)))\r
116 +      (goto-char (overlay-start overlay))\r
117 +      (apply #'notmuch-show-insert-bodypart-internal (nconc part-args (list button)))\r
118 +      (indent-rigidly (overlay-start overlay)\r
119 +                     (1- (overlay-end overlay))\r
120 +                     depth))\r
121 +    ;; We deferred deleting this character to simplify handling of the\r
122 +    ;; overlay: all of the above takes place inside the overlay.\r
123 +    (delete-region (1- (overlay-end overlay)) (overlay-end overlay))))\r
124 +\r
125  (defun notmuch-show-create-part-overlays (msg beg end hide)\r
126    "Add an overlay to the part between BEG and END"\r
127    (let* ((button (button-at beg))\r
128 @@ -891,7 +914,12 @@ If HIDE is non-nil then initially hide this part."\r
129          (button (unless (string= mime-type "text/plain")\r
130                    (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))))\r
131  \r
132 -    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type button)\r
133 +    (if (not hide)\r
134 +        (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type button)\r
135 +      (insert "lazy part")\r
136 +      (button-put button :notmuch-lazy-part\r
137 +                  (list msg part mime-type nth depth content-type)))\r
138 +\r
139      ;; Some of the body part handlers leave point somewhere up in the\r
140      ;; part, so we make sure that we're down at the end.\r
141      (goto-char (point-max))\r
142 -- \r
143 1.7.9.1\r
144 \r