Subject: bug#15577: 24.3; dir-local variables not applied when switching major-mode

From: yary <[email-masked]>
Date: Mon, 14 Oct 2013 14:41:34 -0400

Thinking about switching major modes more, my instinct is that the
right solution involves being "smarter" both about which local
variables to clear and reloading any {dir,file}-local variables for
the new node.

Basically, at the start, instead of calling
"kill-all-local-variables", only clear the locals that were set as a
consequence of the old mode. That is, if it was set directly by the
old mode, or by dir-local matching the old mode, delete it. Don't
delete a buffer-local variable if it was set explicitly by the user
after opening during the editing session.

Then after the new mode has set itself, recheck dir-locals and set any
that match the new mode.

Alas I don't use file-locals so am not sure how their use cases fit.
Ignore any "mode:" specifiers and maybe "eval:" as well after the
mode-change, I'd guess.