Mercurial > hg > xemacs-beta
annotate lisp/shadow.el @ 5554:a42e686a01bf
Automated merge with file:///Sources/xemacs-21.5-checked-out
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 24 Aug 2011 11:07:26 +0100 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
428 | 1 ;;; shadow.el --- Locate Emacs Lisp file shadowings. |
2 | |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Terry Jones <terry@santafe.edu> | |
6 ;; Keywords: lisp | |
7 ;; Created: 15 December 1995 | |
8 | |
9 ;; This file is part of XEmacs. | |
10 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
14 ;; option) any later version. |
428 | 15 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
19 ;; for more details. |
428 | 20 |
21 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2562
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;; The functions in this file detect (`find-emacs-lisp-shadows') | |
27 ;; and display (`list-load-path-shadows') potential load-path | |
28 ;; problems that arise when Emacs Lisp files "shadow" each other. | |
29 ;; | |
30 ;; For example, a file XXX.el early in one's load-path will shadow | |
31 ;; a file with the same name in a later load-path directory. When | |
32 ;; this is unintentional, it may result in problems that could have | |
33 ;; been easily avoided. This occurs often (to me) when installing a | |
34 ;; new version of emacs and something in the site-lisp directory | |
35 ;; has been updated and added to the emacs distribution. The old | |
36 ;; version, now outdated, shadows the new one. This is obviously | |
37 ;; undesirable. | |
38 ;; | |
39 ;; The `list-load-path-shadows' function was run when you installed | |
40 ;; this version of emacs. To run it by hand in emacs: | |
41 ;; | |
42 ;; M-x load-library RET shadow RET | |
43 ;; M-x list-load-path-shadows | |
44 ;; | |
45 ;; or run it non-interactively via: | |
46 ;; | |
47 ;; emacs -batch -l shadow.el -f list-load-path-shadows | |
48 ;; | |
49 ;; Thanks to Francesco Potorti` <pot@cnuce.cnr.it> for suggestions, | |
50 ;; rewritings & speedups. | |
51 | |
52 ;; 1998-08-15 Martin Buchholz: Speed up using hash tables instead of lists. | |
53 | |
54 ;;; Code: | |
55 | |
56 (defun find-emacs-lisp-shadows (&optional path) | |
57 "Return a list of Emacs Lisp files that create shadows. | |
58 This function does the work for `list-load-path-shadows'. | |
59 | |
60 We traverse PATH looking for shadows, and return a \(possibly empty\) | |
61 even-length list of files. A file in this list at position 2i shadows | |
62 the file in position 2i+1. Emacs Lisp file suffixes \(.el and .elc\) | |
63 are stripped from the file names in the list. | |
64 | |
65 See the documentation for `list-load-path-shadows' for further information." | |
66 | |
67 (let (shadows ; List of shadowings, to be returned. | |
68 dir ; The dir being currently scanned. | |
69 curr-files ; This dir's Emacs Lisp files. | |
70 orig-dir ; Where the file was first seen. | |
71 (file-dirs ; File names ever seen, with dirs. | |
72 (make-hash-table :size 2000 :test 'equal)) | |
73 (true-names ; Dirs ever considered. | |
74 (make-hash-table :size 50 :test 'equal)) | |
75 (files-seen-this-dir ; Files seen so far in this dir. | |
76 (make-hash-table :size 100 :test 'equal)) | |
77 ) | |
78 | |
79 (dolist (path-elt (or path load-path)) | |
80 | |
81 (setq dir (file-truename (or path-elt "."))) | |
82 (if (gethash dir true-names) | |
83 ;; We have already considered this PATH redundant directory. | |
84 ;; Show the redundancy if we are interactive, unless the PATH | |
85 ;; dir is nil or "." (these redundant directories are just a | |
86 ;; result of the current working directory, and are therefore | |
87 ;; not always redundant). | |
88 (or noninteractive | |
89 (and path-elt | |
90 (not (string= path-elt ".")) | |
91 (message "Ignoring redundant directory %s" path-elt))) | |
92 | |
93 (puthash dir t true-names) | |
94 (setq dir (or path-elt ".")) | |
95 (setq curr-files (if (file-accessible-directory-p dir) | |
96 (directory-files dir nil ".\\.elc?$" t))) | |
97 (and curr-files | |
98 (not noninteractive) | |
99 (message "Checking %d files in %s..." (length curr-files) dir)) | |
100 | |
101 (clrhash files-seen-this-dir) | |
102 | |
103 (dolist (file curr-files) | |
104 | |
105 (setq file (substring | |
106 file 0 (if (string= (substring file -1) "c") -4 -3))) | |
107 | |
108 ;; FILE now contains the current file name, with no suffix. | |
109 (unless (or (gethash file files-seen-this-dir) | |
110 ;; Ignore these files. | |
111 (member file | |
112 '("subdirs" | |
113 "auto-autoloads" | |
114 "custom-load" | |
2562 | 115 "custom-defines" |
428 | 116 "dumped-lisp" |
117 "_pkg" | |
118 "lpath"))) | |
119 ;; File has not been seen yet in this directory. | |
120 ;; This test prevents us declaring that XXX.el shadows | |
121 ;; XXX.elc (or vice-versa) when they are in the same directory. | |
122 (puthash file t files-seen-this-dir) | |
123 | |
124 (if (setq orig-dir (gethash file file-dirs)) | |
125 ;; This file was seen before, we have a shadowing. | |
126 (setq shadows | |
127 (nconc shadows | |
128 (list (concat (file-name-as-directory orig-dir) | |
129 file) | |
130 (concat (file-name-as-directory dir) | |
131 file)))) | |
132 | |
133 ;; Not seen before, add it to the list of seen files. | |
134 (puthash file dir file-dirs)))))) | |
135 | |
136 ;; Return the list of shadowings. | |
137 shadows)) | |
138 | |
139 | |
140 ;;;###autoload | |
141 (defun list-load-path-shadows () | |
142 "Display a list of Emacs Lisp files that shadow other files. | |
143 | |
144 This function lists potential load-path problems. Directories in the | |
145 `load-path' variable are searched, in order, for Emacs Lisp | |
146 files. When a previously encountered file name is found again, a | |
147 message is displayed indicating that the later file is \"hidden\" by | |
148 the earlier. | |
149 | |
150 For example, suppose `load-path' is set to | |
151 | |
152 \(\"/usr/gnu/emacs/site-lisp\" \"/usr/gnu/emacs/share/emacs/19.30/lisp\"\) | |
153 | |
154 and that each of these directories contains a file called XXX.el. Then | |
155 XXX.el in the site-lisp directory is referred to by all of: | |
156 \(require 'XXX\), \(autoload .... \"XXX\"\), \(load-library \"XXX\"\) etc. | |
157 | |
158 The first XXX.el file prevents emacs from seeing the second \(unless | |
159 the second is loaded explicitly via load-file\). | |
160 | |
161 When not intended, such shadowings can be the source of subtle | |
162 problems. For example, the above situation may have arisen because the | |
163 XXX package was not distributed with versions of emacs prior to | |
164 19.30. An emacs maintainer downloaded XXX from elsewhere and installed | |
165 it. Later, XXX was updated and included in the emacs distribution. | |
166 Unless the emacs maintainer checks for this, the new version of XXX | |
167 will be hidden behind the old \(which may no longer work with the new | |
168 emacs version\). | |
169 | |
170 This function performs these checks and flags all possible | |
171 shadowings. Because a .el file may exist without a corresponding .elc | |
172 \(or vice-versa\), these suffixes are essentially ignored. A file | |
173 XXX.elc in an early directory \(that does not contain XXX.el\) is | |
174 considered to shadow a later file XXX.el, and vice-versa. | |
175 | |
176 When run interactively, the shadowings \(if any\) are displayed in a | |
177 buffer called `*Shadows*'. Shadowings are located by calling the | |
178 \(non-interactive\) companion function, `find-emacs-lisp-shadows'." | |
179 | |
180 (interactive) | |
181 (let* ((path (copy-sequence load-path)) | |
182 (tem path) | |
183 toplevs) | |
184 ;; If we can find simple.el in two places, | |
185 (while tem | |
186 (if (file-exists-p (expand-file-name "simple.el" (car tem))) | |
187 (setq toplevs (cons (car tem) toplevs))) | |
188 (setq tem (cdr tem))) | |
189 (if (> (length toplevs) 1) | |
190 ;; Cut off our copy of load-path right before | |
191 ;; the second directory which has simple.el in it. | |
192 ;; This avoids loads of duplications between the source dir | |
193 ;; and the dir where these files were copied by installation. | |
194 (let ((break (nth (- (length toplevs) 2) toplevs))) | |
195 (setq tem path) | |
196 (while tem | |
197 (if (eq (nth 1 tem) break) | |
198 (progn | |
199 (setcdr tem nil) | |
200 (setq tem nil))) | |
201 (setq tem (cdr tem))))) | |
202 | |
203 (let* ((shadows (find-emacs-lisp-shadows path)) | |
204 (n (/ (length shadows) 2)) | |
205 (msg (format "%s Emacs Lisp load-path shadowing%s found" | |
206 (if (zerop n) "No" (concat "\n" (number-to-string n))) | |
207 (if (= n 1) " was" "s were")))) | |
208 (if (interactive-p) | |
209 (save-excursion | |
210 ;; We are interactive. | |
211 ;; Create the *Shadows* buffer and display shadowings there. | |
212 (let ((output-buffer (get-buffer-create "*Shadows*"))) | |
213 (display-buffer output-buffer) | |
214 (set-buffer output-buffer) | |
215 (erase-buffer) | |
216 (while shadows | |
217 (insert (format "%s hides %s\n" (car shadows) | |
218 (car (cdr shadows)))) | |
219 (setq shadows (cdr (cdr shadows)))) | |
220 (insert msg "\n"))) | |
221 ;; We are non-interactive, print shadows via message. | |
222 (when shadows | |
223 (message "This site has duplicate Lisp libraries with the same name. | |
224 If a locally-installed Lisp library overrides a library in the Emacs release, | |
225 that can cause trouble, and you should probably remove the locally-installed | |
226 version unless you know what you are doing.\n") | |
227 (while shadows | |
228 (message "%s hides %s" (car shadows) (car (cdr shadows))) | |
229 (setq shadows (cdr (cdr shadows)))) | |
230 (message "%s" msg)))))) | |
231 | |
232 (provide 'shadow) | |
233 | |
234 ;;; shadow.el ends here |