Question: I'm aware of `find-grep-dired`, marking the corresponding files and then pressing `Q` to run `dired-do-query-replace-regexp` on the marked files. Unfortunately that requires restarting the grep and no longer using git-grep, ack, or ag and switching to use `find-grep` which has a different syntax for searching.

I'm also aware of `multi-occur` and `occur-edit-mode`, but that requires restarting the search using occur. Finally, `ag-dired` appears to match on the filename, not on the contents of the file.

My current approach is to generate grep output, and then run a macro that starts in the grep buffer, and visits each match and changes it. I would prefer to use `query-replace` directly over the set of matches found.

What I would like to do is to either quickly build a dired buffer from existing grep output so that I can mark the appropriate files and call query-regexp on them, or transform grep output into a list of buffers for `multi-occur` so that I can use `occur-edit-mode` to edit it in place and run `query-replace` on that buffer.

Does this functionality exist, or is there another workflow that solves this problem?

Answer: 
> 
> What I would like to do is to either quickly build a dired buffer from existing grep output [...], or transform grep output into a list of buffers for multi-occur [...].
> 
> 
> 

You don't need to convert the grep results buffer into anything, there's already a mode specifically for editing grep output (and reflecting the changes on the files, of course).

1. Install the [wgrep](https://github.com/mhayashi1120/Emacs-wgrep) package from Melpa.
2. `(require 'wgrep)` in your init file.
3. After doing a grep search, hit `C-c C-p` and edit away!
4. Save your edits with `C-c C-e`

It even works with ack and ag as well.
Here is another approach, using [**Icicles**](http://www.emacswiki.org/Icicles).

In your Emacs `*grep*` output buffer, hit C-c ` (that's C-c backquote), which in *Icicle* mode is bound in buffer `*grep*` to command `icicle-compilation-search`. This lets you quickly navigate among any of the search hits (the `grep` hits) you choose, in any order.

Input you type in the minibuffer dynamically filters (narrows) the set of search hits, and you can use [progressive completion](http://www.emacswiki.org/Icicles_-_Progressive_Completion) to narrow by successively matching multiple patterns (e.g. substrings, regexps).

When navigating among search hits you can replace any of them on demand - either the entire hit (line) or just the part matching your current minibuffer input.

See [Icicles Search - Compile or Grep](http://www.emacswiki.org/Icicles_-_Other_Search_Commands#IciclesCompileOrGrep). An intro to **Icicles** search is [here](http://www.emacswiki.org/Icicles_-_Search_Commands%2c_Overview), and info about replacing matches during **Icicles** search is [here](http://www.emacswiki.org/Icicles_-_Search-And-Replace).