diff options
| author | Juri Linkov | 2009-08-22 00:17:56 +0000 |
|---|---|---|
| committer | Juri Linkov | 2009-08-22 00:17:56 +0000 |
| commit | 32a2cf25a74160b855041c176d2e7e937baa4de8 (patch) | |
| tree | aa1044511807cec6f4cfe700947e1c8970dd546f | |
| parent | 51b4b3fb3829c415dd6e3277ca226440c1f403c1 (diff) | |
| download | emacs-32a2cf25a74160b855041c176d2e7e937baa4de8.tar.gz emacs-32a2cf25a74160b855041c176d2e7e937baa4de8.zip | |
(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'.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/progmodes/grep.el | 36 |
2 files changed, 29 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d3808ed8f9d..6f6e57d56af 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2009-08-22 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * progmodes/grep.el (lgrep, rgrep): At the beginning | ||
| 4 | set `dir' to `default-directory' unless `dir' is a non-nil | ||
| 5 | readable directory. (Bug#4052) | ||
| 6 | (lgrep, rgrep): Change a weird way to report an error | ||
| 7 | from using `read-string' to using `error'. | ||
| 8 | Instead of using interactive arguments in the function body, | ||
| 9 | add new argument `confirm'. | ||
| 10 | |||
| 1 | 2009-08-21 Stefan Monnier <monnier@iro.umontreal.ca> | 11 | 2009-08-21 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 12 | ||
| 3 | * textmodes/remember.el (remember-buffer): | 13 | * textmodes/remember.el (remember-buffer): |
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 9e63c1d0611..30fb40c2620 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el | |||
| @@ -778,7 +778,7 @@ substitution string. Note dynamic scoping of variables.") | |||
| 778 | files)))) | 778 | files)))) |
| 779 | 779 | ||
| 780 | ;;;###autoload | 780 | ;;;###autoload |
| 781 | (defun lgrep (regexp &optional files dir) | 781 | (defun lgrep (regexp &optional files dir confirm) |
| 782 | "Run grep, searching for REGEXP in FILES in directory DIR. | 782 | "Run grep, searching for REGEXP in FILES in directory DIR. |
| 783 | The search is limited to file names matching shell pattern FILES. | 783 | The search is limited to file names matching shell pattern FILES. |
| 784 | FILES may use abbreviations defined in `grep-files-aliases', e.g. | 784 | FILES may use abbreviations defined in `grep-files-aliases', e.g. |
| @@ -800,17 +800,18 @@ This command shares argument histories with \\[rgrep] and \\[grep]." | |||
| 800 | (cond | 800 | (cond |
| 801 | ((and grep-command (equal current-prefix-arg '(16))) | 801 | ((and grep-command (equal current-prefix-arg '(16))) |
| 802 | (list (read-from-minibuffer "Run: " grep-command | 802 | (list (read-from-minibuffer "Run: " grep-command |
| 803 | nil nil 'grep-history) | 803 | nil nil 'grep-history))) |
| 804 | nil)) | ||
| 805 | ((not grep-template) | 804 | ((not grep-template) |
| 806 | (list nil | 805 | (error "grep.el: No `grep-template' available.")) |
| 807 | (read-string "grep.el: No `grep-template' available. Press RET."))) | ||
| 808 | (t (let* ((regexp (grep-read-regexp)) | 806 | (t (let* ((regexp (grep-read-regexp)) |
| 809 | (files (grep-read-files regexp)) | 807 | (files (grep-read-files regexp)) |
| 810 | (dir (read-directory-name "In directory: " | 808 | (dir (read-directory-name "In directory: " |
| 811 | nil default-directory t))) | 809 | nil default-directory t)) |
| 812 | (list regexp files dir)))))) | 810 | (confirm (equal current-prefix-arg '(4)))) |
| 811 | (list regexp files dir confirm)))))) | ||
| 813 | (when (and (stringp regexp) (> (length regexp) 0)) | 812 | (when (and (stringp regexp) (> (length regexp) 0)) |
| 813 | (unless (and dir (file-directory-p dir) (file-readable-p dir)) | ||
| 814 | (setq dir default-directory)) | ||
| 814 | (let ((command regexp)) | 815 | (let ((command regexp)) |
| 815 | (if (null files) | 816 | (if (null files) |
| 816 | (if (string= command grep-command) | 817 | (if (string= command grep-command) |
| @@ -821,13 +822,13 @@ This command shares argument histories with \\[rgrep] and \\[grep]." | |||
| 821 | regexp | 822 | regexp |
| 822 | files)) | 823 | files)) |
| 823 | (when command | 824 | (when command |
| 824 | (if (equal current-prefix-arg '(4)) | 825 | (if confirm |
| 825 | (setq command | 826 | (setq command |
| 826 | (read-from-minibuffer "Confirm: " | 827 | (read-from-minibuffer "Confirm: " |
| 827 | command nil nil 'grep-history)) | 828 | command nil nil 'grep-history)) |
| 828 | (add-to-history 'grep-history command)))) | 829 | (add-to-history 'grep-history command)))) |
| 829 | (when command | 830 | (when command |
| 830 | (let ((default-directory (or dir default-directory))) | 831 | (let ((default-directory dir)) |
| 831 | ;; Setting process-setup-function makes exit-message-function work | 832 | ;; Setting process-setup-function makes exit-message-function work |
| 832 | ;; even when async processes aren't supported. | 833 | ;; even when async processes aren't supported. |
| 833 | (compilation-start (if (and grep-use-null-device null-device) | 834 | (compilation-start (if (and grep-use-null-device null-device) |
| @@ -841,7 +842,7 @@ This command shares argument histories with \\[rgrep] and \\[grep]." | |||
| 841 | (defvar find-name-arg) ; autoloaded | 842 | (defvar find-name-arg) ; autoloaded |
| 842 | 843 | ||
| 843 | ;;;###autoload | 844 | ;;;###autoload |
| 844 | (defun rgrep (regexp &optional files dir) | 845 | (defun rgrep (regexp &optional files dir confirm) |
| 845 | "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. | 846 | "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. |
| 846 | The search is limited to file names matching shell pattern FILES. | 847 | The search is limited to file names matching shell pattern FILES. |
| 847 | FILES may use abbreviations defined in `grep-files-aliases', e.g. | 848 | 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]." | |||
| 863 | (cond | 864 | (cond |
| 864 | ((and grep-find-command (equal current-prefix-arg '(16))) | 865 | ((and grep-find-command (equal current-prefix-arg '(16))) |
| 865 | (list (read-from-minibuffer "Run: " grep-find-command | 866 | (list (read-from-minibuffer "Run: " grep-find-command |
| 866 | nil nil 'grep-find-history) | 867 | nil nil 'grep-find-history))) |
| 867 | nil)) | ||
| 868 | ((not grep-find-template) | 868 | ((not grep-find-template) |
| 869 | (list nil nil | 869 | (error "grep.el: No `grep-find-template' available.")) |
| 870 | (read-string "grep.el: No `grep-find-template' available. Press RET."))) | ||
| 871 | (t (let* ((regexp (grep-read-regexp)) | 870 | (t (let* ((regexp (grep-read-regexp)) |
| 872 | (files (grep-read-files regexp)) | 871 | (files (grep-read-files regexp)) |
| 873 | (dir (read-directory-name "Base directory: " | 872 | (dir (read-directory-name "Base directory: " |
| 874 | nil default-directory t))) | 873 | nil default-directory t)) |
| 875 | (list regexp files dir)))))) | 874 | (confirm (equal current-prefix-arg '(4)))) |
| 875 | (list regexp files dir confirm)))))) | ||
| 876 | (when (and (stringp regexp) (> (length regexp) 0)) | 876 | (when (and (stringp regexp) (> (length regexp) 0)) |
| 877 | (unless (and dir (file-directory-p dir) (file-readable-p dir)) | ||
| 878 | (setq dir default-directory)) | ||
| 877 | (if (null files) | 879 | (if (null files) |
| 878 | (if (not (string= regexp grep-find-command)) | 880 | (if (not (string= regexp grep-find-command)) |
| 879 | (compilation-start regexp 'grep-mode)) | 881 | (compilation-start regexp 'grep-mode)) |
| @@ -909,7 +911,7 @@ This command shares argument histories with \\[lgrep] and \\[grep-find]." | |||
| 909 | (shell-quote-argument ")") | 911 | (shell-quote-argument ")") |
| 910 | " -prune -o "))))) | 912 | " -prune -o "))))) |
| 911 | (when command | 913 | (when command |
| 912 | (if current-prefix-arg | 914 | (if confirm |
| 913 | (setq command | 915 | (setq command |
| 914 | (read-from-minibuffer "Confirm: " | 916 | (read-from-minibuffer "Confirm: " |
| 915 | command nil nil 'grep-find-history)) | 917 | command nil nil 'grep-find-history)) |