aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2016-01-25 16:54:08 +0000
committerArtur Malabarba2016-01-25 23:42:41 +0000
commit777c712c9c419d20de2602e53308fca2eb8442b3 (patch)
treec792cbe54965867e24c0db2b93bf931e3d222cf6
parent6efc59264d02902f9ea52ef6cb0400518fb798d8 (diff)
downloademacs-777c712c9c419d20de2602e53308fca2eb8442b3.tar.gz
emacs-777c712c9c419d20de2602e53308fca2eb8442b3.zip
* lisp/files.el (dir-locals-find-file): Refactor return values
Returning a cache remains unchanged, but the case of returning a file (or pattern) is now changed to return the contaning directory. (dir-locals-read-from-file): Rename to `dir-locals-read-from-dir' and make obsolete. (dir-locals-read-from-dir): Simplify accordingly. (hack-dir-local-variables): Simplify accordingly and rename a variable.
-rw-r--r--lisp/files.el65
1 files changed, 31 insertions, 34 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 5a15c71aab6..91558aa52c4 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3758,24 +3758,19 @@ A cache entry based on a `dir-locals-file' is valid if the modification
3758time stored in the cache matches the current file modification time. 3758time stored in the cache matches the current file modification time.
3759If not, the cache entry is cleared so that the file will be re-read. 3759If not, the cache entry is cleared so that the file will be re-read.
3760 3760
3761This function returns either nil (no directory local variables found), 3761This function returns either:
3762or the matching entry from `dir-locals-directory-cache' (a list), 3762 - nil (no directory local variables found),
3763or the full path to the `dir-locals-file' (a string) in the case 3763 - the matching entry from `dir-locals-directory-cache' (a list),
3764of no valid cache entry. If `dir-locals-file' contains 3764 - or the full path to the directory (a string) containing at
3765wildcards, then the return value is not a proper filename, it is 3765 least one `dir-locals-file' in the case of no valid cache
3766an absolute version of `dir-locals-file' which is guaranteed to 3766 entry."
3767expand to at least one file."
3768 (setq file (expand-file-name file)) 3767 (setq file (expand-file-name file))
3769 (let* ((locals-dir (locate-dominating-file (file-name-directory file) 3768 (let* ((locals-dir (locate-dominating-file (file-name-directory file)
3770 #'dir-locals--all-files)) 3769 #'dir-locals--all-files))
3771 locals-file dir-elt) 3770 dir-elt)
3772 ;; `locate-dominating-file' may have abbreviated the name. 3771 ;; `locate-dominating-file' may have abbreviated the name.
3773 (when locals-dir 3772 (when locals-dir
3774 (setq locals-dir (expand-file-name locals-dir)) 3773 (setq locals-dir (expand-file-name locals-dir)))
3775 (setq locals-file (expand-file-name (if (eq system-type 'ms-dos)
3776 (dosified-file-name dir-locals-file)
3777 dir-locals-file)
3778 locals-dir)))
3779 ;; Find the best cached value in `dir-locals-directory-cache'. 3774 ;; Find the best cached value in `dir-locals-directory-cache'.
3780 (dolist (elt dir-locals-directory-cache) 3775 (dolist (elt dir-locals-directory-cache)
3781 (when (and (string-prefix-p (car elt) file 3776 (when (and (string-prefix-p (car elt) file
@@ -3808,20 +3803,19 @@ expand to at least one file."
3808 (delq dir-elt dir-locals-directory-cache)) 3803 (delq dir-elt dir-locals-directory-cache))
3809 ;; Return the first existing dir-locals file. Might be the same 3804 ;; Return the first existing dir-locals file. Might be the same
3810 ;; as dir-elt's, might not (eg latter might have been deleted). 3805 ;; as dir-elt's, might not (eg latter might have been deleted).
3811 locals-file) 3806 locals-dir)
3812 ;; No cache entry. 3807 ;; No cache entry.
3813 locals-file))) 3808 locals-dir)))
3814 3809
3815(defun dir-locals-read-from-file (file) 3810(defun dir-locals-read-from-dir (dir)
3816 "Load a variables FILE and register a new class and instance. 3811 "Load all variables files in DIR and register a new class and instance.
3817FILE is the absolute name of the file holding the variables to 3812DIR is the absolute name of a directory which must contain at
3818apply. It may contain wildcards. 3813least one dir-local file (which is a file holding variables to
3819The new class name is the same as the directory in which FILE 3814apply).
3820is found. Returns the new class name." 3815Return the new class name, which is a symbol named DIR."
3821 (require 'map) 3816 (require 'map)
3822 (let* ((dir-name (file-name-directory file)) 3817 (let* ((class-name (intern dir))
3823 (class-name (intern dir-name)) 3818 (files (dir-locals--all-files dir))
3824 (files (dir-locals--all-files file))
3825 (read-circle nil) 3819 (read-circle nil)
3826 (success nil) 3820 (success nil)
3827 (variables)) 3821 (variables))
@@ -3838,7 +3832,7 @@ is found. Returns the new class name."
3838 (setq success t)) 3832 (setq success t))
3839 (dir-locals-set-class-variables class-name variables) 3833 (dir-locals-set-class-variables class-name variables)
3840 (dir-locals-set-directory-class 3834 (dir-locals-set-directory-class
3841 dir-name class-name 3835 dir class-name
3842 (seconds-to-time 3836 (seconds-to-time
3843 (if success 3837 (if success
3844 (apply #'max (mapcar (lambda (file) 3838 (apply #'max (mapcar (lambda (file)
@@ -3849,6 +3843,9 @@ is found. Returns the new class name."
3849 0))) 3843 0)))
3850 class-name)) 3844 class-name))
3851 3845
3846(define-obsolete-function-alias 'dir-locals-read-from-file
3847 'dir-locals-read-from-dir "25.1")
3848
3852(defcustom enable-remote-dir-locals nil 3849(defcustom enable-remote-dir-locals nil
3853 "Non-nil means dir-local variables will be applied to remote files." 3850 "Non-nil means dir-local variables will be applied to remote files."
3854 :version "24.3" 3851 :version "24.3"
@@ -3870,17 +3867,17 @@ This does nothing if either `enable-local-variables' or
3870 (not (file-remote-p (or (buffer-file-name) 3867 (not (file-remote-p (or (buffer-file-name)
3871 default-directory))))) 3868 default-directory)))))
3872 ;; Find the variables file. 3869 ;; Find the variables file.
3873 (let ((file-pattern-or-cache (dir-locals-find-file 3870 (let ((dir-or-cache (dir-locals-find-file
3874 (or (buffer-file-name) default-directory))) 3871 (or (buffer-file-name) default-directory)))
3875 (class nil) 3872 (class nil)
3876 (dir-name nil)) 3873 (dir-name nil))
3877 (cond 3874 (cond
3878 ((stringp file-pattern-or-cache) 3875 ((stringp dir-or-cache)
3879 (setq dir-name (file-name-directory file-pattern-or-cache) 3876 (setq dir-name dir-or-cache
3880 class (dir-locals-read-from-file file-pattern-or-cache))) 3877 class (dir-locals-read-from-dir dir-or-cache)))
3881 ((consp file-pattern-or-cache) 3878 ((consp dir-or-cache)
3882 (setq dir-name (nth 0 file-pattern-or-cache)) 3879 (setq dir-name (nth 0 dir-or-cache))
3883 (setq class (nth 1 file-pattern-or-cache)))) 3880 (setq class (nth 1 dir-or-cache))))
3884 (when class 3881 (when class
3885 (let ((variables 3882 (let ((variables
3886 (dir-locals-collect-variables 3883 (dir-locals-collect-variables