path: root/cider-compat.el
diff options
authorTianxiang Xiong <>2017-07-20 14:57:00 -0700
committerBozhidar Batsov <>2017-07-23 08:28:21 +0300
commit7af913fc20192d70fd49311d30887d2217c586e6 (patch)
tree3849d98c8eb33646f03cd231f1dc174c9f3b6189 /cider-compat.el
parent9db616d9c1b06b4d55f9f264c7b14a62c63f640e (diff)
Add `directory-files-recursively` to `cider-compat`
`directory-files-recursively` is [introduced in Emacs 25](
Diffstat (limited to 'cider-compat.el')
1 files changed, 34 insertions, 0 deletions
diff --git a/cider-compat.el b/cider-compat.el
index 4f6e9d8a..7387f833 100644
--- a/cider-compat.el
+++ b/cider-compat.el
@@ -153,5 +153,39 @@ to bind a single value, BINDINGS can just be a plain tuple."
(declare (indent 1) (debug if-let))
`(if-let ,bindings ,(macroexp-progn body)))))
+ (with-no-warnings
+ (unless (fboundp 'directory-files-recursively)
+ (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\"
+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
+ ;; also be offered. We shall suppress them.
+ (tramp-mode (and tramp-mode (file-remote-p (expand-file-name dir)))))
+ (dolist (file (sort (file-name-all-completions "" dir)
+ 'string<))
+ (unless (member file '("./" "../"))
+ (if (directory-name-p file)
+ (let* ((leaf (substring file 0 (1- (length file))))
+ (full-file (expand-file-name leaf dir)))
+ ;; Don't follow symlinks to other directories.
+ (unless (file-symlink-p full-file)
+ (setq result
+ (nconc result (directory-files-recursively
+ full-file regexp include-directories))))
+ (when (and include-directories
+ (string-match regexp leaf))
+ (setq result (nconc result (list full-file)))))
+ (when (string-match regexp file)
+ (push (expand-file-name file dir) files)))))
+ (nconc result (nreverse files)))))))
(provide 'cider-compat)
;;; cider-compat.el ends here