[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master e820f16: Added file-tree-walk to files.el.
From: |
Eric S. Raymond |
Subject: |
[Emacs-diffs] master e820f16: Added file-tree-walk to files.el. |
Date: |
Wed, 03 Dec 2014 14:28:59 +0000 |
branch: master
commit e820f16c06a5a6be4bc87910b349c7c3c6eca0f4
Author: Eric S. Raymond <address@hidden>
Commit: Eric S. Raymond <address@hidden>
Added file-tree-walk to files.el.
---
lisp/ChangeLog | 4 ++++
lisp/files.el | 26 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 10d4888..b79b918 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2014-12-03 Eric S. Raymond <address@hidden>
+
+ * files.el (file-tree-walk): Lisp translation of ANSI ftw(3).
+
2014-12-02 Glenn Morris <address@hidden>
* whitespace.el (whitespace-big-indent-regexp): Add :version.
diff --git a/lisp/files.el b/lisp/files.el
index c9d1d2d..720a633 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -729,6 +729,32 @@ The path separator is colon in GNU and GNU-like systems."
(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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master e820f16: Added file-tree-walk to files.el.,
Eric S. Raymond <=