]> git.eshelyaron.com Git - emacs.git/commitdiff
(image-minor-mode): Exit more gracefully when the image
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 28 Nov 2009 20:45:19 +0000 (20:45 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sat, 28 Nov 2009 20:45:19 +0000 (20:45 +0000)
cannot be displayed (e.g. when doing C-x C-f some-new-file.svg RET).

lisp/ChangeLog
lisp/image-mode.el

index 62f2dc5f4b5622a56bd07ce926de7388452b6f91..39a55c525ccac6eb70da13187607ab5b2a300b9a 100644 (file)
@@ -1,5 +1,8 @@
 2009-11-28  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+       * image-mode.el (image-minor-mode): Exit more gracefully when the image
+       cannot be displayed (e.g. when doing C-x C-f some-new-file.svg RET).
+
        * man.el (Man-completion-table): Make it easier to enter "<sec> <name>".
 
        * eshell/em-prompt.el (eshell-prompt-function): Abbreviate pwd, since
index bb97eb8e0b50725f74fece7a03ae689e55fd4143..2351edc934cf33d3c53c968e8d416b7f5ec608dc 100644 (file)
@@ -362,18 +362,26 @@ See the command `image-mode' for more information on this mode."
     (image-mode-setup-winprops)
     (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)
     (if (display-images-p)
-       (if (not (image-get-display-property))
-           (image-toggle-display)
-         (setq cursor-type nil truncate-lines t
-               image-type (plist-get (cdr (image-get-display-property)) :type)))
+        (condition-case err
+            (progn
+              (if (not (image-get-display-property))
+                  (image-toggle-display)
+                (setq cursor-type nil truncate-lines t
+                      image-type (plist-get (cdr (image-get-display-property))
+                                            :type)))
+              (message "%s"
+                       (concat
+                        (substitute-command-keys
+                         "Type \\[image-toggle-display] to view the image as ")
+                        (if (image-get-display-property)
+                            "text" "an image") ".")))
+          (error
+           (image-toggle-display-text)
+           (funcall
+            (if (called-interactively-p 'any) 'error 'message)
+            "Cannot display image: %s" (cdr err))))
       (setq image-type "text")
-      (use-local-map image-mode-text-map))
-    (if (display-images-p)
-       (message "%s" (concat
-                      (substitute-command-keys
-                       "Type \\[image-toggle-display] to view the image as ")
-                      (if (image-get-display-property)
-                          "text" "an image") ".")))))
+      (use-local-map image-mode-text-map))))
 
 ;;;###autoload
 (defun image-mode-maybe ()