Home / Emacs / Major mode
Automatic selection: Behind the scenes
Emacs determines the major mode as follows:
- First line1 is scanned for
-*- mode: NAME -*-
string. - File name is matched against
auto-mode-alist
in.dir-locals.el
. - Shebang (
#!
) is matched againstinterpreter-mode-alist
. - Beginning of the buffer content is matched against
magic-mode-alist
. - File name is matched against
auto-mode-alist
. - Beginning of the buffer content is matched against
magic-fallback-mode-alist
.
Footnotes:
1
If the first line is a shebang, the second line is scanned.