diff options
| author | Artur Malabarba | 2015-11-10 13:26:00 +0000 |
|---|---|---|
| committer | Artur Malabarba | 2015-11-10 13:26:00 +0000 |
| commit | 9145e79dc2042fb477959ddda59c3e2ff5fa3914 (patch) | |
| tree | 0756a70961959d95a1434392d23954c68a6b438d | |
| parent | 77cebbc1e77edf23bc2c23a218b56d9d6ad68e74 (diff) | |
| download | emacs-9145e79dc2042fb477959ddda59c3e2ff5fa3914.tar.gz emacs-9145e79dc2042fb477959ddda59c3e2ff5fa3914.zip | |
* lisp/files.el: Don't allow customization of dir-locals sorting
In retrospect, this is not a good idea for the same reason that
`dir-locals-file' is a defconst, because it is important that this
behaviour be "uniform across different environments and users".
Sure, the user can still change the sorting with a hack, but we
shouldn't encourage them to change it.
(dir-locals--all-files): Return list in the order returned by
`file-expand-wildcards'.
(file-expand-wildcards): Document the sorting predicate used.
(dir-locals-sort-predicate): Delete variable.
| -rw-r--r-- | lisp/files.el | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/lisp/files.el b/lisp/files.el index efba15ea15f..b4ede7897d9 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -3699,36 +3699,28 @@ VARIABLES list of the class. The list is processed in order. | |||
| 3699 | (setf (alist-get class dir-locals-class-alist) variables)) | 3699 | (setf (alist-get class dir-locals-class-alist) variables)) |
| 3700 | 3700 | ||
| 3701 | (defconst dir-locals-file ".dir-locals*.el" | 3701 | (defconst dir-locals-file ".dir-locals*.el" |
| 3702 | "File that contains directory-local variables. | 3702 | "Pattern for files that contain directory-local variables. |
| 3703 | It has to be constant to enforce uniform values | 3703 | It has to be constant to enforce uniform values across different |
| 3704 | across different environments and users.") | 3704 | environments and users.") |
| 3705 | |||
| 3706 | (defcustom dir-locals-sort-predicate #'string< | ||
| 3707 | "Predicate used to sort dir-locals files before loading them. | ||
| 3708 | The function should take two arguments (file names) and return | ||
| 3709 | non-nil if the first argument should be loaded first (which means | ||
| 3710 | the values in the second file will override those in the first)." | ||
| 3711 | :group 'files | ||
| 3712 | :type 'function) | ||
| 3713 | 3705 | ||
| 3714 | (defun dir-locals--all-files (file-or-dir) | 3706 | (defun dir-locals--all-files (file-or-dir) |
| 3715 | "Return a list of all readable dir-locals files matching FILE-OR-DIR. | 3707 | "Return a list of all readable dir-locals files matching FILE-OR-DIR. |
| 3716 | If FILE-OR-DIR is a file pattern, expand wildcards in it and | 3708 | If FILE-OR-DIR is a file pattern, expand wildcards in it and |
| 3717 | return a sorted list of the results. If it is a directory name, | 3709 | return a sorted list of the results. If it is a directory name, |
| 3718 | return a sorted list of all files matching `dir-locals-file' in | 3710 | return a sorted list of all files matching `dir-locals-file' in |
| 3719 | this directory." | 3711 | this directory. |
| 3712 | The returned list is sorted by `string<' order." | ||
| 3720 | (require 'seq) | 3713 | (require 'seq) |
| 3721 | (let ((default-directory (if (file-directory-p file-or-dir) | 3714 | (let ((default-directory (if (file-directory-p file-or-dir) |
| 3722 | file-or-dir | 3715 | file-or-dir |
| 3723 | default-directory))) | 3716 | default-directory))) |
| 3724 | (sort (seq-filter (lambda (f) (and (file-readable-p f) | 3717 | (seq-filter (lambda (f) (and (file-readable-p f) |
| 3725 | (file-regular-p f))) | 3718 | (file-regular-p f))) |
| 3726 | (file-expand-wildcards | 3719 | (file-expand-wildcards |
| 3727 | (cond ((not (file-directory-p file-or-dir)) file-or-dir) | 3720 | (cond ((not (file-directory-p file-or-dir)) file-or-dir) |
| 3728 | ((eq system-type 'ms-dos) (dosified-file-name dir-locals-file)) | 3721 | ((eq system-type 'ms-dos) (dosified-file-name dir-locals-file)) |
| 3729 | (t dir-locals-file)) | 3722 | (t dir-locals-file)) |
| 3730 | 'full)) | 3723 | 'full)))) |
| 3731 | dir-locals-sort-predicate))) | ||
| 3732 | 3724 | ||
| 3733 | (defun dir-locals-find-file (file) | 3725 | (defun dir-locals-find-file (file) |
| 3734 | "Find the directory-local variables for FILE. | 3726 | "Find the directory-local variables for FILE. |
| @@ -6087,6 +6079,7 @@ by `sh' are supported." | |||
| 6087 | (defun file-expand-wildcards (pattern &optional full) | 6079 | (defun file-expand-wildcards (pattern &optional full) |
| 6088 | "Expand wildcard pattern PATTERN. | 6080 | "Expand wildcard pattern PATTERN. |
| 6089 | This returns a list of file names which match the pattern. | 6081 | This returns a list of file names which match the pattern. |
| 6082 | Files are sorted in `string<' order. | ||
| 6090 | 6083 | ||
| 6091 | If PATTERN is written as an absolute file name, | 6084 | If PATTERN is written as an absolute file name, |
| 6092 | the values are absolute also. | 6085 | the values are absolute also. |