aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2001-10-05 12:30:52 +0000
committerMiles Bader2001-10-05 12:30:52 +0000
commita45717daf6af760a60569d1dfd5290750b05501a (patch)
treea2eb021b54ff42ed9eae51b8f17f3f62278b5262
parent93aca633e14ebd09a0056c8e62e7e55721124619 (diff)
downloademacs-a45717daf6af760a60569d1dfd5290750b05501a.tar.gz
emacs-a45717daf6af760a60569d1dfd5290750b05501a.zip
(grep-use-null-device): New variable.
(grep-command): Mention `grep-use-null-device'. (grep-compute-defaults): Compute `grep-use-null-device' if necessary. Make computation of `grep-command' respect `grep-use-null-device'. (grep): Respect `grep-use-null-device'. Call `grep-compute-defaults' even if grep-command is set, if grep-use-null-device is still tentative.
-rw-r--r--lisp/progmodes/compile.el61
1 files changed, 52 insertions, 9 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 769c356449f..27fbe66fe86 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -67,6 +67,10 @@ will be parsed and highlighted as soon as you try to move to them."
67 67
68(defcustom grep-command nil 68(defcustom grep-command nil
69 "The default grep command for \\[grep]. 69 "The default grep command for \\[grep].
70If the grep program used supports an option to always include file names
71in its output (such as the `-H' option to GNU grep), it's a good idea to
72include it when specifying `grep-command'.
73
70The default value of this variable is set up by `grep-compute-defaults'; 74The default value of this variable is set up by `grep-compute-defaults';
71call that function before using this variable in your program." 75call that function before using this variable in your program."
72 :type 'string 76 :type 'string
@@ -75,6 +79,21 @@ call that function before using this variable in your program."
75 (progn (grep-compute-defaults) grep-command))) 79 (progn (grep-compute-defaults) grep-command)))
76 :group 'compilation) 80 :group 'compilation)
77 81
82(defcustom grep-use-null-device 'auto-detect
83 "If non-nil, append the value of `null-device' to grep commands.
84This is done to ensure that the output of grep includes the filename of
85any match in the case where only a single file is searched, and is not
86necessary if the grep program used supports the `-H' option.
87
88The default value of this variable is set up by `grep-compute-defaults';
89call that function before using this variable in your program."
90 :type 'boolean
91 :get '(lambda (symbol)
92 (if (and grep-use-null-device (not (eq grep-use-null-device t)))
93 (progn (grep-compute-defaults) grep-use-null-device)
94 grep-use-null-device))
95 :group 'compilation)
96
78(defcustom grep-find-command nil 97(defcustom grep-find-command nil
79 "The default find command for \\[grep-find]. 98 "The default find command for \\[grep-find].
80The default value of this variable is set up by `grep-compute-defaults'; 99The default value of this variable is set up by `grep-compute-defaults';
@@ -574,15 +593,38 @@ to a function that generates a unique name."
574 (cons msg code))))) 593 (cons msg code)))))
575 594
576(defun grep-compute-defaults () 595(defun grep-compute-defaults ()
596 (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
597 (setq grep-use-null-device
598 (with-temp-buffer
599 (let ((hello-file (expand-file-name "HELLO" data-directory)))
600 (not
601 (and (equal (condition-case nil
602 (if grep-command
603 ;; `grep-command' is already set, so
604 ;; use that for testing.
605 (call-process-shell-command
606 grep-command nil t nil
607 "^English" hello-file)
608 ;; otherwise use `grep-program'
609 (call-process grep-program nil t nil
610 "-nH" "^English" hello-file))
611 (error nil))
612 0)
613 (progn
614 (goto-char (point-min))
615 (looking-at
616 (concat (regexp-quote hello-file)
617 ":[0-9]+:English")))))))))
577 (unless grep-command 618 (unless grep-command
578 (setq grep-command 619 (setq grep-command
579 (if (equal (condition-case nil ; in case "grep" isn't in exec-path 620 (let ((required-options (if grep-use-null-device "-n" "-nH")))
580 (call-process grep-program nil nil nil 621 (if (equal (condition-case nil ; in case "grep" isn't in exec-path
581 "-e" "foo" null-device) 622 (call-process grep-program nil nil nil
582 (error nil)) 623 "-e" "foo" null-device)
583 1) 624 (error nil))
584 (format "%s -n -e " grep-program) 625 1)
585 (format "%s -n " grep-program)))) 626 (format "%s %s -e " grep-program required-options)
627 (format "%s %s " grep-program required-options)))))
586 (unless grep-find-use-xargs 628 (unless grep-find-use-xargs
587 (setq grep-find-use-xargs 629 (setq grep-find-use-xargs
588 (if (and 630 (if (and
@@ -622,7 +664,8 @@ in the grep command history (or into `grep-command'
622if that history list is empty)." 664if that history list is empty)."
623 (interactive 665 (interactive
624 (let (grep-default (arg current-prefix-arg)) 666 (let (grep-default (arg current-prefix-arg))
625 (unless grep-command 667 (unless (and grep-command
668 (or (not grep-use-null-device) (eq grep-use-null-device t)))
626 (grep-compute-defaults)) 669 (grep-compute-defaults))
627 (when arg 670 (when arg
628 (let ((tag-default 671 (let ((tag-default
@@ -646,7 +689,7 @@ if that history list is empty)."
646 ;; Setting process-setup-function makes exit-message-function work 689 ;; Setting process-setup-function makes exit-message-function work
647 ;; even when async processes aren't supported. 690 ;; even when async processes aren't supported.
648 (let* ((compilation-process-setup-function 'grep-process-setup) 691 (let* ((compilation-process-setup-function 'grep-process-setup)
649 (buf (compile-internal (if null-device 692 (buf (compile-internal (if (and grep-use-null-device null-device)
650 (concat command-args " " null-device) 693 (concat command-args " " null-device)
651 command-args) 694 command-args)
652 "No more grep hits" "grep" 695 "No more grep hits" "grep"