aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2006-08-23 23:23:02 +0000
committerKim F. Storm2006-08-23 23:23:02 +0000
commit84d797c949018ef7f6d1289f45ca02f5e3ea1ed6 (patch)
treeef2b829a8c928f1d8f4edfc6c76ed63cd6852af4
parent74b770deae14252f357519061f630a47b11cb3cb (diff)
downloademacs-84d797c949018ef7f6d1289f45ca02f5e3ea1ed6.tar.gz
emacs-84d797c949018ef7f6d1289f45ca02f5e3ea1ed6.zip
(grep-find-use-xargs): Use explicit value `exec'
to mean "use find -exec"; nil now unambiguously means auto-detect. (grep-compute-defaults): Set grep-find-use-xargs to `exec' if not `gnu'. Use shell-quote-argument to build grep-find-command and grep-find-template. (rgrep): Use shell-quote-argument to properly quote arguments to find. Reported by Tom Seddon.
-rw-r--r--lisp/progmodes/grep.el58
1 files changed, 38 insertions, 20 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index a939d54b3c9..48692f9742f 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -335,7 +335,7 @@ This variable's value takes effect when `grep-compute-defaults' is called.")
335(defvar grep-find-use-xargs nil 335(defvar grep-find-use-xargs nil
336 "Whether \\[grep-find] uses the `xargs' utility by default. 336 "Whether \\[grep-find] uses the `xargs' utility by default.
337 337
338If nil, it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0'; 338If `exec', it uses `find -exec'; if `gnu', it uses `find -print0' and `xargs -0';
339if not nil and not `gnu', it uses `find -print' and `xargs'. 339if not nil and not `gnu', it uses `find -print' and `xargs'.
340 340
341This variable's value takes effect when `grep-compute-defaults' is called.") 341This variable's value takes effect when `grep-compute-defaults' is called.")
@@ -419,21 +419,29 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
419 (format "%s <C> %s <R> <F>" grep-program grep-options))) 419 (format "%s <C> %s <R> <F>" grep-program grep-options)))
420 (unless grep-find-use-xargs 420 (unless grep-find-use-xargs
421 (setq grep-find-use-xargs 421 (setq grep-find-use-xargs
422 (if (and 422 (cond
423 (grep-probe find-program `(nil nil nil ,null-device "-print0")) 423 ((and
424 (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo"))) 424 (grep-probe find-program `(nil nil nil ,null-device "-print0"))
425 'gnu))) 425 (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo")))
426 'gnu)
427 (t
428 'exec))))
426 (unless grep-find-command 429 (unless grep-find-command
427 (setq grep-find-command 430 (setq grep-find-command
428 (cond ((eq grep-find-use-xargs 'gnu) 431 (cond ((eq grep-find-use-xargs 'gnu)
429 (format "%s . -type f -print0 | xargs -0 -e %s" 432 (format "%s . -type f -print0 | xargs -0 -e %s"
430 find-program grep-command)) 433 find-program grep-command))
431 (grep-find-use-xargs 434 ((eq grep-find-use-xargs 'exec)
435 (let ((cmd0 (format "%s . -type f -exec %s"
436 find-program grep-command)))
437 (cons
438 (format "%s {} %s %s"
439 cmd0 null-device
440 (shell-quote-argument ";"))
441 (1+ (length cmd0)))))
442 (t
432 (format "%s . -type f -print | xargs %s" 443 (format "%s . -type f -print | xargs %s"
433 find-program grep-command)) 444 find-program grep-command)))))
434 (t (cons (format "%s . -type f -exec %s {} %s \\;"
435 find-program grep-command null-device)
436 (+ 22 (length grep-command)))))))
437 (unless grep-find-template 445 (unless grep-find-template
438 (setq grep-find-template 446 (setq grep-find-template
439 (let ((gcmd (format "%s <C> %s <R>" 447 (let ((gcmd (format "%s <C> %s <R>"
@@ -441,11 +449,13 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'."
441 (cond ((eq grep-find-use-xargs 'gnu) 449 (cond ((eq grep-find-use-xargs 'gnu)
442 (format "%s . <X> -type f <F> -print0 | xargs -0 -e %s" 450 (format "%s . <X> -type f <F> -print0 | xargs -0 -e %s"
443 find-program gcmd)) 451 find-program gcmd))
444 (grep-find-use-xargs 452 ((eq grep-find-use-xargs 'exec)
453 (format "%s . <X> -type f <F> -exec %s {} %s %s"
454 find-program gcmd null-device
455 (shell-quote-argument ";")))
456 (t
445 (format "%s . <X> -type f <F> -print | xargs %s" 457 (format "%s . <X> -type f <F> -print | xargs %s"
446 find-program gcmd)) 458 find-program gcmd))))))))
447 (t (format "%s . <X> -type f <F> -exec %s {} %s \\;"
448 find-program gcmd null-device))))))))
449 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) 459 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
450 (setq grep-highlight-matches 460 (setq grep-highlight-matches
451 (with-temp-buffer 461 (with-temp-buffer
@@ -736,18 +746,26 @@ This command shares argument histories with \\[lgrep] and \\[grep-find]."
736 (let ((command (grep-expand-template 746 (let ((command (grep-expand-template
737 grep-find-template 747 grep-find-template
738 regexp 748 regexp
739 (concat "\\( -name " 749 (concat (shell-quote-argument "(")
750 " -name "
740 (mapconcat #'shell-quote-argument 751 (mapconcat #'shell-quote-argument
741 (split-string files) 752 (split-string files)
742 " -o -name ") 753 " -o -name ")
743 " \\)") 754 " "
755 (shell-quote-argument ")"))
744 dir 756 dir
745 (and grep-find-ignored-directories 757 (and grep-find-ignored-directories
746 (concat "\\( -path '*/" 758 (concat (shell-quote-argument "(")
747 (mapconcat #'identity 759 ;; we should use shell-quote-argument here
760 " -path "
761 (mapconcat #'(lambda (dir)
762 (shell-quote-argument
763 (concat "*/" dir)))
748 grep-find-ignored-directories 764 grep-find-ignored-directories
749 "' -o -path '*/") 765 " -o -path ")
750 "' \\) -prune -o "))))) 766 " "
767 (shell-quote-argument ")")
768 " -prune -o ")))))
751 (when command 769 (when command
752 (if current-prefix-arg 770 (if current-prefix-arg
753 (setq command 771 (setq command