Add :mindepth property to doom-files-in

+ don't error out if directory doesn't exist.
+ :depth now starts from 0, instead of 1
This commit is contained in:
Henrik Lissner 2018-06-12 16:01:11 +02:00
parent acbad5ca01
commit 399591b951
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 36 additions and 30 deletions

View file

@ -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.'" module. This does not include your byte-compiled, third party packages.'"
(interactive) (interactive)
(cl-loop with default-directory = doom-emacs-dir (cl-loop with default-directory = doom-emacs-dir
for path in (append (doom-files-in doom-emacs-dir :match "\\.elc$" :depth 1) for path in (append (doom-files-in doom-emacs-dir :match "\\.elc$" :depth 0)
(doom-files-in doom-private-dir :match "\\.elc$" :depth 2) (doom-files-in doom-private-dir :match "\\.elc$" :depth 1)
(doom-files-in doom-core-dir :match "\\.elc$") (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) for truepath = (file-truename path)
if (file-exists-p path) if (file-exists-p path)
do (delete-file path) do (delete-file path)

View file

@ -123,6 +123,7 @@ This is used by `associate!', `file-exists-p!' and `project-file-exists-p!'."
(type 'files) (type 'files)
(relative-to (unless full default-directory)) (relative-to (unless full default-directory))
(depth 99999) (depth 99999)
(mindepth 0)
(match "^[^.]")) (match "^[^.]"))
"Returns a list of files/directories in PATH-OR-PATHS (one string path or a "Returns a list of files/directories in PATH-OR-PATHS (one string path or a
list of them). 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)))) nconc (apply #'doom-files-in path (plist-put rest :relative-to relative-to))))
((let ((path path-or-paths) ((let ((path path-or-paths)
result) result)
(dolist (file (directory-files path nil "." nosort)) (when (file-directory-p path)
(unless (member file '("." "..")) (dolist (file (directory-files path nil "." nosort))
(let ((fullpath (expand-file-name file path))) (unless (member file '("." ".."))
(cond ((file-directory-p fullpath) (let ((fullpath (expand-file-name file path)))
(when (and (memq type '(t dirs)) (cond ((file-directory-p fullpath)
(string-match-p match file) (when (and (memq type '(t dirs))
(not (and filter (funcall filter fullpath))) (string-match-p match file)
(not (and (file-symlink-p fullpath) (not (and filter (funcall filter fullpath)))
(not follow-symlinks)))) (not (and (file-symlink-p fullpath)
(setq result (not follow-symlinks)))
(nconc result (<= mindepth 0))
(list (cond (map (funcall map fullpath)) (setq result
(relative-to (file-relative-name fullpath relative-to)) (nconc result
(fullpath)))))) (list (cond (map (funcall map fullpath))
(unless (<= depth 1) (relative-to (file-relative-name fullpath relative-to))
(setq result (fullpath))))))
(nconc result (apply #'doom-files-in fullpath (unless (< depth 1)
(append `(:depth ,(1- depth) :relative-to ,relative-to) (setq result
rest)))))) (nconc result (apply #'doom-files-in fullpath
((and (memq type '(t files)) (append `(:mindepth ,(1- mindepth)
(string-match-p match file) :depth ,(1- depth)
(not (and filter (funcall filter fullpath)))) :relative-to ,relative-to)
(push (if relative-to rest))))))
(file-relative-name fullpath relative-to) ((and (memq type '(t files))
fullpath) (string-match-p match file)
result)))))) (not (and filter (funcall filter fullpath)))
result)))) (<= mindepth 0))
(push (if relative-to
(file-relative-name fullpath relative-to)
fullpath)
result))))))
result)))))
(defun doom*shut-up (orig-fn &rest args) (defun doom*shut-up (orig-fn &rest args)
"Generic advisor for silencing noisy functions." "Generic advisor for silencing noisy functions."