summaryrefslogtreecommitdiff
path: root/lisp/files.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-06-05 14:08:31 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-06-05 14:08:31 +0200
commitd8924e179e2e53bf9abffa987f428890b4edcf57 (patch)
treea4317056abf76174197702532980f8aa2cc87148 /lisp/files.el
parent6011d39b6a4bc659da364255bcae22c4e6ef3a3f (diff)
downloademacs-d8924e179e2e53bf9abffa987f428890b4edcf57.tar.gz
emacs-d8924e179e2e53bf9abffa987f428890b4edcf57.tar.bz2
emacs-d8924e179e2e53bf9abffa987f428890b4edcf57.zip
Extend file-expand-wildcards to allow regexps
* doc/lispref/files.texi (Contents of Directories): Document it. * lisp/files.el (file-expand-wildcards): Extend to allow regexps. * lisp/emacs-lisp/shortdoc.el (file): Expand the file-expand-wildcards example.
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el23
1 files changed, 17 insertions, 6 deletions
diff --git a/lisp/files.el b/lisp/files.el
index b5da0ea5c52..95f5b2c5358 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7198,13 +7198,21 @@ by `sh' are supported."
:type 'string
:group 'dired)
-(defun file-expand-wildcards (pattern &optional full)
+(defun file-expand-wildcards (pattern &optional full regexp)
"Expand wildcard pattern PATTERN.
This returns a list of file names that match the pattern.
-Files are sorted in `string<' order.
-If PATTERN is written as an absolute file name,
-the values are absolute also.
+PATTERN is, by default, a \"glob\"/wildcard string, e.g.,
+\"/tmp/*.png\" or \"/*/*/foo.png\", but can also be a regular
+expression if the optional REGEXP parameter is non-nil. In any
+case, the matches are applied per sub-directory, so a match can't
+span a parent/sub directory, which means that a regexp bit can't
+contain the \"/\" character.
+
+The list of files returned are sorted in `string<' order.
+
+If PATTERN is written as an absolute file name, the values are
+absolute also.
If PATTERN is written as a relative file name, it is interpreted
relative to the current default directory, `default-directory'.
@@ -7219,7 +7227,8 @@ default directory. However, if FULL is non-nil, they are absolute."
(dirs (if (and dirpart
(string-match "[[*?]" (file-local-name dirpart)))
(mapcar 'file-name-as-directory
- (file-expand-wildcards (directory-file-name dirpart)))
+ (file-expand-wildcards
+ (directory-file-name dirpart) nil regexp))
(list dirpart)))
contents)
(dolist (dir dirs)
@@ -7233,7 +7242,9 @@ default directory. However, if FULL is non-nil, they are absolute."
(file-name-nondirectory name))
name))
(directory-files (or dir ".") full
- (wildcard-to-regexp nondir))))))
+ (if regexp
+ nondir
+ (wildcard-to-regexp nondir)))))))
(setq contents
(nconc
(if (and dir (not full))