diff options
| author | Artur Malabarba | 2016-01-25 22:42:50 +0000 |
|---|---|---|
| committer | Artur Malabarba | 2016-01-25 23:42:41 +0000 |
| commit | da976cff352bdea6adc2667582a56eb4061bb5f6 (patch) | |
| tree | 73b89ceb316306267ca9816dd8d30a0445382fb9 | |
| parent | 914fb99d38f8a9db7fbf926d0cf34b808d581afe (diff) | |
| download | emacs-da976cff352bdea6adc2667582a56eb4061bb5f6.tar.gz emacs-da976cff352bdea6adc2667582a56eb4061bb5f6.zip | |
* 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.
| -rw-r--r-- | doc/emacs/custom.texi | 4 | ||||
| -rw-r--r-- | doc/lispref/variables.texi | 39 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/files.el | 58 |
4 files changed, 49 insertions, 57 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index 670848c65a1..7be660c85d1 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi | |||
| @@ -1299,8 +1299,8 @@ named @file{.dir-locals.el}@footnote{ On MS-DOS, the name of this file | |||
| 1299 | should be @file{_dir-locals.el}, due to limitations of the DOS | 1299 | should be @file{_dir-locals.el}, due to limitations of the DOS |
| 1300 | filesystems. If the filesystem is limited to 8+3 file names, the name | 1300 | filesystems. If the filesystem is limited to 8+3 file names, the name |
| 1301 | of the file will be truncated by the OS to @file{_dir-loc.el}. | 1301 | of the file will be truncated by the OS to @file{_dir-loc.el}. |
| 1302 | }@footnote{ You can also use files like @file{.dir-locals2.el}, which | 1302 | }@footnote{ You can also use @file{.dir-locals-2.el}, which |
| 1303 | are loaded in addition. This is useful when @file{.dir-locals.el} is | 1303 | is loaded in addition. This is useful when @file{.dir-locals.el} is |
| 1304 | under version control in a shared repository and can't be used for | 1304 | under version control in a shared repository and can't be used for |
| 1305 | personal customizations. } in a | 1305 | personal customizations. } in a |
| 1306 | directory. Whenever Emacs visits any file in that directory or any of | 1306 | directory. Whenever Emacs visits any file in that directory or any of |
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index 42701614365..6c53e9b6cca 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -1765,33 +1765,20 @@ variables: by putting them in a special file, or by defining a | |||
| 1765 | @dfn{project class} for that directory. | 1765 | @dfn{project class} for that directory. |
| 1766 | 1766 | ||
| 1767 | @defvr Constant dir-locals-file | 1767 | @defvr Constant dir-locals-file |
| 1768 | This constant is a wildcard pattern matching the name of files where | 1768 | This constant is the name of the file where Emacs expects to find the |
| 1769 | Emacs expects to find directory-local variables. Its value is | 1769 | directory-local variables. The name of the file is |
| 1770 | @file{.dir-locals*.el}@footnote{ | 1770 | @file{.dir-locals.el}@footnote{ |
| 1771 | The MS-DOS version of Emacs uses @file{_dir-locals*.el} instead, due to | 1771 | The MS-DOS version of Emacs uses @file{_dir-locals.el} instead, due to |
| 1772 | limitations of the DOS filesystems. | 1772 | limitations of the DOS filesystems. |
| 1773 | }, and the most common file name to use is @file{.dir-locals.el}. | 1773 | }. A file by that name in a directory causes Emacs to apply its |
| 1774 | 1774 | settings to any file in that directory or any of its subdirectories | |
| 1775 | Any file matching this name pattern in a directory causes Emacs to | 1775 | (optionally, you can exclude subdirectories; see below). |
| 1776 | apply its settings when visiting files in that directory or any of its | 1776 | If some of the subdirectories have their own @file{.dir-locals.el} |
| 1777 | subdirectories (optionally, you can exclude subdirectories; see | 1777 | files, Emacs uses the settings from the deepest file it finds starting |
| 1778 | below). | 1778 | from the file's directory and moving up the directory tree. The file |
| 1779 | If some of the subdirectories have their own file matching | 1779 | specifies local variables as a specially formatted list; see |
| 1780 | @file{.dir-locals*.el}, Emacs uses the settings from the deepest file | 1780 | @ref{Directory Variables, , Per-directory Local Variables, emacs, The |
| 1781 | it finds starting from the file's directory and moving up the | 1781 | GNU Emacs Manual}, for more details. |
| 1782 | directory tree. The file specifies local variables as a specially | ||
| 1783 | formatted list; see @ref{Directory Variables, , Per-directory Local | ||
| 1784 | Variables, emacs, The GNU Emacs Manual}, for more details. | ||
| 1785 | |||
| 1786 | If the same directory contains multiple such files (for instance, | ||
| 1787 | @file{.dir-locals.el} and @file{.dir-locals2.el}), then all of them | ||
| 1788 | are used in @code{string<} order. This means that, if two files | ||
| 1789 | specify different values for the same variable, the file sorted after | ||
| 1790 | will override the value of the previous file (for instance, values in | ||
| 1791 | @file{.dir-locals2.el} override those in @file{.dir-locals.el}). Note | ||
| 1792 | that, because of how lexicographic order works, values in | ||
| 1793 | @file{.dir-locals10.el} are overridden by values in @file{.dir-locals2.el}. | ||
| 1794 | This can be avoided by using @file{.dir-locals02.el} instead. | ||
| 1795 | @end defvr | 1782 | @end defvr |
| 1796 | 1783 | ||
| 1797 | @defun hack-dir-local-variables | 1784 | @defun hack-dir-local-variables |
| @@ -179,9 +179,8 @@ by default, and must be enabled by using the `--with-modules' option | |||
| 179 | at configure time. | 179 | at configure time. |
| 180 | 180 | ||
| 181 | +++ | 181 | +++ |
| 182 | ** Any file of the form .dir-locals*.el is now considered a dir-local | 182 | ** A second dir-local file (.dir-locals-2.el) is now accepted. |
| 183 | file, and multiple such files can be used in the same directory. See | 183 | See the variable `dir-locals-file-2' for more information. |
| 184 | the variable `dir-locals-file' for more information. | ||
| 185 | 184 | ||
| 186 | +++ | 185 | +++ |
| 187 | ** Network security (TLS/SSL certificate validity and the like) is | 186 | ** Network security (TLS/SSL certificate validity and the like) is |
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. |
| 3718 | It has to be constant to enforce uniform values across different | 3718 | It has to be constant to enforce uniform values across different |
| 3719 | environments and users. | 3719 | environments and users. |
| 3720 | See also `dir-locals-file-2', whose values override this one's. | ||
| 3721 | See Info node `(elisp)Directory Local Variables' for details.") | ||
| 3720 | 3722 | ||
| 3721 | Multiple 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. |
| 3725 | This essentially a second file that can be used like | ||
| 3726 | `dir-locals-file', so that users can have specify their personal | ||
| 3727 | dir-local variables even if the current directory already has a | ||
| 3728 | `dir-locals-file' that is shared with other users (such as in a | ||
| 3729 | git repository). | ||
| 3723 | See Info node `(elisp)Directory Local Variables' for details.") | 3730 | See 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. |
| 3727 | If FILE-OR-DIR is a file pattern, expand wildcards in it and | 3734 | The returned list is sorted by increasing priority. That is, |
| 3728 | return a sorted list of the results. If it is a directory name, | 3735 | values specified in the last file should take precedence over |
| 3729 | return a sorted list of all files matching `dir-locals-file' in | 3736 | those in the first." |
| 3730 | this directory. | 3737 | (when (file-readable-p directory) |
| 3731 | The 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. |