Rudolf Adamkovič Personal site


Automatic selection: Behind the scenes

Emacs determines the major mode as follows:

  1. First line21 is scanned for -*- mode: NAME -*- string.
  2. File name is matched against ‘auto-mode-alist’ in ‘.dir-locals.el’.
  3. Shebang (#!) is matched against ‘interpreter-mode-alist’.
  4. Beginning of the buffer content is matched against ‘magic-mode-alist’.
  5. File name is matched against ‘auto-mode-alist’.
  6. Beginning of the buffer content is matched against ‘magic-fallback-mode-alist’.

Footnotes

(21)

If the first line is a shebang, the second line is scanned.


© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.