+2014-12-03 Eric S. Raymond <esr@snark.thyrsus.com>
+
+ * files.el (file-tree-walk): Lisp translation of ANSI ftw(3).
+
2014-12-02 Glenn Morris <rgm@gnu.org>
* whitespace.el (whitespace-big-indent-regexp): Add :version.
(lambda (f) (and (file-directory-p f) 'dir-ok)))
(error "No such directory found via CDPATH environment variable"))))
+(defun file-tree-walk (dir action &rest args)
+ "Walk DIR executing ACTION. Each call gets as arguments DIR, a file path,
+and optional ARGS. The ACTION is applied to each subdirectory
+before descending into it, and if nil is returned at that point
+the descent will be prevented. Directory entries are sorted with
+string-lessp"
+ (cond ((file-directory-p dir)
+ (or (char-equal ?/ (aref dir (1- (length dir))))
+ (setq dir (file-name-as-directory dir)))
+ (let ((lst (directory-files dir nil nil t))
+ fullname file)
+ (while lst
+ (setq file (car lst))
+ (setq lst (cdr lst))
+ (cond ((member file '("." "..")))
+ (t
+ (and (apply action dir file args)
+ (setq fullname (concat dir file))
+ (file-directory-p fullname)
+ (apply 'file-tree-walk fullname action args)))))))
+ (t
+ (apply action
+ (file-name-directory dir)
+ (file-name-nondirectory dir)
+ args))))
+
(defun load-file (file)
"Load the Lisp file named FILE."
;; This is a case where .elc makes a lot of sense.