1

I can use display-buffer-alist to configure a command to open in the same window:

(add-to-list 'display-buffer-alist '("*grep*" display-buffer-same-window))

The problem in this case, however, is if I then open a result and subsequently run a new search without closing the original window, Emacs will open a second view of the search results in the current buffer. That gives me two redundant views of the same results, which is obviously not my intention.

I would like this to be a bit smarter, in that if the buffer is already visible in the current frame, it should merely reuse it (or change focus to it), and display in the current window otherwise.

How can I achieve this behavior?

1

display-buffer-alist actions can be multiple functions (a list of functions), the first one which returns non nil is used.

So you can use:

  (add-to-list 'display-buffer-alist '("*grep" (display-buffer-reuse-window
                                              display-buffer-same-window)))

More info:
Emacs manual about ready availabe display-buffer actions

| improve this answer | |
  • Perfect, thanks. I'd seen that page, but didn't realize it could take a list of functions, though I suppose the very name 'list' implies that. – Digicrat Feb 28 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.