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:
parent
cadc778a03
commit
f66d9e1f0e
1 changed files with 16 additions and 5 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue