Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 8 down vote accepted

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.


(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))
share|improve this answer
Found the answer myself, but thanks for a more comprehensive answer :) – NWS Nov 23 '11 at 10:30

I found the answer :

(setq auto-mode-alist (cons '("\\.bob" . c-mode) auto-mode-alist))
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.