unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* file-expand-wildcards should use `save-match-data'
@ 2002-03-25 22:27 Michael Ernst
  2002-03-26  9:08 ` Juanma Barranquero
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Ernst @ 2002-03-25 22:27 UTC (permalink / raw)


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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-03-28 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-25 22:27 file-expand-wildcards should use `save-match-data' Michael Ernst
2002-03-26  9:08 ` Juanma Barranquero
2002-03-28  4:56   ` Richard Stallman
2002-03-28 14:47     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).