dajva / rg.el

Emacs search tool based on ripgrep
https://rgel.readthedocs.io
GNU General Public License v3.0
484 stars 41 forks source link

Running a search replaces search buffer #57

Closed spookylukey closed 5 years ago

spookylukey commented 5 years ago

If I run a search, and then another, the original search buffer is replaced. I would expect a new buffer to be created for each search.

I am aware of rg-back-history, but this doesn't help much for my very common use case:

  1. I'm doing some refactoring or checking, so I search for foo and go down the list of the results. Critically, every time I switch back to the search results buffer, my place in the buffer is remembered
  2. As part of fixing foo, I realize I also need to fix bar, and so start a search for that.
  3. After I finish fixing bar, I can carry on my place fixing foo

rg-back-history puts my cursor back at the top

Other tools e.g. ag-project-regexp from ag.el behaves ideally in this respect - it opens a new buffer for each search. When you are done with a search, you close the buffer and go back to your exact place in the previous search.

I've also tried the "saved search" functionality, but it's not very convenient. If I'm looking through a file, and want to do a search, I have to remember to use it. So before I do a search I have to first find the last search buffer, save it, then go back to where I was. I'm looking for something that will make rg.el always open a new search buffer - I can always close the ones I don't need any more, but if I lose one that I was half way through, I can't go back.

Thanks for your consideration!

dajva commented 5 years ago

Thanks for the report. Regarding the saved search functionality. It should work from any buffer, then saving the last search you did, more specifically the buffer named *rg*, otherwise it's a bug. I don't know if that helps your use case much though.

For your main request, it's something I have considered but never wanted myself so never implemented it. I am open to adding it as a customization though since I can see that some people prefer that behavior.

I have never used ag.el myself but if i understand you correctly you essentially want automatic save when you start a new search, is that correct? I don't have much time implementing this now but it doesn't seem that hard to achieve since it seems like the main functionality of "saving" search buffer already exists. If you want to have a go an implement it I would gladly accept a pr.

As a workaround you could create an advice around the rg-run defun to get this functionality.

spookylukey commented 5 years ago

You're right - it looks like just using advice to run rg-save-search after every rg-run does exactly what I need, and I can do this with advice so that I don't need to create wrappers for each of rg-project, rg-dwim etc. So I'm closing this, as this seems a more elegant solution. Thanks for your time, and for the great package.