aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2016-01-30 16:14:52 +0000
committerArtur Malabarba2016-01-30 19:54:41 +0000
commit71b20b31c8ee25bcd0de1a954c9ca7b49140b3b2 (patch)
tree687f518360ec65ff3d03639a33589720913d729c
parentae26c8a7a46ffa6266a4efce592827cf47e85170 (diff)
downloademacs-71b20b31c8ee25bcd0de1a954c9ca7b49140b3b2.tar.gz
emacs-71b20b31c8ee25bcd0de1a954c9ca7b49140b3b2.zip
Backport: * lisp/files.el: Remove support for extra .dir-locals file
(dir-locals-file-2, dir-locals--all-files): Remove. (dir-locals-collect-variables, dir-locals-file, dir-locals-find-file) (dir-locals-read-from-file, hack-dir-local-variables): Revert changes. * lisp/files-x.el (modify-dir-local-variable): Revert changes. * lisp/help-fns.el (describe-variable): Revert changes. * doc/emacs/custom.texi (Directory Variables): Revert changes. * etc/NEWS: Revert changes.
-rw-r--r--doc/emacs/custom.texi6
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/files-x.el30
-rw-r--r--lisp/files.el198
-rw-r--r--lisp/help-fns.el42
5 files changed, 106 insertions, 174 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 7be660c85d1..c1093353757 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -1298,11 +1298,7 @@ accomplished with @dfn{directory-local variables}.
1298named @file{.dir-locals.el}@footnote{ On MS-DOS, the name of this file 1298named @file{.dir-locals.el}@footnote{ On MS-DOS, the name of this file
1299should be @file{_dir-locals.el}, due to limitations of the DOS 1299should be @file{_dir-locals.el}, due to limitations of the DOS
1300filesystems. If the filesystem is limited to 8+3 file names, the name 1300filesystems. If the filesystem is limited to 8+3 file names, the name
1301of the file will be truncated by the OS to @file{_dir-loc.el}. 1301of the file will be truncated by the OS to @file{_dir-loc.el}. } in a
1302}@footnote{ You can also use @file{.dir-locals-2.el}, which
1303is loaded in addition. This is useful when @file{.dir-locals.el} is
1304under version control in a shared repository and can't be used for
1305personal customizations. } in a
1306directory. Whenever Emacs visits any file in that directory or any of 1302directory. Whenever Emacs visits any file in that directory or any of
1307its subdirectories, it will apply the directory-local variables 1303its subdirectories, it will apply the directory-local variables
1308specified in @file{.dir-locals.el}, as though they had been defined as 1304specified in @file{.dir-locals.el}, as though they had been defined as
diff --git a/etc/NEWS b/etc/NEWS
index d0415a22f95..a7348e4e6f2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -181,10 +181,6 @@ by default, and must be enabled by using the `--with-modules' option
181at configure time. 181at configure time.
182 182
183+++ 183+++
184** A second dir-local file (.dir-locals-2.el) is now accepted.
185See the variable `dir-locals-file-2' for more information.
186
187+++
188** Network security (TLS/SSL certificate validity and the like) is 184** Network security (TLS/SSL certificate validity and the like) is
189added via the new Network Security Manager (NSM) and controlled via 185added via the new Network Security Manager (NSM) and controlled via
190the `network-security-level' variable. 186the `network-security-level' variable.
diff --git a/lisp/files-x.el b/lisp/files-x.el
index 05ad7f57c57..f0102fd83af 100644
--- a/lisp/files-x.el
+++ b/lisp/files-x.el
@@ -429,24 +429,18 @@ from the MODE alist ignoring the input argument VALUE."
429 (catch 'exit 429 (catch 'exit
430 (unless enable-local-variables 430 (unless enable-local-variables
431 (throw 'exit (message "Directory-local variables are disabled"))) 431 (throw 'exit (message "Directory-local variables are disabled")))
432 (let* ((dir-or-cache (and (buffer-file-name) 432 (let ((variables-file (or (and (buffer-file-name)
433 (not (file-remote-p (buffer-file-name))) 433 (not (file-remote-p (buffer-file-name)))
434 (dir-locals-find-file (buffer-file-name)))) 434 (dir-locals-find-file (buffer-file-name)))
435 (variables-file 435 dir-locals-file))
436 ;; If there are several .dir-locals, the user probably 436 variables)
437 ;; wants to edit the last one (the highest priority). 437 (if (consp variables-file) ; result from cache
438 (cond ((stringp dir-or-cache) 438 ;; If cache element has an mtime, assume it came from a file.
439 (car (last (dir-locals--all-files dir-or-cache)))) 439 ;; Otherwise, assume it was set directly.
440 ((consp dir-or-cache) ; result from cache 440 (setq variables-file (if (nth 2 variables-file)
441 ;; If cache element has an mtime, assume it came 441 (expand-file-name dir-locals-file
442 ;; from a file. Otherwise, assume it was set 442 (car variables-file))
443 ;; directly. 443 (cadr variables-file))))
444 (if (nth 2 dir-or-cache)
445 (car (last (dir-locals--all-files (car dir-or-cache))))
446 (cadr dir-or-cache)))
447 ;; Try to make a proper file-name.
448 (t (expand-file-name dir-locals-file))))
449 variables)
450 ;; I can't be bothered to handle this case right now. 444 ;; I can't be bothered to handle this case right now.
451 ;; Dir locals were set directly from a class. You need to 445 ;; Dir locals were set directly from a class. You need to
452 ;; directly modify the class in dir-locals-class-alist. 446 ;; directly modify the class in dir-locals-class-alist.
diff --git a/lisp/files.el b/lisp/files.el
index 92ae4344e1c..3898dff0383 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3663,7 +3663,7 @@ Return the new variables list."
3663 (error 3663 (error
3664 ;; The file's content might be invalid (e.g. have a merge conflict), but 3664 ;; The file's content might be invalid (e.g. have a merge conflict), but
3665 ;; that shouldn't prevent the user from opening the file. 3665 ;; that shouldn't prevent the user from opening the file.
3666 (message "%s error: %s" dir-locals-file (error-message-string err)) 3666 (message ".dir-locals error: %s" (error-message-string err))
3667 nil)))) 3667 nil))))
3668 3668
3669(defun dir-locals-set-directory-class (directory class &optional mtime) 3669(defun dir-locals-set-directory-class (directory class &optional mtime)
@@ -3715,41 +3715,8 @@ VARIABLES list of the class. The list is processed in order.
3715 3715
3716(defconst dir-locals-file ".dir-locals.el" 3716(defconst dir-locals-file ".dir-locals.el"
3717 "File that contains 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
3719environments and users. 3719across different environments and users.")
3720See also `dir-locals-file-2', whose values override this one's.
3721See Info node `(elisp)Directory Local Variables' for details.")
3722
3723(defconst dir-locals-file-2 ".dir-locals-2.el"
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).
3730See Info node `(elisp)Directory Local Variables' for details.")
3731
3732(defun dir-locals--all-files (directory)
3733 "Return a list of all readable dir-locals files in DIRECTORY.
3734The returned list is sorted by increasing priority. That is,
3735values specified in the last file should take precedence over
3736those in the first."
3737 (when (file-readable-p directory)
3738 (let* ((file-1 (expand-file-name (if (eq system-type 'ms-dos)
3739 (dosified-file-name dir-locals-file)
3740 dir-locals-file)
3741 directory))
3742 (file-2 (when (string-match "\\.el\\'" file-1)
3743 (replace-match "-2.el" t nil file-1)))
3744 (out nil))
3745 ;; The order here is important.
3746 (dolist (f (list file-2 file-1))
3747 (when (and f
3748 (file-readable-p f)
3749 (file-regular-p f)
3750 (not (file-directory-p f)))
3751 (push f out)))
3752 out)))
3753 3720
3754(defun dir-locals-find-file (file) 3721(defun dir-locals-find-file (file)
3755 "Find the directory-local variables for FILE. 3722 "Find the directory-local variables for FILE.
@@ -3764,93 +3731,78 @@ A cache entry based on a `dir-locals-file' is valid if the modification
3764time stored in the cache matches the current file modification time. 3731time stored in the cache matches the current file modification time.
3765If not, the cache entry is cleared so that the file will be re-read. 3732If not, the cache entry is cleared so that the file will be re-read.
3766 3733
3767This function returns either: 3734This function returns either nil (no directory local variables found),
3768 - nil (no directory local variables found), 3735or the matching entry from `dir-locals-directory-cache' (a list),
3769 - the matching entry from `dir-locals-directory-cache' (a list), 3736or the full path to the `dir-locals-file' (a string) in the case
3770 - or the full path to the directory (a string) containing at 3737of no valid cache entry."
3771 least one `dir-locals-file' in the case of no valid cache
3772 entry."
3773 (setq file (expand-file-name file)) 3738 (setq file (expand-file-name file))
3774 (let* ((locals-dir (locate-dominating-file (file-name-directory file) 3739 (let* ((dir-locals-file-name
3775 #'dir-locals--all-files)) 3740 (if (eq system-type 'ms-dos)
3776 dir-elt) 3741 (dosified-file-name dir-locals-file)
3742 dir-locals-file))
3743 (locals-file (locate-dominating-file file dir-locals-file-name))
3744 (dir-elt nil))
3777 ;; `locate-dominating-file' may have abbreviated the name. 3745 ;; `locate-dominating-file' may have abbreviated the name.
3778 (when locals-dir 3746 (and locals-file
3779 (setq locals-dir (expand-file-name locals-dir))) 3747 (setq locals-file (expand-file-name dir-locals-file-name locals-file)))
3748 ;; Let dir-locals-read-from-file inform us via demoted-errors
3749 ;; about unreadable files, etc.
3750 ;; Maybe we'd want to keep searching though - that is
3751 ;; a locate-dominating-file issue.
3752;;; (or (not (file-readable-p locals-file))
3753;;; (not (file-regular-p locals-file)))
3754;;; (setq locals-file nil))
3780 ;; Find the best cached value in `dir-locals-directory-cache'. 3755 ;; Find the best cached value in `dir-locals-directory-cache'.
3781 (dolist (elt dir-locals-directory-cache) 3756 (dolist (elt dir-locals-directory-cache)
3782 (when (and (string-prefix-p (car elt) file 3757 (when (and (string-prefix-p (car elt) file
3783 (memq system-type 3758 (memq system-type
3784 '(windows-nt cygwin ms-dos))) 3759 '(windows-nt cygwin ms-dos)))
3785 (> (length (car elt)) (length (car dir-elt)))) 3760 (> (length (car elt)) (length (car dir-elt))))
3786 (setq dir-elt elt))) 3761 (setq dir-elt elt)))
3787 (if (and dir-elt 3762 (if (and dir-elt
3788 (or (null locals-dir) 3763 (or (null locals-file)
3789 (<= (length locals-dir) 3764 (<= (length (file-name-directory locals-file))
3790 (length (car dir-elt))))) 3765 (length (car dir-elt)))))
3791 ;; Found a potential cache entry. Check validity. 3766 ;; Found a potential cache entry. Check validity.
3792 ;; A cache entry with no MTIME is assumed to always be valid 3767 ;; A cache entry with no MTIME is assumed to always be valid
3793 ;; (ie, set directly, not from a dir-locals file). 3768 ;; (ie, set directly, not from a dir-locals file).
3794 ;; Note, we don't bother to check that there is a matching class 3769 ;; Note, we don't bother to check that there is a matching class
3795 ;; element in dir-locals-class-alist, since that's done by 3770 ;; element in dir-locals-class-alist, since that's done by
3796 ;; dir-locals-set-directory-class. 3771 ;; dir-locals-set-directory-class.
3797 (if (or (null (nth 2 dir-elt)) 3772 (if (or (null (nth 2 dir-elt))
3798 (let ((cached-files (dir-locals--all-files (car dir-elt)))) 3773 (let ((cached-file (expand-file-name dir-locals-file-name
3799 ;; The entry MTIME should match the most recent 3774 (car dir-elt))))
3800 ;; MTIME among matching files. 3775 (and (file-readable-p cached-file)
3801 (and cached-files 3776 (equal (nth 2 dir-elt)
3802 (= (time-to-seconds (nth 2 dir-elt)) 3777 (nth 5 (file-attributes cached-file))))))
3803 (apply #'max (mapcar (lambda (f) (time-to-seconds (nth 5 (file-attributes f)))) 3778 ;; This cache entry is OK.
3804 cached-files)))))) 3779 dir-elt
3805 ;; This cache entry is OK. 3780 ;; This cache entry is invalid; clear it.
3806 dir-elt 3781 (setq dir-locals-directory-cache
3807 ;; This cache entry is invalid; clear it. 3782 (delq dir-elt dir-locals-directory-cache))
3808 (setq dir-locals-directory-cache 3783 ;; Return the first existing dir-locals file. Might be the same
3809 (delq dir-elt dir-locals-directory-cache)) 3784 ;; as dir-elt's, might not (eg latter might have been deleted).
3810 ;; Return the first existing dir-locals file. Might be the same 3785 locals-file)
3811 ;; as dir-elt's, might not (eg latter might have been deleted).
3812 locals-dir)
3813 ;; No cache entry. 3786 ;; No cache entry.
3814 locals-dir))) 3787 locals-file)))
3815 3788
3816(defun dir-locals-read-from-dir (dir) 3789(defun dir-locals-read-from-file (file)
3817 "Load all variables files in DIR and register a new class and instance. 3790 "Load a variables FILE and register a new class and instance.
3818DIR is the absolute name of a directory which must contain at 3791FILE is the name of the file holding the variables to apply.
3819least one dir-local file (which is a file holding variables to 3792The new class name is the same as the directory in which FILE
3820apply). 3793is found. Returns the new class name."
3821Return the new class name, which is a symbol named DIR." 3794 (with-temp-buffer
3822 (require 'map)
3823 (let* ((class-name (intern dir))
3824 (files (dir-locals--all-files dir))
3825 (read-circle nil)
3826 (success nil)
3827 (variables))
3828 (with-demoted-errors "Error reading dir-locals: %S" 3795 (with-demoted-errors "Error reading dir-locals: %S"
3829 (dolist (file files) 3796 (insert-file-contents file)
3830 (with-temp-buffer 3797 (unless (zerop (buffer-size))
3831 (insert-file-contents file) 3798 (let* ((dir-name (file-name-directory file))
3832 (condition-case-unless-debug nil 3799 (class-name (intern dir-name))
3833 (setq variables 3800 (variables (let ((read-circle nil))
3834 (map-merge-with 'list (lambda (a b) (map-merge 'list a b)) 3801 (read (current-buffer)))))
3835 variables 3802 (dir-locals-set-class-variables class-name variables)
3836 (read (current-buffer)))) 3803 (dir-locals-set-directory-class dir-name class-name
3837 (end-of-file nil)))) 3804 (nth 5 (file-attributes file)))
3838 (setq success t)) 3805 class-name)))))
3839 (dir-locals-set-class-variables class-name variables)
3840 (dir-locals-set-directory-class
3841 dir class-name
3842 (seconds-to-time
3843 (if success
3844 (apply #'max (mapcar (lambda (file)
3845 (time-to-seconds (nth 5 (file-attributes file))))
3846 files))
3847 ;; If there was a problem, use the values we could get but
3848 ;; don't let the cache prevent future reads.
3849 0)))
3850 class-name))
3851
3852(define-obsolete-function-alias 'dir-locals-read-from-file
3853 'dir-locals-read-from-dir "25.1")
3854 3806
3855(defcustom enable-remote-dir-locals nil 3807(defcustom enable-remote-dir-locals nil
3856 "Non-nil means dir-local variables will be applied to remote files." 3808 "Non-nil means dir-local variables will be applied to remote files."
@@ -3873,17 +3825,17 @@ This does nothing if either `enable-local-variables' or
3873 (not (file-remote-p (or (buffer-file-name) 3825 (not (file-remote-p (or (buffer-file-name)
3874 default-directory))))) 3826 default-directory)))))
3875 ;; Find the variables file. 3827 ;; Find the variables file.
3876 (let ((dir-or-cache (dir-locals-find-file 3828 (let ((variables-file (dir-locals-find-file
3877 (or (buffer-file-name) default-directory))) 3829 (or (buffer-file-name) default-directory)))
3878 (class nil) 3830 (class nil)
3879 (dir-name nil)) 3831 (dir-name nil))
3880 (cond 3832 (cond
3881 ((stringp dir-or-cache) 3833 ((stringp variables-file)
3882 (setq dir-name dir-or-cache 3834 (setq dir-name (file-name-directory variables-file)
3883 class (dir-locals-read-from-dir dir-or-cache))) 3835 class (dir-locals-read-from-file variables-file)))
3884 ((consp dir-or-cache) 3836 ((consp variables-file)
3885 (setq dir-name (nth 0 dir-or-cache)) 3837 (setq dir-name (nth 0 variables-file))
3886 (setq class (nth 1 dir-or-cache)))) 3838 (setq class (nth 1 variables-file))))
3887 (when class 3839 (when class
3888 (let ((variables 3840 (let ((variables
3889 (dir-locals-collect-variables 3841 (dir-locals-collect-variables
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 2021885e996..547bc7ee63a 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -911,35 +911,29 @@ if it is given a local binding.\n"))))
911 (buffer-file-name buffer))) 911 (buffer-file-name buffer)))
912 (dir-locals-find-file 912 (dir-locals-find-file
913 (buffer-file-name buffer)))) 913 (buffer-file-name buffer))))
914 (is-directory nil)) 914 (dir-file t))
915 (princ (substitute-command-keys 915 (princ (substitute-command-keys
916 " This variable's value is directory-local")) 916 " This variable's value is directory-local"))
917 (when (consp file) ; result from cache 917 (if (null file)
918 ;; If the cache element has an mtime, we 918 (princ ".\n")
919 ;; assume it came from a file. 919 (princ ", set ")
920 (if (nth 2 file) 920 (if (consp file) ; result from cache
921 ;; (car file) is a directory. 921 ;; If the cache element has an mtime, we
922 (setq file (dir-locals--all-files (car file))) 922 ;; assume it came from a file.
923 ;; Otherwise, assume it was set directly. 923 (if (nth 2 file)
924 (setq file (car file) 924 (setq file (expand-file-name
925 is-directory t))) 925 dir-locals-file (car file)))
926 (if (null file) 926 ;; Otherwise, assume it was set directly.
927 (princ ".\n") 927 (setq file (car file)
928 (princ ", set ") 928 dir-file nil)))
929 (princ (substitute-command-keys 929 (princ (substitute-command-keys
930 (cond 930 (if dir-file
931 (is-directory "for the directory\n `") 931 "by the file\n `"
932 ;; Many files matched. 932 "for the directory\n `")))
933 ((and (consp file) (cdr file))
934 (setq file (file-name-directory (car file)))
935 (format "by one of the\n %s files in the directory\n `"
936 dir-locals-file))
937 (t (setq file (car file))
938 "by the file\n `"))))
939 (with-current-buffer standard-output 933 (with-current-buffer standard-output
940 (insert-text-button 934 (insert-text-button
941 file 'type 'help-dir-local-var-def 935 file 'type 'help-dir-local-var-def
942 'help-args (list variable file))) 936 'help-args (list variable file)))
943 (princ (substitute-command-keys "'.\n")))) 937 (princ (substitute-command-keys "'.\n"))))
944 (princ (substitute-command-keys 938 (princ (substitute-command-keys
945 " This variable's value is file-local.\n")))) 939 " This variable's value is file-local.\n"))))