Subject: bug#16062: 24.3; Missing .png file gives poor error message when opened

From: Eli Zaretskii <[email-masked]>
Date: Sat, 07 Dec 2013 09:27:32 +0200

> Date: Fri, 06 Dec 2013 22:05:17 +0100
> From: Jarek Czekalski <[email-masked]>
> 
> W dniu 12/06/2013 09:38 AM, Eli Zaretskii pisze:
> > Is it?  What if I come up with an Emacs mode that lets users _create_
> > PNG files?
> 
> What I actually had in mind was that Emacs already does this guessing 
> (what was the intention of opening a png file) and we don't want to 
> change this process. But after we decided we want to display the 
> graphics and before passing the filename to the graphic library, we 
> should check if file exists.

That's not how "C-x C-f" works in this case.  It visits the file as
usual, and then turns on image-mode, which instructs the image library
to display the image using the data we already have in the buffer.  So
the file name is never passed to the image library.

IOW, Emacs does the same in this case as when you type

  C-x C-f non-existent-file.c RET

In the latter case, you get an empty buffer that is in CC mode, and a
message "(New file)" in the echo area.

Therefore, I submit that the problem is with image-mode, which barfs
on empty buffers, obviously assuming such situations won't happen.

> If file does not exist - give the exact message or fallback to 
> non-graphical mode. Both solutions would make it obvious, that the file 
> does not exists. I guess that's the intention of Alex, who reported this.

Would it be wrong to have an empty buffer put in image-mode and "(New
file)" displayed in the echo area?  That is how Emacs behaves in any
other case when the user visits a file that does not exist.