- (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
- (if (and
+ ;; Keep default values.
+ (unless grep-host-defaults-alist
+ (add-to-list
+ 'grep-host-defaults-alist
+ (cons nil
+ `((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)))))
+ (let* ((host-id
+ (intern (or (file-remote-p default-directory 'host) "localhost")))
+ (host-defaults (assq host-id grep-host-defaults-alist))
+ (defaults (assq nil grep-host-defaults-alist)))
+ ;; There are different defaults on different hosts. They must be
+ ;; computed for every host once.
+ (setq grep-command
+ (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