Subject: Re: bug#62426: [PATCH] eshell: Add 'rgrep' builtin.

From: Jim Porter <[email-masked]>
Date: Sat, 8 Apr 2023 18:55:06 -0700

On 3/25/2023 10:22 AM, Sean Whitton wrote:
> On Fri 24 Mar 2023 at 05:04PM -07, Jim Porter wrote:
> 
>> That said, it might be a bit strange for Eshell's rgrep to work this way, when
>> Eshell's agrep/egrep/fgrep work like the external versions. This seems like a
>> tricky case...
> 
> Tricky indeed.  Here is an attempt:
> 
> Normally with M-x rgrep one benefits from how Emacs prompts you
> separately for the parameters to the function, right?  In particular,
> you get completion for the second and third parameters.  Given that,
> you're unlikely to want to type 'rgrep foo bar baz' into Eshell, and not
> benefit from that completion, when you could just type M-x rgrep in the
> same buffer, and benefit from it.
> 
> Given this, I suggest rgrep in Eshell should be /usr/bin/rgrep.

I've dug through the Eshell grep code over the last few days, and after 
some thinking, I agree that the initial patch is the right way to go. 
While I think it would be nice to get the benefits of M-x rgrep into 
Eshell, it's just too much of a deviation from the existing Eshell grep 
builtins. For example, M-x grep defaults to using "--color=auto", but 
eshell/grep doesn't: eshell/grep is (close to) what you'd get if you 
called /usr/bin/grep directly.

It's all a bit strange though since eshell/grep forces you to have the 
flags "-nH" (file and line number) so that the compilation buffer works 
right. But Eshell sets those flags even when you're *not* using a 
compilation buffer (e.g. when piping the output of grep to some other 
process). I'm not sure it's the behavior I'd want, but it is the way it 
is, and I think it's too late to change it now.

I just see one issue with the patch: the NEWS entry and docstring are a 
bit misleading. I know these are just copying from the existing Eshell 
functions, but this isn't really accurate: "Use Emacs grep facility 
instead of calling external rgrep." It *always* calls the external 
rgrep; it's just that sometimes the output goes into a compilation buffer.

Instead, how about something like this? "Call the external rgrep 
program, opening its output in a compilation buffer when possible." 
(Plus similar changes to the other existing functions.) I think that 
makes it clearer what's actually happening.

Anyway, sorry for the back and forth on this. This is a part of Eshell 
that I haven't looked at in much detail before, and I wanted to get a 
better sense of what our options were here.