1 (defvar file-loadable-regexp
2 (replace-regexp-in-string
5 (suffix-list (get-load-suffixes)))
6 (concat (car suffix-list) "$"
7 (dolist (extension (cdr suffix-list) string)
8 (setq string (concat "\\|" extension "$" string))))))
9 "Regular expression that matches any file name with a file
10 extension returned by `get-load-suffixes'.")
12 (defun file-loadable-p (file)
13 "Return t if FILE is an Emacs lisp file.
14 More precisely, return t if the file name extension matches
15 `file-loadable-regexp'"
16 (string-match file-loadable-regexp file))
18 (defun load-dir (&optional directory recurse)
19 "Load all Emacs Lisp files in DIRECTORY.
21 Load files whose file name satisfies predicate `file-loadable-p'.
22 Non-interactively, DIRECTORY must be specified. If both compiled
23 and uncompiled versions of the same file exist, only load the
24 compiled file. If optional argument RECURSE is non-nil, (or,
25 interactively, with prefix argument) recursively load
28 ;; The idea here is to allow a prefix arg to specify recursion, but
29 ;; also to read from the minibuffer the directory name; yet in
30 ;; non-interactive use to only need the one directory-name argument,
31 ;; as in: (load-dir "~/foo")
32 (let* ((recurse (if recurse recurse (when current-prefix-arg t)))
33 (directory (if (stringp directory) directory
34 (when (called-interactively-p 'any)
36 (concat (if recurse "Recursively l" "L")
37 "oad all Emacs lisp files from directory: ")
38 default-directory default-directory t))))
40 ;; For non-interactive use
41 (when (not (called-interactively-p 'any))
43 (error "Must specify a directory to when called non-interactively")))
44 (unless (file-directory-p directory)
45 (error "%s is not a directory" directory))
47 (directory-files (expand-file-name directory)
48 t directory-files-no-dot-files-regexp)))
49 (dolist (file file-list)
52 ;; This will include gzipped elisp files
53 (file-loadable-p file)
54 ;; Ignore symlinks to nonexistent targets.
56 ;; Don't try to load directies whose names end in ".el"
57 ;; etc., as if they were files. Note that we do not
58 ;; predicate on "permission denied" problems, instead
59 ;; letting things fail in that case so the user knows.
60 (not (file-directory-p file))
61 ;; If there exist both compiled and uncompiled versions of
62 ;; the same library, only load the compiled one. (This is
63 ;; why we let-bind the `file-list'.) This could perhaps be
64 ;; factored out, and currently still double-loads gzipped
66 (not (and (string= (file-name-extension file t) ".el")
68 (concat (file-name-sans-extension file) ".elc")
73 (message "error while loading %s: %s" file err)
74 (setq errors (cons (file-name-nondirectory file) errors)))))
75 ((and (file-directory-p file)
77 (setq errors (nconc (load-dir file t) errors))))))
80 (setq inhibit-startup-screen t)
81 (display-buffer "*Messages*")
82 (message "Errors occured while loading: %s" (mapconcat 'identity errors " "))))