Nice! When I press RET on any of the files, I expect the corresponding file to be loaded. At least that would be very convenient. Instead I see in the *Messages* buffer: compilation-next-error: No grep hit here

2 Answers
2

I don't think anything is broken, it seems that Emacs isn't designed to deal with the -l grep flag the way you're trying to use it.

Without the -l flag, Emacs (via eshell or M-x grep) will take the output from grep and insert it in a buffer. It uses the formatted output to create links to the matches in each file.

When you add the -l flag, the output from grep isn't in the same format: it no longer includes line numbers, just the file name. As it is now, Emacs seems to require the line numbers to create the links. The links aren't made, and you get the message No grep hit here.

It would be helpful to provide a link to the first line of the file when you've suppressed the match results with -l. That might make a good feature request (although accommodating all the different messages grep might output could make this trickier than it sounds).

You can get almost what you want via the -m flag. Rather than limit the output to only filenames, you can limit it to only give you the first match in each file:

grep -m1 foo ./*

The resulting buffer will include active links to the first match in each file, rather than the start of the file. It works with GNU grep, but not all greps support the -m flag. The -s flag, to suppress additional messages (about directories or unreadable files etc), might also be useful here.

This answer is similar to the Tyler's answer but presented differently.

The interface is coherent. Indeed, a user can make editions once it knows the appropriate locations (patterns, file names and line numbers). In facts, an hyperlink is included in the special buffer while the user searches the location of a pattern since the next step may be to edit contents in the corresponding files.

Note that the command line is not well formed: the wildcard is unsuitable.