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: Stefan Monnier
Subject: Re: C file recoginzed as image file
Date: Mon, 08 Jan 2007 10:09:21 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux)

>> The reason I decided to detect images by their contents
>> rather than by their file names is that it seems more correct
>> as a way of recognizing them.

>     Why does it seem that way to you?

> The whole point of a magic number is to recognize the file type
> from its contents, regardless of file name.

But they're heuristics as well.  A text file may start with the title
"GIF89a file format".

Basically, I think that determining the major mode for a given file should
neither give precedence to auto-mode-alist nor magic-mode-alist.  Instead it
should consider both.  Each one can associate a file with a set of possible
major modes (typically the set will be singleton) or say "don't know"
(which would be basically the set of all major modes).

E.g. auto-mode-alist would give "don't know" for a file named "/b/c/foo" but
would give the set { perl-mode, prolog-mode } for a file named
"/b/c/foo.pl".  Then magic-mode-alist would give other sets of modes (based
on things like the #! interpreter name, the -*- ... -*- cookie, etc...).
If the intersection of the two sets is a singleton, then use that
major-mode, otherwise query the user to decide whether to believe the file
name or the contents.  After all, an inconsistently named file is generally
a sign that there's something wrong, so it's good to prompt the user
about it.


        Stefan




reply via email to

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