efaq: Associating modes with files
5.8 How do I make Emacs use a certain major mode for certain files?
===================================================================
If you want to use a certain mode FOO for all files whose names end with
the extension ‘.BAR’, this will do it for you:
(add-to-list 'auto-mode-alist '("\\.BAR\\'" . FOO-mode))
Alternatively, put this somewhere in the first line of any file you
want to edit in the mode FOO (in the second line, if the first line
begins with ‘#!’):
-*- FOO -*-
The variable ‘interpreter-mode-alist’ specifies which mode to use
when loading an interpreted script (e.g., shell, python, etc.). Emacs
determines which interpreter you’re using by examining the first line of
the script. Use ‘C-h v’ (or ‘M-x describe-variable’) on
‘interpreter-mode-alist’ to learn more.