emacs-devel
[Top][All Lists]
Advanced

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

Re: C file recoginzed as image file


From: Juanma Barranquero
Subject: Re: C file recoginzed as image file
Date: Fri, 5 Jan 2007 23:44:35 +0100

On 1/5/07, Chris Moore <address@hidden> wrote:

Even if magic-mode-alist was just right, and it only opened files as
images when they contain images, I don't want this mysterious .c file
I just received in the mail being opened as an image, because who
knows what it might do...

That's a reason no to auto-detect images, not a reason to use
`magic-mode-alist' after `auto-mode-alist'.

But when the file contains an image file, Emacs
is happy to just display it without any kind of prompt or warning,
even when the file has a .c extension?

You're right. In my previous message in this tread, I already
suggested to deactivate auto-detection of images.

In short, .c files should be opened in cc-mode, no matter what they
contain, at least not without checking with the user first.  "The
file's extension indicates that this is C source code, but the file
contains an image in PNG format.  Display the image?  (y/n)"

That's more-or-less easy even now:

(defun image-auto-detect-y-or-n-p ()
 (let ((type (image-type-auto-detected-p)))
   (and type
        (y-or-n-p (format "File \"%s\" contains a `%s' image; display it "
                          (file-name-nondirectory buffer-file-name)
                          (image-type-from-buffer))))))

(setcar (rassq 'image-mode magic-mode-alist)
       'image-auto-detect-y-or-n-p)


                   /L/e/k/t/u




reply via email to

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