When a file is visited, function ‘set-auto-mode’ (see set-auto-mode) is called to determine the right MajorMode to use.
‘set-auto-mode’
It looks for a mode: string, then applies these variables in turn:
mode:
CategoryDotEmacs CategoryModes