emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9ac6ff5: Make the test for auto-mode-alist from .dir-local.el str


From: Lars Ingebrigtsen
Subject: master 9ac6ff5: Make the test for auto-mode-alist from .dir-local.el stricter
Date: Sat, 24 Jul 2021 05:16:28 -0400 (EDT)

branch: master
commit 9ac6ff53b105925400a773a5088c9d0ec5b095a4
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 lisp/files.el                            | 15 +++++++++++----
 test/lisp/files-resources/.dir-locals.el |  5 ++++-
 test/lisp/files-resources/auto-test.zot1 |  1 +
 test/lisp/files-resources/auto-test.zot2 |  1 +
 test/lisp/files-resources/auto-test.zot3 |  1 +
 test/lisp/files-tests.el                 |  8 +++++++-
 6 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index d915c2a..aab839e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -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.
 
diff --git a/test/lisp/files-resources/.dir-locals.el 
b/test/lisp/files-resources/.dir-locals.el
index 84997b8..84393aa 100644
--- a/test/lisp/files-resources/.dir-locals.el
+++ b/test/lisp/files-resources/.dir-locals.el
@@ -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))))
diff --git a/test/lisp/files-resources/auto-test.zot1 
b/test/lisp/files-resources/auto-test.zot1
new file mode 100644
index 0000000..80acfcc
--- /dev/null
+++ b/test/lisp/files-resources/auto-test.zot1
@@ -0,0 +1 @@
+zot1
diff --git a/test/lisp/files-resources/auto-test.zot2 
b/test/lisp/files-resources/auto-test.zot2
new file mode 100644
index 0000000..975fc76
--- /dev/null
+++ b/test/lisp/files-resources/auto-test.zot2
@@ -0,0 +1 @@
+zot2
diff --git a/test/lisp/files-resources/auto-test.zot3 
b/test/lisp/files-resources/auto-test.zot3
new file mode 100644
index 0000000..faa0715
--- /dev/null
+++ b/test/lisp/files-resources/auto-test.zot3
@@ -0,0 +1 @@
+zot3
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index fce7e3f..a5c8236 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]