From: Miles Bader Date: Fri, 5 Oct 2001 12:30:52 +0000 (+0000) Subject: (grep-use-null-device): New variable. X-Git-Tag: ttn-vms-21-2-B4~19718 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a45717daf6af760a60569d1dfd5290750b05501a;p=emacs.git (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. --- 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." (defcustom grep-command nil "The default grep command for \\[grep]. +If the grep program used supports an option to always include file names +in its output (such as the `-H' option to GNU grep), it's a good idea to +include it when specifying `grep-command'. + The default value of this variable is set up by `grep-compute-defaults'; call that function before using this variable in your program." :type 'string @@ -75,6 +79,21 @@ call that function before using this variable in your program." (progn (grep-compute-defaults) grep-command))) :group 'compilation) +(defcustom grep-use-null-device 'auto-detect + "If non-nil, append the value of `null-device' to grep commands. +This is done to ensure that the output of grep includes the filename of +any match in the case where only a single file is searched, and is not +necessary if the grep program used supports the `-H' option. + +The default value of this variable is set up by `grep-compute-defaults'; +call that function before using this variable in your program." + :type 'boolean + :get '(lambda (symbol) + (if (and grep-use-null-device (not (eq grep-use-null-device t))) + (progn (grep-compute-defaults) grep-use-null-device) + grep-use-null-device)) + :group 'compilation) + (defcustom grep-find-command nil "The default find command for \\[grep-find]. The default value of this variable is set up by `grep-compute-defaults'; @@ -574,15 +593,38 @@ to a function that generates a unique name." (cons msg code))))) (defun grep-compute-defaults () + (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) + (setq grep-use-null-device + (with-temp-buffer + (let ((hello-file (expand-file-name "HELLO" data-directory))) + (not + (and (equal (condition-case nil + (if grep-command + ;; `grep-command' is already set, so + ;; use that for testing. + (call-process-shell-command + grep-command nil t nil + "^English" hello-file) + ;; otherwise use `grep-program' + (call-process grep-program nil t nil + "-nH" "^English" hello-file)) + (error nil)) + 0) + (progn + (goto-char (point-min)) + (looking-at + (concat (regexp-quote hello-file) + ":[0-9]+:English"))))))))) (unless grep-command (setq grep-command - (if (equal (condition-case nil ; in case "grep" isn't in exec-path - (call-process grep-program nil nil nil - "-e" "foo" null-device) - (error nil)) - 1) - (format "%s -n -e " grep-program) - (format "%s -n " grep-program)))) + (let ((required-options (if grep-use-null-device "-n" "-nH"))) + (if (equal (condition-case nil ; in case "grep" isn't in exec-path + (call-process grep-program nil nil nil + "-e" "foo" null-device) + (error nil)) + 1) + (format "%s %s -e " grep-program required-options) + (format "%s %s " grep-program required-options))))) (unless grep-find-use-xargs (setq grep-find-use-xargs (if (and @@ -622,7 +664,8 @@ in the grep command history (or into `grep-command' if that history list is empty)." (interactive (let (grep-default (arg current-prefix-arg)) - (unless grep-command + (unless (and grep-command + (or (not grep-use-null-device) (eq grep-use-null-device t))) (grep-compute-defaults)) (when arg (let ((tag-default @@ -646,7 +689,7 @@ if that history list is empty)." ;; Setting process-setup-function makes exit-message-function work ;; even when async processes aren't supported. (let* ((compilation-process-setup-function 'grep-process-setup) - (buf (compile-internal (if null-device + (buf (compile-internal (if (and grep-use-null-device null-device) (concat command-args " " null-device) command-args) "No more grep hits" "grep"