diff --git a/etc/NEWS b/etc/NEWS index 29559d143db..1d5d0d64584 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -155,6 +155,11 @@ These variables are for users who would like to avoid the small probability of data corruption due to techniques Emacs uses to recover in these situations. ++++ +** File local and directory local variables are now initialized each +time the major mode is set, not just when the file is first visited. +These local variables will thus not vanish on setting a major mode. + +++ ** A second dir-local file (.dir-locals-2.el) is now accepted. See the variable 'dir-locals-file-2' for more information. diff --git a/lisp/files.el b/lisp/files.el index d89b2f52582..21f7bdc7dcf 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -2316,7 +2316,10 @@ not set local variables (though we do notice a mode specified with -*-.) or from Lisp without specifying the optional argument FIND-FILE; in that case, this function acts as if `enable-local-variables' were t." (interactive) - (fundamental-mode) + (kill-all-local-variables) + (unless delay-mode-hooks + (run-hooks 'change-major-mode-after-body-hook + 'after-change-major-mode-hook)) (let ((enable-local-variables (or (not find-file) enable-local-variables))) ;; FIXME this is less efficient than it could be, since both ;; s-a-m and h-l-v may parse the same regions, looking for "mode:".