home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / gnu / emacs / help / 4016 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.3 KB  |  59 lines

  1. Newsgroups: gnu.emacs.help,gnu.emacs.src
  2. Path: sparky!uunet!stanford.edu!ames!haven.umd.edu!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!math.fu-berlin.de!zrz.tu-berlin.de!mailgzrz.tu-berlin.de!nickel
  3. From: nickel@cs.tu-berlin.de (Juergen Nickelsen)
  4. Subject: Re: M-x which
  5. In-Reply-To: guttman@circe.mitre.org's message of Sat, 5 Sep 1992 18:21:27 GMT
  6. Message-ID: <NICKEL.92Sep6193533@desaster.cs.tu-berlin.de>
  7. Lines: 44
  8. Sender: news@mailgzrz.tu-berlin.de (News Manager)
  9. Nntp-Posting-Host: desaster.cs.tu-berlin.de
  10. Reply-To: nickel@cs.tu-berlin.de
  11. Organization: STONE Project, Technical University of Berlin, Germany
  12. References: <GUTTMAN.92Sep5132127@circe.mitre.org>
  13. Date: Sun, 6 Sep 1992 17:35:35 GMT
  14.  
  15. In article <GUTTMAN.92Sep5132127@circe.mitre.org>
  16. guttman@circe.mitre.org (Joshua D. Guttman) writes:
  17.  
  18. > Does someone have a "M-x which" command?  
  19. > What I mean is a command that will prompt for a string; it then gives as a
  20. > message the pathname of the file that would have been loaded, had "M-x load"
  21. > been given the same string.  You know, it would just emulate the search down
  22. > load-path.
  23.  
  24. Yes. This function returns a list of the locations in load-path where
  25. the file has been found. The file to be loaded is the first of the
  26. list (car found-list).
  27.  
  28. (defun which-load-file (file &optional nosuffix)
  29.   "Determines from where FILE is loaded.
  30. Returned is a list of pathnames or nil if FILE can't be found in
  31. load-path.  If optional second arg NOSUFFIX is non-nil, don't try
  32. adding suffixes .elc or .el to the specified name FILE."
  33.   (interactive "sFile: \nP")
  34.   (let ((found-list nil)
  35.     (files (list (concat file ".elc") (concat file ".el") file))
  36.     (search-list load-path))
  37.     (while search-list
  38.       (let ((file-list files))
  39.     (while file-list
  40.       (let ((actual-path (concat (car search-list)
  41.                      (if (string-match "/$" (car search-list))
  42.                      ""
  43.                        "/")
  44.                      (car file-list))))
  45.         (if (and (file-exists-p actual-path)
  46.              (not (file-directory-p actual-path)))
  47.         (setq found-list (cons actual-path found-list))))
  48.       (setq file-list (cdr file-list))))
  49.       (setq search-list (cdr search-list)))
  50.     (setq found-list (reverse found-list))
  51.     (if (interactive-p)
  52.     (if found-list
  53.         (message "%s" found-list)
  54.       (message "%s not found" file))
  55.       found-list)))
  56. --
  57. Juergen Nickelsen
  58.