list-load-path-shadows simplification

* lisp/emacs-lisp/shadow.el (list-load-path-shadows):
No longer necessary to check for duplicate simple.el, since
2012-07-07 change to init_lread to not include installation lisp
directories in load-path when running uninstalled.

Fixes: debbugs:14270
This commit is contained in:
Glenn Morris 2013-04-26 00:25:45 -07:00
parent 070ccca42d
commit e6ea1f6c9b
2 changed files with 60 additions and 75 deletions

View file

@ -1,3 +1,10 @@
2013-04-26 Glenn Morris <rgm@gnu.org>
* emacs-lisp/shadow.el (list-load-path-shadows):
No longer necessary to check for duplicate simple.el, since
2012-07-07 change to init_lread to not include installation lisp
directories in load-path when running uninstalled. (Bug#14270)
2013-04-26 Leo Liu <sdl.web@gmail.com> 2013-04-26 Leo Liu <sdl.web@gmail.com>
* progmodes/octave.el (octave-submit-bug-report): Obsolete. * progmodes/octave.el (octave-submit-bug-report): Obsolete.

View file

@ -207,101 +207,79 @@ the earlier.
For example, suppose `load-path' is set to For example, suppose `load-path' is set to
\(\"/usr/gnu/emacs/site-lisp\" \"/usr/gnu/emacs/share/emacs/19.30/lisp\"\) \(\"/usr/share/emacs/site-lisp\" \"/usr/share/emacs/24.3/lisp\")
and that each of these directories contains a file called XXX.el. Then and that each of these directories contains a file called XXX.el. Then
XXX.el in the site-lisp directory is referred to by all of: XXX.el in the site-lisp directory is referred to by all of:
\(require 'XXX\), \(autoload .... \"XXX\"\), \(load-library \"XXX\"\) etc. \(require 'XXX), (autoload .... \"XXX\"), (load-library \"XXX\") etc.
The first XXX.el file prevents Emacs from seeing the second \(unless The first XXX.el file prevents Emacs from seeing the second (unless
the second is loaded explicitly via `load-file'\). the second is loaded explicitly via `load-file').
When not intended, such shadowings can be the source of subtle When not intended, such shadowings can be the source of subtle
problems. For example, the above situation may have arisen because the problems. For example, the above situation may have arisen because the
XXX package was not distributed with versions of Emacs prior to XXX package was not distributed with versions of Emacs prior to
19.30. An Emacs maintainer downloaded XXX from elsewhere and installed 24.3. A system administrator downloaded XXX from elsewhere and installed
it. Later, XXX was updated and included in the Emacs distribution. it. Later, XXX was updated and included in the Emacs distribution.
Unless the Emacs maintainer checks for this, the new version of XXX Unless the system administrator checks for this, the new version of XXX
will be hidden behind the old \(which may no longer work with the new will be hidden behind the old (which may no longer work with the new
Emacs version\). Emacs version).
This function performs these checks and flags all possible This function performs these checks and flags all possible
shadowings. Because a .el file may exist without a corresponding .elc shadowings. Because a .el file may exist without a corresponding .elc
\(or vice-versa\), these suffixes are essentially ignored. A file \(or vice-versa), these suffixes are essentially ignored. A file
XXX.elc in an early directory \(that does not contain XXX.el\) is XXX.elc in an early directory (that does not contain XXX.el) is
considered to shadow a later file XXX.el, and vice-versa. considered to shadow a later file XXX.el, and vice-versa.
Shadowings are located by calling the (non-interactive) companion Shadowings are located by calling the (non-interactive) companion
function, `load-path-shadows-find'." function, `load-path-shadows-find'."
(interactive) (interactive)
(let* ((path (copy-sequence load-path)) (let* ((shadows (load-path-shadows-find load-path))
(tem path) (n (/ (length shadows) 2))
toplevs) (msg (format "%s Emacs Lisp load-path shadowing%s found"
;; If we can find simple.el in two places, (if (zerop n) "No" (concat "\n" (number-to-string n)))
(dolist (tt tem) (if (= n 1) " was" "s were"))))
(if (or (file-exists-p (expand-file-name "simple.el" tt)) (with-temp-buffer
(file-exists-p (expand-file-name "simple.el.gz" tt))) (while shadows
(setq toplevs (cons tt toplevs)))) (insert (format "%s hides %s\n" (car shadows)
(if (> (length toplevs) 1) (car (cdr shadows))))
;; Cut off our copy of load-path right before (setq shadows (cdr (cdr shadows))))
;; the last directory which has simple.el in it. (if stringp
;; This avoids loads of duplications between the source dir (buffer-string)
;; and the dir where these files were copied by installation. (if (called-interactively-p 'interactive)
(let ((break (car toplevs))) ;; We are interactive.
(setq tem path) ;; Create the *Shadows* buffer and display shadowings there.
(while tem (let ((string (buffer-string)))
(if (eq (nth 1 tem) break) (with-current-buffer (get-buffer-create "*Shadows*")
(progn (display-buffer (current-buffer))
(setcdr tem nil) (load-path-shadows-mode) ; run after-change-major-mode-hook
(setq tem nil))) (let ((inhibit-read-only t))
(setq tem (cdr tem))))) (erase-buffer)
(insert string)
(let* ((shadows (load-path-shadows-find path)) (insert msg "\n")
(n (/ (length shadows) 2)) (while (re-search-backward "\\(^.*\\) hides \\(.*$\\)"
(msg (format "%s Emacs Lisp load-path shadowing%s found" nil t)
(if (zerop n) "No" (concat "\n" (number-to-string n))) (dotimes (i 2)
(if (= n 1) " was" "s were")))) (make-button (match-beginning (1+ i))
(with-temp-buffer (match-end (1+ i))
(while shadows 'type 'load-path-shadows-find-file
(insert (format "%s hides %s\n" (car shadows) 'shadow-file
(car (cdr shadows)))) (match-string (1+ i)))))
(setq shadows (cdr (cdr shadows)))) (goto-char (point-max)))))
(if stringp ;; We are non-interactive, print shadows via message.
(buffer-string) (unless (zerop n)
(if (called-interactively-p 'interactive) (message "This site has duplicate Lisp libraries with the same name.
;; We are interactive.
;; Create the *Shadows* buffer and display shadowings there.
(let ((string (buffer-string)))
(with-current-buffer (get-buffer-create "*Shadows*")
(display-buffer (current-buffer))
(load-path-shadows-mode) ; run after-change-major-mode-hook
(let ((inhibit-read-only t))
(erase-buffer)
(insert string)
(insert msg "\n")
(while (re-search-backward "\\(^.*\\) hides \\(.*$\\)"
nil t)
(dotimes (i 2)
(make-button (match-beginning (1+ i))
(match-end (1+ i))
'type 'load-path-shadows-find-file
'shadow-file
(match-string (1+ i)))))
(goto-char (point-max)))))
;; We are non-interactive, print shadows via message.
(unless (zerop n)
(message "This site has duplicate Lisp libraries with the same name.
If a locally-installed Lisp library overrides a library in the Emacs release, If a locally-installed Lisp library overrides a library in the Emacs release,
that can cause trouble, and you should probably remove the locally-installed that can cause trouble, and you should probably remove the locally-installed
version unless you know what you are doing.\n") version unless you know what you are doing.\n")
(goto-char (point-min)) (goto-char (point-min))
;; Mimic the previous behavior of using lots of messages. ;; Mimic the previous behavior of using lots of messages.
;; I think one single message would look better... ;; I think one single message would look better...
(while (not (eobp)) (while (not (eobp))
(message "%s" (buffer-substring (line-beginning-position) (message "%s" (buffer-substring (line-beginning-position)
(line-end-position))) (line-end-position)))
(forward-line 1)) (forward-line 1))
(message "%s" msg)))))))) (message "%s" msg)))))))
(provide 'shadow) (provide 'shadow)