[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
file-expand-wildcards should use `save-match-data'
From: |
Michael Ernst |
Subject: |
file-expand-wildcards should use `save-match-data' |
Date: |
Mon, 25 Mar 2002 17:27:33 -0500 |
In Emacs 21.2, file-expand-wildcards can cause problems in code that calls
it, because it changes the match-data. This patch corrects the problem.
ChangeLog entry:
2002-03-25 Michael Ernst <mernst@alum.mit.edu>
* files.el (file-expand-wildcards): Use `save-match-data'.
*** /usr/local/share/emacs/21.2/lisp/files.el Mon Jan 28 11:49:53 2002
--- - Mon Mar 25 17:24:13 2002
***************
*** 3417,3451 ****
The file names returned are normally also relative to the current
default directory. However, if FULL is non-nil, they are absolute."
! (let* ((nondir (file-name-nondirectory pattern))
! (dirpart (file-name-directory pattern))
! ;; A list of all dirs that DIRPART specifies.
! ;; This can be more than one dir
! ;; if DIRPART contains wildcards.
! (dirs (if (and dirpart (string-match "[[*?]" dirpart))
! (mapcar 'file-name-as-directory
! (file-expand-wildcards (directory-file-name
dirpart)))
! (list dirpart)))
! contents)
! (while dirs
! (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
! (file-directory-p (directory-file-name (car dirs))))
! (let ((this-dir-contents
! ;; Filter out "." and ".."
! (delq nil
! (mapcar #'(lambda (name)
! (unless (string-match "\\`\\.\\.?\\'"
! (file-name-nondirectory
name))
! name))
! (directory-files (or (car dirs) ".") full
! (wildcard-to-regexp nondir))))))
! (setq contents
! (nconc
! (if (and (car dirs) (not full))
! (mapcar (function (lambda (name) (concat (car dirs) name)))
! this-dir-contents)
! this-dir-contents)
! contents))))
! (setq dirs (cdr dirs)))
! contents))
(defun list-directory (dirname &optional verbose)
--- 3417,3452 ----
The file names returned are normally also relative to the current
default directory. However, if FULL is non-nil, they are absolute."
! (save-match-data
! (let* ((nondir (file-name-nondirectory pattern))
! (dirpart (file-name-directory pattern))
! ;; A list of all dirs that DIRPART specifies.
! ;; This can be more than one dir
! ;; if DIRPART contains wildcards.
! (dirs (if (and dirpart (string-match "[[*?]" dirpart))
! (mapcar 'file-name-as-directory
! (file-expand-wildcards (directory-file-name
dirpart)))
! (list dirpart)))
! contents)
! (while dirs
! (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
! (file-directory-p (directory-file-name (car dirs))))
! (let ((this-dir-contents
! ;; Filter out "." and ".."
! (delq nil
! (mapcar #'(lambda (name)
! (unless (string-match "\\`\\.\\.?\\'"
!
(file-name-nondirectory name))
! name))
! (directory-files (or (car dirs) ".") full
! (wildcard-to-regexp nondir))))))
! (setq contents
! (nconc
! (if (and (car dirs) (not full))
! (mapcar (function (lambda (name) (concat (car dirs)
name)))
! this-dir-contents)
! this-dir-contents)
! contents))))
! (setq dirs (cdr dirs)))
! contents)))
(defun list-directory (dirname &optional verbose)
- file-expand-wildcards should use `save-match-data',
Michael Ernst <=