3

Example in eshell:

$ cd ~/src/Sporth
$ grep -rl Name *

I get as output:

-*- mode: grep; default-directory: "~/src/Sporth/" -*-
Grep started at Fri Feb  1 17:07:41

grep -n -rl Name LICENSE Makefile README.md config.def.mk examples/ ftmap.c func.c h/ hash.c parse.c plumber.c sporth.c stack.c ugen_reference.txt ugens/ util/
ugen_reference.txt
util/sp_jack.c
util/ugen_lookup
util/chorth/include/chuck_oo.h

Grep finished with matches found at Fri Feb  1 17:07:41

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

Is there something broken? Is additional configuration necessary?

emacs-version evaluates to: GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2018-07-05

5

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.

0

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.

grep -nr Name ~/src/Sporth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.