comparison lisp/emacs-lisp/shadow.el @ 105932:dd099beb5a5b

(find-emacs-lisp-shadows, list-load-path-shadows): Use dolist. (list-load-path-shadows): Use with-current-buffer.
author Glenn Morris <rgm@gnu.org>
date Tue, 10 Nov 2009 08:06:53 +0000
parents bd2966850aac
children 21d623c57072
comparison
equal deleted inserted replaced
105931:a5db20cb0a5a 105932:dd099beb5a5b
70 even-length list of files. A file in this list at position 2i shadows 70 even-length list of files. A file in this list at position 2i shadows
71 the file in position 2i+1. Emacs Lisp file suffixes \(.el and .elc\) 71 the file in position 2i+1. Emacs Lisp file suffixes \(.el and .elc\)
72 are stripped from the file names in the list. 72 are stripped from the file names in the list.
73 73
74 See the documentation for `list-load-path-shadows' for further information." 74 See the documentation for `list-load-path-shadows' for further information."
75
76 (or path (setq path load-path))
77
78 (let (true-names ; List of dirs considered. 75 (let (true-names ; List of dirs considered.
79 shadows ; List of shadowings, to be returned. 76 shadows ; List of shadowings, to be returned.
80 files ; File names ever seen, with dirs. 77 files ; File names ever seen, with dirs.
81 dir ; The dir being currently scanned. 78 dir ; The dir being currently scanned.
82 curr-files ; This dir's Emacs Lisp files. 79 curr-files ; This dir's Emacs Lisp files.
83 orig-dir ; Where the file was first seen. 80 orig-dir ; Where the file was first seen.
84 files-seen-this-dir ; Files seen so far in this dir. 81 files-seen-this-dir ; Files seen so far in this dir.
85 file) ; The current file. 82 file) ; The current file.
86 83 (dolist (pp (or path load-path))
87 84 (setq dir (directory-file-name (file-truename (or pp "."))))
88 (while path
89
90 (setq dir (directory-file-name (file-truename (or (car path) "."))))
91 (if (member dir true-names) 85 (if (member dir true-names)
92 ;; We have already considered this PATH redundant directory. 86 ;; We have already considered this PATH redundant directory.
93 ;; Show the redundancy if we are interactive, unless the PATH 87 ;; Show the redundancy if we are interactive, unless the PATH
94 ;; dir is nil or "." (these redundant directories are just a 88 ;; dir is nil or "." (these redundant directories are just a
95 ;; result of the current working directory, and are therefore 89 ;; result of the current working directory, and are therefore
96 ;; not always redundant). 90 ;; not always redundant).
97 (or noninteractive 91 (or noninteractive
98 (and (car path) 92 (and pp
99 (not (string= (car path) ".")) 93 (not (string= pp "."))
100 (message "Ignoring redundant directory %s" (car path)))) 94 (message "Ignoring redundant directory %s" pp)))
101 95
102 (setq true-names (append true-names (list dir))) 96 (setq true-names (append true-names (list dir)))
103 (setq dir (directory-file-name (or (car path) "."))) 97 (setq dir (directory-file-name (or pp ".")))
104 (setq curr-files (if (file-accessible-directory-p dir) 98 (setq curr-files (if (file-accessible-directory-p dir)
105 (directory-files dir nil ".\\.elc?\\(\\.gz\\)?$" t))) 99 (directory-files dir nil ".\\.elc?\\(\\.gz\\)?$" t)))
106 (and curr-files 100 (and curr-files
107 (not noninteractive) 101 (not noninteractive)
108 (message "Checking %d files in %s..." (length curr-files) dir)) 102 (message "Checking %d files in %s..." (length curr-files) dir))
109 103
110 (setq files-seen-this-dir nil) 104 (setq files-seen-this-dir nil)
111 105
112 (while curr-files 106 (dolist (file curr-files)
113 107
114 (setq file (car curr-files))
115 (if (string-match "\\.gz$" file) 108 (if (string-match "\\.gz$" file)
116 (setq file (substring file 0 -3))) 109 (setq file (substring file 0 -3)))
117 (setq file (substring 110 (setq file (substring
118 file 0 (if (string= (substring file -1) "c") -4 -3))) 111 file 0 (if (string= (substring file -1) "c") -4 -3)))
119 112
139 (concat base1 ".elc") (concat base2 ".elc")))) 132 (concat base1 ".elc") (concat base2 ".elc"))))
140 (setq shadows 133 (setq shadows
141 (append shadows (list base1 base2))))) 134 (append shadows (list base1 base2)))))
142 135
143 ;; Not seen before, add it to the list of seen files. 136 ;; Not seen before, add it to the list of seen files.
144 (setq files (cons (cons file dir) files)))) 137 (setq files (cons (cons file dir) files)))))))
145
146 (setq curr-files (cdr curr-files))))
147 (setq path (cdr path)))
148
149 ;; Return the list of shadowings. 138 ;; Return the list of shadowings.
150 shadows)) 139 shadows))
151 140
152 ;; Return true if neither file exists, or if both exist and have identical 141 ;; Return true if neither file exists, or if both exist and have identical
153 ;; contents. 142 ;; contents.
208 (interactive) 197 (interactive)
209 (let* ((path (copy-sequence load-path)) 198 (let* ((path (copy-sequence load-path))
210 (tem path) 199 (tem path)
211 toplevs) 200 toplevs)
212 ;; If we can find simple.el in two places, 201 ;; If we can find simple.el in two places,
213 (while tem 202 (dolist (tt tem)
214 (if (or (file-exists-p (expand-file-name "simple.el" (car tem))) 203 (if (or (file-exists-p (expand-file-name "simple.el" tt))
215 (file-exists-p (expand-file-name "simple.el.gz" (car tem)))) 204 (file-exists-p (expand-file-name "simple.el.gz" tt)))
216 (setq toplevs (cons (car tem) toplevs))) 205 (setq toplevs (cons tt toplevs))))
217 (setq tem (cdr tem)))
218 (if (> (length toplevs) 1) 206 (if (> (length toplevs) 1)
219 ;; Cut off our copy of load-path right before 207 ;; Cut off our copy of load-path right before
220 ;; the last directory which has simple.el in it. 208 ;; the last directory which has simple.el in it.
221 ;; This avoids loads of duplications between the source dir 209 ;; This avoids loads of duplications between the source dir
222 ;; and the dir where these files were copied by installation. 210 ;; and the dir where these files were copied by installation.
240 (car (cdr shadows)))) 228 (car (cdr shadows))))
241 (setq shadows (cdr (cdr shadows)))) 229 (setq shadows (cdr (cdr shadows))))
242 (if stringp 230 (if stringp
243 (buffer-string) 231 (buffer-string)
244 (if (called-interactively-p 'interactive) 232 (if (called-interactively-p 'interactive)
245 (save-excursion 233 ;; We are interactive.
246 ;; We are interactive. 234 ;; Create the *Shadows* buffer and display shadowings there.
247 ;; Create the *Shadows* buffer and display shadowings there. 235 (let ((string (buffer-string)))
248 (let ((string (buffer-string)) 236 (with-current-buffer (get-buffer-create "*Shadows*")
249 (output-buffer (get-buffer-create "*Shadows*"))) 237 (display-buffer (current-buffer))
250 (display-buffer output-buffer) 238 (setq buffer-undo-list t
251 (set-buffer output-buffer) 239 buffer-read-only nil)
252 (erase-buffer) 240 (erase-buffer)
253 (insert string) 241 (insert string)
254 (insert msg "\n"))) 242 (insert msg "\n")
243 (setq buffer-read-only t)))
255 ;; We are non-interactive, print shadows via message. 244 ;; We are non-interactive, print shadows via message.
256 (unless (zerop n) 245 (unless (zerop n)
257 (message "This site has duplicate Lisp libraries with the same name. 246 (message "This site has duplicate Lisp libraries with the same name.
258 If a locally-installed Lisp library overrides a library in the Emacs release, 247 If a locally-installed Lisp library overrides a library in the Emacs release,
259 that can cause trouble, and you should probably remove the locally-installed 248 that can cause trouble, and you should probably remove the locally-installed