1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 02:31:03 -08:00

* lisp/files.el: Use a fixed file name for the second dir-locals file

(dir-locals-file): Revert to its original fixed value.
(dir-locals-file-2): New const.
(dir-locals--all-files): Don't use `file-name-all-completions'.
Instead, just check for the 2 dir-locals files and return a list
of the ones that exit (if any).

* etc/NEWS: Document the change.

* doc/emacs/custom.texi (Directory Variables): Document the change.

* doc/lispref/variables.texi (Directory Local Variables): Update
accordingly.
This commit is contained in:
Artur Malabarba 2016-01-25 22:42:50 +00:00
parent 914fb99d38
commit da976cff35
4 changed files with 50 additions and 58 deletions

View file

@ -1299,8 +1299,8 @@ named @file{.dir-locals.el}@footnote{ On MS-DOS, the name of this file
should be @file{_dir-locals.el}, due to limitations of the DOS should be @file{_dir-locals.el}, due to limitations of the DOS
filesystems. If the filesystem is limited to 8+3 file names, the name filesystems. If the filesystem is limited to 8+3 file names, the name
of the file will be truncated by the OS to @file{_dir-loc.el}. of the file will be truncated by the OS to @file{_dir-loc.el}.
}@footnote{ You can also use files like @file{.dir-locals2.el}, which }@footnote{ You can also use @file{.dir-locals-2.el}, which
are loaded in addition. This is useful when @file{.dir-locals.el} is is loaded in addition. This is useful when @file{.dir-locals.el} is
under version control in a shared repository and can't be used for under version control in a shared repository and can't be used for
personal customizations. } in a personal customizations. } in a
directory. Whenever Emacs visits any file in that directory or any of directory. Whenever Emacs visits any file in that directory or any of

View file

@ -1765,33 +1765,20 @@ variables: by putting them in a special file, or by defining a
@dfn{project class} for that directory. @dfn{project class} for that directory.
@defvr Constant dir-locals-file @defvr Constant dir-locals-file
This constant is a wildcard pattern matching the name of files where This constant is the name of the file where Emacs expects to find the
Emacs expects to find directory-local variables. Its value is directory-local variables. The name of the file is
@file{.dir-locals*.el}@footnote{ @file{.dir-locals.el}@footnote{
The MS-DOS version of Emacs uses @file{_dir-locals*.el} instead, due to The MS-DOS version of Emacs uses @file{_dir-locals.el} instead, due to
limitations of the DOS filesystems. limitations of the DOS filesystems.
}, and the most common file name to use is @file{.dir-locals.el}. }. A file by that name in a directory causes Emacs to apply its
settings to any file in that directory or any of its subdirectories
Any file matching this name pattern in a directory causes Emacs to (optionally, you can exclude subdirectories; see below).
apply its settings when visiting files in that directory or any of its If some of the subdirectories have their own @file{.dir-locals.el}
subdirectories (optionally, you can exclude subdirectories; see files, Emacs uses the settings from the deepest file it finds starting
below). from the file's directory and moving up the directory tree. The file
If some of the subdirectories have their own file matching specifies local variables as a specially formatted list; see
@file{.dir-locals*.el}, Emacs uses the settings from the deepest file @ref{Directory Variables, , Per-directory Local Variables, emacs, The
it finds starting from the file's directory and moving up the GNU Emacs Manual}, for more details.
directory tree. The file specifies local variables as a specially
formatted list; see @ref{Directory Variables, , Per-directory Local
Variables, emacs, The GNU Emacs Manual}, for more details.
If the same directory contains multiple such files (for instance,
@file{.dir-locals.el} and @file{.dir-locals2.el}), then all of them
are used in @code{string<} order. This means that, if two files
specify different values for the same variable, the file sorted after
will override the value of the previous file (for instance, values in
@file{.dir-locals2.el} override those in @file{.dir-locals.el}). Note
that, because of how lexicographic order works, values in
@file{.dir-locals10.el} are overridden by values in @file{.dir-locals2.el}.
This can be avoided by using @file{.dir-locals02.el} instead.
@end defvr @end defvr
@defun hack-dir-local-variables @defun hack-dir-local-variables

View file

@ -179,9 +179,8 @@ by default, and must be enabled by using the `--with-modules' option
at configure time. at configure time.
+++ +++
** Any file of the form .dir-locals*.el is now considered a dir-local ** A second dir-local file (.dir-locals-2.el) is now accepted.
file, and multiple such files can be used in the same directory. See See the variable `dir-locals-file-2' for more information.
the variable `dir-locals-file' for more information.
+++ +++
** Network security (TLS/SSL certificate validity and the like) is ** Network security (TLS/SSL certificate validity and the like) is

View file

@ -3713,37 +3713,43 @@ VARIABLES list of the class. The list is processed in order.
applied by recursively following these rules." applied by recursively following these rules."
(setf (alist-get class dir-locals-class-alist) variables)) (setf (alist-get class dir-locals-class-alist) variables))
(defconst dir-locals-file ".dir-locals" (defconst dir-locals-file ".dir-locals.el"
"Pattern for files that contain directory-local variables. "File that contains directory-local variables.
It has to be constant to enforce uniform values across different It has to be constant to enforce uniform values across different
environments and users. environments and users.
See also `dir-locals-file-2', whose values override this one's.
Multiple dir-locals files in the same directory are loaded in
`string<' order.
See Info node `(elisp)Directory Local Variables' for details.") See Info node `(elisp)Directory Local Variables' for details.")
(defun dir-locals--all-files (file-or-dir) (defconst dir-locals-file-2 ".dir-locals-2.el"
"Return a list of all readable dir-locals files matching FILE-OR-DIR. "File that contains directory-local variables.
If FILE-OR-DIR is a file pattern, expand wildcards in it and This essentially a second file that can be used like
return a sorted list of the results. If it is a directory name, `dir-locals-file', so that users can have specify their personal
return a sorted list of all files matching `dir-locals-file' in dir-local variables even if the current directory already has a
this directory. `dir-locals-file' that is shared with other users (such as in a
The returned list is sorted by `string<' order." git repository).
(require 'seq) See Info node `(elisp)Directory Local Variables' for details.")
(let ((dir (if (file-directory-p file-or-dir)
file-or-dir (defun dir-locals--all-files (directory)
(or (file-name-directory file-or-dir) "Return a list of all readable dir-locals files in DIRECTORY.
default-directory))) The returned list is sorted by increasing priority. That is,
(file (cond ((not (file-directory-p file-or-dir)) (file-name-nondirectory file-or-dir)) values specified in the last file should take precedence over
((eq system-type 'ms-dos) (dosified-file-name dir-locals-file)) those in the first."
(t dir-locals-file)))) (when (file-readable-p directory)
(seq-filter (lambda (f) (and (file-readable-p f) (let* ((file-1 (expand-file-name (if (eq system-type 'ms-dos)
(file-regular-p f) (dosified-file-name dir-locals-file)
(not (file-directory-p f)))) dir-locals-file)
(mapcar (lambda (f) (expand-file-name f dir)) directory))
(nreverse (file-2 (when (string-match "\\.el\\'" file-1)
(let ((completion-regexp-list '("\\.el\\'"))) (replace-match "-2.el" t nil file-1)))
(file-name-all-completions file dir))))))) (out nil))
;; The order here is important.
(dolist (f (list file-2 file-1))
(when (and f
(file-readable-p f)
(file-regular-p f)
(not (file-directory-p f)))
(push f out)))
out)))
(defun dir-locals-find-file (file) (defun dir-locals-find-file (file)
"Find the directory-local variables for FILE. "Find the directory-local variables for FILE.