Mercurial > emacs
comparison lisp/progmodes/grep.el @ 104525:b8afce0dc654
(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'.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sat, 22 Aug 2009 00:17:48 +0000 |
parents | a3d4286317ce |
children | 3f203311bcc1 |
comparison
equal
deleted
inserted
replaced
104400:ed5d844496e7 | 104525:b8afce0dc654 |
---|---|
776 (and files | 776 (and files |
777 (or (cdr (assoc files grep-files-aliases)) | 777 (or (cdr (assoc files grep-files-aliases)) |
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. |
785 entering `ch' is equivalent to `*.[ch]'. | 785 entering `ch' is equivalent to `*.[ch]'. |
786 | 786 |
798 (progn | 798 (progn |
799 (grep-compute-defaults) | 799 (grep-compute-defaults) |
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) |
817 (setq command nil)) | 818 (setq command nil)) |
818 (setq dir (file-name-as-directory (expand-file-name dir))) | 819 (setq dir (file-name-as-directory (expand-file-name dir))) |
819 (setq command (grep-expand-template | 820 (setq command (grep-expand-template |
820 grep-template | 821 grep-template |
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) |
834 (concat command " " null-device) | 835 (concat command " " null-device) |
835 command) | 836 command) |
839 | 840 |
840 | 841 |
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. |
848 entering `ch' is equivalent to `*.[ch]'. | 849 entering `ch' is equivalent to `*.[ch]'. |
849 | 850 |
861 (progn | 862 (progn |
862 (grep-compute-defaults) | 863 (grep-compute-defaults) |
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)) |
880 (setq dir (file-name-as-directory (expand-file-name dir))) | 882 (setq dir (file-name-as-directory (expand-file-name dir))) |
881 (let ((command (grep-expand-template | 883 (let ((command (grep-expand-template |
907 " -o -path ") | 909 " -o -path ") |
908 " " | 910 " " |
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)) |
916 (add-to-history 'grep-find-history command)) | 918 (add-to-history 'grep-find-history command)) |
917 (let ((default-directory dir)) | 919 (let ((default-directory dir)) |