- (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
- (equal (call-process "find" nil nil nil
- null-device "-print0")
- 0)
- (equal (call-process "xargs" nil nil nil
- "-0" "-e" "echo")
- 0))
- 'gnu)))
- (unless grep-find-command
- (setq grep-find-command
- (cond ((eq grep-find-use-xargs 'gnu)
- (format "%s . -type f -print0 | xargs -0 -e %s"
- find-program grep-command))
- (grep-find-use-xargs
- (format "%s . -type f -print | xargs %s"
- find-program grep-command))
- (t (cons (format "%s . -type f -exec %s {} %s \\;"
- find-program grep-command null-device)
- (+ 22 (length grep-command)))))))
- (unless grep-tree-command
- (setq grep-tree-command
- (let* ((glen (length grep-program))
- (gcmd (concat grep-program " <C>" (substring grep-command glen))))
- (cond ((eq grep-find-use-xargs 'gnu)
- (format "%s <D> <X> -type f <F> -print0 | xargs -0 -e %s <R>"
- find-program gcmd))
- (grep-find-use-xargs
- (format "%s <D> <X> -type f <F> -print | xargs %s <R>"
- find-program gcmd))
- (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;"
- find-program gcmd null-device)))))))
+ (or (cadr (assq 'grep-command host-defaults))
+ (cadr (assq 'grep-command defaults)))
+
+ grep-template
+ (or (cadr (assq 'grep-template host-defaults))
+ (cadr (assq 'grep-template defaults)))
+
+ grep-use-null-device
+ (or (cadr (assq 'grep-use-null-device host-defaults))
+ (cadr (assq 'grep-use-null-device defaults)))
+
+ grep-find-command
+ (or (cadr (assq 'grep-find-command host-defaults))
+ (cadr (assq 'grep-find-command defaults)))
+
+ grep-find-template
+ (or (cadr (assq 'grep-find-template host-defaults))
+ (cadr (assq 'grep-find-template defaults)))
+
+ grep-find-use-xargs
+ (or (cadr (assq 'grep-find-use-xargs host-defaults))
+ (cadr (assq 'grep-find-use-xargs defaults)))
+
+ grep-highlight-matches
+ (or (cadr (assq 'grep-highlight-matches host-defaults))
+ (cadr (assq 'grep-highlight-matches 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 (if grep-command
+ ;; `grep-command' is already set, so
+ ;; use that for testing.
+ (grep-probe grep-command
+ `(nil t nil "^English" ,hello-file)
+ #'call-process-shell-command)
+ ;; otherwise use `grep-program'
+ (grep-probe grep-program
+ `(nil t nil "-nH" "^English" ,hello-file)))
+ (progn
+ (goto-char (point-min))
+ (looking-at
+ (concat (regexp-quote hello-file)
+ ":[0-9]+:English")))))))))
+ (unless (and grep-command grep-find-command
+ grep-template grep-find-template)
+ (let ((grep-options
+ (concat (if grep-use-null-device "-n" "-nH")
+ (if (grep-probe grep-program
+ `(nil nil nil "-e" "foo" ,null-device)
+ nil 1)
+ " -e"))))
+ (unless grep-command
+ (setq grep-command
+ (format "%s %s " grep-program grep-options)))
+ (unless grep-template
+ (setq grep-template
+ (format "%s <C> %s <R> <F>" grep-program grep-options)))
+ (unless grep-find-use-xargs
+ (setq grep-find-use-xargs
+ (cond
+ ((and
+ (grep-probe find-program `(nil nil nil ,null-device "-print0"))
+ (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo")))
+ 'gnu)
+ (t
+ 'exec))))
+ (unless grep-find-command
+ (setq grep-find-command
+ (cond ((eq grep-find-use-xargs 'gnu)
+ (format "%s . -type f -print0 | xargs -0 -e %s"
+ find-program grep-command))
+ ((eq grep-find-use-xargs 'exec)
+ (let ((cmd0 (format "%s . -type f -exec %s"
+ find-program grep-command)))
+ (cons
+ (format "%s {} %s %s"
+ cmd0 null-device
+ (shell-quote-argument ";"))
+ (1+ (length cmd0)))))
+ (t
+ (format "%s . -type f -print | xargs %s"
+ find-program grep-command)))))
+ (unless grep-find-template
+ (setq grep-find-template
+ (let ((gcmd (format "%s <C> %s <R>"
+ grep-program grep-options)))
+ (cond ((eq grep-find-use-xargs 'gnu)
+ (format "%s . <X> -type f <F> -print0 | xargs -0 -e %s"
+ find-program gcmd))
+ ((eq grep-find-use-xargs 'exec)
+ (format "%s . <X> -type f <F> -exec %s {} %s %s"
+ find-program gcmd null-device
+ (shell-quote-argument ";")))
+ (t
+ (format "%s . <X> -type f <F> -print | xargs %s"
+ find-program gcmd))))))))
+ (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
+ (setq grep-highlight-matches
+ (with-temp-buffer
+ (and (grep-probe grep-program '(nil t nil "--help"))
+ (progn
+ (goto-char (point-min))
+ (search-forward "--color" nil t))
+ t))))
+
+ ;; Save defaults for this host.
+ (setq grep-host-defaults-alist
+ (delete (assq host-id grep-host-defaults-alist)
+ grep-host-defaults-alist))
+ (add-to-list
+ 'grep-host-defaults-alist
+ (cons host-id
+ `((grep-command ,grep-command)
+ (grep-template ,grep-template)
+ (grep-use-null-device ,grep-use-null-device)
+ (grep-find-command ,grep-find-command)
+ (grep-find-template ,grep-find-template)
+ (grep-find-use-xargs ,grep-find-use-xargs)
+ (grep-highlight-matches ,grep-highlight-matches))))))
+
+(defun grep-tag-default ()
+ (or (and transient-mark-mode mark-active
+ (/= (point) (mark))
+ (buffer-substring-no-properties (point) (mark)))
+ (funcall (or find-tag-default-function
+ (get major-mode 'find-tag-default-function)
+ 'find-tag-default))
+ ""))