diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-04-19 16:22:37 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-04-19 16:22:37 +0200 |
commit | 35592141cc8951c91a4bd6cc02f73d1ddd35aca4 (patch) | |
tree | f25d59e2c894cb9f4ccb763ea99166e6d9a606e5 | |
parent | 71005decb4fb447635d7b2367104dd18bdfa64ac (diff) | |
download | emacs-35592141cc8951c91a4bd6cc02f73d1ddd35aca4.tar.gz emacs-35592141cc8951c91a4bd6cc02f73d1ddd35aca4.tar.bz2 emacs-35592141cc8951c91a4bd6cc02f73d1ddd35aca4.zip |
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.
-rw-r--r-- | etc/NEWS | 1 | ||||
-rw-r--r-- | lisp/files.el | 11 | ||||
-rw-r--r-- | test/lisp/files-resources/file-mode-multiple | 5 | ||||
-rw-r--r-- | test/lisp/files-tests.el | 4 |
4 files changed, 17 insertions, 4 deletions
@@ -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 135a6177e9c..a9d4b5aea81 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 00000000000..ac051ccbcbd --- /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 f76d047f302..c886bd79851 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 |