changeset 104021:94f1fe5b7430

(shadows-compare-text-p): Remove leading * from defcustom doc. (list-load-path-shadows): Optionally, just return shadows as a string.
author Glenn Morris <rgm@gnu.org>
date Wed, 22 Jul 2009 02:34:11 +0000
parents 48eee3db3afa
children 27b0fc89d852
files lisp/emacs-lisp/shadow.el
diffstat 1 files changed, 40 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/shadow.el	Tue Jul 21 23:51:46 2009 +0000
+++ b/lisp/emacs-lisp/shadow.el	Wed Jul 22 02:34:11 2009 +0000
@@ -1,7 +1,7 @@
 ;;; shadow.el --- locate Emacs Lisp file shadowings
 
-;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+;;   2009  Free Software Foundation, Inc.
 
 ;; Author: Terry Jones <terry@santafe.edu>
 ;; Keywords: lisp
@@ -40,12 +40,11 @@
 ;; The `list-load-path-shadows' function was run when you installed
 ;; this version of emacs. To run it by hand in emacs:
 ;;
-;;     M-x load-library RET shadow RET
 ;;     M-x list-load-path-shadows
 ;;
 ;; or run it non-interactively via:
 ;;
-;;     emacs -batch -l shadow.el -f list-load-path-shadows
+;;     emacs -batch -f list-load-path-shadows
 ;;
 ;; Thanks to Francesco Potorti` <pot@cnuce.cnr.it> for suggestions,
 ;; rewritings & speedups.
@@ -58,7 +57,7 @@
   :group 'lisp)
 
 (defcustom shadows-compare-text-p nil
-  "*If non-nil, then shadowing files are reported only if their text differs.
+  "If non-nil, then shadowing files are reported only if their text differs.
 This is slower, but filters out some innocuous shadowing."
   :type 'boolean
   :group 'lisp-shadow)
@@ -165,9 +164,13 @@
 		      (eq 0 (call-process "cmp" nil nil nil "-s" f1 f2))))))))
 
 ;;;###autoload
-(defun list-load-path-shadows ()
+(defun list-load-path-shadows (&optional stringp)
   "Display a list of Emacs Lisp files that shadow other files.
 
+If STRINGP is non-nil, returns any shadows as a string.
+Otherwise, if interactive shows any shadows in a `*Shadows*' buffer;
+else prints messages listing any shadows.
+
 This function lists potential load path problems.  Directories in
 the `load-path' variable are searched, in order, for Emacs Lisp
 files.  When a previously encountered file name is found again, a
@@ -200,10 +203,8 @@
 XXX.elc in an early directory \(that does not contain XXX.el\) is
 considered to shadow a later file XXX.el, and vice-versa.
 
-When run interactively, the shadowings \(if any\) are displayed in a
-buffer called `*Shadows*'.  Shadowings are located by calling the
-\(non-interactive\) companion function, `find-emacs-lisp-shadows'."
-
+Shadowings are located by calling the (non-interactive) companion
+function, `find-emacs-lisp-shadows'."
   (interactive)
   (let* ((path (copy-sequence load-path))
 	(tem path)
@@ -233,29 +234,38 @@
 	   (msg (format "%s Emacs Lisp load-path shadowing%s found"
 			(if (zerop n) "No" (concat "\n" (number-to-string n)))
 			(if (= n 1) " was" "s were"))))
-      (if (interactive-p)
-	  (save-excursion
-	    ;; We are interactive.
-	    ;; Create the *Shadows* buffer and display shadowings there.
-	    (let ((output-buffer (get-buffer-create "*Shadows*")))
-	      (display-buffer output-buffer)
-	      (set-buffer output-buffer)
-	      (erase-buffer)
-	      (while shadows
-		(insert (format "%s hides %s\n" (car shadows)
-				(car (cdr shadows))))
-		(setq shadows (cdr (cdr shadows))))
-	      (insert msg "\n")))
-	;; We are non-interactive, print shadows via message.
-	(when shadows
-	  (message "This site has duplicate Lisp libraries with the same name.
+      (with-temp-buffer
+	(while shadows
+	  (insert (format "%s hides %s\n" (car shadows)
+			  (car (cdr shadows))))
+	  (setq shadows (cdr (cdr shadows))))
+	(if stringp
+	    (buffer-string)
+	  (if (interactive-p)
+	      (save-excursion
+		;; We are interactive.
+		;; Create the *Shadows* buffer and display shadowings there.
+		(let ((string (buffer-string))
+		      (output-buffer (get-buffer-create "*Shadows*")))
+		  (display-buffer output-buffer)
+		  (set-buffer output-buffer)
+		  (erase-buffer)
+		  (insert string)
+		  (insert msg "\n")))
+	    ;; 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,
 that can cause trouble, and you should probably remove the locally-installed
 version unless you know what you are doing.\n")
-	  (while shadows
-	    (message "%s hides %s" (car shadows) (car (cdr shadows)))
-	    (setq shadows (cdr (cdr shadows))))
-	  (message "%s" msg))))))
+	      (goto-char (point-min))
+	      ;; Mimic the previous behavior of using lots of messages.
+	      ;; I think one single message would look better...
+	      (while (not (eobp))
+		(message "%s" (buffer-substring (line-beginning-position)
+						(line-end-position)))
+		(forward-line 1))
+	      (message "%s" msg))))))))
 
 (provide 'shadow)