31: How do I make Emacs use a certain major mode for certain files?
If you want to use XXX mode for all files which end with the extension
".YYY", this will do it for you:
(setq auto-mode-alist (cons '("\\.YYY\\'" . XXX-mode) auto-mode-alist))
Otherwise put this somewhere in the first line of any file you want to
edit in XXX mode (in the second line, if the first line begins with
"#!"):
-*-XXX-*-
Emacs 19 also includes a new variable, interpreter-mode-alist, that
specifies which mode to use when loading a shell script. (Emacs
determines which interpreter you're using by examining the first line of
the file.) This feature only applies when the file name doesn't indicate
which mode to use. Use "C-h v" (or M-x describe-variable) on
interpreter-mode-alist to learn more.