From ec990559180254c59d80308655b11df4223dd23d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 20 Aug 2020 20:09:51 +0200 Subject: [PATCH] Make image-mode give better feedback when the buffer is empty * lisp/image-mode.el (image-mode): Give a less confusing message if we don't have any image data (bug#16062). Also leave the buffer in fundamental mode. --- lisp/image-mode.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 948e62e10d0..4c719f7cda2 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -612,6 +612,15 @@ Key bindings: (setq major-mode 'image-mode) (setq image-transform-resize image-auto-resize) + ;; Bail out early if we have no image data. + (if (zerop (buffer-size)) + (funcall (if (called-interactively-p 'any) 'error 'message) + (if (file-exists-p buffer-file-name) + "Empty file" + "(New file)")) + (image-mode--display))) + +(defun image-mode--display () (if (not (image-get-display-property)) (progn (when (condition-case err -- 2.39.2