dajva / rg.el

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

How to make "enter" key open target file follow `display-buffer-alist` in rg result buffer? #87

Closed stardiviner closed 4 years ago

stardiviner commented 4 years ago

When I press "Enter" key on rg result buffer to open target file. I found it does not follow the display-buffer-alist. I want it to open in below splited window. Instead of random other window overrided. Is there any solution?

dajva commented 4 years ago

This is controlled by compilation-mode. My understanding is that this should work but I have not used display-buffer-alist myself. Setting it up like this gives me some output in the Messages buffer at least:

(defun my-rg-buffer (bufname action)
  (message "%S - %S" bufname action)
  nil)

(setq display-buffer-alist '((my-rg-buffer)))
stardiviner commented 4 years ago

I tried this method, does not work on my machine. I even tested on minimal Emacs config.

tbruckmaier commented 4 years ago

You can use this method from https://emacs.stackexchange.com/questions/19080/is-there-a-better-way-to-override-opening-window-in-compilation-goto-locus

(defvar display-buffer-same-window-commands
  '(occur-mode-goto-occurrence compile-goto-error))

(add-to-list 'display-buffer-alist
             '((lambda (&rest _)
                 (memq this-command display-buffer-same-window-commands))
               (display-buffer-reuse-window
                display-buffer-same-window)
               (inhibit-same-window . nil)))
stardiviner commented 4 years ago

@tbruckmaier It works for me. That's really great. Thanks a lot.!! :)

tbruckmaier commented 4 years ago

If anyone wants to make this work in doom emacs, you need to use the variable '+popup--display-buffer-alist, as display-buffer-alist is overwritten with that one. There is also a helper macro/function(?) (set-popup-rule!), but I could not make it work that way.