aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el58
1 files changed, 32 insertions, 26 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 91558aa52c4..92ae4344e1c 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3713,37 +3713,43 @@ VARIABLES list of the class. The list is processed in order.
3713 applied by recursively following these rules." 3713 applied by recursively following these rules."
3714 (setf (alist-get class dir-locals-class-alist) variables)) 3714 (setf (alist-get class dir-locals-class-alist) variables))
3715 3715
3716(defconst dir-locals-file ".dir-locals" 3716(defconst dir-locals-file ".dir-locals.el"
3717 "Pattern for files that contain directory-local variables. 3717 "File that contains directory-local variables.
3718It has to be constant to enforce uniform values across different 3718It has to be constant to enforce uniform values across different
3719environments and users. 3719environments and users.
3720See also `dir-locals-file-2', whose values override this one's.
3721See Info node `(elisp)Directory Local Variables' for details.")
3720 3722
3721Multiple dir-locals files in the same directory are loaded in 3723(defconst dir-locals-file-2 ".dir-locals-2.el"
3722`string<' order. 3724 "File that contains directory-local variables.
3725This essentially a second file that can be used like
3726`dir-locals-file', so that users can have specify their personal
3727dir-local variables even if the current directory already has a
3728`dir-locals-file' that is shared with other users (such as in a
3729git repository).
3723See Info node `(elisp)Directory Local Variables' for details.") 3730See Info node `(elisp)Directory Local Variables' for details.")
3724 3731
3725(defun dir-locals--all-files (file-or-dir) 3732(defun dir-locals--all-files (directory)
3726 "Return a list of all readable dir-locals files matching FILE-OR-DIR. 3733 "Return a list of all readable dir-locals files in DIRECTORY.
3727If FILE-OR-DIR is a file pattern, expand wildcards in it and 3734The returned list is sorted by increasing priority. That is,
3728return a sorted list of the results. If it is a directory name, 3735values specified in the last file should take precedence over
3729return a sorted list of all files matching `dir-locals-file' in 3736those in the first."
3730this directory. 3737 (when (file-readable-p directory)
3731The returned list is sorted by `string<' order." 3738 (let* ((file-1 (expand-file-name (if (eq system-type 'ms-dos)
3732 (require 'seq) 3739 (dosified-file-name dir-locals-file)
3733 (let ((dir (if (file-directory-p file-or-dir) 3740 dir-locals-file)
3734 file-or-dir 3741 directory))
3735 (or (file-name-directory file-or-dir) 3742 (file-2 (when (string-match "\\.el\\'" file-1)
3736 default-directory))) 3743 (replace-match "-2.el" t nil file-1)))
3737 (file (cond ((not (file-directory-p file-or-dir)) (file-name-nondirectory file-or-dir)) 3744 (out nil))
3738 ((eq system-type 'ms-dos) (dosified-file-name dir-locals-file)) 3745 ;; The order here is important.
3739 (t dir-locals-file)))) 3746 (dolist (f (list file-2 file-1))
3740 (seq-filter (lambda (f) (and (file-readable-p f) 3747 (when (and f
3741 (file-regular-p f) 3748 (file-readable-p f)
3742 (not (file-directory-p f)))) 3749 (file-regular-p f)
3743 (mapcar (lambda (f) (expand-file-name f dir)) 3750 (not (file-directory-p f)))
3744 (nreverse 3751 (push f out)))
3745 (let ((completion-regexp-list '("\\.el\\'"))) 3752 out)))
3746 (file-name-all-completions file dir)))))))
3747 3753
3748(defun dir-locals-find-file (file) 3754(defun dir-locals-find-file (file)
3749 "Find the directory-local variables for FILE. 3755 "Find the directory-local variables for FILE.