comparison lisp/progmodes/grep.el @ 86249:ef17406635fe

(xargs-program): New variable. (grep-compute-defaults): Use it. (grep-default-command): Doc fix. (grep, lgrep, rgrep): Reflow docstrings.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 20 Nov 2007 16:38:23 +0000
parents d1d369daf8dd
children 29047758dd89
comparison
equal deleted inserted replaced
86248:cde7fc4f5945 86249:ef17406635fe
328 This variable's value takes effect when `grep-compute-defaults' is called.") 328 This variable's value takes effect when `grep-compute-defaults' is called.")
329 329
330 ;;;###autoload 330 ;;;###autoload
331 (defvar find-program "find" 331 (defvar find-program "find"
332 "The default find program for `grep-find-command'. 332 "The default find program for `grep-find-command'.
333 This variable's value takes effect when `grep-compute-defaults' is called.")
334
335 ;;;###autoload
336 (defvar xargs-program "xargs"
337 "The default xargs program for `grep-find-command'.
338 See `grep-find-use-xargs'.
333 This variable's value takes effect when `grep-compute-defaults' is called.") 339 This variable's value takes effect when `grep-compute-defaults' is called.")
334 340
335 ;;;###autoload 341 ;;;###autoload
336 (defvar grep-find-use-xargs nil 342 (defvar grep-find-use-xargs nil
337 "Non-nil means that `grep-find' uses the `xargs' utility by default. 343 "Non-nil means that `grep-find' uses the `xargs' utility by default.
473 (unless grep-find-use-xargs 479 (unless grep-find-use-xargs
474 (setq grep-find-use-xargs 480 (setq grep-find-use-xargs
475 (cond 481 (cond
476 ((and 482 ((and
477 (grep-probe find-program `(nil nil nil ,null-device "-print0")) 483 (grep-probe find-program `(nil nil nil ,null-device "-print0"))
478 (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo"))) 484 (grep-probe xargs-program `(nil nil nil "-0" "-e" "echo")))
479 'gnu) 485 'gnu)
480 (t 486 (t
481 'exec)))) 487 'exec))))
482 (unless grep-find-command 488 (unless grep-find-command
483 (setq grep-find-command 489 (setq grep-find-command
484 (cond ((eq grep-find-use-xargs 'gnu) 490 (cond ((eq grep-find-use-xargs 'gnu)
485 (format "%s . -type f -print0 | xargs -0 -e %s" 491 (format "%s . -type f -print0 | %s -0 -e %s"
486 find-program grep-command)) 492 find-program xargs-program grep-command))
487 ((eq grep-find-use-xargs 'exec) 493 ((eq grep-find-use-xargs 'exec)
488 (let ((cmd0 (format "%s . -type f -exec %s" 494 (let ((cmd0 (format "%s . -type f -exec %s"
489 find-program grep-command))) 495 find-program grep-command)))
490 (cons 496 (cons
491 (format "%s {} %s %s" 497 (format "%s {} %s %s"
492 cmd0 null-device 498 cmd0 null-device
493 (shell-quote-argument ";")) 499 (shell-quote-argument ";"))
494 (1+ (length cmd0))))) 500 (1+ (length cmd0)))))
495 (t 501 (t
496 (format "%s . -type f -print | xargs %s" 502 (format "%s . -type f -print | %s %s"
497 find-program grep-command))))) 503 find-program xargs-program grep-command)))))
498 (unless grep-find-template 504 (unless grep-find-template
499 (setq grep-find-template 505 (setq grep-find-template
500 (let ((gcmd (format "%s <C> %s <R>" 506 (let ((gcmd (format "%s <C> %s <R>"
501 grep-program grep-options))) 507 grep-program grep-options)))
502 (cond ((eq grep-find-use-xargs 'gnu) 508 (cond ((eq grep-find-use-xargs 'gnu)
503 (format "%s . <X> -type f <F> -print0 | xargs -0 -e %s" 509 (format "%s . <X> -type f <F> -print0 | %s -0 -e %s"
504 find-program gcmd)) 510 find-program xargs-program gcmd))
505 ((eq grep-find-use-xargs 'exec) 511 ((eq grep-find-use-xargs 'exec)
506 (format "%s . <X> -type f <F> -exec %s {} %s %s" 512 (format "%s . <X> -type f <F> -exec %s {} %s %s"
507 find-program gcmd null-device 513 find-program gcmd null-device
508 (shell-quote-argument ";"))) 514 (shell-quote-argument ";")))
509 (t 515 (t
510 (format "%s . <X> -type f <F> -print | xargs %s" 516 (format "%s . <X> -type f <F> -print | %s %s"
511 find-program gcmd)))))))) 517 find-program xargs-program gcmd))))))))
512 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) 518 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
513 (setq grep-highlight-matches 519 (setq grep-highlight-matches
514 (with-temp-buffer 520 (with-temp-buffer
515 (and (grep-probe grep-program '(nil t nil "--help")) 521 (and (grep-probe grep-program '(nil t nil "--help"))
516 (progn 522 (progn
541 (get major-mode 'find-tag-default-function) 547 (get major-mode 'find-tag-default-function)
542 'find-tag-default)) 548 'find-tag-default))
543 "")) 549 ""))
544 550
545 (defun grep-default-command () 551 (defun grep-default-command ()
546 "Compute the default grep command for C-u M-x grep to offer." 552 "Compute the default grep command for \\[universal-argument] \\[grep] to offer."
547 (let ((tag-default (shell-quote-argument (grep-tag-default))) 553 (let ((tag-default (shell-quote-argument (grep-tag-default)))
548 ;; This a regexp to match single shell arguments. 554 ;; This a regexp to match single shell arguments.
549 ;; Could someone please add comments explaining it? 555 ;; Could someone please add comments explaining it?
550 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)") 556 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
551 (grep-default (or (car grep-history) grep-command))) 557 (grep-default (or (car grep-history) grep-command)))
594 ;;;###autoload 600 ;;;###autoload
595 (defun grep (command-args) 601 (defun grep (command-args)
596 "Run grep, with user-specified args, and collect output in a buffer. 602 "Run grep, with user-specified args, and collect output in a buffer.
597 While grep runs asynchronously, you can use \\[next-error] (M-x next-error), 603 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
598 or \\<grep-mode-map>\\[compile-goto-error] in the grep \ 604 or \\<grep-mode-map>\\[compile-goto-error] in the grep \
599 output buffer, to go to the lines 605 output buffer, to go to the lines where grep
600 where grep found matches. 606 found matches.
601 607
602 For doing a recursive `grep', see the `rgrep' command. For running 608 For doing a recursive `grep', see the `rgrep' command. For running
603 `grep' in a specific directory, see `lgrep'. 609 `grep' in a specific directory, see `lgrep'.
604 610
605 This command uses a special history list for its COMMAND-ARGS, so you can 611 This command uses a special history list for its COMMAND-ARGS, so you
606 easily repeat a grep command. 612 can easily repeat a grep command.
607 613
608 A prefix argument says to default the argument based upon the current 614 A prefix argument says to default the argument based upon the current
609 tag the cursor is over, substituting it into the last grep command 615 tag the cursor is over, substituting it into the last grep command
610 in the grep command history (or into `grep-command' 616 in the grep command history (or into `grep-command' if that history
611 if that history list is empty)." 617 list is empty)."
612 (interactive 618 (interactive
613 (progn 619 (progn
614 (grep-compute-defaults) 620 (grep-compute-defaults)
615 (let ((default (grep-default-command))) 621 (let ((default (grep-default-command)))
616 (list (read-from-minibuffer "Run grep (like this): " 622 (list (read-from-minibuffer "Run grep (like this): "
734 With \\[universal-argument] prefix, you can edit the constructed shell command line 740 With \\[universal-argument] prefix, you can edit the constructed shell command line
735 before it is executed. 741 before it is executed.
736 With two \\[universal-argument] prefixes, directly edit and run `grep-command'. 742 With two \\[universal-argument] prefixes, directly edit and run `grep-command'.
737 743
738 Collect output in a buffer. While grep runs asynchronously, you 744 Collect output in a buffer. While grep runs asynchronously, you
739 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] 745 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \
740 in the grep output buffer, to go to the lines where grep found matches. 746 in the grep output buffer,
747 to go to the lines where grep found matches.
741 748
742 This command shares argument histories with \\[rgrep] and \\[grep]." 749 This command shares argument histories with \\[rgrep] and \\[grep]."
743 (interactive 750 (interactive
744 (progn 751 (progn
745 (grep-compute-defaults) 752 (grep-compute-defaults)
795 With \\[universal-argument] prefix, you can edit the constructed shell command line 802 With \\[universal-argument] prefix, you can edit the constructed shell command line
796 before it is executed. 803 before it is executed.
797 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'. 804 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'.
798 805
799 Collect output in a buffer. While find runs asynchronously, you 806 Collect output in a buffer. While find runs asynchronously, you
800 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] 807 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \
801 in the grep output buffer, to go to the lines where grep found matches. 808 in the grep output buffer,
809 to go to the lines where grep found matches.
802 810
803 This command shares argument histories with \\[lgrep] and \\[grep-find]." 811 This command shares argument histories with \\[lgrep] and \\[grep-find]."
804 (interactive 812 (interactive
805 (progn 813 (progn
806 (grep-compute-defaults) 814 (grep-compute-defaults)