From 399591b951c089f0356b3d6f85b1d0a3ed1f88cf Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 12 Jun 2018 16:01:11 +0200 Subject: [PATCH] Add :mindepth property to doom-files-in + don't error out if directory doesn't exist. + :depth now starts from 0, instead of 1 --- core/core-dispatcher.el | 6 ++--- core/core-lib.el | 60 ++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/core/core-dispatcher.el b/core/core-dispatcher.el index 5b03ccdbf..a26baa996 100644 --- a/core/core-dispatcher.el +++ b/core/core-dispatcher.el @@ -673,10 +673,10 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files." module. This does not include your byte-compiled, third party packages.'" (interactive) (cl-loop with default-directory = doom-emacs-dir - for path in (append (doom-files-in doom-emacs-dir :match "\\.elc$" :depth 1) - (doom-files-in doom-private-dir :match "\\.elc$" :depth 2) + for path in (append (doom-files-in doom-emacs-dir :match "\\.elc$" :depth 0) + (doom-files-in doom-private-dir :match "\\.elc$" :depth 1) (doom-files-in doom-core-dir :match "\\.elc$") - (doom-files-in doom-modules-dirs :match "\\.elc$" :depth 4)) + (doom-files-in doom-modules-dirs :match "\\.elc$" :depth 3)) for truepath = (file-truename path) if (file-exists-p path) do (delete-file path) diff --git a/core/core-lib.el b/core/core-lib.el index 5b078c988..e22918f22 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -123,6 +123,7 @@ This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'." (type 'files) (relative-to (unless full default-directory)) (depth 99999) + (mindepth 0) (match "^[^.]")) "Returns a list of files/directories in PATH-OR-PATHS (one string path or a list of them). @@ -151,33 +152,38 @@ MATCH is a string regexp. Only entries that match it will be included." nconc (apply #'doom-files-in path (plist-put rest :relative-to relative-to)))) ((let ((path path-or-paths) result) - (dolist (file (directory-files path nil "." nosort)) - (unless (member file '("." "..")) - (let ((fullpath (expand-file-name file path))) - (cond ((file-directory-p fullpath) - (when (and (memq type '(t dirs)) - (string-match-p match file) - (not (and filter (funcall filter fullpath))) - (not (and (file-symlink-p fullpath) - (not follow-symlinks)))) - (setq result - (nconc result - (list (cond (map (funcall map fullpath)) - (relative-to (file-relative-name fullpath relative-to)) - (fullpath)))))) - (unless (<= depth 1) - (setq result - (nconc result (apply #'doom-files-in fullpath - (append `(:depth ,(1- depth) :relative-to ,relative-to) - rest)))))) - ((and (memq type '(t files)) - (string-match-p match file) - (not (and filter (funcall filter fullpath)))) - (push (if relative-to - (file-relative-name fullpath relative-to) - fullpath) - result)))))) - result)))) + (when (file-directory-p path) + (dolist (file (directory-files path nil "." nosort)) + (unless (member file '("." "..")) + (let ((fullpath (expand-file-name file path))) + (cond ((file-directory-p fullpath) + (when (and (memq type '(t dirs)) + (string-match-p match file) + (not (and filter (funcall filter fullpath))) + (not (and (file-symlink-p fullpath) + (not follow-symlinks))) + (<= mindepth 0)) + (setq result + (nconc result + (list (cond (map (funcall map fullpath)) + (relative-to (file-relative-name fullpath relative-to)) + (fullpath)))))) + (unless (< depth 1) + (setq result + (nconc result (apply #'doom-files-in fullpath + (append `(:mindepth ,(1- mindepth) + :depth ,(1- depth) + :relative-to ,relative-to) + rest)))))) + ((and (memq type '(t files)) + (string-match-p match file) + (not (and filter (funcall filter fullpath))) + (<= mindepth 0)) + (push (if relative-to + (file-relative-name fullpath relative-to) + fullpath) + result)))))) + result))))) (defun doom*shut-up (orig-fn &rest args) "Generic advisor for silencing noisy functions."