diff options
| author | Richard M. Stallman | 1998-06-23 15:51:47 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-06-23 15:51:47 +0000 |
| commit | 1ffddaf4d4c079452ac0b5f935cef2281a99780e (patch) | |
| tree | 1e43544e7e2f3f0ab1b8f4d2988c24602455e51a | |
| parent | b296cbd4abf9a9b203f0a57d5d06f5c01fa8ee93 (diff) | |
| download | emacs-1ffddaf4d4c079452ac0b5f935cef2281a99780e.tar.gz emacs-1ffddaf4d4c079452ac0b5f935cef2281a99780e.zip | |
(grep-command): Initialize to nil.
(grep-find-command): Initialize to nil.
(grep-find-use-xargs): Initialize to nil.
(grep-compute-defaults): New function, sets those three vars properly.
(grep, grep-find): Call grep-compute-defaults if ...command variable
is still nil.
(grep-program): Doc fix.
| -rw-r--r-- | lisp/progmodes/compile.el | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 8ac326dee46..92ff015f28f 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el | |||
| @@ -381,42 +381,28 @@ Otherwise, it saves all modified buffers without asking." | |||
| 381 | ;;; 1) | 381 | ;;; 1) |
| 382 | ;;; "zgrep" | 382 | ;;; "zgrep" |
| 383 | ;;; "grep") | 383 | ;;; "grep") |
| 384 | "The default grep program for `grep-command' and `grep-find-command'.") | 384 | "The default grep program for `grep-command' and `grep-find-command'. |
| 385 | This variable's value takes effect when `grep-compute-defaults' is called.") | ||
| 385 | 386 | ||
| 386 | ;; Use -e if grep supports it, | 387 | ;; Use -e if grep supports it, |
| 387 | ;; because that avoids lossage if the pattern starts with `-'. | 388 | ;; because that avoids lossage if the pattern starts with `-'. |
| 388 | (defvar grep-command | 389 | (defvar grep-command nil |
| 389 | (if (equal (condition-case nil ; in case "grep" isn't in exec-path | 390 | "The default grep command for \\[grep]. |
| 390 | (call-process grep-program nil nil nil | 391 | The real default value of this variable is set up by `grep-compute-defaults'; |
| 391 | "-e" "foo" null-device) | 392 | call that function before using this variable.") |
| 392 | (error nil)) | 393 | |
| 393 | 1) | 394 | (defvar grep-find-use-xargs nil |
| 394 | (format "%s -n -e " grep-program) | ||
| 395 | (format "%s -n " grep-program)) | ||
| 396 | "The default grep command for \\[grep].") | ||
| 397 | |||
| 398 | (defvar grep-find-use-xargs | ||
| 399 | (if (equal (call-process "find" nil nil nil | ||
| 400 | null-device "-print0") | ||
| 401 | 0) | ||
| 402 | 'gnu) | ||
| 403 | "Whether \\[grep-find] uses the `xargs' utility by default. | 395 | "Whether \\[grep-find] uses the `xargs' utility by default. |
| 404 | 396 | ||
| 405 | If nil, it uses `grep -exec'; if `gnu', it uses `find -print0' and `xargs -0'; | 397 | If nil, it uses `grep -exec'; if `gnu', it uses `find -print0' and `xargs -0'; |
| 406 | if not nil and not `gnu', it uses `find -print' and `xargs'. | 398 | if not nil and not `gnu', it uses `find -print' and `xargs'. |
| 407 | 399 | ||
| 408 | This variable's value takes effect when `compile.el' is loaded | 400 | This variable's value takes effect when `grep-compute-defaults' is called.") |
| 409 | by influencing the default value for the variable `grep-find-command'.") | ||
| 410 | 401 | ||
| 411 | (defvar grep-find-command | 402 | (defvar grep-find-command nil |
| 412 | (cond ((eq grep-find-use-xargs 'gnu) | 403 | "The default find command for \\[grep-find]. |
| 413 | (format "find . -type f -print0 | xargs -0 -e %s" grep-command)) | 404 | The default value of this variable is set up by `grep-compute-defaults'; |
| 414 | (grep-find-use-xargs | 405 | call that function before using this variable.") |
| 415 | (format "find . -type f -print | xargs %s" grep-command)) | ||
| 416 | (t (cons (format "find . -type f -exec %s {} /dev/null \\;" | ||
| 417 | grep-command) | ||
| 418 | (+ 22 (length grep-command))))) | ||
| 419 | "The default find command for \\[grep-find].") | ||
| 420 | 406 | ||
| 421 | ;;;###autoload | 407 | ;;;###autoload |
| 422 | (defcustom compilation-search-path '(nil) | 408 | (defcustom compilation-search-path '(nil) |
| @@ -543,6 +529,31 @@ to a function that generates a unique name." | |||
| 543 | (cons msg code))) | 529 | (cons msg code))) |
| 544 | (cons msg code))))) | 530 | (cons msg code))))) |
| 545 | 531 | ||
| 532 | (defun grep-compute-defaults () | ||
| 533 | (setq grep-command | ||
| 534 | (if (equal (condition-case nil ; in case "grep" isn't in exec-path | ||
| 535 | (call-process grep-program nil nil nil | ||
| 536 | "-e" "foo" null-device) | ||
| 537 | (error nil)) | ||
| 538 | 1) | ||
| 539 | (format "%s -n -e " grep-program) | ||
| 540 | (format "%s -n " grep-program))) | ||
| 541 | (unless grep-find-use-xargs | ||
| 542 | (setq grep-find-use-xargs | ||
| 543 | (if (equal (call-process "find" nil nil nil | ||
| 544 | null-device "-print0") | ||
| 545 | 0) | ||
| 546 | 'gnu))) | ||
| 547 | (setq grep-find-command | ||
| 548 | (cond ((eq grep-find-use-xargs 'gnu) | ||
| 549 | (format "find . -type f -print0 | xargs -0 -e %s" | ||
| 550 | grep-command)) | ||
| 551 | (grep-find-use-xargs | ||
| 552 | (format "find . -type f -print | xargs %s" grep-command)) | ||
| 553 | (t (cons (format "find . -type f -exec %s {} /dev/null \\;" | ||
| 554 | grep-command) | ||
| 555 | (+ 22 (length grep-command))))))) | ||
| 556 | |||
| 546 | ;;;###autoload | 557 | ;;;###autoload |
| 547 | (defun grep (command-args) | 558 | (defun grep (command-args) |
| 548 | "Run grep, with user-specified args, and collect output in a buffer. | 559 | "Run grep, with user-specified args, and collect output in a buffer. |
| @@ -558,6 +569,8 @@ in the grep command history (or into `grep-command' | |||
| 558 | if that history list is empty)." | 569 | if that history list is empty)." |
| 559 | (interactive | 570 | (interactive |
| 560 | (let (grep-default (arg current-prefix-arg)) | 571 | (let (grep-default (arg current-prefix-arg)) |
| 572 | (unless grep-command | ||
| 573 | (grep-compute-defaults)) | ||
| 561 | (when arg | 574 | (when arg |
| 562 | (let* ((tag-default | 575 | (let* ((tag-default |
| 563 | (funcall (or find-tag-default-function | 576 | (funcall (or find-tag-default-function |
| @@ -611,8 +624,12 @@ to find the text that grep hits refer to. | |||
| 611 | This command uses a special history list for its arguments, so you can | 624 | This command uses a special history list for its arguments, so you can |
| 612 | easily repeat a find command." | 625 | easily repeat a find command." |
| 613 | (interactive | 626 | (interactive |
| 614 | (list (read-from-minibuffer "Run find (like this): " | 627 | (progn |
| 615 | grep-find-command nil nil 'grep-find-history))) | 628 | (unless grep-find-command |
| 629 | (grep-compute-defaults)) | ||
| 630 | (list (read-from-minibuffer "Run find (like this): " | ||
| 631 | grep-find-command nil nil | ||
| 632 | 'grep-find-history)))) | ||
| 616 | (let ((null-device nil)) ; see grep | 633 | (let ((null-device nil)) ; see grep |
| 617 | (grep command-args))) | 634 | (grep command-args))) |
| 618 | 635 | ||