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

From: Alex <[email-masked]>
Date: Sat, 23 Jul 2016 16:12:55 -0600

Eli Zaretskii <[email-masked]> writes:

>> Date: Sat, 23 Jul 2016 21:00:37 +0300
>> From: Eli Zaretskii <[email-masked]>
>> Cc: [email-masked], [email-masked]
>> 
>> > Grep exited abnormally with code 2 at ...
>> 
>> Because of this:
>> 
>> > grep: ..?*: No such file or directory
>
> 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?

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index f04a722..c696f75 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -573,10 +573,14 @@ This function is called from `compilation-filter-hook'."
                 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"))))
+                     (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