Emacs’ file extension recognition

emacsfilenamesopen files

How do I get Emacs to recognize new file extensions? For example if I have a .c file and I open it in Emacs, I get the correct syntax highlighting for C, but if I have a .bob file format (which I know to be C), how do I tell Emacs to interpret it in the same way as a .c file?

Best Answer

This is described on Emacs Beginner's Howto.

With the line

(setq auto-mode-alist (cons '("README" . text-mode) auto-mode-alist))

You tell emacs to enter "text-mode" if you open a file which is named README.

with

(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.htm$" . html-helper-mode) auto-mode-alist))

you tell emacs to type "html-helper-mode" if the file is named *.html or *.htm

on stackoverflow there is an example, that highligts *.emacs files as lisp.code:

(setq auto-mode-alist 
      (append '((".*\\.emacs\\'" . lisp-mode))
              auto-mode-alist))
Related Question