changeset 23473:4c242b09e413

(find-file-wildcards): New option. (find-file-noselect): Handle wild cards, if enabled. (file-expand-wildcards): New function.
author Richard M. Stallman <rms@gnu.org>
date Fri, 16 Oct 1998 19:20:55 +0000
parents d75fa19c5fc0
children 242836a572c4
files lisp/files.el
diffstat 1 files changed, 101 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Fri Oct 16 19:15:04 1998 +0000
+++ b/lisp/files.el	Fri Oct 16 19:20:55 1998 +0000
@@ -860,6 +860,13 @@
 		 (setq list (cdr list))))
 	  found))))
 
+(defcustom find-file-wildcards t
+  "*Non-nil means file-visiting commands should handle wildcards.
+For example, if you specify `*.c', that would visit all the files
+whose names match the pattern."
+  :group 'files
+  :type 'boolean)
+
 (defun find-file-noselect (filename &optional nowarn rawfile)
   "Read file FILENAME into a buffer and return the buffer.
 If a buffer exists visiting FILENAME, return that one, but
@@ -876,91 +883,97 @@
 			      (abbreviate-file-name (file-truename filename))
 			    filename))
 	(error "%s is a directory" filename))
-    (let* ((buf (get-file-buffer filename))
-	   (truename (abbreviate-file-name (file-truename filename)))
-	   (number (nthcdr 10 (file-attributes truename)))
-	   ;; Find any buffer for a file which has same truename.
-	   (other (and (not buf) (find-buffer-visiting filename))))
-      ;; Let user know if there is a buffer with the same truename.
-      (if other
-	  (progn
-	    (or nowarn
-		(string-equal filename (buffer-file-name other))
-		(message "%s and %s are the same file"
-			 filename (buffer-file-name other)))
-	    ;; Optionally also find that buffer.
-	    (if (or find-file-existing-other-name find-file-visit-truename)
-		(setq buf other))))
-      (if buf
-	  ;; We are using an existing buffer.
-	  (progn
-	    (or nowarn
-		(verify-visited-file-modtime buf)
-		(cond ((not (file-exists-p filename))
-		       (error "File %s no longer exists!" filename))
-		      ;; Certain files should be reverted automatically
-		      ;; if they have changed on disk and not in the buffer.
-		      ((and (not (buffer-modified-p buf))
-			    (let ((tail revert-without-query)
-				  (found nil))
-			      (while tail
-				(if (string-match (car tail) filename)
-				    (setq found t))
-				(setq tail (cdr tail)))
-			      found))
-		       (with-current-buffer buf
-			 (message "Reverting file %s..." filename)
-			 (revert-buffer t t)
-			 (message "Reverting file %s...done" filename)))
-		      ((yes-or-no-p
-			(if (string= (file-name-nondirectory filename)
-				     (buffer-name buf))
+    (if (and find-file-wildcards
+	     (string-match "[[*?]" filename))
+	(let ((files (file-expand-wildcards filename t))
+	      (find-file-wildcards nil))
+	  (car (mapcar #'(lambda (fn) (find-file-noselect fn))
+		       files)))
+      (let* ((buf (get-file-buffer filename))
+	     (truename (abbreviate-file-name (file-truename filename)))
+	     (number (nthcdr 10 (file-attributes truename)))
+	     ;; Find any buffer for a file which has same truename.
+	     (other (and (not buf) (find-buffer-visiting filename))))
+	;; Let user know if there is a buffer with the same truename.
+	(if other
+	    (progn
+	      (or nowarn
+		  (string-equal filename (buffer-file-name other))
+		  (message "%s and %s are the same file"
+			   filename (buffer-file-name other)))
+	      ;; Optionally also find that buffer.
+	      (if (or find-file-existing-other-name find-file-visit-truename)
+		  (setq buf other))))
+	(if buf
+	    ;; We are using an existing buffer.
+	    (progn
+	      (or nowarn
+		  (verify-visited-file-modtime buf)
+		  (cond ((not (file-exists-p filename))
+			 (error "File %s no longer exists!" filename))
+			;; Certain files should be reverted automatically
+			;; if they have changed on disk and not in the buffer.
+			((and (not (buffer-modified-p buf))
+			      (let ((tail revert-without-query)
+				    (found nil))
+				(while tail
+				  (if (string-match (car tail) filename)
+				      (setq found t))
+				  (setq tail (cdr tail)))
+				found))
+			 (with-current-buffer buf
+			   (message "Reverting file %s..." filename)
+			   (revert-buffer t t)
+			   (message "Reverting file %s...done" filename)))
+			((yes-or-no-p
+			  (if (string= (file-name-nondirectory filename)
+				       (buffer-name buf))
+			      (format
+			       (if (buffer-modified-p buf)
+				   "File %s changed on disk.  Discard your edits? "
+				 "File %s changed on disk.  Reread from disk? ")
+			       (file-name-nondirectory filename))
 			    (format
 			     (if (buffer-modified-p buf)
-				 "File %s changed on disk.  Discard your edits? "
-			       "File %s changed on disk.  Reread from disk? ")
-			     (file-name-nondirectory filename))
-			  (format
-			   (if (buffer-modified-p buf)
-			       "File %s changed on disk.  Discard your edits in %s? "
-			     "File %s changed on disk.  Reread from disk into %s? ")
-			   (file-name-nondirectory filename)
-			   (buffer-name buf))))
-		       (with-current-buffer buf
-			 (revert-buffer t t)))))
-	    (with-current-buffer buf
-	      (when (not (eq (not (null rawfile))
-			     (not (null find-file-literally))))
-		(if (buffer-modified-p)
+				 "File %s changed on disk.  Discard your edits in %s? "
+			       "File %s changed on disk.  Reread from disk into %s? ")
+			     (file-name-nondirectory filename)
+			     (buffer-name buf))))
+			 (with-current-buffer buf
+			   (revert-buffer t t)))))
+	      (with-current-buffer buf
+		(when (not (eq (not (null rawfile))
+			       (not (null find-file-literally))))
+		  (if (buffer-modified-p)
+		      (if (y-or-n-p (if rawfile
+					"Save file and revisit literally? "
+				      "Save file and revisit non-literally? "))
+			  (progn
+			    (save-buffer)
+			    (find-file-noselect-1 buf filename nowarn
+						  rawfile truename number))
+			(if (y-or-n-p (if rawfile
+					  "Discard your edits and revisit file literally? "
+					"Discard your edits and revisit file non-literally? "))
+			    (find-file-noselect-1 buf filename nowarn
+						  rawfile truename number)
+			  (error (if rawfile "File already visited non-literally"
+				   "File already visited literally"))))
 		    (if (y-or-n-p (if rawfile
-				      "Save file and revisit literally? "
-				    "Save file and revisit non-literally? "))
-			(progn
-			  (save-buffer)
-			  (find-file-noselect-1 buf filename nowarn
-						rawfile truename number))
-		      (if (y-or-n-p (if rawfile
-					"Discard your edits and revisit file literally? "
-				      "Discard your edits and revisit file non-literally? "))
-			  (find-file-noselect-1 buf filename nowarn
-						rawfile truename number)
-			(error (if rawfile "File already visited non-literally"
-				 "File already visited literally"))))
-		  (if (y-or-n-p (if rawfile
-				    "Revisit file literally? "
-				  "Revisit file non-literally? "))
-		      (find-file-noselect-1 buf filename nowarn
-					    rawfile truename number)
-		    (error (if rawfile "File already visited non-literally"
-			     "File already visited literally"))))))
-	    ;; Return the buffer we are using.
-	    buf)
-	;; Create a new buffer.
-	(setq buf (create-file-buffer filename))
-	(set-buffer-major-mode buf)
-	;; find-file-noselect-1 may use a different buffer.
-	(find-file-noselect-1 buf filename nowarn
-			      rawfile truename number)))))
+				      "Revisit file literally? "
+				    "Revisit file non-literally? "))
+			(find-file-noselect-1 buf filename nowarn
+					      rawfile truename number)
+		      (error (if rawfile "File already visited non-literally"
+			       "File already visited literally"))))))
+	      ;; Return the buffer we are using.
+	      buf)
+	  ;; Create a new buffer.
+	  (setq buf (create-file-buffer filename))
+	  (set-buffer-major-mode buf)
+	  ;; find-file-noselect-1 may use a different buffer.
+	  (find-file-noselect-1 buf filename nowarn
+				rawfile truename number))))))
 
 (defun find-file-noselect-1 (buf filename nowarn rawfile truename number)
   (let ((inhibit-read-only t)
@@ -3027,6 +3040,12 @@
   :type 'string
   :group 'dired)
 
+(defun file-expand-wildcards (pattern &optional full)
+  "Expand wildcard pattern PATTERN.
+This returns a list of file names which match the pattern."
+  (directory-files (file-name-directory pattern) full
+		   (wildcard-to-regexp (file-name-nondirectory pattern))))
+
 (defun list-directory (dirname &optional verbose)
   "Display a list of files in or matching DIRNAME, a la `ls'.
 DIRNAME is globbed by the shell if necessary.