annotate lisp/emacs-lisp/shadow.el @ 43091:f18f05d77411

(calculator-displayers): Doc fixes.
author Pavel Janík <Pavel@Janik.cz>
date Sun, 03 Feb 2002 13:43:37 +0000
parents b174db545cfd
children 621fbfd0bf87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 22170
diff changeset
1 ;;; shadow.el --- locate Emacs Lisp file shadowings
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5 ;; Author: Terry Jones <terry@santafe.edu>
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Keywords: lisp
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7 ;; Created: 15 December 1995
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; any later version.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14058
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14058
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14058
diff changeset
24 ;; Boston, MA 02111-1307, USA.
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14058
diff changeset
27
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;; The functions in this file detect (`find-emacs-lisp-shadows')
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29 ;; and display (`list-load-path-shadows') potential load-path
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;; problems that arise when Emacs Lisp files "shadow" each other.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;;
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;; For example, a file XXX.el early in one's load-path will shadow
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;; a file with the same name in a later load-path directory. When
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;; this is unintentional, it may result in problems that could have
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; been easily avoided. This occurs often (to me) when installing a
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; new version of emacs and something in the site-lisp directory
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;; has been updated and added to the emacs distribution. The old
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;; version, now outdated, shadows the new one. This is obviously
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;; undesirable.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 ;;
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;; The `list-load-path-shadows' function was run when you installed
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;; this version of emacs. To run it by hand in emacs:
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 ;;
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;; M-x load-library RET shadow RET
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;; M-x list-load-path-shadows
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;;
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47 ;; or run it non-interactively via:
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 ;;
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 ;; emacs -batch -l shadow.el -f list-load-path-shadows
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 ;;
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 ;; Thanks to Francesco Potorti` <pot@cnuce.cnr.it> for suggestions,
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 ;; rewritings & speedups.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 ;;; Code:
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55
21365
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
56 (defgroup shadow nil
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
57 "Locate Emacs Lisp file shadowings."
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
58 :prefix "shadows-"
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
59 :group 'lisp)
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
60
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
61 (defcustom shadows-compare-text-p nil
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
62 "*If non-nil, then shadowing files are reported only if their text differs.
21365
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
63 This is slower, but filters out some innocuous shadowing."
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
64 :type 'boolean
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 19982
diff changeset
65 :group 'shadow)
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
66
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 (defun find-emacs-lisp-shadows (&optional path)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 "Return a list of Emacs Lisp files that create shadows.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 This function does the work for `list-load-path-shadows'.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 We traverse PATH looking for shadows, and return a \(possibly empty\)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 even-length list of files. A file in this list at position 2i shadows
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 the file in position 2i+1. Emacs Lisp file suffixes \(.el and .elc\)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 are stripped from the file names in the list.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 See the documentation for `list-load-path-shadows' for further information."
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 (or path (setq path load-path))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 (let (true-names ; List of dirs considered.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 shadows ; List of shadowings, to be returned.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 files ; File names ever seen, with dirs.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 dir ; The dir being currently scanned.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 curr-files ; This dir's Emacs Lisp files.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 orig-dir ; Where the file was first seen.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 files-seen-this-dir ; Files seen so far in this dir.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 file) ; The current file.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (while path
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
92 (setq dir (directory-file-name (file-truename (or (car path) "."))))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 (if (member dir true-names)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 ;; We have already considered this PATH redundant directory.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95 ;; Show the redundancy if we are interactiver, unless the PATH
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 ;; dir is nil or "." (these redundant directories are just a
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 ;; result of the current working directory, and are therefore
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 ;; not always redundant).
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 (or noninteractive
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100 (and (car path)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 (not (string= (car path) "."))
15736
73a325c414a5 (list-load-path-shadows): Fix ambiguous wording.
Karl Heuer <kwzh@gnu.org>
parents: 14348
diff changeset
102 (message "Ignoring redundant directory %s" (car path))))
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
103
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 (setq true-names (append true-names (list dir)))
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
105 (setq dir (directory-file-name (or (car path) ".")))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 (setq curr-files (if (file-accessible-directory-p dir)
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
107 (directory-files dir nil ".\\.elc?$" t)))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 (and curr-files
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 (not noninteractive)
15736
73a325c414a5 (list-load-path-shadows): Fix ambiguous wording.
Karl Heuer <kwzh@gnu.org>
parents: 14348
diff changeset
110 (message "Checking %d files in %s..." (length curr-files) dir))
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
111
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 (setq files-seen-this-dir nil)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 (while curr-files
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 (setq file (car curr-files))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 (setq file (substring
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 file 0 (if (string= (substring file -1) "c") -4 -3)))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119
19226
c160218de690 (find-emacs-lisp-shadows): Don't mention `subdirs.el'.
Richard M. Stallman <rms@gnu.org>
parents: 15756
diff changeset
120 ;; FILE now contains the current file name, with no suffix.
c160218de690 (find-emacs-lisp-shadows): Don't mention `subdirs.el'.
Richard M. Stallman <rms@gnu.org>
parents: 15756
diff changeset
121 (unless (or (member file files-seen-this-dir)
c160218de690 (find-emacs-lisp-shadows): Don't mention `subdirs.el'.
Richard M. Stallman <rms@gnu.org>
parents: 15756
diff changeset
122 ;; Ignore these files.
c160218de690 (find-emacs-lisp-shadows): Don't mention `subdirs.el'.
Richard M. Stallman <rms@gnu.org>
parents: 15756
diff changeset
123 (member file '("subdirs")))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 ;; File has not been seen yet in this directory.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 ;; This test prevents us declaring that XXX.el shadows
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 ;; XXX.elc (or vice-versa) when they are in the same directory.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 (setq files-seen-this-dir (cons file files-seen-this-dir))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 (if (setq orig-dir (assoc file files))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 ;; This file was seen before, we have a shadowing.
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
131 ;; Report it unless the files are identical.
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
132 (let ((base1 (concat (cdr orig-dir) "/" file))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
133 (base2 (concat dir "/" file)))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
134 (if (not (and shadows-compare-text-p
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
135 (shadow-same-file-or-nonexistent
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
136 (concat base1 ".el") (concat base2 ".el"))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
137 ;; This is a bit strict, but safe.
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
138 (shadow-same-file-or-nonexistent
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
139 (concat base1 ".elc") (concat base2 ".elc"))))
22170
01df0098b07f Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 21927
diff changeset
140 (setq shadows
01df0098b07f Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 21927
diff changeset
141 (append shadows (list base1 base2)))))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 ;; Not seen before, add it to the list of seen files.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (setq files (cons (cons file dir) files))))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (setq curr-files (cdr curr-files))))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 (setq path (cdr path)))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 ;; Return the list of shadowings.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 shadows))
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151
19982
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
152 ;; Return true if neither file exists, or if both exist and have identical
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
153 ;; contents.
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
154 (defun shadow-same-file-or-nonexistent (f1 f2)
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
155 (let ((exists1 (file-exists-p f1))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
156 (exists2 (file-exists-p f2)))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
157 (or (and (not exists1) (not exists2))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
158 (and exists1 exists2
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
159 (or (equal (file-truename f1) (file-truename f2))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
160 ;; As a quick test, avoiding spawning a process, compare file
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
161 ;; sizes.
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
162 (and (= (nth 7 (file-attributes f1))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
163 (nth 7 (file-attributes f2)))
199256234202 (shadows-compare-text-p): Add.
Karl Heuer <kwzh@gnu.org>
parents: 19313
diff changeset
164 (zerop (call-process "cmp" nil nil nil "-s" f1 f2))))))))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 ;;;###autoload
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 (defun list-load-path-shadows ()
15756
30e9db641e6f (list-load-path-shadows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 15736
diff changeset
168 "Display a list of Emacs Lisp files that shadow other files.
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 This function lists potential load-path problems. Directories in the
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 `load-path' variable are searched, in order, for Emacs Lisp
15756
30e9db641e6f (list-load-path-shadows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 15736
diff changeset
172 files. When a previously encountered file name is found again, a
30e9db641e6f (list-load-path-shadows): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 15736
diff changeset
173 message is displayed indicating that the later file is \"hidden\" by
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 the earlier.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 For example, suppose `load-path' is set to
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 \(\"/usr/gnu/emacs/site-lisp\" \"/usr/gnu/emacs/share/emacs/19.30/lisp\"\)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 and that each of these directories contains a file called XXX.el. Then
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 XXX.el in the site-lisp directory is referred to by all of:
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 \(require 'XXX\), \(autoload .... \"XXX\"\), \(load-library \"XXX\"\) etc.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 The first XXX.el file prevents emacs from seeing the second \(unless
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 the second is loaded explicitly via load-file\).
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 When not intended, such shadowings can be the source of subtle
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 problems. For example, the above situation may have arisen because the
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 XXX package was not distributed with versions of emacs prior to
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 19.30. An emacs maintainer downloaded XXX from elsewhere and installed
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 it. Later, XXX was updated and included in the emacs distribution.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 Unless the emacs maintainer checks for this, the new version of XXX
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 will be hidden behind the old \(which may no longer work with the new
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 emacs version\).
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 This function performs these checks and flags all possible
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 shadowings. Because a .el file may exist without a corresponding .elc
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 \(or vice-versa\), these suffixes are essentially ignored. A file
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 XXX.elc in an early directory \(that does not contain XXX.el\) is
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 considered to shadow a later file XXX.el, and vice-versa.
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 When run interactively, the shadowings \(if any\) are displayed in a
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 buffer called `*Shadows*'. Shadowings are located by calling the
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 \(non-interactive\) companion function, `find-emacs-lisp-shadows'."
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 (interactive)
19313
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
207 (let* ((path (copy-sequence load-path))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
208 (tem path)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
209 toplevs)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
210 ;; If we can find simple.el in two places,
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
211 (while tem
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
212 (if (file-exists-p (expand-file-name "simple.el" (car tem)))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
213 (setq toplevs (cons (car tem) toplevs)))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
214 (setq tem (cdr tem)))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
215 (if (> (length toplevs) 1)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
216 ;; Cut off our copy of load-path right before
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
217 ;; the second directory which has simple.el in it.
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
218 ;; This avoids loads of duplications between the source dir
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
219 ;; and the dir where these files were copied by installation.
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
220 (let ((break (nth (- (length toplevs) 2) toplevs)))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
221 (setq tem path)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
222 (while tem
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
223 (if (eq (nth 1 tem) break)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
224 (progn
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
225 (setcdr tem nil)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
226 (setq tem nil)))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
227 (setq tem (cdr tem)))))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
228
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
229 (let* ((shadows (find-emacs-lisp-shadows path))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
230 (n (/ (length shadows) 2))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
231 (msg (format "%s Emacs Lisp load-path shadowing%s found"
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
232 (if (zerop n) "No" (concat "\n" (number-to-string n)))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
233 (if (= n 1) " was" "s were"))))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
234 (if (interactive-p)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
235 (save-excursion
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
236 ;; We are interactive.
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
237 ;; Create the *Shadows* buffer and display shadowings there.
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
238 (let ((output-buffer (get-buffer-create "*Shadows*")))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
239 (display-buffer output-buffer)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
240 (set-buffer output-buffer)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
241 (erase-buffer)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
242 (while shadows
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
243 (insert (format "%s hides %s\n" (car shadows)
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
244 (car (cdr shadows))))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
245 (setq shadows (cdr (cdr shadows))))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
246 (insert msg "\n")))
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
247 ;; We are non-interactive, print shadows via message.
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
248 (when shadows
04175c55c49b (list-load-path-shadows): Exclude, from the path we search, all but
Richard M. Stallman <rms@gnu.org>
parents: 19226
diff changeset
249 (message "This site has duplicate Lisp libraries with the same name.
19226
c160218de690 (find-emacs-lisp-shadows): Don't mention `subdirs.el'.
Richard M. Stallman <rms@gnu.org>
parents: 15756
diff changeset
250 If a locally-installed Lisp library overrides a library in the Emacs release,
c160218de690 (find-emacs-lisp-shadows): Don't mention `subdirs.el'.
Richard M. Stallman <rms@gnu.org>
parents: 15756
diff changeset
251 that can cause trouble, and you should probably remove the locally-installed
21927
8332fee2c358 (list-load-path-shadows): Don't say
Richard M. Stallman <rms@gnu.org>
parents: 21365
diff changeset
252 version unless you know what you are doing.\n")
8332fee2c358 (list-load-path-shadows): Don't say
Richard M. Stallman <rms@gnu.org>
parents: 21365
diff changeset
253 (while shadows
8332fee2c358 (list-load-path-shadows): Don't say
Richard M. Stallman <rms@gnu.org>
parents: 21365
diff changeset
254 (message "%s hides %s" (car shadows) (car (cdr shadows)))
8332fee2c358 (list-load-path-shadows): Don't say
Richard M. Stallman <rms@gnu.org>
parents: 21365
diff changeset
255 (setq shadows (cdr (cdr shadows))))
8332fee2c358 (list-load-path-shadows): Don't say
Richard M. Stallman <rms@gnu.org>
parents: 21365
diff changeset
256 (message "%s" msg))))))
14058
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 (provide 'shadow)
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259
be8c739308f7 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 ;;; shadow.el ends here