emacs-helm / helm

Emacs incremental completion and selection narrowing framework
https://emacs-helm.github.io/helm/
GNU General Public License v3.0
3.37k stars 390 forks source link

Query Replace on contents of marked files #832

Closed mads-hartmann closed 9 years ago

mads-hartmann commented 9 years ago

Is it possible to run query-replace on the contents of the files that are marked in the helm buffer rather than on the filenames of the marked files.

E.g. the following sequence will allow me to rename all the files in the analytics folder that have the .ml extension

C-c p h 
analytics .ml
M-a
M-%

I would love to have a similar way to run query-replace on the contents of the marked files.

thierryvolpiatto commented 9 years ago

Mads Hartmann Jensen notifications@github.com writes:

Is it possible to run query-replace on the contents of the files that are marked in the helm buffer rather than on the filenames of the marked files.

E.g. the following sequence will allow me to rename all the files in the analytics folder that have the .ml extension

C-c p h analytics .ml M-a M-%

I would love to have a similar way to run query-replace on the contents of the marked files.

I haven't implemented this because it is accessible from helm-buffers-list once you have opened all your marked files from helm-find-files.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

mads-hartmann commented 9 years ago

Ah cool, wasn't aware of that. Is it possible to filter in the helm-buffers-list using the path of the underlying file and not just the buffers name?

thierryvolpiatto commented 9 years ago

Mads Hartmann Jensen notifications@github.com writes:

Ah cool, wasn't aware of that. Is it possible to filter in the helm-buffers-list using the path of the underlying file and not just the buffers name? Dunno what you mean by underlying file, say I want to list all the buffers from elisp files in my helm directory from M-x helm-buffers-list, I write:

pattern: /github/helm/ el$

Hit C-c ? for embeded documentation.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

mads-hartmann commented 9 years ago

The "Search by directory name" part of documentation was what I was looking, awesome, somehow I had missed that on my first read through.

So one last thing before we can close this issue. What if I don't have the files opened? Can I use helm to open all marked files? Might be that this is a special case and I'm better off using dired

thierryvolpiatto commented 9 years ago

Mads Hartmann Jensen notifications@github.com writes:

The "Search by directory name" part of documentation was what I was looking, awesome, somehow I had missed that on my first read through.

So one last thing before we can close this issue. What if I don't have the files opened? Can I use helm to open all marked files? Might be that this is a special case and I'm better off using dired

From helm-find-files, mark your files and press RET. M-x helm-buffers-list and narrow down to those files, hit M-m (mark all) and hit M-% or C-M-%.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

thierryvolpiatto commented 9 years ago

BTW leave this open, I will probably add an action and binding to work directly on files as soon as possible.

mads-hartmann commented 9 years ago

Awesome, thanks. The flow in your previous message does the trick. But I'd love to be able to do it directly on files. Cheers.

lewang commented 9 years ago

Wgrep is a great for this functionality as well, it has support for helm.

thierryvolpiatto commented 9 years ago

Le Wang notifications@github.com writes:

Wgrep is a great for this functionality as well, it has support for helm.

Yes. When unsure of the regexp to use one can use grep from helm-find-files on the marked files to see which lines matches, then C-x C-s' in the helm grep buffer and thenC-c C-p' to edit the grep buffer. I generally use iedit to do this instead of query-replace.

This is generally a much better workflow than query-replace. Thanks @lewang to point on this.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

mads-hartmann commented 9 years ago

Thats awesome, thanks!

aguynamedben commented 9 years ago

I followed until C-c C-p' to edit the grep buffer. In my saved helm-grep buffer (*hgrep*)C-c C-p' is undefined. What command do you have that bound to?

I'm having a difficult time understanding how to do a find/replace from a saved helm-grep buffer. I see the viewing commands like `C-o' (helm-grep-mode-jump-other-window), (helm-grep-mode-jump-other-window-forward), etc. but I don't see any options to run a replace from there.

Also, thanks so much for the other helpful info on how to run a replace from within helm-buffers-list and helm-find-files, I was looking for that for a long time before I realized you could do that from those place.

aguynamedben commented 9 years ago

Also, not sure if this is a separate thing (should I file an new issue?), but when performing a find/replace from within helm-buffers-list or helm-find-files, hitting 'Y' does not replace all instances in all buffers like the embedded documentation states. Hitting 'Y' instead performs the functionality that hitting lowercase 'y' does (only the current instance in the current buffer is replaced).

thierryvolpiatto commented 9 years ago

Ben Standefer notifications@github.com writes:

I followed until C-c C-p' to edit the grep buffer. In my saved helm-grep buffer (hgrep)C-c C-p` is undefined. What command do you have that bound to?

You have to install wgrep to have C-c C-p available.

https://github.com/mhayashi1120/Emacs-wgrep

C-c C-p is bound to wgrep-change-to-wgrep-mode.

I'm having a difficult time understanding how to do a find/replace from a saved helm-grep buffer. I see the viewing commands like `C-o' (helm-grep-mode-jump-other-window), (helm-grep-mode-jump-other-window-forward), etc. but I don't see any options to run a replace from there.

Once wgrep is installed and you hit C-c C-p all query-replace, iedit operations are availables (my favorite is iedit).

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

thierryvolpiatto commented 9 years ago

Ben Standefer notifications@github.com writes:

Also, not sure if this is a separate thing (should I file an new issue?), but when performing a find/replace from within helm-buffers-list or helm-find-files, hitting 'Y' does not replace all instances in all buffers like the embedded documentation states. Hitting 'Y' instead performs the functionality that hitting lowercase 'y' does (only the current instance in the current buffer is replaced).

Indeed, "Y" is not working as expected, you have to hit "!" as many times there is buffers to query-replace.

I will look into this ASAP.

Thanks.

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

thierryvolpiatto commented 9 years ago

Should work now. Not easy to understand what the "abomination functions" in replace.el do (sometimes nearly 500 lines long!!!).

aguynamedben commented 9 years ago

@thierryvolpiatto Wow, you are awesome. Both of those worked perfectly.

How do I send you internet beers?

Also, I can't do it right now because I'm getting married in a few weeks, but I'm making a personal TODO to submit a docs PR that helps explains find/replace with helm a bit better. This is blowing my mind. Thank you so much for your hard work on this project.

thierryvolpiatto commented 9 years ago

Ben Standefer notifications@github.com writes:

Also, I can't do it right now because I'm getting married in a few weeks,

Congrats!!! ;-)

but I'm making a personal TODO to submit a docs PR that helps explains find/replace with helm a bit better.

Sounds great, thanks

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

thierryvolpiatto commented 9 years ago

Ben Standefer notifications@github.com writes:

How do I send you internet beers?

You have a paypal icon on the github page ;-)

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997

aguynamedben commented 9 years ago

You have a paypal icon on the github page ;-)

@thierryvolpiatto Done! sent you like a 30-pack of cheap beer, or maybe 4-5 nice beers, or a nice wine since you're in France =) Thanks again

thierryvolpiatto commented 9 years ago

Ben Standefer notifications@github.com writes:

You have a paypal icon on the github page ;-)

@thierryvolpiatto Done! sent you like a 30-pack of cheap beer, or maybe 4-5 nice beers, or a nice wine since you're in France =) Thanks again

Wow! Many thanks :-)

Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997