--- grep.el.orig 2006-08-22 18:24:34.734375000 +0100 +++ grep.el 2006-08-22 19:55:58.703125000 +0100 @@ -335,10 +335,18 @@ (defvar grep-find-use-xargs nil "Whether \\[grep-find] uses the `xargs' utility by default. -If nil, it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0'; -if not nil and not `gnu', it uses `find -print' and `xargs'. +If `no', it uses `find -exec'; if `gnu', it uses `find -print0' +and `xargs -0'; if `yes', it uses `find -print' and `xargs'. -This variable's value takes effect when `grep-compute-defaults' is called.") +This variable's value takes effect when `grep-compute-defaults' +is called. + +\(For backwards compatibility, if `grep-find-use-xargs' is nil, +`grep-compute-defaults' will set it to one of `gnu' or `no'; or, +if `grep-find-use-xargs' is non-nil, but not one of the valid +settings, `grep-compute-defaults' will set it to `yes'.\) + +") ;; History of grep commands. ;;;###autoload @@ -382,6 +390,7 @@ (error nil)) (or result 0))) + ;;;###autoload (defun grep-compute-defaults () (unless (or (not grep-use-null-device) (eq grep-use-null-device t)) @@ -417,23 +426,39 @@ (unless grep-template (setq grep-template (format "%s %s " grep-program grep-options))) - (unless grep-find-use-xargs - (setq grep-find-use-xargs - (if (and - (grep-probe find-program `(nil nil nil ,null-device "-print0")) - (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo"))) - 'gnu))) + ;; "Normalize" `grep-find-use-xargs'. Hardly ideal, but + ;; preserves the previous behaviour (unless 'no was being as the + ;; non-null value of course). + ;; + ;; Presumably keeping nil to mean 'auto-detect' is desirable? + (setq grep-find-use-xargs + (cond ((null grep-find-use-xargs) + (if (and + (grep-probe find-program `(nil nil nil ,null-device "-print0")) + (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo"))) + 'gnu + 'no)) + ((not (or (eq grep-find-use-xargs 'gnu) + (eq grep-find-use-xargs 'no))) + 'yes) + (t + 'no))) (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 + ((eq grep-find-use-xargs 'yes) (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))))))) + ((eq grep-find-use-xargs 'no) + (let ((command (format "%s . -type f -exec %s {} %s %s" + find-program grep-command null-device (shell-quote-argument ";")))) + (cons command + (+ (string-match (regexp-quote grep-command) + command) + (length grep-command) + 1))))))) (unless grep-find-template (setq grep-find-template (let ((gcmd (format "%s %s " @@ -441,11 +466,12 @@ (cond ((eq grep-find-use-xargs 'gnu) (format "%s . -type f -print0 | xargs -0 -e %s" find-program gcmd)) - (grep-find-use-xargs + ((eq grep-find-use-xargs 'yes) (format "%s . -type f -print | xargs %s" find-program gcmd)) - (t (format "%s . -type f -exec %s {} %s \\;" - find-program gcmd null-device)))))))) + ((eq grep-find-use-xargs 'no) + (format "%s . -type f -exec %s {} %s %s" + find-program gcmd null-device (shell-quote-argument ";"))))))))) (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) (setq grep-highlight-matches (with-temp-buffer @@ -736,18 +762,23 @@ (let ((command (grep-expand-template grep-find-template regexp - (concat "\\( -name " + (concat (shell-quote-argument "(") + " -name " (mapconcat #'shell-quote-argument (split-string files) " -o -name ") - " \\)") + " " + (shell-quote-argument ")")) dir (and grep-find-ignored-directories - (concat "\\( -path '*/" + (concat (shell-quote-argument "(") + " -path '*/" (mapconcat #'identity grep-find-ignored-directories "' -o -path '*/") - "' \\) -prune -o "))))) + "' " + (shell-quote-argument ")") + " -prune -o "))))); (when command (if current-prefix-arg (setq command