Subject: Re: bug#23463: safe local variable properties no longer effective

From: Alan Mackenzie <[email-masked]>
Date: Fri, 6 May 2016 09:14:54 +0000

Hello, Glenn.

On Thu, May 05, 2016 at 05:59:55PM -0400, Glenn Morris wrote:
> Package: emacs
> Version: 25.1.50

> emacs -Q foo.py

> where foo.py has contents:

> # Local Variables:
> # python-indent-offset: 2
> # End:

> Current emacs-25 branch: file opens fine with no prompting,
> python-indent-offset is set to 2.
> Current master: one is told that python-indent-offset is not safe

Yes.  What is happening is that the call to `fundamental-mode' at the
beginning of `normal-mode' is itself calling `hack-local-variables' (via
`run-mode-hooks').  This is wrong.  At that stage, python-mode has not
yet been loaded, so `hack-local-variables' doesn't know that
`python-indent-offset' is "safe".

> Same applies to any similar major-mode-specific local variable.

> This is due to 25f455815bfaa868dc470d445413df9a7a546c46.

Please try out the following, and let me know how it works:

diff --git a/lisp/files.el b/lisp/files.el
index d89b2f5..21f7bdc 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2316,7 +2316,10 @@ normal-mode
 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:".

-- 
Alan Mackenzie (Nuremberg, Germany).