]> git.eshelyaron.com Git - emacs.git/commitdiff
(lgrep, rgrep): At the beginning
authorJuri Linkov <juri@jurta.org>
Sat, 22 Aug 2009 00:17:56 +0000 (00:17 +0000)
committerJuri Linkov <juri@jurta.org>
Sat, 22 Aug 2009 00:17:56 +0000 (00:17 +0000)
set `dir' to `default-directory' unless `dir' is a non-nil
readable directory.  (Bug#4052)
(lgrep, rgrep): Change a weird way to report an error
from using `read-string' to using `error'.
Instead of using interactive arguments in the function body,
add new argument `confirm'.

lisp/ChangeLog
lisp/progmodes/grep.el

index d3808ed8f9da1c56f4bd38f73435b7e2c87d88bd..6f6e57d56aff5460506e450a0b84011938d1c41f 100644 (file)
@@ -1,3 +1,13 @@
+2009-08-22  Juri Linkov  <juri@jurta.org>
+
+       * progmodes/grep.el (lgrep, rgrep): At the beginning
+       set `dir' to `default-directory' unless `dir' is a non-nil
+       readable directory.  (Bug#4052)
+       (lgrep, rgrep): Change a weird way to report an error
+       from using `read-string' to using `error'.
+       Instead of using interactive arguments in the function body,
+       add new argument `confirm'.
+
 2009-08-21  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * textmodes/remember.el (remember-buffer):
index 9e63c1d0611d349c0bb07f49ae77f1000c11bdca..30fb40c26208e898c52806f9a95f36e4808eddcb 100644 (file)
@@ -778,7 +778,7 @@ substitution string.  Note dynamic scoping of variables.")
             files))))
 
 ;;;###autoload
-(defun lgrep (regexp &optional files dir)
+(defun lgrep (regexp &optional files dir confirm)
   "Run grep, searching for REGEXP in FILES in directory DIR.
 The search is limited to file names matching shell pattern FILES.
 FILES may use abbreviations defined in `grep-files-aliases', e.g.
@@ -800,17 +800,18 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
      (cond
       ((and grep-command (equal current-prefix-arg '(16)))
        (list (read-from-minibuffer "Run: " grep-command
-                                  nil nil 'grep-history)
-            nil))
+                                  nil nil 'grep-history)))
       ((not grep-template)
-       (list nil
-            (read-string "grep.el: No `grep-template' available. Press RET.")))
+       (error "grep.el: No `grep-template' available."))
       (t (let* ((regexp (grep-read-regexp))
                (files (grep-read-files regexp))
                (dir (read-directory-name "In directory: "
-                                         nil default-directory t)))
-          (list regexp files dir))))))
+                                         nil default-directory t))
+               (confirm (equal current-prefix-arg '(4))))
+          (list regexp files dir confirm))))))
   (when (and (stringp regexp) (> (length regexp) 0))
+    (unless (and dir (file-directory-p dir) (file-readable-p dir))
+      (setq dir default-directory))
     (let ((command regexp))
       (if (null files)
          (if (string= command grep-command)
@@ -821,13 +822,13 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
                       regexp
                       files))
        (when command
-         (if (equal current-prefix-arg '(4))
+         (if confirm
              (setq command
                    (read-from-minibuffer "Confirm: "
                                          command nil nil 'grep-history))
            (add-to-history 'grep-history command))))
       (when command
-       (let ((default-directory (or dir default-directory)))
+       (let ((default-directory dir))
          ;; Setting process-setup-function makes exit-message-function work
          ;; even when async processes aren't supported.
          (compilation-start (if (and grep-use-null-device null-device)
@@ -841,7 +842,7 @@ This command shares argument histories with \\[rgrep] and \\[grep]."
 (defvar find-name-arg)                  ; autoloaded
 
 ;;;###autoload
-(defun rgrep (regexp &optional files dir)
+(defun rgrep (regexp &optional files dir confirm)
   "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
 The search is limited to file names matching shell pattern FILES.
 FILES may use abbreviations defined in `grep-files-aliases', e.g.
@@ -863,17 +864,18 @@ This command shares argument histories with \\[lgrep] and \\[grep-find]."
      (cond
       ((and grep-find-command (equal current-prefix-arg '(16)))
        (list (read-from-minibuffer "Run: " grep-find-command
-                                  nil nil 'grep-find-history)
-            nil))
+                                  nil nil 'grep-find-history)))
       ((not grep-find-template)
-       (list nil nil
-            (read-string "grep.el: No `grep-find-template' available. Press RET.")))
+       (error "grep.el: No `grep-find-template' available."))
       (t (let* ((regexp (grep-read-regexp))
                (files (grep-read-files regexp))
                (dir (read-directory-name "Base directory: "
-                                         nil default-directory t)))
-          (list regexp files dir))))))
+                                         nil default-directory t))
+               (confirm (equal current-prefix-arg '(4))))
+          (list regexp files dir confirm))))))
   (when (and (stringp regexp) (> (length regexp) 0))
+    (unless (and dir (file-directory-p dir) (file-readable-p dir))
+      (setq dir default-directory))
     (if (null files)
        (if (not (string= regexp grep-find-command))
            (compilation-start regexp 'grep-mode))
@@ -909,7 +911,7 @@ This command shares argument histories with \\[lgrep] and \\[grep-find]."
                                    (shell-quote-argument ")")
                                    " -prune -o ")))))
        (when command
-         (if current-prefix-arg
+         (if confirm
              (setq command
                    (read-from-minibuffer "Confirm: "
                                          command nil nil 'grep-find-history))