From 78d3f5494b3b35b96289f8dd7a6bcb0c67228584 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 29 May 2016 17:16:07 +0200 Subject: [PATCH] Make message-toggle-image-thumbnails work better * lisp/gnus/message.el (message-toggle-image-thumbnails): Use `insert-image' instead of `put-image' to make it possible to edit the resulting text in a sensible manner. --- lisp/gnus/message.el | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index 1ca7c5cafef..a998687ccb3 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -8386,30 +8386,32 @@ Used in `message-simplify-recipients'." (defun message-toggle-image-thumbnails () "For any included image files, insert a thumbnail of that image." (interactive) - (let ((overlays (overlays-in (point-min) (point-max))) - (displayed nil)) - (while overlays - (let ((overlay (car overlays))) - (when (overlay-get overlay 'put-image) - (delete-overlay overlay) - (setq displayed t))) - (setq overlays (cdr overlays))) + (let ((displayed nil)) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (when-let ((props (get-text-property (point) 'display))) + (when (and (consp props) + (eq (car props) 'image)) + (put-text-property (point) (1+ (point)) 'display nil) + (setq displayed t))))) (unless displayed (save-excursion (goto-char (point-min)) - (while (re-search-forward "" nil t) + (let ((string (match-string 0)) + (file (match-string 1)) (edges (window-inside-pixel-edges (get-buffer-window (current-buffer))))) - (put-image + (delete-region (match-beginning 0) (match-end 0)) + (insert-image (create-image file 'imagemagick nil :max-width (truncate (* 0.7 (- (nth 2 edges) (nth 0 edges)))) :max-height (truncate (* 0.5 (- (nth 3 edges) (nth 1 edges))))) - (match-beginning 0) - " "))))))) + string))))))) (provide 'message) -- 2.39.2