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.
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?
This is a bit late, but here is the emacs-lisp function I use regularly:
(defun find-iname-grep-dired (dir pattern regexp)
(interactive
"DFind-name (directory): \nsFind-name (filename wildcard): \nsFind-grep (grep regexp): ")
(find-dired dir (concat "-iname " (shell-quote-argument pattern) " "
"-type f -exec " grep-program " " find-grep-options " -e "
(shell-quote-argument regexp) " "
(shell-quote-argument "{}") " "
(shell-quote-argument ";"))))
It combines find-grep-dired
and find-name-dired
with case-insensitive file name matching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With