unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Fix image toggling for emacs 29.1
@ 2023-09-16 23:51 David Bremner
  2023-09-16 23:51 ` [PATCH 1/4] emacs: save undisplayer function for MIME parts David Bremner
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Bremner @ 2023-09-16 23:51 UTC (permalink / raw)
  To: notmuch

This obsoletes the WIP patch at

     id:20230903114215.60583-1-david@tethera.net

The main changes are breaking the patch up into more managable pieces,
and only saving redisplay data for images.

I am more or less satisfied with the performance impact of this
change. I ran the following test before and after and didn't see a
noticable impact in memory use (in fact it seemed to go down in some
cases, which is a mystery to me).

(profiler-start 'mem)
(notmuch-show "mimetype:image and date:2023")
(profiler-stop)
(profiler-report)

More scientific testing or personal experience welcome. And of course
I'd like to know if this breaks, the code I'm modifying is fairly
complex and has accreted over a decade or so.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] emacs: save undisplayer function for MIME parts
  2023-09-16 23:51 Fix image toggling for emacs 29.1 David Bremner
@ 2023-09-16 23:51 ` David Bremner
  2023-09-16 23:51 ` [PATCH 2/4] emacs/show: save redisplay redisplay data when showing lazy part David Bremner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2023-09-16 23:51 UTC (permalink / raw)
  To: notmuch

For some kinds of MIME parts (at least images), our trickery with
overlays will not work, so save the more drastic function created by
Gnus that actually deletes the part from the buffer. In an ideal world
we would return this function as (part of) a value, but here the call
stack is too complicated for anything that simple, so we stash it in
the part plist and rely on that being preserved (unlike the mm handle,
which is transient).
---
 emacs/notmuch-lib.el | 1 +
 1 file changed, 1 insertion(+)

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
-- 
2.40.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] emacs/show: save redisplay redisplay data when showing lazy part.
  2023-09-16 23:51 Fix image toggling for emacs 29.1 David Bremner
  2023-09-16 23:51 ` [PATCH 1/4] emacs: save undisplayer function for MIME parts David Bremner
@ 2023-09-16 23:51 ` David Bremner
  2023-09-16 23:51 ` [PATCH 3/4] emacs: save image redisplay data during non-lazy display David Bremner
  2023-09-16 23:51 ` [PATCH 4/4] emacs/show: special case toggling display of images David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2023-09-16 23:51 UTC (permalink / raw)
  To: notmuch

This data will be used to redisplay an image that is hidden by
deleting it from the buffer.  We cannot easily delay until the image
is hidden, as we won't have the original data at that point.
---
 emacs/notmuch-show.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 36cce619..8e1bc9b8 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1019,10 +1019,13 @@ will return nil if the CID is unknown or cannot be retrieved."
 	   (part-end (copy-marker (point) t))
 	   ;; We have to save the depth as we can't find the depth
 	   ;; when narrowed.
-	   (depth (notmuch-show-get-depth)))
+	   (depth (notmuch-show-get-depth))
+	   (mime-type (plist-get part-args :computed-type)))
       (save-restriction
 	(narrow-to-region part-beg part-end)
 	(delete-region part-beg part-end)
+	(when (and mime-type (string-match "^image/" mime-type))
+	  (button-put button :notmuch-redisplay-data part-args))
 	(apply #'notmuch-show-insert-bodypart-internal part-args)
 	(indent-rigidly part-beg
 			part-end
-- 
2.40.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] emacs: save image redisplay data during non-lazy display
  2023-09-16 23:51 Fix image toggling for emacs 29.1 David Bremner
  2023-09-16 23:51 ` [PATCH 1/4] emacs: save undisplayer function for MIME parts David Bremner
  2023-09-16 23:51 ` [PATCH 2/4] emacs/show: save redisplay redisplay data when showing lazy part David Bremner
@ 2023-09-16 23:51 ` David Bremner
  2023-09-16 23:51 ` [PATCH 4/4] emacs/show: special case toggling display of images David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2023-09-16 23:51 UTC (permalink / raw)
  To: notmuch

This data will eventually be used to redisplay hidden images. A
certain amount of refactoring is done here to avoid code
duplication.
---
 emacs/notmuch-show.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 8e1bc9b8..9f281a4b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1109,14 +1109,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
+      (apply #'notmuch-show-insert-bodypart-internal part-data)
+      (when (and button (string-match "^image/" mime-type))
+	(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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] emacs/show: special case toggling display of images
  2023-09-16 23:51 Fix image toggling for emacs 29.1 David Bremner
                   ` (2 preceding siblings ...)
  2023-09-16 23:51 ` [PATCH 3/4] emacs: save image redisplay data during non-lazy display David Bremner
@ 2023-09-16 23:51 ` David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2023-09-16 23:51 UTC (permalink / raw)
  To: notmuch

According to emacs upstream [1], we can't expect overlay invisibility
and images to get along. This commit uses the previously stashed
undisplayer functions to actually remove the images from the buffer.
When the image is toggled, it is essentially redisplayed from scratch,
using the previously stashed redisplay data.

[1]: https://lists.gnu.org/archive/html/emacs-devel/2023-08/msg00593.html
---
 emacs/notmuch-show.el | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9f281a4b..7a4b489d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -644,8 +644,24 @@ 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 :computed-type))
+		     (redisplay-data (button-get button
+						 :notmuch-redisplay-data))
+		     (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
-- 
2.40.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-16 23:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-16 23:51 Fix image toggling for emacs 29.1 David Bremner
2023-09-16 23:51 ` [PATCH 1/4] emacs: save undisplayer function for MIME parts David Bremner
2023-09-16 23:51 ` [PATCH 2/4] emacs/show: save redisplay redisplay data when showing lazy part David Bremner
2023-09-16 23:51 ` [PATCH 3/4] emacs: save image redisplay data during non-lazy display David Bremner
2023-09-16 23:51 ` [PATCH 4/4] emacs/show: special case toggling display of images David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).