this post was submitted on 19 Nov 2023
1 points (100.0% liked)

Emacs

305 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

I'm looking for a way to preview the results of a grep search within files as well as fold the output when there are multiple matches in the same file.

helm-projectile-ag is my current grepping tool but doesn't seem to offer such a facility, unless I haven't read the docs well enough.

My issues are:

  1. It can present a lot of hits in the same file it but lists each one separately. A good option would be to fold the output when there are multiple matches, then I can use the Tab keep to expand the fold and scan through the previews and even edit them right away.

  2. The search panel is modal. It doesn't create a result buffer which you can save and then return to later to continue to select files to edit. Once you lose focus it is gone. It doesn't even seem to retain the search term so you can use it later.

  3. It would be nice to have a window that shows the actual CLI command passed to the search utility. I see them once in a while but it would be good to show them up front or make them easily accessible.

Do any of the project grep tools or helm-projectile-ag itself offer such features?

top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 10 months ago (1 children)

For previewing file, press `C-c C-f` to enable `follow-mode`. Then, a buffer is opened whenever you move your highlight to a file.

For saving buffer, Helm offers an action to save:

https://preview.redd.it/1sszl5rsgc1c1.png?width=436&format=png&auto=webp&s=5683d25b81da642f28fc9cba4846a882649bc82f

By default, you press `tab` to access action menu.

[–] [email protected] 1 points 10 months ago

I'm trying it and get can't the action menu.

Is this in a new version of helm-projectile-ag?

[–] [email protected] 1 points 10 months ago

Consult is what you are looking for: https://github.com/minad/consult In particular try consult-ripgrep

[–] [email protected] 1 points 10 months ago

Try embark and the embark export along with consult (or maybe helm). With consult for example you can hit Tab to jump to the next file. Embark export can export the grep results, which can even be saved - and re-opened later and browsed with grep mode enabled :)