comparison lisp/progmodes/compile.el @ 39599:56800ba6a856

(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.
author Miles Bader <miles@gnu.org>
date Fri, 05 Oct 2001 12:30:52 +0000
parents d599e4f7047f
children 8c4c4c89b007
comparison
equal deleted inserted replaced
39598:67884544e4c8 39599:56800ba6a856
65 (integer :tag "First N lines")) 65 (integer :tag "First N lines"))
66 :group 'compilation) 66 :group 'compilation)
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].
70 If the grep program used supports an option to always include file names
71 in its output (such as the `-H' option to GNU grep), it's a good idea to
72 include it when specifying `grep-command'.
73
70 The default value of this variable is set up by `grep-compute-defaults'; 74 The default value of this variable is set up by `grep-compute-defaults';
71 call that function before using this variable in your program." 75 call that function before using this variable in your program."
72 :type 'string 76 :type 'string
73 :get '(lambda (symbol) 77 :get '(lambda (symbol)
74 (or grep-command 78 (or grep-command
75 (progn (grep-compute-defaults) grep-command))) 79 (progn (grep-compute-defaults) grep-command)))
80 :group 'compilation)
81
82 (defcustom grep-use-null-device 'auto-detect
83 "If non-nil, append the value of `null-device' to grep commands.
84 This is done to ensure that the output of grep includes the filename of
85 any match in the case where only a single file is searched, and is not
86 necessary if the grep program used supports the `-H' option.
87
88 The default value of this variable is set up by `grep-compute-defaults';
89 call 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))
76 :group 'compilation) 95 :group 'compilation)
77 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].
80 The default value of this variable is set up by `grep-compute-defaults'; 99 The default value of this variable is set up by `grep-compute-defaults';
572 (t 591 (t
573 (cons msg code))) 592 (cons msg code)))
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
589 (equal (call-process "find" nil nil nil 631 (equal (call-process "find" nil nil nil
590 null-device "-print0") 632 null-device "-print0")
620 tag the cursor is over, substituting it into the last grep command 662 tag the cursor is over, substituting it into the last grep command
621 in the grep command history (or into `grep-command' 663 in the grep command history (or into `grep-command'
622 if that history list is empty)." 664 if 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
629 (funcall (or find-tag-default-function 672 (funcall (or find-tag-default-function
630 (get major-mode 'find-tag-default-function) 673 (get major-mode 'find-tag-default-function)
644 nil nil 'grep-history)))) 687 nil nil 'grep-history))))
645 688
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"
653 ;; Give it a simpler regexp to match. 696 ;; Give it a simpler regexp to match.
654 nil grep-regexp-alist))))) 697 nil grep-regexp-alist)))))