From 11cf3e90c62e197c600a32f9c226294255abd7a5 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Tue, 9 Dec 2014 07:20:53 +0100 Subject: [PATCH] Implement a new function directory-files-recursively * doc/lispref/files.texi (Contents of Directories): Document directory-files-recursively. * etc/NEWS: Mention directory-files-recursively. * lisp/files.el (find-files): New function. --- doc/lispref/ChangeLog | 5 +++++ doc/lispref/files.texi | 8 ++++++++ etc/ChangeLog | 4 ++++ etc/NEWS | 3 +++ lisp/ChangeLog | 2 ++ lisp/files.el | 21 +++++++++++++++++++++ 6 files changed, 43 insertions(+) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index d8215be6b15..e7b5606b681 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,8 @@ +2014-12-09 Lars Magne Ingebrigtsen + + * files.texi (Contents of Directories): Document + directory-files-recursively. + 2014-12-04 Eli Zaretskii * display.texi (Bidirectional Display): Document diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index ac77b94d8f6..92bb718e46a 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -2605,6 +2605,14 @@ 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. +@end defun + @defun directory-files-and-attributes directory &optional full-name match-regexp nosort id-format This is similar to @code{directory-files} in deciding which files to report on and how to report their names. However, instead diff --git a/etc/ChangeLog b/etc/ChangeLog index 309c01fe51f..9ac0d0040c2 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog @@ -1,3 +1,7 @@ +2014-12-09 Lars Magne Ingebrigtsen + + * NEWS: Mention directory-files-recursively. + 2014-12-08 Lars Magne Ingebrigtsen * NEWS: Mention the new eww `S' command. diff --git a/etc/NEWS b/etc/NEWS index 4bca9e9ebc1..58a5836a1c0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -137,6 +137,9 @@ buffers to allow certain parts of the text to be writable. to all the files and subdirectories of a directory, similarly to the C library function `ftw'. +** A new function `directory-files-recursively' returns all matching +files (recursively) under a directory. + * Editing Changes in Emacs 25.1 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cadb2094b5f..9c044c3a3b6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,7 @@ 2014-12-09 Lars Magne Ingebrigtsen + * files.el (find-files): New function. + * net/shr.el (shr-dom-print): Don't print comments. (shr-tag-svg): Give inline SVG images the right type. diff --git a/lisp/files.el b/lisp/files.el index 0f54a22d61e..5127519732d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -762,6 +762,27 @@ prevented. Directory entries are sorted with string-lessp." (file-name-nondirectory dir) args)))) +(defun directory-files-recursively (dir match &optional include-directories) + "Return all files under DIR that have file names matching MATCH (a regexp). +This function works recursively. Files are returned in \"depth first\" +and alphabetical order. +If INCLUDE-DIRECTORIES, also include directories that have matching names." + (let ((result nil) + (files nil)) + (dolist (file (directory-files dir t)) + (let ((leaf (file-name-nondirectory file))) + (unless (member leaf '("." "..")) + (if (file-directory-p file) + (progn + (when (and include-directories + (string-match match leaf)) + (push file files)) + (setq result (nconc result (directory-files-recursively + file match include-directories)))) + (when (string-match match leaf) + (push file files)))))) + (nconc result (nreverse files)))) + (defun load-file (file) "Load the Lisp file named FILE." ;; This is a case where .elc makes a lot of sense. -- 2.39.2