From 7af913fc20192d70fd49311d30887d2217c586e6 Mon Sep 17 00:00:00 2001 From: Tianxiang Xiong Date: Thu, 20 Jul 2017 14:57:00 -0700 Subject: Add `directory-files-recursively` to `cider-compat` `directory-files-recursively` is [introduced in Emacs 25](https://github.com/purcell/package-lint/blob/4e4b34fc4f12ef2f7965fa959c5809aacdb6af63/package-lint.el#L186). --- cider-compat.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'cider-compat.el') 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))))) +(eval-and-compile + + (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 -- cgit v1.2.3