aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKim F. Storm2002-05-30 22:11:29 +0000
committerKim F. Storm2002-05-30 22:11:29 +0000
commit9ebd759d59c966f2d05c808c07884810f2212971 (patch)
tree8825291c51c9aa07cc0e701c16b381d547a78f5b /lisp
parentb186095c507d229b3d21b6709c076a8d1a8c199d (diff)
downloademacs-9ebd759d59c966f2d05c808c07884810f2212971.tar.gz
emacs-9ebd759d59c966f2d05c808c07884810f2212971.zip
(grep-tree-command, grep-tree-files-aliases)
(grep-tree-ignore-CVS-directories, grep-tree-ignore-case): New custom variables. (grep-compute-defaults): Compute grep-tree-command's default value. (grep-expand-command-macros): New aux function. (grep-tree-last-regexp, grep-tree-last-files): New aux variables. (grep-tree): New command like grep-find but extended prompting.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/compile.el120
1 files changed, 119 insertions, 1 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 02fa3abb90c..7a759f1e2ef 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -121,7 +121,19 @@ will be parsed and highlighted as soon as you try to move to them."
121 find-program grep-command)) 121 find-program grep-command))
122 (t (cons (format "%s . -type f -exec %s {} %s \\;" 122 (t (cons (format "%s . -type f -exec %s {} %s \\;"
123 find-program grep-command null-device) 123 find-program grep-command null-device)
124 (+ 22 (length grep-command)))))))) 124 (+ 22 (length grep-command)))))))
125 (unless grep-tree-command
126 (setq grep-tree-command
127 (let* ((glen (length grep-program))
128 (gcmd (concat grep-program " <C>" (substring grep-command glen))))
129 (cond ((eq grep-find-use-xargs 'gnu)
130 (format "%s <D> <X> -type f <F> -print0 | xargs -0 -e %s <R>"
131 find-program gcmd))
132 (grep-find-use-xargs
133 (format "%s <D> <X> -type f <F> -print | xargs %s <R>"
134 find-program gcmd))
135 (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;"
136 find-program gcmd null-device)))))))
125 137
126(defcustom grep-command nil 138(defcustom grep-command nil
127 "The default grep command for \\[grep]. 139 "The default grep command for \\[grep].
@@ -162,6 +174,46 @@ call that function before using this variable in your program."
162 (progn (grep-compute-defaults) grep-find-command))) 174 (progn (grep-compute-defaults) grep-find-command)))
163 :group 'compilation) 175 :group 'compilation)
164 176
177(defcustom grep-tree-command nil
178 "The default find command for \\[grep-tree].
179The default value of this variable is set up by `grep-compute-defaults';
180call that function before using this variable in your program.
181The following place holders should be present in the string:
182 <D> - base directory for find
183 <X> - find options to restrict or expand the directory list
184 <F> - find options to limit the files matched
185 <C> - place to put -i if case insensitive grep
186 <R> - the regular expression searched for."
187 :type 'string
188 :version "21.4"
189 :get (lambda (symbol)
190 (or grep-tree-command
191 (progn (grep-compute-defaults) grep-tree-command)))
192 :group 'compilation)
193
194(defcustom grep-tree-files-aliases '(
195 ("ch" . "*.[ch]")
196 ("c" . "*.c")
197 ("h" . "*.h")
198 ("m" . "[Mm]akefile*")
199 ("asm" . "*.[sS]")
200 ("all" . "*")
201 ("el" . "*.el")
202 )
203 "*Alist of aliases for the FILES argument to `grep-tree'."
204 :type 'alist
205 :group 'compilation)
206
207(defcustom grep-tree-ignore-case t
208 "*If non-nil, `grep-tree' ignores case in matches."
209 :type 'boolean
210 :group 'compilation)
211
212(defcustom grep-tree-ignore-CVS-directories t
213 "*If non-nil, `grep-tree' does no recurse into CVS directories."
214 :type 'boolean
215 :group 'compilation)
216
165(defvar compilation-error-list nil 217(defvar compilation-error-list nil
166 "List of error message descriptors for visiting erring functions. 218 "List of error message descriptors for visiting erring functions.
167Each error descriptor is a cons (or nil). Its car is a marker pointing to 219Each error descriptor is a cons (or nil). Its car is a marker pointing to
@@ -785,6 +837,72 @@ easily repeat a find command."
785 (let ((null-device nil)) ; see grep 837 (let ((null-device nil)) ; see grep
786 (grep command-args))) 838 (grep command-args)))
787 839
840(defun grep-expand-command-macros (command &optional regexp files dir excl case-fold)
841 "Patch grep COMMAND replacing <D>, etc."
842 (setq command
843 (replace-regexp-in-string "<D>"
844 (or dir ".") command t t))
845 (setq command
846 (replace-regexp-in-string "<X>"
847 (or excl "") command t t))
848 (setq command
849 (replace-regexp-in-string "<F>"
850 (or files "") command t t))
851 (setq command
852 (replace-regexp-in-string "<C>"
853 (if case-fold "-i" "") command t t))
854 (setq command
855 (replace-regexp-in-string "<R>"
856 (or regexp "") command t t))
857 command)
858
859;;;###autoload
860(defvar grep-tree-last-regexp "")
861(defvar grep-tree-last-files (car (car grep-tree-files-aliases)))
862
863(defun grep-tree (regexp files dir)
864 "Grep in directory tree with simplified prompting for search parameters.
865Collect output in a buffer.
866While find runs asynchronously, you can use the \\[next-error] command
867to find the text that grep hits refer to.
868
869This command uses a special history list for its arguments, so you can
870easily repeat a find command."
871 (interactive
872 (let* ((regexp
873 (if current-prefix-arg
874 grep-tree-last-regexp
875 (let* ((default (current-word))
876 (spec (read-string
877 (concat "Search for"
878 (if (and default (> (length default) 0))
879 (format " (default %s): " default) ": ")))))
880 (if (equal spec "") default spec))))
881 (files
882 (read-string (concat "Search for \"" regexp "\" in files (default " grep-tree-last-files "): ")))
883 (dir
884 (read-directory-name "Base directory: " nil default-directory t)))
885 (list regexp files dir)))
886 (unless grep-tree-command
887 (grep-compute-defaults))
888 (unless (and (stringp files) (> (length files) 0))
889 (setq files grep-tree-last-files))
890 (when files
891 (setq grep-tree-last-files files)
892 (let ((mf (assoc files match-files-aliases)))
893 (if mf
894 (setq files (cdr mf)))))
895 (let ((command-args (grep-expand-command-macros
896 grep-tree-command
897 (setq grep-tree-last-regexp regexp)
898 (and files (concat "-name '" files "'"))
899 nil ;; we change default-directory to dir
900 (and grep-tree-ignore-CVS-directories "-path '*/CVS' -prune -o ")
901 grep-tree-ignore-case))
902 (default-directory dir)
903 (null-device nil)) ; see grep
904 (grep command-args)))
905
788(defcustom compilation-scroll-output nil 906(defcustom compilation-scroll-output nil
789 "*Non-nil to scroll the *compilation* buffer window as output appears. 907 "*Non-nil to scroll the *compilation* buffer window as output appears.
790 908