emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 79527cd: Fix problem with viewing .webp files from .zip buffers


From: Lars Ingebrigtsen
Subject: master 79527cd: Fix problem with viewing .webp files from .zip buffers
Date: Mon, 3 Aug 2020 03:01:03 -0400 (EDT)

branch: master
commit 79527cd56e9e3f8b5b1630fe18b92f7ea95e87fd
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Fix problem with viewing .webp files from .zip buffers
    
    * lisp/image-mode.el (image-toggle-display-image): Make it
    possible to view images (via external formatters, like webp) from
    zip files (and other archive modes) (bug#39994).
---
 lisp/image-mode.el | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 1295295..c417be4 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -818,13 +818,21 @@ was inserted."
                      (- (nth 2 edges) (nth 0 edges))))
         (max-height (when edges
                       (- (nth 3 edges) (nth 1 edges))))
-        (type (if (image--imagemagick-wanted-p filename)
-                  'imagemagick
-                (image-type file-or-data nil data-p)))
         (inhibit-read-only t)
         (buffer-undo-list t)
         (modified (buffer-modified-p))
-        props image)
+        props image type)
+
+    ;; If the data in the current buffer isn't from an existing file,
+    ;; but we have a file name (this happens when visiting images from
+    ;; a zip file, for instance), provide a type hint based on the
+    ;; suffix.
+    (when (and data-p filename)
+      (setq data-p (intern (format "image/%s"
+                                   (file-name-extension filename)))))
+    (setq type (if (image--imagemagick-wanted-p filename)
+                  'imagemagick
+                (image-type file-or-data nil data-p)))
 
     ;; Get the rotation data from the file, if any.
     (when (zerop image-transform-rotation) ; don't reset modified value
@@ -841,10 +849,13 @@ was inserted."
     ;; :scale 1: If we do not set this, create-image will apply
     ;; default scaling based on font size.
     (setq image (if (not edges)
-                   (create-image file-or-data type data-p :scale 1)
+                   (create-image file-or-data type data-p :scale 1
+                                  :format (and filename data-p))
                  (create-image file-or-data type data-p :scale 1
                                :max-width max-width
-                               :max-height max-height)))
+                               :max-height max-height
+                                ;; Type hint.
+                                :format (and filename data-p))))
 
     ;; Discard any stale image data before looking it up again.
     (image-flush image)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]