See Info node `(elisp)Directory Local Variables' for details.")
-(defun dir-locals--all-files (directory)
+(defun dir-locals--all-files (directory &optional base-el-only)
"Return a list of all readable dir-locals files in DIRECTORY.
The returned list is sorted by increasing priority. That is,
values specified in the last file should take precedence over
those in the first."
(when (file-readable-p directory)
(let* ((file-1 (expand-file-name (if (eq system-type 'ms-dos)
- (dosified-file-name dir-locals-file)
- dir-locals-file)
- directory))
+ (dosified-file-name dir-locals-file)
+ dir-locals-file)
+ directory))
(file-2 (when (string-match "\\.el\\'" file-1)
(replace-match "-2.el" t nil file-1)))
- (out nil))
- ;; The order here is important.
- (dolist (f (list file-2 file-1))
+ out)
+ (dolist (f (or (and base-el-only (list file-1))
+ ;; The order here is important.
+ (list file-2 file-1)))
(when (and f
(file-readable-p f)
;; FIXME: Aren't file-regular-p and
(push f out)))
out)))
+(defun dir-locals--base-file (directory)
+ "Return readable `dir-locals-file' in DIRECTORY, or nil."
+ (dir-locals--all-files directory 'base-el-only))
+
(defun dir-locals-find-file (file)
"Find the directory-local variables for FILE.
This searches upward in the directory tree from FILE.
entry."
(setq file (expand-file-name file))
(let* ((locals-dir (locate-dominating-file (file-name-directory file)
- #'dir-locals--all-files))
+ #'dir-locals--base-file))
dir-elt)
;; `locate-dominating-file' may have abbreviated the name.
(when locals-dir
;; Invocation through env, with modified environment.
(files-tests--check-shebang "#!/usr/bin/env -S PYTHONPATH=/...:${PYTHONPATH} python" 'python-base-mode))
+(ert-deftest files-test-dir-locals-2-solo ()
+ "Ensure that solo `.dir-locals-2.el' is ignored."
+ (with-current-buffer
+ (find-file-noselect (ert-resource-file
+ (concat "dir-locals-2-solo/dir-locals-2-solo.txt")))
+ (should-not (local-variable-p 'dir-locals-2-loaded))))
+
+(ert-deftest files-test-dir-locals-2-paired ()
+ "Ensure that `.dir-locals-2.el' is loaded, if paired."
+ (let ((enable-local-variables :all))
+ (with-current-buffer (find-file-noselect
+ (ert-resource-file (concat "dir-locals-and-2/dir-locals-and-2.txt")))
+ (should (local-variable-p 'dir-locals-loaded))
+ (should (local-variable-p 'dir-locals-2-loaded)))))
+
(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"))