I commonly do find-grep-dired
to find an expression in a project directory. That gives me a nice dired
view of all the files that contain that expression. But my next step is invariably to open one of those files and do an isearch-forward
with the same search expression. How can I save myself from typing in the search words twice each time (or more than twice if there are multiple files I want to edit)?
This should work for you:
find-grep-dired
as usualdired-do-search
. When prompted, instead of typing, press M-p, this will bring up your find-grep regexp since both functions use the same prompting history listAnd if you want it all in one shot, here you go:
(defun find-grep-dired-do-search (dir regexp)
"First perform `find-grep-dired', and wait for it to finish.
Then, using the same REGEXP as provided to `find-grep-dired',
perform `dired-do-search' on all files in the *Find* buffer."
(interactive "DFind-grep (directory): \nsFind-grep (grep regexp): ")
(find-grep-dired dir regexp)
(while (get-buffer-process (get-buffer "*Find*"))
(sit-for 1))
(with-current-buffer "*Find*"
(dired-toggle-marks)
(dired-do-search regexp)))