From f66d9e1f0e6960e9b8faf461203a47303ac3662b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 6 Sep 2022 21:09:51 +0200 Subject: [PATCH] feat(lib): only return dirs if doom-glob SEGMENTS end with / Also, doom-glob will return relative paths if SEGMENTS don't form an absolute path. --- lisp/lib/files.el | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lisp/lib/files.el b/lisp/lib/files.el index 19f6769f4..6e055e41d 100644 --- a/lisp/lib/files.el +++ b/lisp/lib/files.el @@ -54,11 +54,22 @@ inaccurate)." ;;;###autoload (defun doom-glob (&rest segments) - "Construct a path from SEGMENTS and expand glob patterns. -Returns nil if the path doesn't exist. -Ignores `nil' elements in SEGMENTS." - (let (case-fold-search) - (file-expand-wildcards (apply #'doom-path segments) t))) + "Return file list matching the glob created by joining SEGMENTS. + +The returned file paths will be relative to `default-directory', unless SEGMENTS +concatenate into an absolute path. + +Returns nil if no matches exist. +Ignores `nil' elements in SEGMENTS. +If the glob ends in a slash, only returns matching directories." + (declare (side-effect-free t)) + (let* (case-fold-search + file-name-handler-alist + (path (apply #'file-name-concat segments)) + (full? (file-name-absolute-p path))) + (if (string-suffix-p "/" path) + (cl-delete-if-not #'file-directory-p (file-expand-wildcards (substring path 0 -1) full?)) + (file-expand-wildcards path full?)))) ;;;###autoload (defun doom-dir (&rest segments)