]> code.delx.au - gnu-emacs/commitdiff
Document 'directory-files-recursively'
authorEli Zaretskii <eliz@gnu.org>
Tue, 1 Dec 2015 16:16:22 +0000 (18:16 +0200)
committerEli Zaretskii <eliz@gnu.org>
Tue, 1 Dec 2015 16:16:22 +0000 (18:16 +0200)
* lisp/files.el (directory-files-recursively): Doc fix.  Rename
the argument MATCH to REGEXP, to be more explicit about its form.

* doc/lispref/files.texi (Contents of Directories): Improve the
documentation of 'directory-files-recursively'.  Add
cross-references.

* etc/NEWS: Move the entry for 'directory-files-recursively' to
its place and mark it documented.

doc/lispref/files.texi
etc/NEWS
lisp/files.el

index 9a1b2cd217f0895ccd205db2529439ee9ea5ac05..e8ed7ccd9f7fcf1726e08ee30c38dfc0a18aff6c 100644 (file)
@@ -2632,12 +2632,20 @@ An error is signaled if @var{directory} is not the name of a directory
 that can be read.
 @end defun
 
-@defun directory-files-recursively directory match &optional include-directories
-Return all files under @var{directory} whose file names match
-@var{match} recursively.  The file names are returned depth first,
-meaning that contents of sub-directories are returned before contents
-of the directories.  If @var{include-directories} is non-@code{nil},
-also return directory names that have matching names.
+@defun directory-files-recursively directory regexp &optional include-directories
+Return all files under @var{directory} whose names match @var{regexp}.
+This function searches the specified @var{directory} and its
+sub-directories, recursively, for files whose basenames (i.e., without
+the leading directories) match the specified @var{regexp}, and returns
+a list of the absolute file names of the matching files
+(@pxref{Relative File Names, absolute file names}).  The file names
+are returned in depth-first order, meaning that files in some
+sub-directory are returned before the files in its parent directory.
+In addition, matching files found in each subdirectory are sorted
+alphabetically by their basenames.  By default, directories whose
+names match @var{regexp} are omitted from the list, but if the
+optional argument @var{include-directories} is non-@code{nil}, they
+are included.
 @end defun
 
 @defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format
index b9e0bd4ba2434abe1489c01a5d54c915a5ed64ba..bd7435b1760e095c50846fbb2151f754db0be166 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -181,9 +181,6 @@ for use in Emacs bug reports.
 hiding character but the default `.' can be used by let-binding the
 variable `read-hide-char'.
 
-** A new function `directory-files-recursively' returns all matching
-files (recursively) under a directory.
-
 ** The new function `directory-name-p' can be used to check whether a file
 name (as returned from, for instance, `file-name-all-completions' is
 a directory file name.  It returns non-nil if the last character in
@@ -1137,6 +1134,10 @@ of subprocess.
 process filter, sentinel, etc., through keyword arguments (similar to
 `make-network-process').
 
++++
+** A new function `directory-files-recursively' returns all matching
+files (recursively) under a directory.
+
 +++
 ** New variable `inhibit-message', when bound to non-nil, inhibits
 `message' and related functions from displaying messages the Echo
index e892ac6b94bc2cfd5c58d7c095916ca52603270c..f37c23b7bdd5f0665e0b7228840cc40ac2f46b7d 100644 (file)
@@ -744,11 +744,13 @@ The path separator is colon in GNU and GNU-like systems."
   (and (> (length name) 0)
        (char-equal (aref name (1- (length name))) ?/)))
 
-(defun directory-files-recursively (dir match &optional include-directories)
-  "Return all files under DIR that have file names matching MATCH (a regexp).
+(defun directory-files-recursively (dir regexp &optional include-directories)
+  "Return list of all files under DIR that have file names matching REGEXP.
 This function works recursively.  Files are returned in \"depth first\"
-and alphabetical order.
-If INCLUDE-DIRECTORIES, also include directories that have matching names."
+order, and files from each directory are sorted in alphabetical order.
+Each file name appears in the returned list in its absolute form.
+Optional argument INCLUDE-DIRECTORIES non-nil means also include in the
+output directories whose names match REGEXP."
   (let ((result nil)
        (files nil)
        ;; When DIR is "/", remote file names like "/method:" could
@@ -764,11 +766,11 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names."
              (unless (file-symlink-p full-file)
                (setq result
                      (nconc result (directory-files-recursively
-                                    full-file match include-directories))))
+                                    full-file regexp include-directories))))
              (when (and include-directories
-                        (string-match match leaf))
+                        (string-match regexp leaf))
                (setq result (nconc result (list full-file)))))
-         (when (string-match match file)
+         (when (string-match regexp file)
            (push (expand-file-name file dir) files)))))
     (nconc result (nreverse files))))