51.2.4 Local Variables in Files

A file can specify local variable values to use when editing the file with Emacs. Visiting the file or setting a major mode checks for local variable specifications; it automatically makes these variables local to the buffer, and sets them to the values specified in the file.

There are two ways to set file local variables: in the first line, or with a local variables list near the end of the file.

If a file has local variables in both a local variables list and in line one, Emacs processes everything in line one first, and everything in the local variables list afterward. The exception to this is a major mode specification. Emacs applies this first, wherever it appears, since most major modes kill all local variables as part of their initialization.

File local variables override directory local variables (see Per-Directory Local Variables), if any are specified for a file’s directory.