changeset 70259:58edc69a1813

(grep-read-files): Use buffer-name if no buffer-file-name. Default to *.ext if no alias matches. No default if no extension.
author Kim F. Storm <storm@cua.dk>
date Fri, 28 Apr 2006 23:39:02 +0000
parents 5dfde453f39e
children fbd84671cce3
files lisp/progmodes/grep.el
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/grep.el	Fri Apr 28 22:22:01 2006 +0000
+++ b/lisp/progmodes/grep.el	Fri Apr 28 23:39:02 2006 +0000
@@ -599,10 +599,13 @@
 
 (defun grep-read-files (regexp)
   "Read files arg for interactive grep."
-  (let* ((default
-	   (or (and (stringp (buffer-file-name))
-		    (let ((fn (file-name-nondirectory (buffer-file-name)))
-			  (aliases grep-files-aliases)
+  (let* ((bn (or (buffer-file-name) (buffer-name)))
+	 (fn (and bn
+		  (stringp bn)
+		  (file-name-nondirectory bn)))
+	 (default
+	   (or (and fn
+		    (let ((aliases grep-files-aliases)
 			  alias)
 		      (while aliases
 			(setq alias (car aliases)
@@ -611,10 +614,14 @@
 			    (setq aliases nil)
 			  (setq alias nil)))
 		      (cdr alias)))
-	       (car grep-files-history)))
+	       (and fn
+		    (let ((ext (file-name-extension fn)))
+		      (and ext (concat "*." ext))))))
 	 (files (read-string
 		 (concat "Search for \"" regexp
-			 "\" in files (default " default "): ")
+			 "\" in files"
+			 (if default (concat " (default " default ")"))
+			 ": ")
 		 nil 'grep-files-history default)))
     (and files
 	 (or (cdr (assoc files grep-files-aliases))