Automatic selection: Behind the scenes
Emacs determines the major mode as follows:
- First line is scanned for
-*- mode: NAME -*-
string.
- File name is matched against ‘auto-mode-alist’ in ‘.dir-locals.el’.
- Shebang (
#!
) is matched against ‘interpreter-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’.