diff options
| author | Richard M. Stallman | 1998-12-26 05:14:48 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-12-26 05:14:48 +0000 |
| commit | 4db2a7dec96c66205dabe625f3e940781cdb5b44 (patch) | |
| tree | 2c0162193a6299466e28d2189539a9a04f55a4ae | |
| parent | ab26be45d49626b966dbbea36ee8f5b07fd9c371 (diff) | |
| download | emacs-4db2a7dec96c66205dabe625f3e940781cdb5b44.tar.gz emacs-4db2a7dec96c66205dabe625f3e940781cdb5b44.zip | |
(file-expand-wildcards): Handle wildcards in directory name.
Be careful about whether to return a relative file name,
and if so, relative to what directory.
| -rw-r--r-- | lisp/files.el | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/lisp/files.el b/lisp/files.el index e6f3837c4df..c4e16fae252 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -3064,9 +3064,40 @@ by `sh' are supported." | |||
| 3064 | 3064 | ||
| 3065 | (defun file-expand-wildcards (pattern &optional full) | 3065 | (defun file-expand-wildcards (pattern &optional full) |
| 3066 | "Expand wildcard pattern PATTERN. | 3066 | "Expand wildcard pattern PATTERN. |
| 3067 | This returns a list of file names which match the pattern." | 3067 | This returns a list of file names which match the pattern. |
| 3068 | (directory-files (file-name-directory pattern) full | 3068 | |
| 3069 | (wildcard-to-regexp (file-name-nondirectory pattern)))) | 3069 | If PATTERN is written as an absolute relative file name, |
| 3070 | the values are absolute also. | ||
| 3071 | |||
| 3072 | If PATTERN is written as a relative file name, it is interpreted | ||
| 3073 | relative to the current default directory, `default-directory'. | ||
| 3074 | The file names returned are normally also relative to the current | ||
| 3075 | default directory. However, if FULL is non-nil, they are absolute." | ||
| 3076 | (let* ((nondir (file-name-nondirectory pattern)) | ||
| 3077 | (dirpart (file-name-directory pattern)) | ||
| 3078 | ;; A list of all dirs that DIRPART specifies. | ||
| 3079 | ;; This can be more than one dir | ||
| 3080 | ;; if DIRPART contains wildcards. | ||
| 3081 | (dirs (if (and dirpart (string-match "[[.*+\\^$?]" dirpart)) | ||
| 3082 | (mapcar 'file-name-as-directory | ||
| 3083 | (file-expand-wildcards (directory-file-name dirpart))) | ||
| 3084 | (list dirpart))) | ||
| 3085 | contents) | ||
| 3086 | (while dirs | ||
| 3087 | (when (or (null (car dirs)) ; Possible if DIRPART is not wild. | ||
| 3088 | (file-directory-p (directory-file-name (car dirs)))) | ||
| 3089 | (let ((this-dir-contents | ||
| 3090 | (directory-files (or (car dirs) ".") full | ||
| 3091 | (wildcard-to-regexp nondir)))) | ||
| 3092 | (setq contents | ||
| 3093 | (nconc | ||
| 3094 | (if (and (car dirs) (not full)) | ||
| 3095 | (mapcar (function (lambda (name) (concat (car dirs) name))) | ||
| 3096 | this-dir-contents) | ||
| 3097 | this-dir-contents) | ||
| 3098 | contents)))) | ||
| 3099 | (setq dirs (cdr dirs))) | ||
| 3100 | contents)) | ||
| 3070 | 3101 | ||
| 3071 | (defun list-directory (dirname &optional verbose) | 3102 | (defun list-directory (dirname &optional verbose) |
| 3072 | "Display a list of files in or matching DIRNAME, a la `ls'. | 3103 | "Display a list of files in or matching DIRNAME, a la `ls'. |