[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 35592141cc: Allow several mode: elements in the local variable se
From: |
Lars Ingebrigtsen |
Subject: |
master 35592141cc: Allow several mode: elements in the local variable section |
Date: |
Tue, 19 Apr 2022 10:22:51 -0400 (EDT) |
branch: master
commit 35592141cc8951c91a4bd6cc02f73d1ddd35aca4
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow several mode: elements in the local variable section
* 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 | 1 +
lisp/files.el | 11 +++++++----
test/lisp/files-resources/file-mode-multiple | 5 +++++
test/lisp/files-tests.el | 4 ++++
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 3e7788277d..496ff32d20 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2071,6 +2071,7 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>.
Local variables:
coding: utf-8
+mode: outline
mode: emacs-news
paragraph-separate: "[ ]*$"
end:
diff --git a/lisp/files.el b/lisp/files.el
index 135a6177e9..a9d4b5aea8 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -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
index 0000000000..ac051ccbcb
--- /dev/null
+++ b/test/lisp/files-resources/file-mode-multiple
@@ -0,0 +1,5 @@
+Local variables:
+mode: text
+mode: test-mode-undef
+mode: outline
+end:
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index f76d047f30..c886bd7985 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 35592141cc: Allow several mode: elements in the local variable section,
Lars Ingebrigtsen <=