+(defvar normal-top-level-add-subdirs-inode-list nil)
+
+(defun normal-top-level-add-subdirs-to-load-path ()
+ "Add all subdirectories of current directory to `load-path'.
+More precisely, this uses only the subdirectories whose names
+start with letters or digits; it excludes any subdirectory named `RCS'
+or `CVS', and any subdirectory that contains a file named `.nosearch'."
+ (let (dirs
+ attrs
+ (pending (list default-directory)))
+ ;; This loop does a breadth-first tree walk on DIR's subtree,
+ ;; putting each subdir into DIRS as its contents are examined.
+ (while pending
+ (setq dirs (cons (car pending) dirs))
+ (setq pending (cdr pending))
+ (setq attrs (nthcdr 10 (file-attributes (car dirs))))
+ (let ((contents (directory-files (car dirs)))
+ (default-directory (car dirs)))
+ (unless (member attrs normal-top-level-add-subdirs-inode-list)
+ (setq normal-top-level-add-subdirs-inode-list
+ (cons attrs normal-top-level-add-subdirs-inode-list))
+ (while contents
+ (unless (member (car contents) '("." ".." "RCS" "CVS"))
+ (when (and (string-match "\\`[a-zA-Z0-9]" (car contents))
+ ;; Avoid doing a `stat' when it isn't necessary
+ ;; because that can cause trouble when an NFS server
+ ;; is down.
+ (not (string-match "\\.elc?\\'" (car contents)))
+ (file-directory-p (car contents)))
+ (let ((expanded (expand-file-name (car contents))))
+ (unless (file-exists-p (expand-file-name ".nosearch"
+ expanded))
+ (setq pending (nconc pending (list expanded)))))))
+ (setq contents (cdr contents))))))
+ (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
+
+;; This function is called from a subdirs.el file.
+;; It assumes that default-directory is the directory
+;; in which the subdirs.el file exists,
+;; and it adds to load-path the subdirs of that directory
+;; as specified in DIRS. Normally the elements of DIRS are relative.