]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow several mode: elements in the local variable section
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 19 Apr 2022 14:22:37 +0000 (16:22 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 19 Apr 2022 14:22:37 +0000 (16:22 +0200)
* etc/NEWS (mode): Fall back on outline-mode in older Emacsen.
* lisp/files.el (hack-local-variables--find-variables): Use the
final mode: line (which is the same as having several mode: bits
in the header line.

etc/NEWS
lisp/files.el
test/lisp/files-resources/file-mode-multiple [new file with mode: 0644]
test/lisp/files-tests.el

index 3e7788277d3033d76bbf08e3c5315039d5834805..496ff32d2026efe7fc74dd3bf0be82833172fbb5 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2071,6 +2071,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 \f
 Local variables:
 coding: utf-8
+mode: outline
 mode: emacs-news
 paragraph-separate: "[         \f]*$"
 end:
index 135a6177e9c4250b7ff7390589e08fe4ca5ad700..a9d4b5aea817594b4950ff6b1e3221db06f4d2a8 100644 (file)
@@ -3978,8 +3978,7 @@ major-mode."
                (forward-line 1))
              (goto-char (point-min))
 
-             (while (not (or (eobp)
-                              (and (eq handle-mode t) result)))
+             (while (not (eobp))
                ;; Find the variable name;
                (unless (looking-at hack-local-variable-regexp)
                   (user-error "Malformed local variable line: %S"
@@ -4005,7 +4004,8 @@ major-mode."
                           (not (string-match
                                 "-minor\\'"
                                 (setq val2 (downcase (symbol-name val)))))
-                          (setq result (intern (concat val2 "-mode"))))
+                           ;; Allow several mode: elements.
+                           (push (intern (concat val2 "-mode")) result))
                    (cond ((eq var 'coding))
                          ((eq var 'lexical-binding)
                           (unless hack-local-variables--warned-lexical
@@ -4029,7 +4029,10 @@ major-mode."
                                         val)
                                    result))))))
                (forward-line 1)))))))
-    result))
+    (if (eq handle-mode t)
+        ;; Return the final mode: setting that's defined.
+        (car (seq-filter #'fboundp result))
+      result)))
 
 (defun hack-local-variables-apply ()
   "Apply the elements of `file-local-variables-alist'.
diff --git a/test/lisp/files-resources/file-mode-multiple b/test/lisp/files-resources/file-mode-multiple
new file mode 100644 (file)
index 0000000..ac051cc
--- /dev/null
@@ -0,0 +1,5 @@
+Local variables:
+mode: text
+mode: test-mode-undef
+mode: outline
+end:
index f76d047f3024b70dc4c10287726381271f32b67d..c886bd7985133024cb113b6f2f1dc8c9f3ff26fb 100644 (file)
@@ -1821,5 +1821,9 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil."
   ;; Check that the mode cookie doesn't override the explicit setting.
   (should (eq major-mode 'emacs-lisp-mode)))
 
+(ert-deftest files-test-set-mode-multiple ()
+  (find-file (ert-resource-file "file-mode-multiple"))
+  (should (eq major-mode 'outline-mode)))
+
 (provide 'files-tests)
 ;;; files-tests.el ends here