* [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