bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12357: 24.2; list-load-path-shadow should ignore .dir-locals.el


From: Xue Fuqiao
Subject: bug#12357: 24.2; list-load-path-shadow should ignore .dir-locals.el
Date: Wed, 26 Feb 2014 16:49:22 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Johan Claesson <johanclaesson@bredband.net> writes:

> A command to search for .dir-local.el shadows could look something like
> below.

Looks fine to me.  I made a patch (and tested it).  Any comments?

(I haven't written the documentation/ChangeLog/NEWS yet.)

=== modified file 'lisp/emacs-lisp/shadow.el'
--- lisp/emacs-lisp/shadow.el   2014-01-01 07:43:34 +0000
+++ lisp/emacs-lisp/shadow.el   2014-02-26 08:38:54 +0000
@@ -115,7 +115,8 @@
          ;; FILE now contains the current file name, with no suffix.
          (unless (or (member file files-seen-this-dir)
                      ;; Ignore these files.
-                     (member file '("subdirs" "leim-list")))
+                     (member file '("subdirs" "leim-list"))
+                     (string= file (file-name-sans-extension dir-locals-file)))
            ;; File has not been seen yet in this directory.
            ;; This test prevents us declaring that XXX.el shadows
            ;; XXX.elc (or vice-versa) when they are in the same directory.
@@ -281,6 +282,49 @@
              (forward-line 1))
            (message "%s" msg)))))))
 
+
+
+(defun list-load-path-dir-locals-shadows ()
+  "Display a list of dir-local files that shadow other files."
+  (interactive)
+  (dir-locals-shadows load-path))
+
+(defun dir-locals-shadows (path)
+  "Display a list of dir-local files that shadow other files under PATH."
+  (when (stringp path)
+    (setq path (list path)))
+  (with-current-buffer (get-buffer-create "*Dir-Locals-Shadows*")
+    (erase-buffer)
+    (dolist (dir path)
+      (dir-locals-shadows-1 dir (dir-locals-find-file (file-name-as-directory 
dir))))
+    (if (> (point-max) (point-min))
+        (display-buffer (current-buffer))
+      (kill-buffer (current-buffer))
+      (message "No dir-local shadows found."))))
+
+(defun dir-locals-class-name (class)
+  (if (stringp class)
+      class
+    (if (file-name-directory (symbol-name (cadr class)))
+        (concat (car class) dir-locals-file)
+      (format "%s%s (class %s)" (car class) dir-locals-file (cadr class)))))
+
+(defun dir-locals-shadows-1 (dir locals)
+  "Auxiliary function for `dir-locals-shadows'."
+  (dolist (file (directory-files dir nil nil 'no-sort))
+    (let ((subdir (expand-file-name file dir)))
+      (when (and (file-directory-p subdir)
+                 (not (or (string-equal file ".")
+                          (string-equal file "..")
+                          (file-symlink-p subdir))))
+        (let ((subdir-locals (dir-locals-find-file (file-name-as-directory 
subdir))))
+          (and locals
+               (not (equal locals subdir-locals))
+               (insert (format "%s shadows %s\n"
+                               (dir-locals-class-name subdir-locals)
+                               (dir-locals-class-name locals))))
+          (dir-locals-shadows-1 subdir subdir-locals))))))
+
 (provide 'shadow)
 
 ;;; shadow.el ends here

-- 
http://www.gnu.org/software/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]