How to keep dir-local variables when switching major modes?

As per comments to Aaron Miller’s answer, here is an overview of what happens when a mode function is called (with an explanation of derived modes); how calling a mode manually differs from Emacs calling it automatically; and where after-change-major-mode-hook and hack-local-variables fit into this, in the context of the following suggested code: (add-hook ‘after-change-major-mode-hook … Read more

eval-after-load vs. mode hook

Code wrapped in eval-after-load will be executed only once, so it is typically used to perform one-time setup such as setting default global values and behaviour. An example might be setting up a default keymap for a particular mode. In eval-after-load code, there’s no notion of the “current buffer”. Mode hooks execute once for every … Read more