From: Lars Ingebrigtsen Date: Mon, 18 Apr 2022 08:36:32 +0000 (+0200) Subject: Fix major-mode setting regression when there's a mode: cookie X-Git-Tag: emacs-29.0.90~1931^2~435 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=713a1997059fb823f9fa26f92cee032fb6bfdc25;p=emacs.git 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). --- diff --git a/lisp/files.el b/lisp/files.el index 80180276a99..135a6177e9c 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -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))) diff --git a/test/lisp/files-resources/file-mode b/test/lisp/files-resources/file-mode new file mode 100644 index 00000000000..92ac4c30ef5 --- /dev/null +++ b/test/lisp/files-resources/file-mode @@ -0,0 +1,3 @@ +Local variables: +mode: text +end: diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index e4424f3cbed..f76d047f302 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -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