On 11/1/07, Don Dwiggins <[EMAIL PROTECTED]> wrote:
> Rob McMullen wrote:
>> The upshot is that the code needs to be imported to check to see if a
>> file works with a major mode.
>
> In emacs (Gnu, at least), there are three basic schemes for doing this:
>
>
> auto-mode-alist, which is a list of pairs of regular expressions and modes,
> and applies each regex to the file name until it gets a match;
> magic-mode-alist, which is a similar list, except the regex is applied to
> the beginning bytes of the file (a function can be used in place of the
> regex to do the matching);
> interpreter-mode-alist, which is used with files that begin "#!{interpreter
> file path}". Pretty simple, really, but it works reasonably well, and it
> might spark some ideas.
I have something similar, implemented is classmethods in each major
mode. What I'm thinking is that I can move these matching heuristics
to the plugin code itself. Currently each plugin returns a list of
major mode classes it knows about, which implies that the major mode
has to be imported when the plugin is imported.
If I move the heuristics to the plugin code, it would allow on-demand
loading of the major mode, because the import of the major mode would
be inside some conditional. If it doesn't match, it wouldn't be
imported.
If you want to see the types of matches currently performed you can go to:
http://trac.flipturn.org/browser/trunk/peppy/major.py#L145
but basically I match in order of precidence:
url protocol
url regular expression
emacs mode specifier (i.e. -*- hexl-mode -*-)
bangpath
magic bytes
attempt to open using a library open function
where the matching stops once it has a unique match.
Rob