0

I use 'occur' to search for regexp in current buffer and edit the results in occur buffer .

Now my requirement is to search all the files in a directory(including sub-directories ) and edit the results.

ie. Edit the result of ' grep -r foo * '

Is there anything similar(like occur buffer) that allows to edit the searched results in my case.

3
  • Searching recursively or searching multiple files (anywhere). The question is not too clear. How do you want to specify the set of files to search? See, for example, command multi-occur-in-matching-buffers.
    – Drew
    Commented May 18, 2019 at 14:54
  • Set of files from command: ' grep -r foo * '. I have updated my question.
    – Green
    Commented May 19, 2019 at 4:34
  • It seems this question has been asked earlier, but differently . emacs.stackexchange.com/questions/212/… .
    – Green
    Commented May 19, 2019 at 4:38

2 Answers 2

1

Elgrep allows you to grep files in a directory and recursively in its sub-directories. It lists the found matches in an *elgrep* buffer (much like occur).

New users should input the search data in the *elgrep-menu* buffer opened by the command M-x elgrep-menu RET.

The minor mode elgrep-edit-mode can be toggled on through the menu item Elgrep -> Elgrep-edit in the *elgrep* buffer it is also bound to the key sequence C-c C-e. The user experience in editing the *elgrep* buffer is a bit different from that one editing the *occur* buffer.The edits are not performed instantaneous in the corresponding file buffer but you save the edits in the *elgrep* buffer with save-buffer (normally bound to C-x C-s) when you are done.
The edits in the *elgrep* buffer are applied to the files with the matches on save-buffer.

Remarks:

  • You can install elgrep via melpa. If you have registered correctly melpa in package-archives you just call M-x package-install RET elgrep RET.
  • You can use the option Run asynchronously in the *elgrep-menu* buffer even if that one is marked as experimentally. I use it for years now and it is rock-solid. The only drawback is the weak feedback if no matches are found. It just prints a message No matches found in the echo area.
  • If you save the edits from the *elgrep* buffer elgrep checks whether it finds the old matches in the listed files. It does not apply the edit for a match if it does not find the old match. This is a measure of caution. It has the drawback that you can/should not edit and save matches multiple times without a new run of elgrep.
  • You can edit the matched texts in the *elgrep* buffer but you cannot edit the file names or the line numbers for the matches. They are protected with the read-only text property.
-1

To expand on Tobias's answer, there's already a built-in rgrep which does much the same. It uses the grep binary though.

1
  • rgrep doesn't allow editing in the results buffer like OP asked for.
    – user12563
    Commented May 19, 2019 at 12:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.