]> code.delx.au - gnu-emacs/blob - lisp/progmodes/grep.el
(c-safe-scan-lists): Fix spellings.
[gnu-emacs] / lisp / progmodes / grep.el
1 ;;; grep.el --- run Grep as inferior of Emacs, parse match messages
2
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
5
6 ;; Author: Roland McGrath <roland@gnu.org>
7 ;; Maintainer: FSF
8 ;; Keywords: tools, processes
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; This package provides the grep facilities documented in the Emacs
30 ;; user's manual.
31
32 ;;; Code:
33
34 (require 'compile)
35
36 (defgroup grep nil
37 "Run compiler as inferior of Emacs, parse error messages."
38 :group 'tools
39 :group 'processes)
40
41
42 ;;;###autoload
43 (defcustom grep-window-height nil
44 "*Number of lines in a grep window. If nil, use `compilation-window-height'."
45 :type '(choice (const :tag "Default" nil)
46 integer)
47 :version "22.1"
48 :group 'grep)
49
50 (defcustom grep-auto-highlight t
51 "*Specify how many grep matches to highlight (and parse) initially.
52 \(Highlighting applies to an grep match when the mouse is over it.)
53 If this is a number N, all grep matches in the first N lines
54 are highlighted and parsed as soon as they arrive in Emacs.
55 If t, highlight and parse the whole grep output as soon as it arrives.
56 If nil, don't highlight or parse any of the grep buffer until you try to
57 move to the error messages.
58
59 Those grep matches which are not parsed and highlighted initially
60 will be parsed and highlighted as soon as you try to move to them."
61 :type '(choice (const :tag "All" t)
62 (const :tag "None" nil)
63 (integer :tag "First N lines"))
64 :version "22.1"
65 :group 'grep)
66
67 (defcustom grep-highlight-matches 'auto-detect
68 "If t, use special markers to highlight grep matches.
69
70 Some grep programs are able to surround matches with special
71 markers in grep output. Such markers can be used to highlight
72 matches in grep mode.
73
74 This option sets the environment variable GREP_COLOR to specify
75 markers for highlighting and GREP_OPTIONS to add the --color
76 option in front of any explicit grep options before starting
77 the grep.
78
79 The default value of this variable is set up by `grep-compute-defaults';
80 call that function before using this variable in your program."
81 :type '(choice (const :tag "Do not highlight matches with grep markers" nil)
82 (const :tag "Highlight matches with grep markers" t)
83 (other :tag "Not Set" auto-detect))
84 :version "22.1"
85 :group 'grep)
86
87 (defcustom grep-scroll-output nil
88 "*Non-nil to scroll the *grep* buffer window as output appears.
89
90 Setting it causes the grep commands to put point at the end of their
91 output window so that the end of the output is always visible rather
92 than the begining."
93 :type 'boolean
94 :version "22.1"
95 :group 'grep)
96
97 ;;;###autoload
98 (defcustom grep-command nil
99 "The default grep command for \\[grep].
100 If the grep program used supports an option to always include file names
101 in its output (such as the `-H' option to GNU grep), it's a good idea to
102 include it when specifying `grep-command'.
103
104 The default value of this variable is set up by `grep-compute-defaults';
105 call that function before using this variable in your program."
106 :type '(choice string
107 (const :tag "Not Set" nil))
108 :group 'grep)
109
110 (defcustom grep-use-null-device 'auto-detect
111 "If t, append the value of `null-device' to `grep' commands.
112 This is done to ensure that the output of grep includes the filename of
113 any match in the case where only a single file is searched, and is not
114 necessary if the grep program used supports the `-H' option.
115
116 The default value of this variable is set up by `grep-compute-defaults';
117 call that function before using this variable in your program."
118 :type '(choice (const :tag "Do Not Append Null Device" nil)
119 (const :tag "Append Null Device" t)
120 (other :tag "Not Set" auto-detect))
121 :group 'grep)
122
123 ;;;###autoload
124 (defcustom grep-find-command nil
125 "The default find command for \\[grep-find].
126 The default value of this variable is set up by `grep-compute-defaults';
127 call that function before using this variable in your program."
128 :type '(choice string
129 (const :tag "Not Set" nil))
130 :group 'grep)
131
132 (defcustom grep-tree-command nil
133 "The default find command for \\[grep-tree].
134 The default value of this variable is set up by `grep-compute-defaults';
135 call that function before using this variable in your program.
136 The following place holders should be present in the string:
137 <D> - base directory for find
138 <X> - find options to restrict or expand the directory list
139 <F> - find options to limit the files matched
140 <C> - place to put -i if case insensitive grep
141 <R> - the regular expression searched for."
142 :type '(choice string
143 (const :tag "Not Set" nil))
144 :version "22.1"
145 :group 'grep)
146
147 (defcustom grep-tree-files-aliases '(
148 ("ch" . "*.[ch]")
149 ("c" . "*.c")
150 ("h" . "*.h")
151 ("m" . "[Mm]akefile*")
152 ("asm" . "*.[sS]")
153 ("all" . "*")
154 ("el" . "*.el")
155 )
156 "*Alist of aliases for the FILES argument to `grep-tree'."
157 :type 'alist
158 :group 'grep)
159
160 (defcustom grep-tree-ignore-case t
161 "*If non-nil, `grep-tree' ignores case in matches."
162 :type 'boolean
163 :group 'grep)
164
165 (defcustom grep-tree-ignore-CVS-directories t
166 "*If non-nil, `grep-tree' does no recurse into CVS directories."
167 :type 'boolean
168 :group 'grep)
169
170 (defcustom grep-error-screen-columns nil
171 "*If non-nil, column numbers in grep hits are screen columns.
172 See `compilation-error-screen-columns'"
173 :type '(choice (const :tag "Default" nil)
174 integer)
175 :version "22.1"
176 :group 'grep)
177
178 ;;;###autoload
179 (defcustom grep-setup-hook nil
180 "List of hook functions run by `grep-process-setup' (see `run-hooks')."
181 :type 'hook
182 :group 'grep)
183
184 (defvar grep-mode-map
185 (let ((map (cons 'keymap compilation-minor-mode-map)))
186 (define-key map " " 'scroll-up)
187 (define-key map "\^?" 'scroll-down)
188 (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
189
190 ;; This is intolerable -- rms
191 ;;; (define-key map [remap next-line] 'compilation-next-error)
192 ;;; (define-key map [remap previous-line] 'compilation-previous-error)
193
194 (define-key map "\r" 'compile-goto-error) ;; ?
195 (define-key map "n" 'next-error-no-select)
196 (define-key map "p" 'previous-error-no-select)
197 (define-key map "{" 'compilation-previous-file)
198 (define-key map "}" 'compilation-next-file)
199 (define-key map "\t" 'compilation-next-file)
200
201 ;; Set up the menu-bar
202 (define-key map [menu-bar grep]
203 (cons "Grep" (make-sparse-keymap "Grep")))
204
205 (define-key map [menu-bar grep compilation-kill-compilation]
206 '("Kill Grep" . kill-compilation))
207 (define-key map [menu-bar grep compilation-separator2]
208 '("----" . nil))
209 (define-key map [menu-bar grep compilation-compile]
210 '("Compile..." . compile))
211 (define-key map [menu-bar grep compilation-grep]
212 '("Another grep" . grep))
213 (define-key map [menu-bar grep compilation-recompile]
214 '("Repeat grep" . recompile))
215 (define-key map [menu-bar grep compilation-separator2]
216 '("----" . nil))
217 (define-key map [menu-bar grep compilation-first-error]
218 '("First Match" . first-error))
219 (define-key map [menu-bar grep compilation-previous-error]
220 '("Previous Match" . previous-error))
221 (define-key map [menu-bar grep compilation-next-error]
222 '("Next Match" . next-error))
223 map)
224 "Keymap for grep buffers.
225 `compilation-minor-mode-map' is a cdr of this.")
226
227 (defalias 'kill-grep 'kill-compilation)
228
229 ;;;; TODO --- refine this!!
230
231 ;;; (defcustom grep-use-compilation-buffer t
232 ;;; "When non-nil, grep specific commands update `compilation-last-buffer'.
233 ;;; This means that standard compile commands like \\[next-error] and \\[compile-goto-error]
234 ;;; can be used to navigate between grep matches (the default).
235 ;;; Otherwise, the grep specific commands like \\[grep-next-match] must
236 ;;; be used to navigate between grep matches."
237 ;;; :type 'boolean
238 ;;; :group 'grep)
239
240 ;; override compilation-last-buffer
241 (defvar grep-last-buffer nil
242 "The most recent grep buffer.
243 A grep buffer becomes most recent when its process is started
244 or when it is used with \\[grep-next-match].
245 Notice that using \\[next-error] or \\[compile-goto-error] modifies
246 `complation-last-buffer' rather than `grep-last-buffer'.")
247
248 ;;;###autoload
249 (defvar grep-regexp-alist
250 ;; rms: I removed the code to match parens around the line number
251 ;; because it causes confusion and so we will find out if anyone needs it.
252 ;; It causes confusion with a file name that contains a number in parens.
253 '(("^\\(.+?\\)\\([: \t]\\)+\
254 \\([0-9]+\\)\\([.:]?\\)\\([0-9]+\\)?\
255 \\(?:-\\(?:\\([0-9]+\\)\\4\\)?\\.?\\([0-9]+\\)?\\)?\\2"
256 1 (3 . 6) (5 . 7))
257 ("^\\(\\(.+?\\):\\([0-9]+\\):\\).*?\
258 \\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\(?:\033\\[K\\)?\\)"
259 2 3
260 ;; Calculate column positions (beg . end) of first grep match on a line
261 ((lambda ()
262 (setq compilation-error-screen-columns nil)
263 (- (match-beginning 5) (match-end 1) 8))
264 .
265 (lambda () (- (match-end 5) (match-end 1) 8)))
266 nil 1)
267 ("^Binary file \\(.+\\) matches$" 1 nil nil 1))
268 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
269
270 (defvar grep-error "grep hit"
271 "Message to print when no matches are found.")
272
273 ;; Reverse the colors because grep hits are not errors (though we jump there
274 ;; with `next-error'), and unreadable files can't be gone to.
275 (defvar grep-hit-face compilation-info-face
276 "Face name to use for grep hits.")
277
278 (defvar grep-error-face compilation-error-face
279 "Face name to use for grep error messages.")
280
281 (defvar grep-match-face 'match
282 "Face name to use for grep matches.")
283
284 (defvar grep-mode-font-lock-keywords
285 '(;; Command output lines.
286 ("^\\([A-Za-z_0-9/\.+-]+\\)[ \t]*:" 1 font-lock-function-name-face)
287 (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$"
288 1 grep-error-face)
289 ;; remove match from grep-regexp-alist before fontifying
290 ("^Grep finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*"
291 (0 '(face nil message nil help-echo nil mouse-face nil) t)
292 (1 grep-hit-face nil t)
293 (2 grep-error-face nil t))
294 ("^Grep \\(exited abnormally\\) with code \\([0-9]+\\).*"
295 (0 '(face nil message nil help-echo nil mouse-face nil) t)
296 (1 compilation-warning-face)
297 (2 compilation-line-face))
298 ;; Highlight grep matches and delete markers
299 ("\\(\033\\[01;41m\\)\\(.*?\\)\\(\033\\[00m\\(?:\033\\[K\\)?\\)"
300 ;; Refontification does not work after the markers have been
301 ;; deleted. So we use the font-lock-face property here as Font
302 ;; Lock does not clear that.
303 (2 (list 'face nil 'font-lock-face grep-match-face))
304 ((lambda (p))
305 (progn
306 ;; Delete markers with `replace-match' because it updates
307 ;; the match-data, whereas `delete-region' would render it obsolete.
308 (replace-match "" t t nil 3)
309 (replace-match "" t t nil 1)))))
310 "Additional things to highlight in grep output.
311 This gets tacked on the end of the generated expressions.")
312
313 ;;;###autoload
314 (defvar grep-program
315 ;; Currently zgrep has trouble. It runs egrep instead of grep,
316 ;; and it doesn't pass along long options right.
317 "grep"
318 ;; (if (equal (condition-case nil ; in case "zgrep" isn't in exec-path
319 ;; (call-process "zgrep" nil nil nil
320 ;; "foo" null-device)
321 ;; (error nil))
322 ;; 1)
323 ;; "zgrep"
324 ;; "grep")
325 "The default grep program for `grep-command' and `grep-find-command'.
326 This variable's value takes effect when `grep-compute-defaults' is called.")
327
328 ;;;###autoload
329 (defvar find-program "find"
330 "The default find program for `grep-find-command'.
331 This variable's value takes effect when `grep-compute-defaults' is called.")
332
333 ;;;###autoload
334 (defvar grep-find-use-xargs nil
335 "Whether \\[grep-find] uses the `xargs' utility by default.
336
337 If nil, it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0';
338 if not nil and not `gnu', it uses `find -print' and `xargs'.
339
340 This variable's value takes effect when `grep-compute-defaults' is called.")
341
342 ;; History of grep commands.
343 ;;;###autoload
344 (defvar grep-history nil)
345 ;;;###autoload
346 (defvar grep-find-history nil)
347
348 ;;;###autoload
349 (defun grep-process-setup ()
350 "Setup compilation variables and buffer for `grep'.
351 Set up `compilation-exit-message-function' and run `grep-setup-hook'."
352 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
353 (grep-compute-defaults))
354 (when (eq grep-highlight-matches t)
355 ;; Modify `process-environment' locally bound in `compilation-start'
356 (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") " --color=always"))
357 (setenv "GREP_COLOR" "01;41"))
358 (set (make-local-variable 'compilation-exit-message-function)
359 (lambda (status code msg)
360 (if (eq status 'exit)
361 (cond ((zerop code)
362 '("finished (matches found)\n" . "matched"))
363 ((= code 1)
364 '("finished with no matches found\n" . "no match"))
365 (t
366 (cons msg code)))
367 (cons msg code))))
368 (run-hooks 'grep-setup-hook))
369
370 ;;;###autoload
371 (defun grep-compute-defaults ()
372 (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
373 (setq grep-use-null-device
374 (with-temp-buffer
375 (let ((hello-file (expand-file-name "HELLO" data-directory)))
376 (not
377 (and (equal (condition-case nil
378 (if grep-command
379 ;; `grep-command' is already set, so
380 ;; use that for testing.
381 (call-process-shell-command
382 grep-command nil t nil
383 "^English" hello-file)
384 ;; otherwise use `grep-program'
385 (call-process grep-program nil t nil
386 "-nH" "^English" hello-file))
387 (error nil))
388 0)
389 (progn
390 (goto-char (point-min))
391 (looking-at
392 (concat (regexp-quote hello-file)
393 ":[0-9]+:English")))))))))
394 (unless grep-command
395 (setq grep-command
396 (let ((required-options (if grep-use-null-device "-n" "-nH")))
397 (if (equal (condition-case nil ; in case "grep" isn't in exec-path
398 (call-process grep-program nil nil nil
399 "-e" "foo" null-device)
400 (error nil))
401 1)
402 (format "%s %s -e " grep-program required-options)
403 (format "%s %s " grep-program required-options)))))
404 (unless grep-find-use-xargs
405 (setq grep-find-use-xargs
406 (if (and
407 (equal (call-process "find" nil nil nil
408 null-device "-print0")
409 0)
410 (equal (call-process "xargs" nil nil nil
411 "-0" "-e" "echo")
412 0))
413 'gnu)))
414 (unless grep-find-command
415 (setq grep-find-command
416 (cond ((eq grep-find-use-xargs 'gnu)
417 (format "%s . -type f -print0 | xargs -0 -e %s"
418 find-program grep-command))
419 (grep-find-use-xargs
420 (format "%s . -type f -print | xargs %s"
421 find-program grep-command))
422 (t (cons (format "%s . -type f -exec %s {} %s \\;"
423 find-program grep-command null-device)
424 (+ 22 (length grep-command)))))))
425 (unless grep-tree-command
426 (setq grep-tree-command
427 (let* ((glen (length grep-program))
428 (gcmd (concat grep-program " <C>" (substring grep-command glen))))
429 (cond ((eq grep-find-use-xargs 'gnu)
430 (format "%s <D> <X> -type f <F> -print0 | xargs -0 -e %s <R>"
431 find-program gcmd))
432 (grep-find-use-xargs
433 (format "%s <D> <X> -type f <F> -print | xargs %s <R>"
434 find-program gcmd))
435 (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;"
436 find-program gcmd null-device))))))
437 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
438 (setq grep-highlight-matches
439 (with-temp-buffer
440 (and (equal (condition-case nil
441 (call-process grep-program nil t nil "--help")
442 (error nil))
443 0)
444 (progn
445 (goto-char (point-min))
446 (search-forward "--color" nil t))
447 t)))))
448
449 (defun grep-default-command ()
450 (let ((tag-default
451 (shell-quote-argument
452 (or (funcall (or find-tag-default-function
453 (get major-mode 'find-tag-default-function)
454 'find-tag-default))
455 "")))
456 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
457 (grep-default (or (car grep-history) grep-command)))
458 ;; Replace the thing matching for with that around cursor.
459 (when (or (string-match
460 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
461 sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
462 grep-default)
463 ;; If the string is not yet complete.
464 (string-match "\\(\\)\\'" grep-default))
465 (unless (or (not (stringp buffer-file-name))
466 (when (match-beginning 2)
467 (save-match-data
468 (string-match
469 (wildcard-to-regexp
470 (file-name-nondirectory
471 (match-string 3 grep-default)))
472 (file-name-nondirectory buffer-file-name)))))
473 (setq grep-default (concat (substring grep-default
474 0 (match-beginning 2))
475 " *."
476 (file-name-extension buffer-file-name))))
477 (replace-match tag-default t t grep-default 1))))
478
479 ;;;###autoload
480 (defun grep (command-args &optional highlight-regexp)
481 "Run grep, with user-specified args, and collect output in a buffer.
482 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
483 or \\<grep-mode-map>\\[compile-goto-error] in the grep \
484 output buffer, to go to the lines
485 where grep found matches.
486
487 This command uses a special history list for its COMMAND-ARGS, so you can
488 easily repeat a grep command.
489
490 A prefix argument says to default the argument based upon the current
491 tag the cursor is over, substituting it into the last grep command
492 in the grep command history (or into `grep-command'
493 if that history list is empty).
494
495 If specified, optional second arg HIGHLIGHT-REGEXP is the regexp to
496 temporarily highlight in visited source lines."
497 (interactive
498 (progn
499 (unless (and grep-command
500 (or (not grep-use-null-device) (eq grep-use-null-device t)))
501 (grep-compute-defaults))
502 (let ((default (grep-default-command)))
503 (list (read-from-minibuffer "Run grep (like this): "
504 (if current-prefix-arg
505 default grep-command)
506 nil nil 'grep-history
507 (if current-prefix-arg nil default))))))
508
509 ;; Setting process-setup-function makes exit-message-function work
510 ;; even when async processes aren't supported.
511 (let ((compilation-process-setup-function 'grep-process-setup))
512 (compilation-start (if (and grep-use-null-device null-device)
513 (concat command-args " " null-device)
514 command-args)
515 'grep-mode nil highlight-regexp)))
516
517 (define-compilation-mode grep-mode "Grep"
518 "Sets `grep-last-buffer' and `compilation-window-height'."
519 (setq grep-last-buffer (current-buffer))
520 (set (make-local-variable 'compilation-error-face)
521 grep-hit-face)
522 (set (make-local-variable 'compilation-error-regexp-alist)
523 grep-regexp-alist)
524 ;; Set `font-lock-lines-before' to 0 to not refontify the previous
525 ;; line where grep markers may be already removed.
526 (set (make-local-variable 'font-lock-lines-before) 0))
527
528 ;;;###autoload
529 (defun grep-find (command-args)
530 "Run grep via find, with user-specified args COMMAND-ARGS.
531 Collect output in a buffer.
532 While find runs asynchronously, you can use the \\[next-error] command
533 to find the text that grep hits refer to.
534
535 This command uses a special history list for its arguments, so you can
536 easily repeat a find command."
537 (interactive
538 (progn
539 (unless (and grep-command
540 (or (not grep-use-null-device) (eq grep-use-null-device t)))
541 (grep-compute-defaults))
542 (if grep-find-command
543 (list (read-from-minibuffer "Run find (like this): "
544 grep-find-command nil nil
545 'grep-find-history))
546 ;; No default was set
547 (read-string
548 "compile.el: No `grep-find-command' command available. Press RET.")
549 (list nil))))
550 (when (and grep-find-command command-args)
551 (let ((null-device nil)) ; see grep
552 (grep command-args))))
553
554 ;;;###autoload
555 (defalias 'find-grep 'grep-find)
556
557 (defun grep-expand-command-macros (command &optional regexp files dir excl case-fold)
558 "Patch grep COMMAND replacing <D>, etc."
559 (setq command
560 (replace-regexp-in-string "<D>"
561 (or dir ".") command t t))
562 (setq command
563 (replace-regexp-in-string "<X>"
564 (or excl "") command t t))
565 (setq command
566 (replace-regexp-in-string "<F>"
567 (or files "") command t t))
568 (setq command
569 (replace-regexp-in-string "<C>"
570 (if case-fold "-i" "") command t t))
571 (setq command
572 (replace-regexp-in-string "<R>"
573 (or regexp "") command t t))
574 command)
575
576 (defvar grep-tree-last-regexp "")
577 (defvar grep-tree-last-files (car (car grep-tree-files-aliases)))
578
579 ;;;###autoload
580 (defun grep-tree (regexp files dir &optional subdirs)
581 "Grep for REGEXP in FILES in directory tree rooted at DIR.
582 Collect output in a buffer.
583 Interactively, prompt separately for each search parameter.
584 With prefix arg, reuse previous REGEXP.
585 The search is limited to file names matching shell pattern FILES.
586 FILES may use abbreviations defined in `grep-tree-files-aliases', e.g.
587 entering `ch' is equivalent to `*.[ch]'.
588
589 While find runs asynchronously, you can use the \\[next-error] command
590 to find the text that grep hits refer to.
591
592 This command uses a special history list for its arguments, so you can
593 easily repeat a find command.
594
595 When used non-interactively, optional arg SUBDIRS limits the search to
596 those sub directories of DIR."
597 (interactive
598 (let* ((regexp
599 (if current-prefix-arg
600 grep-tree-last-regexp
601 (let* ((default (current-word))
602 (spec (read-string
603 (concat "Search for"
604 (if (and default (> (length default) 0))
605 (format " (default %s): " default) ": ")))))
606 (if (equal spec "") default spec))))
607 (files
608 (read-string (concat "Search for \"" regexp "\" in files (default " grep-tree-last-files "): ")))
609 (dir
610 (read-directory-name "Base directory: " nil default-directory t)))
611 (list regexp files dir)))
612 (unless grep-tree-command
613 (grep-compute-defaults))
614 (unless (and (stringp files) (> (length files) 0))
615 (setq files grep-tree-last-files))
616 (when files
617 (setq grep-tree-last-files files)
618 (let ((mf (assoc files grep-tree-files-aliases)))
619 (if mf
620 (setq files (cdr mf)))))
621 (let ((command-args (grep-expand-command-macros
622 grep-tree-command
623 (setq grep-tree-last-regexp regexp)
624 (and files (concat "-name '" files "'"))
625 (if subdirs
626 (if (stringp subdirs)
627 subdirs
628 (mapconcat 'identity subdirs " "))
629 nil) ;; we change default-directory to dir
630 (and grep-tree-ignore-CVS-directories "-path '*/CVS' -prune -o ")
631 grep-tree-ignore-case))
632 (default-directory (file-name-as-directory (expand-file-name dir)))
633 (null-device nil)) ; see grep
634 (grep command-args regexp)))
635
636
637 (provide 'grep)
638
639 ;; arch-tag: 5a5b9169-a79d-4f38-9c38-f69615f39c4d
640 ;;; grep.el ends here