Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!enea!dkuug!iesd!amanda From: amanda@iesd.uucp (Per Abrahamsen) Newsgroups: comp.emacs Subject: Re: mode by file contents Message-ID: <1253@iesd.uucp> Date: 29 Jan 89 14:49:12 GMT References: Reply-To: amanda@iesd.dk (Per Abrahamsen) Organization: Games Research, University of Aalborg, Denmark Lines: 29 In article ghh@thought.princeton.edu (Gilbert Harman) writes: >I would like to put something in my .emacs that would >determine the major mode of a buffer on the basis of the >contents of the file read into the buffer rather than on the >basis of something about the name of the file. > >For example, if the file began with "\documentstyle... " >the buffer would be automatically put into latex mode. > Check out the documentation for find-file-hooks. This is from my initfile: (setq find-file-hooks (append '(check-for-magic) find-file-hooks)) ; I would like to say: ; If no commands build into file then... ; But i have to say ; If no commands that change the major mode is build into file then... ; Sorry (defun check-for-magic () "Check to see if a buffer contain perl code." (if (eq major-mode default-major-mode) (cond ((looking-at "#!/bin/perl") (perl-mode))))) -- Per Abrahamsen, amanda@iesd.dk, {...}!mcvax!diku!iesd!amanda