tags:

views:

53

answers:

2

This seems like a pretty typical use case, but I'll be damned if I can figure it out. There must be something fundamental I'm missing.

find-dired is basically a front end to the find command that yields a dired-buffer of results

find-grep-dired seems to be more of a front end to grep more so than find. and yields a dired-buffer but it searches all files in the directory tree.

What I would like is the ability to start at a given path and search *.css for #some-id and have it give me a dired-buffer for further processing.

Seems all the pieces are there but I haven't figured it out. So I'm thinking it's something fundamental I may have missed.

+1  A: 

It sounds like the function you are looking for is grep. It will call the grep utility with the expression you give it, and collect the output in an interactive buffer. You may select any of the match lines in the buffer to jump to that line in the file that the match is from.

For example, if you run M-x grep, you should get the following prompt in the mini-buffer:

Run grep (like this): grep -n

Then you add the regexp and glob pattern that you want to pass to grep:

Run grep (like this): grep -n #some-id *.css

And it should give you a list of matches for #some-id in all the files matching *.css in the current directory. If you want to recurse through sub-directories, then you need to use rgrep instead of grep. Does this sound like what you are looking for, or have I completely misunderstood your request?

A. Levy
almost, I need it combined with find to recurse through unless grep can be made to do that.
Tom Willis
Try rgrep. It uses find to recurse through sub-directories and grep all files within.
A. Levy
ah rgrep is closer, the only thing missing is outputting to a dired buffer so I can do things like select/move/copy all those files at once.
Tom Willis
+1  A: 

I'll give A. Levy credit. But I think I figured it out. It seems that find-dired is indeed the tool for the job, but on my windows machine it doesn't pre-fill the args with "-exec grep" and it didn't dawn on me to do that. My linux machine however does pre-fill it with grep.

So....

  #on Linux
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -exec grep -q -e \{\} \; 

  #on windows
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): 

  #Solution
  M-x find-dired
  Run Find in Directory: <current_path> 
  Run find(with args): -type f -iname "*.css" -exec grep -q -e #some-id \{\} \; 
Tom Willis