From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id uGNINzhx9GTvCwAA9RJhRA:P1 (envelope-from ) for ; Sun, 03 Sep 2023 13:42:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id uGNINzhx9GTvCwAA9RJhRA (envelope-from ) for ; Sun, 03 Sep 2023 13:42:49 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 82C55445F5 for ; Sun, 3 Sep 2023 13:42:46 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1693741368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=0ZSXsDPsEeIO+9ssLieCD+F7/T7x+NP3Je+7zAhjq34=; b=TOnWqtBBuo7MDR6HaYvag81PrJYW6mCFqD4eJUYW1C3maNbfLi3piWJGih7pPjO3WUm+Ec chIYu4/FSYYv4RouheTSFauuiBU+jgL0cRQwofKVaz4bXJmlz5j4cNSPhla4lex4FF+zRu Amh4VqCXPtNH+gmB7zXeN8XUPTjHkXpnbTKXVqYo7F1tqVU/oPDFHOcIHZjiV9SvL1t3We ApG5WfandZvHYitiyzUip5jVQ1K3lhuN5C/fJHJPsN9fLpIfsmaKKTBgd6P3+gPqCH9aAs IaYIK8OjGuRrcf8a+MXcp2E3ale039If6KNKtRE9xO1/tCF3sRdH/GNuCdkVtA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1693741368; a=rsa-sha256; cv=none; b=f4ekMhCkwp2AwlqSGWy5OX7TYv6MqRGs9/Ae2MYOmRf4s/HHxbHzJuCjHlhoXs30i8IIpu 8sefqxndQWWOqFWTnM+LQSLHVDYy7huEb2403z54heV7AKFWNYiHoUrPILxWlKtwYIFkdH RucyOU/D7DlNzLaer6+Ac/efcYGiucwsLv5BIENvpLWxsApe6+lw1tkRzDqnKqhQRJ/Lkk jmFkaXJJ4iTub3TOKZbjbe4OAWMal8BhIanaWvUhGRiYFFAh9ASJdBmaLgJ+BMAxpBvMP7 Eei1nLNV8a8EzgYSKnAEfQDmEKtP7MMkFzaMdeXIkXJzqTdGDow+n6CSMtGR9g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org; dmarc=none Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E70135F343; Sun, 3 Sep 2023 11:42:36 +0000 (UTC) Received: from phubs.tethera.net (phubs.tethera.net [IPv6:2607:5300:60:3a9d::1]) by mail.notmuchmail.org (Postfix) with ESMTPS id 25F325E537 for ; Sun, 3 Sep 2023 11:42:34 +0000 (UTC) Received: from motzkin.cs.unb.ca (fctnnbsc51w-159-2-210-253.dhcp-dynamic.fibreop.nb.bellaliant.net [159.2.210.253]) by phubs.tethera.net (Postfix) with ESMTPS id 5521F180066; Sun, 3 Sep 2023 08:42:32 -0300 (ADT) Received: (nullmailer pid 60597 invoked by uid 1000); Sun, 03 Sep 2023 11:42:31 -0000 From: David Bremner To: David Bremner , Jon Fineman , "notmuch@notmuchmail.org" Subject: [PATCH] WIP: use gnus supplied undisplay function to hide images Date: Sun, 3 Sep 2023 08:42:15 -0300 Message-Id: <20230903114215.60583-1-david@tethera.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <87h6ofqrkf.fsf@motzkin.cs.unb.ca> References: <87h6ofqrkf.fsf@motzkin.cs.unb.ca> MIME-Version: 1.0 Message-ID-Hash: GLKFDHPFVCYHT2MQHILNHK3P7Y6W3GD4 X-Message-ID-Hash: GLKFDHPFVCYHT2MQHILNHK3P7Y6W3GD4 X-MailFrom: bremner@motzkin.cs.unb.ca X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Country: DE X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx0.migadu.com X-Migadu-Spam-Score: -3.85 X-Spam-Score: -3.85 X-Migadu-Queue-Id: 82C55445F5 X-TUID: GyxuJOGQ53zY According to emacs upstream [1], we can't expect overlay invisibilityy and images to get along. This is a first attempt to use the "undisplayer" functions saved by gnus (specificially mm-insert-image) to do the hiding. There are some potential efficiency concerns. A second copy of all parts is saved. That could (perhaps?) be optimized to only be done for the toggled ones. Profile / test first, optimize later [1]: https://lists.gnu.org/archive/html/emacs-devel/2023-08/msg00593.html --- emacs/notmuch-lib.el | 1 + emacs/notmuch-show.el | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 84ba8c5e..a09f4ab8 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -703,6 +703,7 @@ current buffer, if possible." (when (mm-inlinable-p handle) (set-buffer display-buffer) (mm-display-part handle) + (plist-put part :undisplayer (mm-handle-undisplayer handle)) t)))))) ;;; Generic Utilities diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 36cce619..7911be5d 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -618,7 +618,7 @@ message at DEPTH in the current thread." (let ((button (or button (button-at (point))))) (when button (let ((overlay (button-get button 'overlay)) - (lazy-part (button-get button :notmuch-lazy-part))) + (lazy-part (button-get button :notmuch-lazy-part))) ;; We have a part to toggle if there is an overlay or if there ;; is a lazy part. If neither is present we cannot toggle the ;; part so we just return nil. @@ -644,8 +644,25 @@ message at DEPTH in the current thread." (when show (button-put button :notmuch-lazy-part nil) (notmuch-show-lazy-part lazy-part button)) - ;; else there must be an overlay. - (overlay-put overlay 'invisible (not show)) + (let* ((part (plist-get properties :notmuch-part)) + (undisplayer (plist-get part :undisplayer)) + (mime-type (plist-get part :content-type)) + (redisplay-data (button-get button + :notmuch-redisplay-data)) + ;; XXX FIXME use computed content type + (imagep (string-match "^image/" mime-type))) + (cond + ((and imagep (not show) undisplayer) + ;; call undisplayer thunk created by gnus. + (funcall undisplayer) + ;; there is an extra newline left + (delete-region + (+ 1 (button-end button)) + (+ 2 (button-end button)))) + ((and imagep show redisplay-data) + (notmuch-show-lazy-part redisplay-data button)) + (t + (overlay-put overlay 'invisible (not show))))) t))))))) ;;; Part content ID handling @@ -1023,6 +1040,7 @@ will return nil if the CID is unknown or cannot be retrieved." (save-restriction (narrow-to-region part-beg part-end) (delete-region part-beg part-end) + (button-put button :notmuch-redisplay-data part-args) (apply #'notmuch-show-insert-bodypart-internal part-args) (indent-rigidly part-beg part-end @@ -1106,14 +1124,18 @@ is t, hide the part initially and show the button." (and deep button) (and high button) (and long button)))) - (content-beg (point))) + (content-beg (point)) + (part-data (list msg part mime-type nth depth button))) ;; Store the computed mime-type for later use (e.g. by attachment handlers). (plist-put part :computed-type mime-type) - (if show-part - (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button) + (cond + (show-part + (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button) + (when button + (button-put button :notmuch-redisplay-data part-data))) + (t (when button - (button-put button :notmuch-lazy-part - (list msg part mime-type nth depth button)))) + (button-put button :notmuch-lazy-part part-data)))) ;; 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)) -- 2.40.1