mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Make the test for auto-mode-alist from .dir-local.el stricter
* lisp/files.el (set-auto-mode--dir-local-valid-p): New function. (set-auto-mode--apply-alist): Use it as a stricter test.
This commit is contained in:
parent
59eaa30c90
commit
9ac6ff53b1
6 changed files with 25 additions and 6 deletions
|
|
@ -3238,14 +3238,21 @@ extra checks should be done."
|
|||
(setq mode (car mode)
|
||||
name (substring name 0 (match-beginning 0)))
|
||||
(setq name nil)))
|
||||
(when (and dir-local mode)
|
||||
(unless (string-suffix-p "-mode" (symbol-name mode))
|
||||
(message "Ignoring invalid mode `%s'" (symbol-name mode))
|
||||
(setq mode nil)))
|
||||
(when (and dir-local mode
|
||||
(not (set-auto-mode--dir-local-valid-p mode)))
|
||||
(message "Ignoring invalid mode `%s'" mode)
|
||||
(setq mode nil))
|
||||
(when mode
|
||||
(set-auto-mode-0 mode keep-mode-if-same)
|
||||
t))))
|
||||
|
||||
(defun set-auto-mode--dir-local-valid-p (mode)
|
||||
"Say whether MODE can be used in a .dir-local.el `auto-mode-alist'."
|
||||
(and (symbolp mode)
|
||||
(string-suffix-p "-mode" (symbol-name mode))
|
||||
(commandp mode)
|
||||
(not (provided-mode-derived-p mode 'special-mode))))
|
||||
|
||||
(defun set-auto-mode (&optional keep-mode-if-same)
|
||||
"Select major mode appropriate for current buffer.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,5 @@
|
|||
;; This is used by files-tests.el.
|
||||
((auto-mode-alist . (("\\.quux\\'" . tcl-mode))))
|
||||
((auto-mode-alist . (("\\.quux\\'" . tcl-mode)
|
||||
("\\.zot1\\'" . foobar)
|
||||
("\\.zot2\\'" . (lambda ()))
|
||||
("\\.zot3\\'" . dired-mode))))
|
||||
|
|
|
|||
1
test/lisp/files-resources/auto-test.zot1
Normal file
1
test/lisp/files-resources/auto-test.zot1
Normal file
|
|
@ -0,0 +1 @@
|
|||
zot1
|
||||
1
test/lisp/files-resources/auto-test.zot2
Normal file
1
test/lisp/files-resources/auto-test.zot2
Normal file
|
|
@ -0,0 +1 @@
|
|||
zot2
|
||||
1
test/lisp/files-resources/auto-test.zot3
Normal file
1
test/lisp/files-resources/auto-test.zot3
Normal file
|
|
@ -0,0 +1 @@
|
|||
zot3
|
||||
|
|
@ -1537,7 +1537,13 @@ The door of all subtleties!
|
|||
(ert-deftest files-test-dir-locals-auto-mode-alist ()
|
||||
"Test an `auto-mode-alist' entry in `.dir-locals.el'"
|
||||
(find-file (ert-resource-file "whatever.quux"))
|
||||
(should (eq major-mode 'tcl-mode)))
|
||||
(should (eq major-mode 'tcl-mode))
|
||||
(find-file (ert-resource-file "auto-test.zot1"))
|
||||
(should (eq major-mode 'fundamental-mode))
|
||||
(find-file (ert-resource-file "auto-test.zot2"))
|
||||
(should (eq major-mode 'fundamental-mode))
|
||||
(find-file (ert-resource-file "auto-test.zot3"))
|
||||
(should (eq major-mode 'fundamental-mode)))
|
||||
|
||||
(provide 'files-tests)
|
||||
;;; files-tests.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue