Fix major-mode setting regression when there's a mode: cookie

* lisp/files.el (hack-local-variables): Fix regression in setting
the major mode when there are mode: cookies in the file (bug#54993).
This commit is contained in:
Lars Ingebrigtsen 2022-04-18 10:36:32 +02:00
parent 736fd8b258
commit 713a199705
3 changed files with 11 additions and 1 deletions

View file

@ -3899,7 +3899,7 @@ inhibited."
(with-demoted-errors "Directory-local variables error: %s"
;; Note this is a no-op if enable-local-variables is nil.
(hack-dir-local-variables))
(let ((result (append (hack-local-variables--find-variables)
(let ((result (append (hack-local-variables--find-variables handle-mode)
(hack-local-variables-prop-line))))
(if (and enable-local-variables
(not (inhibit-local-variables-p)))

View file

@ -0,0 +1,3 @@
Local variables:
mode: text
end:

View file

@ -1814,5 +1814,12 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil."
(should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" "")))
(should (equal (file-name-split "foo/bar/") '("foo" "bar" ""))))
(ert-deftest files-test-set-mode ()
(find-file (ert-resource-file "file-mode"))
(should (eq major-mode 'text-mode))
(emacs-lisp-mode)
;; Check that the mode cookie doesn't override the explicit setting.
(should (eq major-mode 'emacs-lisp-mode)))
(provide 'files-tests)
;;; files-tests.el ends here