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.
This commit is contained in:
Henrik Lissner 2022-09-06 21:09:51 +02:00
parent cadc778a03
commit f66d9e1f0e
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -54,11 +54,22 @@ inaccurate)."
;;;###autoload ;;;###autoload
(defun doom-glob (&rest segments) (defun doom-glob (&rest segments)
"Construct a path from SEGMENTS and expand glob patterns. "Return file list matching the glob created by joining SEGMENTS.
Returns nil if the path doesn't exist.
Ignores `nil' elements in SEGMENTS." The returned file paths will be relative to `default-directory', unless SEGMENTS
(let (case-fold-search) concatenate into an absolute path.
(file-expand-wildcards (apply #'doom-path segments) t)))
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 ;;;###autoload
(defun doom-dir (&rest segments) (defun doom-dir (&rest segments)