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

rg opens a new window for each result file #26

Closed NimoTh closed 6 years ago

NimoTh commented 6 years ago

Currently, rg opens a new window for every file when I press Enter in the *rg* buffer. I would prefer rg to only open a new window once when I visit a result. rg should then reuse that newly opened window when I press Enter on another result. Is that possible?

dajva commented 6 years ago

For me windows are reused, i.e. first time I press ENTER a new window is opened and then that window is reused on further accesses. Which version of emacs are you using?

Might be some setting you have related to compilation-mode possibly?

Try to load emacs without your init.el file to get a vanilla emacs: emacs -Q -l rg.el Does the same happen?

NimoTh commented 6 years ago

I tried with emacs -Q -l s.el -l rg.el. Using latest rg.el from elpa (20180116.9). I can reproduce the "issue" -- with a twist. The behavior I described only occurs when the Emacs frame is on my secondary display! (WTF?) My MacBook (macOS 10.13.2 (17C205)) is the primary display. When the Emacs frame is on that display, windows are reused even with when loading my custom init.el (.emacs in my case). Once I move the frame to my secondary display, which is my monitor, a new window is opened for every different file/buffer when using Enter or the mouse to select a match (next-error works fine)

  1. emacs -Q -l s.el -l rg.el
  2. Move frame to secondary display.
  3. find-file .emacs.d/elpa/rg-20180116.9/rg.el
  4. rg with search string require, file type elisp, directory .emacs.d/elpa
  5. use next-error to visit matches; all matches are shown in the same window, even matches in other files
  6. hit Enter or mouse-click on a match in a file which is currently not displayed in any window Expected: same as using next-error, i.e. reuse existing window. Actual: a new window is opened to visit the buffer

Any ideas?

dajva commented 6 years ago

This seems to be some internal problelm with how emacs displays windows in your setup. I know that compilation-mode that rg-mode is based on is using other-window to show the buffer in some other window than what is current. How that is actually implemented I don't know. I suggest you try to debug the different next-error defuns in compile.el and the window display code. It might help to see when this happens, e.g. will it happen from pure compilation buffers, if you use emacs built in grep or rgrep etc.

Sorrry I can't help you more. I don't think it's a problem with this package. That should be easy to check by testing with grep for instance.

NimoTh commented 6 years ago

Yes, you're right. rgrep has the same issue. Thanks for the hint. I will investigate further in that direction.

Cheers!