Subject: bug#9226: 23.3; [rgrep]; (matches found) ?

From: Juri Linkov <[email-masked]>
Date: Sat, 17 Sep 2011 21:24:16 +0300

> grep -inH -e "test" *
> Grep finished (matches found)
>
> grep -inH -e "testx" *
> Grep finished with no matches found
>
> grepx -inH -e "test" *
> Grep exited abnormally with code 127
>
> find . -exec grep -i test {} \;
> Grep finished (matches found)
>
> find . -exec grep -i testx {} \;
> Grep finished with no matches found
>
> find . -name testx -exec grep -i testx {} \;
> Grep finished with no matches found
>
> find . -print0 | xargs -0 -e grep -i -nH -e test
> Grep finished (matches found)
>
> find . -print0 | xargs -0 -e grep -i -nH -e testx
> Grep finished with no matches found
>
> === modified file 'lisp/progmodes/grep.el'
> --- lisp/progmodes/grep.el	2011-08-10 20:31:17 +0000
> +++ lisp/progmodes/grep.el	2011-08-17 16:47:24 +0000
> @@ -463,9 +463,9 @@ (defun grep-process-setup ()
>    (set (make-local-variable 'compilation-exit-message-function)
>         (lambda (status code msg)
>  	 (if (eq status 'exit)
> -	     (cond ((zerop code)
> +	     (cond ((and (zerop code) (buffer-modified-p))
>  		    '("finished (matches found)\n" . "matched"))
> -		   ((= code 1)
> +		   ((or (= code 1) (not (buffer-modified-p)))

Another use-case:

find . -exec zgrep -inH test {} \;
./file1:1:Test #1
Grep finished (matches found)

find . -exec zgrep -inH test {} +
./file1:1:Test #1
Grep finished with no matches found

The latter's message is wrong because zgrep returns 1
when matches are found successfully.

The following patch provides more reliable message
"Grep exited abnormally with code 1" and still works
correctly for other cases:

--- lisp/progmodes/grep.el	2011-09-08 21:04:30 +0000
+++ lisp/progmodes/grep.el	2011-09-17 18:20:31 +0000
@@ -478,7 +478,7 @@ (defun grep-process-setup ()
 	     ;; so the buffer is still unmodified if there is no output.
 	     (cond ((and (zerop code) (buffer-modified-p))
 		    '("finished (matches found)\n" . "matched"))
-		   ((or (= code 1) (not (buffer-modified-p)))
+		   ((not (buffer-modified-p))
 		    '("finished with no matches found\n" . "no match"))
 		   (t
 		    (cons msg code)))