Subject: Re: bug#23590: 25.0.94; Errors in default lgrep command

From: Lars Ingebrigtsen <[email-masked]>
Date: Fri, 04 Sep 2020 16:09:52 +0200

Alex <[email-masked]> writes:

>> Actually, I see that "Is a directory" also caused exit code of 2.  So
>> I guess patches are welcome to add --directory=skip to the Grep
>> command when a preliminary test reveals that Grep supports it.
>
> Is the following patch acceptable?

There was discussion here before the patch was posted, but then no
follow-up.  I've respun the patch for Emacs 28 -- does anybody have any
comments?

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index c71a90344f..17f0422ac7 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -696,10 +696,15 @@ grep-compute-defaults
       (let ((grep-options
 	     (concat (if grep-use-null-device "-n" "-nH")
                      (if grep-use-null-filename-separator " --null")
-		     (if (grep-probe grep-program
-				     `(nil nil nil "-e" "foo" ,null-device)
-				     nil 1)
-			 " -e"))))
+                     (when (grep-probe grep-program
+                                       `(nil nil nil "--directories=skip" "foo"
+                                             ,null-device)
+                                       nil 1)
+                       " --directories=skip")
+                     (when (grep-probe grep-program
+                                       `(nil nil nil "-e" "foo" ,null-device)
+                                       nil 1)
+                       " -e"))))
 	(unless grep-command
 	  (setq grep-command
 		(format "%s %s %s " grep-program

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no