0
votes

I want emacs grep to always search from the root project directory, not the directory of the currently opened file. The assumption here is that all of your coding projects are under the same folder (like ~/repositories/).

I tried to prefix the grep command with a command that cds into the project root, but this leaves the emacs working directory variable untouched, so while the grep is performed in the correct filesystem location, jumping to search results is broken, because the partial file paths of the grep matches are appended to the emacs working directory.

To summarize, I want to be in ~/repositories/my_project/folder1/file1.c, invoke grep command which will search from ~/repositories/my_project/, and have the jump to file functionality of the grep buffer work.

How can I achieve this?

1

1 Answers

1
votes

This does not answer directly your grep question but especially when working with projects, I always find projectile to be a great tool.

Projectile, amongst other things, provides a grep, ack and ag search on a project level which is probably what you are looking for.

E.g.

C-c p s g runs grep on the files in the project.