(vc-svn-registered): Catch all errors.
[bpt/emacs.git] / lisp / subr.el
index 2348c1e..26a741f 100644 (file)
@@ -183,18 +183,6 @@ macros."
           (not (car-safe (cdr-safe (cdr-safe (cdr-safe (cdr-safe object)))))))
       (subrp object) (byte-code-function-p object)
       (eq (car-safe object) 'lambda)))
-
-;; This should probably be written in C (i.e., without using `walk-windows').
-(defun get-buffer-window-list (buffer &optional minibuf frame)
-  "Return list of all windows displaying BUFFER, or nil if none.
-BUFFER can be a buffer or a buffer name.
-See `walk-windows' for the meaning of MINIBUF and FRAME."
-  (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
-    (walk-windows (function (lambda (window)
-                             (if (eq (window-buffer window) buffer)
-                                 (setq windows (cons window windows)))))
-                 minibuf frame)
-    windows))
 \f
 ;;;; List functions.
 
@@ -1321,8 +1309,52 @@ definition only or variable definition only.
        (setq files (cdr files)))
       file)))
 
+;;;###autoload
+(defun locate-library (library &optional nosuffix path interactive-call)
+  "Show the precise file name of Emacs library LIBRARY.
+This command searches the directories in `load-path' like `\\[load-library]'
+to find the file that `\\[load-library] RET LIBRARY RET' would load.
+Optional second arg NOSUFFIX non-nil means don't add suffixes `load-suffixes'
+to the specified name LIBRARY.
+
+If the optional third arg PATH is specified, that list of directories
+is used instead of `load-path'.
+
+When called from a program, the file name is normaly returned as a
+string.  When run interactively, the argument INTERACTIVE-CALL is t,
+and the file name is displayed in the echo area."
+  (interactive (list (completing-read "Locate library: "
+                                     'locate-file-completion
+                                     (cons load-path load-suffixes))
+                    nil nil
+                    t))
+  (let ((file (locate-file library
+                          (or path load-path)
+                          (append (unless nosuffix load-suffixes) '("")))))
+    (if interactive-call
+       (if file
+           (message "Library is file %s" (abbreviate-file-name file))
+         (message "No library %s in search path" library)))
+    file))
+
 \f
-;;;; Specifying things to do after certain files are loaded.
+;;;; Specifying things to do later.
+
+(defmacro eval-at-startup (&rest body)
+  "Make arrangements to evaluate BODY when Emacs starts up.
+If this is run after Emacs startup, evaluate BODY immediately.
+Always returns nil.
+
+This works by adding a function to `before-init-hook'.
+That function's doc string says which file created it."
+  `(progn
+     (if command-line-processed
+        (progn . ,body)
+       (add-hook 'before-init-hook
+                '(lambda () ,(concat "From " (or load-file-name "no file"))
+                   . ,body)
+                t))
+     nil))
 
 (defun eval-after-load (file form)
   "Arrange that, if FILE is ever loaded, FORM will be run at that time.
@@ -1346,7 +1378,8 @@ evaluated whenever that feature is `provide'd."
            ;; Make sure `load-history' contains the files dumped with
            ;; Emacs for the case that FILE is one of them.
            ;; (load-symbol-file-load-history)
-           (assoc file load-history))
+           (when (locate-library file)
+             (assoc (locate-library file) load-history)))
          (eval form))))
   form)
 
@@ -1845,43 +1878,6 @@ a system-dependent default device name is used."
       (play-sound-internal sound)
     (error "This Emacs binary lacks sound support")))
 
-(defun make-temp-file (prefix &optional dir-flag suffix)
-  "Create a temporary file.
-The returned file name (created by appending some random characters at the end
-of PREFIX, and expanding against `temporary-file-directory' if necessary),
-is guaranteed to point to a newly created empty file.
-You can then use `write-region' to write new data into the file.
-
-If DIR-FLAG is non-nil, create a new empty directory instead of a file.
-
-If SUFFIX is non-nil, add that at the end of the file name."
-  (let ((umask (default-file-modes))
-       file)
-    (unwind-protect
-       (progn
-         ;; Create temp files with strict access rights.  It's easy to
-         ;; loosen them later, whereas it's impossible to close the
-         ;; time-window of loose permissions otherwise.
-         (set-default-file-modes ?\700)
-         (while (condition-case ()
-                    (progn
-                      (setq file
-                            (make-temp-name
-                             (expand-file-name prefix temporary-file-directory)))
-                      (if suffix
-                          (setq file (concat file suffix)))
-                      (if dir-flag
-                          (make-directory file)
-                        (write-region "" nil file nil 'silent nil 'excl))
-                      nil)
-                  (file-already-exists t))
-           ;; the file was somehow created by someone else between
-           ;; `make-temp-name' and `write-region', let's try again.
-           nil)
-         file)
-      ;; Reset the umask.
-      (set-default-file-modes umask))))
-
 (defun shell-quote-argument (argument)
   "Quote an argument for passing as argument to an inferior shell."
   (if (eq system-type 'ms-dos)